Page 1 of 1

escaping dollar signs in plugin output

PostPosted: Wed Apr 24, 2019 1:11 am
by wby47
I have a plugin, written in Python.
I'm using Nagios 3.5.1; mail alerts are sent using mailx.

To get the web UI to display a literal dollar sign in the web UI, I have to escape the literal dollar sign; this seems to work Ok there:
that is:
Code: Select all
'OK: no transactions exceeding threshold (\${}) in the previous {} seconds.'
              .format(args.upper_alert_threshold, args.time_seconds))

will display
OK: no transactions exceeding threshold ($123) in the previous 23 seconds.

however, if I get a message via email or via integration with OpsGenie, the text will show the literal backslash instead, with the dollar sign presumably getting interpolated, and not showing up:
OK: no transactions exceeding threshold (\123) in the previous 23 seconds.

Is there any magic combination that will result in a literal dollar sign in both cases? I've tried some other combinations, but so far, nothing that works for both. Most of the suggestions online relate to slightly different use cases that don't seem to line up with the problem I'm seeing.

Re: escaping dollar signs in plugin output

PostPosted: Wed Apr 24, 2019 7:23 am
by scottwilkerson
It's hard to say without the whole plugin, but I think you need a second $

Code: Select all
'OK: no transactions exceeding threshold (\$${}) in the previous {} seconds.'
              .format(args.upper_alert_threshold, args.time_seconds))

Re: escaping dollar signs in plugin output

PostPosted: Sun May 26, 2019 5:20 pm
by wby47
Code: Select all
\$$
gives me literal $$ in the web UI. Haven't tested via mail notification yet.
Code: Select all
\\$
looks Ok in web UI


What would seeing more of the code help? the actual value being interpolated is just a string representing a number. The issue, I think is that mailx is trying to do variable interpolation on it, whereas web interface / OpsGenie integration are rendering it literally.

Re: escaping dollar signs in plugin output

PostPosted: Tue May 28, 2019 6:52 am
by scottwilkerson
If the problem is just with the mail it could be that your mail notification commands are wrapped in double quotes instead of single quotes