Last active
July 15, 2019 09:38
-
-
Save EJSohn/df21de2262d72f6add824353efde67fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import csv | |
import comware | |
class HPEConf(object): | |
def __init__(self, input_filenames, output_filename): | |
self.input_filenames = input_filenames | |
self.output_filename = output_filename | |
def _writerows(self, data): | |
with open(self.output_filename, 'wb') as f: | |
writer = csv.writer(f) | |
writer.writerows(data) | |
def run(self): | |
results = [] | |
for input_filename in self.input_filenames: | |
with open(input_filename, 'rb') as f: | |
reader = csv.reader(f) | |
cnt = 0 | |
for row in reader: | |
cnt += 1 | |
if cnt == 1: | |
continue | |
vuln_id = row[0] | |
stig_id = row[4] | |
check_command = row[7] | |
response = '' | |
for command in check_command.split('\n'): | |
try: | |
c = comware.CLI(command, False) | |
response = response + '\n ' + ', '.join(c.get_output()) | |
except Exception as e: | |
response = response + '\n ' + e.message | |
result = [input_filename, \ | |
vuln_id, \ | |
stig_id, \ | |
check_command, \ | |
response] | |
results.append(result) | |
print '{} rows completed'.format(cnt) | |
self._writerows(results) | |
if __name__ == '__main__': | |
conf = HPEConf(['L2S.csv', 'NDM.csv', 'RTR.csv'], 'switch_output.csv') | |
conf.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment