Skip to content

Instantly share code, notes, and snippets.

@02strich
Created May 16, 2014 13:48
Show Gist options
  • Save 02strich/440dd9c072cd84c53c1f to your computer and use it in GitHub Desktop.
Save 02strich/440dd9c072cd84c53c1f to your computer and use it in GitHub Desktop.
Twilio Notifications for Check MK
#!/usr/bin/env python
# Send Notifications via SMS (twilio)
import os
import logging
from twilio.rest import TwilioRestClient
ACCOUNT_SID = "<<YOUR SID>>"
AUTH_TOKEN = "<<YOUR TOKEN>>"
if __name__ == '__main__':
message = """%(item_type)s - %(type)s
%(short_date)s
Host: %(host_name)s - %(host_state)s""" % {
'item_type': "SERVICE" if os.environ["NOTIFY_SERVICEDESC"] != '$SERVICEDESC$' else "HOST",
'type': os.environ["NOTIFY_NOTIFICATIONTYPE"],
'short_date': os.environ["NOTIFY_SHORTDATETIME"],
'host_name': os.environ["NOTIFY_HOSTNAME"],
'host_state': os.environ["NOTIFY_HOSTSTATE"]
}
if os.environ["NOTIFY_SERVICEDESC"] == '$SERVICEDESC$':
message = message + "\nOutput: " + os.environ["NOTIFY_HOSTOUTPUT"]
else:
message = message + "\nService: " + os.environ["NOTIFY_SERVICEDESC"] + " - " + os.environ["NOTIFY_SERVICESTATE"]
message = message + "\nOutput: " + os.environ["NOTIFY_SERVICEOUTPUT"]
client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)
message = client.messages.create(to=os.environ['NOTIFY_CONTACTPAGER'], from_="<<YOUR FROM NUMBER>>", body=message)
@Dee-jays
Copy link

Hello,
where i should put this script and how can i activate it? Thank you

@aricade
Copy link

aricade commented Jan 13, 2020

Here are some breadcrumbs I will leave for myself and others...
Read this for instructions as logging into cli as the site user of your check_mk
install twilio library as site user:
OMD[mysite]:~$ pip install twilio

copy the above script to : /omd/sites/name of your site here/share/check_mk/notifications/

edit the following lines as the TwilioRest client has been deprecated.

  • line 7: from twilio.rest import Client
  • line 9: SID
  • line 10: TOKEN
  • line 29: client = Client(ACCOUNT_SID, AUTH_TOKEN)
  • line 30: FROM NUMBER

@TheBigBear
Copy link

How does this send the message? What internet service needs to be available? I would like to setup nodeping on-prem monitoring to watch the on-prem checkmk server can reach the twilio messaging internet infrastructure and have nodeping notify me if it notices that my checkmk cannot send sms alerts via twilio. is a ping check to a specific twilio internet host enough, or do we know a http connection against twilio that I coudl check for on a specifc twilio sms messaging server?

@UnknownRepository
Copy link

Hi are you guys still able to help?

I did as it was informed but I'm still having trouble to make it work.

Where should I Insert the number I want checkmk send the messages to?

@02strich
Copy link
Author

The number is expected in the environment variable NOTIFY_CONTACTPAGER

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment