Class ClientsExecutor
java.lang.Object
org.sentrysoftware.metricshub.engine.client.ClientsExecutor
The ClientsExecutor class provides utility methods for executing
various operations through Clients. It includes functionalities for executing
requests, running scripts, and handling general execution tasks. The
execution is done on a remote host, and various protocols, clients, and
utilities like AWK, HTTP, IPMI, JFlat, SNMP, SSH, TableJoin, VCenter, WBEM,
WMI, WinRM, and XFlat are supported.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnum representing different types of SNMP requests. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.sentrysoftware.ssh.SshClientconnectSshClientTerminal(@NonNull String hostname, @NonNull String username, char[] password, File privateKey, int timeout) Connect to the SSH terminal.static org.sentrysoftware.ssh.SshClientcreateSshClientInstance(String hostname) Creates a new instance of theSshClient.executeAwkScript(String embeddedFileScript, String input) Call AwkExecutor in order to execute the Awk script on the given inputexecuteHttp(@NonNull HttpRequest httpRequest, boolean logMode) Executes the given HTTP requestexecuteIpmiDetection(String hostname, @NonNull IpmiConfiguration ipmiConfiguration) Runs IPMI detection to determine the Chassis power state.executeIpmiGetSensors(String hostname, @NonNull IpmiConfiguration ipmiConfiguration) Executes an IPMI Over-LAN request to retrieve information about all sensors.executeJson2Csv(String jsonSource, String jsonEntryKey, List<String> propertyList, String separator) Execute JSON to CSV operation.static StringexecuteRemoteWinRmCommand(@NonNull String hostname, @NonNull WinRmConfiguration winRmConfiguration, @NonNull String command) Execute a WinRM remote commandexecuteSNMPGet(@NonNull String oid, @NonNull SnmpConfiguration configuration, @NonNull String hostname, boolean logMode) Execute SNMP Get requestexecuteSNMPGetNext(@NonNull String oid, @NonNull SnmpConfiguration configuration, @NonNull String hostname, boolean logMode) Execute SNMP GetNext requestexecuteSNMPTable(@NonNull String oid, @NonNull String[] selectColumnArray, @NonNull SnmpConfiguration configuration, @NonNull String hostname, boolean logMode) Execute SNMP TableexecuteTableJoin(List<List<String>> leftTable, List<List<String>> rightTable, int leftKeyColumnNumber, int rightKeyColumnNumber, List<String> defaultRightLine, boolean wbemKeyType, boolean caseInsensitive) Execute TableJoinexecuteWbem(@NonNull String hostname, @NonNull WbemConfiguration wbemConfig, @NonNull String query, @NonNull String namespace) Determine if a vCenter server is configured and call the appropriate method to run the WBEM query.static StringexecuteWinRemoteCommand(String hostname, IConfiguration configuration, String command, List<String> embeddedFiles) Perform a WQL remote command query, either against a CIM server (WBEM) or WMIexecuteWmi(String hostname, @NonNull WmiConfiguration wmiConfig, @NonNull String wbemQuery, @NonNull String namespace) Execute a WMI querystatic StringexecuteWmiRemoteCommand(String command, String hostname, String username, char[] password, int timeout, List<String> localFiles) Execute a command on a remote Windows system through Client and return an object with the output of the command.executeWql(String hostname, IConfiguration configuration, String query, String namespace) Perform a WQL query, either against a CIM server (WBEM) or WMIexecuteWqlThroughWinRm(@NonNull String hostname, @NonNull WinRmConfiguration winRmConfiguration, @NonNull String query, @NonNull String namespace) Execute a WinRM queryexecuteXmlParsing(String xml, String properties, String recordTag) Parse a XML with the argument properties into a list of values list.static StringrunRemoteSshCommand(@NonNull String hostname, @NonNull String username, char[] password, File keyFilePath, String command, long timeout, List<File> localFiles, String noPasswordCommand) Use ssh-client in order to run ssh command.
-
Constructor Details
-
ClientsExecutor
public ClientsExecutor()
-
-
Method Details
-
executeSNMPGetNext
public String executeSNMPGetNext(@NonNull @NonNull String oid, @NonNull @NonNull SnmpConfiguration configuration, @NonNull @NonNull String hostname, boolean logMode) throws InterruptedException, ExecutionException, TimeoutException Execute SNMP GetNext request- Parameters:
oid- The Object Identifier (OID) for the SNMP GETNEXT request.configuration- The SNMP configuration specifying parameters like version, community, etc.hostname- The hostname or IP address of the SNMP-enabled device.logMode- A boolean indicating whether to log errors and warnings during execution.- Returns:
- The SNMP response as a String value.
- Throws:
InterruptedException- If the execution is interrupted.ExecutionException- If an exception occurs during execution.TimeoutException- If the execution times out.
-
executeSNMPGet
public String executeSNMPGet(@NonNull @NonNull String oid, @NonNull @NonNull SnmpConfiguration configuration, @NonNull @NonNull String hostname, boolean logMode) throws InterruptedException, ExecutionException, TimeoutException Execute SNMP Get request- Parameters:
oid- The Object Identifier (OID) for the SNMP GET request.configuration- The SNMP configuration specifying parameters like version, community, etc.hostname- The hostname or IP address of the SNMP-enabled device.logMode- A boolean indicating whether to log errors and warnings during execution.- Returns:
- The SNMP response as a String value.
- Throws:
InterruptedException- If the execution is interrupted.ExecutionException- If an exception occurs during execution.TimeoutException- If the execution times out.
-
executeSNMPTable
public List<List<String>> executeSNMPTable(@NonNull @NonNull String oid, @NonNull @NonNull String[] selectColumnArray, @NonNull @NonNull SnmpConfiguration configuration, @NonNull @NonNull String hostname, boolean logMode) throws InterruptedException, ExecutionException, TimeoutException Execute SNMP Table- Parameters:
oid- The SNMP Object Identifier (OID) representing the table.selectColumnArray- An array of column names to select from the SNMP table.configuration- The SNMP configuration containing connection details.hostname- The hostname or IP address of the SNMP-enabled device.logMode- Flag indicating whether to log warnings in case of errors.- Returns:
- A list of rows, where each row is a list of string cells representing the SNMP table.
- Throws:
InterruptedException- If the thread executing this method is interrupted.ExecutionException- If an exception occurs during the execution of the SNMP request.TimeoutException- If the SNMP request times out.
-
executeTableJoin
public List<List<String>> executeTableJoin(List<List<String>> leftTable, List<List<String>> rightTable, int leftKeyColumnNumber, int rightKeyColumnNumber, List<String> defaultRightLine, boolean wbemKeyType, boolean caseInsensitive) Execute TableJoin- Parameters:
leftTable- The left table.rightTable- The right table.leftKeyColumnNumber- The column number for the key in the left table.rightKeyColumnNumber- The column number for the key in the right table.defaultRightLine- The default line for the right table.wbemKeyType-trueif WBEM.caseInsensitive-truefor case-insensitive comparison.- Returns:
- The result of the table join operation.
-
executeAwkScript
Call AwkExecutor in order to execute the Awk script on the given input- Parameters:
embeddedFileScript- The embedded file script.input- The input for the Awk script.- Returns:
- The result of executing the Awk script.
- Throws:
AwkException- if an error occurs during Awk script execution.
-
executeJson2Csv
public String executeJson2Csv(String jsonSource, String jsonEntryKey, List<String> propertyList, String separator) throws InterruptedException, ExecutionException, TimeoutException Execute JSON to CSV operation.- Parameters:
jsonSource- The JSON source string.jsonEntryKey- The JSON entry key.propertyList- The list of properties.separator- The separator for CSV.- Returns:
- The CSV representation of the JSON.
- Throws:
TimeoutException- If the execution times out.ExecutionException- If an execution exception occurs.InterruptedException- If the execution is interrupted.
-
executeXmlParsing
public List<List<String>> executeXmlParsing(String xml, String properties, String recordTag) throws org.sentrysoftware.xflat.exceptions.XFlatException Parse a XML with the argument properties into a list of values list.- Parameters:
xml- The XML.properties- A string containing the paths to properties to retrieve separated by a semi-colon character.
If the property comes from an attribute, it will be preceded by a superior character: '>'.recordTag- A string containing the first element xml tags path to convert. example: /rootTag/tag2- Returns:
- The list of values list.
- Throws:
org.sentrysoftware.xflat.exceptions.XFlatException- if an error occurred in the XML parsing.
-
executeWql
public List<List<String>> executeWql(String hostname, IConfiguration configuration, String query, String namespace) throws ClientException Perform a WQL query, either against a CIM server (WBEM) or WMI- Parameters:
hostname- Hostnameconfiguration- The WbemConfiguration or WmiConfiguration object specifying how to connect to specified hostquery- WQL query to executenamespace- The namespace- Returns:
- A table (as a
ListofListofStrings) resulting from the execution of the query. - Throws:
ClientException- when anything wrong happens
-
executeWinRemoteCommand
public static String executeWinRemoteCommand(String hostname, IConfiguration configuration, String command, List<String> embeddedFiles) throws ClientException Perform a WQL remote command query, either against a CIM server (WBEM) or WMI- Parameters:
hostname- Hostnameconfiguration- The WbemConfiguration or WmiConfiguration object specifying how to connect to specified hostcommand- Windows remote command to executeembeddedFiles- The list of embedded files used in the wql remote command query- Returns:
- A table (as a
ListofListofStrings) resulting from the execution of the query. - Throws:
ClientException- when anything wrong happens
-
executeWbem
public List<List<String>> executeWbem(@NonNull @NonNull String hostname, @NonNull @NonNull WbemConfiguration wbemConfig, @NonNull @NonNull String query, @NonNull @NonNull String namespace) throws ClientException Determine if a vCenter server is configured and call the appropriate method to run the WBEM query.- Parameters:
hostname- HostnamewbemConfig- WBEM Protocol configuration, incl. credentialsquery- WQL query to executenamespace- WBEM namespace- Returns:
- A table (as a
ListofListofStrings) resulting from the execution of the query. - Throws:
ClientException- when anything goes wrong (details in cause)
-
executeWmi
public List<List<String>> executeWmi(String hostname, @NonNull @NonNull WmiConfiguration wmiConfig, @NonNull @NonNull String wbemQuery, @NonNull @NonNull String namespace) throws ClientException Execute a WMI query- Parameters:
hostname- The hostname of the device where the WMI service is running (nullfor localhost)wmiConfig- WMI Protocol configuration (credentials, timeout)wbemQuery- The WQL to executenamespace- The WBEM namespace where all the classes reside- Returns:
- A list of rows, where each row is represented as a list of strings.
- Throws:
ClientException- when anything goes wrong (details in cause)
-
executeWmiRemoteCommand
public static String executeWmiRemoteCommand(String command, String hostname, String username, char[] password, int timeout, List<String> localFiles) throws ClientException Execute a command on a remote Windows system through Client and return an object with the output of the command.- Parameters:
command- The command to execute. (Mandatory)hostname- The host to connect to. (Mandatory)username- The username.password- The password.timeout- Timeout in secondslocalFiles- The local files list- Returns:
- The output of the executed command.
- Throws:
ClientException- For any problem encountered.
-
executeHttp
Executes the given HTTP request- Parameters:
httpRequest- TheHttpRequestvalues.logMode- Whether or not logging is enabled.- Returns:
- The result of the execution of the given HTTP request.
-
runRemoteSshCommand
public static String runRemoteSshCommand(@NonNull @NonNull String hostname, @NonNull @NonNull String username, char[] password, File keyFilePath, String command, long timeout, List<File> localFiles, String noPasswordCommand) throws ClientException Use ssh-client in order to run ssh command.- Parameters:
hostname- The hostname or IP address to connect to.username- The SSH username.password- The SSH password as a character array.keyFilePath- The path to the SSH key file.command- The SSH command to execute.timeout- The timeout for the command execution in seconds.localFiles- List of local files to be transferred to the remote host.noPasswordCommand- The command to execute without password.- Returns:
- The result of the SSH command.
- Throws:
ClientException- If an error occurs during the SSH command execution.
-
createSshClientInstance
Creates a new instance of theSshClient.- Parameters:
hostname- The hostname.- Returns:
- A
SshClientinstance.
-
connectSshClientTerminal
public static org.sentrysoftware.ssh.SshClient connectSshClientTerminal(@NonNull @NonNull String hostname, @NonNull @NonNull String username, char[] password, File privateKey, int timeout) throws ClientException Connect to the SSH terminal. For that:- Create an SSH Client instance.
- Connect to SSH.
- Open a SSH session.
- Open a terminal.
- Parameters:
hostname- The hostname (mandatory)username- The username (mandatory)password- The passwordprivateKey- The private key filetimeout- The timeout (>0) in seconds- Returns:
- The SSH client
- Throws:
ClientException- If a Client error occurred.
-
executeIpmiDetection
public String executeIpmiDetection(String hostname, @NonNull @NonNull IpmiConfiguration ipmiConfiguration) throws InterruptedException, ExecutionException, TimeoutException Runs IPMI detection to determine the Chassis power state.- Parameters:
hostname- The host name or IP address to query.ipmiConfiguration- The MetricsHubIpmiConfigurationinstance with required fields for IPMI requests.- Returns:
- A string value, e.g., "System power state is up."
- Throws:
InterruptedException- If the execution is interrupted.ExecutionException- If the execution encounters an exception.TimeoutException- If the operation times out.
-
executeIpmiGetSensors
public String executeIpmiGetSensors(String hostname, @NonNull @NonNull IpmiConfiguration ipmiConfiguration) throws InterruptedException, ExecutionException, TimeoutException Executes an IPMI Over-LAN request to retrieve information about all sensors.- Parameters:
hostname- The host for which theIpmiConfigurationis set.ipmiConfiguration- The MetricsHubIpmiConfigurationinstance containing the required fields for IPMI requests.- Returns:
- A string containing information about FRUs, sensor states, and readings.
- Throws:
InterruptedException- If the execution is interrupted.ExecutionException- If the execution encounters an exception.TimeoutException- If the operation times out.
-
executeWqlThroughWinRm
public List<List<String>> executeWqlThroughWinRm(@NonNull @NonNull String hostname, @NonNull @NonNull WinRmConfiguration winRmConfiguration, @NonNull @NonNull String query, @NonNull @NonNull String namespace) throws ClientException Execute a WinRM query- Parameters:
hostname- The hostname of the device where the WinRM service is running (nullfor localhost)winRmConfiguration- WinRM Protocol configuration (credentials, timeout)query- The query to executenamespace- The namespace on which to execute the query- Returns:
- The result of the query
- Throws:
ClientException- when anything goes wrong (details in cause)
-
executeRemoteWinRmCommand
public static String executeRemoteWinRmCommand(@NonNull @NonNull String hostname, @NonNull @NonNull WinRmConfiguration winRmConfiguration, @NonNull @NonNull String command) throws ClientException Execute a WinRM remote command- Parameters:
hostname- The hostname of the device where the WinRM service is running (nullfor localhost)winRmConfiguration- WinRM Protocol configuration (credentials, timeout)command- The command to execute- Returns:
- The result of the query
- Throws:
ClientException- when anything goes wrong (details in cause)
-