News:

We really need your input in this questionnaire

Main Menu

Alarm notification call API

Started by richard21, September 21, 2025, 09:52:39 PM

Previous topic - Next topic

richard21

Hi is it possible to set up an Alarm action that will call an external systems API

Alex Kirhenshtein

Add "server action" in EPP rule where you are creating alarm

richard21

I have found the Variables and they are now passing to the API via the alarm action as below but is there a variable for the Alarm ID as shown in the UI

/etc/netxms/scripts/send_event.sh "%K" "%I" "%n" "%S" "%c" "%A"

Filipp Sudanov

#3
Yes, right, these are the macros described here: https://netxms.org/documentation/adminguide/event-processing.html#macros-for-event-processing

There's no built-in macro for alarm ID, but there's %[script_name] which will call a script from script library. There'll be a few variables set in the script, specifically:
$object - always is set
$node - set if event is created on a node
$event - when script is called from EPP
$alarm - if at given moment of event processing by EPP rules an alarm is already created.

$alarm variable has Alarm class described here: https://netxms.org/documentation/nxsl-latest/#class-alarm , so simple script

return $alarm.id;

should do the job.

richard21

Hi Filipp

thanks for the assistance that works great for new alarms unfortunately when it runs for a terminating alarm it doesn't return the alarm id

Regards
Richard

Filipp Sudanov

Well, while not being a LLM, I've hallucinated about $alarm :). It does not actually exist.

But in $event there's lastAlarmKey attribute, so we can use that to get alarm's ID:

a = FindAlarmByKey($event.lastAlarmKey);
return a.id;

Or course, alarm should have a key and this key should be unique.

At some point we will add lastAlarmID attribute to $event.

richard21

Hi Filipp,

thanks for the reply that also works for new Alarms but this issue I have is when the event is raised for terminating the alarm it doesn't work and raises the below

Error:
Minor   vm-netxms-srev   SYS_SCRIPT_ERROR   Script (getAlarmID) execution error: Error 14 in line 3: Function or operation argument is not an object   07.10.2025 08:58:16

Script:
//return $event.id;
a = FindAlarmByKey($event.lastAlarmKey);
return a.id;

Filipp Sudanov

Well, yes, FindAlarmByKey() is not searching through already terminated alarms, only current ones. And even if everything happens within one  EPP rule, alarm termination happens first and server action happens after that.

So the solution for now is to store the ID somehow before alarm termination. We can use filtering script in the EPP rule:

a = FindAlarmByKey($event.lastAlarmKey);
$event.setNamedParameter("lastAlarmID", a.id);
return true;

return true; is needed since this is filtering script and EPP rule will be processed further only if this script returns true.

And in your script that is used by the %[script] macro:
return $event.getParameter("lastAlarmID");

We are adding a new parameter to the event. This parameter will be accessible in any EPP rule that goes below the one where it's being added.

Ah, and actually you don't need the %[script] thing any more - you can just use %<lastAlarmID> macro - this should return value of event's parameter.