Permalink
Browse files

Add NEMS Alias to Telegram, improve script

  • Loading branch information...
NEMS Linux
NEMS Linux committed Nov 9, 2018
1 parent f7dc446 commit d459f836ddf31f9fc8b4afaa6e554d8bfa001752
Showing with 9 additions and 4 deletions.
  1. +9 −4 data/1.5/nagios/plugins/telegram_nems.lua
@@ -1,20 +1,25 @@
#!/usr/bin/lua
https = require('ssl.https')
local telegram_url = 'https://api.telegram.org/' .. arg[1] .. '/sendMessage?'
local chat_id = arg[2]
local handle = io.popen("/usr/local/bin/nems-info alias")
local result = handle:read("*a")
handle:close()
local alias = string.gsub(result, "\n", "")
local telegram_url = 'https://api.telegram.org/bot' .. arg[1] .. '/sendMessage?'
local chat_id = '-' .. arg[2]
Notification = "Notification Type: " .. arg[3] ..'\n' --$NOTIFICATIONTYPE$
Host = "Host: " .. arg[4] ..'\n' --$HOSTNAME$
State = "State: " .. arg[5] ..'\n' --$HOSTSTATE$/$SERVICESTATE$
Address = "Address: " .. arg[6] ..'\n' --$HOSTADDRESS$
Info = "Info: " .. arg[7] ..'\n' --$HOSTOUTPUT$/"$SERVICEOUTPUT$"
Date_Time = "Date/Time: " .. arg[8] ..'\n' --$LONGDATETIME$
Alias = "Reporting NEMS Server: " .. alias .. '\n' --NEMS Server Alias
if (#arg == 8) then --assumes this since 8 arguments have been passed
message = '***** Nagios ***** ' ..'\n' ..'\n' .. Notification .. Host ..State .. Address .. Info .. Date_Time
message = '***** NEMS Linux ***** ' ..'\n' ..'\n' .. Notification .. Host ..State .. Address .. Info .. Date_Time .. Alias
else
Service = "Service: " .. arg[8] .. '\n' --$SERVICEDESC$
message = '***** Nagios ***** ' ..'\n' ..'\n' .. Notification .. Host .. Service ..State .. Address .. Info .. Date_Time
message = '***** NEMS Linux ***** ' ..'\n' ..'\n' .. Notification .. Host .. Service ..State .. Address .. Info .. Date_Time .. Alias
end
local data_str = 'chat_id=' .. chat_id .. '&text=' .. message..''

0 comments on commit d459f83

Please sign in to comment.