Define new command location

Hi everyone,

I am new to Icinga2.
By default all check commands are defined in the Icinga Template Libary (ITL) which are located under /usr/share/icinga2/include

Now I want to add a second path for my check commands for that I have adjusted the icinga2.conf with the following line:

include_recursive "/etc/icinga2/conf.d/xxx/command"

Then I defined my own check command ifopserstatus.conf under this path.

The check command looks like this:

object CheckCommand “ifoperstatus” {
command = [ PluginDir + “/check_ifoperstatus” ]
arguments = {
“-H” = “$address$”
“-d” = “$ifdescription$”
“-C” = “$community$”
}
vars.community = “xxx”
}
When I try to restart Icinga2 it reports an error with this file. But I am not really sure where the problem is. The same check command works when I put it in the ITL.

– Unit icinga2.service has begun reloading its configuration
Mai 10 11:21:31 icinga2 safe-reload[542]: Validating config files: Failed
Mai 10 11:21:31 icinga2 safe-reload[542]: [2020-05-10 11:21:31 +0200] information/cli: Icinga application loader (version: r2.11.3-1)
Mai 10 11:21:31 icinga2 safe-reload[542]: [2020-05-10 11:21:31 +0200] information/cli: Loading configuration file(s).
Mai 10 11:21:31 icinga2 safe-reload[542]: [2020-05-10 11:21:31 +0200] critical/config: Error: Object ‘ifoperstatus’ of type ‘CheckCommand’ re-defined: in /etc/icinga2/conf.d/xxx/command/ifstatus.conf: 1:0-1:33; previous definition: in /etc/icinga2/conf.d/rohlmann
Mai 10 11:21:31 icinga2 safe-reload[542]: Location: in /etc/icinga2/conf.d/xxxcommand/ifstatus.conf: 1:0-1:33
Mai 10 11:21:31 icinga2 safe-reload[542]: /etc/icinga2/conf.d/xxx/command/ifstatus.conf(1): object CheckCommand “ifoperstatus” {
Mai 10 11:21:31 icinga2 safe-reload[542]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Mai 10 11:21:31 icinga2 safe-reload[542]: /etc/icinga2/conf.d/xxx/command/ifstatus.conf(2): command = [ PluginDir + “/check_ifoperstatus” ]
Mai 10 11:21:31 icinga2 safe-reload[542]: /etc/icinga2/conf.d/xxx/command/ifstatus.conf(3): arguments = {
Mai 10 11:21:31 icinga2 safe-reload[542]: [2020-05-10 11:21:31 +0200] critical/cli: Config validation failed. Re-run with ‘icinga2 daemon -C’ after fixing the config.
Mai 10 11:21:31 icinga2 systemd[1]: icinga2.service: Control process exited, code=exited status=1
Mai 10 11:21:31 icinga2 systemd[1]: Reload failed for Icinga host/service/network monitoring system.
– Subject: Unit icinga2.service has finished reloading its configuration
– Defined-By: systemd
– Support: http://www.ubuntu.com/support

Could you tell me what I have missed or what I am doing wrong?

best Regards,
ciscler

Have you checked the message in the output?

Error: Object ‘ifoperstatus’ of type ‘CheckCommand’ re-defined:
in /etc/icinga2/conf.d/xxx/command/ifstatus.conf: 1:0-1:33;
previous definition: in /etc/icinga2/conf.d/rohlmann

So, it appears that you have two files with the same CheckCommand defined in
each, under the /etc/icinga2/conf.d directory.

Regards,

Antony.

Hi Antony,

thanks for the quick reply. I do not have the same CheckCommand defined. I have tried to rename the CheckCommand to ifoperstatus2 and I got the same error message when reloading icinga.

best Regards,

Ciscler

So, what is in the file /etc/icinga2/conf.d/rohlmann?

Antony.

This a fold which includes my hosts.

I searched for “object CheckCommand” and there is only the one in the command/ifstatus.conf

root@icinga2:/etc/icinga2/conf.d/rohlmann# grep -r “object CheckCommand” *
command/ifstatus.conf:#object CheckCommand “ifoperstatus2” {

It sounds to me like you have a symlink, because you changed ifoperstatus to
ifoperstatus2 in (I assume) /etc/icinga2/conf.d/xxx/command/ifstatus.conf and
now the file /etc/icinga2/conf.d/rohlmann has the same content.

What do you get from the commands:

cd /etc/icinga2

grep -r ifoperstatus .

?

Antony.

I got the following output:

root@icinga2:/etc/icinga2# grep -r ifoperstatus .

./conf.d/rohlmann/command/ifstatus.conf:#object CheckCommand “ifoperstatus2” {
./conf.d/rohlmann/command/ifstatus.conf:# command = [ PluginDir + “/check_ifoperstatus” ]
./conf.d/rohlmann/opnsense.conf:object Service “ifoperstatus_em1”{
./conf.d/rohlmann/opnsense.conf: check_command = “ifoperstatus”
./conf.d/rohlmann/opnsense.conf:object Service “ifoperstatus_em0”{
./conf.d/rohlmann/opnsense.conf: check_command = “ifoperstatus”

So, now, ifoperstatus (or ifoperstatus2) is not defined at all as a
CheckCommand as far as I can see.

I’m now confused as to what error message you get when reloading icinga2.

Antony.

Hi Antony,

I found the issue.
In the icinga2.conf the direcotry was twice included. At the end of the icinga2.conf file the was this line here

include_recursive “conf.d”

So I removed my previous added line:

include_recursive “/etc/icinga2/conf.d/xxx/command”

Thanks for your help.

best regards,
Ciscler