opinkerfi/okconfig — pull request #61 by tomas-edwardsson (2014-06-12 13:20:48+00:00)
Title: Enable template options

# What it does
Enables template options via --opt VAR=SOMETHING

# What it does NOT
Break how everything used to work, so old templates still work

# Description
```
$ okconfig addtemplate www.okconfig.org --template http \
--opt VIRTUAL_HOST=vhost.okconfig.org \
--opt SEARCH_STRING=something
Saved /etc/nagios/okconfig/hosts/default/www.okconfig.org-http-vhost.okconfig.org.cfg
```

Contents of the file (/etc/nagios/okconfig/hosts/default/www.okconfig.org-http-vhost.okconfig.org.cfg) become
```
define service {
use	okc-check_http
host_name	www.okconfig.org
contact_groups	default
service_description	HTTP vhost.okconfig.org
#check_command	okc-check_http

__VIRTUAL_HOST	vhost.okconfig.org
#__URI	/
__SEARCH_STRING	something
#__RESPONSE_WARNING	2.0
#__RESPONSE_CRITICAL	10.0
#__PORT	80
#__ON_REDIRECT follow

}
```

Then there is the configuration for the template options.
/usr/share/okconfig/examples/http.yml
```
filename: "{HOSTNAME}-http-{VIRTUAL_HOST}.cfg"
parms:
VIRTUAL_HOST:
default: k:HOSTNAME
summary: Virtual host to query for
URI:
default: /
SEARCH_STRING:
default:
RESPONSE_WARNING:
default: 2.0
summary: Response time in seconds till warning
RESPONSE_CRITICAL:
default: 10.0
summary: Response time in seconds till critical
PORT:
default: 80
ON_REDIRECT:
default: follow
summary: Action to on redirects, eg

```

It still uses the example file which now looks like this:
```
define service {
use	okc-check_http
host_name	HOSTNAME
contact_groups	GROUP
service_description	HTTP ^VIRTUAL_HOST
#check_command	okc-check_http

__VIRTUAL_HOST	^VIRTUAL_HOST
#__URI	^URI
#__SEARCH_STRING	^SEARCH_STRING
#__RESPONSE_WARNING	^RESPONSE_WARNING
#__RESPONSE_CRITICAL	^RESPONSE_CRITICAL
#__PORT	^PORT
#__ON_REDIRECT follow

}
```