/** {@inheritDoc} */
 @Override
 public void foundMonitoredService(String serviceName) {
   OnmsServiceType svcType = getServiceType(serviceName);
   OnmsMonitoredService service = new OnmsMonitoredService(m_currentInterface, svcType);
   service.setStatus("A");
   m_currentInterface.getMonitoredServices().add(service);
 }
  public boolean isRequisitioned(OnmsMonitoredService monSvc) {
    String foreignSource = monSvc.getIpInterface().getNode().getForeignSource();
    String foreignId = monSvc.getIpInterface().getNode().getForeignId();

    // is this a discovered node
    if (foreignSource == null) return false;

    OnmsNode reqNode = getRequisitionedNode(foreignSource, foreignId);
    if (reqNode == null) {
      // this is no requisition node?
      LogUtils.errorf(
          "No requistion exists for node with foreignSource %s and foreignId %s.  Treating node as unrequistioned",
          foreignSource, foreignId);
      return false;
    }

    OnmsIpInterface reqIp = reqNode.getIpInterfaceByIpAddress(monSvc.getIpAddress());
    if (reqIp == null) {
      // there is no matching requistion ip so the interface was discovered
      return false;
    }

    OnmsMonitoredService reqSvc = reqIp.getMonitoredServiceByServiceType(monSvc.getServiceName());

    // if we found the service then its a requistion service
    return reqSvc != null;
  }
 /** {@inheritDoc} */
 @Transactional
 public void deleteService(final Integer nodeId, final InetAddress addr, final String service) {
   final OnmsMonitoredService monSvc = m_monitoredServiceDao.get(nodeId, addr, service);
   if (monSvc != null && shouldDelete(monSvc)) {
     m_monitoredServiceDao.delete(monSvc);
     monSvc.visit(new DeleteEventVisitor(m_eventForwarder));
   }
 }
 @Override
 public void visitMonitoredService(OnmsMonitoredService monSvc) {
   OnmsServiceType dbType = monSvc.getServiceType();
   if (dbType.getId() == null) {
     dbType = createServiceTypeIfNecessary(dbType.getName());
   }
   monSvc.setServiceType(dbType);
 }
 /**
  * setMonitoredService
  *
  * @param monitoredService a {@link org.opennms.netmgt.model.OnmsMonitoredService} object.
  * @return a {@link org.opennms.netmgt.model.events.EventBuilder} object.
  */
 public EventBuilder setMonitoredService(final OnmsMonitoredService monitoredService) {
   if (monitoredService != null) {
     m_event.setNodeid(monitoredService.getNodeId().longValue());
     m_event.setInterfaceAddress(monitoredService.getIpAddress());
     m_event.setService(monitoredService.getServiceName());
   }
   return this;
 }
  @Test
  @Transactional
  public void testLazy() {
    final List<OnmsMonitoredService> allSvcs = m_monitoredServiceDao.findAll();
    assertTrue(allSvcs.size() > 1);

    final OnmsMonitoredService svc = allSvcs.iterator().next();
    assertEquals(addr("192.168.1.1"), svc.getIpAddress());
    assertEquals(1, svc.getIfIndex().intValue());
    assertEquals(m_databasePopulator.getNode1().getId(), svc.getIpInterface().getNode().getId());
    assertEquals("M", svc.getIpInterface().getIsManaged());
  }
  /** {@inheritDoc} */
  public void poll(OnmsMonitoredService monSvc, int pollResultId) {

    EventBuilder bldr =
        new EventBuilder(EventConstants.DEMAND_POLL_SERVICE_EVENT_UEI, "PollerService");

    bldr.setNodeid(monSvc.getNodeId());
    bldr.setInterface(monSvc.getIpAddress());
    bldr.setIfIndex(monSvc.getIfIndex());
    bldr.setService(monSvc.getServiceType().getName());

    bldr.addParam(EventConstants.PARM_DEMAND_POLL_ID, pollResultId);

    sendEvent(bldr.getEvent());
  }
  @Test
  @Transactional
  public void testGetByCompositeId() {
    final OnmsMonitoredService monSvc =
        m_monitoredServiceDao.get(
            m_databasePopulator.getNode1().getId(), addr("192.168.1.1"), "SNMP");
    assertNotNull(monSvc);

    final OnmsMonitoredService monSvc2 =
        m_monitoredServiceDao.get(
            m_databasePopulator.getNode1().getId(),
            addr("192.168.1.1"),
            monSvc.getIfIndex(),
            monSvc.getServiceId());
    assertNotNull(monSvc2);
  }
