NetXMS Support Forum

English Support => General Support => Topic started by: mem16421 on October 26, 2020, 04:36:57 PM

Title: NXSL: Alarms by node
Post by: mem16421 on October 26, 2020, 04:36:57 PM
I need a little assistance on how to use nxsl to pull all alarms from a node.  Any help would be appreciated.
Title: Re: NXSL: Alarms by node
Post by: Filipp Sudanov on October 26, 2020, 06:42:30 PM
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

Title: Re: NXSL: Alarms by node
Post by: mem16421 on October 26, 2020, 07:26:02 PM
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
Title: Re: NXSL: Alarms by node
Post by: Victor Kirhenshtein on October 27, 2020, 06:10:19 PM
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