Created
June 27, 2012 10:35
-
-
Save unicolet/3003202 to your computer and use it in GitHub Desktop.
Nagios cfg from Google Docs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
from jinja2 import Template,FileSystemLoader,Environment | |
loader = FileSystemLoader('templates') | |
env = Environment(loader=FileSystemLoader('templates')) | |
tmp=[] | |
hostgroups=set() | |
hosts = csv.reader(open('hosts.csv'), delimiter=',', quotechar='"') | |
for h in hosts: | |
if h[0]!="" and h[0]!="ip": | |
tmp.append(h) # skip rows w/o ip address | |
for x in h[3].split(',') : hostgroups.add(x) | |
hosts=tmp | |
files = {'hostgroups':'','services':'','hosts':''} | |
templates = {} | |
for k in files.keys(): | |
templates[k]=env.get_template(k) | |
for k in files.keys(): | |
files[k] += templates[k].render(hosts=hosts, hostgroups=hostgroups) | |
for k in sorted(files.keys(),reverse=True): | |
print files[k] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for hg in hostgroups %} | |
define hostgroup{ | |
hostgroup_name {{ hg }} | |
alias {{ hg }} | |
} | |
# host hostgroup template | |
define host{ | |
check_command check-host-alive | |
notification_options d,u,r | |
max_check_attempts 5 | |
name {{ hg }} | |
register 0 | |
} | |
{% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% for record in hosts %} | |
define host{ | |
host_name {{ record[1].replace(' ','_') }} | |
alias {{ record[1] }} | |
address {{ record[0] }} | |
hostgroups {{ record[3]}} | |
use {{ record[3].split(",")[0] }} | |
} | |
{% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# intentionally left blank |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment