What is this?

This knowledgebase contains questions and answers about PRTG Network Monitor and network monitoring in general.

Learn more

PRTG Network Monitor

Intuitive to Use. Easy to manage.
More than 500,000 users rely on Paessler PRTG every day. Find out how you can reduce cost, increase QoS and ease planning, as well.

Free Download

Top Tags


View all Tags

Single quote in sensor message breaks notification script

Votes:

0

I currently have an issue with my notification script, when the sensor message has a single quote in it.

I'm running a PowerShell script to automatically create a ticket. The parameters for running the script: '%sensor' '%sensorid' '%status' '%message' '%device' '%since' '%lastup' '' '' '' '%prio'

All goes well, as long as the sensor message doesn't contain a quote. However, as soon as it contains a quote like "Error by lookup value 'Critical (2)' in channel 'Drum Unit' (Ready)" (a channel of the default SNMP printer settings sensor in PRTG), it breaks my script. The parameters following the '%message' parameter all get jumbled up.

It considers the single quote as a parameter. So: %message becomes "Error by lookup value" %device becomes "Critical" %since becomes "2" %lastup becomes "in channel" %prio becomes NULL (because of the 3 empty inputs, due to the structure of the PowerShell script)

I know I can kinda work around this by putting the '%message' parameter as last parameter, but that means I won't get the entire message in my ticket. So, no proper solution. This has either has to be a change in PRTG (not insert single quote in the sensor message), or a change in the way I pass the parameters to the script (but I have no idea how)...

message notification powershell quote sensor

Created on Jul 21, 2017 9:35:25 AM



15 Replies

Votes:

0

Hi Corné,

Did you already try the following: '%sensor' '%sensorid' '%status' ''%message'' '%device' '%since' '%lastup' '' '' '' '%prio Note the double single quotes around the %message placeholder. Does that work?


Kind regards,
Stephan Linke, Tech Support Team

Created on Jul 21, 2017 10:04:58 AM by  Stephan Linke [Paessler Support]



Votes:

0

Hi Stephan,

I tested with the double single quotes around %message , but with the single double quotes the script doesn't do anything at all anymore.

I kinda worked around the problem by setting the %message parameter as the last parameter (and changed the PowerShell script accordingly). At least it's creating tickets, but it only has part of the sensor message in the ticket.

So, it's a workaround, not a solution.

Any other tips to fix this problem?

Created on Jul 21, 2017 10:56:56 AM



Votes:

0

How about double quotes? Not working as well?

Created on Jul 21, 2017 11:07:20 AM by  Stephan Linke [Paessler Support]



Votes:

0

Tested it already with double quotes around all parameters (replaced all single quotes in parameters field with double quotes). The result was the same as with double single quotes: the script didn't do anything at all anymore.

So unfortunately double quotes didn't help either...

Created on Jul 21, 2017 2:50:02 PM



Votes:

0

I'll check back with the dev and let you know what he said :)

Created on Jul 24, 2017 5:05:17 AM by  Stephan Linke [Paessler Support]



Votes:

0

A new (similar) issue arose: When you have a sensor with a \ in the name, and you pass the name on to the PowerShell notification script (using the '%sensor' parameter), it's treating the \ as escape character (normal PowerShell behaviour). Not sure how I can mitigate this issue, since I don't think using for example -replace ([RegEx]::Escape(%sensor)), "%sensorname" as parameter, or for example -replace (%sensor -replace '
','
'), %sensorname, will work. Double quotes won't help either, as (once again) a \ is a valid PowerShell escape character.

Of course there's the work-around of going through all the sensors and replace the backslashes in the sensor names with forward slashes. But it's a work-around, not a solution...

Anyone have any ideas?

Created on Jul 27, 2017 2:29:25 PM



Votes:

0

But why would you have a backslash in the name? :D Drives/Mounts?

Created on Jul 28, 2017 5:22:45 AM by  Stephan Linke [Paessler Support]



Votes:

0

It's a backslash, not a forward slash. ;-)

I have quite a few sensors checking Scheduled Tasks, using the ScheduledTask2XML.exe (prtgtoolsfamily). The sensor names include the group names the sensors are created in
(Scheduled Task: \<group_name>\<sensor_name>

Just did some more testing (manual input): PowerShell is able to handle a single backslash. It goes wrong when it uses the value to do an API call to our ticket system. A double backslash...

\\<group_name>\\<sensor_name>

can be handled by the ticket system. I managed to solve this particular message by adding one line in the PowerShell: $sensor = $sensor -replace "\\", "\\\\"

So, disregard the issue with backslash; that's solved in Powershell.

The issue with the single still remains! I can't fix that in PowerShell, since it's already breaking at calling PowerShell with parameters...

Created on Jul 28, 2017 12:20:30 PM

Last change on Jul 31, 2017 7:30:48 AM by  Stephan Linke [Paessler Support]



Votes:

0

Let's see what the developer says about it ... I'll forward him the link to this thread, maybe he
has an idea of how to implement this properly. May take a while, depends on his workload.

Created on Jul 31, 2017 7:46:52 AM by  Stephan Linke [Paessler Support]

Last change on Jul 31, 2017 7:49:47 AM by  Stephan Linke [Paessler Support]



Votes:

0

Just to keep you in the loop, the developer is currently on vacation and had no time to take a look at it. This will probably take about 3-4 weeks until he responds. Sorry that this takes so long, he was on sick leave right before the vacation started - not much room for bug checking :(

Created on Aug 9, 2017 10:45:59 AM by  Stephan Linke [Paessler Support]



Votes:

0

Got word from development, we're not going to implement it (or change anything about it), since we can potentially break what users have currently configured. Maybe this is helpful, it will make PowerShell based notifications rather tedious to set up from what I can tell:

[StackoverFlow]Command Line escaping single quote for PowerShell

Sorry to be the bearer of bad news here :/


Kind regards,
Stephan Linke, Tech Support Team

Created on Aug 15, 2017 1:09:46 PM by  Stephan Linke [Paessler Support]

Last change on Aug 15, 2017 1:10:47 PM by  Stephan Linke [Paessler Support]



Votes:

0

Hi Stephan,

It's okay. I'll just keep the message parameter as last parameter. That way, if it does contain a single quote, the only effect would be that only part of the message will be in my ticket (but at least it won't break the 'create ticket' script).

I'll try to comprehend what they're doing on the webpage you gave me (StackoverFlow), but I'd need a quiet period to focus on that. And with the current workload that's going to be a bit harder said than done ;-)

As for the 'we can potentially break what users have currently configured' part: Just change the message of the sensors so they don't include singe quotes anymore. That shouldn't break anything, I'd say...?

Created on Aug 16, 2017 8:21:44 AM



Votes:

0

Hi Corné,

Hehe, alright then. I guess the "removing single quotes" part is easier said than done as well since the way we're executing PowerShell code is already slightly convoluted, to put it charitably.
Testing this is a really tedious process as well and nobody wants to open pandora's box here :)


Kind regards,
Stephan Linke, Tech Support Team

Created on Aug 16, 2017 8:34:22 AM by  Stephan Linke [Paessler Support]

Last change on Aug 16, 2017 8:34:33 AM by  Stephan Linke [Paessler Support]



Votes:

0

"It's too hard" seems an unfortunate state of affairs with this.

My suggestion: create a new placeholder, say %escaped_message that provides a properly escaped powershell compatible message parameter.

I also have this problem. Many of the messages produced by PRTG now include single quotes, so single quoting the %message placeholder goes wrong in my notification and ticket scripts.

Created on Jul 31, 2019 12:18:19 AM



Votes:

0

We're currently evaluating the switch to PowerShell Core (instead of using the PowerShell 5.1 that comes with Windows), which will hopefully alleviate the issues we're having with passing parameters, etc. :) This may take a while, though :)

Created on Jul 31, 2019 10:28:25 AM by  Stephan Linke [Paessler Support]




Disclaimer: The information in the Paessler Knowledge Base comes without warranty of any kind. Use at your own risk. Before applying any instructions please exercise proper system administrator housekeeping. You must make sure that a proper backup of all your data is available.