Skip to content

Commit

Permalink
NMS-15597: Catch I/O Exceptions and add some additional information
Browse files Browse the repository at this point in the history
Catch I/O Exceptions running and tell the user which service detector and IP address was affected.
  • Loading branch information
indigo423 committed Jun 29, 2023
1 parent 33395d4 commit 3807cd2
Showing 1 changed file with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

package org.opennms.netmgt.provision.detector.snmp;

import java.io.IOException;
import java.net.InetAddress;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -104,38 +105,40 @@ public boolean isServiceDetected(final InetAddress address, final SnmpAgentConfi
//
configureAgentPTR(agentConfig);

LOG.debug("capsd: service= SNMP address={}", agentConfig);
LOG.debug("provisiond: service= SNMP address={}", agentConfig);

// Establish SNMP session with interface
//
final String hostAddress = InetAddressUtils.str(agentConfig.getAddress());
try {
LOG.debug("HostResourceSwRunMonitor.poll: SnmpAgentConfig address: {}", agentConfig);
LOG.debug("HostResourceSWRunDetector.detect: SnmpAgentConfig address: {}", agentConfig);

if (serviceName == null) {
LOG.warn("HostResourceSwRunMonitor.poll: No Service Name Defined! ");
LOG.warn("HostResourceSWRunDetector.detect: No Service Name Defined! ");
return status;
}

// This returns two maps: one of instance and service name, and one of instance and status.
Map<SnmpInstId, SnmpValue> nameResults = SnmpUtils.getOidValues(agentConfig, "HostResourceSwRunMonitor", SnmpObjId.get(getServiceNameOid()));
Map<SnmpInstId, SnmpValue> nameResults = SnmpUtils.getOidValues(agentConfig, "HostResourceSWRunDetector", SnmpObjId.get(getServiceNameOid()));

// Iterate over the list of running services
for(Entry<SnmpInstId, SnmpValue> entry : nameResults.entrySet()) {
SnmpValue value = entry.getValue();

// See if the service name is in the list of running services
if (match(serviceName, StringUtils.stripExtraQuotes(value.toString())) && !status) {
LOG.debug("poll: HostResourceSwRunMonitor poll succeeded, addr={} service name={} value={}", hostAddress, serviceName, value);
LOG.debug("HostResourceSWRunDetector succeeded, addr={} service name={} value={}", hostAddress, serviceName, value);
status = true;
break;
}
}

} catch (NumberFormatException e) {
LOG.warn("Number operator used on a non-number {}", e.getMessage());
} catch (IllegalArgumentException e) {
LOG.warn("Invalid SNMP Criteria: {}", e.getMessage());
} catch (NumberFormatException nfe) {
LOG.warn("Number operator used on a non-number {}", nfe.getMessage());
} catch (IllegalArgumentException iae) {
LOG.warn("Invalid SNMP Criteria: {}", iae.getMessage());
} catch (IOException ioe) {
LOG.warn("I/O exception occured with error message: {}, addr={}, service name={}", ioe.getMessage(), hostAddress, serviceName);
} catch (Throwable t) {
LOG.warn("Unexpected exception during SNMP poll of interface {}", hostAddress, t);
}
Expand Down

0 comments on commit 3807cd2

Please sign in to comment.