Array and custom vars in host object

Hi,

i’m using the oracle_health plugin to check a lot of different database metrics. because some hosts have dozen of DBs i used an array in the service config. everything is working fine so far.

the oracle_health plugin has different modes, every mode is a different check…for instance “connected users”. now i want to set a custom warning/critical value exactly for this one check mode (connected users). the vars are “vars.oracle_health_warning” and “vars.oracle_health_critical” - every check mode use this vars to define custom warning/critical values!

i can do that global for all databases…

Service:

apply Service “Oracle Users " for (db => config in host.vars.db_instances) {
import “generic-service”
check_command = “oracle_health”
vars.oracle_health_connect = db
vars.sections = [ “database” ]
vars += config
vars.oracle_health_mode = “connected-users”
vars.oracle_health_warning = 100
vars.oracle_health_critical = 200
display_name = “[” + db + “]” + " Connected Users”
assign where host.vars.dbcheck == “oracle”
}

but i want to do that for a specific database (DB1 in the following example), so i think i’ve to edit the host object vars…

vars.db_instances[“DB1”] = {
oracle_health_username = “icinga”
oracle_health_password = “xxx”
}
vars.db_instances[“DB2”] = {
oracle_health_username = “icinga”
oracle_health_password = “yyy”
}

the problem is, i dont know how i can do that just for the connected-users check because every service check (oracle_health_mode) needs his own vars.oracle_health_warning values. should i use an if clause or something else?

You overwrite the vars so maybe only do this if empty or not set? Then you could add it to the host.vars maybe also differentiated by check mode?

i tried to overwrite the default values by adding some syntax to the host object…but this doesn’t work as expected.

1.) first attempt

adding oracle_health_warning/critical to the host object

object Host “host.domain” {
import “generic-host”
import “oracle-checks”
address = “host.domain”
//DB1
vars.db_instances[“DB1”]= {
oracle_health_username = “icinga”
oracle_health_password = “xxx”
oracle_health_warning = “150”
oracle_health_critical = “250”
}

but that changes the warn/crit value for all check modes of oracle_health, so this is not a solution. i just want to change the values for the connected-users check.

2.) second attempt

i tried to overwrite the values only for the connected-users check-mode…

object Host “host.domain” {
import “generic-host”
import “oracle-checks”
address = “host.domain”
//DB1
vars.db_instances[“DB1”]= {
oracle_health_username = “icinga”
oracle_health_password = “xxx”
vars.oracle_health_mode[“connected-users”] = {
oracle_health_warning = “150”
oracle_health_critical = “250”
}
}

but again…no success…

i think this must be syntax problem!?

whats the service name of the service you want to override the vars for?

If you want to do it this way, you need to put logic into your apply rule and use vars.oracle_health_mode.connected-users to match and then overwrite the defaults only for this mode.