Microsoft Teams Connector for notifications

I am trying to use this with director.

I’m struggling to make it work. Is anyone using this? I want to send notifications to Teams.

I have the script in place… executable… path modified… url in place… command defined in director… notifications configured in director with no luck

2 Likes

I don’t use that plugin but it’s probably helpful if you add more details to the actual error or the part that is not working.

Some things that come to mind:

  • is the notification feature enabled?
  • is the script executable for the correct user (probably nagios)?
  • do you see in the icinga2.log that the icinga2 daemon triggered the notification?
1 Like

Notifications are enabled and working fine with custom html email notifications.

The script is executable.

When I look at the log during a notification I see the script being executed and exiting complaining that it requires two arguments -s and -n. I have both of those defined on the command and the preview in Director matches the example config on the github site.

I’m a little confused as to why it isn’t working.

Ok, I had a look at the code of the plugin in and that’s actually pretty straight forward. The error you mentioned is returned by the argparse module. So it’s nothing wrong in the script.

Argparse usually tells you which parameters are required and which one exactly is missing.

Can you share the notification command? And you can change the Python script to get some more output out there. You can get a list of all provided arguments with sys.argv[1:].

This looks like one of the 2 variables is not provided or there is a configuration issue.

object NotificationCommand "teams-notify" {
    import "plugin-notification-command"
    command = [ "/opt/teams_connector/teams_connector.py" ]
    arguments += {
        "-n" = "$notif_name$"
        "-s" = "$notif_state$"
    }
    vars.notif_name = "$host.name$"
    vars.notif_state = "$host.last_hard_state$"
}

This pretty much matches the example config in the github repo. This is the preview of the command in the Director web interface.

In the config.json file I pasted the webhook url in the quotes after url and did not change anything else.

I tried running it and supplying arguments at the command line like -s 1 -n “hostname” and it doesn’t complain that an argument is missing but nothing ever shows up in Teams.

I know the webhook works because I tried a Nagios perl based plugin with the webhook and it showed up in Teams.

If I cannot get this plugin to work I will likely go back to that one and try to make it work. I also had trouble with no notifications hitting Teams with the perl based plugin when I used it in Icinga2 via Director. My testing that did show up in Teams was from the command line supplying bogus argument data.

Perl based plugin

UPDATE:

I just recreated everything (the code snippet above is still accurate) and I’m watching the logs when notifications are firing and I no longer see the error about missing arguments but nothing ever hits Teams :frowning:

Switching gears here… with respect to the perl based plugin here.

How in Icinga (Director) can I have the command provide the export information to populate the notification? I have it successfully sending to my Teams webhook… but I don’t understand how to populate for example NAGIOS_HOSTALIAS with the icinga hostname

Hello,

I have forked the nagios-msteams and removed the requirements of environment variables in favor of configurable arguments to work directly with the Director. To have the same style as the default mail notification commands, i splitted it into two scripts. One for hosts and one for services. I used the default mail notification command parameters as a start, so the parameters are nearly the same. Cleanup is necessary here because its more like a clone :slight_smile:

oh, did i mentioned that I included a director basket for the commands? These baskets are so great, we should have repositories for them :slight_smile:

Regards,
Rafael

3 Likes

I’m trying your fork.
Does the Teams webhook go under the -p page value, it’s not entirely clear or do I need to create my own argument for webhook

Yes, its the -p switch. You can use the default “pager” in your user (contact) to place the webhook url there.

Even if you do not use the Director, you can get an overview for the command, if you take a look in the director basket:

But keep in mind, that this is a nearly direct clone of the mail notification command. Not all parameters are working with the teams script. I need to clean them up

1 Like

Thanks for the that, I’ve sorted a custom notification, I suspect the others will work.
I did notice the link came through as https://monitoring.mydomane.com

Do i need to and a specific field for that?

you need to add -icingaweb2url ‘https://yourdomain.com/icingaweb2’ as switch/variable or simply change the default one directly in the script (my $icingaweb2url = https://monitoring.mydomane.com/icingaweb2")

1 Like

added the variable notification_icingaweb2url to the Notification template it’s worked a treat, just needed to get the fqdn and path sorted. Thanks for the help

1 Like

Its funny: by reading the code, i have no idea why that is working :slight_smile:

Here is an example for the notifications:

Hi!
I have imported the JSON file for director BASKET…
I have also restore the 2 notifications commands from JSON

