Giter VIP home page Giter VIP logo

ups-telegram-notify's Introduction

ups-telegram-notify

Notification of the status of an Uninterruptible Power Supply by Telegram

Telegram notification example

In the event of a power failure, you may want to be notified in order to check systems that are not protected. It is also interesting to know whether there has been a prolonged power failure and whether measures have been initiated in the form of shutdowns. To realise this via the messanger Telegram, this Linux script solution can be used.

DOWNLOAD AND INSTALLATION

Download von Notification Script von Github-Repository

cd  /etc/nut
wget https://raw.githubusercontent.com/filipnet/ups-telegram-notify/main/notifycmd.sh

CONFIGURATION

Don´t forget to change the first lines GROUP_IDand BOT_TOKEN Parameters inside the script.

Open file /etc/nut/upsmon.confwith your favorite editor (vim/nano) and add the following lines to the end of the config file.

# Email script for NOTIFYCMD
NOTIFYCMD "/etc/nut/notifycmd.sh"

# Notification events
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

Restart nut services to take affect

sudo systemctl restart nut-server.service
sudo systemctl restart nut-driver.service
sudo systemctl restart nut-monitor.service

LICENSE

ups-telegram-notify and all individual scripts are under the BSD 3-Clause license unless explicitly noted otherwise. Please refer to the LICENSE

ups-telegram-notify's People

Contributors

fabreg avatar filipnet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ups-telegram-notify's Issues

No emoji showed

Hello,
the script works fine, I get the notification from Telegram but unfortunately no emoji are appearing.

Screenshot from 2023-09-13 20-56-54

If i pass

-F "text=echo -e '\U0001F514'" \ (bell)

to the curl, I'm able to see the emoji but there should be a better way.

Thank you!

Something is not working Correctly?

I followed your instructions and it's not working?

If I feed it some text into notifycmd.sh for example [ ./etc/nut/notifycmd.sh "test" ] I get a notification on Telegram, like this

IMG_5268

But when I test the UPS, by pulling power, I don't get any notification?

Here's my notifycmd.sh

#!/bin/bash

GROUP_ID=#######
BOT_TOKEN=######

NOW=$(date)
case "${NOTIFYTYPE}" in
    ONLINE|COMMOK)
        EMOJI=$'\xE2\x9C\x85' # white heavy check mark
        ;;
    ONBATT|COMMBAD|REPLBATT)
        EMOJI=$'\xE2\x9A\xA0' # warning sign
        ;;
    LOWBATT|FSD|NOCOMM|SHUTDOWN)
        EMOJI=$'\xF0\x9F\x86\x98' # squared sos
        ;;
    NOPARENT)
        EMOJI=$'\xF0\x9F\x94\x84' # anticlockwise downwards and upwards open circle arrows
        ;;
esac

EMOJI+=$'\xEF\xB8\x8F' # The emoji should be displayed with emoji presentation
MESSAGE="${EMOJI} UPS Notification%0A"
MESSAGE+="UPS Name: $UPSNAME %0ANotify type: $NOTIFYTYPE %0ANotify message: $*"

curl \
-s \
--data "parse_mode=HTML" \
--data "text=$MESSAGE" \
--data "chat_id=$GROUP_ID" 'https://api.telegram.org/bot'$BOT_TOKEN'/sendMessage' > /dev/null

And I added the text in the /etc/nut upsmod.config as recommended, also added the correct permission to the notifycmd.sh file and added it to the Nut group.

Please help

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.