Is it possible to send alert notifications to a Telegram group or contact?
Q: I need to post a message to a Telegram room every time alert is executed. How can I do that? A: Follow the below tutorial on how to post IPNetwork Monitor alert notifications to Telegram chat. We will create a bot for this purpose, but will only use the bot’s token (won’t implement any response handling). Screenshots below were taken using Android client for Telegram.1. Create a bot
Contact BotFather, start a chat with it, and issue a command /newbot. Give new bot a name and a username of your choice:2. Create a new group chat or talk to the bot directly
Either create a new group and invite your bot to it, or just locate it by name (this is IPNetwork-demo above; use the one of your own choice) and start a chat. You need to type first “/start” command to activate bot, then any message (such as “Hi”) to this chat:https://api.telegram.org/botBOT_TOKEN/getUpdateswhere BOT_TOKEN is the token string obtained at step 1. The URL, if crafted correctly, will return a JSON object; locate chat ID in it:
3. Create Execute program action
Now open IPNetwork Monitor GUI client and create new “Execute program” action (click “Alerting > Alerts”, select “Simple Actions” tab):- Mode: set to Run program
- Path: $IPNetworkInstallDir\curl.exe (curl.exe bundled with IPNetwork Monitor)
- Arguments: a very long line that looks exactly like this:
-s --max-time 10 -d "chat_id=your_chat_id&disable_web_page_preview=1&parse_mode=Markdown" --data-urlencode "text=[$MonitorName]($MonitorReportUrl) on [$HostName]($HostReportUrl) - $EventShortDescription $Duration" -k https://api.telegram.org/botyour_token/sendMessage
where your_chat_id: chat ID obtained at step 2 your_token: token obtained at step 1 - Credentials for authentication are not necessary, leave them empty.
4. Test Telegram notifications
Now that “Send to Telegram” action has been added to alerts, try putting a monitor to Down state and back (by altering its “State conditions” and polling the monitor), or use “Alerting > Testing” tab to simulate alert execution. If Telegram integration has been done correctly, you will see something like below in your Telegram chat:5. Troubleshooting
In case the notification testing (see step 4. above) doesn’t result in message appearing in the corresponding Telegram chat, try doing the following: a. Open, in your browser, the below URL:https://api.telegram.org/botyour_token/sendMessage?chat_id=your_chat_id&disable_web_page_preview=1&parse_mode=Markdown&text=Test%20messagehaving first replaced both “your_token” and “your_chat_id” placeholders with appropriate strings obtained at earlier steps. If you have set up everything correctly
- the “Test message” string should be posted to corresponding Telegram chat
- the page displayed in browser (JSON response) should start with “ok: true” record
C: cd "C:\program Files (x86)\IPNetwork Monitor" curl.exe --max-time 10 -d "chat_id=your_chat_id&disable_web_page_preview=1&parse_mode=Markdown" --data-urlencode "text=Test message" https://api.telegram.org/botyour_token/sendMessageagain, having first replaced both “your_token” and “your_chat_id” placeholders with appropriate strings. Note that curl.exe arguments should all be printed on the same line (do not insert any linebreaks). Unless you get no clues why posting notifications to Telegram chat fails, send us the test results (what is printed and displayed when you perform checks a. and b. above), along with error message(s) IPNetwork prints when you try to send corresponding test alert.