#!/bin/sh # $1 = event type (ONLINE, ONBATT, LOWBATT, FSD, etc.) # Configuration MIKROTIK_TARGETS="192.168.7.1 103.125.50.7" TELEGRAM_BOT_TOKEN="6770207225:AAG3yNPepyhhGXqNh8BYjLYUMctc1DSfrH4" TELEGRAM_CHAT_ID="6796478523" # Message for Telegram DATE=$(date "+%Y-%m-%d %H:%M:%S") MESSAGE="UPS Notification: $1 at $DATE" # 1. Send to Telegram using CURL (Secure) curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" -d chat_id="$TELEGRAM_CHAT_ID" -d text="$MESSAGE" > /dev/null 2>&1 & # 2. Send to MikroTik Routers for IP in $MIKROTIK_TARGETS; do # Log event ssh -i /root/.ssh/id_rsa -y upsuser@$IP "/log warning \"UPS Notification: $1\"" & # Shutdown on Critical if [ "$1" = "LOWBATT" ] || [ "$1" = "FSD" ]; then ssh -i /root/.ssh/id_rsa -y upsuser@$IP "/system shutdown" & fi done wait