Skip to content

Instantly share code, notes, and snippets.

@martinrusev
Created September 27, 2015 12:42
Show Gist options
  • Save martinrusev/385a1ddb5ce52e6791e2 to your computer and use it in GitHub Desktop.
Save martinrusev/385a1ddb5ce52e6791e2 to your computer and use it in GitHub Desktop.
amon_integrations
import requests
import json
from amon.apps.notifications.models import notifications_model
from amon.apps.notifications.generator import generate_message
def send_victorops_notification(notification=None):
sent = False
victorops_data = notifications_model.get_for_provider(provider_id='victorops')
url = victorops_data.get('rest_endpoint')
message = generate_message(notification=notification)
# {
# "message_type":"CRITICAL",
# "timestamp":"1383239337",
# "entity_id":"disk space/db01.mycompany.com",
# "state_message":"the disk is really really full"
# }
data = {'message_type': 'CRITICAL',
'entity_id': 'amonalert',
'state_message': message
}
data = json.dumps(data)
error = None
try:
r = requests.post(url, data=data, timeout=5)
except Exception, e:
error = e
return error
import requests
from amon.apps.notifications.models import notifications_model
def send_pushover_notification(message=None):
sent = False
url = "https://api.pushover.net/1/messages.json"
auth_data = notifications_model.get_for_provider(provider_id='pushover')
data = {'token': auth_data.get('application_api_key'),
'user': auth_data.get('user_key'),
'message': message}
error = None
try:
r = requests.post(url, data=data, timeout=5)
except Exception, e:
error = e
return error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment