NetXMS Support Forum

English Support => General Support => Topic started by: richard21 on September 21, 2025, 09:52:39 PM

Title: Alarm notification call API
Post by: richard21 on September 21, 2025, 09:52:39 PM
Hi is it possible to set up an Alarm action that will call an external systems API
Title: Re: Alarm notification call API
Post by: Alex Kirhenshtein on September 21, 2025, 09:57:57 PM
Add "server action" in EPP rule where you are creating alarm
Title: Re: Alarm notification call API
Post by: richard21 on September 30, 2025, 06:44:14 PM
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"
Title: Re: Alarm notification call API
Post by: Filipp Sudanov on September 30, 2025, 09:39:10 PM
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.
Title: Re: Alarm notification call API
Post by: richard21 on October 04, 2025, 06:25:55 PM
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
Title: Re: Alarm notification call API
Post by: Filipp Sudanov on October 06, 2025, 03:22:23 PM
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.
Title: Re: Alarm notification call API
Post by: richard21 on October 07, 2025, 11:23:35 AM
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;
Title: Re: Alarm notification call API
Post by: Filipp Sudanov on October 07, 2025, 02:14:21 PM
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.