# Advanced use of dictionary (oracle)

**URL:** <https://community.icinga.com/t/advanced-use-of-dictionary-oracle/3335>\
**Category:** Service Monitoring\
**Created:** [January 28, 2020, 4:34pm UTC](https://community.icinga.com/t/advanced-use-of-dictionary-oracle/3335 "2020-01-28T16:34:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sbeee](https://community.icinga.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sbeee](https://community.icinga.com/u/sbeee)\
**Post date:** [January 28, 2020, 4:34pm UTC](https://community.icinga.com/t/advanced-use-of-dictionary-oracle/3335/1 "2020-01-28T16:34:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dnsmichi](https://community.icinga.com/user_avatar/community.icinga.com/dnsmichi/32/7721_2.png) [@dnsmichi](https://community.icinga.com/u/dnsmichi)\
**Post date:** [January 28, 2020, 6:04pm UTC](https://community.icinga.com/t/advanced-use-of-dictionary-oracle/3335/2 "2020-01-28T18:04:30Z")

</div>

Hi,

I’d advise checking the [docs](https://icinga.com/docs/icinga2/latest/doc/03-monitoring-basics/#apply-for-and-custom-variable-override) which explain the apply for loop unrolling first.

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

```auto
  vars.plugin_user = config.oracle_health_username

```

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

```auto
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:

```auto
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](https://community.icinga.com/t/dsl-flatten-a-nested-dictionary-with-a-function-for-apply-for-rules/1330) I had written in the past.

Cheers,  
Michael

---

<div class="post-metadata">

**Author:** ![sbeee](https://community.icinga.com/letter_avatar_proxy/v4/letter/s/58f4c7/32.png) [@sbeee](https://community.icinga.com/u/sbeee)\
**Post date:** [January 29, 2020, 7:03am UTC](https://community.icinga.com/t/advanced-use-of-dictionary-oracle/3335/3 "2020-01-29T07:03:00Z")

</div>

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