| 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 |
import argparse |
| 26 |
|
| 27 |
parser = argparse.ArgumentParser(description = "Performs checks by given scripts and returns the result") |
| 28 |
parser.add_argument("globs", metavar = "F", type = str, nargs = "+", |
| 29 |
help = "File or glob of the check script to process") |
| 30 |
|
| 31 |
args = parser.parse_args() |
| 32 |
|
| 33 |
import glob |
| 34 |
files = [] |
| 35 |
for g in args.globs: |
| 36 |
gfiles = glob.glob(g) |
| 37 |
files.extend(gfiles) |
| 38 |
if len(gfiles) == 0: |
| 39 |
print("No file matches '%s'" % (g)) |
| 40 |
|
| 41 |
import os |
| 42 |
|
| 43 |
xccdf_result_map = dict() |
| 44 |
xccdf_result_map["XCCDF_RESULT_PASS"] = 101 |
| 45 |
xccdf_result_map["XCCDF_RESULT_FAIL"] = 102 |
| 46 |
xccdf_result_map["XCCDF_RESULT_ERROR"] = 103 |
| 47 |
xccdf_result_map["XCCDF_RESULT_UNKNOWN"] = 104 |
| 48 |
xccdf_result_map["XCCDF_RESULT_NOT_APPLICABLE"] = 105 |
| 49 |
xccdf_result_map["XCCDF_RESULT_NOT_CHECKED"] = 106 |
| 50 |
xccdf_result_map["XCCDF_RESULT_NOT_SELECTED"] = 107 |
| 51 |
xccdf_result_map["XCCDF_RESULT_INFORMATIONAL"] = 108 |
| 52 |
xccdf_result_map["XCCDF_RESULT_FIXED"] = 109 |
| 53 |
|
| 54 |
xccdf_reverse_result_map = dict() |
| 55 |
for key, value in xccdf_result_map.items(): |
| 56 |
xccdf_reverse_result_map[value] = key |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
for key, value in xccdf_result_map.items(): |
| 61 |
os.environ[key] = str(value) |
| 62 |
|
| 63 |
import subprocess |
| 64 |
|
| 65 |
for file_path in files: |
| 66 |
result = subprocess.call(["./%s" % (file_path)]) |
| 67 |
if result in xccdf_reverse_result_map: |
| 68 |
result_text = xccdf_reverse_result_map[result] |
| 69 |
else: |
| 70 |
result_text = "Unknown exit code %i" % (result) |
| 71 |
print("Result of '%s' is %s" % (file_path, result_text)) |
| 72 |
|