Automations
Subscribe

From OpenNMS

Jump to: navigation, search

As of version 1.3, OpenNMS provides you with a more robust solution by automating its behavior to meet the requirements of your business or organization. For example, say you have an alarm with the severity of "Minor" that has not been acknowledged in the last twenty minutes - you might want to escalate the severity.

OpenNMS has a daemon that runs SQL statements on an interval called Vacuumd. Its configuration has been enhanced with a configuration that now allows configuration of processes we're calling Automations that are defined by Triggers and Actions.

Contents

Automation attributes

An automation is made up of trigger and actions statments that can query and update tables in the OpenNMS database (the next release will allow processing of external databases). The OpenNMS automation is defined with the following attributes (ones marked with a "*" are required):

name (*) 
A string that identifies the automation
interval (*) 
An integer specifying, in milliseconds, how often to run the automation
trigger-name 
A string that references a trigger by its name attribute
action-name (*) 
A string that references an action by its name attribute
action-event 
A string that references an action-event by its name attribute

Triggers

A trigger is defined with 3 attributes and an SQL statement. The trigger's statement is designed to be an SQL DQL select statement. The results of the query are analyzed and processed by the action statement.

A trigger has the following attributes (ones marked with a "*" are required):

name 
String identifying the name of the trigger referenced by the automation attribute 'trigger-name'
row-count 
Used with the operator attribute to determine if the action should be executed
operator 
Used with the row-count attribute to determine if the action should be executed

Actions

The action, unlike a trigger, is required for an automation. Its SQL is designed to be a DML statement that can be executed against the result set of an automation or it can be executed independently.

Actions that process trigger results will usually require access to the data from the columns specified in the DQL statement. To access this column data, specify the column using the format '${<column name>}'. For example, to update the severity of all alarms returned in the result of a trigger (an escalation):

UPDATE alarms SET severity = least(7, severity+1)
 WHERE alarmid = ${alarmid}
   AND alarmAckUser is NULL

OpenNMS' AutomationProcessor class will analyze this statement and verify that the result set contains the required columns and will execute the update.

Action-events

An action-event defines an event to be sent. An action-event has the following attributes:

name 
String identifying the name of the trigger referenced by the automation attribute 'action-event'
for-each-result 
Boolean, default false. Controls whether the event is produced for every original event or just once

An action-event can have assignments, which have the following attributes:

type 
string, either "field" or "parameter"
name 
string, identifying the field or parameter
value 
string, the value for the field or parameter

You can put result columns from the SQL query into the new event. Say you had "select nodeid as _nodeid" in your SQL statement. You have to reference the name of the result column like this:

      <assignment type="field" name="nodeid" value="${_nodeid}" />

This will set the field nodeid to the _nodeid queried from the database.

Note: this does only work if you configure "for-each-result=true".

vacuumd-configuration.xml

Below, is a sample Vacuumd configuration file with examples for the old formatted statements as well as the new automation feature.

<VacuumdConfiguration period="86400000" >
  <statement>
     DELETE FROM node WHERE node.nodeType = 'D';
  </statement>

    <automations>
<!-- These are not fully tested -->
           <automation name="autoEscalate" interval="10000" trigger-name="selectWithCounter"
               auto-event-name="escalationEvent" action-name="escalate" active="true" />
           <automation name="cleanUpAlarms" interval="300000" action-name="deleteDayOldAlarms"
               active="true" />
           <automation name="cosmicClear" interval="30000" trigger-name="selectResolvers" 
               action-name="clearProblems" active="true" />
    </automations>
    <triggers>
           <trigger name="selectAll" operator=">=" row-count="1" >
               <statement>SELECT * FROM alarms</statement>
           </trigger>
           <trigger name="selectWithCounter" >
               <statement>SELECT alarmid FROM alarms WHERE counter >= 2</statement>
           </trigger>
                  <trigger name="selectResolvers" operator=">=" row-count="1" >
                      <statement>SELECT * FROM alarms WHERE alarmType=2</statement>
          </trigger>
    </triggers>
    <actions>
           <action name="clear" >
               <statement>UPDATE alarms SET severity=2 WHERE alarmid = ${alarmid}</statement>
           </action>
           <action name="clearProblems" >
               <statement>UPDATE alarms SET severity=2 WHERE alarmType=1 
                   AND lastEventTime <=  ${lastEventTime} AND severity > 2 
                   AND eventUei = ${clearUei} AND dpName = ${dpName} 
                   and nodeID = ${nodeID} and ipaddr = ${ipaddr} and serviceID = ${serviceID}
               </statement>
               <!-- <statement>UPDATE alarms SET severity=2 WHERE alarmType=1 AND severity > 2
                        AND dpName = ${dpName} and nodeID = ${nodeID} and ipaddr = ${ipaddr}
                        and serviceID = ${serviceID}
                    </statement> -->
           </action>
           <action name="escalate" >
               <statement>UPDATE alarms SET severity = severity+1 WHERE alarmid = ${alarmid} 
                   and severity < 7 and alarmAckUser is null</statement>
           </action>
           <action name="delete" >
               <statement>DELETE FROM alarms WHERE nodeid = ${nodeid} 
                   and eventuei = ${eventuei}</statement>
           </action>
           <action name="deleteDayOldAlarms" >
               <statement>DELETE FROM alarms WHERE alarmAckUser IS NOT NULL 
                   AND lastEventTime < CURRENT_TIMESTAMP</statement>
           </action>
    </actions>
    <auto-events>
        <auto-event name="escalationEvent" >
            <uei>uei.opennms.org/vacuumd/alarmEscalated</uei>
        </auto-event>
    </auto-events>

</VacuumdConfiguration>

See also Alarms and Configure_event_reduction_using_automations.

If you need to add information or transform events when they are created, you should have a look at Event_Translator.