Hi,

I've wrote a custom notification script with PowerShell and want to pass the %message placeholder as a parameter. Unfortunately the message may contain single or double quotes. This depends on the message from PRTG itself.

My problem now is: If I pass the parameter wrapped in single quotes and the message (resolved by %message placeholder) contains a single quote itself, the string passed will be terminated too early and the script will fail, as it treats the rest of the message string as parameters or else... (Same thing with wrapping the string with double quotes and message contains a " itself...)

------------------

Example:

The message resolved by PRTGs %message placeholder: You can see, that the resolved placeholder "%message" contains single quotes and even #.

Warning caused by lookup value 'Unable to check revocation status' in channel 'Revoked' - -121 # (Days to Expiration) is below ...

So if I call my script with the following parameter line...

-prtgMessage '%message'

...it will be expanded to...

-prtgMessage 'Warning caused by lookup value 'Unable to check revocation status' in channel 'Revoked' - -121 # (Days to Expiration) is below...'

...resulting in that PowerShell parses the parameter -prtgMessage until the first single quote of the message and treat the following text as a another parameter.

I know I can wrap the placeholder in double quotes and the example will work here. BUT: I have seen other messages that contain double quotes in the text aswell, so the problem persists.

So how can I pass the %message placeholder as a parameter correctly to PowerShell, so my notification script will work reliably?

Regards


Article Comments

Ok, so meanwhile I found out that others have this problem aswell. https://helpdesk.paessler.com/en/support/solutions/articles/90453-single-quotes-in-message-break-notification-script

The suggestion to make the the custom sensors "Set placeholders as environment values" option available for notification scripts, too, would be a great feature.

But if you have any other suggestions, please let me know.


Nov, 2022 - Permalink

Hello,

you are right, this is a know issue.

For the foreseeable future, environment variables are not planned for Exe notifications because other features are in much higher demand.

Workarounds exist, one of them being to query the lastmessage value through the PRTG API. As alternative you might want to use a string array for the powershell parameter.


Nov, 2022 - Permalink