Menu

#2 stripcslashes trashes misccommands.cfg

open
nobody
None
5
2009-02-11
2009-02-11
tkivinen
No

The stock commands.cfg-sample from Nagios 3.x (and older) has several commands with embedded "\n" args which get rendered literally after one save of the cfg file. It appears the stripcslashes is a problem in format() and print_list(). Also when add/editing a new item, PHP by default calls magic_quotes_gpc which escapes them as well.

I resolved this by commenting out stripclashes in format() and print_list(), and adding the following in edit.php around line 175:
if(isset($_GET['object']) && $_GET['object']=="misccommands")
$new_entry['data'][command_line] = stripcslashes($new_entry['data'][command_line]);

Example without patch:

define command{
command_name notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

Afterward:

define command{
command_name notify-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****

Notification Type: $NOTIFICATIONTYPE$

Host: $HOSTALIAS$
State: $SERVICESTATE$
Address: $HOSTADDRESS$
Info: $HOSTOUTPUT$

Date/Time: $LONGDATETIME$
" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.