escaping dollar signs in plugin output

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
wby47
Posts: 2
Joined: Wed Apr 24, 2019 1:04 am

escaping dollar signs in plugin output

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: escaping dollar signs in plugin output

Post 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))
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
wby47
Posts: 2
Joined: Wed Apr 24, 2019 1:04 am

Re: escaping dollar signs in plugin output

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: escaping dollar signs in plugin output

Post 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
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked