use of org.opennms.netmgt.model.OnmsSeverity in project opennms by OpenNMS.
the class Bsmd method handleBusinessServiceStateChanged.
/**
* Called when the operational status of a business service was changed.
*/
@Override
public void handleBusinessServiceStateChanged(BusinessService businessService, Status newStatus, Status prevStatus) {
final OnmsSeverity newSeverity = SeverityMapper.toSeverity(newStatus);
final OnmsSeverity prevSeverity = SeverityMapper.toSeverity(prevStatus);
// Always send an serviceOperationalStatusChanged event
EventBuilder ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_OPERATIONAL_STATUS_CHANGED_UEI, NAME);
addBusinessServicesAttributesAsEventParms(businessService, ebldr);
ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_ID, businessService.getId());
ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_NAME, businessService.getName());
ebldr.addParam(EventConstants.PARM_PREV_SEVERITY_ID, prevSeverity.getId());
ebldr.addParam(EventConstants.PARM_PREV_SEVERITY_LABEL, prevSeverity.getLabel());
ebldr.addParam(EventConstants.PARM_NEW_SEVERITY_ID, newSeverity.getId());
ebldr.addParam(EventConstants.PARM_NEW_SEVERITY_LABEL, newSeverity.getLabel());
m_eventIpcManager.sendNow(ebldr.getEvent());
// Generate a serviceProblem or a serviceProblemResolved event based on the current status
if (newSeverity.isGreaterThan(OnmsSeverity.NORMAL)) {
ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_UEI, NAME);
addBusinessServicesAttributesAsEventParms(businessService, ebldr);
ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_ID, businessService.getId());
ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_NAME, businessService.getName());
ebldr.setSeverity(newSeverity.toString());
} else {
ebldr = new EventBuilder(EventConstants.BUSINESS_SERVICE_PROBLEM_RESOLVED_UEI, NAME);
addBusinessServicesAttributesAsEventParms(businessService, ebldr);
ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_ID, businessService.getId());
ebldr.addParam(EventConstants.PARM_BUSINESS_SERVICE_NAME, businessService.getName());
}
m_eventIpcManager.sendNow(ebldr.getEvent());
}
use of org.opennms.netmgt.model.OnmsSeverity in project opennms by OpenNMS.
the class GraphMLEdgeStatus method merge.
public static GraphMLEdgeStatus merge(final GraphMLEdgeStatus s1, final GraphMLEdgeStatus s2) {
final OnmsSeverity severity = s1.getSeverity().isGreaterThan(s2.getSeverity()) ? s1.getSeverity() : s2.getSeverity();
final Map<String, String> styleProperties = Maps.newHashMap(EMPTY_PROPERTIES);
for (final Map.Entry<String, String> e : s1.styleProperties.entrySet()) {
if (e.getValue() != null) {
styleProperties.put(e.getKey(), e.getValue());
}
}
for (final Map.Entry<String, String> e : s2.styleProperties.entrySet()) {
if (e.getValue() != null) {
styleProperties.put(e.getKey(), e.getValue());
}
}
return new GraphMLEdgeStatus(severity, styleProperties);
}
use of org.opennms.netmgt.model.OnmsSeverity in project opennms by OpenNMS.
the class ApplicationStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
Map<VertexRef, Status> returnMap = new HashMap<>();
Map<ApplicationStatusEntity.Key, Status> statusMap = new HashMap<>();
List<ApplicationStatusEntity> result = applicationDao.getAlarmStatus();
for (ApplicationStatusEntity eachRow : result) {
DefaultStatus status = createStatus(eachRow.getSeverity(), eachRow.getCount());
statusMap.put(eachRow.getKey(), status);
}
// status for all known node ids
Collection<VertexRef> vertexRefsForNamespace = getVertexRefsForNamespace(vertices);
Collection<VertexRef> vertexRefsRoot = getRootElements(vertexRefsForNamespace);
Collection<VertexRef> vertexRefs = new ArrayList<>(vertexRefsForNamespace);
vertexRefs.removeAll(vertexRefsRoot);
// calculate status for children
for (VertexRef eachVertex : vertexRefs) {
ApplicationVertex applicationVertex = (ApplicationVertex) eachVertex;
Status alarmStatus = statusMap.get(createKey(applicationVertex));
if (alarmStatus == null) {
alarmStatus = createStatus(OnmsSeverity.NORMAL, 0);
}
returnMap.put(eachVertex, alarmStatus);
}
// calculate status for root
for (VertexRef eachRoot : vertexRefsRoot) {
ApplicationVertex eachRootApplication = (ApplicationVertex) eachRoot;
OnmsSeverity maxSeverity = OnmsSeverity.NORMAL;
int count = 0;
for (VertexRef eachChild : eachRootApplication.getChildren()) {
ApplicationVertex eachChildApplication = (ApplicationVertex) eachChild;
ApplicationStatusEntity.Key childKey = createKey(eachChildApplication);
Status childStatus = statusMap.get(childKey);
if (childStatus != null && maxSeverity.isLessThan(createSeverity(childStatus.computeStatus()))) {
maxSeverity = createSeverity(childStatus.computeStatus());
count = Integer.parseInt(childStatus.getStatusProperties().get("statusCount"));
}
}
returnMap.put(eachRoot, createStatus(maxSeverity, count));
}
return returnMap;
}
use of org.opennms.netmgt.model.OnmsSeverity in project opennms by OpenNMS.
the class QoSDrxAlarmEventReceiverEventHandlerImpl2 method onNotifyNewAlarmEvent.
// ************************
// On Event Methods
// ************************
/** {@inheritDoc} */
@Override
public void onNotifyNewAlarmEvent(NotifyNewAlarmEvent nnae, OssBeanAlarmEventReceiver callingAer) {
// Get a reference to the QoSD logger instance assigned by OpenNMS
String logheader = "RX:" + callingAer.getName() + ":" + this.getClass().getSimpleName() + ".onNotifyNewAlarmEvent(): ";
LOG.debug("{} Statistics: {}", logheader, callingAer.getRuntimeStatistics());
if (!initialised) {
LOG.error("{} event handler not initialised. init() must be called by receiver before handling any events", logheader);
return;
}
try {
OnmsAlarm alarm = null;
String ossPrimaryKey = nnae.getAlarmKey().getAlarmPrimaryKey();
String applicationDN = nnae.getAlarmKey().getApplicationDN();
LOG.debug("{} Received an onNotifyNewAlarmEvent() - AlarmPrimaryKey: {} ApplictionDN: {} eventtime: {}", logheader, ossPrimaryKey, applicationDN, nnae.getEventTime());
LOG.debug("{} Using this OssDao (toString):{}", logheader, ossDao.toString());
if ((applicationDN == null) || (applicationDN.equals("")) || (ossPrimaryKey == null) || (ossPrimaryKey.equals(""))) {
LOG.error("{} ApplicatioDN or PrimaryKey not set", logheader);
} else {
LOG.debug("{} Creating new alarm", logheader);
// alarm = ossDao.getCurrentAlarmForUniqueKey(applicationDN, ossPrimaryKey);
// if (alarm!=null) { // already an alarm with this unique id - LOG.error
// LOG.error("{} Alarm Already exists with this Unique ID", logheader);
// } else {
alarm = new OnmsAlarm();
alarm.setUei(OnmsAlarmOssjMapper.ossjAlarmTypeToUei(nnae.getAlarmType()));
alarm.setX733AlarmType((nnae.getAlarmType() == null) ? "" : nnae.getAlarmType());
alarm.setX733ProbableCause(nnae.getProbableCause());
// needed?
alarm.setTTicketState(null);
// TODO changed
alarm.setTTicketId("");
// TODO changed
alarm.setQosAlarmState("external_type");
// needed?
alarm.setSuppressedUser("");
// needed?
alarm.setSuppressedUntil(new Date());
// needed?
alarm.setSuppressedTime(new Date());
OnmsSeverity onmsseverity;
try {
onmsseverity = OnmsAlarmOssjMapper.ossjSeveritytoOnmsSeverity(nnae.getPerceivedSeverity());
} catch (IllegalArgumentException iae) {
LOG.error("{} problem setting severity used default:'WARNING'. Exception:", logheader, iae);
onmsseverity = OnmsSeverity.WARNING;
}
alarm.setSeverity(onmsseverity);
//TODO not needed
// OnmsServiceType service= new OnmsServiceType();
// service.setId(new Integer(-1));
// alarm.setServiceType(new OnmsServiceType()); // needed?
alarm.setReductionKey(":managedObjectInstance:" + nnae.getManagedObjectInstance() + ":managedObjectType:" + nnae.getManagedObjectClass() + ":ossPrimaryKey:-" + ossPrimaryKey + ":applicationDN:-" + // must be unique because of alarm_reductionkey_idx
applicationDN);
alarm.setOssPrimaryKey(ossPrimaryKey);
alarm.setOperInstruct(nnae.getProposedRepairActions());
// defaultvalue if search fails - will update node with ID 1
// TODO remove ossDao.makeExtendedOnmsNode();
OnmsNode node = new OnmsNode();
// node id cannot be null
node.setId(new Integer(1));
//
alarm.setNode(node);
if (almUpdateBehaviour == null) {
LOG.error("RX:{}: This receiver's alarmUpdateBehaviour is not set: defaulting to update nodeID:1", callingAer.getName());
} else if (callingAer.getName() == null) {
LOG.error("RX:{}: This receiver has no name: default alarms will update nodeID:1", callingAer.getName());
} else {
LOG.debug("{} alarmUpdateBehaviour:{} {}", logheader, almUpdateBehaviour, alarmUpdateBehaviour);
if (almUpdateBehaviour.equals(SPECIFY_OUTSTATION)) {
// this will look for first match of node label to callingAer.getName()
// and set node id to this value.
LOG.debug("{} SPECIFY_OUTSTATION looking for node with nodelabel:{}", logheader, callingAer.getName());
try {
// TODO temp remove ?
try {
node = ossDao.findNodeByLabel(callingAer.getName());
} catch (Throwable ex) {
LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node ", logheader, ex);
}
if (node != null) {
LOG.debug("{} alarmUpdateBehaviour.equals(SPECIFY_OUTSTATION):NODE FOUND for this RX Name:{} setting node id to NodeLabel:{} NodeID:{}", logheader, callingAer.getName(), node.getLabel(), node.getId());
// maps into FIRST instance of node with the same managedObjectInstance and managedObjectType
alarm.setNode(node);
} else {
LOG.error("{} alarmUpdateBehaviour.equals(SPECIFY_OUTSTATION):NODE NOT FOUND for this RX Name:{} setting node id to default NodeID: 1", logheader, callingAer.getName());
// TODO remove ossDao.makeExtendedOnmsNode();
node = new OnmsNode();
// node id cannot be null
node.setId(new Integer(1));
//
alarm.setNode(node);
}
} catch (Throwable ex) {
LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node for alarm Set to default nodeID:1", logheader, 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 = nnae.getManagedObjectClass();
String managedObjectInstance = nnae.getManagedObjectInstance();
LOG.debug("{} USE_TYPE_INSTANCE looking for node with managedObjectType:{} managedObjectInstance:{}", logheader, managedObjectType, managedObjectInstance);
try {
node = ossDao.findNodeByInstanceAndType(managedObjectInstance, managedObjectType);
if (node != null) {
LOG.debug("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE):NODE FOUND for this RX Name:{} setting node id to NodeLabel:{} NodeID:{}", logheader, callingAer.getName(), node.getLabel(), node.getId());
// maps into FIRST instance of node with the same managedObjectInstance and managedObjectType
alarm.setNode(node);
} else {
LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE):NODE NOT FOUND for this managedObjectType:{} managedObjectInstance:{} setting node id to default NodeID: 1", logheader, managedObjectType, managedObjectInstance);
// TODO remove ossDao.makeExtendedOnmsNode();
node = new OnmsNode();
// node id cannot be null
node.setId(new Integer(1));
//
alarm.setNode(node);
}
} catch (Throwable ex) {
LOG.error("{} alarmUpdateBehaviour.equals(USE_TYPE_INSTANCE) Problem looking up Node for alarm Set to default nodeID:1", logheader, ex);
}
} else {
LOG.error("{} Invalid value for alarmUpdateBehaviour:{} {} defaulting to update nodeID:1", logheader, almUpdateBehaviour, alarmUpdateBehaviour);
}
}
// needed?
alarm.setMouseOverText("");
alarm.setManagedObjectType(nnae.getManagedObjectClass());
alarm.setManagedObjectInstance(nnae.getManagedObjectInstance());
alarm.setLogMsg(nnae.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
// alarm.setLastEvent(event);
// needed?
alarm.setIpAddr(InetAddressUtils.getLocalHostAddress());
// set null as updating alarm
alarm.setId(null);
alarm.setFirstEventTime(nnae.getEventTime());
alarm.setLastEventTime(nnae.getEventTime());
alarm.setDistPoller(distPollerDao.whoami());
//TODO need Qosd Not to generate this if remote
alarm.setDescription(nnae.getAdditionalText());
alarm.setCounter(new Integer(1));
alarm.setApplicationDN(applicationDN);
// set to raise alarm
alarm.setAlarmType(new Integer(1));
//alarm.setAlarmAckUser(arg0);
//alarm.setAlarmAckTime(arg0);
//TODO added for new alarm field
HashMap<String, String> m_details = new HashMap<String, String>();
alarm.setDetails(m_details);
try {
LOG.debug("{} Creating Alarm: ", logheader);
OnmsAlarm updatedAlarm = ossDao.addCurrentAlarmForUniqueKey(alarm);
LOG.debug("{} Created alarm: {}", logheader, OssDaoOpenNMSImpl.alarmToString(updatedAlarm));
} catch (Exception ex) {
LOG.error("{} problem creating new alarm AlarmPrimaryKey: {} ApplictionDN: {}", logheader, ossPrimaryKey, applicationDN, ex);
}
}
//TODO remove }
} catch (Throwable e) {
LOG.error("{} Error", logheader, e);
}
}
use of org.opennms.netmgt.model.OnmsSeverity in project opennms by OpenNMS.
the class AlarmFeed method getFeed.
/**
* <p>getFeed</p>
*
* @return a {@link com.sun.syndication.feed.synd.SyndFeed} object.
*/
@Override
public SyndFeed getFeed() {
SyndFeed feed = new SyndFeedImpl();
feed.setTitle("Alarms");
feed.setDescription("OpenNMS Alarms");
feed.setLink(getUrlBase() + "alarm/list.htm");
List<SyndEntry> entries = new ArrayList<SyndEntry>();
List<Filter> filters = new ArrayList<Filter>();
if (this.getRequest().getParameter("node") != null) {
Integer nodeId = WebSecurityUtils.safeParseInt(this.getRequest().getParameter("node"));
filters.add(new NodeFilter(nodeId, getServletContext()));
}
if (this.getRequest().getParameter("severity") != null) {
String sev = this.getRequest().getParameter("severity");
for (OnmsSeverity severity : OnmsSeverity.values()) {
if (severity.getLabel().equalsIgnoreCase(sev)) {
filters.add(new SeverityFilter(severity));
}
}
}
OnmsCriteria queryCriteria = AlarmUtil.getOnmsCriteria(new AlarmCriteria(filters.toArray(new Filter[] {}), SortStyle.FIRSTEVENTTIME, AcknowledgeType.BOTH, this.getMaxEntries(), AlarmCriteria.NO_OFFSET));
OnmsAlarm[] alarms = m_webAlarmRepository.getMatchingAlarms(queryCriteria);
SyndEntry entry;
for (OnmsAlarm alarm : alarms) {
entry = new SyndEntryImpl();
entry.setPublishedDate(alarm.getFirstEventTime());
if (alarm.getAckTime() != null) {
entry.setTitle(sanitizeTitle(alarm.getLogMsg()) + " (acknowledged by " + alarm.getAckUser() + ")");
entry.setUpdatedDate(alarm.getAckTime());
} else {
entry.setTitle(sanitizeTitle(alarm.getLogMsg()));
entry.setUpdatedDate(alarm.getFirstEventTime());
}
entry.setLink(getUrlBase() + "alarm/detail.htm?id=" + alarm.getId());
entry.setAuthor("OpenNMS");
SyndContent content = new SyndContentImpl();
content.setType("text/html");
content.setValue(alarm.getDescription());
entry.setDescription(content);
entries.add(entry);
}
feed.setEntries(entries);
return feed;
}
Aggregations