Dumb question - is it me or is Object Tools not playing correctly?

Started by paul, July 14, 2019, 04:04:09 PM

Previous topic - Next topic

paul

Wondering if anybody else has hit this problem - I am pretty sure I am not the first - and was wondering what I am missing.

Trying to add to my expanding collection of Object tools / Alarm tools - but having some bad luck with Alarms. I want an Alarm Tool to create a Help Desk ticket via PowerShell but NetXMS is not acting as expected.

I do not think it is the extremely limited documentation - I think it is an inconsistency in parameter availability.

The command below is designed to get the Alarm message either in its entirety, a specific variable, or even the Event Message, the severity and the time the alarm occurred.

The only documentation that half helped is this - https://netxms.readthedocs.io/projects/admin/en/latest/event-processing.html?highlight=message#event-processing-macros
as well as section 23.2.1 of the 2.2.11 admin guide (which lists in a table the fields available - but are for Event Processing Policy only??)

The problem is as follows:
1. Time of the alarm is not passed. %t is empty
2. %m passes the first word only.
3. NetXMS passes the rest of the message as variables (no idea what name) using a blank as the separator. I have added additional variables just to pick up them up.
4. Fortunately, using PowerShell names variables, the input variable is passed successfully, even if PowerShell has it last in its list.
5. I can export the Alarm as CSV and Message field and Created Time are correct and complete - exactly what I want - but seemingly impossible to achieve.
6. An alarm that has special characters such as / % , etc. cause NetXMS to hang the execution - either never finishes or terminates with blank output.
7. It would appear %A would do it - but that is empty - tried that as well.
 
This can be reproduced by anyone as per below. I changed %t to %c as %t caused the script to hang - using %c allows me to see that the -c Code  variables is working.

My Object tool command (local script): It has one input - variable name  is pass. The command does produce output 9tick the box)
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe c:\scripts\create-inc-from-alarm.ps1 -device  %n  -sev %s -tyme %c -pd %(pass) -msg %m

My PowerShell is as follows:

Param(
[string]$device,
[string]$msg,
[string]$tyme,
[string]$sev,
[string]$m1,
[string]$m2,
[string]$m3,
[string]$m4,
[string]$m5,
[string]$m6,
[string]$m7,
[string]$m8,
[string]$m9,
[string]$m10,
[string]$m11,
[string]$pd)


write-host  " Alarm on $device with msg $msg $m1 $m2 $m3 $m4 $m5 $m6 $m7 $m8 $m9 $m10 $m11 that occured at $tyme with severity $sev using pass $pd "




Victor Kirhenshtein

Hi,

you have to wrap message (and anything that can have space in it) into double quotes, like this:

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe c:\scripts\create-inc-from-alarm.ps1 -device  "%n" -sev %s -tyme %c -pd "%(pass)" -msg "%m"

then you should have full message text in msg.

Best regards,
Victor

paul

Hi Victor - thanks for that - except that you are not correct - but you were close enough!!

I thought I had tried your suggestion and failed - but tried it again - and failed again. :(

Tried double double quotes - no good. :( :(

Tried triple double quotes - and it worked!!   :) :)  ;D

Other than %t being empty, I got the whole message in %m . 

This works:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe c:\scripts\create-inc-from-alarm.ps1 -device  "%n" -sev "%s" -tyme """%t""" -pd "%(pass)" -msg """%m"""

The only two questions that remain are a follows:
1. Is time Alarm Created available? - %t is empty
2. Can I get the Event message? I would like this so I can create the ticket with Event Message which I create as a summary of the alarm.