From 4eb861d9c3225e108b73b2f8c7a5efbe6bd17302 Mon Sep 17 00:00:00 2001 From: Wabri <12409541+Wabri@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:04:33 +0200 Subject: [PATCH] fix(zypper.sh): remove lint problems Signed-off-by: Wabri <12409541+Wabri@users.noreply.github.com> --- zypper.py | 16 ++++++++-------- zypper.sh | 31 +++++++++++++++---------------- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/zypper.py b/zypper.py index 69f13c7..d862ec0 100755 --- a/zypper.py +++ b/zypper.py @@ -3,7 +3,7 @@ """ Description: Expose metrics from zypper updates and patches. -The script can take 2 arguments: `--more` and `--less`. +The script can take 2 arguments: `--more` and `--less`. The selection of the arguments change how many informations are going to be printed. The `--more` is by default. @@ -113,8 +113,8 @@ def print_reboot_required(): stderr=subprocess.DEVNULL, check=False) - print('# HELP node_reboot_required Node require reboot to activate installed updates or '\ - 'patches. (0 = not needed, 1 = needed)') + print('# HELP node_reboot_required Node require reboot to activate installed updates or ' + 'patches. (0 = not needed, 1 = needed)') print('# TYPE node_reboot_required gauge') if result.returncode == 0: print('node_reboot_required 0') @@ -228,7 +228,7 @@ def main(argv: Sequence[str] | None = None) -> int: ).stdout.decode('utf-8') data_zypper_orphaned = __extract_orphaned_data(raw_zypper_orphaned) - print('# HELP zypper_update_pending zypper package update available from repository. (0 = not '\ + print('# HELP zypper_update_pending zypper package update available from repository. (0 = not ' 'available, 1 = available)') print('# TYPE zypper_update_pending gauge') print_pending_updates(data_zypper_lu, args.all_info) @@ -237,7 +237,7 @@ def main(argv: Sequence[str] | None = None) -> int: print('# TYPE zypper_updates_pending_total counter') print_updates_sum(data_zypper_lu) - print('# HELP zypper_patch_pending zypper patch available from repository. (0 = not available '\ + print('# HELP zypper_patch_pending zypper patch available from repository. (0 = not available ' ', 1 = available)') print('# TYPE zypper_patch_pending gauge') print_pending_patches(data_zypper_lp, args.all_info) @@ -246,21 +246,21 @@ def main(argv: Sequence[str] | None = None) -> int: print('# TYPE zypper_patches_pending_total counter') print_patches_sum(data_zypper_lp) - print('# HELP zypper_patches_pending_security_total zypper patches available with category '\ + print('# HELP zypper_patches_pending_security_total zypper patches available with category ' 'security total') print('# TYPE zypper_patches_pending_security_total counter') print_patches_sum(data_zypper_lp, prefix="zypper_patches_pending_security_total", filters={'Category': 'security'}) - print('# HELP zypper_patches_pending_security_important_total zypper patches available with '\ + print('# HELP zypper_patches_pending_security_important_total zypper patches available with ' 'category security severity important total') print('# TYPE zypper_patches_pending_security_important_total counter') print_patches_sum(data_zypper_lp, prefix="zypper_patches_pending_security_important_total", filters={'Category': 'security', 'Severity': 'important'}) - print('# HELP zypper_patches_pending_reboot_total zypper patches available which require '\ + print('# HELP zypper_patches_pending_reboot_total zypper patches available which require ' 'reboot total') print('# TYPE zypper_patches_pending_reboot_total counter') print_patches_sum(data_zypper_lp, diff --git a/zypper.sh b/zypper.sh index 624ac68..54d3279 100755 --- a/zypper.sh +++ b/zypper.sh @@ -10,7 +10,8 @@ set -o nounset # fail if unset variables set -o pipefail # reflect exit status if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then - echo """Usage: zypper.sh [OPTION] + # shellcheck disable=SC1078 + echo "Usage: zypper.sh [OPTION] This is an script to extract monitoring values for the zypper package It work only with root permission! @@ -21,9 +22,8 @@ Available options: Examples: zypper.sh --less - zypper.sh -m -""" - exit + zypper.sh -m" + exit 0 fi # Check if we are root @@ -32,6 +32,7 @@ if [ "$EUID" -ne 0 ]; then exit 1 fi +# shellcheck disable=SC2016 filter_pending_updates=' BEGIN { FS=" \\| "; # set field separator to " | " @@ -56,6 +57,7 @@ NR { } ' +# shellcheck disable=SC2016 filter_pending_patches=' BEGIN { FS=" \\| "; # set field separator to " | " @@ -86,6 +88,7 @@ NR { } ' +# shellcheck disable=SC2016 filter_orphan_packages=' BEGIN { FS=" \\| "; # set field separator to " | " @@ -107,10 +110,10 @@ NR { get_pending_updates() { if [ -z "$1" ]; then - echo 'zypper_update_pending{repository="",package-name="",available-version=""} 0' + echo "zypper_update_pending{repository=\"\",package-name=\"\",available-version=\"\"} 0" else echo "$1" | - awk -v output_format=$2 "$filter_pending_updates" + awk -v output_format="$2" "$filter_pending_updates" fi } @@ -128,10 +131,10 @@ get_updates_sum() { get_pending_patches() { if [ -z "$1" ]; then - echo 'zypper_patch_pending{repository="",patch-name="",category="",severity="",interactive="",status=""} 0' + echo "zypper_patch_pending{repository=\"\",patch-name=\"\",category=\"\",severity=\"\",interactive=\"\",status=\"\"} 0" else echo "$1" | - awk -v output_format=$2 "$filter_pending_patches" + awk -v output_format="$2" "$filter_pending_patches" fi } @@ -141,8 +144,7 @@ get_pending_security_patches() { echo "0" else echo "$1" | - grep "| security" | - wc -l + grep -c "| security" fi } | awk '{print "zypper_patches_pending_security_total "$1}' @@ -154,9 +156,7 @@ get_pending_security_important_patches() { echo "0" else echo "$1" | - grep "| security" | - grep important | - wc -l + grep -c "| security.*important" fi } | awk '{print "zypper_patches_pending_security_important_total "$1}' @@ -168,8 +168,7 @@ get_pending_reboot_patches() { echo "0" else echo "$1" | - grep reboot | - wc -l + grep -c "reboot" fi } | awk '{print "zypper_patches_pending_reboot_total "$1}' @@ -194,7 +193,7 @@ get_zypper_version() { get_orphan_packages() { if [ -z "$1" ]; then - echo 'zypper_package_orphan{package="",installed-version=""} 0' + echo "zypper_package_orphan{package=\"\",installed-version=\"\"} 0" else echo "$1" | awk "$filter_orphan_packages"