use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class BgpSessionMonitor 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 = "";
PollStatus status = PollStatus.unavailable();
InetAddress ipaddr = svc.getAddress();
// Initialize the messages if the session is down
String adminStateMsg = "N/A";
String peerStateMsg = "N/A";
String remoteAsMsg = "N/A";
String lastErrorMsg = "N/A";
String estTimeMsg = "N/A";
// 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
//
// This should never need to be overridden, but it can be in order to be used with similar tables.
String bgpPeerIp = ParameterMap.getKeyedString(parameters, "bgpPeerIp", null);
if (bgpPeerIp == null) {
LOG.warn("poll: No BGP-Peer IP Defined! ");
return status;
}
// 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()));
//
try {
LOG.debug("poll: SnmpAgentConfig address: {}", agentConfig);
// Get the BGP peer state
SnmpObjId bgpPeerStateSnmpObject = SnmpObjId.get(BGP_PEER_STATE_OID + "." + bgpPeerIp);
SnmpValue bgpPeerState = SnmpUtils.get(agentConfig, bgpPeerStateSnmpObject);
// If no peer state is received or SNMP is not possible, service is down
if (bgpPeerState == null) {
LOG.warn("No BGP peer state received!");
return status;
} else {
LOG.debug("poll: bgpPeerState: {}", bgpPeerState);
peerStateMsg = resolvePeerState(bgpPeerState.toInt());
}
/*
* Do no unnecessary SNMP requests, if peer state is up, return with
* service available and go away.
*/
if (bgpPeerState.toInt() == BGP_PEER_STATE.ESTABLISHED.value()) {
LOG.debug("poll: bgpPeerState: {}", BGP_PEER_STATE.ESTABLISHED.name());
return PollStatus.available();
}
// Peer state is not established gather some information
SnmpObjId bgpPeerAdminStateSnmpObject = SnmpObjId.get(BGP_PEER_ADMIN_STATE_OID + "." + bgpPeerIp);
SnmpValue bgpPeerAdminState = SnmpUtils.get(agentConfig, bgpPeerAdminStateSnmpObject);
// Check correct MIB-Support
if (bgpPeerAdminState == null) {
LOG.warn("Cannot receive bgpAdminState");
} else {
LOG.debug("poll: bgpPeerAdminState: {}", bgpPeerAdminState);
adminStateMsg = resolveAdminState(bgpPeerAdminState.toInt());
}
SnmpObjId bgpPeerRemoteAsSnmpObject = SnmpObjId.get(BGP_PEER_REMOTEAS_OID + "." + bgpPeerIp);
SnmpValue bgpPeerRemoteAs = SnmpUtils.get(agentConfig, bgpPeerRemoteAsSnmpObject);
// Check correct MIB-Support
if (bgpPeerRemoteAs == null) {
LOG.warn("Cannot receive bgpPeerRemoteAs");
} else {
LOG.debug("poll: bgpPeerRemoteAs: {}", bgpPeerRemoteAs);
remoteAsMsg = bgpPeerRemoteAs.toString();
}
SnmpObjId bgpPeerLastErrorSnmpObject = SnmpObjId.get(BGP_PEER_LAST_ERROR_OID + "." + bgpPeerIp);
SnmpValue bgpPeerLastError = SnmpUtils.get(agentConfig, bgpPeerLastErrorSnmpObject);
// Check correct MIB-Support
if (bgpPeerLastError == null) {
LOG.warn("Cannot receive bgpPeerLastError");
} else {
LOG.debug("poll: bgpPeerLastError: {}", bgpPeerLastError);
lastErrorMsg = resolveBgpErrorCode(bgpPeerLastError.toHexString());
}
SnmpObjId bgpPeerFsmEstTimeSnmpObject = SnmpObjId.get(BGP_PEER_FSM_EST_TIME_OID + "." + bgpPeerIp);
SnmpValue bgpPeerFsmEstTime = SnmpUtils.get(agentConfig, bgpPeerFsmEstTimeSnmpObject);
// Check correct MIB-Support
if (bgpPeerFsmEstTime == null) {
LOG.warn("Cannot receive bgpPeerFsmEstTime");
} else {
LOG.debug("poll: bgpPeerFsmEsmTime: {}", bgpPeerFsmEstTime);
estTimeMsg = bgpPeerFsmEstTime.toString();
}
returnValue = "BGP Session state to AS-" + remoteAsMsg + " via " + bgpPeerIp + " is " + peerStateMsg + "! Last peer " + "error message is " + lastErrorMsg + ". BGP admin state is " + adminStateMsg + ". BGP Session established time: " + estTimeMsg;
// Set service down and return gathered information
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.SnmpObjId 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.SnmpObjId 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);
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class LogMatchTableMonitor 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("PrTableMonitor.poll: SnmpAgentConfig address: {}", agentConfig);
SnmpObjId lmTableErrorSnmpObject = SnmpObjId.get(lmTableErrorFlag);
Map<SnmpInstId, SnmpValue> flagResults = SnmpUtils.getOidValues(agentConfig, "LogMatchTableMonitor", lmTableErrorSnmpObject);
if (flagResults.size() == 0) {
LOG.debug("SNMP poll failed: no results, addr={} oid={}", hostAddress, lmTableErrorSnmpObject);
return PollStatus.unavailable();
}
for (Map.Entry<SnmpInstId, SnmpValue> e : flagResults.entrySet()) {
LOG.debug("poll: SNMPwalk poll succeeded, addr={} oid={} instance={} value={}", hostAddress, lmTableErrorSnmpObject, e.getKey(), e.getValue());
if (e.getValue().toString().equals("1")) {
LOG.debug("LogMatchTableMonitor.poll: found errorFlag=1");
SnmpObjId lmTableFilenameSnmpObject = SnmpObjId.get(lmTableFileName + "." + e.getKey().toString());
SnmpObjId lmTableRegExSnmpObject = SnmpObjId.get(lmTableRegEx + "." + e.getKey().toString());
SnmpObjId lmTableCountSnmpObject = SnmpObjId.get(lmTableCount + "." + e.getKey().toString());
String lmErrorMsg = "Rexeg " + SnmpUtils.get(agentConfig, lmTableRegExSnmpObject).toDisplayString() + ", for log file " + SnmpUtils.get(agentConfig, lmTableFilenameSnmpObject).toDisplayString() + " has matched " + SnmpUtils.get(agentConfig, lmTableCountSnmpObject).toDisplayString() + "time(s).";
// Stash the error in an ArrayList to then enumerate over later
errorStringReturn.add(lmErrorMsg);
}
}
// 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 " + e.getMessage();
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;
LOG.warn(reason1, t);
return PollStatus.unavailable(reason1);
}
}
use of org.opennms.netmgt.snmp.SnmpObjId in project opennms by OpenNMS.
the class NetScalerGroupHealthMonitor method poll.
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
InetAddress ipaddr = svc.getAddress();
final SnmpAgentConfig agentConfig = getAgentConfig(svc, parameters);
final String hostAddress = InetAddressUtils.str(ipaddr);
PollStatus status = PollStatus.unavailable("NetScalerGroupHealthMonitor: cannot determinate group health, addr=" + hostAddress);
int groupHealth = ParameterMap.getKeyedInteger(parameters, "group-health", 60);
String groupName = ParameterMap.getKeyedString(parameters, "group-name", null);
if (groupName == null) {
status.setReason("NetScalerGroupHealthMonitor no group-name defined, addr=" + hostAddress);
LOG.warn("NetScalerGroupHealthMonitor.poll: No Service Name Defined!");
return status;
}
int snLength = groupName.length();
final StringBuilder serviceOidBuf = new StringBuilder(SVC_GRP_MEMBER_STATE);
serviceOidBuf.append(".").append(Integer.toString(snLength));
for (byte thisByte : groupName.getBytes()) {
serviceOidBuf.append(".").append(Byte.toString(thisByte));
}
LOG.debug("For group name '{}', OID to check is {}", groupName, serviceOidBuf.toString());
try {
final SnmpObjId groupStateOid = SnmpObjId.get(serviceOidBuf.toString());
final Map<SnmpInstId, SnmpValue> hostResults = new HashMap<SnmpInstId, SnmpValue>();
RowCallback callback = new RowCallback() {
@Override
public void rowCompleted(SnmpRowResult result) {
hostResults.put(result.getInstance(), result.getValue(groupStateOid));
}
};
TableTracker tracker = new TableTracker(callback, groupStateOid);
try (SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "NetScalerGroupHealthMonitor", tracker)) {
walker.start();
walker.waitFor();
}
int totalServers = hostResults.size();
if (totalServers == 0) {
status = PollStatus.unavailable("NetScalerGroupHealthMonitor poll failed: there are 0 servers on group " + groupName + " for " + hostAddress);
LOG.debug(status.getReason());
}
int activeServers = 0;
for (SnmpValue v : hostResults.values()) {
if (v.toInt() == 7) {
activeServers++;
}
}
double health = (new Double(activeServers) / new Double(totalServers)) * 100.0;
LOG.debug("There are {} of {} active servers ({}%) on group {} for NetScaler {}", activeServers, totalServers, health, groupName, hostAddress);
if (health >= groupHealth) {
status = PollStatus.available();
} else {
status = PollStatus.unavailable("NetScalerGroupHealthMonitor poll failed: there are " + activeServers + " of " + totalServers + " servers active (" + health + "%) on group " + groupName + ", which is less than " + groupHealth + "% for " + hostAddress);
LOG.debug(status.getReason());
}
} catch (Throwable t) {
status = PollStatus.unavailable("Unexpected exception during SNMP poll of interface " + hostAddress);
LOG.warn(status.getReason(), t);
}
return status;
}
Aggregations