use of org.opennms.netmgt.snmp.SnmpAgentConfig 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<String>();
// 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.SnmpAgentConfig in project opennms by OpenNMS.
the class PollerRequestDTOTest method getPollerRequestWithAgentConfig.
public static PollerRequestDTO getPollerRequestWithAgentConfig() throws UnknownHostException {
PollerRequestDTO dto = new PollerRequestDTO();
dto.setLocation("MINION");
dto.setClassName("org.opennms.netmgt.poller.monitors.IcmpMonitor");
dto.setAddress(InetAddress.getByName("127.0.0.1"));
dto.addAttribute("agent", new SnmpAgentConfig());
return dto;
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpTrapHelper method forwardV1Trap.
/**
* Create an SNMP V1 trap based on the content of the specified trap configuration, and send it to the appropriate destination.
*
* @param trapConfig The trap configuration mapping object
* @throws SnmpTrapException if any.
*/
private void forwardV1Trap(SnmpTrapConfig trapConfig) throws SnmpTrapException {
SnmpV1TrapBuilder trap = SnmpUtils.getV1TrapBuilder();
trap.setEnterprise(SnmpObjId.get(trapConfig.getEnterpriseId()));
trap.setAgentAddress(trapConfig.getHostAddress());
if (trapConfig.hasGeneric()) {
trap.setGeneric(trapConfig.getGeneric());
}
if (trapConfig.hasSpecific()) {
trap.setSpecific(trapConfig.getSpecific());
}
trap.setTimeStamp(System.currentTimeMillis() / 1000);
addParameters(trap, trapConfig);
try {
SnmpAgentConfig config = getAgentConfig(trapConfig);
trap.send(config.getAddress().getHostAddress(), config.getPort(), config.getReadCommunity());
} catch (Throwable e) {
throw new SnmpTrapException("Failed to send trap " + e.getMessage(), e);
}
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpTrapHelper method getAgentConfig.
/**
* Gets the SNMP agent configuration.
*
* @param trapConfig The trap configuration mapping object
* @return the SNMP agent configuration
* @throws SnmpTrapException if any.
*/
// TODO Compare the estimated size with a maximum value:
// If the estimated is lower than the maximum in X percentage, log a warning.
// Otherwise, log an error and throw an exception
private SnmpAgentConfig getAgentConfig(SnmpTrapConfig trapConfig) throws SnmpTrapException {
SnmpAgentConfig agentConfig = trapConfig.getAgentConfig();
if (trapConfig.getVersion().intValue() != agentConfig.getVersion()) {
throw new SnmpTrapException("SNMP Version mismatch for " + trapConfig);
}
int estimatedSize = getEstimatedPacketSize(trapConfig, agentConfig);
LOG.info("Sending SNMP{} using {}. The estimated packet size is {} bytes", trapConfig.getVersion().stringValue(), trapConfig, estimatedSize);
return agentConfig;
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpTrapHelper method forwardV2Inform.
/**
* Create an SNMP V2 inform based on the content of the specified trap configuration, and send it to the appropriate destination.
*
* @param trapConfig The trap configuration mapping object
* @throws SnmpTrapException if any.
*/
private void forwardV2Inform(SnmpTrapConfig trapConfig) throws SnmpTrapException {
SnmpV2TrapBuilder trap = SnmpUtils.getV2InformBuilder();
populateTrapBuilder(trap, trapConfig);
try {
SnmpAgentConfig config = getAgentConfig(trapConfig);
trap.sendInform(config.getAddress().getHostName(), config.getPort(), config.getTimeout(), config.getRetries(), config.getReadCommunity());
} catch (Throwable e) {
throw new SnmpTrapException("Failed to send trap " + e.getMessage(), e);
}
}
Aggregations