Alarm key SERVICE_DOWN_ => Function or operation argument is not an object

Started by BigBlue, May 07, 2021, 02:13:26 PM

Previous topic - Next topic

BigBlue

Hi,

I tried a NXSL script to display the content of all alarms.
It works for MAC_ADDRESS_CHANGED_.* for example:
alarm = FindAlarmByKeyRegex("MAC_ADDRESS_CHANGED_.*");
println alarm->message;

MAC address for interface unknown changed from XX:XX:XX:XX:XX:XX to XX:XX:XX:XX:XX:XX
*** FINISHED ***


But it doesn't work for SERVICE_DOWN_?
alarm = FindAlarmByKeyRegex("SERVICE_DOWN_.*");
println alarm->message;

Error 14 in line 64: Function or operation argument is not an object

I must be doing it wrong...

Can you help me?

Thanks
BB

Zebble

alarm = FindAlarmByKeyRegex("SERVICE_DOWN_.*");

works for me, but only if there are alarms that have SERVICE_DOWN_.  If there aren't any, you'll get a "Function or operation argument is not an object" if you try to println alarm->message because alarm isn't an object.  Alarm would be set to NULL in this case, so best to check for this:

if (alarm != NULL)
  println alarm->message;

BigBlue


BigBlue

But, I think this is not the right way...
a_key = %("NODE_DOWN_.*","SERVICE_DOWN_.*","IF_DOWN_.*","IF_UNEXP_UP_.*","BAD_NETMASK_.*","SCRIPT_ERR_.*","DCI_STATUS_.*","DC_THRESHOLD_.*","DCTTHR_.*","SYS_THREAD_HANG_.*","MAINTENANCE_MODE_.*","AGENT_UNREACHABLE_.*","SNMP_UNREACHABLE_.*","SYS_LDAP_SYNC_ERROR_.*","SYS_AGENT_LOG_PROBLEM_.*","SYS_AGENT_LOCAL_DATABASE_PROBLEM_.*","MAC_ADDRESS_CHANGED_.*","BAD_NETMASK_.*","ROUTING_LOOP_.*","SW_PKG_.*");

for (i = 0; i < a_key->size; i++ )
{
alarm = FindAlarmByKeyRegex(a_key[i]);
if (alarm != NULL)
{
println  (alarm->key) . (alarm->message) . "\n";
}
}


NODE_DOWN_0x000099C6Node down

SCRIPT_ERR_Template::Zone Proxy::108_Error in line 1: syntax error, unexpected $end, expecting ';'Script (Template::Zone Proxy::108) execution error: Error in line 1: syntax error, unexpected $end, expecting ';'

MAC_ADDRESS_CHANGED_0x0001EDB7_1MAC address for interface unknown changed from XX:XX:XX:XX:XX:XX to XX:XX:XX:XX:XX:XX


*** FINISHED ***

Result:



I have a lot of errors and "alarm->message" does not return all the information.
Do you know if it is possible to get about the same result in "Alarm Browser"?

Zebble

Your script works without issue on my end.  I'm using 3.8.314.


Filipp Sudanov

The script in your example returns only one alarm for each key. E.g. if you have several node with NODE_DOWN alarm, only one will be returned.

Can you give some information on what you are trying to achieve as the final result?

BigBlue

Hi,

I'm trying to get the logs as displayed in the "Alarm Browser" window.
As I said, this may not be the right way to do it  :-[

I have now gone another way, exporting the alarms when they appear using the "Event Processing Policy" and an associated "Action".
But then I'll have to manage the acknowledgements myself ... etc...

BB

Victor Kirhenshtein

Hi,

you can access all alarms via "Entire Network" or "Infrastructure Services" objects. FOr example, the following script will print all alarm messages:

for(a : FindObject(1)->alarms)
{
println a->message;
}


Best regards,
Victor

BigBlue

hi,

Thank you, this has inspired me a lot!

Now I can display the id, name and message of each alarm.

for (n : GetAllNodes())
{
for(a : n->alarms)
{
println n->id . "\t" . n->name . "\t" . a->message;
}
}


But I don't know how to display the date ?

Thanks for your help.
BB

BigBlue

oh!

I've got it:
oldestAlarmTime = min(oldestAlarmTime, a->creationTime);
println n->id . "\t" . n->name . "\t" . a->message . "\t" . strftime("%Y-%m-%d %H:%M", a->creationTime);


Thanks to all.

BB