Added slack

This commit is contained in:
Cory Hawkless 2022-10-03 14:35:13 +10:30
parent 2b1bf7f6d2
commit ee8d75b637
1 changed files with 26 additions and 1 deletions

View File

@ -6,6 +6,29 @@ import json
from telnetlib import theNULL
import pingparsing
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={
"1": {
@ -61,7 +84,9 @@ def pinger(test_id):
notify=1
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)