we have to check databases, where more then one instance is running on one host. Basic idea was as follows:
- create service template for each check
- create host template “db_checks” and assign check templates
- create host template “<DB_SID>” which contains the value of “db_sid” + any instance specific variables and inherits the service checks from “db_checks” template
- assign host template “<DB_SID>” to host, where DB is running
- if there is more then one instance running, assign further “<DB_SID>” templates to this host
This works well for a single instance per host. If I have two instances, the checks will show up only once in Icinga2, because they have the same names. Solution: Use an apply rule “<check_name> $config$”, and assign the checks where “<db_sid>” is set (which is true for host template “<DB_SID>”. Now we see a check for each service called “<check_name> <DB_SID>” and the template “db_checks” is not needed anymore in this configuration, because the rule is assigning the checks to template “<DB_SID>” directly.
Problem: If I assign a variable “connect_string” to a <DB_SID> template “DB1” and the same variable to template “DB2” with a different value (because we need a different connect string there), the assignment of the value to the Instance name is getting lost during inheritance (not a code problem, but conceptual error by ourself). Both checks will use the value assigned to the template that is last in the inheritance list, so one connect will fail.
I assume it is not possible to use a dynamic variable name in the command definition like "connect_string = “connect_string_$db_sid$”? Is there another elegant way to solve this? Please keep in mind, that there might be quite a lot of adaptions/variables per database instance, so an array [ <db_sid> , <connect_string> ] is not what I’m looking for. I need to fill the same variables (command options) dedicated to specific <db_sid> values, so they can coexist on one host.
Thanks a lot for ideas.