File: find_orphans.py

package info (click to toggle)
pynag 0.9.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 1,196 kB
  • ctags: 1,181
  • sloc: python: 9,155; makefile: 200; sh: 151
file content (33 lines) | stat: -rwxr-xr-x 911 bytes parent folder | download
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
32
33
#!/usr/bin/python
import sys

## This is for the custom nagios module
sys.path.insert(1, '../')
from pynag.Parsers import config

## Create the plugin option
nc = config('/etc/nagios/nagios.cfg')
nc.parse()

## These are top level items.  We don't care if they dont' have a parent.
## Things like datacenters should be displayed here
top_level_items = ['main data center']



orphan_hosts = []
print "The following hosts do not have parent items:"

for host in nc['all_host']:
    use_attr = ''
    for attribute in ['host_name', 'name', 'alias']:
        if host.has_key(attribute):
            use_attr = attribute
    
    if not host.has_key('parents') or not host['parents']:
        if  host[use_attr] not in top_level_items:
		orphan_hosts.append(host)
        	print "%-12s %-32s (%s)" % (use_attr, host[use_attr], host['meta']['filename'])

if not len(orphan_hosts):
    print "No ophaned hosts found"