printf "%b" in notification command definition

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
User avatar
roddie
Posts: 10
Joined: Tue Apr 24, 2018 3:23 pm
Location: Services (Unhandled)

printf "%b" in notification command definition

Post by roddie »

Can someone please help explain the %b portion of the printf command in the default notification command definitions? Is it just to allow \n to produce new lines in the construction of an email? I want to build an additional notification command that is simplified for SMS messaging (so will all be on a single line) and wondering if I need to keep the %b, replace it with something else or just drop it?

Code: Select all

define command{
        command_name    notify-host-by-sms
        command_line    /usr/bin/printf "%b" "$NOTIFICATIONTYPE$ ALERT: $HOSTALIAS$ is $HOSTSTATE$ ($SHORTDATETIME$)" | /usr/bin/sendemail -f $USER9$ -t $CONTACTEMAIL$ -s "mail.server.com:587" -o tls=yes -xu $USER9$ -xp $USER10$ -l /var/log/sendemail.log
        }
User avatar
eloyd
Cool Title Here
Posts: 2129
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: printf "%b" in notification command definition

Post by eloyd »

From the man page for printf:

Code: Select all

       %b     ARGUMENT as a string with '\' escapes interpreted, except that octal escapes are of the form \0 or \0NNN
One could argue that this is so you can pass in arbitrary "blobs" (hence, "b") of data that don't get interpreted as further \-codes. So, basically, you're half right. This is so the macros that Nagios passes in, which may have weird stuff in them, get printed out properly instead of interpreted by the printf itself.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoydI'm a Nagios Fanatic!
User avatar
roddie
Posts: 10
Joined: Tue Apr 24, 2018 3:23 pm
Location: Services (Unhandled)

Re: printf "%b" in notification command definition

Post by roddie »

Okay, brilliant; thanks for your help :P
User avatar
mbellerue
Posts: 1403
Joined: Fri Jul 12, 2019 11:10 am

Re: printf "%b" in notification command definition

Post by mbellerue »

Glad to hear it's working! Also, thanks, Eric!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked