execute command on management server - string not passed correctly
-
Hi,
"%m" should work, although I didn't test it specifically with powershell scripts. When I test it with the following cmd script:
@echo off echo %2 >> c:\temp\cmd.logand action configured as
c:\\temp\\test.cmd parameter_1 "%m"
file c:\temp\cmd.log contains records like
"Node status changed to UNMANAGED"
Note that cmd script interprets " as part of parameter. Can you create a simple powershell script which will just log all command line parameters it got?
Best regards,
Victor -
Hello Victor
Thx for your reply. I just tested if your test with the batch-file works in my configuration. It is exactly the same behaviour as with the powershell script... if I configure the action as:
c:\\temp\\test.cmd parameter_1 "%m" it won't get executed. If I remove the "" from the %m (c:\\temp\\test.cmd parameter_1 %m) it gets executed but I just receive the first word. In my case "Zone:"Message form the event is configured as: Zone:\t%[get_first_parent]\nSystem:\t%n\nTime:\t\t%t\nSeverity:\t%S\n\n%2 is stopped!
We have the version 1.2.13 running.
Thx for help & best regards
Ap_ops -
Hi,
I suppose that new line characters is the problem. I doubt that command line parser can handle them even inside quotes. Try to form message without new lines. If it helps, you can pass some other characters to indicate new lines and replace them in your script before sending SMS.
Best regards,
Victor -
Hi,
Alright I made the recommended changes: I removed all \n and \t characters. The Batchfile works now. After this success I just checked with a simple powerShell script:
param( [String]$msg = $(throw "-msg is required.") ); $error_log_path = "C:\log.txt" "$(get-date) - "+ $msg | Out-File -Append $error_log_pathI Just receive: "Zone:Comp" instead of
"Zone:Comp XX NMS - 172.20.1.0/24System:[VM]Time:[22-Sep-2014 12:19:46]Severity:[Critical][TEST]isstopped!"The Line above is created through "Zone:%[get_first_parent]System:[%n]Time:[%t]Severity:[%S][%2]isstopped!" event config.
Do you have any idea what could be the reason for that? Is is possible that the output is not a single string? Or the string is splitted in each space?
Best regards,
AP_ops -
Hi,
I just found the reason...now its not NetXMS. One should know how to execute powershell from cmd environment. If you call a ps1 script fom cmd environment or in this case NetXMS you have to use "powershell -file -para "bla" -para2 "bla" " if no -file is used..just the first word is taken. It has to do with a security "feature"..
thanks for your help!
-
Hi Victor,
I know now how I could reformat all message texts to handover by commandline. But the option to avoid all /t /n characters is not the way with the least work as I use the formatted message texts mostly for messages by mail. Do you have any idea if it's possible to parse this characters in the script or if there is a way to solve this problem without building every message from scretch?
thanks for help
AP_ops -
Hi,
I probably can add an escape mode for all external commands executed by server, which will replace new line characters with \n and so on.
Best regards,
Victor -
-
Hi,
I've added configuration option EscapeLocalCommands. If it is set to 1, tab, carriage return, and new line characters will be replaced by \t, \r, and \n in commands. It will be available in release 1.2.17.
Best regards,
Victor -
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login