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.
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.
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.
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
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
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
oh, did i mentioned that I included a director basket for the commands? These baskets are so great, we should have repositories for them
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
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
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
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?
/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.
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.