Class ClientsExecutor

java.lang.Object
org.sentrysoftware.metricshub.engine.client.ClientsExecutor

public class ClientsExecutor extends Object
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.
  • 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 - true if WBEM.
      caseInsensitive - true for case-insensitive comparison.
      Returns:
      The result of the table join operation.
    • executeAwkScript

      public String executeAwkScript(String embeddedFileScript, String input) throws AwkException
      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 - Hostname
      configuration - The WbemConfiguration or WmiConfiguration object specifying how to connect to specified host
      query - WQL query to execute
      namespace - The namespace
      Returns:
      A table (as a List of List of Strings) 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 - Hostname
      configuration - The WbemConfiguration or WmiConfiguration object specifying how to connect to specified host
      command - Windows remote command to execute
      embeddedFiles - The list of embedded files used in the wql remote command query
      Returns:
      A table (as a List of List of Strings) 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 - Hostname
      wbemConfig - WBEM Protocol configuration, incl. credentials
      query - WQL query to execute
      namespace - WBEM namespace
      Returns:
      A table (as a List of List of Strings) 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 (null for localhost)
      wmiConfig - WMI Protocol configuration (credentials, timeout)
      wbemQuery - The WQL to execute
      namespace - 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 seconds
      localFiles - The local files list
      Returns:
      The output of the executed command.
      Throws:
      ClientException - For any problem encountered.
    • executeHttp

      public String executeHttp(@NonNull @NonNull HttpRequest httpRequest, boolean logMode)
      Executes the given HTTP request
      Parameters:
      httpRequest - The HttpRequest values.
      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

      public static org.sentrysoftware.ssh.SshClient createSshClientInstance(String hostname)
      Creates a new instance of the SshClient.
      Parameters:
      hostname - The hostname.
      Returns:
      A SshClient instance.
    • 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 password
      privateKey - The private key file
      timeout - 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 MetricsHub IpmiConfiguration instance 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 the IpmiConfiguration is set.
      ipmiConfiguration - The MetricsHub IpmiConfiguration instance 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 (null for localhost)
      winRmConfiguration - WinRM Protocol configuration (credentials, timeout)
      query - The query to execute
      namespace - 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 (null for 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)