Hi,
I am no lua or nas expert, but it appear that the notes property on alarms is set to 0 if it has no notes and 1 if it has a note attached to it.
But there appears to be no easy way to grab which note it is attached to.
Here is an example demonstrating what I mean with the notes property on an alarm.
al=alarm.list()
if al ~= nil then
for i=1,#al do
sNote = "No"
-- Print nimid, hostname, severity, message and note
if al[i].notes == 1 then
sNote = "yes"
end
printf("%02d %s %s %s %s Note: %s",i,al[i].nimid,al[i].hostname,al[i].severity,al[i].message, sNote)
end
end
printf "select alarms with notes"
al=alarm.list("notes","1")
if al ~= nil then
for i=1,#al do
-- Print nimid, hostname, severity, message and note
printf("%02d %s %s %s %s",i,al[i].nimid,al[i].hostname,al[i].severity,al[i].message)
end
end
output might be something like
----------- Executing script at 19.04.2011 09:30:24 ----------
01 FA11050196-91595 w7geha information Testmessage2 Note: yes
02 FA11050196-91594 w7geha information Testmessage 1 Note: No
select alarms with notes
01 FA11050196-91595 w7geha information Testmessage2
Here I have attached a note to test message 2.
Here is another example I cooked up. There may be better ways to do this. It assumes you have nis bridge turned on in NAS.
sQueryFormat = "SELECT" ..
" n.* " ..
"FROM" ..
" NAS_NOTES n " ..
"INNER JOIN " ..
" NAS_ALARM_NOTE an ON an.note_id = n.note_id " ..
"INNER JOIN " ..
" NAS_ALARMS a ON a.nimid = an.nimid " ..
"WHERE " ..
" a.nimid = '$NIMID$' "
sData_engine = "provider=nis;database=none;driver=/***/***/***/data_engine;"
database.open(sData_engine)
printf "select alarms with notes"
al=alarm.list("notes","1")
if al ~= nil then
for i=1,#al do
-- Print nimid, hostname, severity, message and note
printf("Alarm: %02d %s %s %s %s",i,al[i].nimid,al[i].hostname,al[i].severity,al[i].message)
sQuery = string.gsub(sQueryFormat,"'$NIMID$'","'" .. al[i].nimid .. "'")
-- printf(sQuery)
rs = database.query(sQuery)
for j=1, #rs do
printf("Note id: %d, note key: %s, description: %s", rs[j].note_id, rs[j].note_key, rs[j].description)
end
end
end
database.close()
Output may look like
----------- Executing script at 19.04.2011 09:36:57 ----------
select alarms with notes
Alarm: 01 FA11050196-91595 w7geha information Testmessage2
Note id: 24, note key: TK03195155-00002, description: test notat 2
Thanks,
Geir.