Learning Academy

The Cure of Ignorance is to Question. MUHAMMAD (PBUH)

Monitoring

Nagios SMS Alerts using CURL and External HTTP SMS Gateway

Configure Nagios.

We need to configure following CFGs

Edit commands.cfg

vi /etc/Nagios/objects/commands.cfg

and add

################################################################################
#
# SMS  NOTIFICATION COMMANDS
#
# These are some example notification commands.
# Please provide details of PhoneNumber, User, Password and http://
# you can mention a single PhoneNumber of Named List in PhoneNumber variable.
#
################################################################################

# ‘notify-host-by-SMS’ command definition
define command {
command_name    notify-host-by-sms
command_line    /usr/bin/curl -d ‘PhoneNumber=’ -d ‘user=’ -d ‘password=’  -d ‘text=”* Nagios * Notification Type: $NOTIFICATIONTYPE$ Host: $HOSTNAME$ State: $HOSTSTATE$ Address: $HOSTADDRESS$ Info: $HOSTOUTPUT$ Date/Time: $LONGDATETIME$”‘
http://<Server-IP>:<Server-Port>
}

# ‘notify-service-by-SMS’ command definition
define command {
command_name    notify-service-by-sms
command_line    /usr/bin/curl -d ‘PhoneNumber=’ -d ‘user=’ -d ‘password=’ -d ‘text=”* Nagios * Notification Type: $NOTIFICATIONTYPE$ Service: $SERVICEDESC$ Host: $HOSTALIAS$ Address: $HOSTADDRESS$ State: $SERVICESTATE$ Date/Time: $LONGDATETIME$ Additional Info:$SERVICEOUTPUT$”‘
http://<Server-IP>:<Server-Port>

}

Edit templates.cfs

Now edit templates.cfs

vi /etc/Nagios/objects/templates.cfg

and add

###############################################################################
###############################################################################
#
# CONTACT TEMPLATES
#
###############################################################################
###############################################################################

# Generic contact definition template – This is NOT a real contact, just a template!

define contact{
name
generic-contact         ; The name of this contact template
service_notification_period          24×7                    ; service notifications can be sent anytime
host_notification_period              24×7                    ; 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-email ; send service notifications via email
service_notification_commands   notify-service-by-sms,notify-service-by-email  ; send service notifications via email and SMS
host_notification_commands       notify-host-by-email    ; send host notifications via email
host_notification_commands       notify-host-by-sms,notify-host-by-email    ; send host notifications via email and SMS
register                                          0                       ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL CONTACT, JUST A TEMPLATE!
}

Once you’ve made all required changes, you may wish to check the nagios configuration. Please Issue

nagios -v /etc/nagios/nagios.cfg

and check there are no warnings and errors. It should appear something like this:

…….
Checking for circular paths between hosts…
Checking for circular host and service dependencies…
Checking global event handlers…
Checking obsessive compulsive processor commands…
Checking misc settings…
Total Warnings: 0
Total Errors:   0

Things look okay – No serious problems were detected
If you’re all good, you can then reload your nagios configuration

/etc/init.d/nagios restart

You should now be able to receive SMS alerts via Nagios.

Please monitor log files SMS alerts

tail -f /var/log/nagios/nagios.log

OR

tail -f /var/log/messages

I hope this will work for you and thanks for visiting https://www.learnacad.com

References

  1. http://www.nagios.org
  2. http://www.nagios.org/about/
  3. http://support.nagios.com/knowledgebase
  4. http://exchange.nagios.org/

Muhammad Shaukat

Content Developer at LearnAcad.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Pin It on Pinterest