/** {@inheritDoc} */ @Override public void foundInterface( final String ipAddr, final Object descr, final InterfaceSnmpPrimaryType snmpPrimary, final boolean managed, final int status) { if ("".equals(ipAddr)) { LOG.error("Found interface on node {} with an empty ipaddr! Ignoring!", m_node.getLabel()); // create a bogus OnmsIpInterface and set it to current to services we run across get ignored // as well m_currentInterface = new OnmsIpInterface(); return; } m_currentInterface = new OnmsIpInterface(ipAddr, m_node); m_currentInterface.setIsManaged(status == 3 ? "U" : "M"); m_currentInterface.setIsSnmpPrimary(PrimaryType.get(snmpPrimary.toString())); // m_currentInterface.setIpStatus(status == 3 ? new Integer(3) : new Integer(1)); if (InterfaceSnmpPrimaryType.P.equals(snmpPrimary)) { final InetAddress addr = InetAddressUtils.addr(ipAddr); if (addr == null) { LOG.error( "Unable to resolve address of snmpPrimary interface for node {}", m_node.getLabel()); } m_collector = new IfSnmpCollector(addr); } // FIXME: verify this doesn't conflict with constructor. The constructor already adds this // interface to the node. m_node.addIpInterface(m_currentInterface); }
public Map<Integer, String> getNodeLabelsById() { Map<Integer, String> nodeLabelsById = new HashMap<Integer, String>(); for (OnmsNode node : getNodes()) { nodeLabelsById.put(node.getId(), node.getLabel()); } return nodeLabelsById; }
/** {@inheritDoc} */ @Override public String getNodeLabel(int nodeId) { final OnmsNode onmsNode = m_nodeDao.get(nodeId); if (onmsNode == null) { return null; } return onmsNode.getLabel(); }
protected AbstractVertex getVertex(OnmsNode onmsnode) { OnmsIpInterface ip = getAddress(onmsnode); AbstractVertex vertex = new SimpleLeafVertex(TOPOLOGY_NAMESPACE_LINKD, onmsnode.getNodeId(), 0, 0); vertex.setIconKey(getIconName(onmsnode)); vertex.setLabel(onmsnode.getLabel()); vertex.setIpAddress(ip == null ? null : ip.getIpAddress().getHostAddress()); vertex.setNodeID(Integer.parseInt(onmsnode.getNodeId())); vertex.setTooltipText(getNodeTooltipText(onmsnode, vertex, ip)); return vertex; }
@Override public VertexHopGraphProvider.VertexHopCriteria getDefaultCriteria() { final OnmsNode node = m_topologyDao.getDefaultFocusPoint(); VertexHopGraphProvider.VertexHopCriteria criterion = null; if (node != null) { final Vertex defaultVertex = getVertex(node); if (defaultVertex != null) { criterion = new LinkdHopCriteria(node.getNodeId(), node.getLabel(), m_nodeDao); } } return criterion; }
/** * compareTo * * @param o a {@link org.opennms.netmgt.model.OnmsNode} object. * @return a int. */ @Override public int compareTo(OnmsNode o) { String compareLabel = ""; Integer compareId = 0; if (o != null) { compareLabel = o.getLabel(); compareId = o.getId(); } int returnval = this.getLabel().compareToIgnoreCase(compareLabel); if (returnval == 0) { return this.getId().compareTo(compareId); } else { return returnval; } }
@Test @Transactional public void testAlarmSummary_AlarmWithNoEvent() { OnmsNode node = m_nodeDao.findAll().iterator().next(); OnmsAlarm alarm = new OnmsAlarm(); alarm.setNode(node); alarm.setUei("uei://org/opennms/test/badAlarmTest"); alarm.setSeverityId(new Integer(7)); alarm.setCounter(1); alarm.setDistPoller(m_distPollerDao.load("localhost")); m_alarmDao.save(alarm); List<AlarmSummary> summary = m_alarmDao.getNodeAlarmSummaries(); Assert.assertNotNull(summary); Assert.assertEquals(1, summary.size()); AlarmSummary sum = summary.get(0); Assert.assertEquals(node.getLabel(), sum.getNodeLabel()); Assert.assertEquals(alarm.getSeverity().getId(), sum.getMaxSeverity().getId()); Assert.assertEquals("N/A", sum.getFuzzyTimeDown()); }
@Test @Transactional public void testAlarmSummary() { OnmsEvent event = new OnmsEvent(); event.setEventLog("Y"); event.setEventDisplay("Y"); event.setEventCreateTime(new Date()); event.setDistPoller(m_distPollerDao.load("localhost")); event.setEventTime(new Date()); event.setEventSeverity(new Integer(7)); event.setEventUei("uei://org/opennms/test/EventDaoTest"); event.setEventSource("test"); m_eventDao.save(event); OnmsNode node = m_nodeDao.findAll().iterator().next(); OnmsAlarm alarm = new OnmsAlarm(); alarm.setNode(node); alarm.setUei(event.getEventUei()); alarm.setSeverityId(event.getEventSeverity()); alarm.setFirstEventTime(event.getEventTime()); alarm.setLastEvent(event); alarm.setCounter(1); alarm.setDistPoller(m_distPollerDao.load("localhost")); m_alarmDao.save(alarm); List<AlarmSummary> summary = m_alarmDao.getNodeAlarmSummaries(); Assert.assertNotNull(summary); Assert.assertEquals(1, summary.size()); AlarmSummary sum = summary.get(0); Assert.assertEquals(node.getLabel(), sum.getNodeLabel()); Assert.assertEquals(alarm.getSeverity().getId(), sum.getMaxSeverity().getId()); Assert.assertNotSame("N/A", sum.getFuzzyTimeDown()); }
private void declareBeans(BSFManager bsfManager) throws BSFException { NodeDao nodeDao = Notifd.getInstance().getNodeDao(); Integer nodeId; try { nodeId = Integer.valueOf(m_notifParams.get(NotificationManager.PARAM_NODE)); } catch (NumberFormatException nfe) { nodeId = null; } OnmsNode node = null; OnmsAssetRecord assets = null; List<String> categories = new ArrayList<String>(); String nodeLabel = null; String foreignSource = null; String foreignId = null; if (nodeId != null) { node = nodeDao.get(nodeId); nodeLabel = node.getLabel(); assets = node.getAssetRecord(); for (OnmsCategory cat : node.getCategories()) { categories.add(cat.getName()); } foreignSource = node.getForeignSource(); foreignId = node.getForeignId(); } bsfManager.declareBean("bsf_notif_strategy", this, BSFNotificationStrategy.class); retrieveParams(); bsfManager.declareBean("notif_params", m_notifParams, Map.class); bsfManager.declareBean("node_label", nodeLabel, String.class); bsfManager.declareBean("foreign_source", foreignSource, String.class); bsfManager.declareBean("foreign_id", foreignId, String.class); bsfManager.declareBean("node_assets", assets, OnmsAssetRecord.class); bsfManager.declareBean("node_categories", categories, List.class); bsfManager.declareBean("node", node, OnmsNode.class); for (Argument arg : m_arguments) { if (NotificationManager.PARAM_TEXT_MSG.equals(arg.getSwitch())) bsfManager.declareBean("text_message", arg.getValue(), String.class); if (NotificationManager.PARAM_NUM_MSG.equals(arg.getSwitch())) bsfManager.declareBean("numeric_message", arg.getValue(), String.class); if (NotificationManager.PARAM_NODE.equals(arg.getSwitch())) bsfManager.declareBean("node_id", arg.getValue(), String.class); if (NotificationManager.PARAM_INTERFACE.equals(arg.getSwitch())) bsfManager.declareBean("ip_addr", arg.getValue(), String.class); if (NotificationManager.PARAM_SERVICE.equals(arg.getSwitch())) bsfManager.declareBean("svc_name", arg.getValue(), String.class); if (NotificationManager.PARAM_SUBJECT.equals(arg.getSwitch())) bsfManager.declareBean("subject", arg.getValue(), String.class); if (NotificationManager.PARAM_EMAIL.equals(arg.getSwitch())) bsfManager.declareBean("email", arg.getValue(), String.class); if (NotificationManager.PARAM_PAGER_EMAIL.equals(arg.getSwitch())) bsfManager.declareBean("pager_email", arg.getValue(), String.class); if (NotificationManager.PARAM_XMPP_ADDRESS.equals(arg.getSwitch())) bsfManager.declareBean("xmpp_address", arg.getValue(), String.class); if (NotificationManager.PARAM_TEXT_PAGER_PIN.equals(arg.getSwitch())) bsfManager.declareBean("text_pin", arg.getValue(), String.class); if (NotificationManager.PARAM_NUM_PAGER_PIN.equals(arg.getSwitch())) bsfManager.declareBean("numeric_pin", arg.getValue(), String.class); if (NotificationManager.PARAM_WORK_PHONE.equals(arg.getSwitch())) bsfManager.declareBean("work_phone", arg.getValue(), String.class); if (NotificationManager.PARAM_HOME_PHONE.equals(arg.getSwitch())) bsfManager.declareBean("home_phone", arg.getValue(), String.class); if (NotificationManager.PARAM_MOBILE_PHONE.equals(arg.getSwitch())) bsfManager.declareBean("mobile_phone", arg.getValue(), String.class); if (NotificationManager.PARAM_TUI_PIN.equals(arg.getSwitch())) bsfManager.declareBean("phone_pin", arg.getValue(), String.class); if (NotificationManager.PARAM_MICROBLOG_USERNAME.equals(arg.getSwitch())) bsfManager.declareBean("microblog_username", arg.getValue(), String.class); } }
/** {@inheritDoc} */ @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String nodeIdString = request.getParameter("node"); String labelType = request.getParameter("labeltype"); String userLabel = request.getParameter("userlabel"); if (nodeIdString == null) { throw new MissingParameterException("node", new String[] {"node", "labeltype", "userlabel"}); } if (labelType == null) { throw new MissingParameterException( "labeltype", new String[] {"node", "labeltype", "userlabel"}); } if (userLabel == null) { throw new MissingParameterException( "userlabel", new String[] {"node", "labeltype", "userlabel"}); } try { final int nodeId = WebSecurityUtils.safeParseInt(nodeIdString); final OnmsNode node = NetworkElementFactory.getInstance(getServletContext()).getNode(nodeId); NodeLabelJDBCImpl oldLabel = new NodeLabelJDBCImpl(node.getLabel(), node.getLabelSource()); NodeLabelJDBCImpl newLabel = null; if (labelType.equals("auto")) { newLabel = NodeLabelJDBCImpl.getInstance().computeLabel(nodeId); } else if (labelType.equals("user")) { newLabel = new NodeLabelJDBCImpl(userLabel, NodeLabelSource.USER); } else { throw new ServletException("Unexpected labeltype value: " + labelType); } final String newNodeLabel = newLabel.getLabel(); boolean managedByProvisiond = node.getForeignSource() != null && node.getForeignId() != null; if (managedByProvisiond) { WebApplicationContext beanFactory = WebApplicationContextUtils.getWebApplicationContext(getServletContext()); final TransactionTemplate transactionTemplate = beanFactory.getBean(TransactionTemplate.class); final RequisitionAccessService requisitionService = beanFactory.getBean(RequisitionAccessService.class); transactionTemplate.execute( new TransactionCallback<RequisitionNode>() { @Override public RequisitionNode doInTransaction(TransactionStatus status) { MultivaluedMapImpl params = new MultivaluedMapImpl(); params.putSingle("node-label", newNodeLabel); requisitionService.updateNode(node.getForeignSource(), node.getForeignId(), params); return requisitionService.getNode(node.getForeignSource(), node.getForeignId()); } }); } this.sendLabelChangeEvent(nodeId, oldLabel, newLabel); if (managedByProvisiond) { response.sendRedirect( Util.calculateUrlBase( request, "admin/nodelabelProvisioned.jsp?node=" + nodeIdString + "&foreignSource=" + node.getForeignSource())); } else { NodeLabelJDBCImpl.getInstance().assignLabel(nodeId, newLabel); response.sendRedirect( Util.calculateUrlBase(request, "element/node.jsp?node=" + nodeIdString)); } } catch (SQLException e) { throw new ServletException("Database exception", e); } catch (Throwable e) { throw new ServletException("Exception sending node label change event", e); } }
/** * mergeNodeAttributes * * @param scannedNode a {@link org.opennms.netmgt.model.OnmsNode} object. */ public void mergeNodeAttributes(OnmsNode scannedNode, EventForwarder eventForwarder) { final String scannedLabel = scannedNode.getLabel(); boolean send = false; if (m_oldLabel != null || m_oldLabelSource != null) { send = true; } else if (hasNewValue(scannedLabel, getLabel())) { m_oldLabel = getLabel(); m_oldLabelSource = getLabelSource(); send = true; } if (send) { LOG.debug("mergeNodeAttributes(): sending NODE_LABEL_CHANGED_EVENT_UEI"); // Create a NODE_LABEL_CHANGED_EVENT_UEI event final EventBuilder bldr = new EventBuilder( EventConstants.NODE_LABEL_CHANGED_EVENT_UEI, "OnmsNode.mergeNodeAttributes"); bldr.setNodeid(scannedNode.getId()); bldr.setHost("host"); if (m_oldLabel != null) { bldr.addParam(EventConstants.PARM_OLD_NODE_LABEL, m_oldLabel); if (m_oldLabelSource != null) { bldr.addParam(EventConstants.PARM_OLD_NODE_LABEL_SOURCE, m_oldLabelSource.toString()); } } if (scannedLabel != null) { bldr.addParam(EventConstants.PARM_NEW_NODE_LABEL, scannedLabel); if (scannedNode.getLabelSource() != null) { bldr.addParam( EventConstants.PARM_NEW_NODE_LABEL_SOURCE, scannedNode.getLabelSource().toString()); } } m_oldLabel = null; m_oldLabelSource = null; eventForwarder.sendNow(bldr.getEvent()); // Update the node label value m_label = scannedLabel; } else { LOG.debug("mergeNodeAttributes(): skipping event."); } if (hasNewValue(scannedNode.getForeignSource(), getForeignSource())) { setForeignSource(scannedNode.getForeignSource()); } if (hasNewValue(scannedNode.getForeignId(), getForeignId())) { setForeignId(scannedNode.getForeignId()); } if (hasNewValue(scannedNode.getLabelSource(), getLabelSource())) { setLabelSource(scannedNode.getLabelSource()); } if (hasNewValue(scannedNode.getNetBiosName(), getNetBiosDomain())) { setNetBiosName(scannedNode.getNetBiosDomain()); } if (hasNewValue(scannedNode.getNetBiosDomain(), getNetBiosDomain())) { setNetBiosDomain(scannedNode.getNetBiosDomain()); } if (hasNewValue(scannedNode.getOperatingSystem(), getOperatingSystem())) { setOperatingSystem(scannedNode.getOperatingSystem()); } mergeAgentAttributes(scannedNode); mergeAdditionalCategories(scannedNode); }
/** * 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; }