UIM - Send alarms via EMAIL on severity change (every first occurrence)
search cancel

UIM - Send alarms via EMAIL on severity change (every first occurrence)

book

Article ID: 125511

calendar_today

Updated On:

Products

DX Unified Infrastructure Management (Nimsoft / UIM) CA Unified Infrastructure Management On-Premise (Nimsoft / UIM) CA Unified Infrastructure Management SaaS (Nimsoft / UIM)

Issue/Introduction

Attached to this article is a script provided by development that will enable you to send every first occurrence of an alarm severity change via email.

Environment

  • UIM 20.x
  • NAS 9.06 and later

Cause

  • Guidance

Resolution

Please note that Broadcom Support does not support or maintain custom scripting, therefore the use of the script is on the responsibility of the user. 

If you do not have the emailgtw probe configured, please follow the documentation to configure the email gateway:

•  emailgtw (Email Gateway) Release Notes

•  Use emailgtw and NAS to send UIM alarms via email



1. Attached to this article is a custom script, download the script and place it into the nas directory (Nimsoft\probes\service\nas\scripts). 

NOTE: You will need to update the recipient email address in line 3: 

recipient    = "[email protected]" --Recipient's email/profile-name configured in emailgtw



2. Open the NAS GUI -> Auto Operator -> Profiles -> Right click "NEW" to configure a new AO profile: 

Action type = script 
Script = select the script in question (example: sendemailscript). 
Action mode = On message arrival 
Severity Level = select the severities you require (example: MINOR, MAJOR, CRITICAL)



NOTE: You can customize what message you would like to match on, hostname, probe, message string etc. 

3. Save the profile, apply the changes and the NAS probe will restart. 

Additional Information

Script:

 

--SCRIPT VERSION 1 --

require ("library/html-alarms-lib")

recipient    = "[email protected]" --Recipient's email/profile-name configured in emailgtw
-- Gets the ao-filtered alarm
a = alarm.get()
msg = pds.create ()
-- Add raw alarm data

 udata = pds.create()

 -- Create message header

    pds.putString (msg,"nimid",a.nimid)
    pds.putInt    (msg,"nimts",timestamp.now() )
    pds.putString (msg,"source",a.source)
    pds.putString (msg,"md5sum","")
    pds.putString (msg,"robot",a.robot)
    pds.putString (msg,"domain",a.domain)
    pds.putString (msg,"origin",a.origin)
    pds.putInt    (msg,"pri",a.level)
    pds.putString    (msg,"subject","EMAIL")   
    pds.putString (msg,"prid",a.prid)    
 -- Add raw alarm data
 
    pds.putInt(udata,"event_type",a.event_type)
    pds.putString(udata,"nimid",a.nimid)
    pds.putInt(udata,"nimts",a.nimts)
    pds.putInt(udata,"arrival",a.arrival)
    pds.putString(udata,"severity",a.severity)
    pds.putInt(udata,"level",a.level)
    pds.putString(udata,"subsys",a.subsys)
    pds.putString(udata,"message",a.message)
    pds.putString(udata,"source",a.source)
    pds.putString(udata,"hostname",a.hostname)
    pds.putString(udata,"sid",a.sid)
    pds.putString(udata,"domain",a.domain)
    pds.putString(udata,"hub",a.hub)
    pds.putString(udata,"nas",a.nas)
    pds.putString(udata,"robot",a.robot)
    pds.putString(udata,"origin",a.origin)
    pds.putString(udata,"prid",a.prid)
    pds.putInt(udata,"suppcount",a.suppcount)
    pds.putInt(udata,"tz_offset",a.tz_offset)
    pds.putInt(udata,"visible",a.visible)
    pds.putInt(udata,"aots",a.aots)
    pds.putString (udata,"ao_argument",recipient)
    pds.putPDS(msg,"udata",udata)
    
-- This will open the default user database 'user.db'
database.open("database.db")
rs = database.query("select level,prevlevel from NAS_ALARMS where nimid='"..a.nimid.."'")
if rs == nil then
   print ("Query did not complete, or had no results")
