Package org.metricshub.winrm
Class WmiHelper
java.lang.Object
org.metricshub.winrm.WmiHelper
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic StringcreateNetworkResource(String hostname, String namespace) The "network resource" is either just the namespace (for localhost), or \\hostname\\namespace.executeWqlInCimv2(WindowsRemoteExecutor windowsRemoteExecutor, String wqlQuery, long timeout) Execute one of the library's internal housekeeping WQL queries (encoding detection, Windows directory discovery) explicitly in the "ROOT\\CIMV2" namespace — where the standardWin32_*classes live — regardless of the executor's configured default namespace, which the caller may have pointed at a custom namespace.Extract the exact name of the properties from a WMI result.Extract the exact name of the properties from a WMI result.static booleanisLocalNetworkResource(String networkResource) static booleanisValidWql(String wqlQuery) Check if the WQL Query respect the simple syntax in the form ofSelect * from (where)orSelect a,b,c from (where)is valid.
-
Field Details
-
DEFAULT_NAMESPACE
- See Also:
-
-
Method Details
-
isValidWql
Check if the WQL Query respect the simple syntax in the form ofSelect * from (where)orSelect 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 standardWin32_*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 hostwqlQuery- The WQL query to runtimeout- Timeout in milliseconds- Returns:
- the query result rows
- Throws:
TimeoutException- To notify userName of timeoutWqlQuerySyntaxException- On WQL syntax errorsWindowsRemoteException- For any problem encountered on the remote host
-
createNetworkResource
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
- 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 parsedwql- 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 parsedwqlQuery- The WQL query that was used (so we make sure to return the properties in the same order)- Returns:
- a list of property names
-