Search in sources :

Example 26 with OnmsMonitoredService

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));
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 27 with OnmsMonitoredService

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());
    }
}
Also used : OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

Example 28 with OnmsMonitoredService

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();
        }
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with OnmsMonitoredService

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);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 30 with OnmsMonitoredService

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;
}
Also used : Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) NeRestriction(org.opennms.core.criteria.restrictions.NeRestriction) Criteria(org.opennms.core.criteria.Criteria) LinkedList(java.util.LinkedList) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Aggregations

OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)116 Date (java.util.Date)35 OnmsNode (org.opennms.netmgt.model.OnmsNode)35 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)33 Test (org.junit.Test)26 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)23 Transactional (org.springframework.transaction.annotation.Transactional)21 OnmsApplication (org.opennms.netmgt.model.OnmsApplication)20 OnmsLocationSpecificStatus (org.opennms.netmgt.model.OnmsLocationSpecificStatus)18 ArrayList (java.util.ArrayList)17 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)16 OnmsLocationMonitor (org.opennms.netmgt.model.OnmsLocationMonitor)15 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)15 LinkedList (java.util.LinkedList)13 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)12 HashSet (java.util.HashSet)8 Before (org.junit.Before)6 Criteria (org.opennms.core.criteria.Criteria)5 BusinessServiceEntity (org.opennms.netmgt.bsm.persistence.api.BusinessServiceEntity)5 SimpleWebTable (org.opennms.web.svclayer.model.SimpleWebTable)5