Actions - Parameter?

Started by jdl, June 26, 2009, 09:38:26 AM

Previous topic - Next topic

jdl

Hi all,

Having defined several actions, I was wondering whether there is a way to define actions (remote or not) in the server related panel to which some parameters could be given when called through an event policy.

That would be very interesting as a defined action could be so generic that it would be called in several events but with different parameters. Example, a script "start_process.pl" to which you would give the process name and the user whose rights shall be used to start it. You may also want to provide the remote node name on which to start this process...

Cheers,
Jdamien

jdl

In the same context...

Would be nice to pass as argument the email addresses for the "sendmail" action!
And why not also content and subject or a specific template... well a bit more flexibility around here would be very powerful.

Cheers,

Jdamien

jdl

I would appreciate if someone could take some time to put some inputs here on this subject...

Possible? Not possible?
Another example: Imagine you want to send an email to different staff in function of the alarm/event... do you have to create a specific action for each email?

Thanks in advance for ur support and time.
Rgds,

Jdamien

Victor Kirhenshtein

Hello!

You cannot pass parameters to actions directly in event processing policy. However, you can use macros in defined actions - this can cover basic things like host name, event message text, severity, and so on easily. You can also use node's custom attributes (via %{..} macro). And for event more complicated things, you can call NXSL script when expanding macros in actions (via %[..] macro). When called, this script has access to node and event information via $node and $event global variables. You can also set global variable CUSTOM_MESSAGE in event matching script and later insert this value into alarms or actions via %M macro.


Little example of using scripts

Goal: send e-mail to different people depending on node's domain name.

Steps:

1. create e-mail action as usual, in recipient address field enter %[SelectEmail]
2. create script in script library, named SelectEmail:


sub main()
{
   if (right($node->name, 11) == ".domain.com")
      return "[email protected]";
   if (right($node->name, 12) == ".domain2.com")
      return "[email protected]";
   return "[email protected]";
}


3. in event processing policy, use defined action as usual

Best regards,
Victor

jdl

#4
Jesus... that's great!
Thanks for the info...

But you know my next question, don't you ;-)

Where can I find a description of $node and $event variables/objects?

So I found $nodes object attributes:
Attributes of node object:

name      Node name
id         Object identifier
status      Node status (0 = Normal, 1 = Warning, 2 = Minor, 3 = Major, 4 = Critical, 5 = Unknown, 6 = Unmanaged)
ipAddr      Node primary IP address (as text string, like 10.2.1.4)
isAgent      Agent presense flag: 1 if NetXMS agent present on node, 0 if not
isSNMP      SNMP support flag: 1 if SNMP is supported by node, 0 if not
isBridge      Bridge flag: 1 if node is bridge or switch, 0 if not
isRouter      IP router flag: 1 if node is Ip router (can forward IP packets), 0 if not
isPrinter      Printer flag: 1 if node detected to be a network printer, 0 if not
isCDP      CDP (Cisco Discovery Protocol) support flag: 1 node supports CDP, 0 if not
isSONMP      SONMP (SynOptics Network Management Protocol) support flag: 1 node supports SONMP, 0 if not
isLLDP      LLDP (Link Layer Discovery Protocol) support flag: 1 node supports LLDP, 0 if not
snmpVersion   SNMP version used for communication with node's SNMP agent
snmpOID   SNMP   object ID
agentVersion   NetXMS agent version (as string, like 0.2.26)
platformName   Platform name, as returned by NetXMS agent (for example, windows-i386)

Remains $event object attribute...

Regards,
JDamien

Victor Kirhenshtein

#5
Event object (represented by $event variable) has the following attributes:


codeEvent code
idEvent ID
severitySeverity code (0=Normal 1=Warning 2=Minor 3=Major 4=Critical)
timestampTimestamp as number of seconds since 1 Jan 1970 00:00:00 UTC
messageMessage text
customMessageCustom message text (added in 0.2.27)
userTagUser tag
parametersEvent parameters (this property is an array with first element started at 1)

Also, starting from version 0.2.27 you can access node's custom attributes directly via object referenced by $node variable, if attribute's name conforms to NXSL identifier naming restrictions (contains only letters, digits, underscore and dollar sign, and not starts with digit). For example, if you define custom attribute terminalId, you can access it in script as following:


$node->terminalId


Best regards,
Victor

jdl

Thanks for this rapid feedback!

Regards,
Jdamien

jdl

Hi

One more in this topic...

Using $event->message we get the message text defined in the "event" panel.
How do you differentiate between this message text and the one you can re-define in the "event processing" panel when defining an alarm? Is there a property to the $event object that covers this one?

In the script, the $event->message refers to the text message defined in the event not in the alarm which can be more specific as we get additional macro's at that level, right?

Regards,
Jdamien

Victor Kirhenshtein

Yes, you right - alarm message is unavailable within script. For the next version, I add new global variable $alarmMessage which will hold alarm's text. It's not part of event object (it's only created based on event data), so it will be incorrect and technically slightly harder to put it as $event attribute.

Currently you able to pass alarm message to action via %A macro - this can help if you don't need it in script.

Quote from: jdl on June 30, 2009, 04:28:15 PM
In the script, the $event->message refers to the text message defined in the event not in the alarm which can be more specific as we get additional macro's at that level, right?

You have only two additional macros at alarm definition level - %m (event's message text) and %M (custom message, if set in matching script). All other macros are the same (including scripts and custom node attributes).

Best regards,
Victor