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:
[code]
#!/bin/sh
NAG_ROOT="/usr/local/nagios"
CONTACTPAGER=${1}
CONTACTEMAIL=${2}
HOSTALIAS=${3}
HOSTNAME=${4}
HOSTADDRESS=${4}
HOSTSTATE=${5}
NOTIFICATIONTYPE=${6}
HOSTNOTES=${7}
HOSTOUTPUT=${8}
${NAG_ROOT}/libexec/check_smtp -H 88.xxx.xxx.xxx
if “$?” -ne 0 ];
then
Send SMS if SMTP not reply##
/usr/local/nagios/bin/sendsms $CONTACTPAGER 'NOTIFICA: ‘$NOTIFICATIONTYPE’ HOST: ‘$HOSTALIAS’ INDIRIZZO: ‘$HOSTADDRESS’ NOTE: '$HOSTNOTES
else
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
fi[/code]
I have add this command in file command.cfg:
define command {
command_name notify-service-by-smsEmail
command_line $USER1$/check_email_sms $CONTACTPAGER:ns-3$ $CONTACTEMAIL:ns-3$ $HOSTALIAS$ $HOSTNAME$ $HOSTADDRESS$ $HOSTSTATE$ $NOTIFICATIONTYPE$ $HOSTNOTES$ $HOSTOUTPUT$
}
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 172.xx.x.xxx ; 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
register 0 ; DONT REGISTER THIS - ITS JUST A TEMPLATE
}
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…