Hi,
So I assume you currently don’t have a distributed environment.
You can put it there but I wouldn’t recommend it. Icinga 2 reads all *.conf
files in the conf.d
directory in the default configuration. You can put a service definition/apply rule inside the templates.conf
file since the Icinga 2 config compiler does not care about which object type is configured in which config file.
To keep the configuration clean and clear I recommend to put the service definitions/apply rules in the services.conf
file. Host objects on the other hand in the hosts.conf
file.
This are basically two services:
- HTTP status check
- Certificate expiration check
Both can be handled with the check_http
plugin which is provided by the Monitoring Plugins package and is defined in the ITL with the definition http
.
Now it becomes a bit tricky since both checks would use the custom variables vars.http_*
. If we create an service apply rule both services would use the same attributes and would do a certificate expiration check, we don’t want this. You could define single service objects for each check, for two services this might be a easy possibility, but think ahead and think about you have 10 HTTP status checks and 10 certificate expiration checks, this becomes a bit messy overtime and you have a lot of typing. We don’t want that too.
So let’s dive into a more advanced topic: Apply for rules.
We modify the known host and declare a set for the HTTP status check and a set for the certificate expiration check. The name inside the [ ]
brackets will become the service name that you’ll later see in Icinga Web 2. Since your HTTP service provides a certificate we can turn on SSL and SNI for the HTTP status check.
# vim /etc/icinga2/conf.d/hosts.conf
object Host “test-host-001” {
import “generic-host”
address = "127.0.0.1"
vars.os = "Linux"
vars.osversion = "Debian 10"
vars.vhosts["http internal-service.my.domain"] = {
http_vhost = "internal-service.my.domain"
http_ssl = true
http_sni = true
}
vars.vhosts["certificate internal-service.my.domain"] = {
http_vhost = "internal-service.my.domain"
http_ssl = true
http_sni = true
http_certificate = "7,3"
}
}
Now we define the apply for rule inside the services.conf
file. This will create a service for each set defined using the syntax vars.vhosts["service name"]
. There are also more advanced techniques possible where you can ignore specific values using ignore where expressions
. Please have a look inside the documentation for an example. We now focus on our example:
# vim /etc/icinga2/conf.d/services.conf
apply Service for (vhost => config in host.vars.vhosts) {
import "generic-service"
check_command = "http"
vars += config
}
The config compiler will now create two services for your host.
http internal-service.my.domain
certificate internal-service.my.domain
If you need additional attributes for the services you can add them from the ITL http
template to the set e.g. your URI you can be added with http_uri = /example
.
https://icinga.com/docs/icinga2/latest/doc/10-icinga-template-library/#http
Best regards
Michael