Telegram Notifications for PPPoE Status
Telegram Notifications for PPPoE Status
The script uses different segments for 'On Up' and 'On Down' events. In the 'On Up' section, the script gathers data when a user logs in successfully and sends a message including the user's name, login time, and other connection details. Conversely, in the 'On Down' section, it triggers upon a user disconnection, sending a notification with the date, time, and active client count, thereby allowing it to differentiate between online and offline status .
When a user logs in, the script captures the event by utilizing the PPP active state and retrieves specific details about the user, such as IP address, uptime, and caller-id. It constructs a message which includes the user's name, the current date and time, IP client address and the number of active clients, and sends this information using a constructed Telegram API URL .
The script constructs a Telegram API URL with parameters including the bot token, chat ID, and the message text. This URL is used by the 'tool fetch' command to send HTTP GET requests, which dispatch messages to a particular chat specified by the chat ID on Telegram .
The script primarily functions to monitor a system's status and send notifications via Telegram. It reports both successful logins and login failures by users, along with pressing events like system power restoration. This is achieved through fetching Telegram API URLs to send appropriate messages based on the system events detected .
Incorrect Telegram bot token or chat ID would result in failed message delivery since the API calls would not reach the intended recipients or the authentication would be invalid. This could lead to missed notifications about critical system events, impacting the monitoring and response efficiency of the overall system .
For system reboot notifications, the script checks a global variable 'RebootStatus'. If the system starts after losing power and the 'RebootStatus' is not already true, it sends a message notifying the event. The script then sets 'RebootStatus' to true to prevent duplicate notifications unless the global status is reset, ensuring it only sends messages when the state changes .
The 'TGSendMessage' function encapsulates the logic for sending messages via Telegram by crafting the API URL with dynamic parameters like bot token, chat ID, and message text. This function is modular, allowing the main script to call it whenever a Telegram message needs to be sent, supporting cleaner and more maintainable code structures .
Employing a global variable like 'RebootStatus' allows the script to maintain state across sessions, which is critical for determining whether a reboot notification has already been sent. This minimizes redundant messaging and ensures notifications are sent only during state changes, which is particularly important in preventing alert spamming and maintaining relevant notification flow .
Incorporating system clock information into messages provides precise timestamps for each event notification, which is crucial for tracking and correlating events in system monitoring. This temporal data allows administrators to accurately analyze and respond to issues as they arise and to understand patterns in system behavior over time .
Using a Telegram bot provides an automatic, scalable solution for notifications without requiring additional infrastructure. Telegram offers APIs that developers can easily integrate into scripts, allowing for real-time messaging that's particularly useful in system monitoring. Additionally, Telegram is a widely-used application, making it accessible for both administrators and users .