Hi, I have little programming knowledge, but I would like to try to compile a bot with uptime functionality for web services, starting with checking websites and notifying when these services are unavailable. Any suggestions or help is welcome, thanks
Well, it doesn’t seem so hard to do, basically listen for text messages, checking if they are a URL (perhaps a regex for this), keep track of every URL that a user wants to be checked and also a way for users to remove URL to be checked, keeping the track on some kind of database(With folders and file should be enough).
Make a web request every some time to check if the pages are down, perhaps every 5 minutes, if you are using python you can use “Requests” library to make the requests.
You can use deltabot-cli library for the bot, it’s pretty easy to use.
this should be pretty easy to do (well not so easy for someone without much programming experience maybe)
here you have an example bot that checks for URLs/services and reports to a given address when one of them is down:
import time
from threading import Thread
import requests
from deltachat2 import MsgData, events
from deltabot_cli import BotCli
cli = BotCli("uptimebot")
cli.add_generic_option("--notify", help="address to notify if service is down", required=True)
services = [
"https://delta.chat",
"https://support.delta.chat",
]
@cli.on_start
def on_start(bot, args):
Thread(target=worker, args=(bot, args.notify)).start()
def worker(bot, addr):
accid = bot.rpc.get_all_account_ids()[0]
conid = bot.rpc.create_contact(accid, addr, None)
chatid = bot.rpc.create_chat_by_contact_id(accid, conid)
errors = []
while True:
for url in services:
try:
with requests.get(url) as resp:
resp.raise_for_status()
except Exception as ex:
errors.append(f"FAILED: {url}: {ex}")
if errors:
bot.rpc.send_msg(accid, chatid, MsgData(text="\n\n".join(errors)))
time.sleep(60 * 60 * 6) # check every 6 hours
if __name__ == "__main__":
cli.start()
save it in a file like uptimebot.py
then install dependencies:
pip install deltabot-cli requests
then you can run the bot like this:
python uptimebot.py --notify YOUR_EMAIL serve
replace YOUR_EMAIL with the email address you want to notify