-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_pdns_zones.py
50 lines (39 loc) · 1.21 KB
/
check_pdns_zones.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
import subprocess
import sys
msg = "DNS ZONES "
try:
out = subprocess.check_output('/usr/bin/pdnssec check-all-zones'.split()).split('\n')
except:
print msg + "UNKNOWN: cannot execute /usr/bin/pdnssec"
sys.exit(3)
bad_zones = ""
details = []
exit_num = 0
for x in out[:-2]:
splitted = x.split(' ')
if splitted[0] == 'Checked':
if int(splitted[5]) > 0 or int(splitted[7]) > 0:
# Errors, so CRIT
if int(splitted[5]) > 0:
exit_num = 2
# Warnings, so WARN
if int(splitted[7]) > 0 and exit_num < 1:
exit_num = 1
bad_zones += " %s: E:%s, W:%s;" % (splitted[4][1:-2], splitted[5], splitted[7])
# Go to the next iteration
continue
if splitted[0] == '[Warning]' or splitted[0] == '[Error]':
details.append(x)
continue
# If we get here, we couldn't understand the line, throw an UNKNOWN
print msg + "UNKNOWN: Unable to parse line: %s" % x
sys.exit(3)
if exit_num == 0:
print msg + "OK"
if exit_num == 1:
print msg + "WARNING:" + bad_zones
if exit_num == 2:
print msg + "CRITICAL:" + bad_zones
print '\n'.join(details)
exit(exit_num)