-
Notifications
You must be signed in to change notification settings - Fork 10
Understanding benchmarks.py
This page explains what benchmarks.py does
To start off, this module is the heart of the tool and has the definitions of how to perform the control's test.
-
log_fileThis is a global variable that contains the path to the folder where the log files are to be created. This is assigned whenever thetestfunction is called and is used by thecheckfunction -
benchmark_These variables contain the following- recommendation number
- Scored (1) [OR] Not Scored (0)
- Server Profile -> Level 1 (1) [OR] Level 2 (2) [OR] N/A (0)
- Workstation Profile -> Level 1 (1) [OR] Level 2 (2) [OR] N/A (0)
- Control Explanation
-
checkThis function performs the test by executing the command it receives as argument. It returns the test result. It also writes the result, execution start and end times in a log file named after the time stamp of when the function was called. To know more about logging, read this wiki. -
_recommendation_number_distroThese make up the bulk of the code in this script. This function performs the actual test. It calls thecheckfunction, passing the command as defined in the CIS Benchmark document. The result that was returned is checked against the requirements as laid out by the CIS Benchmark document. Based on the findings, the following is returned as a list calledreturn_value- Message (less than 45 characters to prevent overflow in the report)
- Result (PASS, FAIL [or] CHEK)
- Explanation (description of what was done and the appropriate result)
-
testThis function is called from SeBAz.py and performs the test as requested in the function call. The test is identified by it's recommendation numberrand distrodist. The global variablelog_fileis assigned tolog, so as to be accessed bycheck. The given recommendation is evaluated usingeval, with the recommendation number enclosed with_and suffixed withdist. In thereturn_valuethat is returned, the recommendation number is prefixed and the time taken to perform the test is suffixed. Then, this is converted into the second value of a 2-D list, with the first value being 2 if the test PASSED and is SCORED, 1 if the test PASSED and is NOT SCORED, and 0 if the test FAILED or needs to be CHECKED. Ifverbosityis True, then the correspondingprint_function is called with the recommendation number, message, result, andwidthargument, which uses HuePy to display colored text on the terminal. -
print_These functions print the recommendation number, message, and result on the terminal in the color as specified.lenspecifies how much space message can take on the terminal, so that the result would be right aligned to the end of the terminal