예제 #1
0
 @Override
 public OnmsNode load(Integer id) {
   OnmsNode node = new OnmsNode();
   node.setId(777);
   node.setLabel("p-brane");
   return node;
 }
예제 #2
0
 private static OnmsIpInterface getInterface() {
   OnmsNode node = new OnmsNode();
   node.setId(1);
   OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
   iface.setId(1);
   return iface;
 }
 private OnmsResource getNodeResource(int nodeId) {
   final NodeResourceType nodeResourceType = new NodeResourceType(m_resourceDao, m_nodeDao);
   OnmsNode node = new OnmsNode();
   node.setId(nodeId);
   node.setLabel("Node" + nodeId);
   return nodeResourceType.createResourceForNode(node);
 }
  @Test
  public void testSimpleFilter() throws Exception {
    final InetAddress oneNinetyTwo = addr("192.168.0.1");

    final List<InetAddress> addresses = Arrays.asList(oneNinetyTwo);
    m_filterDao.setActiveIPAddressList(addresses);

    final OnmsNode node = new OnmsNode(null, "foo");
    node.setId(1);
    node.setForeignSource("foo");
    node.setForeignId("bar");
    node.setSysObjectId(".1.2.3.4.5");
    final OnmsIpInterface iface = new OnmsIpInterface(oneNinetyTwo, node);
    final OnmsServiceType serviceType = new OnmsServiceType("SNMP");
    final OnmsMonitoredService service = new OnmsMonitoredService(iface, serviceType);
    m_monitoredServiceDao.setMatching(Arrays.asList(service));

    final Response response = m_configResource.getAgentsJson("example1", "SNMP");
    assertEquals(200, response.getStatus());
    final Object entity = response.getEntity();
    assertNotNull(entity);
    assertTrue(entity instanceof GenericEntity<?>);
    @SuppressWarnings("unchecked")
    final List<AgentResponse> agentResponses =
        (List<AgentResponse>) ((GenericEntity<?>) entity).getEntity();
    System.err.println(agentResponses);
    assertEquals(1, agentResponses.size());
    assertEquals(oneNinetyTwo, agentResponses.get(0).getAddress());
    assertEquals(1161, agentResponses.get(0).getPort().intValue());
    assertEquals(".1.2.3.4.5", agentResponses.get(0).getParameters().get("sysObjectId"));
    assertEquals("1", agentResponses.get(0).getParameters().get("nodeId"));
    assertEquals("foo", agentResponses.get(0).getParameters().get("foreignSource"));
    assertEquals("bar", agentResponses.get(0).getParameters().get("foreignId"));
  }
 private OnmsResource getNodeResource(String fs, String fid) {
   NodeResourceType nodeSourceResourceType = new NodeResourceType(m_resourceDao, m_nodeDao);
   OnmsNode node = new OnmsNode();
   node.setId(0);
   node.setLabel("Node");
   node.setForeignSource(fs);
   node.setForeignId(fid);
   return nodeSourceResourceType.createResourceForNode(node);
 }
예제 #6
0
  public void testPoll() throws EventProxyException {

    final int expectedPolldId = 7;

    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    final OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);

    m_eventProxy.send(isA(Event.class));
    expectLastCall()
        .andAnswer(
            new IAnswer<Object>() {

              @Override
              public Object answer() throws Throwable {
                Event event = (Event) getCurrentArguments()[0];
                assertEquals(
                    "Incorrect uei for demandPollService event",
                    EventConstants.DEMAND_POLL_SERVICE_EVENT_UEI,
                    event.getUei());
                assertEquals(
                    "Incorrect nodeid for demandPollService event",
                    monSvc.getNodeId().longValue(),
                    event.getNodeid().longValue());
                assertEquals(
                    "Incorrect ipadr for demandPollService event",
                    InetAddressUtils.str(monSvc.getIpAddress()),
                    event.getInterface());
                assertEquals(
                    "Incorrect ifIndex for demandPollService event",
                    monSvc.getIfIndex(),
                    Integer.valueOf(event.getIfIndex()));
                assertEquals(
                    "Incorrect service for demandPollService event",
                    monSvc.getServiceType().getName(),
                    event.getService());
                EventUtils.requireParm(event, EventConstants.PARM_DEMAND_POLL_ID);
                assertEquals(
                    expectedPolldId,
                    EventUtils.getIntParm(event, EventConstants.PARM_DEMAND_POLL_ID, -1));
                return null;
              }
            });

    replay(m_eventProxy);

    m_pollerService.poll(monSvc, expectedPolldId);

    verify(m_eventProxy);
  }
