use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class EventDaoIT method testSave.
@Test
@Transactional
public void testSave() {
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventCreateTime(new Date());
event.setEventDescr("event dao test");
event.setEventHost("localhost");
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogGroup("event dao test log group");
event.setEventLogMsg("event dao test log msg");
event.setEventSeverity(7);
event.setEventSource("EventDaoTest");
event.setEventTime(new Date());
event.setEventUei("uei://org/opennms/test/EventDaoTest");
OnmsNode node = (OnmsNode) m_nodeDao.findAll().iterator().next();
OnmsIpInterface iface = (OnmsIpInterface) node.getIpInterfaces().iterator().next();
OnmsMonitoredService service = (OnmsMonitoredService) iface.getMonitoredServices().iterator().next();
event.setNode(node);
event.setServiceType(service.getServiceType());
OnmsAlarm alarm = new OnmsAlarm();
event.setAlarm(alarm);
event.setIpAddr(iface.getIpAddress());
event.setEventParms("label=node(string,text);ds=(memAvailReal + memCached) / memTotalReal * 100.0(string,text);description=(memAvailReal + memCached) / memTotalReal * 100.0(string,text);value=4.7(string,text);instance=node(string,text);instanceLabel=node(string,text);resourceId=node[70].nodeSnmp[](string,text);threshold=5.0(string,text);trigger=2(string,text);rearm=10.0(string,text)");
m_eventDao.save(event);
OnmsEvent newEvent = m_eventDao.load(event.getId());
assertEquals("uei://org/opennms/test/EventDaoTest", newEvent.getEventUei());
assertNotNull(newEvent.getServiceType());
assertEquals(service.getNodeId(), newEvent.getNode().getId());
assertEquals(event.getIpAddr(), newEvent.getIpAddr());
System.err.println(JaxbUtils.marshal(event));
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class MonitoredServiceDaoIT method testFindAllServices.
@Test
public void testFindAllServices() {
final List<OnmsMonitoredService> allSvcs = m_monitoredServiceDao.findAllServices();
assertTrue(allSvcs.size() > 1);
for (OnmsMonitoredService ifservice : allSvcs) {
assertNotNull(ifservice.getIpInterface());
assertNotNull(ifservice.getIpInterface().getNode());
assertNotNull(ifservice.getIpAddress());
assertNotNull(ifservice.getNodeId());
assertNotNull(ifservice.getServiceType());
}
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class NodeDaoIT method testQueryWithHierarchyCloseTransaction.
/** Test for bug 1594 */
@Test
@Transactional
public void testQueryWithHierarchyCloseTransaction() throws Exception {
OnmsNode n = getNodeHierarchy(getNode1().getId());
validateNode(n);
for (OnmsIpInterface ip : n.getIpInterfaces()) {
ip.getIpAddress();
for (OnmsMonitoredService service : ip.getMonitoredServices()) {
service.getServiceName();
}
}
// Test for bug 1594
for (OnmsSnmpInterface snmp : n.getSnmpInterfaces()) {
for (OnmsIpInterface ip : snmp.getIpInterfaces()) {
ip.getIpAddress();
}
}
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class QueryManagerDaoImpl method updateServiceStatus.
@Override
public void updateServiceStatus(int nodeId, String ipAddr, String serviceName, String status) {
try {
OnmsMonitoredService service = m_monitoredServiceDao.get(nodeId, InetAddress.getByName(ipAddr), serviceName);
service.setStatus(status);
m_monitoredServiceDao.saveOrUpdate(service);
} catch (UnknownHostException e) {
LOG.error("Failed to set the status for service named {} on node id {} and interface {} to {}.", serviceName, nodeId, ipAddr, status, e);
}
}
use of org.opennms.netmgt.model.OnmsMonitoredService in project opennms by OpenNMS.
the class QueryManagerDaoImpl method getNodeServices.
@Override
public List<String[]> getNodeServices(int nodeId) {
final LinkedList<String[]> servicemap = new LinkedList<String[]>();
Criteria criteria = new Criteria(OnmsMonitoredService.class);
criteria.setAliases(Arrays.asList(new Alias[] { new Alias("ipInterface", "ipInterface", JoinType.LEFT_JOIN), new Alias("ipInterface.node", "node", JoinType.LEFT_JOIN) }));
criteria.addRestriction(new EqRestriction("node.id", nodeId));
// Ignore forced-unmanaged
criteria.addRestriction(new NeRestriction("status", "F"));
for (OnmsMonitoredService service : m_monitoredServiceDao.findMatching(criteria)) {
servicemap.add(new String[] { service.getIpAddressAsString(), service.getServiceName() });
}
return servicemap;
}
Aggregations