Created
June 7, 2014 11:57
-
-
Save javierwilson/745f8756d88508de8761 to your computer and use it in GitHub Desktop.
Generates and upload Nagios config for Access Points
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
define hostgroup{ | |
hostgroup_name access_points | |
alias Access Points | |
} | |
{%- for ap in items %} | |
define host{ | |
use generic-switch | |
host_name {{ ap.name }} | |
alias {{ ap.name }} | |
address {{ ap.ip }} | |
hostgroups access_points | |
} | |
define service{ | |
use generic-service | |
host_name {{ ap.name }} | |
service_description PING | |
check_command check_ping!200.0,20%!600.0,60% | |
} | |
{%- 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
10.0.0.221 Linksys1 | |
10.0.0.222 Linksys2 | |
10.0.0.223 Cisco1 | |
10.0.0.226 Linksys5 | |
10.0.0.227 Linksys6 | |
10.0.0.228 Linksys7 | |
10.0.0.229 Linksys8 | |
10.0.0.230 DLink1 | |
10.0.0.231 DLink2 | |
10.0.0.232 DLink3 | |
10.0.0.233 DLink4 | |
10.0.0.234 DLink5 | |
10.0.0.235 Linksys9 | |
10.0.0.236 DLink6 | |
10.0.0.237 DLink7 | |
10.0.0.238 DLink8 | |
10.0.0.239 DLink9 | |
10.0.0.240 DLink10 | |
10.0.0.241 DLink11 | |
10.0.0.242 DLink12 |
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
from fabric.api import env, task | |
from fabric.contrib.files import upload_template | |
@task | |
def eueom(): | |
env.hosts = open('hosts.eueom', 'r').readlines() | |
@task | |
def guegue(): | |
env.hosts = open('hosts.guegue', 'r').readlines() | |
env.user = 'bob' | |
@task | |
def nagios_config(): | |
with open('access_points.txt') as f: | |
lines = f.readlines() | |
items = [] | |
for line in lines: | |
args =line.rstrip().split(' ') | |
items.append({'ip': args[0], 'name': args[1]}) | |
context = {'items' : items} | |
upload_template('access_points.cfg', '/etc/nagios/conf.d/access_points.cfg', context, use_jinja=True, use_sudo=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment