Hello Community,
Grafana is really a great art developed by the team.
Alert messages from Grafana panel can be sent on WhatsApp opting any WhatsApp API service provider. Text in “message” portion of alert panel can be sent on WhatsApp
In this example, Chat-API is used as WhatsApp API service provider. Free for first 3 days. After creating account notedown https APIURL and token.
Steps:
- Install Flask dependencies, Create Flask webserver use below py script(app.py)
from flask import Flask, request, jsonify
from wabot import WABot
import json
app = Flask(__name__)
@app.route('/', methods=['POST'])
def home():
if request.method == 'POST':
print(request.json)
bot = WABot(request.json)
return bot.processing()
if(__name__) == '__main__':
app.run(host="localhost", port=8000)
- In another py script (wabot.py) enter details of your Chat-API APIURL and token. At the end, enter details of country code and phone number
import json
import requests
import datetime
class WABot():
def __init__(self, json):
self.json = json
self.dict_messages = json
# Chat-API Details
self.APIURL = 'https://api.chat-api.com/instance......./'
self.token = '.....................'
def send_requests(self, method, data):
url = f"{self.APIURL}{method}?token={self.token}"
headers = {'Content-type': 'application/json'}
answer = requests.post(url, data=json.dumps(data), headers=headers)
return answer.json
def send_message_with_phone(self, phoneNumber, text):
data = {"phone": phoneNumber,
"body": text}
answer = self.send_requests('sendMessage', data)
return answer
def processing(self):
# print("messages = ",self.dict_messages)
if self.dict_messages != []:
for message in self.dict_messages:
# print("message = ",message)
if message == "message":
text = self.dict_messages[message]
return self.send_message_with_phone('91xxxxxxxxxx',text)
- Create notification channel of type - webhook, url - http://localhost:8000/, Http Method - POST
- Add this notification channel in your Grafana alert panel. In alerting state, Grafana Webhook will ping flask webserver and expose message through WhatsApp API.
- Keep app.py running
Explore Grafana!!!