Use variables from an external file

Hello everyone!

We would like to store some variables in files to can be used in several Services.
In this way if would be easier for us to modify passwords, etc.

we want to use the service “check_snmp” and catch the community from a external file
This is what we have.

  • services.conf *

    apply Service “check_snmp” {
    import “generic-service”
    display_name = “uptime”
    check_command = “snmp”
    vars.snmp_oid = “”
    vars.snmp_community = {{ snmp_community }}
    assign where host.vars.check_snmp == true

  • constants.conf *

    /* snmpv2 community data */
    const snmp_community = “$/var/lib/icinga2/credentials/snmpv2_community$”

  • server.conf *

vars.check_snmp = true

But it doesn’t work. I don’t know what we are doing wrong.
Inside the Inspect you can see that the community doesn’t appear:
"‘/usr/lib64/nagios/plugins/check_snmp’ ‘-H’ ‘10.xx.xx.xx’ ‘-o’ ‘’ ‘-t’ ‘10’

The external file only contains the password, and the file has enough permissions.
We have tried in those files deleting the $, put [ ]
We have tried putting something like this:
“file: /var/lib/icinga2/credentials/snmpv2_community”
. to Icinga can catch the text but nothing.

If in the services.conf we modify that line and we put directly the password, it works fine.
vars.snmp_community = “our_password_”

P.S We need to do it through the console instead the Director module.

Thanks in advance.

Hi & welcome,

What about storing as constants e.g. /var/lib/icinga2/credentials:

const snmp_community = “bla"

and add this (and any other “constant storage”) to /etc/icinga2/icinga2.conf:

include /var/lib/icinga2/credentials


vars.snmp_community = snmp_community