commit 50379a4646423e6cf39666c84622f5b0b79f156c Author: m00t Date: Sat Feb 8 19:04:01 2020 -0500 Script now takes a csv, finds relevant memory usage values, calcuates % memory available, and adds it to a Python OrderedDict to be rewritten to csv. new file: .gitignore new file: sadfadd diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..726c3ca --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.*.sw* diff --git a/sadfadd b/sadfadd new file mode 100755 index 0000000..abbb362 --- /dev/null +++ b/sadfadd @@ -0,0 +1,35 @@ +#!/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:])