Service Apply Rules with array variable

Hello.
I would like to define a service apply rubles, based on an array variable.
I read:
Service Apply for Example - Icinga Director

I would like that $config$ is an array.
I need to enter for example the array (value1;value2;value3) on the host on which service apply is applied.

is it possible to defice the Service Apply Rule as:
Field1: $config$[0]
Field2: $config$[1]
Field3: $config$[2]
?
So
Field1=vaule1
Field2=vaule2
Field3=vaule3

Is it possible?
Thanks a lot
Mario

icinga2 - The Icinga 2 network monitoring daemon (version: r2.13.1-1)

Icinga Web 2 Version
2.9.3
Git commit
c757a17530c326c7d6daebd6171486cb8167a8a1
PHP Version
7.2.24-0ubuntu0.18.04.8
Git commit date
2021-08-10

Modules:
businessprocess 2.3.1
director master
fileshipper 1.1.0
monitoring 2.9.3

It is possible, but not with the Director.
At least I’m not sure how that would be done. Apply For is definitely not usable for that.
You will have to do that via some config file in /etc/icinga2/zones.d or /etc/icinga2/conf.d

# icinga2 console
Icinga 2 (version: r2.12.5-1)
Type $help to view available commands.
<1> => var a = ["hi", "hello"]
null
<2> => a
[ "hi", "hello" ]
<3> => var b = a[0]
null
<4> => b
"hi"
<5> => var c = a[1]
null
<6> => c
"hello"

side note for the future:

I would suggest not using the master but the latest version tag as checkout.

1 Like

Thanks.
My issue is because I need to select different warning and critical threshold for disk usage.

For example:
Disk C: warning 80% critical 90%
Disk D: warning 70% critical 75%
etc.

So, I am not suer that that is the right way to implement it
Thanks

I would check what options are available with the plugin by running -h or /?, etc. It may be possible for specific thresholds, or you could add two services (one for C: with thresholds x and one for D: with thresholds y) to the host.

1 Like

Yes, I know the option available and they work fromo the command line.
But Idon’t like to create a service for every disk.
I preferred to create a “Service Template” and an “Apply rule” for that service instead of create a single service one to one to disks

Well, you keep us quite in the dark on what check you want to use and how you currently have configured it :wink:

For this scenario my first idea is to create an apply rule for each disk check and configure the values there.
Then create a new data field of type array for the disk-partitions add it to the respective hosts and set what partitions they have.
After that you can configure assign where host.vars.disk_partitions_list contains C/D/E/what ever in the apply rule assignment logic.

An apply for would basically work similar to this, you need an array data field at the host and the apply for rule would then create a service for each entry in the array. But this would be the same service config(e.g. thresholds) for all of them expect for the name of the service and partition variable.
You could realize different threshold variables inside the apply for with multiple if clauses when using the config files instead of the Director

2 Likes

Thanks a lot for your big support.
You are right.

Infact I realized multiple “Apply For rule” with different threshold
image

an I used the array list variable on the host with disk:
image

but I preferred to have the possibility to enter in a variable an array for example: (C:; 80%;90%) (D:; 70%;75%)

But as I understand, it is not possible from Director.

1 Like

Hi,

I would suggest you to separate in diff service checks using same service template. From this template then you can create service check for dedicated drive and requered thresholds. For example you can add in service template filed “disk_drive”, “disk_warn” and “disk_crit”. Then you need to create apply rules, where you will specify what kind of parametrs/thresholds you want to have for each drive. It should be apply rule per drive.

So that means if you have 4 drives you will need to know the list of servers which has 4 drives and create from 1 service template 4 service checks. You can put those 4 service checks in set of services and put apply rule on set of service. In this apply rule must be machines on what you want to implement those service checks.

If you are new to icinga2 please check in docu about service template, service objects and apply rules and try to figure it out correlation.

My opinion is that director is good and bad. Bad is cause you cannot use “fancy programing style icinga2 conf” and you cannot do crazy combination of conditions and be like “ninja”. Good thing it will force you to use it on right way to have clean environment.

Hope this can help you.

1 Like

There should be support for Apply For, multidimensional array TBH , in Icinga director

That way as the OP said, you could select different row elements, $config$[1], $config[2]

for an array like
[
[
“value1”,
“value2”
],
[
“value1”,
“value2”
],
[
“value1”,
“value2”
]
]

Would be so very useful, don’t see why it can’t be done…

+1 vote feature request :slight_smile:

1 Like