Page Nav

HIDE

Grid

GRID_STYLE

Get Nagios to send SMS alerts using Google Voice

Introduction How to link into Google Voice and send SMS alerts when Nagios detects servers down. Disclaimer: This might work only in...

Image result for Get Nagios to send SMS alerts using Google Voice

Introduction

How to link into Google Voice and send SMS alerts when Nagios detects servers down.
Disclaimer: This might work only in the United States.

Steps (13 total)

1

Ensure you have the following

-Nagios installed (I used Nagios Core 4.1.0 link to how to install it below)
-Python
-git
-Google Voice account
2

Change directories to your Nagios installation directory

# cd /usr/local/nagios/
3

clone the pygvoicelib using git

4

navigate into the pygvoicelib folder

# cd pygvoicelib/
5

Enable 2-step verification of your google account.

a link can be found on the following page. https://accounts.google.com/b/0/IssuedAuthSubTokens
6

Create an Application Specific password

Navigate to:
https://accounts.google.com/b/0/IssuedAuthSubTokens
scroll to the bottom and in the name field put “Nagios Server” (or whatever other name you want to identify the device). Click on Generate password.
7

You will then be given a one-time use password

8

Back on the Server run

# python get_auth.py
for 'username' enter your google account email
for 'apppass' enter the onetime use password you generated
Save the information the script outputs
9

Create a script text.py

# vi text.py
Enter the following in the script:
#!/usr/bin/python
import pygvoicelib
import sys
number = 9518675309
txtmsg = sys.stdin.read()
client = pygvoicelib.GoogleVoice(username,apppass,auth_token,rnr_se)
client.sms(number,txtmsg)
10

Adjust the script

number = your phone number
username = email address
apppass = the generated password
auth_token = output from step 8
rnr_se = output from step 8
single quote each item example 'tom@email.com'
after saving the file run:
# chmod 755 text.py
11

create a new contact in nagios

# vi /usr/local/nagios/etc/objects/contacts.cfg
add the following to the file:
define contact{
contact_name googlevoice
use generic-contact
alias Damien Google Voice
host_notification_commands notify-host-by-gv
service_notification_commands notify-service-by-gv
}
12

create to notification commands

# vi /usr/local/nagios/etc/objects/commands.cfg
add the following to the file:
define command{
command_name notify-host-by-gv
command_line /usr/bin/printf "%b" "$NOTIFICATIONTYPE$ on $HOSTNAME$\nState: $HOSTSTATE$ Info: $HOSTOUTPUT$" | /usr/local/nagios/pygvoicelib/text.py
}
define command{
command_name notify-service-by-gv
command_line /usr/bin/printf "%b" "$NOTIFICATIONTYPE$ $SERVICEDESC$ on $HOSTALIAS$\nState:$SERVICESTATE$ Info:$SERVICEOUTPUT$" | /usr/local/nagios/pygvoicelib/text.py
}
13

Add the contact gv to one of your hosts

Conclusion

Now when a server goes down you will get a text to your phone.

References

No comments