Check Host - receive UP Notification bat not DOWN Notificati


Hi all,
i have write a script in bash that use check_smtp for check my email server and if it is down send me Notification SMS Otherwise it send me email. This is my script:



${NAG_ROOT}/libexec/check_smtp -H

if “$?” -ne 0 ];

Send SMS if SMTP not reply##


Send EMAIL if SMTP reply

/usr/bin/printf “%b” “***** Nagios SMS TEST ***\n\nNotification Type: $NOTIFICATIONTYPE\n Host: $HOSTALIAS\nAddress: $HOSTADDRESS\nNotes: $HOSTNOTES\nAdditional Info:\n\n$HOSTOUTPUT" | /usr/bin/mail -s " $NOTIFICATIONTYPE Service Alert: $HOSTALIAS **” $CONTACTEMAIL


I have add this command in file command.cfg:

define command {
	 command_name 	notify-service-by-smsEmail

i have write a test.cfg (it is loaded in nagios.cfg):

define host{
	use		generic-switch-TEST		; Inherit default values from a template
	host_name	test-switch			; The name we're giving to this switch
	alias		test-switch 		; A longer name associated with the switch
	address		; IP address of the switch
	hostgroups   TEST-devices
	contacts	ns-3

define hostgroup{
	hostgroup_name	TEST-devices		; The name of the hostgroup
	alias			TEST Network Devices	; Long name of the group

and in templeates.cfg i have write this:

define contact{
        name                            generic-contact-test    	; The name of this contact template
        service_notification_period     24x7			; service notifications can be sent anytime
        host_notification_period        24x7			; host notifications can be sent anytime
        service_notification_options    w,u,c,r,f,s		; send notifications for all service states, flapping events, and scheduled downtime events
        host_notification_options       d,u,r,f,s		; send notifications for all host states, flapping events, and scheduled downtime events
        service_notification_commands   notify-service-by-smsEmail	; send service notifications via email
        host_notification_commands      notify-service-by-smsEmail	; send host notifications via email
        register                        0       		; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!

define host{
        name                            generic-host    ; The name of this host template
        notifications_enabled           1       	; Host notifications are enabled
        event_handler_enabled           1       	; Host event handler is enabled
        flap_detection_enabled          1       	; Flap detection is enabled
        failure_prediction_enabled      1       	; Failure prediction is enabled
        process_perf_data               1       	; Process performance data
        retain_status_information       1       	; Retain status information across program restarts
        retain_nonstatus_information    1       	; Retain non-status information across program restarts
	notification_period		24x7		; Send host notifications at any time
        register                        0       	; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!

define host{
	name			generic-switch-TEST	; The name of this host template
	use			generic-host	; Inherit default values from the generic-host template
	check_period		24x7		; By default, switches are monitored round the clock
	check_interval		5		; Switches are checked every 5 minutes
	retry_interval		1		; Schedule host check retries at 1 minute intervals
	max_check_attempts	2		; Check each switch 10 times (max)
	check_command		check-host-alive	; Default command to check if routers are "alive"
	notification_period	24x7		; Send notifications at any time
	notification_interval	0		; Resend notifications every 30 minutes
	notification_options	d,u,r		; Only send notifications for specific host states
	contacts		ns-3		; Notifications get sent to the admins by default

finally i have add my group in contacts.cfg:

define contact{
        contact_name     ns-3		; Short name of user
	  use		 	 generic-contact-test		; Inherit default values from generic-contact template (defined above)
        alias            network specialist		; Full name of user
        email            myemailATemailorg	; 
	  pager		 +xxxxxxxxxxxx

When my switch go DOWN i dont receive email/sms…when go UP i receive it.
in Nagios log i have that it send Notification:

What mistake?
Thanks to all for the answers…



I had a right old time of it when trying to get my sendsms script to operate correctly when called from nagios…

Eventually after a couple of days going down dead ends, I found if I rejigged the output and used printf, everything started working.

I don’t know if you are having the same problem, but you might like to try something like this command in your script instead:

  ## Send SMS if SMTP not reply##
   /usr/bin/printf "%b" "\'NOTIFICA: \'$NOTIFICATIONTYPE\' HOST: \'$HOSTALIAS\' INDIRIZZO: \'$HOSTADDRESS\' NOTE: \'$HOSTNOTES"  | /usr/local/nagios/bin/sendsms $CONTACTPAGER




thanks for answer.
i have modify but i receive always only notification of UP but not DOWN.
you think that problem is sendsms:?: but why i receive UP and not DOWN…only thing that change is macro NOTIFICATIONTYPE.


I have test to insert in the script only this:
/usr/bin/printf “%b” “TEST” | | /usr/bin/mail -s “TEST”

But not receive DOWN notification…


Ah, I follow now…
I think maybe $HOSTOUTPUT would also change?
like from “Ping OK” to "(Host Check Timed Out)"
and perhaps the bracket characters are casuing your problem
What if maybe that was not in the command object definition?
Or perhaps include bracket characters in the illegal_macro_output_chars variable in nagios.cfg





Than if i would use $HOSTOUTPUT i cant?


if you remove $HOSTOUTPUT$ from the command object and it works, then the brackets are what is causing a problem.
If you wish to add it back in again, you may be able to if you configure illegal_macro_output_chars to include the brackets.
This will automatically remove them from the output and stop your script falling over
(ie it will send “Host Check Timed Out” instead of “(Host Check Timed Out)”


Yes…it works fine!!! Thanks thanks thanks.
I have also a problem with date with macro $LONGDATETIME my output should be that:
“Date/Time: Tue Mar 18 15:23:14 CET 2008”

but i receive only “Date/Time: True”.
How can format it?



Glad to hear it :frowning:

Not sure on the date issue… possibly it doesn’t work because all the spaces.
Maybe you could use the unixtime macro $TIMET$ instead and convert it using date in your script