You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
4 years ago
|
#!/usr/bin/env python3
|
||
|
import csv, sys, getopt
|
||
|
|
||
|
## Main Function, operating on cmdln args
|
||
|
def main(argv):
|
||
|
inptcsv = ''
|
||
|
outptfile = ''
|
||
|
tempfile = '/tmp/sadfaddtemp.tmp'
|
||
|
try:
|
||
|
opts, args = getopt.getopt(argv,"f:t:",["infile=","type="])
|
||
|
## opts used wrong?
|
||
|
except getopt.GetoptError:
|
||
|
print("Usage Message")
|
||
|
sys.exit(2)
|
||
|
## opts used correctly
|
||
|
for opt, arg in opts:
|
||
|
if opt == '-f':
|
||
|
inptcsv = arg
|
||
|
## opt unrecognized
|
||
|
else:
|
||
|
print("Unrecognized opt")
|
||
|
## Parse input csv
|
||
|
open(tempfile,'w').writelines([ line for line in open(inptcsv) if 'LINUX-' not in line])
|
||
|
with open(tempfile, newline='') as csvfile:
|
||
|
csvreader = csv.DictReader(csvfile, delimiter=';')
|
||
|
for row in csvreader:
|
||
|
rowkeys = row.keys()
|
||
|
kbtotal = int(row.get('kbmemused')) + int(row.get('kbmemfree'))
|
||
|
kbavail = int(row.get('kbavail'))
|
||
|
percavail = (kbavail/kbtotal)
|
||
|
fmtpavail = str('{:.1%}'.format(percavail))
|
||
|
row.update({'%kbavail':fmtpavail})
|
||
|
print(row['# hostname'],row['timestamp'],row['%kbavail'])
|
||
|
if __name__ == "__main__":
|
||
|
main(sys.argv[1:])
|