Use node category membership in Drools rules for alarms

Description

Example automation we would like to accomplish with Drools rules:

<automation name="escalationEMERGENCYF0" interval="30000" active="true" trigger-name="selectEmergencyF0NodeAlarms" action-name="escalateAlarm" action-event="sendAlarmEscalatedEvent" />
<trigger name="selectEmergencyF0NodeAlarms" operator=">=" row-count="1" > <statement> SELECT a.alarmid AS _alarmid, now() AS _ts FROM alarms a LEFT JOIN category_node cn ON cn.nodeid = a.nodeid LEFT JOIN categories ca ON ca.categoryid = cn.categoryid WHERE ( a.eventuei = 'uei.opennms.org/nodes/nodeDown' OR a.eventuei = 'uei.opennms.org/nodes/interfaceDown') AND ca.categoryname = 'EMERGENCY_F0' AND severity > 3 AND severity < 7 </statement> </trigger>

Acceptance / Success Criteria

None

Lucidchart Diagrams

Activity

Show:

Jesse White March 21, 2019 at 2:32 PM

Jesse White March 6, 2019 at 5:00 PM

I think we may need to patch alarmd with something like:

diff --git a/opennms-alarms/daemon/src/main/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContext.java b/opennms-alarms/daemon/src/main/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContext.java index a919bedf56c..2a37a82299c 100644 --- a/opennms-alarms/daemon/src/main/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContext.java +++ b/opennms-alarms/daemon/src/main/java/org/opennms/netmgt/alarmd/drools/DroolsAlarmContext.java @@ -381,6 +381,10 @@ public class DroolsAlarmContext extends ManagedDroolsContext implements AlarmLif // The last event may be null in unit tests Hibernate.initialize(alarm.getLastEvent().getEventParameters()); } + if (alarm.getNode() != null) { + // Allow rules to use the categories on the associated node + Hibernate.initialize(alarm.getNode().getCategories()); + } final AlarmAndFact alarmAndFact = alarmsById.get(alarm.getId());

in order to allow for the categories to be accessible and not throw lazy initialization exceptions.

Fixed

Details

Assignee

Reporter

Sprint

Fix versions

Affects versions

Priority

PagerDuty

Created March 6, 2019 at 4:59 PM
Updated June 3, 2019 at 8:05 AM
Resolved March 27, 2019 at 3:14 PM

Flag notifications