mirror of
https://github.com/ovh/debian-cis.git
synced 2024-11-21 21:17:00 +01:00
Add silent mode and json summary (#128)
Co-authored-by: GoldenKiwi <thibault.dewailly@corp.ovh.com>
This commit is contained in:
parent
3d2d97a727
commit
ad192c9457
@ -26,6 +26,7 @@ ALLOW_SERVICE_LIST=0
|
||||
SET_HARDENING_LEVEL=0
|
||||
SUDO_MODE=''
|
||||
BATCH_MODE=''
|
||||
SUMMARY_JSON=''
|
||||
ASK_LOGLEVEL=''
|
||||
ALLOW_UNSUPPORTED_DISTRIBUTION=0
|
||||
|
||||
@ -101,9 +102,13 @@ OPTIONS:
|
||||
Finally note that '--sudo' mode only works for audit mode.
|
||||
|
||||
--set-log-level <level>
|
||||
This option sets LOGLEVEL, you can choose : info, warning, error, ok, debug.
|
||||
This option sets LOGLEVEL, you can choose : info, warning, error, ok, debug or silent.
|
||||
Default value is : info
|
||||
|
||||
--summary-json
|
||||
While performing system audit, this option sets LOGLEVEL to silent and
|
||||
only output a json summary at the end
|
||||
|
||||
--batch
|
||||
While performing system audit, this option sets LOGLEVEL to 'ok' and
|
||||
captures all output to print only one line once the check is done, formatted like :
|
||||
@ -165,6 +170,10 @@ while [[ $# -gt 0 ]]; do
|
||||
--sudo)
|
||||
SUDO_MODE='--sudo'
|
||||
;;
|
||||
--summary-json)
|
||||
SUMMARY_JSON='--summary-json'
|
||||
ASK_LOGLEVEL=silent
|
||||
;;
|
||||
--batch)
|
||||
BATCH_MODE='--batch'
|
||||
ASK_LOGLEVEL=ok
|
||||
@ -355,6 +364,18 @@ if [ "$BATCH_MODE" ]; then
|
||||
BATCH_SUMMARY+=" CONFORMITY_PERCENTAGE:N.A" # No check runned, avoid division by 0
|
||||
fi
|
||||
becho "$BATCH_SUMMARY"
|
||||
elif [ "$SUMMARY_JSON" ]; then
|
||||
if [ "$TOTAL_TREATED_CHECKS" != 0 ]; then
|
||||
CONFORMITY_PERCENTAGE=$(div $((PASSED_CHECKS * 100)) $TOTAL_TREATED_CHECKS)
|
||||
else
|
||||
CONFORMITY_PERCENTAGE=0 # No check runned, avoid division by 0
|
||||
fi
|
||||
printf '{'
|
||||
printf '"available_checks": %s, ' "$TOTAL_CHECKS"
|
||||
printf '"run_checks": %s, ' "$TOTAL_TREATED_CHECKS"
|
||||
printf '"passed_checks": %s, ' "$PASSED_CHECKS"
|
||||
printf '"conformity_percentage": %s' "$CONFORMITY_PERCENTAGE"
|
||||
printf '}\n'
|
||||
else
|
||||
printf "%40s\n" "################### SUMMARY ###################"
|
||||
printf "%30s %s\n" "Total Available Checks :" "$TOTAL_CHECKS"
|
||||
|
@ -25,6 +25,9 @@ backup_file() {
|
||||
#
|
||||
|
||||
case $LOGLEVEL in
|
||||
silent)
|
||||
MACHINE_LOG_LEVEL=0
|
||||
;;
|
||||
error)
|
||||
MACHINE_LOG_LEVEL=1
|
||||
;;
|
||||
|
Loading…
Reference in New Issue
Block a user