10-20-2017, 12:37 PM
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):
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...
4) In NConf, add the following to Misccommands:
As usual: use at your own risk!
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)
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$"