escaping dollar signs in plugin output

This forum is intended for the discussion of Nagios plugin development. Feature requests, patches, bug fixes, and all types of development-related discussions are welcome!

NOTE: The SourceForge.net nagiosplug-devel mailing list has been deprecated in favor of this forum in order to expedite support and provide additional features not available on the old mailing list.

escaping dollar signs in plugin output

Postby wby47 » Wed Apr 24, 2019 1:11 am

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.
wby47
 
Posts: 2
Joined: Wed Apr 24, 2019 1:04 am

Re: escaping dollar signs in plugin output

Postby scottwilkerson » Wed Apr 24, 2019 7:23 am

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))
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 17032
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises

Re: escaping dollar signs in plugin output

Postby wby47 » Sun May 26, 2019 5:20 pm

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.
wby47
 
Posts: 2
Joined: Wed Apr 24, 2019 1:04 am

Re: escaping dollar signs in plugin output

Postby scottwilkerson » Tue May 28, 2019 6:52 am

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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
scottwilkerson
DevOps Engineer
 
Posts: 17032
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises


Return to Nagios Plugin Development

Who is online

Users browsing this forum: No registered users and 1 guest