use of org.opennms.netmgt.model.OnmsSeverity in project opennms by OpenNMS.
the class IfTttDaemon method startPoller.
/**
* Initializes and starts the alarm poller.
*
* @param pollInterval the poller interval to be used
*/
private void startPoller(final long pollInterval) {
LOG.debug("Starting alarm poller (interval {}s).", pollInterval);
m_alarmPoller = Executors.newScheduledThreadPool(1);
m_alarmPoller.scheduleWithFixedDelay(new Runnable() {
private Map<Boolean, Map<String, Integer>> oldAlarmCount = new HashMap<>();
private Map<Boolean, Map<String, OnmsSeverity>> oldSeverity = new HashMap<>();
{
oldAlarmCount.put(Boolean.TRUE, new HashMap<>());
oldAlarmCount.put(Boolean.FALSE, new HashMap<>());
oldSeverity.put(Boolean.TRUE, new HashMap<>());
oldSeverity.put(Boolean.FALSE, new HashMap<>());
}
private List<OnmsAlarm> filterAlarms(List<OnmsAlarm> alarms, TriggerPackage triggerPackage) {
if (triggerPackage.getOnlyUnacknowledged()) {
return alarms.stream().filter(alarm -> alarm.getNodeId() != null).filter(alarm -> !alarm.isAcknowledged()).filter(alarm -> Strings.isNullOrEmpty(triggerPackage.getCategoryFilter()) || alarm.getNode().getCategories().stream().anyMatch(category -> category.getName().matches(triggerPackage.getCategoryFilter()))).collect(Collectors.toList());
} else {
return alarms.stream().filter(alarm -> alarm.getNodeId() != null).filter(alarm -> Strings.isNullOrEmpty(triggerPackage.getCategoryFilter()) || alarm.getNode().getCategories().stream().anyMatch(category -> category.getName().matches(triggerPackage.getCategoryFilter()))).collect(Collectors.toList());
}
}
@Override
public void run() {
try {
final IfTttConfig ifTttConfig = m_fileReloadContainer.getObject();
if (ifTttConfig.getPollInterval() != pollInterval) {
restartPoller(ifTttConfig.getPollInterval());
return;
}
if (!ifTttConfig.getEnabled()) {
LOG.debug("Disabled - skipping alarm polling.");
return;
}
transactionOperations.execute(new TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
// Retrieve the alarms with an associated node and filter for matching categories.
final CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsAlarm.class).isNotNull("node").gt("severity", OnmsSeverity.NORMAL);
final List<OnmsAlarm> alarms = alarmDao.findMatching(criteriaBuilder.toCriteria());
for (final TriggerPackage triggerPackage : ifTttConfig.getTriggerPackages()) {
if (!oldSeverity.get(triggerPackage.getOnlyUnacknowledged()).containsKey(triggerPackage.getCategoryFilter())) {
oldSeverity.get(triggerPackage.getOnlyUnacknowledged()).put(triggerPackage.getCategoryFilter(), OnmsSeverity.INDETERMINATE);
oldAlarmCount.get(triggerPackage.getOnlyUnacknowledged()).put(triggerPackage.getCategoryFilter(), 0);
}
final List<OnmsAlarm> filteredAlarms = filterAlarms(alarms, triggerPackage);
// Compute the maximum severity.
final Optional<OnmsSeverity> maxAlarmsSeverity = filteredAlarms.stream().map(OnmsAlarm::getSeverity).max(Comparator.naturalOrder());
final OnmsSeverity newSeverity = maxAlarmsSeverity.orElse(OnmsSeverity.NORMAL);
final int newAlarmCount = filteredAlarms.size();
LOG.debug("Received {} filtered, {} new severity", newAlarmCount, newSeverity);
final DefaultVariableNameExpansion defaultVariableNameExpansion = new DefaultVariableNameExpansion(oldSeverity.get(triggerPackage.getOnlyUnacknowledged()).get(triggerPackage.getCategoryFilter()), newSeverity, oldAlarmCount.get(triggerPackage.getOnlyUnacknowledged()).get(triggerPackage.getCategoryFilter()), newAlarmCount);
if (!newSeverity.equals(oldSeverity.get(triggerPackage.getOnlyUnacknowledged()).get(triggerPackage.getCategoryFilter())) || newAlarmCount != oldAlarmCount.get(triggerPackage.getOnlyUnacknowledged()).get(triggerPackage.getCategoryFilter())) {
fireIfTttTriggerSet(ifTttConfig, triggerPackage.getCategoryFilter(), newSeverity, defaultVariableNameExpansion);
}
LOG.debug("Old severity: {}, new severity: {}, old alarm count: {}, new alarm count: {}", oldSeverity.get(triggerPackage.getOnlyUnacknowledged()).get(triggerPackage.getCategoryFilter()), newSeverity, oldAlarmCount.get(triggerPackage.getOnlyUnacknowledged()).get(triggerPackage.getCategoryFilter()), newAlarmCount);
oldSeverity.get(triggerPackage.getOnlyUnacknowledged()).put(triggerPackage.getCategoryFilter(), newSeverity);
oldAlarmCount.get(triggerPackage.getOnlyUnacknowledged()).put(triggerPackage.getCategoryFilter(), newAlarmCount);
}
}
});
} catch (Exception e) {
LOG.error("Error while polling alarm table.", e);
} finally {
LOG.debug("Run complete. Next poll in {}s.", pollInterval);
}
}
}, pollInterval, pollInterval, TimeUnit.SECONDS);
}
use of org.opennms.netmgt.model.OnmsSeverity in project opennms by OpenNMS.
the class PathOutageStatusProvider method getStatusForVertices.
@Override
public Map<VertexRef, Status> getStatusForVertices(VertexProvider vertexProvider, Collection<VertexRef> vertices, Criteria[] criteria) {
final List<Integer> nodeIds = vertices.stream().filter(v -> v.getNamespace().equals(getNamespace())).map(v -> (PathOutageVertex) v).map(v -> v.getNodeID()).collect(Collectors.toList());
if (nodeIds.isEmpty()) {
return new HashMap<>();
}
// Preparing database request
final StringBuilder hql = new StringBuilder();
hql.append("SELECT node.id, max(event.eventSeverity) ");
hql.append("FROM OnmsOutage as outage ");
hql.append("LEFT JOIN outage.monitoredService as ifservice ");
hql.append("LEFT JOIN ifservice.ipInterface as ipinterface ");
hql.append("LEFT JOIN ipinterface.node as node ");
hql.append("LEFT JOIN outage.serviceLostEvent as event ");
hql.append("WHERE node.id in (:nodeIds) ");
hql.append("AND outage.serviceRegainedEvent is null ");
hql.append("GROUP BY node.id");
final List<String> paramNames = Lists.newArrayList("nodeIds");
final List<Object> paramValues = new ArrayList();
paramValues.add(Lists.newArrayList(nodeIds));
final List<Object[]> retvals = this.persistenceAccessor.findUsingNamedParameters(hql.toString(), paramNames.toArray(new String[paramNames.size()]), paramValues.toArray());
// Generating alarms map
final Map<Integer, OnmsSeverity> mappedAlarms = new HashedMap();
for (int i = 0; i < retvals.size(); i++) {
final Integer nodeId = (Integer) retvals.get(i)[0];
final Integer severity = Optional.ofNullable((Integer) retvals.get(i)[1]).orElse(OnmsSeverity.NORMAL.ordinal());
mappedAlarms.put(nodeId, OnmsSeverity.get(severity));
}
final Map<VertexRef, Status> status = vertices.stream().map(v -> (PathOutageVertex) v).collect(Collectors.toMap(v -> v, v -> {
if (!mappedAlarms.containsKey(v.getNodeID())) {
return new DefaultStatus(OnmsSeverity.NORMAL.getLabel(), 0);
} else {
return new DefaultStatus(mappedAlarms.get(v.getNodeID()).getLabel(), 0);
}
}));
return status;
}
use of org.opennms.netmgt.model.OnmsSeverity in project opennms by OpenNMS.
the class OnmsAlarmOssjMapper method populateOnmsAlarmFromOssjAlarm.
// ****************
// Business methods
// ****************
/**
* 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 {
String logheader = this.getClass().getSimpleName() + "populateOnmsAlarmFromOssjAlarm():";
try {
String ossPrimaryKey = alarmValue.getAlarmKey().getAlarmPrimaryKey();
String applicationDN = alarmValue.getAlarmKey().getApplicationDN();
LOG.debug("{} AlarmPrimaryKey: {} ApplictionDN: {} alarmRaisedTime: {}", logheader, ossPrimaryKey, applicationDN, alarmValue.getAlarmRaisedTime());
if ((applicationDN == null) || (applicationDN.equals("")) || (ossPrimaryKey == null) || (ossPrimaryKey.equals(""))) {
LOG.error("{} ApplicatioDN or PrimaryKey not set", logheader);
} else {
LOG.debug("{} trying to find existing alarm using getCurrentAlarmForUniqueKey", logheader);
onmsAlarm = ossDao.getCurrentAlarmForUniqueKey(applicationDN, ossPrimaryKey);
if (onmsAlarm != null) {
// already an alarm with this unique id - log error
LOG.error("{} Alarm Already exists with this Unique ID", logheader);
} else {
onmsAlarm = new OnmsAlarm();
onmsAlarm.setUei(ossjAlarmTypeToUei(alarmValue.getAlarmType()));
onmsAlarm.setX733AlarmType((alarmValue.getAlarmType() == null) ? "" : alarmValue.getAlarmType());
onmsAlarm.setX733ProbableCause(alarmValue.getProbableCause());
// needed?
onmsAlarm.setTTicketState(null);
// needed?
onmsAlarm.setTTicketId("");
onmsAlarm.setQosAlarmState("");
// needed?
onmsAlarm.setSuppressedUser("");
// needed?
onmsAlarm.setSuppressedUntil(new Date());
// needed?
onmsAlarm.setSuppressedTime(new Date());
OnmsSeverity onmsseverity;
try {
onmsseverity = ossjSeveritytoOnmsSeverity(alarmValue.getPerceivedSeverity());
} catch (IllegalArgumentException iae) {
LOG.error("{} problem setting severity used default:'WARNING'.", logheader, iae);
onmsseverity = OnmsSeverity.WARNING;
}
onmsAlarm.setSeverity(onmsseverity);
OnmsServiceType service = new OnmsServiceType();
service.setId(new Integer(-1));
// needed?
onmsAlarm.setServiceType(new OnmsServiceType());
onmsAlarm.setReductionKey(":managedObjectInstance:" + alarmValue.getManagedObjectInstance() + ":managedObjectType:" + alarmValue.getManagedObjectClass() + ":ossPrimaryKey:-" + ossPrimaryKey + ":applicationDN:-" + // must be unique because of alarm_reductionkey_idx
applicationDN);
onmsAlarm.setOssPrimaryKey(ossPrimaryKey);
onmsAlarm.setOperInstruct(alarmValue.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));
//
onmsAlarm.setNode(node);
if (almUpdateBehaviour == null) {
LOG.error("{} This receiver's alarmUpdateBehaviour is not set: defaulting to update nodeID:1", logheader);
} else {
LOG.debug("{} alarmUpdateBehaviour:{} {}", logheader, 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.
LOG.debug("{} SPECIFY_OUTSTATION looking for node with nodelabel:{}", logheader, defaultUpdateNodeLabel);
try {
// TODO temp remove ?
try {
node = ossDao.findNodeByLabel(defaultUpdateNodeLabel);
} 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 name:{} setting node id to NodeLabel:{} NodeID:{}", logheader, defaultUpdateNodeLabel, node.getLabel(), node.getId());
// maps into FIRST instance of node with the same managedObjectInstance and managedObjectType
onmsAlarm.setNode(node);
} else {
LOG.error("{} alarmUpdateBehaviour.equals(SPECIFY_OUTSTATION): NODE NOT FOUND for this name:{} setting node id to default NodeID: 1", logheader, defaultUpdateNodeLabel);
// TODO remove ossDao.makeExtendedOnmsNode();
node = new OnmsNode();
// node id cannot be null
node.setId(new Integer(1));
//
onmsAlarm.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 = alarmValue.getManagedObjectClass();
String managedObjectInstance = alarmValue.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, defaultUpdateNodeLabel, node.getLabel(), node.getId());
// maps into FIRST instance of node with the same managedObjectInstance and managedObjectType
onmsAlarm.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));
//
onmsAlarm.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, getAlarmUpdateBehaviourForInt(almUpdateBehaviour));
}
}
// needed?
onmsAlarm.setMouseOverText("");
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);
// needed?
onmsAlarm.setIpAddr(InetAddressUtils.getLocalHostAddress());
// set null as updating alarm
onmsAlarm.setId(null);
onmsAlarm.setFirstEventTime(alarmValue.getAlarmRaisedTime());
onmsAlarm.setLastEventTime(alarmValue.getAlarmChangedTime());
onmsAlarm.setDistPoller(distPollerDao.whoami());
// TODO need Qosd Not to generate this if remote
onmsAlarm.setDescription(alarmValue.getAdditionalText());
onmsAlarm.setCounter(new Integer(1));
onmsAlarm.setApplicationDN(applicationDN);
// set to raise alarm
onmsAlarm.setAlarmType(new Integer(1));
// alarm.setAlarmAckUser(arg0);
// alarm.setAlarmAckTime(arg0);
LOG.debug("{} Creating Alarm", logheader);
}
}
} catch (Throwable e) {
LOG.error("{} Error : ", logheader, e);
}
return onmsAlarm;
}
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.rometools.rome.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<>();
List<Filter> filters = new ArrayList<>();
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