0

For now I use the below config for Icinga2 host server to work:

vars.health_check["my_module1"]={
   host = "HEALTH_CHECK_SERVER_URL"
   module = "my_module1"
}

vars.health_check["my_module2"]={
   host = "HEALTH_CHECK_SERVER_URL"
   module = "my_module2"
}

The problem as you see is that I have to redeclare the same host address. When I put the host address outside of service like below, it does not work and reloading of Icinga2 fails:

   end_url = "HEALTH_CHECK_SERVER_URL"
   vars.health_check["my_module1"]={
       host = "$end_url$"
       module = "my_module1"
    }

    vars.health_check["my_module2"]={
       host = "$end_url$"
       module = "my_module2"
    }

I even tried to use vars.end_url but again the same scenario. How should I declare a variable in Icinga2.

Alireza
  • 6,497
  • 13
  • 59
  • 132

1 Answers1

1

You can use the host's address with $address$ so if the host's address is the what the URL resolves to it should work like:

end_url = "HEALTH_CHECK_SERVER_URL"
   vars.health_check["my_module1"]={
       host = "$address$"
       module = "my_module1"
    }

    vars.health_check["my_module2"]={
       host = "$address$"
       module = "my_module2"
    }

Have you looked into Icinga2 Director?. It's handy and host configs are more easily managed. Also, monitoring-portal.org Is a good resource for the Icinga Community.

If you use director you can make a clone of the command and then set the arguments to variables like $end_url$ then create the field. Then you can add the field to your template(import) and enter it once there.

For example we use this method for SNMP Community strings. We have a field for $snmp_community$ attached to our templates. So in any command where we need the community we just use this variable. This is how Icinga2 knows all our LAN Distro's community strings, and if we need to change it we just change it once.

enter image description here

enter image description here

enter image description here

cflinspach
  • 290
  • 1
  • 4
  • 16
  • 1
    `$address$` refers to host address of config file. What I want is a variable with a different value like `example.com`. Thanks for `Icinga2 director` it was brilliant but again it does not solve my problem. I moved the config to commands section for now. +1 – Alireza Aug 22 '17 at 05:38
  • Do you need the end url to always be the same? – cflinspach Aug 22 '17 at 15:59
  • Yes, for now I have moved it into commands section to use it once. – Alireza Aug 23 '17 at 07:26
  • Ok I edited the answer and added screenshots. This way you can set the value on the template or host, or really anywhere you add that field. – cflinspach Aug 23 '17 at 14:13