Filling variables for a command in Director

I’m trying to use this plugin:

https://github.com/akadoya/nagios-msteams

The example given in the readme shows export NAGIOS_HOSTALIAS=“hostname” etc… but the command does not seem to offer arguments for this information.

How can I configure the command in Director to populate the various variables with the correct information from Icinga2?

So how would I configure it in Director to populate NAGIOS_HOSTALIAS with $host.name$ for example when the command doesn’t seem to accept arguments?

The plugin relies on environment variables not arguments, so in that aspect it is not compatible with the current usage of Director.

It seems that this in order to use this you will need to define the environment variables on the host you run this plugin and for the user under which the plugin will run ( usually icinga ).

If your Perl is sufficient, you can alter the script to accept the variables ( https://perlmaven.com/argv-in-perl ), and then integrate the script to Director in the usual method.

Colin, you can build a wrapper script for example using bash. You pass the needed values as argument. And the Script set the values as environment variables as the perl script needed written in the docs. After this should run.

Such an idea.

Interesting. I get what you mean but could you maybe show me an example of what the script may look like? Would it just have export NAGIO_HOSTALIAS=$host.name$ or something like that at the top of the script followed by the execution of the perl plugin with webhook argument?

e.g.

#!/bin/bash
NAGIOS_HOSTALIAS=$1
./scriptxy --arg $2

So $1 would be $host.name$ ? I guess that is where I am confused… how does the hostname for example coming from Icinga2 populate the NAGIOS_HOSTALIAS= so it has the correct hostname everytime it executes?

Look here for using arguments in bash scripts https://tecadmin.net/tutorial/bash-scripting/bash-command-arguments/

Icinga call the script like .

/script $host.name$ $service.name$

Thanks Stevie, I’ll check it out.

I have it working! Thank you so much for the suggestion. I now have host and service notifications going to a Microsoft Teams channel.

nice, you’re welcome