icinga2/doc/3.5-using-templates.md

48 lines
1.2 KiB
Markdown
Raw Normal View History

2013-10-02 09:50:26 +02:00
## Using Templates
Templates may be used to apply a set of similar settings to more than one
object.
2013-10-07 09:35:44 +02:00
For example, rather than manually creating a `ping` service object for each of
2013-10-02 09:50:26 +02:00
your hosts you can use templates to avoid having to copy & paste parts of your
config:
template Host "linux-server" {
services["ping"] = {
check_command = "ping4"
},
check = "ping4"
}
object Host "my-server1" inherits "linux-server" {
macros["address"] = "10.0.0.1"
}
object Host "my-server2" inherits "linux-server" {
macros["address"] = "10.0.0.2"
}
2013-10-07 09:35:44 +02:00
In this example both `my-server1` and `my-server2` each get their own ping
2013-10-02 09:50:26 +02:00
service check.
Objects as well as templates themselves can inherit from an arbitrary number of
templates. Attributes inherited from a template can be overridden in the
object if necessary.
Templates can also be used in service and notification definitions using the
2013-10-07 09:35:44 +02:00
`templates` attribute:
2013-10-02 09:50:26 +02:00
template Service "weekend-service" {
check_interval = 0.5m,
check_period = "weekend"
}
object Host "my-server1" {
services["backup"] {
check_command = "backup-check",
templates = [ "weekend-service" ]
}
}