예제 #7
0
  @Override
  public List<OnmsNode> findAll() {

    List<OnmsNode> nodeList = new LinkedList<OnmsNode>();

    OnmsNode node = new OnmsNode();
    node.setId(777);
    node.setLabel("p-brane");

    nodeList.add(node);
    return nodeList;
  }
  @Before
  public void setUp() {
    m_node1 = new OnmsNode();
    m_node1.setId(1);

    m_node2 = new OnmsNode();
    m_node2.setId(2);

    m_nodeChennai = new OnmsNode();
    m_nodeChennai.setId(14);

    m_nodeDehli = new OnmsNode();
    m_nodeDehli.setId(10);

    m_alarmDao = EasyMock.createMock(AlarmDao.class);
    m_ospfLinkDao = EasyMock.createMock(OspfLinkDao.class);

    m_statusProvider = new OspfLinkStatusProvider();
    m_statusProvider.setAlarmDao(m_alarmDao);
    m_statusProvider.setOspfLinkDao(m_ospfLinkDao);

    m_edgeProvider = EasyMock.createMock(EdgeProvider.class);
  }
예제 #9
0
  @Before
  public void setUp() throws Exception {
    m_mockNetwork.createStandardNetwork();

    m_eventdIpcMgr.setEventWriter(m_database);

    // Insert some empty nodes to avoid foreign-key violations on subsequent events/alarms
    final OnmsNode node = new OnmsNode();
    node.setId(1);
    node.setLabel("node1");
    m_nodeDao.save(node);

    m_northbounder = new MockNorthbounder();
    m_registry.register(m_northbounder, Northbounder.class);
  }
 /**
  * Constructor for AbstractSaveOrUpdateOperation.
  *
  * @param nodeId a {@link java.lang.Integer} object.
  * @param foreignSource a {@link java.lang.String} object.
  * @param foreignId a {@link java.lang.String} object.
  * @param nodeLabel a {@link java.lang.String} object.
  * @param building a {@link java.lang.String} object.
  * @param city a {@link java.lang.String} object.
  */
 public AbstractSaveOrUpdateOperation(
     final Integer nodeId,
     final String foreignSource,
     final String foreignId,
     final String nodeLabel,
     final String building,
     final String city) {
   m_node = new OnmsNode();
   m_node.setId(nodeId);
   m_node.setLabel(nodeLabel);
   m_node.setLabelSource(NodeLabelSource.USER);
   m_node.setType(NodeType.ACTIVE);
   m_node.setForeignSource(foreignSource);
   m_node.setForeignId(foreignId);
   m_node.getAssetRecord().setBuilding(building);
   m_node.getAssetRecord().setCity(city);
 }
예제 #11
0
 private void setNode1(final OnmsNode node1) {
   node1.setId(1);
   m_node1 = node1;
 }
예제 #12
0
 private void setNode8(final OnmsNode node8) {
   node8.setId(8);
   m_node8 = node8;
 }
예제 #13
0
 private void setNode7(final OnmsNode node7) {
   node7.setId(7);
   m_node7 = node7;
 }
예제 #14
0
 private void setNode6(final OnmsNode node6) {
   node6.setId(6);
   m_node6 = node6;
 }
예제 #15
0
 private void setNode5(final OnmsNode node5) {
   node5.setId(5);
   m_node5 = node5;
 }
예제 #16
0
 private void setNode4(final OnmsNode node4) {
   node4.setId(4);
   m_node4 = node4;
 }
