-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_extxtune
More file actions
131 lines (105 loc) · 4 KB
/
check_extxtune
File metadata and controls
131 lines (105 loc) · 4 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/env python3
#-------------------------------------------------------------------------------
import argparse
import sys
import os
import subprocess
import platform
#-------------------------------------------------------------------------------
_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 mapstatustoexitcode(status):
if status=="OK":
exitcode = 0
elif status=="WARNING":
exitcode = 1
elif status=="CRITICAL":
exitcode = 2
elif status=="UNKNOWN":
exitcode = 3
else:
exitcode = 4
return exitcode
def exitnagios(status,message):
exitcode = mapstatustoexitcode(status)
print(status+": "+message, flush=True)
sys.exit(exitcode)
#-------------------------------------------------------------------------------
def extractlinevalue(line,test):
result = None
infomsg(line)
if line.startswith(test):
result = line[len(test):].strip()
infomsg(result)
return result
def checktune(partition,mountcount,mountperiod):
cmdline = ["/usr/sbin/dumpe2fs","-h",partition]
completedproc = subprocess.run(cmdline,capture_output=True)
output = completedproc.stdout.decode("utf-8").strip()
errors = completedproc.stderr.decode("utf-8").strip()
exitcode = completedproc.returncode
infomsg(output)
currentcount = None
currentperiod = None
for line in output.splitlines():
testcount = extractlinevalue(line,"Maximum mount count:")
if testcount!=None:
currentcount = testcount.split()[0]
testinterval = extractlinevalue(line,"Check interval:")
if testinterval!=None:
currentperiod = testinterval.split()[0]
infomsg(currentcount)
infomsg(currentperiod)
validcount =str(currentcount)==str(mountcount)
validperiod = str(currentperiod)==str(mountperiod)
result = validcount and validperiod
return result
def dopostgresclustercountcall(mountcount,mountperiod):
cmdline = ["/usr/bin/findmnt","--real","--types=ext2,ext3,ext4","--noheadings","--list","--uniq","--nofsroot","--notruncate","--output=SOURCE"]
completedproc = subprocess.run(cmdline,capture_output=True)
output = completedproc.stdout.decode("utf-8").strip()
errors = completedproc.stderr.decode("utf-8").strip()
exitcode = completedproc.returncode
if exitcode == 0:
lines = output.splitlines()
filesystems = []
for line in lines:
test = line.strip()
if test not in filesystems:
filesystems.append(test)
infomsg(filesystems)
issues = []
for partition in filesystems:
tuned = checktune(partition,mountcount,mountperiod)
if not tuned:
issues = issues + [partition]
if len(issues)>0:
exitnagios("CRITICAL","the filesystems <"+" ".join(issues)+"> are not properly tuned - "+" ".join(filesystems))
else:
exitnagios("OK","all filesystems are properly tuned - "+" ".join(filesystems))
else:
exitnagios("CRITICAL","issue retrieving the list of mounted filesystems")
#-------------------------------------------------------------------------------
def parse_args(forcedargs=None):
parser = argparse.ArgumentParser()
parser.add_argument("-®", "--debug", action="store_true", dest="debug", default=False, help="be more verbose")
args = parser.parse_args(forcedargs)
return args
def main(forcedargs=None):
args = parse_args(forcedargs)
setcandebug(args.debug)
mountcount = 1
mountperiod = 604800
dopostgresclustercountcall(mountcount,mountperiod)
#-------------------------------------------------------------------------------
if __name__ == "__main__":
main()
#-------------------------------------------------------------------------------