-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
224 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from africastalking.AfricasTalkingGateway import AfricasTalkingGateway, AfricasTalkingGatewayException | ||
|
||
from hc.front.templatetags.hc_extras import hc_duration | ||
|
||
|
||
class AfricasTalkingSMS(object): | ||
def __init__(self, username, api_key): | ||
self.gateway = AfricasTalkingGateway(username, api_key) | ||
|
||
def send(self, recipients, message): | ||
try: | ||
self.gateway.sendMessage(recipients, message) | ||
|
||
except AfricasTalkingGatewayException as e: | ||
return 'Encountered an error while sending: %s' % str(e) | ||
|
||
|
||
def send_sms(ctx): | ||
check = ctx.get('check', None) | ||
channel = ctx.get('channel', None) | ||
dtfmt = "%Y-%m-%d %H:%M" | ||
|
||
if not (check and channel): | ||
return False | ||
username, api_key, recipients = channel.africas_talking_username, channel.africas_talking_api_key, channel.value | ||
message = """ | ||
HEALTH-CHECKS ALERT! | ||
Name: %(name)s\n | ||
Status: %(status)s\n | ||
Period: %(period)s\n | ||
Last Ping: %(l_ping)s\n | ||
Total Pings: %(t_ping)s\n | ||
""" % dict(name=check.name_then_code(),status=check.status,period=hc_duration(check.timeout),l_ping=check.last_ping.strftime(dtfmt),t_ping=check.n_pings) | ||
instance = AfricasTalkingSMS(username, api_key) | ||
return instance.send(recipients, message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.