Class WmiHelper

java.lang.Object
org.metricshub.winrm.WmiHelper

public abstract class WmiHelper extends Object
  • Field Details

  • Method Details

    • isValidWql

      public static boolean isValidWql(String wqlQuery)
      Check if the WQL Query respect the simple syntax in the form of Select * from (where) or Select a,b,c from (where) is valid.
      Parameters:
      wqlQuery -
      Returns:
      whether specified WQL query's syntax is valid or not
    • executeWqlInCimv2

      public static List<Map<String,Object>> executeWqlInCimv2(WindowsRemoteExecutor windowsRemoteExecutor, String wqlQuery, long timeout) throws TimeoutException, WqlQuerySyntaxException, WindowsRemoteException
      Execute one of the library's internal housekeeping WQL queries (encoding detection, Windows directory discovery) explicitly in the "ROOT\\CIMV2" namespace — where the standard Win32_* classes live — regardless of the executor's configured default namespace, which the caller may have pointed at a custom namespace. Executors that do not support an explicit per-query namespace fall back to their default namespace, preserving the historical behavior.
      Parameters:
      windowsRemoteExecutor - Executor connected to the remote host
      wqlQuery - The WQL query to run
      timeout - Timeout in milliseconds
      Returns:
      the query result rows
      Throws:
      TimeoutException - To notify userName of timeout
      WqlQuerySyntaxException - On WQL syntax errors
      WindowsRemoteException - For any problem encountered on the remote host
    • createNetworkResource

      public static String createNetworkResource(String hostname, String namespace)
      The "network resource" is either just the namespace (for localhost), or \\hostname\\namespace.
      Parameters:
      hostname - Host to connect to.
      namespace - The Namespace.
      Returns:
      resource
    • isLocalNetworkResource

      public static boolean isLocalNetworkResource(String networkResource)
      Parameters:
      networkResource - Network resource string to test
      Returns:
      whether specified networkResource is local or not
    • extractPropertiesFromResult

      public static List<String> extractPropertiesFromResult(List<Map<String,Object>> resultRows, String wql)
      Extract the exact name of the properties from a WMI result. The interest is to retrieve the exact case of the property names, instead of the lowercase that we have at this stage.
      Parameters:
      resultRows - The result whose first row will be parsed
      wql - The WQL query that was used (so we make sure to return the properties in the same order)
      Returns:
      a list of property names
      Throws:
      IllegalStateException - if the specified WQL is invalid
    • extractPropertiesFromResult

      public static List<String> extractPropertiesFromResult(List<Map<String,Object>> resultRows, WqlQuery wqlQuery)
      Extract the exact name of the properties from a WMI result. The interest is to retrieve the exact case of the property names, instead of the lowercase that we have at this stage. Note: The exact case cannot be retrieved if result is empty, in which case all names are reported in lower case
      Parameters:
      resultRows - The result whose first row will be parsed
      wqlQuery - The WQL query that was used (so we make sure to return the properties in the same order)
      Returns:
      a list of property names