Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

VaiTon
VaiTon

Posted on

     

Notification service via [matrix] and WebHooks

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:

  1. Invite@_webhook:t2bot.io to your Matrix room.
  2. Send the message!webhook
  3. 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})
Enter fullscreen modeExit fullscreen mode
  • 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 lastn1n-1 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!
Enter fullscreen modeExit fullscreen mode

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...
Enter fullscreen modeExit fullscreen mode

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    🇮🇹
  • Joined

Trending onDEV CommunityHot

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp