summaryrefslogtreecommitdiffstats
path: root/modules/nagios_config.py
blob: d7668f9a92cb413771d5379a48765754f1475938 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)