use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class ScanManager method updateSnmpData.
void updateSnmpData(final OnmsNode node) {
try {
m_systemGroup = new SystemGroup(m_address);
final Set<SnmpInstId> ipAddrs = new TreeSet<>();
final Set<InetAddress> ipAddresses = new HashSet<>();
for (final OnmsIpInterface iface : node.getIpInterfaces()) {
final InetAddress addr = iface.getIpAddress();
if (addr != null && addr instanceof Inet4Address) {
ipAddrs.add(new SnmpInstId(InetAddressUtils.toOid(addr)));
}
ipAddresses.add(addr);
}
m_ipAddrTable = new IpAddrTable(m_address, ipAddrs);
m_ipAddressTable = IpAddressTable.createTable(m_address, ipAddresses);
AggregateTracker tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ipAddrTable, m_ipAddressTable));
final SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(m_address, MonitoringLocationUtils.getLocationNameOrNullIfDefault(node));
try {
m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("system/ipAddrTable/ipAddressTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
} catch (ExecutionException e) {
// pass
}
final Set<SnmpInstId> ifIndices = new TreeSet<>();
for (final Integer ifIndex : m_ipAddrTable.getIfIndices()) {
ifIndices.add(new SnmpInstId(ifIndex));
}
m_ifTable = new IfTable(m_address, ifIndices);
m_ifXTable = new IfXTable(m_address, ifIndices);
tracker = new AggregateTracker(Lists.newArrayList(m_systemGroup, m_ifTable, m_ifXTable));
try {
m_locationAwareSnmpClient.walk(agentConfig, tracker).withDescription("ifTable/ifXTable").withLocation(node.getLocation() == null ? null : node.getLocation().getLocationName()).execute().get();
} catch (ExecutionException e) {
// pass
}
m_systemGroup.updateSnmpDataForNode(node);
for (final SnmpInstId ifIndex : ifIndices) {
m_ifTable.updateSnmpInterfaceData(node, ifIndex.toInt());
}
for (final SnmpInstId ifIndex : ifIndices) {
m_ifXTable.updateSnmpInterfaceData(node, ifIndex.toInt());
}
for (final SnmpInstId ipAddr : ipAddrs) {
m_ipAddrTable.updateIpInterfaceData(node, ipAddr.toString());
}
for (final InetAddress addr : ipAddresses) {
m_ipAddressTable.updateIpInterfaceData(node, InetAddressUtils.str(addr));
}
} catch (final InterruptedException e) {
LOG.info("thread interrupted while updating SNMP data", e);
Thread.currentThread().interrupt();
}
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class TcaProtocolCollector method collect.
@Override
public CollectionJob collect(final CollectionJob collectionJob) {
logger.info("TcaProtocolCollector is collecting collectionJob '{}'", collectionJob);
SnmpAgentConfig snmpAgentConfig = SnmpAgentConfig.parseProtocolConfigurationString(collectionJob.getProtocolConfiguration());
List<Collectable> trackers = new ArrayList<>();
for (final String metricObjId : collectionJob.getAllMetrics()) {
final String keyword = metricObjId.substring(metricObjId.lastIndexOf("_") + 1);
final SnmpObjId requestOid = SnmpObjId.get(metricObjId.substring(0, metricObjId.lastIndexOf("_")));
SnmpObjId base = requestOid.getPrefix(requestOid.length() - 1);
int lastId = requestOid.getLastSubId();
SingleInstanceTracker instanceTracker = new SingleInstanceTracker(base, new SnmpInstId(lastId)) {
@Override
protected void storeResult(SnmpResult result) {
logger.trace("Collected SnmpValue '{}'", result);
SnmpValue value = result.getValue();
String compositeResult = getCompositeValue(keyword, value.toDisplayString());
collectionJob.setMetricValue(metricObjId, "int32", compositeResult);
}
@Override
public void setFailed(boolean failed) {
super.setFailed(failed);
logger.trace("Collection Failed for metricObjId '{}'", metricObjId);
collectionJob.setMetricValue(metricObjId, "unknown", null);
}
@Override
public void setTimedOut(boolean timedOut) {
super.setTimedOut(timedOut);
logger.trace("Collection timedOut for metricObjId '{}'", metricObjId);
collectionJob.setMetricValue(metricObjId, "unknown", null);
}
};
trackers.add(instanceTracker);
}
CollectionTracker tracker = new AggregateTracker(trackers);
try (SnmpWalker walker = m_snmpStrategy.createWalker(snmpAgentConfig, "SnmpProtocolCollector for " + snmpAgentConfig.getAddress(), tracker)) {
walker.start();
try {
walker.waitFor();
} catch (InterruptedException e) {
logger.error("Interuppted while waiting for collector. Results may be incomplete.", e);
}
}
return collectionJob;
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class CiscoIpSlaMonitor method poll.
/**
* {@inheritDoc}
*
* <P>
* The poll() method is responsible for polling the specified address for
* SNMP service availability.
* </P>
* @exception RuntimeException
* Thrown for any uncrecoverable errors.
*/
@Override
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
String returnValue = "SNMP request failed or Cisco IP SLA tag ";
boolean monitorThresh = false;
PollStatus status = PollStatus.unavailable();
InetAddress ipaddr = svc.getAddress();
// Retrieve this interface's SNMP peer object
//
final SnmpAgentConfig agentConfig = getAgentConfig(svc, parameters);
final String hostAddress = InetAddressUtils.str(ipaddr);
LOG.debug("poll: setting SNMP peer attribute for interface {}", hostAddress);
// Get configuration parameters for tag to monitor
String adminTag = ParameterMap.getKeyedString(parameters, "admin-tag", null);
if (adminTag == null) {
LOG.debug("No IP SLA admin-tag parameter defined! ");
status = PollStatus.unavailable("No IP SLA admin-tag parameter defined! ");
return status;
}
// If no ip sla tag found, tell which ip sla tag is configured
returnValue += adminTag + " not found";
// Get configuration parameter to check if threshold should monitor
String ignoreThreshold = ParameterMap.getKeyedString(parameters, "ignore-thresh", null);
if (ignoreThreshold == null) {
LOG.debug("No ignoreThreshold parmater defined! ");
status = PollStatus.unavailable("No ignoreThreshold parmater defined! ");
return status;
}
// Convert threshold parameter to boolean
if (ignoreThreshold.equals("false")) {
monitorThresh = true;
}
// set timeout and retries on SNMP peer object
//
agentConfig.setTimeout(ParameterMap.getKeyedInteger(parameters, "timeout", agentConfig.getTimeout()));
agentConfig.setRetries(ParameterMap.getKeyedInteger(parameters, "retry", ParameterMap.getKeyedInteger(parameters, "retries", agentConfig.getRetries())));
agentConfig.setPort(ParameterMap.getKeyedInteger(parameters, "port", agentConfig.getPort()));
// Establish SNMP session with interface
try {
LOG.debug("poll: SnmpAgentConfig address: {}", agentConfig);
// Get all configured ip sla tags
Map<SnmpInstId, SnmpValue> tagResults = SnmpUtils.getOidValues(agentConfig, "CiscoIpSlaMonitor", SnmpObjId.get(RTT_ADMIN_TAG_OID));
if (tagResults == null) {
LOG.debug("No admin tags received! ");
status = PollStatus.unavailable("No admin tags received! ");
return status;
}
// Iterate over the list of configured IP SLAs
for (SnmpInstId ipslaInstance : tagResults.keySet()) {
// Check if a given IP-SLA with the specific "tag" exist
if (tagResults.get(ipslaInstance).toString().equals(adminTag)) {
// Get all operation sense
Map<SnmpInstId, SnmpValue> operSenseResults = SnmpUtils.getOidValues(agentConfig, "CiscoIpSlaMonitor", SnmpObjId.get(RTT_LATEST_OPERSENSE_OID));
if (operSenseResults == null) {
LOG.debug("No latest oper sense received! ");
status = PollStatus.unavailable("No latest oper sense received! ");
return status;
}
// Get all operation states
Map<SnmpInstId, SnmpValue> operStateResults = SnmpUtils.getOidValues(agentConfig, "CiscoIpSlaMonitor", SnmpObjId.get(RTT_OPER_STATE_OID));
if (operStateResults == null) {
LOG.debug("No oper state received! ");
status = PollStatus.unavailable("No oper state received! ");
return status;
}
// Get all configured ip sla types
Map<SnmpInstId, SnmpValue> adminTypeResults = SnmpUtils.getOidValues(agentConfig, "CiscoIpSlaMonitor", SnmpObjId.get(RTT_ADMIN_TYPE_OID));
if (adminTypeResults == null) {
LOG.debug("No ip sla types received! ");
status = PollStatus.unavailable("No ip sla types received! ");
return status;
}
// Get all configured ip sla latest RTT
Map<SnmpInstId, SnmpValue> latestRttResults = SnmpUtils.getOidValues(agentConfig, "CiscoIpSlaMonitor", SnmpObjId.get(RTT_LATEST_OID));
if (latestRttResults == null) {
LOG.debug("No ip sla latest RTT received! ");
status = PollStatus.unavailable("No ip sla latest RTT received! ");
return status;
}
LOG.debug("poll: instance={} admin tag={} value={} oper state={} ignoreThreshold={} latest RTT{}", ipslaInstance.toInt(), adminTag, tagResults.get(ipslaInstance), operStateResults.get(ipslaInstance), ignoreThreshold, latestRttResults.get(ipslaInstance));
// Build return value for service down
returnValue = "Cisco IP SLA tag " + adminTag + " with oper state " + resolveOperSate(operStateResults.get(ipslaInstance).toInt()) + " returned with oper sense " + resolveOperSense(operSenseResults.get(ipslaInstance).toInt()) + ". Configured IP SLA type is " + resolveAdminType(adminTypeResults.get(ipslaInstance).toInt()) + ". Latest RTT is " + latestRttResults.get(ipslaInstance);
LOG.debug(returnValue);
// Check if thresholding is relevant
if (monitorThresh && (operSenseResults.get(ipslaInstance).toInt() == RTT_MON_OPER_SENSE.OVER_THRESHOLD.value())) {
// Get all configured ip sla thresholds
Map<SnmpInstId, SnmpValue> threshResults = SnmpUtils.getOidValues(agentConfig, "CiscoIpSlaMonitor", SnmpObjId.get(RTT_ADMIN_THRESH_OID));
if (monitorThresh && threshResults == null) {
LOG.debug("No ip sla thresholds received! ");
status = PollStatus.unavailable("No ip sla thresholds received! ");
return status;
}
// Threshold monitoring
LOG.debug("IP SLA: {} threshold exceeded.", tagResults.get(ipslaInstance));
returnValue += ". Monitoring threshold is enabled. Threshold value is " + threshResults.get(ipslaInstance);
// Configured threshold is exceeded, service unavailable
return PollStatus.unavailable(returnValue);
} else {
/*
* Threshold should be ignored, check if OK or
* OVER_THRESHOLD.
* Over threshold means also OK, no timeout or other
* error occurred.
*/
if (operSenseResults.get(ipslaInstance).toInt() == RTT_MON_OPER_SENSE.OK.value() || operSenseResults.get(ipslaInstance).toInt() == RTT_MON_OPER_SENSE.OVER_THRESHOLD.value()) {
LOG.debug("Threshold is ignored rttMonLatestOperSense: {}", operSenseResults.get(ipslaInstance).toInt());
LOG.debug(returnValue);
status = PollStatus.available(Double.parseDouble(latestRttResults.get(ipslaInstance).toString()));
// No error or connection timeout, service available
return status;
}
}
}
// else no configured IP SLA tag exist
}
// Otherwise set service down
status = PollStatus.unavailable(returnValue);
} catch (NullPointerException e) {
String reason = "Unexpected error during SNMP poll of interface " + hostAddress;
LOG.debug(reason, e);
status = PollStatus.unavailable(reason);
} catch (NumberFormatException e) {
String reason = "Number operator used on a non-number " + e.getMessage();
LOG.debug(reason);
status = PollStatus.unavailable(reason);
} catch (IllegalArgumentException e) {
String reason = "Invalid SNMP Criteria: " + e.getMessage();
LOG.debug(reason);
status = PollStatus.unavailable(reason);
} catch (Throwable t) {
String reason = "Unexpected exception during SNMP poll of interface " + hostAddress;
LOG.debug(reason, t);
status = PollStatus.unavailable(reason);
}
// Otherwise, the service will be unavailable.
return status;
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class DiskUsageMonitor method poll.
/**
* {@inheritDoc}
*
* The poll() method is responsible for polling the specified address for
* SNMP service availability.
*
* @param svc
* @param parameters
* @return PollStatus
* <p>
* @exception RuntimeException
* Thrown for any unrecoverable errors.
*/
@Override
public PollStatus poll(final MonitoredService svc, final Map<String, Object> parameters) {
MatchType matchType = MatchType.EXACT;
RequireType reqType = RequireType.ALL;
PollStatus status = PollStatus.available();
InetAddress ipaddr = svc.getAddress();
// Retrieve this interface's SNMP peer object
//
final SnmpAgentConfig agentConfig = getAgentConfig(svc, parameters);
final String hostAddress = InetAddressUtils.str(ipaddr);
LOG.debug("poll: setting SNMP peer attribute for interface {}", hostAddress);
agentConfig.setTimeout(ParameterMap.getKeyedInteger(parameters, "timeout", agentConfig.getTimeout()));
agentConfig.setRetries(ParameterMap.getKeyedInteger(parameters, "retry", ParameterMap.getKeyedInteger(parameters, "retries", agentConfig.getRetries())));
agentConfig.setPort(ParameterMap.getKeyedInteger(parameters, "port", agentConfig.getPort()));
String diskNamePattern = ParameterMap.getKeyedString(parameters, "disk", null);
if (diskNamePattern == null) {
throw new RuntimeException("Invalid null value for parameter 'disk'");
}
Integer percentFree = ParameterMap.getKeyedInteger(parameters, "free", 15);
String matchTypeStr = ParameterMap.getKeyedString(parameters, "match-type", "exact");
try {
matchType = MatchType.valueOf(matchTypeStr.toUpperCase());
} catch (IllegalArgumentException e) {
throw new RuntimeException("Unknown value '" + matchTypeStr + "' for parameter 'match-type'");
}
String reqTypeStr = ParameterMap.getKeyedString(parameters, "require-type", "all");
try {
reqType = RequireType.valueOf(reqTypeStr.toUpperCase());
} catch (IllegalArgumentException e) {
throw new RuntimeException("Unknown value '" + reqTypeStr + "' for parameter 'require-type'");
}
LOG.debug("poll: diskNamePattern={}", diskNamePattern);
LOG.debug("poll: percentfree={}", percentFree);
LOG.debug("poll: matchType={}", matchTypeStr);
LOG.debug("poll: reqType={}", reqTypeStr);
LOG.debug("poll: service={} address={}", svc, agentConfig);
try {
LOG.debug("poll: SnmpAgentConfig address: {}", agentConfig);
SnmpObjId hrStorageDescrSnmpObject = SnmpObjId.get(hrStorageDescr);
Map<SnmpInstId, SnmpValue> results = SnmpUtils.getOidValues(agentConfig, "DiskUsagePoller", hrStorageDescrSnmpObject);
if (results.isEmpty()) {
LOG.debug("SNMP poll failed: no results, addr={} oid={}", hostAddress, hrStorageDescrSnmpObject);
return PollStatus.unavailable("No entries found in hrStorageDescr");
}
boolean foundDisk = false;
for (Map.Entry<SnmpInstId, SnmpValue> e : results.entrySet()) {
LOG.debug("poll: SNMPwalk poll succeeded, addr={} oid={} instance={} value={}", hostAddress, hrStorageDescrSnmpObject, e.getKey(), e.getValue());
final String snmpInstance = e.getKey().toString();
final String diskName = e.getValue().toString();
if (isMatch(diskName, diskNamePattern, matchType)) {
LOG.debug("poll: found disk={}", diskName);
final SnmpObjId hrStorageSizeSnmpObject = SnmpObjId.get(hrStorageSize, snmpInstance);
final SnmpObjId hrStorageUsedSnmpObject = SnmpObjId.get(hrStorageUsed, snmpInstance);
final SnmpValue snmpSize = SnmpUtils.get(agentConfig, hrStorageSizeSnmpObject);
final SnmpValue snmpUsed = SnmpUtils.get(agentConfig, hrStorageUsedSnmpObject);
float calculatedPercentage = ((((float) snmpSize.toLong() - (float) snmpUsed.toLong()) / (float) snmpSize.toLong())) * 100;
LOG.debug("poll: calculatedPercentage={} percentFree={}", calculatedPercentage, percentFree);
if (calculatedPercentage < percentFree) {
return PollStatus.unavailable(diskName + " usage high (" + (100 - (int) calculatedPercentage) + "%)");
} else {
if (matchType == MatchType.EXACT || reqType == RequireType.ANY) {
return status;
}
if (reqType == RequireType.ALL) {
foundDisk = true;
}
}
}
}
if (foundDisk) {
return status;
}
// if we get here.. it means we did not find the disk... which means we should not be monitoring it.
LOG.debug("poll: no disks found");
return PollStatus.unavailable("Could not find " + diskNamePattern + " in hrStorageTable");
} catch (NumberFormatException e) {
String reason = "Number operator used on a non-number " + e.getMessage();
LOG.debug(reason);
status = PollStatus.unavailable(reason);
} catch (IllegalArgumentException e) {
String reason = "Invalid SNMP Criteria: " + e.getMessage();
LOG.debug(reason);
status = PollStatus.unavailable(reason);
} catch (Throwable t) {
String reason = "Unexpected exception during SNMP poll of interface " + hostAddress;
LOG.debug(reason, t);
status = PollStatus.unavailable(reason);
}
return status;
}
use of org.opennms.netmgt.snmp.SnmpInstId in project opennms by OpenNMS.
the class DskTableMonitor method poll.
/**
* {@inheritDoc}
*
* <P>
* The poll() method is responsible for polling the specified address for
* SNMP service availability.
* </P>
* @exception RuntimeException
* Thrown for any uncrecoverable errors.
*/
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
PollStatus status = PollStatus.available();
InetAddress ipaddr = svc.getAddress();
ArrayList<String> errorStringReturn = new ArrayList<>();
// Retrieve this interface's SNMP peer object
final SnmpAgentConfig agentConfig = getAgentConfig(svc, parameters);
final String hostAddress = InetAddressUtils.str(ipaddr);
LOG.debug("poll: setting SNMP peer attribute for interface {}", hostAddress);
agentConfig.setTimeout(ParameterMap.getKeyedInteger(parameters, "timeout", agentConfig.getTimeout()));
agentConfig.setRetries(ParameterMap.getKeyedInteger(parameters, "retry", ParameterMap.getKeyedInteger(parameters, "retries", agentConfig.getRetries())));
agentConfig.setPort(ParameterMap.getKeyedInteger(parameters, "port", agentConfig.getPort()));
LOG.debug("poll: service= SNMP address= {}", agentConfig);
try {
LOG.debug("DskTableMonitor.poll: SnmpAgentConfig address: {}", agentConfig);
SnmpObjId dskTableErrorSnmpObject = SnmpObjId.get(dskTableErrorFlag);
Map<SnmpInstId, SnmpValue> flagResults = SnmpUtils.getOidValues(agentConfig, "DskTableMonitor", dskTableErrorSnmpObject);
if (flagResults.size() == 0) {
LOG.debug("SNMP poll failed: no results, addr={} oid={}", hostAddress, dskTableErrorSnmpObject);
return PollStatus.unavailable();
}
for (Map.Entry<SnmpInstId, SnmpValue> e : flagResults.entrySet()) {
LOG.debug("poll: SNMPwalk poll succeeded, addr={} oid={} instance={} value={}", hostAddress, dskTableErrorSnmpObject, e.getKey(), e.getValue());
if (e.getValue().toString().equals("1")) {
LOG.debug("DskTableMonitor.poll: found errorFlag=1");
SnmpObjId dskTableErrorMsgSnmpObject = SnmpObjId.get(dskTableErrorMsg + "." + e.getKey().toString());
String DiskErrorMsg = SnmpUtils.get(agentConfig, dskTableErrorMsgSnmpObject).toDisplayString();
// Stash the error in an ArrayList to then enumerate over later
errorStringReturn.add(DiskErrorMsg);
}
}
// Check the arraylist and construct return value
if (errorStringReturn.size() > 0) {
return PollStatus.unavailable(errorStringReturn.toString());
} else {
return status;
}
} catch (NumberFormatException e) {
String reason1 = "Number operator used on a non-number";
LOG.error(reason1, e);
return PollStatus.unavailable(reason1);
} catch (IllegalArgumentException e) {
String reason1 = "Invalid SNMP Criteria: " + e.getMessage();
LOG.error(reason1, e);
return PollStatus.unavailable(reason1);
} catch (Throwable t) {
String reason1 = "Unexpected exception during SNMP poll of interface " + hostAddress + ": " + t.getMessage();
LOG.warn(reason1, t);
return PollStatus.unavailable(reason1);
}
}
Aggregations