-
Notifications
You must be signed in to change notification settings - Fork 0
/
realcheck2.py
95 lines (75 loc) · 2.89 KB
/
realcheck2.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
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 python
import datetime
import calendar
import os
from operator import itemgetter
if 'COLUMNSORT' in os.environ:
sortcol=int(os.environ['COLUMNSORT'])
else:
sortcol=3
data = []
'''
hostname,filesystem,fstype,size,mountcount,maxmounts,interval,checkafterdate
host19.example.com,/dev/sda1,ext3,99,41,-1,0,
host32.example.com,/dev/mapper/VolGroup01-LV_FPCMPRR1,ext4,2016,
host65.example.com,/dev/mapper/ofhpcdvg1-LV_DVFHPCD1,ext3,75596,2,32,15552000,Mon Jun 15 18:09:20 2015,
host197.example.com,/dev/mapper/ofhpcsvg1-LV_DVFHPCS1,ext3,40318,2,39,15552000,Mon Jun 15 18:09:44 2015,
host53.example.com,/dev/mapper/vg00-bladelogic,ext4,1952,4,-1,0,
'''
MAINTENANCE_DAY = "Sun Jan 17 23:01:02 2016"
mds = datetime.datetime.strptime(MAINTENANCE_DAY, "%a %b %d %H:%M:%S %Y")
with open('small-data.txt', 'r+') as f:
for line in f:
if line.strip():
parts = line.strip().split(',')
# ignore bad data
if len(parts) < 7:
continue
maxmount_disabled = False
mnt_fsck_date_old = False
mnt_interval_invalid = False
mnt_count_exceeded = False
mnt_date_empty = False
for idx,x in enumerate(parts):
if x.isdigit():
parts[idx] = int(x)
parts[3] = int(parts[3])
mntcount = int(parts[4])
maxmount = int(parts[5])
interval = int(parts[6])
datestr = parts[7]
if mntcount >= maxmount:
mnt_count_exceeded = True
if maxmount == 0 or maxmount == -1:
maxmount_disabled = True
if int(interval) == 0:
mnt_interval_invalid = True
if datestr == "":
mnt_date_empty = True
if not mnt_date_empty:
# https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior
try:
ds = datetime.datetime.strptime(datestr, "%a %b %d %H:%M:%S %Y")
except:
print "bad date: %s" % datestr
import pdb; pdb.set_trace()
if calendar.timegm(ds.timetuple()) < calendar.timegm(mds.timetuple()):
mnt_fsck_date_old = True
fsck = False
if not mnt_date_empty:
if (not maxmount_disabled) and (not mnt_interval_invalid):
if mnt_count_exceeded or mnt_fsck_date_old:
fsck = True
if fsck:
#print "#################################################"
#print parts[0],parts[1]
#data.append(','.join(parts))
data.append(parts)
#import pdb; pdb.set_trace()
data.sort(key=itemgetter(sortcol),reverse=True)
for row in data:
tmprow = [str(x) for x in row]
if int(row[3]) > 100000:
print '\033[91m' + ",".join(tmprow) + '\033[0m'
else:
print ",".join(tmprow)