Many of you are familiar with the good old $USERn$
macros from Icinga 1.x.
They were used for various purposes, but best known for storing credentials / passwords in a central place.
In Icinga 2 you can define “global” vars, that will be available to any object, by adding them to IcingaApplication
Example
An easy to maintain example can work like this:
constants.conf
// ... any other vars
const GlobalVars = {
USER10 = "some-username"
USER11 = "some-generic-password"
local_mysql_user = "icinga"
local_mysql_password = ""
}
conf.d/app.conf
object IcingaApplication "app" {
// vars can also be defined inline here...
vars = GlobalVars
}
conf.d/services.conf
apply Service "mysql" {
import "generic-service"
check_command = "mysql"
vars = {
mysql_username = "$local_mysql_user$"
mysql_password = "$local_mysql_password$"
}
}
Be careful
- Those vars are enabled globally, and will work in every macro
- If you use any variable name that is used by a
CheckCommand
, the value may be used unintentionally - Those variables are always last in order (after service, host, checkcommand)
- Variables can be used by any user that is able to change config
Recommendations
- Use a prefix or site specific variable name
- Maintain the vars in
constants.conf
and only set the const to vars inIcingaApplication
- Document available vars for other users
Any opinions or questions on this?