-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_smb_checks
95 lines (77 loc) · 2.52 KB
/
check_smb_checks
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
##aptitude install python-nagiosplugin
import argparse
import subprocess
import socket
import sys
import re
#-------------------------------------------------------------------------------
_candebug = False
def candebug():
global _candebug
return _candebug
def setcandebug(value):
global _candebug
_candebug = value
def infomsg(msg):
if candebug() == True:
print(msg, flush=True)
def exitnagios(status,message):
if status=="OK":
exitcode = 0
elif status=="WARNING":
exitcode = 1
elif status=="CRITICAL":
exitcode = 2
elif status=="UNKNOWN":
exitcode = 3
else:
exitcode = 4
print(status+": "+message, flush=True)
sys.exit(exitcode)
#-------------------------------------------------------------------------------
def check_kcc():
result = []
command = ["/usr/bin/samba-tool", "drs", "kcc"]
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT).decode()
except subprocess.CalledProcessError:
output = "Error during 'samba-tool drs kcc'"
return False, output
return True, output
def check_sysvol():
result = []
command = ["/usr/bin/samba-tool", "ntacl", "sysvolcheck"]
try:
output = subprocess.check_output(command, stderr=subprocess.STDOUT).decode()
except subprocess.CalledProcessError:
output = "Error during 'samba-tool ntacl sysvolcheck'"
return False, output
return True, output
#-------------------------------------------------------------------------------
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("-®", "--debug", action="store_true", dest="debug", default=False, help="be more verbose")
args = parser.parse_args()
return args
def main():
args = parse_args()
setcandebug(args.debug)
errors = 0
output = ""
kcc_result, kcc_output = check_kcc()
if kcc_result == False:
errors = errors+1
output += kcc_output+"\n"
sysvol_result, sysvol_output = check_sysvol()
if sysvol_result == False:
errors = errors+1
output += sysvol_output+"\n"
if errors == 0:
exitnagios("OK","no issues detected in kcc nor sysvol")
else:
exitnagios("CRITICAL",output)
if __name__ == "__main__":
main()
#-------------------------------------------------------------------------------