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)
@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