-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_disk.py
More file actions
executable file
·63 lines (55 loc) · 1.64 KB
/
check_disk.py
File metadata and controls
executable file
·63 lines (55 loc) · 1.64 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
#!/usr/bin/env python3
# SPDX-License-Identifier: GPL-2.0-only
# - flo932@uxsrv.de micha.r
import os
import subprocess
os.system("id")
_exit = 0
r=100
cmd="free -m| tail -n 2 | xargs | jq -R 'split(\" \")|{all:.[1],used:.[2],free:.[6]}'"
cmd="df -lmT | grep -v tmpfs "
cmd="""df -lmT | grep -v "tmpfs\|fuse" | tail -n +2 | sed 's/[ ][ ]*/ /g' | jq -R 'split(" ")|{disk:.[0],fs:.[1],free:.[4],used:.[5],mount:.[6]}| join(", ")'"""
cmd="""df -lmT | grep -v "tmpfs\|fuse" | tail -n +2 | sed 's/[ ][ ]*/ /g' | jq -R 'split(" ")|{disk:.[0],fs:.[1],free:.[4],used:.[5],mount:.[6]}'"""
#print(cmd.replace("|","I"))
#r = subprocess.Popen([cmd])a
r = os.popen(cmd)
#print(dir(r))
if not r:
_exit += 1
#exitcode = writer.wait()
txt = r.read()
txt = "["+txt.replace('}\n{','},\n{')+"]"
print(txt)
print()
import json
perf = []
_max = 80
_exit = 3 #unknown
if txt:
jj = json.loads(txt)
for j in jj:
if "used" in j and "disk" in j:
d = j["disk"]
try:
u = int(j["used"][:-1]) #f/a # used in %
#print("used: {} %".format(u) )
if u > _max:
_exit = 2 # krit
if u > _max-10:
if _exit == 3:
_exit = 1 # warn
else:
if _exit == 3:
_exit = 0
pf = "|{}={};{};{}".format(d,u,_max-10,_max)
#print(pf)
perf.append(pf)
except Exception as e:print(e)
print()
#_exit = 3 #unbek
print("exit:",_exit)
if perf:
for i,p in enumerate(perf):
#print("|disk{}=".format(i)+p)
print(p)
print()