pds_putstring(a,"ao_argument",recipient)
nimbus.request ("spooler","hubpost",msg)
else
   for idx,row in pairs (rs ) do
      if( row['level'] ~= row['prevlevel']) then
          print "sending email "

            -- Post the message to the hub-spooler
            nimbus.request ("spooler","hubpost",msg)
        end
   end 
end
pds.delete (msg)
pds.delete (udata)
database.close()



 

 

--Additional notes--

This script essentially sends an email if thhe PREVLEVEL of an alarm is different from the LEVEL (the comparison is made in the NAS_ALARMS table)

 

In some cases, the PREVLEVEL of some alarms is not populated and remains as NULL. This makes the script to send the EMAIL as soon as the alarms arrives as the condition PREVLEVEL not equal to LEVEL is met:

 

To avoid this, the script can be modified as below with an additional condition: 

 

Replacing this: :

 

for idx,row in pairs (rs ) do
      if( row['level'] ~= row['prevlevel']) then
          print "sending email "

 

with this:

 

for idx,row in pairs (rs ) do

    if row['prevlevel'] ~= nil then

      if( row['level'] ~= row['prevlevel']) then
          print "sending email "


    end


Then it would only send the email if PREVLEVEL is already populated (not equal to null).

The complete script in that case would be:

 

 

--SCRIPT VERSION 2 --

require ("library/html-alarms-lib")

recipient    =
"recipient" --Recipient's email/profile-name configured in emailgtw

-- Gets the ao-filtered alarm

a = alarm.get ()
msg = pds.create ()

-- Add raw alarm data

 udata = pds.create()

 -- Create message header

    pds.putString (msg,"nimid",a.nimid)
    pds.putInt    (msg,"nimts",timestamp.now() )
   pds.putString (msg,"source",a.source)
   pds.putString (msg,"md5sum","")
   pds.putString (msg,"robot",a.robot)
   pds.putString (msg,"domain",a.domain)
   pds.putString (msg,"origin",a.origin)
   pds.putInt    (msg,"pri",a.level)
   pds.putString    (msg,"subject","EMAIL")  
   pds.putString (msg,"prid",a.prid)   

 -- Add raw alarm data

   pds.putInt(udata,"event_type",a.event_type)
   pds.putString(udata,"nimid",a.nimid)
   pds.putInt(udata,"nimts",a.nimts)
   pds.putInt(udata,"arrival",a.arrival)
   pds.putString(udata,"severity",a.severity)
   pds.putInt(udata,"level",a.level)
   pds.putString(udata,"subsys",a.subsys)
   pds.putString(udata,"message",a.message)
   pds.putString(udata,"source",a.source)
   pds.putString(udata,"hostname",a.hostname)
  pds.putString(udata,"sid",a.sid)
   pds.putString(udata,"domain",a.domain)
   pds.putString(udata,"hub",a.hub)
   pds.putString(udata,"nas",a.nas)
   pds.putString(udata,"robot",a.robot)
   pds.putString(udata,"origin",a.origin)
   pds.putString(udata,"prid",a.prid)
   pds.putInt(udata,"suppcount",a.suppcount)
   pds.putInt(udata,"tz_offset",a.tz_offset)
   pds.putInt(udata,"visible",a.visible)
   pds.putInt(udata,"aots",a.aots)
   pds.putString (udata,"ao_argument",recipient)
   pds.putPDS(msg,"udata",udata)
 

-- This will open the default user database 'user.db'

database.open("database.db")

rs = database.query("select level,prevlevel from NAS_ALARMS where nimid='"..a.nimid.."'")
if rs == nil then
  print ("Query did not complete, or had no results")
pds_putstring(a,"ao_argument",recipient)
nimbus.request ("spooler","hubpost",msg)
else
for idx,row in pairs (rs ) do
   if row['prevlevel'] ~= nil then
     if( row['level'] ~= row['prevlevel']) then
         print "sending email "
   end


            -- Post the message to the hub-spooler
           nimbus.request ("spooler","hubpost",msg)
       end
  end
end

pds.delete
(msg)
pds.delete (udata)
database.close()

Attachments

1558537050579SendEmailScript.zip get_app