Hello There, Guest! Login Register
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Telegram Push notifications

#1
Hi,

In another project I use Telegram to receive push notifications on my phone so I thought it would be nice to have the same in NEMS.
It is actually quite simple to set this up.

For those interested, here are the steps:

1) Get a Telegram account (it is free!): https://telegram.org/
After setting up your account you will have a bot and a chat id.

2) install lua-sec (this will also install lua-socket):


Code:
sudo apt-get install lua-sec


3) Install the following script in /usr/local/bin:
Name the script 'telegram_nems.lua'
This is a simple lua script I wrote just to get this working, so it is really minimal without error checking etc...


Code:
#!/usr/bin/lua
https = require('ssl.https')
local telegram_url = 'https://api.telegram.org/<your bot>/sendMessage?'
local chat_id = '<your chat id>'

     Notification = "Notification Type: " .. arg[1] ..'\n'    --$NOTIFICATIONTYPE$
     Host = "Host: " .. arg[2] ..'\n'                         --$HOSTNAME$
     State = "State: " .. arg[3] ..'\n'                       --$HOSTSTATE$/$SERVICESTATE$
     Address = "Address: " .. arg[4] ..'\n'                   --$HOSTADDRESS$
     Info = "Info: "  .. arg[5] ..'\n'                        --$HOSTOUTPUT$/"$SERVICEOUTPUT$"
     Date_Time = "Date/Time: " .. arg[6] ..'\n'               --$LONGDATETIME$
   if (#arg == 6) then
     message = '***** Nagios ***** ' ..'\n' ..'\n' .. Notification .. Host ..State .. Address .. Info .. Date_Time
   else
     Service = "Service: " .. arg[7] .. '\n'                  --$SERVICEDESC$
     message = '***** Nagios ***** ' ..'\n' ..'\n' .. Notification .. Host  .. Service ..State .. Address .. Info .. Date_Time
   end

local data_str = 'chat_id=' .. chat_id .. '&text=' .. message..''  
local res, code, headers, status = https.request(telegram_url, data_str)

4) In NConf, add the following to Misccommands:

Code:
command_name                          notify-host-by-telegram
command_line                          /usr/local/bin/telegram_nems.lua "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$HOSTSTATE$" "$HOSTADDRESS$" "$HOSTOUTPUT$" "$LONGDATETIME$"


Code:
command_name                          notify-service-by-telegram
command_line                          /usr/local/bin/telegram_nems.lua "$NOTIFICATIONTYPE$" "$HOSTNAME$" "$SERVICESTATE$" "$HOSTADDRESS$" "$SERVICEOUTPUT$" "$LONGDATETIME$" "$SERVICEDESC$"

As usual: use at your own risk!
 
Messages In This Thread
Telegram Push notifications - by baggins - 10-20-2017, 12:37 PM
RE: Telegram Push notifications - by Robbie Ferguson - 10-20-2017, 02:00 PM
RE: Telegram Push notifications - by baggins - 10-20-2017, 04:24 PM
RE: Telegram Push notifications - by Robbie Ferguson - 10-23-2017, 06:48 AM
RE: Telegram Push notifications - by Robbie Ferguson - 10-23-2017, 10:43 AM
RE: Telegram Push notifications - by Robbie Ferguson - 10-25-2017, 09:39 AM
RE: Telegram Push notifications - by Robbie Ferguson - 10-25-2017, 10:31 AM
RE: Telegram Push notifications - by Kaganishu - 10-26-2018, 11:34 AM
RE: Telegram Push notifications - by Robbie Ferguson - 10-26-2018, 08:53 PM
RE: Telegram Push notifications - by Kaganishu - 10-27-2018, 03:42 AM
RE: Telegram Push notifications - by Robbie Ferguson - 10-29-2018, 09:08 AM
RE: Telegram Push notifications - by Kaganishu - 10-29-2018, 10:49 AM
RE: Telegram Push notifications - by Robbie Ferguson - 10-29-2018, 02:38 PM
RE: Telegram Push notifications - by Kaganishu - 10-30-2018, 04:09 AM
RE: Telegram Push notifications - by Robbie Ferguson - 11-08-2018, 11:33 AM
RE: Telegram Push notifications - by baggins - 11-25-2018, 05:47 AM
RE: Telegram Push notifications - by Kaganishu - 11-25-2018, 09:29 AM
RE: Telegram Push notifications - by baggins - 11-25-2018, 09:58 AM
RE: Telegram Push notifications - by Robbie Ferguson - 11-26-2018, 11:05 AM
RE: Telegram Push notifications - by baggins - 11-27-2018, 05:13 AM
RE: Telegram Push notifications - by Robbie Ferguson - 11-27-2018, 10:00 AM
RE: Telegram Push notifications - by baggins - 11-28-2018, 09:50 AM
RE: Telegram Push notifications - by baggins - 11-28-2018, 11:02 AM
RE: Telegram Push notifications - by Robbie Ferguson - 11-28-2018, 11:52 AM
RE: Telegram Push notifications - by Robbie Ferguson - 11-28-2018, 12:45 PM
RE: Telegram Push notifications - by baggins - 11-28-2018, 12:50 PM
RE: Telegram Push notifications - by Robbie Ferguson - 11-28-2018, 01:41 PM
RE: Telegram Push notifications - by Robbie Ferguson - 11-28-2018, 02:05 PM
RE: Telegram Push notifications - by baggins - 11-28-2018, 02:39 PM
RE: Telegram Push notifications - by Robbie Ferguson - 11-28-2018, 02:56 PM
RE: Telegram Push notifications - by baggins - 11-28-2018, 07:16 PM
RE: Telegram Push notifications - by Robbie Ferguson - 11-29-2018, 11:38 AM
RE: Telegram Push notifications - by Robbie Ferguson - 11-29-2018, 12:20 PM
RE: Telegram Push notifications - by baggins - 11-29-2018, 12:30 PM
RE: Telegram Push notifications - by Robbie Ferguson - 11-29-2018, 01:32 PM
RE: Telegram Push notifications - by baggins - 12-02-2018, 11:21 AM
RE: Telegram Push notifications - by Robbie Ferguson - 12-02-2018, 01:04 PM
RE: Telegram Push notifications - by baggins - 12-06-2018, 05:21 AM
RE: Telegram Push notifications - by Robbie Ferguson - 12-11-2018, 11:22 AM
RE: Telegram Push notifications - by baggins - 12-11-2018, 11:53 AM
RE: Telegram Push notifications - by Robbie Ferguson - 12-11-2018, 12:09 PM
RE: Telegram Push notifications - by baggins - 12-11-2018, 12:24 PM
RE: Telegram Push notifications - by Robbie Ferguson - 12-11-2018, 02:29 PM
RE: Telegram Push notifications - by baggins - 12-11-2018, 06:14 PM
RE: Telegram Push notifications - by Robbie Ferguson - 12-16-2018, 04:09 PM
RE: Telegram Push notifications - by baggins - 12-16-2018, 05:58 PM
RE: Telegram Push notifications - by Robbie Ferguson - 12-16-2018, 09:24 PM
RE: Telegram Push notifications - by baggins - 12-17-2018, 04:45 AM
RE: Telegram Push notifications - by Robbie Ferguson - 12-17-2018, 11:01 AM
RE: Telegram Push notifications - by Robbie Ferguson - 12-17-2018, 11:12 AM
RE: Telegram Push notifications - by baggins - 12-17-2018, 12:43 PM
RE: Telegram Push notifications - by Robbie Ferguson - 12-17-2018, 12:57 PM
 
Forum Jump:

Users browsing this thread: 5 Guest(s)