use of javax.oss.fm.monitor.AlarmKey in project opennms by OpenNMS.
the class OnmsAlarmOssjMapper method populateOssjAlarmFromOpenNMSAlarm.
/**
* This method maps OpenNMS alarm to an OSS/J alarms and adds additional information
*
* @param _openNMSalarm data to use to populate the OSS/J alarm
* @param alarmValueSpecification AlarmValue object to be populated - Invariant (Specifcation) values should be already populated
* @return the _av OSS/J AlarmValue populated with opennms data
* @throws java.lang.IllegalArgumentException if any.
* @throws javax.oss.UnsupportedAttributeException if any.
*/
public AlarmValue populateOssjAlarmFromOpenNMSAlarm(AlarmValue alarmValueSpecification, OnmsAlarm _openNMSalarm) throws IllegalArgumentException, UnsupportedAttributeException {
String logheader = this.getClass().getSimpleName() + "populateOssjAlarmFromOpenNMSAlarm():";
//Node node = null;
OnmsNode node = null;
// Asset asset = null;
OnmsAssetRecord asset = null;
// true if alarm is received from Qosdrx
boolean isQoSDrxAlarm = false;
LOG.debug("{} Populating alarm", logheader);
// come from Qosdrx.
if ((_openNMSalarm.getManagedObjectInstance() != null) && (_openNMSalarm.getManagedObjectType() != null) && (!_openNMSalarm.getManagedObjectInstance().equals("")) && (!_openNMSalarm.getManagedObjectType().equals(""))) {
isQoSDrxAlarm = true;
LOG.debug("{} isQoSDrxAlarm TRUE - because OpenNMS alarm has ManagedObjectInstance and ManagedObjectType", logheader);
} else {
isQoSDrxAlarm = false;
LOG.debug("{} isQoSDrxAlarm FALSE - because OpenNMS alarm NOT POPULATED ManagedObjectInstance and ManagedObjectType", logheader);
}
try {
// in the OSS/J alarm
if ((null != _openNMSalarm.getAlarmAckTime()) && (null != _openNMSalarm.getAlarmAckUser())) {
alarmValueSpecification.setAckUserId(_openNMSalarm.getAlarmAckUser());
// OnmsAlarm can contain java.sql.Timestamp - convert to Date
alarmValueSpecification.setAckTime(new Date(_openNMSalarm.getAlarmAckTime().getTime()));
alarmValueSpecification.setAlarmAckState(AlarmAckState.ACKNOWLEDGED);
} else {
alarmValueSpecification.setAlarmAckState(AlarmAckState.UNACKNOWLEDGED);
}
// the clear occured.
if (_openNMSalarm.getSeverity() == OnmsSeverity.CLEARED) {
// OnmsAlarm can contain java.sql.Timestamp - convert to Date
alarmValueSpecification.setAlarmClearedTime(new Date(_openNMSalarm.getLastEventTime().getTime()));
} else {
alarmValueSpecification.setAlarmClearedTime(null);
}
// OnmsAlarm can contain java.sql.Timestamp - convert to Date
if (null != _openNMSalarm.getFirstEventTime()) {
alarmValueSpecification.setAlarmRaisedTime(new Date(_openNMSalarm.getFirstEventTime().getTime()));
}
if (null != _openNMSalarm.getLastEventTime()) {
alarmValueSpecification.setAlarmChangedTime(new Date(_openNMSalarm.getLastEventTime().getTime()));
}
} catch (Throwable e) {
LOG.error("{} Problem getting ACK time information", logheader, e);
}
Matcher matcher = null;
String _uei_no_html = "NOT_SET";
try {
String uei = _openNMSalarm.getUei();
if (null != uei) {
matcher = p.matcher(uei);
// remove any HTML tags from uei
_uei_no_html = matcher.replaceAll(" ");
}
alarmValueSpecification.setAlarmType((_openNMSalarm.getX733AlarmType() == null) ? javax.oss.fm.monitor.AlarmType.EQUIPMENT_ALARM : _openNMSalarm.getX733AlarmType());
} catch (Throwable e) {
LOG.error("{} Problem getting X733AlarmType or Uei", logheader, e);
}
// Get some local node information as to where the alarm came from
// This includes, what type of managed element the node is
// and what its node id and label are.*/
// String mftr = "NOT_SET"; // FIXME: Not read
// String modelNo = "NOT_SET"; // FIXME: Not read
// String assetserno = "NOT_SET"; // FIXME: Not read
// String nodelabel = "NOT_SET"; // FIXME: Not read
// String alarmIP = "NOT_SET"; // FIXME: Not read
String managedObjectType = "NOT_SET";
String managedObjectInstance = "NOT_SET";
String assetManagedObjectType = "NOT_SET";
String assetManagedObjectInstance = "NOT_SET";
String assetDescription = "NOT_SET";
String assetAddress2 = "NOT_SET";
if (!isQoSDrxAlarm) {
// if is locally generated alarm
try {
// set default values if no node information present
if (_openNMSalarm.getNode() != null) {
node = ossDao.findNodeByID(_openNMSalarm.getNode().getId());
asset = node.getAssetRecord();
// }
if (asset != null) {
// TODO was used for managed object class as is 128 char long
if (asset.getDescription() != null)
assetDescription = asset.getDescription();
// TODO was used for managed object instance - as is 256 char long string
if (asset.getAddress2() != null)
assetAddress2 = asset.getAddress2();
if (asset.getManagedObjectInstance() != null)
assetManagedObjectInstance = asset.getManagedObjectInstance();
if (asset.getManagedObjectType() != null)
assetManagedObjectType = asset.getManagedObjectType();
}
managedObjectInstance = assetManagedObjectInstance;
managedObjectType = assetManagedObjectType;
LOG.debug("{} isQoSDrxAlarm=FALSE OpenNMS type and instance not set. Using from Node Asset record: ManagedObjectInstance: {} ManagedObjectType:{}", logheader, managedObjectInstance, managedObjectType);
}
} catch (Throwable ex) {
LOG.error("{} Problem getting node and asset information", logheader, ex);
}
} else {
// is a received alarm
try {
managedObjectInstance = _openNMSalarm.getManagedObjectInstance();
managedObjectType = _openNMSalarm.getManagedObjectType();
LOG.debug("{} isQoSDrxAlarm=FALSE OpenNMS type and instance not set. Using from Node Asset record: ManagedObjectInstance: {} ManagedObjectType:{}", logheader, managedObjectInstance, managedObjectType);
} catch (Throwable ex) {
LOG.error("{} Problem managedObjectInstance or managedObjectType", logheader, ex);
}
}
alarmValueSpecification.setManagedObjectClass(managedObjectType);
LOG.debug("{} _av.setManagedObjectClass set to: ", logheader, managedObjectType);
alarmValueSpecification.setManagedObjectInstance(managedObjectInstance);
LOG.debug("{} _av.setManagedObjectInstance set to: ", logheader, managedObjectInstance);
// set severity and probable cause
try {
alarmValueSpecification.setPerceivedSeverity(onmsSeverityToOssjSeverity(_openNMSalarm.getSeverity()));
// alarmValueSpecification.setProbableCause((short)-1); // OSS/J set to -1 then text contains description
alarmValueSpecification.setProbableCause((short) _openNMSalarm.getX733ProbableCause());
} catch (Throwable e) {
LOG.error("{} Problem getting severity or probable cause: ", logheader, e);
}
if (!isQoSDrxAlarm) {
try {
String _opinstr = _openNMSalarm.getOperInstruct();
if (null != _opinstr) {
matcher = p.matcher(_opinstr);
// remove all HTML tags from operator instructions
_opinstr = matcher.replaceAll(" ");
} else
_opinstr = "NOT_SET";
alarmValueSpecification.setProposedRepairActions(_opinstr);
String _logmsg = _openNMSalarm.getLogMsg();
if (null != _logmsg) {
matcher = p.matcher(_logmsg);
// remove all HTML tags from operator instructions
_logmsg = matcher.replaceAll(" ");
} else
_logmsg = "NOT_SET";
String _description = _openNMSalarm.getDescription();
if (null != _description) {
matcher = p.matcher(_description);
// remove all HTML tags from description
_description = matcher.replaceAll(" ");
} else
_description = "NOT_SET";
// using manufacturers own definition of specific problem here ( OSS/J )
alarmValueSpecification.setSpecificProblem(_logmsg);
Integer alarmid = _openNMSalarm.getId();
Integer counter = _openNMSalarm.getCounter();
String reductionkey = _openNMSalarm.getReductionKey();
// note some OnmsAlarms can have null nodes - we use a default value of 0 for ID
Integer nodeid = 0;
String onmsnodelabel = "";
if (_openNMSalarm.getNode() != null) {
nodeid = _openNMSalarm.getNode().getId();
onmsnodelabel = _openNMSalarm.getNode().getLabel();
}
InetAddress ipaddress = _openNMSalarm.getIpAddr();
String x733AlarmType = _openNMSalarm.getX733AlarmType();
String x733ProbableCause;
try {
x733ProbableCause = OOSSProbableCause.getStringforEnum((short) _openNMSalarm.getX733ProbableCause());
} catch (Throwable e) {
x733ProbableCause = "X733 Probable Cause Incorrectly Defined";
}
alarmValueSpecification.setAdditionalText("<alarmid>" + alarmid + "</alarmid>" + "\n " + "<logmsg>" + _logmsg + "</logmsg>" + "\n " + "<uei>" + _uei_no_html + "<uei>" + "\n " + "<x733AlarmType>" + x733AlarmType + "</x733AlarmType>" + "\n " + "<x733ProbableCause>" + x733ProbableCause + "</x733ProbableCause>" + "\n " + "<counter>" + counter + "</counter>" + "\n " + "<reductionkey>" + reductionkey + "</reductionkey>" + "\n " + "<nodeid>" + nodeid + "</nodeid>" + "\n " + "<nodelabel>" + onmsnodelabel + "</nodelabel>" + "\n " + "<ipaddress>" + InetAddressUtils.toIpAddrString(ipaddress) + "</ipaddress>" + "\n " + "<description>" + _description + "</description>" + "\n " + "<opinstr>" + _opinstr + "</opinstr>" + "\n " + "<asset.managedobjectinstance>" + assetManagedObjectInstance + "</asset.managedobjectinstance>" + //TODO - was used for object instance
"\n " + "<asset.managedobjecttype>" + assetManagedObjectType + "</asset.managedobjecttype>" + "\n " + "<asset.address2>" + assetAddress2 + "</asset.address2>" + //TODO - was used for object instance
"\n " + "<asset.description>" + assetDescription + "</asset.description>" + //TODO - was used for object instancetype
"\n");
} catch (Throwable e) {
LOG.error("{} Problem setting description, logmessage or operator instrctions: ", logheader, e);
}
} else {
// is a received alarm
try {
String _opinstr = _openNMSalarm.getOperInstruct();
if (null == _opinstr)
_opinstr = "NOT_SET";
alarmValueSpecification.setProposedRepairActions(_opinstr);
String _logmsg = _openNMSalarm.getLogMsg();
if (null == _logmsg)
_logmsg = "NOT_SET";
// using manufacturers own definition of specific problem here ( OSS/J )
alarmValueSpecification.setSpecificProblem(_logmsg);
String _description = _openNMSalarm.getDescription();
if (null == _description)
_description = "NOT_SET";
alarmValueSpecification.setAdditionalText(_description);
} catch (Throwable e) {
LOG.error("{} Problem setting description, logmessage or operator instrctions: ", logheader, e);
}
}
// TODO replacement method to populate the alarm key
try {
//populate alarm key
//TODO was AlarmKey ak = new OOSSAlarmKey(Integer.toString(_openNMSalarm.getId()));
AlarmKey ak = alarmValueSpecification.getAlarmKey();
ak.setAlarmPrimaryKey(Integer.toString(_openNMSalarm.getId()));
ak.setPrimaryKey(ak.getAlarmPrimaryKey());
} catch (Throwable e) {
LOG.error("{} Problem setting AlarmKey: ", logheader, e);
}
LOG.debug("{} Alarm Populated", logheader);
return alarmValueSpecification;
}
use of javax.oss.fm.monitor.AlarmKey in project opennms by OpenNMS.
the class QoSDimpl2 method sendAlarms.
/**
* A method to request an alarm list from the OpenNMS database using the ossDao,
* convert them to OSS/J alarms using the onmsAlarmOssjMapper and send the OSS/J alarms
* using the alarm list connection manager (alcm) to update the the AlarmMonitor bean.
* This is called from ossDao every time there is an update to the database.
*/
@Override
public void sendAlarms() {
Hashtable<AlarmKey, AlarmValue> ossjAlarmUpdateList = new Hashtable<AlarmKey, AlarmValue>();
OnmsAlarm[] onmsAlarmUpdateList = null;
AlarmValue ossjAlarm;
try {
LOG.debug("sendAlarms() using ossDao to get current alarm list");
onmsAlarmUpdateList = ossDao.getAlarmCache();
} catch (Throwable ex) {
//problems contacting the PostgreSQL database
LOG.error("sendAlarms() Cannot retrieve alarms from ossDao.getAlarmCache()", ex);
throw new UndeclaredThrowableException(ex, "sendAlarms() Cannot retrieve alarms from ossDao.getAlarmCache()");
}
LOG.debug("sendAlarms() Alarms fetched. Processing each alarm in list.");
// Convert the OnmsAlarm array alarmBuf to a hashtable using the alarmid as the key.
try {
for (int i = 0; i < onmsAlarmUpdateList.length; i++) {
LOG.debug("sendAlarms() processing an OpenNMS alarm:");
// QosD-configuration.xml file will be included in the list.
if (useUeiList) {
LOG.debug("sendAlarms() useUeiList= true: using UeiList to determine alarms to send");
if (null == triggerUeiList.get(onmsAlarmUpdateList[i].getUei())) {
LOG.debug("sendAlarms() alarm UEI not in QosD-configuration.xml. Not sending. alarmID:{} alarmUEI:{}", onmsAlarmUpdateList[i].getId(), onmsAlarmUpdateList[i].getUei());
// ignore this event and return
continue;
}
LOG.debug("sendAlarms() alarm UEI is in QosD-configuration.xml. Trying to send alarmID:{} alarmUEI:{}", onmsAlarmUpdateList[i].getId(), onmsAlarmUpdateList[i].getUei());
}
if (onmsAlarmUpdateList[i].getAlarmType() != 1) {
LOG.debug("sendAlarms() Alarm AlarmType !=1 ( not raise alarm ) Not sending alarmID:{} :alarmBuf[i].getQosAlarmState()=: {}", onmsAlarmUpdateList[i].getId(), onmsAlarmUpdateList[i].getQosAlarmState());
continue;
} else {
LOG.debug("sendAlarms() Alarm AlarmType==1 ( raise alarm ) Sending alarmID:{} :alarmBuf[i].getQosAlarmState()=: {}", onmsAlarmUpdateList[i].getId(), onmsAlarmUpdateList[i].getQosAlarmState());
try {
// Code which creates the OSSJ AlarmValue from the Spring OSS?J AlarmValue Specification
LOG.debug("sendAlarms(): generating the OSS/J alarm specification:");
ossjAlarm = alarmListConnectionManager.makeAlarmValueFromSpec();
LOG.debug("sendAlarms(): OSS/J alarm specification:{}", OOSSAlarmValue.converttoString(ossjAlarm));
// Code which creates the OSSJ AlarmValue from the Spring OSS/J AlarmValue Specification
LOG.debug("sendAlarms(): onmsAlarmOssjMapper.populateOssjAlarmFromOpenNMSAlarm:");
ossjAlarm = onmsAlarmOssjMapper.populateOssjAlarmFromOpenNMSAlarm(ossjAlarm, onmsAlarmUpdateList[i]);
LOG.debug("buildList(): alarm specifcation: {}", OOSSAlarmValue.converttoString(ossjAlarm));
// TODO selector on ACKNOWLEDGED and CLEARED - currently always sends all alarms in list
if (true)
try {
// alarms which are ACKNOWLEDGED and CLEARED are included in this current alarm list
LOG.debug("sendAlarms() including ACKNOWLEDGED and CLEARED alarms in alarm in list");
ossjAlarmUpdateList.put(ossjAlarm.getAlarmKey(), ossjAlarm);
} catch (Throwable e) {
LOG.error("sendAlarms() error putting alarm in alarmList", e);
}
//TODO - THIS CODE NEVER RUN
/*
else try {
// no alarms which are ACKNOWLEDGED and CLEARED are included in this current alarm list
if (ossjAlarm.getAlarmAckState() == javax.oss.fm.monitor.AlarmAckState.UNACKNOWLEDGED ) {
ossjAlarmUpdateList.put(ossjAlarm.getAlarmKey(), ossjAlarm); // put all unacknowledged alarms in list
}
else if (ossjAlarm.getPerceivedSeverity() != javax.oss.fm.monitor.PerceivedSeverity.CLEARED ){
ossjAlarmUpdateList.put(ossjAlarm.getAlarmKey(), ossjAlarm); // put all uncleared acknowledged alarms in list
}
} catch (Throwable e) {
log.error("sendAlarms() error in alarmACKState or PercievedSeverity - check alarm definitons", e);
}*/
} catch (Throwable ex) {
LOG.error("sendAlarms() error trying to populate alarm - alarm disguarded - check alarm definitons", ex);
}
}
}
} catch (Throwable ex) {
LOG.error("Qosd.sendAlarms(): Problem when building alarm list:", ex);
throw new UndeclaredThrowableException(ex, "Qosd.sendAlarms(): Problem when building alarm list");
}
try {
// debug code prints out alarm list to be sent if enabled
if (LOG.isDebugEnabled()) {
LOG.debug("QosD sendAlarms() - Alarm list built:");
LOG.debug("QosD sendAlarms() - ******* Alarm List to be sent : primary keys");
for (Entry<AlarmKey, AlarmValue> entry : ossjAlarmUpdateList.entrySet()) {
LOG.debug("QosD sendAlarms() key:{} AlarmValue.getAlarmChangedTime: {}", entry.getKey().getPrimaryKey(), entry.getValue().getAlarmChangedTime());
}
LOG.debug("QosD sendAlarms() - ******* END OF LIST");
LOG.debug("QosD sendAlarms() Sending alarm list to bean");
}
//send the alarmList to Ossbeans EJB or local runner via the connection manager thread.
alarmListConnectionManager.send(ossjAlarmUpdateList);
} catch (Throwable ex) {
LOG.error("Qosd.sendAlarms(): Problem when sending alarm list:", ex);
throw new UndeclaredThrowableException(ex, "Qosd.sendAlarms(): Problem when sending alarm list");
}
}
Aggregations