From 5ef22b942a10cd3c9b8c0c4034670e48515da383 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 | 14 +++++++------- zypper.sh | 27 +++++++++++++-------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/zypper.py b/zypper.py index 69f13c7..77b5126 100755 --- a/zypper.py +++ b/zypper.py @@ -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..073f2f8 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,9 @@ Available options: Examples: zypper.sh --less - zypper.sh -m -""" - exit + zypper.sh -m" + # shellcheck enable=SC1078 + exit 0 fi # Check if we are root @@ -32,6 +33,7 @@ if [ "$EUID" -ne 0 ]; then exit 1 fi +# shellcheck disable=SC2016 filter_pending_updates=' BEGIN { FS=" \\| "; # set field separator to " | " @@ -104,10 +106,11 @@ NR { printf "zypper_package_orphan{package=\"%s\",installed-version=\"%s\"} 1\n", package, installed_version } ' +# shellcheck enable=SC2016 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" @@ -128,7 +131,7 @@ 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" @@ -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"