NXSL: Alarms by node

Started by mem16421, October 26, 2020, 04:36:57 PM

Previous topic - Next topic

mem16421

I need a little assistance on how to use nxsl to pull all alarms from a node.  Any help would be appreciated.

Filipp Sudanov

Something like that:
for(a : $object->alarms)
{
println(a->message);
}


List of alarms is an attribute of any object, not only node - it could be container, subnet, sensor... That's why I am using $object->alarms in the example, but if the object you are querying is a node, you can use $node->alarms

Documentation it's here: https://www.netxms.org/documentation/nxsl-latest/#class-netobj


mem16421

Thank you, I wasn't very detailed with my question.  What I am trying to figure out if a script runs I can pull alarms from a node, but from any node I choose.  So in a script how would I say clear alarms from 192.168.1.1 and it would switch to that node and run the commands.  Do I need to use like GetObject or something like that?  I am not a coder (clearly) but my struggle is understanding how to be in the correct context/object to run class commands

Victor Kirhenshtein

Yes, you have to get node object first. Global variables $node and $object refer to current node. You can use function FindObject to get other objects. This function accepts either object ID or name. For example, if you want to print alarms for node named "netxms-server":

node = FindObject("netxms-server");
for(a : node->alarms)
{
println(a->message);
}


Best regards,
Victor