Questo articolo è disponibile anche initaliano
Have you ever wanted to set up a notification service for your long standing process / monitoring and didn't know how to do it without setting up anMTA?
Don't get me wrong, emails are good, but sometimes you need a faster approach than setting up postfix (or exim4) with a smarthost and bla bla bla when you just need to be able to recieve a notification when something goes wrong!
In this guide we leverage the power of webhooks and the matrix network to do exactly that.
1. Create a webhook
First, create a new Matrix room.Be sure to make it unencrypted, as t2bot.io webhooks bridge still doesn't support encrypted rooms.
Then, followt2bot.io documentation for creating a webhook:
- Invite
@_webhook:t2bot.io
to your Matrix room.- Send the message
!webhook
- The bridge will send you a URL to use alongside simple instructions on how to use it.
2. Create the script
Create a file namednotifyMatrix.py
and paste this snippet:
(I'm using python for simplicity, but you could also do a simplecurl
!)
#!/bin/env python3importrequestsimportsysargs="".join(sys.argv[1:])WEBHOOK="..."BOTNAME="..."requests.post(WEBHOOK,json={"text":args,"format":"plain","displayName":BOTNAME})
WEBHOOK
should be set to the URL that the bot gave you previously.BOTNAME
can be set to anything. It will be used as the username thatsends the message to the Matrix room.
The script simply takes the last arguments, creates a string by joining them (with a space in between each) and sends it to the specified webhook.
Now try running
./notifyMatrix.py ciao!
and you should get a message in the room you created with the contentciao!
.
If everything went well, you should have your notification service up and running, and it took only a couple of minutes!
3. Usage
You can now use the script wherever you want, for example in a system with a software RAID controlled by MDADM:
In/etc/mdadm/mdadm.conf
...PROGRAM /root/notifyMatrix.py...
and you're done!
Credits
If you enjoyed this guide and/or found it useful, consider donating tot2bot.io and to thematrix foundation!
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse