10RUPTiV
(10RUPTiV)
February 8, 2023, 1:19pm
1
Hi,
Is there an easy way to send notification using an http call with a json instead of having to define all the “environment” variable ?
We are trying to send all notification to an http endpoint that will manage them and it will be easier to maintain having a json that contain everything instead of having to define all variable one by one…
Any idea ?
rivad
(Dominik)
February 8, 2023, 2:55pm
2
1 Like
10RUPTiV
(10RUPTiV)
February 8, 2023, 3:28pm
3
already found one like that for Slack… almost the same code.
I was looking more for a couple lines of code instead of a full script that format the message before sending.
I really need only a curl sending a json of all the data available.
rivad
(Dominik)
February 8, 2023, 3:51pm
4
I don’t get it, why not just rip out the formatting and authentication for Teams and replace it with the one your tool needs?
Maybe you can combine Library Reference - Icinga 2 with Library Reference - Icinga 2 so you don’t need to handle every variable separately but I doubt that your HTTP endpoint can handle Icinga2 objects formatted as JSON without some formatting or in the case of JSON structuring.
<100 variables it’s maybe faster doing it by hand then coding it
10RUPTiV
(10RUPTiV)
February 8, 2023, 3:54pm
5
we are building a custom endpoint that’s why I only need to send a full JSON!
Our endpoint will manage it after!
I think I will modify our actual PHP script that was responsible to send the notification to just also send out a json to our http endpoint.
rivad
(Dominik)
February 8, 2023, 4:10pm
6
Ok, then I think, you really can use the Icinga2 DSL to get all the variables and send them as JSON
10RUPTiV
(10RUPTiV)
February 8, 2023, 4:15pm
7
yeah maybe but I would really need more help on that one. Not really playing with DSL
rivad
(Dominik)
February 8, 2023, 4:29pm
8
10RUPTiV
(10RUPTiV)
February 9, 2023, 3:41pm
9
Trying to play with that since yesterday, I would really need some help on that one…
var notification_data = {
ICINGA_CONTACTALIAS = "$user.display_name$",
ICINGA_CONTACTEMAIL = "$user.email$",
....
ICINGA_USEREMAIL = "$user.email$",
}
Already have my variable with all I need…
But I’m stuck after that about sending that using curl…
rivad
(Dominik)
February 13, 2023, 11:04am
10
}
plugin_output_escaped = plugin_output.replace("\"", "\\\"").replace("\\", "\\\\")
payload_attachments = "{\"@type\":\"MessageCard\",\"themeColor\":\"" + color + "\",\"summary\":\"" + fallback_text + "\",\"sections\":[{\"activityTitle\":\"" + fallback_text + "\",\"facts\":[{\"name\":\"Host\",\"value\":\"" + host_name_with_link + "\"}," + service_details + "{\"name\":\"State\",\"value\":\"" + state_text + "\"}," + state_duration + notification_type_custom_text + "{\"name\":\"Plugin output\",\"value\":\"```" + plugin_output_escaped + "```\"}],\"markdown\":true}]}"
log(LogDebug, "teams-notifications", "Sending notification...generated notification text successfully: " + payload_attachments)
log(LogDebug, "teams-notifications", "Generating notification command")
var payload_argument = escape_shell_arg(payload_attachments)
var teams_webhook_url_argument = escape_shell_arg(teams_webhook_url)
var cmd = [
"curl",
"--fail",
"--connect-timeout", "30",
"--max-time", "60",
"--silent", "--show-error",
"--header", "'Content-Type: application/json'",
"-X", "POST",
"--data", payload_argument,
teams_webhook_url_argument
]
what’s wrong with:
var cmd = [
"curl",
"--fail",
"--connect-timeout", "30",
"--max-time", "60",
"--silent", "--show-error",
"--header", "'Content-Type: application/json'",
"-X", "POST",
"--data", notification_data,
url
]