Notification script json to http


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 ?

For inspiration, have a look at how the Teams notification handles the JSON payload: icinga2-teams-notification/teams-notifications-command.conf at e4f4b9c7fb50fd7d4a5366a47bba18ad52fd5eb5 · seffparker/icinga2-teams-notification · GitHub

1 Like

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.

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 :wink:

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. :wink:

Ok, then I think, you really can use the Icinga2 DSL to get all the variables and send them as JSON :smiling_imp:

yeah maybe but I would really need more help on that one. Not really playing with DSL

Well, I’s more consistent then PHP :wink:

Trying to play with that since yesterday, I would really need some help on that one…

  var notification_data = {
    ICINGA_CONTACTALIAS = "$user.display_name$",

Already have my variable with all I need…

But I’m stuck after that about sending that using curl…

what’s wrong with:

    var cmd = [
                "--connect-timeout", "30",
                "--max-time", "60",
                "--silent", "--show-error",
		"--header", "'Content-Type: application/json'",
                "-X", "POST",
		"--data", notification_data,