NagiosQL: formatting problem of emails


#1

Hi all!

NagiosQL is sending poorly formatted notifications:

""*****""Nagios""*****nnNotification""Type:""PROBLEMnnService:""check_ntpnHost:""www.gipz.comnAddress:""127.0.0.1nState:""CRITICALnnDate/Time:""Thu""Oct""13""13:59:12""CEST""2005nnAdditional""Info:nnNTP""CRITICAL:""server""127.0.0.1,""stratum""2,""offset""-0.000000,""delay""0.02563""

The command that generates this output is:

/usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "Host $HOSTSTATE$ alert for $HOSTNAME$!" $CONTACTEMAIL$

This looks OK. Could it be the printf-version of Gentoo?


#2

evert,

i’m not sure if this might be the problem, but it looks like your missing the backslash for your line breaks. that’s why it all runs together. take a look at my code below. :wink:

command_line /usr/bin/printf “%b” “***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n” | /bin/mail -s “$HOSTNAME$ IS $HOSTSTATE$!” $CONTACTEMAIL$

Edited Thu Oct 13 2005, 05:48AM ]


#3

i just noticed when i replied that it removed the backslashes from my code also, so maybe this isn’t your problem.
Edited Thu Oct 13 2005, 05:49AM ]


#4

Your command defintion looks wrong.

define command{
command_name notify-by-email
command_line /usr/bin/printf “%b” “***** Nagios ***\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $DATETIME$\n\nAdditional Info:\n\n$OUTPUT$" | /bin/mail -s " $NOTIFICATIONTYPE$ alert - $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **” $CONTACTEMAIL$
}

Edited Thu Oct 13 2005, 05:41AM ]


#5

that looks better jakkedup. :slight_smile: when i pasted my code, it blanked the backslashes.


#6

Yup, now it looks decent. Thanks, man! 8)

One little suggestion: Replace ‘…Additional Info:\n\n$OUTPUT$…’ with ‘…Additional Info:\n\n$SERVICEOUTPUT$…’ 8)

Edited Thu Oct 13 2005, 08:49PM ]


#7

The problem is somewhere in NagiosQL: When I use its interface to enter the correct command, it gets ‘mutilated’ to the (non-working) version at the top of this post… The only way to get the correct command in NagiosQL was editing the MySQL table directly… :x


#8

I don’t know what nagiosql is, but it appears to be doing the same thing that your forum is doing. This forum, and nagiosql must be stripping out the backslash. In order to tell the forum and nagiosql to not do this, is to use TWO backslashes in a row, that way it says “look forum/nagiosql, then next backslash is a real character and not a command or something”.

So try your nagiosql thingy and use TWO backslashes instead of just one.
backslashbackslashnbackslashbackslashn =
\n\n


#9

I’ll check it out on monday… :frowning:

(Must be a PHP-thingie?)


#10

Yea, I suppose it is. You also see that behavior in RegEx stuff with nagiostat.