Search in sources :

Example 1 with AlarmValue

use of javax.oss.fm.monitor.AlarmValue 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");
    }
}
Also used : AlarmKey(javax.oss.fm.monitor.AlarmKey) Hashtable(java.util.Hashtable) OOSSAlarmValue(org.openoss.ossj.jvt.fm.monitor.OOSSAlarmValue) AlarmValue(javax.oss.fm.monitor.AlarmValue) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException)

Aggregations

UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 Hashtable (java.util.Hashtable)1 AlarmKey (javax.oss.fm.monitor.AlarmKey)1 AlarmValue (javax.oss.fm.monitor.AlarmValue)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 OOSSAlarmValue (org.openoss.ossj.jvt.fm.monitor.OOSSAlarmValue)1