Added slack
This commit is contained in:
parent
2b1bf7f6d2
commit
ee8d75b637
27
pingmon.py
27
pingmon.py
|
@ -6,6 +6,29 @@ import json
|
||||||
from telnetlib import theNULL
|
from telnetlib import theNULL
|
||||||
import pingparsing
|
import pingparsing
|
||||||
from prometheus_client import CollectorRegistry, Gauge, push_to_gateway
|
from prometheus_client import CollectorRegistry, Gauge, push_to_gateway
|
||||||
|
import logging
|
||||||
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
|
|
||||||
|
import os
|
||||||
|
from slack import WebClient
|
||||||
|
from slack.errors import SlackApiError
|
||||||
|
|
||||||
|
slack_token = 'xoxb-250697658007-4127858946773-gyM0PMGA5XPbh3ZEYot4Yy5Z'
|
||||||
|
def slack_message(message, channel):
|
||||||
|
client = WebClient(token=slack_token)
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = client.chat_postMessage(
|
||||||
|
channel=channel,
|
||||||
|
text=message
|
||||||
|
)
|
||||||
|
except SlackApiError as e:
|
||||||
|
# You will get a SlackApiError if "ok" is False
|
||||||
|
assert e.response["error"] # str like 'invalid_auth', 'channel_not_found'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tests={
|
tests={
|
||||||
"1": {
|
"1": {
|
||||||
|
@ -61,7 +84,9 @@ def pinger(test_id):
|
||||||
notify=1
|
notify=1
|
||||||
|
|
||||||
if notify:
|
if notify:
|
||||||
print(json.dumps(ping_parser.parse(result).as_dict(), indent=4))
|
issue_data=json.dumps(ping_parser.parse(result).as_dict(), indent=4)
|
||||||
|
slack_message(issue_data,"ng-alerts")
|
||||||
|
print(issue_data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue