Page 1 of 2

$CONTACTEMAIL$ wouldn't expand to actual value

Posted: Mon Jan 06, 2014 5:21 am
by lkthomas
[1389002582.193171] [2048.1] [pid=11452] **** BEGIN MACRO PROCESSING ***********
[1389002582.193199] [2048.1] [pid=11452] Processing: '/usr/bin/printf "%b" "***** System Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -r [email protected] -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$'
[1389002582.193235] [2048.0] [pid=11452] WARNING: An error occurred processing macro 'CONTACTEMAIL'!
[1389002582.193344] [2048.1] [pid=11452] Done. Final output: '/usr/bin/printf "%b" "***** System Alert *****\n\nNotification Type: \nHost: ptk.one.com\nState: UP\nAddress: ptk.one.com\nInfo: \n\nDate/Time: Mon Jan 6 18:03:02 HKT 2014\n" | /usr/bin/mailx -r [email protected] -s "** Host Alert: ptk.one.com is UP **" $CONTACTEMAIL$'
[1389002582.193424] [2048.1] [pid=11452] **** END MACRO PROCESSING *************


Currently running Ubuntu 12.04 LTS + Nagios core 3.5.1

Anyone have idea what is going on?

Re: $CONTACTEMAIL$ wouldn't expand to actual value

Posted: Mon Jan 06, 2014 10:51 am
by abrist
Can we see the contact definition for this object?

Re: $CONTACTEMAIL$ wouldn't expand to actual value

Posted: Mon Jan 06, 2014 8:31 pm
by lkthomas
define contact {
contact_name thomas
host_notifications_enabled 1
service_notifications_enabled 1
host_notification_period 24x7
service_notification_period 24x7
host_notification_options d,u,r,f,s
service_notification_options w,u,c,r,f,s
host_notification_commands notify-host-by-email,notify-service-by-email
service_notification_commands notify-host-by-email,notify-service-by-email
can_submit_commands 1
retain_status_information 1
retain_nonstatus_information 1
email [email protected]
register 1
}

Re: $CONTACTEMAIL$ wouldn't expand to actual value

Posted: Tue Jan 07, 2014 10:40 am
by abrist
Can you try putting $CONTACTEMAIL$ in quotes in the command definition?

Code: Select all

/usr/bin/printf "%b" "***** System Alert *****\n\nNotification Type: \nHost: ptk.one.com\nState: UP\nAddress: ptk.one.com\nInfo: \n\nDate/Time: Mon Jan 6 18:03:02 HKT 2014\n" | /usr/bin/mailx -r [email protected] -s "** Host Alert: ptk.one.com is UP **" "$CONTACTEMAIL$"
If that still does not work, could you post the full notification commands you are using?

Re: $CONTACTEMAIL$ wouldn't expand to actual value

Posted: Tue Jan 07, 2014 8:51 pm
by lkthomas
That's the result after putting quote on CONTACTEMAIL:

[1389145678.055954] [2048.1] [pid=27967] Processing: '/usr/bin/printf "%b" "***** System Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -r [email protected] -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$'
[1389145678.056022] [2048.0] [pid=27967] WARNING: An error occurred processing macro 'CONTACTEMAIL'!
[1389145678.056049] [2048.1] [pid=27967] Done. Final output: '/usr/bin/printf "%b" "***** System Alert *****\n\nNotification Type: \nHost: ptk.one.com\nState: UP\nAddress: ptk.one.com\nInfo: \n\nDate/Time: Wed Jan 8 09:47:58 HKT 2014\n" | /usr/bin/mailx -r [email protected] -s "** Host Alert: ptk.one.com is UP **" $CONTACTEMAIL$'

Re: $CONTACTEMAIL$ wouldn't expand to actual value

Posted: Wed Jan 08, 2014 11:38 am
by abrist
abrist wrote: If that still does not work, could you post the full notification commands you are using?

Re: $CONTACTEMAIL$ wouldn't expand to actual value

Posted: Thu Jan 09, 2014 9:02 pm
by lkthomas
define command {
command_name notify-service-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: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" "$CONTACTEMAIL$"
register 1
}

Re: $CONTACTEMAIL$ wouldn't expand to actual value

Posted: Fri Jan 10, 2014 10:23 am
by abrist
Remove the "register 1" from the command definition as command do not use template directives . . .

Code: Select all

define command {
command_name notify-service-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: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" "$CONTACTEMAIL$"
}

Re: $CONTACTEMAIL$ wouldn't expand to actual value

Posted: Sun Jan 12, 2014 9:27 pm
by lkthomas
same problem:

[1389580006.047341] [2048.1] [pid=956] Processing: '/usr/bin/printf "%b" "***** System Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mailx -r [email protected] -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" "$CONTACTEMAIL$"'
[1389579946.009623] [2048.0] [pid=956] WARNING: An error occurred processing macro 'CONTACTEMAIL'!


commands.cfg:

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

Re: $CONTACTEMAIL$ wouldn't expand to actual value

Posted: Mon Jan 13, 2014 5:33 pm
by sreinhardt
I have two things to test at the moment. Ideally you should only have one notification command for each notification type on your contact. Lets stick to notify-host-by-email for hosts and notify-service-by-email for services. Also it seems that another person removed the second $ from contactemail and it began working. Normally I wouldn't suggest it, but let's give it a shot for atleast a test. So instead of $CONTACTEMAIL$ use $CONTACTEMAIL This seems to be especially true if some of your output contains escaped html or other code.