Search in sources :

Example 6 with WmiParams

use of org.opennms.protocols.wmi.WmiParams in project opennms by OpenNMS.

the class WmiDetector method isServiceDetected.

@Override
public boolean isServiceDetected(final InetAddress address, final WmiAgentConfig agentConfig) {
    WmiParams clientParams = null;
    if (getWmiWqlStr().equals(DEFAULT_WMI_WQL)) {
        // Create the check parameters holder.
        clientParams = new WmiParams(WmiParams.WMI_OPERATION_INSTANCEOF, getCompVal(), getCompOp(), getWmiClass(), getWmiObject());
    } else {
        // Define the WQL Query.
        clientParams = new WmiParams(WmiParams.WMI_OPERATION_WQL, getCompVal(), getCompOp(), getWmiWqlStr(), getWmiObject());
    }
    // Use WMI credentials from configuration files, and override values with the detector parameters if they exists.
    if (getUsername() != null)
        agentConfig.setUsername(getUsername());
    if (getPassword() != null)
        agentConfig.setPassword(getPassword());
    if (getDomain() != null)
        agentConfig.setDomain(getDomain());
    if (getRetries() > 0)
        agentConfig.setRetries(getRetries());
    if (getTimeout() > 0)
        agentConfig.setTimeout(getTimeout());
    // Perform the operation specified in the parameters.
    WmiResult result = isServer(address, agentConfig.getUsername(), agentConfig.getPassword(), agentConfig.getDomain(), getNamespace(), getMatchType(), agentConfig.getRetries(), agentConfig.getTimeout(), clientParams);
    // Only fail on critical and unknown returns.
    return (result != null && result.getResultCode() != WmiResult.RES_STATE_CRIT && result.getResultCode() != WmiResult.RES_STATE_UNKNOWN);
}
Also used : WmiResult(org.opennms.protocols.wmi.WmiResult) WmiParams(org.opennms.protocols.wmi.WmiParams)

Aggregations

WmiParams (org.opennms.protocols.wmi.WmiParams)6 WmiException (org.opennms.protocols.wmi.WmiException)5 WmiManager (org.opennms.protocols.wmi.WmiManager)5 WmiResult (org.opennms.protocols.wmi.WmiResult)3 OnmsWbemObjectBiosStub (org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectBiosStub)2 OnmsWbemObjectSetBiosStub (org.opennms.protocols.wmi.test.stubs.OnmsWbemObjectSetBiosStub)2 OnmsWbemPropBiosStub (org.opennms.protocols.wmi.test.stubs.OnmsWbemPropBiosStub)2 OnmsWbemPropSetBiosStub (org.opennms.protocols.wmi.test.stubs.OnmsWbemPropSetBiosStub)2 OnmsWbemObjectSet (org.opennms.protocols.wmi.wbem.OnmsWbemObjectSet)2 InetAddress (java.net.InetAddress)1 TimeoutTracker (org.opennms.core.utils.TimeoutTracker)1 WmiAgentConfig (org.opennms.netmgt.config.wmi.WmiAgentConfig)1