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
Add comment