Skip to content

michaelruck/upsmon2telegram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 

Repository files navigation

upsmon2telegram

Sending upsmon messages to telegram bot

You have to have a running ups/nut system to use this feature.

Network UPS Tools (NUT Server) Ultimate Guide https://www.youtube.com/watch?v=vyBP7wpN72c

Create telegram bot

To send a message to Telegram group or channel, you should first create your own bot. Just open Telegram, find @BotFather and type /start. Then follow instructions to create bot and get token to access the HTTP API.

Create Channel

Create a new Channel in Telegram and add your bot as a member. So your bot could send messages to the Channel.

In order to get Channel Id, first, post any message to the Channel. Then use this link template to get Channel Id:

https://api.telegram.org/bot<YourBOTToken>/getUpdates

Here is a response example:

{
  "ok":true,
  "result": [
    {
      "update_id":123,
      "channel_post": {
        "message_id":48,
        "chat": {
          "id":-123123123, // this is your channel id
          "title":"Notifications",
          "type":"channel"
        },
        "date":1574485277,
        "text":"test"
      }
    }
  ]
}

Script to send messages

Here you will be helped about telegram bots: https://telegram-bot-sdk.readme.io/reference/sendmessage

I have crafted the upsmon2telegram.sh bash script. First create the file in the right place.

sudo nano /usr/bin/upsmon2telegram.sh

Paste the code. Save it. Exit nano. Make the file executable.

sudo chmod +x /usr/bin/upsmon2telegram.sh

Test it:

NOTIFYTYPE=ONBATT upsmon2telegram.sh Test message

You should receive a message in your telegram channel.

Make upsmon do the trick

Edit upsmon.conf
sudo nano /etc/nut/upsmon.conf
RUN_AS_USER root

MONITOR ups@localhost 1 user password master

NOTIFYCMD "upsmon2telegram.sh"

NOTIFYMSG ONLINE "UPS %s on line power" NOTIFYMSG ONBATT "UPS %s on battery" NOTIFYMSG LOWBATT "UPS %s battery is low" NOTIFYMSG FSD "UPS %s: forced shutdown in progress" NOTIFYMSG COMMOK "Communications with UPS %s established" NOTIFYMSG COMMBAD "Communications with UPS %s lost" NOTIFYMSG SHUTDOWN "Auto logout and shutdown proceeding" NOTIFYMSG REPLBATT "UPS %s battery needs to be replaced" NOTIFYMSG NOCOMM "UPS %s is unavailable" NOTIFYMSG NOPARENT "upsmon parent process died - shutdown impossible"

NOTIFYFLAG ONLINE SYSLOG+WALL+EXEC NOTIFYFLAG ONBATT SYSLOG+WALL+EXEC NOTIFYFLAG LOWBATT SYSLOG+WALL+EXEC NOTIFYFLAG FSD SYSLOG+WALL+EXEC NOTIFYFLAG COMMOK SYSLOG+WALL+EXEC NOTIFYFLAG COMMBAD SYSLOG+WALL+EXEC NOTIFYFLAG SHUTDOWN SYSLOG+WALL+EXEC NOTIFYFLAG REPLBATT SYSLOG+WALL+EXEC NOTIFYFLAG NOCOMM SYSLOG+WALL+EXEC NOTIFYFLAG NOPARENT SYSLOG+WALL+EXEC

Reboot your system. Pull the plug and see what happens. Have fun.

About

Sending upsmon messages to telegram bot

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages