Skip to content
Permalink
Browse files

Markdown in Telegram

  • Loading branch information...
NEMS Linux
NEMS Linux committed Sep 6, 2019
1 parent f472672 commit 05e1a59d2065fd30dd85d5d3bf1a6067a485e44a
Showing with 17 additions and 17 deletions.
  1. +17 −17 data/1.5/nagios/plugins/notify-by-telegram.lua
@@ -4,7 +4,7 @@
-- Kaganishu for helping with documentation and improvements for NEMS 1.5
-- NickTheGreek for contributing his findings to help improve functionality for NEMS 1.5

-- VERSION 1.5.4
-- VERSION 1.5.6

https = require('ssl.https')
local handle = io.popen("/usr/local/bin/nems-info alias")
@@ -16,30 +16,30 @@ local chat_id = '-' .. arg[2]:gsub('%g', '')

-- UTF-8 Emojis Based on State
if string.find(arg[3]:lower(), "problem") then
scolor = "⚠️" -- Warning Sign
emoji = "⚠️" -- Warning Sign
elseif string.find(arg[3]:lower(), "flappingstart") then
scolor = "⚠️" -- Warning Sign
emoji = "⚠️" -- Warning Sign
else
scolor = "" -- White Heavy Check Mark
emoji = "" -- White Heavy Check Mark
end
-- Extras (may use later)
-- scolor = "🚫" -- No Entry Sign
-- scolor = "❓" -- Question Mark
-- emoji = "🚫" -- No Entry Sign
-- emoji = "❓" -- Question Mark

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: " .. nemsalias .. '\n' --NEMS Server Alias
Notification = "*Notification Type:*\n" .. arg[3] ..'\n\n' --$NOTIFICATIONTYPE$
Host = "*Host:*\n" .. arg[4] ..'\n\n' --$HOSTNAME$
State = "*State:*\n" .. arg[5] ..'\n\n' --$HOSTSTATE$/$SERVICESTATE$
Address = "*Address:*\n" .. arg[6] ..'\n\n' --$HOSTADDRESS$
Info = "*Info:*\n" .. arg[7] ..'\n\n' --$HOSTOUTPUT$/"$SERVICEOUTPUT$"
Date_Time = "*Date/Time:*\n" .. arg[8] ..'\n\n' --$LONGDATETIME$
Alias = "*Reporting NEMS Server:*\n" .. nemsalias .. '\n\n' --NEMS Server Alias

if (#arg == 8) then --assumes this since 8 arguments have been passed
message = scolor .. '\n' .. '\n' .. Alias .. Date_Time .. Notification .. Host ..State .. Address .. Info
message = emoji .. '\n\n' .. Alias .. Date_Time .. Notification .. Host ..State .. Address .. Info
else
Service = "Service: " .. arg[8] .. '\n' --$SERVICEDESC$
message = scolor .. '\n' .. '\n' .. Alias .. Date_Time .. Notification .. Host .. Service ..State .. Address .. Info
Service = "*Service:*\n" .. arg[9] .. '\n\n' --$SERVICEDESC$
message = emoji .. '\n\n' .. Alias .. Date_Time .. Notification .. Host .. Service ..State .. Address .. Info
end

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

0 comments on commit 05e1a59

Please sign in to comment.
You can’t perform that action at this time.