icinga2/doc/3.05-using-templates.md

49 lines
1.3 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
2013-10-10 16:55:59 +02:00
configuration:
2013-10-02 09:50:26 +02:00
template Host "linux-server" {
services["ping"] = {
check_command = "ping4"
},
2013-10-11 13:46:06 +02:00
check = "ping"
2013-10-02 09:50:26 +02:00
}
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-11 13:46:06 +02:00
In this example both `my-server1` and `my-server2` each get their own `ping`
service check. Each host gets its own host `check` defined as the `ping`
service too.
2013-10-02 09:50:26 +02:00
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" ]
}
}