I created a command like this:
/etc/icinga2/scripts/teams-service-notification.pl -p https://outlook.office.com/webhook/92d608da-f23d-45b0-aae3-1c12xxxxx@0f8443ec-43ff-47f7-acd2-xxxxxxxxxxxx

But no notification arrive to my channel…
How do I have to create the command for notification ?
THX

Do you get any output from the command when running it from the command line?
Have you tried adding more parameters, like hostname, servicename, serviceouput?

if you execute your command line from the console it should work.

“/etc/icinga2/scripts/teams-service-notification.pl -p https://outlook.office.com/webhook/92d608da-f23d-45b0-aae3-1c12xxxxx@0f8443ec-43ff-47f7-acd2-xxxxxxxxxxxx” are enough parameters to send the notification. It willl throw some errors, but it works.

the Output on the console should look like this:

/etc/icinga2/scripts/teams-service-notification.pl -p https://outlook.office.com/webhook/x
Use of uninitialized value $servicestate in string at /etc/icinga2/scripts/teams-service-notification.pl line 80.
Use of uninitialized value $hostdisplayname in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 81.
Use of uninitialized value $servicename in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 81.
Use of uninitialized value $servicestate in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 81.
Use of uninitialized value $hostdisplayname in string at /etc/icinga2/scripts/teams-service-notification.pl line 83.
Use of uninitialized value $servicename in string at /etc/icinga2/scripts/teams-service-notification.pl line 83.
Use of uninitialized value $serviceoutput in string at /etc/icinga2/scripts/teams-service-notification.pl line 83.
Use of uninitialized value $servicename in substitution (s///) at /etc/icinga2/scripts/teams-service-notification.pl line 106.
Use of uninitialized value $hostname in substitution (s///) at /etc/icinga2/scripts/teams-service-notification.pl line 107.
Use of uninitialized value $hostname in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 108.
Use of uninitialized value $servicename in concatenation (.) or string at /etc/icinga2/scripts/teams-service-notification.pl line 108.
Request:
POST https://outlook.office.com/webhook/x
Content-Type: application/json

{"sections":[{"facts":[{"value":"","name":"Host:"},{"value":"","name":"Service:"},{"value":"","name":"Details:"}]}],"summary":" :  is ","title":" :  is ","themecolor":null,"@type":"MessageCard","@context":"https://schema.org/extensions","potentialAction":[{"targets":[{"os":"default","uri":"https://dom/icingaweb2/monitoring/service/show?host=&service="}],"@type":"OpenUri","name":"Open in Icinga2"}]}

Response:
HTTP/1.1 200 OK
Cache-Control: no-cache
Date: Mon, 09 Mar 2020 07:51:44 GMT
Pragma: no-cache
Content-Length: 1
Content-Type: text/plain; charset=utf-8
Expires: -1
[...]

1

{"sections":[{"facts":[{"value":"","name":"Host:"},{"value":"","name":"Service:"},{"value":"","name":"Details:"}]}],"summary":" :  is ","title":" :  is ","themecolor":null,"@type":"MessageCard","@context":"https://schema.org/extensions","potentialAction":[{"targets":[{"os":"default","uri":"https://dom/icingaweb2/monitoring/service/show?host=&service="}],"@type":"OpenUri","name":"Open in Icinga2"}]}r

If this is not working you have some other problems.

Hi and thanks for the plugin.

Could you please guide me how to import the json to get the command with all arguments?

I just imported the json into a basket using director but I cannot see the command with arguments imported… I had to create the command manually and use the -p = $user.pager$ to make it work as a test.

Hi,

after import, click on Snapshots, select the only one that is there and click import.

1 Like

Thank you for your help. Now I’m getting notifications on teams.

Cris,

1 Like

Hello,

I have already configured this addon.
But the Problem ist, i couldnt receive any notifications.
When i try “/etc/icinga2/scripts/teams-service-notification.pl -p https://outlook.office.com/webhook/92d608da-f23d-45b0-aae3-1c12xxxxx@0f8443ec-43ff-47f7-acd2-xxxxxxxxxxxx”

The Notification is in Teams…
What i did wrong?

Kind regrads :slight_smile:

Update:
I used the -p option and
I removed the Value “$user.pager$” and set my webhook link and it works.
(“value”: “$user.pager$”)
:slight_smile:

1 Like