$CONTACTEMAIL$ wouldn't expand to actual value

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.
lkthomas
Posts: 7
Joined: Mon Jan 06, 2014 5:11 am

$CONTACTEMAIL$ wouldn't expand to actual value

Post 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?
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

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

Post by abrist »

Can we see the contact definition for this object?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
lkthomas
Posts: 7
Joined: Mon Jan 06, 2014 5:11 am

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

Post 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
}
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

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

Post 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?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
lkthomas
Posts: 7
Joined: Mon Jan 06, 2014 5:11 am

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

Post 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$'
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

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

Post by abrist »

abrist wrote: If that still does not work, could you post the full notification commands you are using?
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
lkthomas
Posts: 7
Joined: Mon Jan 06, 2014 5:11 am

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

Post 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
}
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

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

Post 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$"
}
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
lkthomas
Posts: 7
Joined: Mon Jan 06, 2014 5:11 am

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

Post 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$"
}
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

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

Post 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.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked