Hi,
I query the DB regularly to check to see if something has happened (or hasn't happened) at some point in the past. Great for assurance monitoring, here's the script:
rc = database.open("provider=nis;database=nis;driver=none")
query = "SELECT message from nas_transaction_summary where created > DATE_SUB(CURRENT_TIMESTAMP(),INTERVAL 6 HOUR) and message like 'EXPECTED_ALARM_TEST%' union select 'Dummy Record' from dual limit 1;"
alarms, rc = database.query(query)
for _, al in pairs (alarms) do
require ("library/html-alarms-lib")
recipient = "SOMEONE@SOME.COM"
title = "SOMETHING HAS NOT HAPPENED within the last 6 hours"
message = "SOMETHING HAS NOT HAPPENED within the last 6 hours"
message1 = "Severity = Critical"
SUPPKEY = "SUPP_KEY"
SUBSYS = "SUBSYS"
SOURCE = "SOURCE"
buf = ""
buf = buf .. html_start (title)
buf = buf .. html_alarm_message(message)
buf = buf .. html_separator(hr)
buf = buf .. html_alarm_message(message1)
buf = buf .. html_separator(hr)
buf = buf .. html_end ()
if regexp (al.message,"*EXPECTED_ALARM_TEXT*")
--then print (al.message)
then print ("Everything is fine")
--else print (al.message)
else nimbus.alarm (5, message , SUPPKEY , SUBSYS , SOURCE)
action.email (recipient,title,buf)
end
database.close()
end
So, if something has happened, great! Take no action.
If not, create a critical alert and email someone.
The hashed out lines are good for offline troubleshooting, so you're not creating alerts all over the place!
Hope it helps :)
Original Message:
Sent: 06-13-2019 07:14 AM
From: martin Nepolean
Subject: DB query in lua
Hi,
I am trying to get the history of a particular alert before triggering an action in nas. The script works perfectly in test UIM but throws error in prod.
NAS version in test - 9.06HF7
NAS version in prod - 9.06
a = alarm.get('AH65869489-88882')
database.open("Provider=nis;database=nis;driver=none")
--Query to get the process down alert count from a robot in last 1 hour
rs = database.query("select count(nimid) as alertcount from nas_transaction_summary where (robot = '..a.robot..' and supp_key = '..a.supp_key..' and created > dateadd(minute, -60, getdate()))")
database.close()
Error : attempt to index field '?' (a nil value)
If i replace look for nimid instead of robot it works not sure why it is not working when i use robot in prod UIM .
rs = database.query("select count(nimid) as alertcount from nas_transaction_summary where (nimid= '..a.nimid..' and created > dateadd(minute, -60, getdate()))")