use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class JmsNorthBounderTest method testForwardAlarms.
/**
* This tests forwarding of 7 alarms, one for each OpenNMS severity to
* verify the LOG_LEVEL agrees with the Severity based on our algorithm.
*
* @throws Exception the exception
*/
@Test
public void testForwardAlarms() throws Exception {
String xml = generateConfigXml();
Resource resource = new ByteArrayResource(xml.getBytes());
JmsNorthbounderConfigDao dao = new JmsNorthbounderConfigDao();
dao.setConfigResource(resource);
dao.afterPropertiesSet();
JmsNorthbounderConfig config = dao.getConfig();
List<JmsDestination> destinations = config.getDestinations();
List<JmsNorthbounder> nbis = new LinkedList<>();
for (JmsDestination jmsDestination : destinations) {
JmsNorthbounder nbi = new JmsNorthbounder(config, m_jmsNorthbounderConnectionFactory, jmsDestination);
nbi.afterPropertiesSet();
nbis.add(nbi);
}
int j = 7;
List<NorthboundAlarm> alarms = new LinkedList<>();
OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), NODE_LABEL);
node.setForeignSource("TestGroup");
node.setForeignId("1");
node.setId(m_nodeDao.getNextNodeId());
OnmsSnmpInterface snmpInterface = new OnmsSnmpInterface(node, 1);
snmpInterface.setId(1);
snmpInterface.setIfAlias("Connection to OpenNMS Wifi");
snmpInterface.setIfDescr("en1");
snmpInterface.setIfName("en1/0");
snmpInterface.setPhysAddr("00:00:00:00:00:01");
Set<OnmsIpInterface> ipInterfaces = new LinkedHashSet<OnmsIpInterface>(j);
InetAddress address = InetAddress.getByName("10.0.1.1");
OnmsIpInterface onmsIf = new OnmsIpInterface(address, node);
onmsIf.setSnmpInterface(snmpInterface);
onmsIf.setId(1);
onmsIf.setIfIndex(1);
onmsIf.setIpHostName(NODE_LABEL);
onmsIf.setIsSnmpPrimary(PrimaryType.PRIMARY);
ipInterfaces.add(onmsIf);
node.setIpInterfaces(ipInterfaces);
m_nodeDao.save(node);
m_nodeDao.flush();
// TX via NBIs
for (JmsNorthbounder nbi : nbis) {
for (int i = 1; i <= j; ++i) {
OnmsAlarm onmsAlarm = new OnmsAlarm();
onmsAlarm.setId(i);
onmsAlarm.setUei("uei.opennms.org/test/jmsNorthBounder");
onmsAlarm.setNode(node);
onmsAlarm.setSeverityId(i);
onmsAlarm.setIpAddr(InetAddress.getByName("127.0.0.1"));
onmsAlarm.setCounter(i);
onmsAlarm.setLogMsg("Node Down");
onmsAlarm.setX733AlarmType(NorthboundAlarm.x733AlarmType.get(i).name());
onmsAlarm.setX733ProbableCause(NorthboundAlarm.x733ProbableCause.get(i).getId());
if (i < j) {
// Do not add parameters to the last alarm for
// testing NMS-6383
OnmsEvent event = new OnmsEvent();
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "foreignSource", "fabric", "string"), new OnmsEventParameter(event, "foreignId", "space-0256012012000038", "string"), new OnmsEventParameter(event, "reason", "Aborting node scan : Agent timed out while scanning the system table", "string"), new OnmsEventParameter(event, ".1.3.6.1.4.1.2636.3.18.1.7.1.2.732", "207795895", "TimeTicks")));
onmsAlarm.setLastEvent(event);
}
NorthboundAlarm a = new NorthboundAlarm(onmsAlarm);
Assert.assertFalse(nbi.accepts(a));
onmsAlarm.setUei("uei.opennms.org/nodes/nodeDown");
a = new NorthboundAlarm(onmsAlarm);
Assert.assertTrue(nbi.accepts(a));
alarms.add(a);
}
nbi.forwardAlarms(alarms);
}
Thread.sleep(100);
// Let's become a consumer and receive the messages!
List<String> messages = new LinkedList<>();
Message m = m_template.receive("OpenNMSAlarmQueue");
while (m != null) {
Assert.assertTrue(m instanceof TextMessage);
messages.add(((TextMessage) m).getText());
m = m_template.receive("OpenNMSAlarmQueue");
}
Assert.assertTrue("Log messages sent: 7, Log messages received: " + messages.size(), 7 == messages.size());
for (String message : messages) {
System.out.println(message);
}
int i = 0;
for (String message : messages) {
Assert.assertTrue("ALARM ID:" + (i + 1), message.contains("ALARM ID:" + (i + 1) + " "));
Assert.assertTrue(message.contains("NODE:" + NODE_LABEL));
i++;
}
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class ProvisionerIT method testPopulateWithIpv6SnmpAndNodeScan.
// fail if we take more than five minutes
@Test(timeout = 300000)
@JUnitSnmpAgents({ @JUnitSnmpAgent(host = "10.1.15.245", resource = "classpath:/snmpwalk-demo.properties"), @JUnitSnmpAgent(host = "10.3.20.23", resource = "classpath:/snmpwalk-demo.properties"), @JUnitSnmpAgent(host = "2001:0470:e2f1:cafe:16c1:7cff:12d6:7bb9", resource = "classpath:/snmpwalk-demo.properties") })
public void testPopulateWithIpv6SnmpAndNodeScan() throws Exception {
final ForeignSource fs = new ForeignSource();
fs.setName("matt:");
fs.addDetector(new PluginConfig("SNMP", "org.opennms.netmgt.provision.detector.snmp.SnmpDetector"));
m_foreignSourceRepository.putDefaultForeignSource(fs);
importFromResource("classpath:/requisition_then_scanv6.xml", Boolean.TRUE.toString());
// Verify distpoller count
assertEquals(1, getDistPollerDao().countAll());
// Verify node count
assertEquals(1, getNodeDao().countAll());
// Verify ipinterface count
assertEquals(1, getInterfaceDao().countAll());
// Verify ifservices count
assertEquals(1, getMonitoredServiceDao().countAll());
// Verify service count
assertEquals(1, getServiceTypeDao().countAll());
// Verify snmpInterface count
assertEquals(1, getSnmpInterfaceDao().countAll());
runPendingScans();
// Verify distpoller count
assertEquals(1, getDistPollerDao().countAll());
// Verify node count
assertEquals(1, getNodeDao().countAll());
// Verify ipinterface count
assertEquals("Unexpected number of IP interfaces found: " + getInterfaceDao().findAll(), 3, getInterfaceDao().countAll());
// Verify ifservices count - discover snmp service on other if
assertEquals("Unexpected number of services found: " + getMonitoredServiceDao().findAll(), 3, getMonitoredServiceDao().countAll());
// Verify service count
assertEquals("Unexpected number of service types found: " + getServiceTypeDao().findAll(), 1, getServiceTypeDao().countAll());
// Verify snmpInterface count
assertEquals("Unexpected number of SNMP interfaces found: " + getSnmpInterfaceDao().findAll(), 6, getSnmpInterfaceDao().countAll());
// Ensure that collection is on for all ip interfaces
for (OnmsIpInterface iface : getInterfaceDao().findAll()) {
OnmsSnmpInterface snmpIface = iface.getSnmpInterface();
assertNotNull("Expected an snmp interface associated with " + iface.getIpAddress(), snmpIface);
assertTrue("Expected snmp interface associated with " + iface.getIpAddress() + " to have collection enabled.", snmpIface.isCollectionEnabled());
}
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class MatchingIpInterfacePolicy method act.
/**
* {@inheritDoc}
*/
@Override
public OnmsIpInterface act(OnmsIpInterface iface) {
OnmsSnmpInterface snmpiface = iface.getSnmpInterface();
switch(m_action) {
case DO_NOT_PERSIST:
LOG.debug("NOT Persisting {} according to policy", iface);
return null;
case MANAGE:
LOG.debug("Managing {} according to policy", iface);
iface.setIsManaged("M");
return iface;
case UNMANAGE:
LOG.debug("Unmanaging {} according to policy", iface);
iface.setIsManaged("U");
return iface;
case ENABLE_SNMP_POLL:
LOG.debug("SNMP polling {} according to policy", iface);
snmpiface.setPoll("P");
iface.setSnmpInterface(snmpiface);
return iface;
case DISABLE_SNMP_POLL:
LOG.debug("Disable SNMP polling {} according to policy", iface);
snmpiface.setPoll("N");
iface.setSnmpInterface(snmpiface);
return iface;
case DISABLE_COLLECTION:
LOG.debug("Disabled collection for {} according to policy", iface);
snmpiface.setCollectionEnabled(false);
iface.setSnmpInterface(snmpiface);
return iface;
case ENABLE_COLLECTION:
LOG.debug("Enabled collection for {} according to policy", iface);
snmpiface.setCollectionEnabled(true);
iface.setSnmpInterface(snmpiface);
return iface;
default:
return iface;
}
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class DefaultPollContext method update.
/**
* {@inheritDoc}
*/
@Override
public void update(OnmsSnmpInterface snmpinterface) {
OnmsSnmpInterface dbSnmpInterface = getSnmpInterfaceDao().findByNodeIdAndIfIndex(snmpinterface.getNode().getId(), snmpinterface.getIfIndex());
if (dbSnmpInterface == null) {
log().debug("updating SnmpInterface: no interface found on db for: " + snmpinterface.toString());
} else {
dbSnmpInterface.setIfOperStatus(snmpinterface.getIfOperStatus());
dbSnmpInterface.setIfAdminStatus(snmpinterface.getIfAdminStatus());
dbSnmpInterface.setLastSnmpPoll(snmpinterface.getLastSnmpPoll());
log().debug("updating SnmpInterface: " + dbSnmpInterface.toString());
getSnmpInterfaceDao().update(dbSnmpInterface);
}
}
use of org.opennms.netmgt.model.OnmsSnmpInterface in project opennms by OpenNMS.
the class PollableSnmpInterface method doPoll.
// end Run method
private void doPoll(SnmpPollInterfaceMonitor pollMonitor, List<SnmpMinimalPollInterface> mifaces) {
LOG.info("doPoll: input interfaces number: {}", mifaces.size());
mifaces = pollMonitor.poll(getAgentConfig(), mifaces);
boolean refresh = false;
Date now = getDate();
if (mifaces != null) {
LOG.info("doPoll: PollerMonitor return interfaces number: {}", mifaces.size());
for (SnmpMinimalPollInterface miface : mifaces) {
LOG.debug("Working on interface with ifindex: {}", miface.getIfindex());
LOG.debug("Interface PollStatus is {}", miface.getStatus().getStatusName());
if (miface.getStatus().isUp()) {
OnmsSnmpInterface iface = m_snmpinterfaces.get(Integer.valueOf(miface.getIfindex()));
LOG.debug("Previuos status Admin/Oper: {}/{}", iface.getIfAdminStatus(), iface.getIfOperStatus());
LOG.debug("Current status Admin/Oper: {}/{}", miface.getAdminstatus(), miface.getOperstatus());
// If the interface is Admin Up, and the interface is Operational Down, we generate an alarm.
if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_UP && miface.getOperstatus() == SnmpMinimalPollInterface.IF_DOWN && iface.getIfOperStatus() == SnmpMinimalPollInterface.IF_UP) {
sendOperDownEvent(iface);
}
// if was previuos down in alarm table
if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_UP && miface.getOperstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfOperStatus() == SnmpMinimalPollInterface.IF_DOWN) {
sendOperUpEvent(iface);
}
if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_DOWN && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_UP) {
sendAdminDownEvent(iface);
}
if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_DOWN && miface.getOperstatus() != SnmpMinimalPollInterface.IF_UP) {
sendAdminUpEvent(iface);
}
if (miface.getAdminstatus() == SnmpMinimalPollInterface.IF_UP && iface.getIfAdminStatus() == SnmpMinimalPollInterface.IF_DOWN && miface.getOperstatus() == SnmpMinimalPollInterface.IF_UP) {
sendAdminUpEvent(iface);
sendOperUpEvent(iface);
}
iface.setIfAdminStatus(Integer.valueOf(miface.getAdminstatus()));
iface.setIfOperStatus(Integer.valueOf(miface.getOperstatus()));
iface.setLastSnmpPoll(now);
// Save Data to Database
try {
update(iface);
} catch (Throwable e) {
LOG.warn("Failing updating Interface {} {}", iface.getIfName(), e.getLocalizedMessage());
refresh = true;
}
} else {
LOG.debug("No {} data available for interface.", getContext().getServiceName());
}
// End if status OK
}
if (refresh)
getParent().getParent().refresh(getParent().getNodeid());
} else {
LOG.error("the monitor return null object");
}
// end If not null
}
Aggregations