0% found this document useful (0 votes)
78 views1 page

Telegram Bot Status Notification Script

The document contains code to send status update messages to Telegram when a server is up or down. It defines variables for the chat ID, bot ID, host name, date, time, and status messages. It then makes API calls to Telegram to send the messages.

Uploaded by

Rizky Samaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views1 page

Telegram Bot Status Notification Script

The document contains code to send status update messages to Telegram when a server is up or down. It defines variables for the chat ID, bot ID, host name, date, time, and status messages. It then makes API calls to Telegram to send the messages.

Uploaded by

Rizky Samaa
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

\\HRSVR01

\\[Link]

Up
====
:local CHID "XXXXXXXXX";
:local BotID "XXXXXXXX:XXXXXXX-XXX-XXX-XXX";
:local HostStatus "Koneksi Server Anda Sudah Kembali Normal";

:local message "Ping $host $HostStatus";


/tool fetch url="[Link]
chat_id=$CHID&text=$message";
====
Down
====
:local CHID "XXXXXXXXX";
:local BotID "XXXXXXXX:XXXXXXX_XXX_XXX-XXX";
:local HostStatus "Koneksi Server Anda Sedang Down";

:local message "Ping $host $HostStatus";


/tool fetch url="[Link]
chat_id=$CHID&text=$message";
=====
-------------------------------------------
Up
==============
:local hh $host
:local bot "904712554:AXXX"
:local chat "59XXX"
:local datetime "Tanggal: $[/system clock get date] %0A Jam: $[/system clock get
time]"
/tool fetch url="[Link]
chat_id=$chat&text=$datetime %0ARouter: $hh ON \E2\9C\85" keep-result=no
==============
Down
==============
:local hh $host
:local bot "904712554:AAXXXX"
:local chat "550XX"
:local datetime "Tanggal: $[/system clock get date] %0A Jam: $[/system clock get
time]"
/tool fetch url="[Link]
chat_id=$chat&text=$datetime %0ARouter: $com $hh OFF \E2\9D\8C " keep-result=no

Common questions

Powered by AI

The datetime variable is generated by retrieving the current system date and time using the '/system clock get date' and '/system clock get time' commands. This timestamp is incorporated into the notification message to provide context for when the server status change occurred, thereby enhancing the informational value of the notification for decision-making purposes .

The notification system could be expanded by integrating additional monitoring metrics such as bandwidth usage, response time, or external threat alerts. Implementing a graphical user interface (GUI) for visualizing data in real time, or deploying machine learning algorithms to predict potential issues before they occur, could enhance proactive network management and provide comprehensive insights into network health .

Sending both 'Up' and 'Down' status messages is crucial for real-time monitoring and management of server performance. It allows users to quickly react to changes in server status, facilitating prompt troubleshooting and ensuring minimal downtime. This timely communication is essential for maintaining service reliability and client satisfaction .

In this system, CHID is used to specify the chat ID that the notification should be sent to via the Telegram bot. BotID is the identifier of the Telegram bot, which authenticates the message sending process. HostStatus represents the current connectivity status of the server, used to construct the notification message sent to users .

The use of separate fetch commands for 'Up' and 'Down' messages suggests that the system is designed to handle discrete events for changes in server status efficiently. Each command targets a specific scenario, enabling the system to provide targeted and timely updates depending on the reported status, reflecting a need for precise operational communication .

To handle rapid fluctuations in server status without bombarding users with notifications, the system could implement a debounce mechanism, where notifications are only sent if a status change persists beyond a defined interval. This could involve introducing a delay before sending notifications to confirm a steady state, reducing unnecessary alerts .

The system monitors server connectivity status and sends notifications using a Telegram bot. When the server connectivity is normal, it sends an 'Up' message with details such as date, time, and router status to a specified chat ID through the Telegram API. Conversely, when the server is down, it sends a similar 'Down' message indicating the connectivity issue .

Using Telegram for server status notifications is effective due to its wide availability and ease of integration with server scripts via its API. It allows for instant, person-to-person communication across devices, which is ideal for urgent notifications. However, its security depends heavily on the safe handling of API tokens and chat IDs, requiring diligent security practices to prevent misuse .

'keep-result=no' in the fetch command indicates that the output or result of the fetch request is not stored. This is useful in scenarios where storing the response is unnecessary, such as one-time notifications, thereby conserving system resources and simplifying the script as the information is processed in real-time and immediately discarded .

Using a BotID exposed in scripts can be a significant security risk, as it could allow unauthorized parties to send messages or access sensitive data if they gain access to the script. Best practices would include encrypting these credentials or storing them in a secure environment variable, accessible only to authorized processes, to avoid potential leaks .

You might also like