News:

We really need your input in this questionnaire

Main Menu

Sending alarms to N8N?

Started by Sorikan, October 20, 2025, 05:58:32 PM

Previous topic - Next topic

Sorikan

Has anyone been able to come up with a way to send alarms to an N8N instance? I have tried Hook::AlarmStateChange, and a notification channel and nothing works. I was on 5.2.4 but upgraded to 5.2.6 to see if that opens anything up.

I have been hitting up Google and all the LLM's, to no avail.

I am attempting to sedn JSON from netxms to N8N.

Thanks!

Filipp Sudanov

Can you point me to n8n documentation on the api call you are trying to use

Sorikan

Thats not really a thing? I am trying to get all of the alarm information I can into N8N. You can see the documentation in the link below. I had attempted to build the JSON in hook::AlarmStateChange, but that appears to be a dead end at this point? I am now trying to just dump the data to a script with a shell notification channel - but I am not getting any actual alarm data in the fields yet.

https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.webhook/#webhook-urls

Thanks.

Sorikan

I tried doing something like this, but kept hitting various walls, when using hook::alarmstatechange

function main()
{
   webhook = "https://my.host.hstgr.cloud/webhook-test/netxms-alarm";

   payload = "{"
      + "\"id\":\""        + ToString($alarm->id) + "\","
      + "\"state\":\""     + ToString($alarm->state) + "\","
      + "\"severity\":\""  + ToString($alarm->severity) + "\","
      + "\"message\":\""   + EscapeString(($alarm->message != null) ? $alarm->message : "") + "\","
      + "\"source\":\""    + (($alarm->sourceObject != null) ? EscapeString($alarm->sourceObject->name) : "") + "\","
      + "\"eventCode\":\"" + ToString($alarm->eventCode) + "\","
      + "\"eventName\":\"" + EscapeString(($alarm->eventName != null) ? $alarm->eventName : "") + "\""
      + "}";

   WriteLog(0, "Alarm JSON: " + payload);

   cmd = "curl -s -X POST -H 'Content-Type: application/json' -d '" + payload + "' " + webhook;
   Execute(cmd);
}

function EscapeString(s)
{
   if (s == null)
      return "";
   s = Replace(s, "\\", "\\\\");   
   s = Replace(s, "\"", "\\\"");   
   return s;
}



Alex Kirhenshtein

There are no "Execute()" function in the NXSL, and you can't execute external commands in any way - that's by design.

What I'd do:
- create Action which runs external shell script to form  json and send query using curl. Pass required event fields as arguments to the script.
- add this Action to EPP (I'd create separate rule just for this integration - this way you can control what exactly being sent)

Or, you setup web service (Settings -> Web service definition), and call it from NXSL. But again, I'd use action for that, not hook.

Note on the json string escaping: instead of manual processing, you can use construct https://netxms.org/documentation/nxsl-latest/#class-jsonobject and produce perfectly valid json.

Alex Kirhenshtein

also you don't need "function main()", just write code.

something like this:

source = FindObject($alarm.sourceObject());

j = JsonObject();
j.set("id", $alarm.id);
j.set("state", $alarm.state);
j.set("severity", $alarm.severity);
j.set("message", $alarm.message);
j.set("source", source ? source.name : "");
j.set("eventCode", $alarm.eventCode);
j.set("eventName", $alarm.eventName);

trace(0, j.serialize());

I highly recommend you to read https://www.netxms.org/documentation/nxsl-latest/.