Пример #9
0
 @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);
   }
 }
Пример #10
0
 private PolledService createPolledService(
     int serviceID,
     OnmsMonitoredService service,
     Map<String, Object> monitorConfiguration,
     long interval) {
   service.setId(serviceID);
   return new PolledService(service, monitorConfiguration, new OnmsPollModel(interval));
 }
Пример #11
0
  @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));
    criteria.addRestriction(new NeRestriction("status", "F")); // Ignore forced-unmanaged
    for (OnmsMonitoredService service : m_monitoredServiceDao.findMatching(criteria)) {
      servicemap.add(new String[] {service.getIpAddressAsString(), service.getServiceName()});
    }

    return servicemap;
  }
Пример #12
0
  private boolean shouldDelete(final OnmsMonitoredService monSvc) {
    String foreignSource = monSvc.getIpInterface().getNode().getForeignSource();

    // only delete services that are on discovered nodes if discovery is enabled
    // meaning provisiond is managing discovered nodes rather than capsd
    if (foreignSource == null) return isDiscoveryEnabled();

    // if we enable deletion of requisitioned entities then we can delete this
    if (isRequisitionedEntityDeletionEnabled()) return true;

    // otherwise only delete if it is not requistioned
    return !isRequisitioned(monSvc);
  }
  @Test
  @Transactional
  public void testNotificationSave() {
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_distPollerDao.load("localhost"));
    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/NotificationDaoTest");
    //        OnmsAlarm alarm = new OnmsAlarm();
    //        event.setAlarm(alarm);

    OnmsNode node = m_nodeDao.findAll().iterator().next();
    OnmsIpInterface iface = node.getIpInterfaces().iterator().next();
    OnmsMonitoredService service = iface.getMonitoredServices().iterator().next();
    event.setNode(node);
    event.setServiceType(service.getServiceType());
    event.setIpAddr(iface.getIpAddress());
    m_eventDao.save(event);
    OnmsEvent newEvent = m_eventDao.load(event.getId());
    assertEquals("uei://org/opennms/test/NotificationDaoTest", newEvent.getEventUei());

    OnmsNotification notification = new OnmsNotification();
    notification.setEvent(newEvent);
    notification.setTextMsg("Tests are fun!");
    m_notificationDao.save(notification);

    OnmsNotification newNotification = m_notificationDao.load(notification.getNotifyId());
    assertEquals(
        "uei://org/opennms/test/NotificationDaoTest", newNotification.getEvent().getEventUei());
  }
Пример #14
0
  Service(OnmsMonitoredService monSvc) {
    setId(monSvc.getId());
    setNodeId(monSvc.getNodeId());

    setIpAddress(InetAddressUtils.str(monSvc.getIpAddress()));
    setServiceId(monSvc.getServiceId());
    setServiceName(monSvc.getServiceName());
    if (monSvc.getLastGood() != null) {
      setLastGood(monSvc.getLastGood().toString());
    }
    if (monSvc.getLastFail() != null) {
      setLastFail(monSvc.getLastFail().toString());
    }
    setNotify(monSvc.getNotify());
    if (monSvc.getStatus() != null) {
      setStatus(monSvc.getStatus().charAt(0));
    }
  }