Advanced use of dictionary (oracle)

Hi,

i’m using check_oracle_health to monitor some basic oracle metrics. that works well.

Our DBAs are using an additional check script to monitor some deeper metrics (especially to monitor Oracle RAC). Now i want to include these additional checks into Icinga.

Some of the required arguments like DB instance, username and password are already defined in the host object (for use with check_oracle_health). Now i want to use them in a new apply service with my custom command. but how can i do that?

Host Object:

object Host "scan-listener-xyz.localdomain" {
 import "generic-host"
 address = "scan-listener-xyz.localdomain"
 vars.dbtype = "oracle-rac"
 vars.db_instances["DB1"]= {
   oracle_health_username = "icinga"
   oracle_health_password = "pw1"
  }
 vars.db_instances["DB2"]= {
   oracle_health_username = "icinga"
   oracle_health_password = "pw2"
 }
 vars.db_instances["DB3"]= {
   oracle_health_username = "icinga"
   oracle_health_password = "pw3"
 }

Service:

apply Service "RAC Diskgroup " for (db => config in host.vars.db_instances) {
 import "generic-service"
 check_command = "oracle_rac_check"
 vars.plugin_db = db
 vars.plugin_mode = "check_diskgroup"
 vars.plugin_user = ????host.vars.db_instances.????.oracle_health_username????
 vars.plugin_password = ????host.vars.db_instances.????.oracle_health_password????
 vars += config
 display_name = "[" + db + "]" + " Diskgroups"
 assign where host.vars.dbtype == "oracle-rac"
}

Btw…i’ve created a custom command and the check is working if i enter a string into vars.plugin_user & vars.plugin_password.

Hi,

I’d advise checking the docs which explain the apply for loop unrolling first.

config is the loop iterator’s value and contains the sub keys from your nested dictionary.

  vars.plugin_user = config.oracle_health_username

Although I’d recommend to just use oracle_health as CheckCommand, where the generic

vars += config

is sufficient. In the long run, this could be written as "copy every key-value pair from config into vars.
Specifically, this does the following in your example:

vars.oracle_health_username = config.oracle_health_username
vars.oracle_health_password = config.oracle_health_password

Also, I’d suggest storing the passwords in constants, and assign them into host templates, hidden from the actual host object.

If you want to go into deeper nesting of your database dictionaries, check this howto I had written in the past.

Cheers,
Michael

1 Like

Thank you very much for your explanation. this helps me to understand iciniga better.

1 Like