use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class SnmpPeerFactoryTest method testGetV2cConfigWithoutLocation.
public void testGetV2cConfigWithoutLocation() throws UnknownHostException {
SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("192.167.0.50"), "Default");
assertNotNull(agentConfig);
assertEquals(agentConfig.getVersion(), SnmpAgentConfig.VERSION2C);
assertEquals("rangev2", agentConfig.getReadCommunity());
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class ManageSnmpIntfServlet method doPost.
/** {@inheritDoc} */
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
HttpSession userSession = request.getSession(false);
if (userSession == null)
throw new ServletException("Session exceeded");
String nodeIdString = request.getParameter("node");
if (nodeIdString == null) {
throw new org.opennms.web.servlet.MissingParameterException("node");
}
int nodeId = WebSecurityUtils.safeParseInt(nodeIdString);
String intfIdString = request.getParameter("intf");
if (intfIdString == null) {
throw new org.opennms.web.servlet.MissingParameterException("intf");
}
int intfId = WebSecurityUtils.safeParseInt(intfIdString);
String statusString = request.getParameter("status");
if (statusString == null) {
throw new org.opennms.web.servlet.MissingParameterException("status");
}
int status = WebSecurityUtils.safeParseInt(statusString);
LOG.debug("ManageSnmpIntfServlet.doPost: parameters - node {} intf {} status {}", nodeId, intfId, status);
String snmpIp = null;
Service[] snmpServices = null;
try {
snmpServices = NetworkElementFactory.getInstance(getServletContext()).getServicesOnNode(nodeId, this.snmpServiceId);
if (snmpServices != null && snmpServices.length > 0) {
List<InetAddress> ips = new ArrayList<InetAddress>();
for (int i = 0; i < snmpServices.length; i++) {
ips.add(InetAddressUtils.addr(snmpServices[i].getIpAddress()));
}
InetAddress lowest = InetAddressUtils.getLowestInetAddress(ips);
if (lowest != null) {
snmpIp = InetAddressUtils.str(lowest);
}
}
InetAddress[] inetAddress = InetAddress.getAllByName(snmpIp);
SnmpAgentConfig agent = SnmpPeerFactory.getInstance().getAgentConfig(inetAddress[0]);
LOG.debug("ManageSnmpIntfServlet.doPost: agent SNMP version/write community {}/{}", agent.getVersion(), agent.getWriteCommunity());
SnmpIfAdmin snmpIfAdmin = new SnmpIfAdmin(nodeId, agent);
if (snmpIfAdmin.setIfAdmin(intfId, status)) {
LOG.debug("ManageSnmpIntfServlet.doPost: snmpIAdmin return OK ");
} else {
LOG.debug("ManageSnmpIntfServlet.doPost: snmpIAdmin return error ");
}
redirect(request, response);
} catch (SQLException e) {
throw new ServletException(e);
} catch (UnknownHostException e) {
throw new ServletException(e);
} catch (IOException e) {
throw new ServletException(e);
}
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class OmsaStorageMonitor method configureAgent.
private SnmpAgentConfig configureAgent(MonitoredService svc, Map<String, Object> parameters) {
// Retrieve this interface's SNMP peer object
//
final SnmpAgentConfig agentConfig = getAgentConfig(svc, parameters);
LOG.debug("poll: setting SNMP peer attribute for interface {}", InetAddressUtils.str(svc.getAddress()));
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()));
return agentConfig;
}
use of org.opennms.netmgt.snmp.SnmpAgentConfig in project opennms by OpenNMS.
the class OmsaStorageMonitor method poll.
/** {@inheritDoc} */
@Override
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
PollStatus status = PollStatus.available();
InetAddress ipaddr = svc.getAddress();
final StringBuffer returnValue = new StringBuffer();
SnmpAgentConfig agentConfig = configureAgent(svc, parameters);
Integer virtualDiskNumber = ParameterMap.getKeyedInteger(parameters, "virtualDiskNumber", 1);
LOG.debug("poll: service= SNMP address= {}", agentConfig);
final String hostAddress = InetAddressUtils.str(ipaddr);
try {
LOG.debug("OMSAStorageMonitor.poll: SnmpAgentConfig address: {}", agentConfig);
SnmpObjId virtualDiskRollUpStatusSnmpObject = SnmpObjId.get(virtualDiskRollUpStatus + "." + virtualDiskNumber);
SnmpValue virtualDiskRollUpStatus = SnmpUtils.get(agentConfig, virtualDiskRollUpStatusSnmpObject);
if (virtualDiskRollUpStatus == null || virtualDiskRollUpStatus.isNull()) {
LOG.debug("SNMP poll failed: no results, addr={} oid={}", hostAddress, virtualDiskRollUpStatusSnmpObject);
return PollStatus.unavailable();
}
if (virtualDiskRollUpStatus.toInt() != 3) {
// array or one of its components is not happy lets find out which
// XXX should degraded be the virtualDiskState ?
returnValue.append("log vol(").append(virtualDiskNumber).append(") degraded");
SnmpObjId arrayDiskLogicalConnectionVirtualDiskNumberSnmpObject = SnmpObjId.get(arrayDiskLogicalConnectionVirtualDiskNumber);
Map<SnmpInstId, SnmpValue> arrayDisks = SnmpUtils.getOidValues(agentConfig, "OMSAStorageMonitor", arrayDiskLogicalConnectionVirtualDiskNumberSnmpObject);
SnmpObjId arrayDiskLogicalConnectionArrayDiskNumberSnmpObject = SnmpObjId.get(arrayDiskLogicalConnectionArrayDiskNumber);
Map<SnmpInstId, SnmpValue> arrayDiskConnectionNumber = SnmpUtils.getOidValues(agentConfig, "OMSAStorageMonitor", arrayDiskLogicalConnectionArrayDiskNumberSnmpObject);
for (Map.Entry<SnmpInstId, SnmpValue> disk : arrayDisks.entrySet()) {
LOG.debug("OMSAStorageMonitor :: arrayDiskNembers=", disk.getValue());
if (disk.getValue().toInt() == virtualDiskNumber) {
LOG.debug("OMSAStorageMonitor :: Disk Found! ");
LOG.debug("OMSAStorageMonitor :: Found This Array Disk Value {}", disk.getKey());
SnmpObjId arrayDiskStateSnmpObject = SnmpObjId.get(arrayDiskState + "." + arrayDiskConnectionNumber.get(disk.getKey()));
SnmpValue diskValue = SnmpUtils.get(agentConfig, arrayDiskStateSnmpObject);
LOG.debug("OmsaStorageMonitor :: Disk State=", diskValue);
if (diskValue.toInt() != 3) {
String arrayDiskState = getArrayDiskStatus(diskValue);
SnmpObjId arrayDiskNexusIDSnmpObject = SnmpObjId.get(arrayDiskNexusID + "." + disk.getKey().toString());
SnmpValue nexusValue = SnmpUtils.get(agentConfig, arrayDiskNexusIDSnmpObject);
returnValue.append(" phy drv(").append(nexusValue).append(") ").append(arrayDiskState);
}
}
}
return PollStatus.unavailable(returnValue.toString());
}
} 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.SnmpAgentConfig in project opennms by OpenNMS.
the class OpenManageChassisMonitor 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 eventLogStatusTxt = "N/A";
String manufacturerName = "N/A";
String modelName = "N/A";
String serviceTagTxt = "N/A";
String chassisStatusTxt = "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);
// 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 chassis status
SnmpObjId chassisStatusSnmpObject = SnmpObjId.get(CHASSIS_STATUS_OID);
SnmpValue chassisStatus = SnmpUtils.get(agentConfig, chassisStatusSnmpObject);
// service is down
if (chassisStatus == null) {
LOG.warn("No chassis status received!");
return status;
} else {
LOG.debug("poll: chassis status: {}", chassisStatus);
}
/*
* Do no unnecessary SNMP requests, if chassis status is OK,
* return with service available and go away.
*/
if (chassisStatus.toInt() == DELL_STATUS.OK.value()) {
LOG.debug("poll: chassis status: {}", chassisStatus.toInt());
return PollStatus.available();
} else {
LOG.debug("poll: chassis status: {}", chassisStatus.toInt());
chassisStatusTxt = resolveDellStatus(chassisStatus.toInt());
}
// Chassis status is not OK gather some information
SnmpObjId eventLogStatusSnmpObject = SnmpObjId.get(EVENT_LOG_STATUS_OID);
SnmpValue eventLogStatus = SnmpUtils.get(agentConfig, eventLogStatusSnmpObject);
// Check correct MIB-Support
if (eventLogStatus == null) {
LOG.warn("Cannot receive eventLogStatus.");
} else {
LOG.debug("poll: eventLogStatus: {}", eventLogStatus);
eventLogStatusTxt = resolveDellStatus(eventLogStatus.toInt());
}
SnmpObjId manufacturerSnmpObject = SnmpObjId.get(MANUFACTURER_OID);
SnmpValue manufacturer = SnmpUtils.get(agentConfig, manufacturerSnmpObject);
// Check correct MIB-Support
if (manufacturer == null) {
LOG.warn("Cannot receive manufacturer.");
} else {
LOG.debug("poll: manufacturer: {}", manufacturer);
manufacturerName = manufacturer.toString();
}
SnmpObjId modelSnmpObject = SnmpObjId.get(MODEL_NAME_OID);
SnmpValue model = SnmpUtils.get(agentConfig, modelSnmpObject);
// Check correct MIB-Support
if (model == null) {
LOG.warn("Cannot receive model name.");
} else {
LOG.debug("poll: model name: {}", model);
modelName = model.toString();
}
SnmpObjId serviceTagSnmpObject = SnmpObjId.get(SERVICE_TAG_OID);
SnmpValue serviceTag = SnmpUtils.get(agentConfig, serviceTagSnmpObject);
// Check correct MIB-Support
if (serviceTag == null) {
LOG.warn("Cannot receive service tag");
} else {
LOG.debug("poll: service tag: {}", serviceTag);
serviceTagTxt = serviceTag.toString();
}
returnValue = "Chassis status from " + manufacturerName + " " + modelName + " with service tag " + serviceTagTxt + " is " + chassisStatusTxt + ". Last event log status is " + eventLogStatusTxt + ". For further information, check your OpenManage website!";
// 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;
}
Aggregations