Introduction How to link into Google Voice and send SMS alerts when Nagios detects servers down. Disclaimer: This might work only in...
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)
-Nagios installed (I used Nagios Core 4.1.0 link to how to install it below)
-Python
-git
-Google Voice account
-Python
-git
-Google Voice account
# cd /usr/local/nagios/
# git clone https://github.com/korylprince/pygvoicelib.git
# cd pygvoicelib/
a link can be found on the following page. https://accounts.google.com/b/0/IssuedAuthSubTokens
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.
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.
# python get_auth.py
for 'username' enter your google account email
for 'apppass' enter the onetime use password you generated
for 'apppass' enter the onetime use password you generated
Save the information the script outputs
# vi text.py
Enter the following in the script:
#!/usr/bin/python
import pygvoicelib
import sys
import pygvoicelib
import sys
number = 9518675309
txtmsg = sys.stdin.read()
txtmsg = sys.stdin.read()
client = pygvoicelib.GoogleVoice(username,apppass,auth_token,rnr_se)
client.sms(number,txtmsg)
client.sms(number,txtmsg)
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'
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
# chmod 755 text.py
# 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
}
contact_name googlevoice
use generic-contact
alias Damien Google Voice
host_notification_commands notify-host-by-gv
service_notification_commands notify-service-by-gv
}
# 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
}
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
}
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
}
Conclusion
Now when a server goes down you will get a text to your phone.
No comments
Post a Comment