emailing action variables

Started by raindrop, December 15, 2023, 01:17:20 PM

Previous topic - Next topic

raindrop

Hi,

I am hoping that someone can point me in the right direction with my query.  I have been searching both the forums and google, but so far not come up with an answer.

I am very new to NetXMS and still learning my way around it.

What I am hoping to achieve is that when an Alarm is triggered, an email gets sent to me with details about the alarm. I have managed to get quite a lot of information on the email based on the "macros for event processing" (https://www.netxms.org/documentation/adminguide/event-processing.html#macros-for-event-processing), however what I would like is to be able to include the Container Path of where the object is.

e.g. Under Infrastructure Services I have 3 containers:-

Company A
Company B
Company C

within each company I then have sub-containers called "Servers", "Workstation", "Switches", "Routers" etc.

If a server in Company B triggered a NODE_DOWN alarm, the email would include "Company B > Servers > Server Name".

I can get the Server Name using %n  but I cannot seem to find how I could get the container names.


I hope I have explained clearly what I want, and also that someone can point me in the right direction.

Thank you,
Phil

Filipp Sudanov

Hi,

there is %[script_name] macro, that calls a script from script library. This way you can prepare any text that will go into your notifications.
When developing scripts, it's easier to open "Execute script" from context menu of any node. In this case script will be running in context of that node (special variables like $object or $node will be pointing to that specific node). So if you try below script on any node:
sub getParents(o, path) {
  if (o->id == 2) {  // Infrastructure services
    println(path);
  }
  for (p : o->parents) {
    if (path == "") {
      getParents(p, p->name);
    }
    else
    {
      getParents(p, p->name . " > " . path);
    }
  }
}
getParents($object, "");

In will print paths from "Infrastructure services" to that node. The problem is, that a node can be located under several container paths (it's actually a cool feature, as you can arrange your nodes in various ways, e.g. by location, by OS, or you may have a container with nodes that have specific software, require upgrade or attention, etc).
If there are several possible paths, scrip can just print first that it finds, or you can have some ways to instruct the script what path to take, e.g. you can have a custom attribute on some container under "Infrastructure services" and script will be taking only paths that contain that container.

Now we just need to modify above script to return the value instead of printing it:
global r = "";
sub getParents(o, path) {
  if (o->id == 2 and r == "") {  // Infrastructure services
    r = path;
  }
  for (p : o->parents) {
    if (path == "") {
      getParents(p, p->name);
    }
    else
    {
      getParents(p, p->name . " > " . path);
    }
  }
}
getParents($object, "");
return r;

and this is the script that you have to save into script library. It will return first found path.

raindrop

Thank you Filipp,

I have copied your code, and saved it as a new script called "pipsPath" in the Script Library, and then in my email report, added   %[pipsPath]   but when the email comes through it doesn't show any information.


I am guessing that I haven't done something correctly, have tried searching to see if I can find out what, but have had no luck.

:(
Thanks,
Phil.

Filipp Sudanov

Make sure you've copied all lines of second script - last line should be "return r;"

Try executing this script on any node - right-click a node in object tree, select "Execute script". Paste the script into "Source" and click "Execute" button. In the output it should print, e.g.:


*** FINISHED ***

Result: Infrastructure Services

raindrop

Thanks Filipp,

You are correct, I had missed the last line.

This now gives me a path that I can experiment with.

Thank you again,
Phil.