예제 #17
0
 private void setNode3(final OnmsNode node3) {
   node3.setId(3);
   m_node3 = node3;
 }
예제 #18
0
 /**
  * Simply replaces the current asset record with the new record
  *
  * @param scannedNode a {@link org.opennms.netmgt.model.OnmsNode} object.
  */
 public void replaceCurrentAssetRecord(OnmsNode scannedNode) {
   scannedNode.getAssetRecord().setId(this.getAssetRecord().getId());
   scannedNode.setId(this.m_id); // just in case
   this.setAssetRecord(scannedNode.getAssetRecord());
 }
예제 #19
0
 /**
  * setNodeId
  *
  * @param nodeid a {@link java.lang.String} object.
  */
 public void setNodeId(String nodeid) {
   setId(Integer.valueOf(nodeid));
 }
예제 #20
0
 private void setNode2(final OnmsNode node2) {
   node2.setId(2);
   m_node2 = node2;
 }
  /**
   * This method maps an OSS/J AlarmValue to OpenNMS alarm
   *
   * @param onmsAlarm OnmsAlarm object to be populated
   * @param alarmValue OSS/J AlarmValue data to use to populate OnmsAlarm
   * @param almUpdateBehaviour - determines how to treat the node name of the new alarm must be of
   *     value; <code>USE_TYPE_INSTANCE</code> - populate nodeID with node having same asset type
   *     and instance data as alarm or <code>SPECIFY_OUTSTATION</code> - populate nodeID with node
   *     having same nodeLabel as defaultUpdateNodeLabel
   * @param defaultUpdateNodeLabel name of node to be updated if
   *     almUpdateBehaviour==SPECIFY_OUTSTATION
   * @return the OnmsAlarm populated with OSS/J NotifyNewAlarmEvent data
   * @throws java.lang.IllegalArgumentException if any.
   * @throws javax.oss.UnsupportedAttributeException if any.
   */
  public OnmsAlarm populateOnmsAlarmFromOssjAlarm(
      OnmsAlarm onmsAlarm,
      AlarmValue alarmValue,
      Integer almUpdateBehaviour,
      String defaultUpdateNodeLabel)
      throws IllegalArgumentException, UnsupportedAttributeException {
    ThreadCategory log = getLog();
    String logheader =
        "\t\t" + this.getClass().getSimpleName() + "populateOnmsAlarmFromOssjAlarm():";

    try {
      String ossPrimaryKey = alarmValue.getAlarmKey().getAlarmPrimaryKey();
      String applicationDN = alarmValue.getAlarmKey().getApplicationDN();
      if (log.isDebugEnabled())
        log.debug(
            logheader
                + " - AlarmPrimaryKey: "
                + ossPrimaryKey
                + " ApplictionDN: "
                + applicationDN
                + " alarmRaisedTime: "
                + alarmValue.getAlarmRaisedTime());
      if ((applicationDN == null)
          || (applicationDN.equals(""))
          || (ossPrimaryKey == null)
          || (ossPrimaryKey.equals(""))) {
        log.error(logheader + " ApplicatioDN or PrimaryKey not set");
      } else {
        if (log.isDebugEnabled())
          log.debug(
              logheader + ": trying to find existing alarm using getCurrentAlarmForUniqueKey");

        onmsAlarm = ossDao.getCurrentAlarmForUniqueKey(applicationDN, ossPrimaryKey);
        if (onmsAlarm != null) { // already an alarm with this unique id - log error
          log.error(logheader + " Alarm Already exists with this Unique ID");
        } else {
          onmsAlarm = new OnmsAlarm();

          onmsAlarm.setUei(ossjAlarmTypeToUei(alarmValue.getAlarmType()));
          onmsAlarm.setX733AlarmType(
              (alarmValue.getAlarmType() == null) ? "" : alarmValue.getAlarmType());
          onmsAlarm.setX733ProbableCause(alarmValue.getProbableCause());

          onmsAlarm.setTTicketState(null); // needed?
          onmsAlarm.setTTicketId(""); // needed?
          onmsAlarm.setQosAlarmState("");
          onmsAlarm.setSuppressedUser(""); // needed?
          onmsAlarm.setSuppressedUntil(new Date()); // needed?
          onmsAlarm.setSuppressedTime(new Date()); // needed?

          OnmsSeverity onmsseverity;
          try {
            onmsseverity = ossjSeveritytoOnmsSeverity(alarmValue.getPerceivedSeverity());
          } catch (IllegalArgumentException iae) {
            log.error(
                logheader + " problem setting severity used default:'WARNING'. Exception:" + iae);
            onmsseverity = OnmsSeverity.WARNING;
          }
          onmsAlarm.setSeverity(onmsseverity);

          OnmsServiceType service = new OnmsServiceType();
          service.setId(new Integer(-1));
          onmsAlarm.setServiceType(new OnmsServiceType()); // needed?

          onmsAlarm.setReductionKey(
              ":managedObjectInstance:"
                  + alarmValue.getManagedObjectInstance()
                  + ":managedObjectType:"
                  + alarmValue.getManagedObjectClass()
                  + ":ossPrimaryKey:-"
                  + ossPrimaryKey
                  + ":applicationDN:-"
                  + applicationDN); // must be unique because of alarm_reductionkey_idx

          onmsAlarm.setOssPrimaryKey(ossPrimaryKey);
          onmsAlarm.setOperInstruct(alarmValue.getProposedRepairActions());

          // defaultvalue if search fails - will update node with ID 1
          OnmsNode node = new OnmsNode(); // TODO remove ossDao.makeExtendedOnmsNode();
          node.setId(new Integer(1)); // node id cannot be null
          onmsAlarm.setNode(node); //

          if (almUpdateBehaviour == null) {
            log.error(
                logheader
                    + ": This receiver's alarmUpdateBehaviour is not set: defaulting to update nodeID:1");
          } else {
            if (log.isDebugEnabled())
              log.debug(
                  logheader
                      + " alarmUpdateBehaviour:"
                      + almUpdateBehaviour
                      + " "
                      + getAlarmUpdateBehaviourForInt(almUpdateBehaviour));

            if (almUpdateBehaviour.equals(SPECIFY_OUTSTATION)) {
              // this will look for first match of node label to callingAer.getName()
              // and set node id to this value.

              if (log.isDebugEnabled())
                log.debug(
                    logheader
                        + " SPECIFY_OUTSTATION looking for node with nodelabel:"
                        + defaultUpdateNodeLabel);
              try {
                // TODO temp remove ?
                try {
                  node = ossDao.findNodeByLabel(defaultUpdateNodeLabel);
                } catch (Throwable ex) {
                  log.error(
                      logheader
                          + " alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node "
                          + ex);
                }

                if (node != null) {
                  if (log.isDebugEnabled())
                    log.debug(
                        logheader
                            + " alarmUpdateBehaviour.equals(SPECIFY_OUTSTATION):"
                            + "NODE FOUND for this name:"
                            + defaultUpdateNodeLabel
                            + " setting node id to NodeLabel:"
                            + node.getLabel()
                            + " NodeID:"
                            + node.getId());
                  onmsAlarm.setNode(
                      node); // maps into FIRST instance of node with the same managedObjectInstance
                  // and managedObjectType
                } else {
                  log.error(
                      logheader
                          + " alarmUpdateBehaviour.equals(SPECIFY_OUTSTATION):"
                          + "NODE NOT FOUND for this name:"
                          + defaultUpdateNodeLabel
                          + " setting node id to default NodeID: 1");
                  node = new OnmsNode(); // TODO remove ossDao.makeExtendedOnmsNode();
                  node.setId(new Integer(1)); // node id cannot be null
                  onmsAlarm.setNode(node); //
                }
              } catch (Throwable ex) {
                log.error(
                    logheader
                        + " alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node for alarm Set to default nodeID:1"
                        + ex);
              }

            } else if (almUpdateBehaviour.equals(USE_TYPE_INSTANCE)) {
              // this will look for first match of node Managed object Instance and Managed Object
              // type
              // and set node id to this value.
              String managedObjectType = alarmValue.getManagedObjectClass();
              String managedObjectInstance = alarmValue.getManagedObjectInstance();

              if (log.isDebugEnabled())
                log.debug(
                    logheader
                        + " USE_TYPE_INSTANCE looking for node with managedObjectType:"
                        + managedObjectType
                        + " managedObjectInstance:"
                        + managedObjectInstance);
              try {
                node = ossDao.findNodeByInstanceAndType(managedObjectInstance, managedObjectType);

                if (node != null) {
                  if (log.isDebugEnabled())
                    log.debug(
                        logheader
                            + " alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE):"
                            + "NODE FOUND for this RX Name:"
                            + defaultUpdateNodeLabel
                            + " setting node id to NodeLabel:"
                            + node.getLabel()
                            + " NodeID:"
                            + node.getId());
                  onmsAlarm.setNode(
                      node); // maps into FIRST instance of node with the same managedObjectInstance
                  // and managedObjectType
                } else {
                  log.error(
                      logheader
                          + " alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE):"
                          + "NODE NOT FOUND for this managedObjectType:"
                          + managedObjectType
                          + " managedObjectInstance:"
                          + managedObjectInstance
                          + " setting node id to default NodeID: 1");
                  node = new OnmsNode(); // TODO remove ossDao.makeExtendedOnmsNode();
                  node.setId(new Integer(1)); // node id cannot be null
                  onmsAlarm.setNode(node); //
                }
              } catch (Throwable ex) {
                log.error(
                    logheader
                        + " alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node for alarm Set to default nodeID:1"
                        + ex);
              }
            } else {
              log.error(
                  logheader
                      + " Invalid value for alarmUpdateBehaviour:"
                      + almUpdateBehaviour
                      + " "
                      + getAlarmUpdateBehaviourForInt(almUpdateBehaviour)
                      + " defaulting to update nodeID:1");
            }
          }

          onmsAlarm.setMouseOverText(""); // needed?
          onmsAlarm.setManagedObjectType(alarmValue.getManagedObjectClass());
          onmsAlarm.setManagedObjectInstance(alarmValue.getManagedObjectInstance());
          onmsAlarm.setLogMsg(alarmValue.getSpecificProblem());

          // NOTE - this has no effect here as .setLastEvent nulls value
          // alarm.setLastEventTime(nnae.getEventTime());

          //					TODO REMOVED - DO NOT CREATE EVENT WITH HIBERNATE AlarmDAo
          //					OnmsEvent event= new OnmsEvent();
          //					//event.setId(new Integer(1));  // This is NOT set since unique constraint in
          // alarms table on Events table
          //					onmsAlarm.setLastEvent(event);

          onmsAlarm.setIpAddr(InetAddressUtils.getLocalHostAddress()); // needed?
          onmsAlarm.setId(null); // set null as updating alarm
          onmsAlarm.setFirstEventTime(alarmValue.getAlarmRaisedTime());
          onmsAlarm.setLastEventTime(alarmValue.getAlarmChangedTime());

          //					TODO removed - do create distpoller with hibernate dao
          //					onmsAlarm.setDistPoller(new OnmsDistPoller("undefined","localhost")); //simple
          // constructor
          onmsAlarm.setDistPoller(distPollerDao.get("localhost"));

          onmsAlarm.setDescription(
              alarmValue.getAdditionalText()); // TODO need Qosd Not to generate this if remote
          onmsAlarm.setCounter(new Integer(1));
          onmsAlarm.setApplicationDN(applicationDN);
          onmsAlarm.setAlarmType(new Integer(1)); // set to raise alarm
          // alarm.setAlarmAckUser(arg0);
          // alarm.setAlarmAckTime(arg0);

          if (log.isDebugEnabled()) log.debug(logheader + ": Creating Alarm: ");
        }
      }
    } catch (Throwable e) {
      log.error(logheader + " Error : ", e);
    }
    return onmsAlarm;
  }