mirror of
https://github.com/ntop/ntopng.git
synced 2026-04-30 16:09:32 +00:00
Changed notification text and Http method #4269
This commit is contained in:
parent
5a9071ba17
commit
4a9a9feff1
3 changed files with 36 additions and 13 deletions
|
|
@ -58,7 +58,7 @@ end
|
|||
local function readSettings(recipient)
|
||||
local settings = {
|
||||
-- Endpoint
|
||||
url = "https://api.telegram.org/bot" .. recipient.endpoint_conf.telegram_token .. "/sendMessage?chat_id=" .. recipient.recipient_params.telegram_channel .. "&text=", -- this information is coming from the endpoint configuration recipient.endpoint_conf. ...
|
||||
url = "https://api.telegram.org/bot" .. recipient.endpoint_conf.telegram_token .. "/sendMessage"
|
||||
}
|
||||
|
||||
return settings
|
||||
|
|
@ -67,7 +67,7 @@ end
|
|||
-- ##############################################
|
||||
|
||||
-- Function called whenever a message has to be sent out to telegram
|
||||
function telegram.sendMessage(message_body, settings)
|
||||
function telegram.sendMessage(recipient, message_body, settings)
|
||||
local rc = false
|
||||
local retry_attempts = 3
|
||||
|
||||
|
|
@ -77,9 +77,17 @@ function telegram.sendMessage(message_body, settings)
|
|||
|
||||
while retry_attempts > 0 do
|
||||
|
||||
-- In this case "httpGet" method is needed
|
||||
tmp, tmp2 = string.match(message_body, "(.*) %[Info(.*)")
|
||||
|
||||
local post_rc = ntop.httpGet(settings.url .. message_body)
|
||||
if tmp == nil then
|
||||
tmp = message_body
|
||||
end
|
||||
|
||||
-- In this case "httpPost" method is needed
|
||||
local msg = json.encode(message_body)
|
||||
data = '{"chat_id": "' .. recipient.recipient_params.telegram_channel .. '", "text": "' .. tmp .. '", "disable_notification": true}'
|
||||
|
||||
local post_rc = ntop.httpPost(settings.url, data)
|
||||
|
||||
if(post_rc and (post_rc.RESPONSE_CODE == 200)) then
|
||||
rc = true
|
||||
|
|
@ -143,10 +151,8 @@ function telegram.dequeueRecipientAlerts(recipient, budget, high_priority)
|
|||
|
||||
local json_msg = table.concat(alerts, " | ")
|
||||
|
||||
-- traceError(TRACE_ERROR, TRACE_CONSOLE, json_msg)
|
||||
|
||||
if not telegram.sendMessage(json_msg, settings) then
|
||||
return {success=false, error_message="Unable to send alerts to the telegram"}
|
||||
if not telegram.sendMessage(recipient, json_msg, settings) then
|
||||
return {success=false, error_message="- unable to send alerts to the telegram"}
|
||||
end
|
||||
|
||||
-- Remove the processed messages from the queue
|
||||
|
|
@ -166,7 +172,7 @@ function telegram.runTest(recipient)
|
|||
|
||||
local settings = readSettings(recipient)
|
||||
|
||||
local success = telegram.sendMessage("test", settings)
|
||||
local success = telegram.sendMessage(recipient, "test", settings)
|
||||
|
||||
if not success then
|
||||
message_info = i18n("telegram_alert_endpoint.telegram_send_error")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue