nagios xi sms alerting ahmed

12
Nagios SMS Alerting System 1 SMS Alerting System Version 0.1 (23-10-2010) Mohammed Aijaz Ahmed Network Administrator IST Dept. Amana Steel Buildings and Contracting Co. (www.amanabuildings.com ) [email protected] [email protected]

Upload: rhio-concepcion

Post on 10-Oct-2014

168 views

Category:

Documents


7 download

TRANSCRIPT

Page 1: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  1 

SMS Alerting System

Version 0.1 (23-10-2010)

Mohammed Aijaz Ahmed

Network Administrator

IST Dept.

Amana Steel Buildings and Contracting Co. (www.amanabuildings.com)

[email protected] [email protected]

Page 2: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  2 

Table of contents:

Introduction........................................................................................................ 3

Target audience, assumptions and recommendations………………………………………. 3

Acknowledgements …………………………..………………………………………………..... 3

Installation

Install CentOS 5.4 …………………………………………………………………………….…. 6

Manual installation of Nagios XI…………………………………………………………………. 6

Install SMS server tools …………………………………………………………………………... 6

Configuration

Integrate Nagios with SMS server ………………………………………………………………. 7

Create commands…………………………………………………………………………………. 8

Create SMS contacts………………………………………………………………………………. 10

Associating SMS contact to a service……………………………………………………………. 12

 

 

 

 

 

Page 3: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  3 

Nagios SMS Alerting System

Introduction:

This is a step-by-step guide to implement SMS alerting system with Nagios. Target audience is any beginning to advanced network administrator who wants practical documentation of rumored feature of NagiosXI. As the internet is lousy with documentation on nooks and crannies of NagiosXI SMS support, I’ve tried to provide documentation on SMS alerting with NagiosXI.

Target Audience, Assumptions, and Recommendations:

I assume a few things about the user. First, the user has basic understanding of Linux and networking, especially with Linux users and groups, Linux file permissions and ownership, using command line, etc. Second, I assume the reader has working NagiosXI installation on a physical machine.

I recommend that before implementing this on a production server, the users test this in a controlled environment. I accept no responsibility for damage, misconfiguration or loss of any kind as a result of referring to this documentation. Proceed at your own risk.

Acknowledgements:

As with many human endeavors, this work is made possible with effort of others. For me this effort represents 4 years of learning and network administration. Without the greater Linux community, I would not be able to provide this resource.

I acknowledge that my colleague Mr. Padeep Kumar has contributed his time, suggestions and corrections over the course of this project.

Now, let me welcome you to the pleasure and reliability of SMS alerting with Nagios!

Page 4: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  4 

Objective: To monitor the network and services like SMTP, backup, VPN connectivity, etc. and to get notified via SMS on failure of these services.

Solution: This can be attained by using NagiosXI monitoring system on a Linux server which can monitor servers in data center and remote branch offices. By connecting a GSM modem to the server and configure it to work with Nagios you can receive alerts on your mobile phone.

Hardware consideration

1. HP DL360 G6 Server 2. HDD : 146 GBx2 HDD (Raid 1) 3. RAM : 6 GB RAM 4. CPU : Quad corex2 @ 2.27 Ghz 5. SMPS : Redundant power supply 6. GSM modem : Telular XS5D GSM / FAX modem

Software consideration

1. CentOS release 5.4 2. Nagios XI 2009R1.3G 3. SMS server tools

Installation Stages

Stage 1: Install CentOS 5.4 Stage 2: Manual installation of Nagios XI Stage 3: Install SMS server tools

Configuration Stages

Stage 4: Integrate Nagios with SMS server Stage 5: Create commands Stage 6: Create SMS contacts

 

 

 

 

Page 5: Nagios XI SMS Alerting Ahmed

Nagios SMMS Alerting Sy

Fig. 1

ystem 

is graphical representatiion of Nagioss monitoring

g system set

5

up

Page 6: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  6 

Stage 1: Install CentOS 5.4 final release with server option.

Select all server packages and deselect Graphical desktop environment (Gnome/KDE/etc.). No additional packages required.

Stage 2: Manual installation of Nagios XI is basically done by running a set of shell scripts. Please refer to the document Manual_Installation_Nagios_XI_Instructions.pdf available at Nagios library.

Stage 3: Install SMS server tools utility to send alerts via SMS to mobile phones.

Connect a GSM modem (Telular XS5D GSM/FAX modem) with a valid SIM card to the server via serial cable. By configuring it to work with Nagios we can receive Nagios alerts on mobile phone 24x7.

All you need is to install SMS server tools and then create customized commands and contacts in Nagios to enable it to send alerts via SMS.

Download smstools-2.2.20.tar.gz from http://stefanfrings.de/smstools/index-en.html

Run the following command

# tar -xvzf smstools-2.2.20.tar.gz

Enter the newly created directory

#cd sms

#./install.sh

Normally, the default configuration file /etc/smsd.conf should work fine.

Starting SMS server

#/etc/init.d/sms start

Send a test SMS by running the following command

#sendsms 0507295873 “Last night was exciting, when can we meet again?”

You can check for any errors in /var/log/smsd.log

