diff options
author | Christos Triantafyllidis <christos.triantafyllidis@gmail.com> | 2012-06-12 00:49:17 +0300 |
---|---|---|
committer | Christos Triantafyllidis <christos.triantafyllidis@gmail.com> | 2012-06-12 00:49:17 +0300 |
commit | cf9c34812219c3417d9e4d8af4cafaedd1e8988c (patch) | |
tree | cef1abdeae93887b20de84202b6d7cd42e713a72 /modules/nagios_config.py | |
download | DynamicNagiosConfig-cf9c34812219c3417d9e4d8af4cafaedd1e8988c.tar.gz DynamicNagiosConfig-cf9c34812219c3417d9e4d8af4cafaedd1e8988c.tar.xz DynamicNagiosConfig-cf9c34812219c3417d9e4d8af4cafaedd1e8988c.zip |
Initial GIT import
Diffstat (limited to 'modules/nagios_config.py')
-rw-r--r-- | modules/nagios_config.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/nagios_config.py b/modules/nagios_config.py new file mode 100644 index 0000000..d7668f9 --- /dev/null +++ b/modules/nagios_config.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python +from string import Template + +def generate(defaults,hosts,datacenters): + host_template = Template(file("templates/host", 'r').read()) + for host in hosts: + hostdict = {"hostname": host} + if hosts[host].has_key("parents"): + hostdict["parents"] = 'parents ' + hosts[host]["parents"] + elif hosts[host].has_key("datacenter") and datacenters.has_key(hosts[host]["datacenter"]): + hostdict["parents"] = 'parents ' + datacenters[hosts[host]["datacenter"]]["gateway"] + else: + hostdict["parents"] = '' + + if hosts[host].has_key("use"): + hostdict["use"] = hosts[host]["use"] + else: + hostdict["use"] = defaults["default_host_use"] + + if hosts[host].has_key("alias"): + hostdict["host_alias"] = hosts[host]["alias"] + else: + hostdict["host_alias"] = host + + if hosts[host].has_key("address"): + hostdict["host_address"] = hosts[host]["address"] + else: + hostdict["host_address"] = host + + print host_template.substitute(hostdict) +
\ No newline at end of file |