Sending alarms to N8N?
-
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!
-
Can you point me to n8n documentation on the api call you are trying to use
-
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.
Webhook | Nodes | n8n Docs
Learn how to use the Webhook node in n8n. Follow technical documentation to integrate Webhook node into your workflows.
(docs.n8n.io)
Thanks.
-
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;
} -
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.
-
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/.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login