Add a batch short option for one line result

When using this script on a large amount a machine (via clustershell or
instance) it can be easier to have a very short result on one line
showing only the vulnerabilities
This commit is contained in:
Pierre Gaxatte 2018-09-04 08:37:35 +02:00
parent 80e0db7cc4
commit 221b202d0d
1 changed files with 7 additions and 1 deletions

View File

@ -66,6 +66,7 @@ show_usage()
--arch-prefix PREFIX specify a prefix for cross-inspecting a kernel of a different arch, for example "aarch64-linux-gnu-", --arch-prefix PREFIX specify a prefix for cross-inspecting a kernel of a different arch, for example "aarch64-linux-gnu-",
so that invoked tools will be prefixed with this (i.e. aarch64-linux-gnu-objdump) so that invoked tools will be prefixed with this (i.e. aarch64-linux-gnu-objdump)
--batch text produce machine readable output, this is the default if --batch is specified alone --batch text produce machine readable output, this is the default if --batch is specified alone
--batch short produce only one line with the vulnerabilities separated by spaces
--batch json produce JSON output formatted for Puppet, Ansible, Chef... --batch json produce JSON output formatted for Puppet, Ansible, Chef...
--batch nrpe produce machine readable output formatted for NRPE --batch nrpe produce machine readable output formatted for NRPE
--batch prometheus produce output for consumption by prometheus-node-exporter --batch prometheus produce output for consumption by prometheus-node-exporter
@ -640,7 +641,7 @@ while [ -n "$1" ]; do
opt_no_color=1 opt_no_color=1
shift shift
case "$1" in case "$1" in
text|nrpe|json|prometheus) opt_batch_format="$1"; shift;; text|short|nrpe|json|prometheus) opt_batch_format="$1"; shift;;
--*) ;; # allow subsequent flags --*) ;; # allow subsequent flags
'') ;; # allow nothing at all '') ;; # allow nothing at all
*) *)
@ -739,6 +740,7 @@ pvulnstatus()
case "$opt_batch_format" in case "$opt_batch_format" in
text) _echo 0 "$1: $2 ($3)";; text) _echo 0 "$1: $2 ($3)";;
short) short_output="${short_output}$1 ";;
json) json)
case "$2" in case "$2" in
UNK) is_vuln="null";; UNK) is_vuln="null";;
@ -3418,6 +3420,10 @@ if [ "$opt_batch" = 1 ] && [ "$opt_batch_format" = "nrpe" ]; then
fi fi
fi fi
if [ "$opt_batch" = 1 ] && [ "$opt_batch_format" = "short" ]; then
_echo 0 "${short_output% }"
fi
if [ "$opt_batch" = 1 ] && [ "$opt_batch_format" = "json" ]; then if [ "$opt_batch" = 1 ] && [ "$opt_batch_format" = "json" ]; then
_echo 0 "${json_output%?}]" _echo 0 "${json_output%?}]"
fi fi