Adding SMS server to start in default run level 

#echo “/etc/init.d/sms start” >> /etc/rc.d/rc.local

 

 

 

Page 7: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  7 

Stage 4: Integrate Nagios with SMS server tools to send SMS alerts.

The SMS Server Tools have been made to send and receive short messages using GSM modems or mobile phones. It may be used for text messages with 7, 8 and 16 Bit character set as well as for binary messages.

To send short messages, you need to create a simple text file in a spool directory. The program monitors that directory and sends new files automatically. Received messages are stored into text files in another spool directory (http://stefanfrings.de/smstools/index-en.html)

I’ve named this section as “Integration of SMS server tools with Nagios” because here we allow Nagios to write messages into SMS spool directory. The SMS tools program then sends the messages accordingly.

All you need is to give “nagios” user ownership to the spool directories.

#chown –R nagios.nagios /var/spool/sms

To verify the ownership information execute the following command.

#ls –la /var/spool/sms

The result should be as follows

drwxr-xr-x 5 nagios nagios 4096 Aug 8 11:59 .

drwxr-xr-x 17 root root 4096 Aug 8 11:59 ..

drwxr-xr-x 2 nagios nagios 4096 Oct 13 23:36 checked

drwxr-xr-x 2 nagios nagios 4096 Oct 11 11:44 incoming

drwxr-xr-x 2 nagios nagios 4096 Oct 13 23:36 outgoing

With the help of custom commands and services, Nagios can send the short customized messages as SMS. The custom commands/services are discussed in later sections.

Note: The SMS server tools manual can be found at http://stefanfrings.de/smstools/SMS_Applications.pdf

Page 8: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  8 

Stage 5: Create Commands:

Host Command for SMS:

E-mail alert is usually longer which contains the banner of the monitoring system, extra lines and spaces. Commands for sending e-mail alerts are present in the system by default. An SMS alert is intended to be smaller in order to accommodate the information in a single SMS. Commands for sending SMS alerts are not present in the system by default and should be created as follows:

E.g. host command to send SMS alert: (To send host down/recovery alert by SMS)

Go to nagios core config manager commands add new enter command name enter command line select command type as misc command.

notify-host-by-sms: /usr/bin/printf "%b" "Nagios Says: $HOSTNAME$ is $HOSTSTATE$ Info is: $HOSTOUTPUT$ $LONGDATETIME$" | /usr/local/bin/sendsms $CONTACTPAGER$

Click on save and then click on apply configuration.

Tip: Copy the above command (notify-host-by-sms) and paste in the command line as shown above.

Page 9: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  9 

Service Command for SMS:

A service command is created to send service alerts by SMS.

E.g. service command to send SMS alert:

Go to nagios core config manager commands add new enter command name enter command line select command type as misc command.

notify-service-by-sms: /usr/bin/printf "%b" "Nagios Says: $SERVICEDESC$ on $HOSTALIAS$ is: $SERVICESTATE$ $LONGDATETIME$ Info is: $SERVICEOUTPUT$" | /usr/local/bin/sendsms $CONTACTPAGER$

In the above examples the following macros are used and their description is as follows:

$HOSTNAME$ : fetches the host name of the monitored server from the system.

$SERVICEDESC$ : fetches the service description from the system.

$HOSTOUTPUT$ : fetches the output of the host check.

$HOSTSTATE$ : fetches the current state of the host down/up/flapping.

$SERVICEOUTPUT$ : fetches the output result of the service check i.e. service stopped/ok or the numeric output value of the service check e.g. disk usage is 600 MB, etc.

$SERVICESTATE$ : fetches the current state of the service based on the thresholds set. The output is warning/critical/flapping.

$LONGDATETIME$ : fetches the current date and time from the system e.g. 14/10/2010 12:47:31

$CONTACTPAGER$ : fetches the mobile no. specified in the SMS contact. (We enter mobile no. in place of pager no in the template)

 

 

 

 

 

 

 

 

 

Page 10: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  10 

Stage 6: Create SMS contacts

An SMS contact is used to send alerts to a mobile phone. This feature is not available in Nagios XI but can be done by entering mobile phone number in place of pager number in the contact template and then selecting customized host/service commands.

To create an SMS contact click on “contacts” “add new” fill the template as below:

 

 

Enter the contact name, description, time period hosts, time period services and check on “Active”. 

 

 

 

 

 

 

 

Page 11: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  11 

Select the custom host and service command by clicking on the edit button as follows: 

 

 

Similarly, select the proper service command and click on Save. Then click on “Apply configuration”. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Page 12: Nagios XI SMS Alerting Ahmed

Nagios SMS Alerting System  12 

Stage 7: Associating SMS contact to a service: It’s the show time!

Now, since you have successfully installed the SMS server tools, created appropriate check commands, contacts, etc. you will need to assign the SMS contacts to those services for which you want to receive SMS alerts.

To associate a SMS contact to a service go to “core config manager” ”services” select the required service select “Alert settings” tab select the newly created SMS contact click on “save” click on “Apply configuration”

 

 

Hurray… You can now receive your favorite Nagios alerts on your mobile phone even when the Exchange server / Firewall / Router in your datacenter are down.