Skip to content

Commit

Permalink
fix(zypper.sh): remove lint problems
Browse files Browse the repository at this point in the history
Signed-off-by: Wabri <[email protected]>
  • Loading branch information
Wabri committed Oct 24, 2024
1 parent 810711b commit 5ef22b9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
14 changes: 7 additions & 7 deletions zypper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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,
Expand Down
27 changes: 13 additions & 14 deletions zypper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand All @@ -32,6 +33,7 @@ if [ "$EUID" -ne 0 ]; then
exit 1
fi

# shellcheck disable=SC2016
filter_pending_updates='
BEGIN {
FS=" \\| "; # set field separator to " | "
Expand Down Expand Up @@ -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"
Expand All @@ -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"
Expand All @@ -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}'
Expand All @@ -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}'
Expand All @@ -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}'
Expand All @@ -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"
Expand Down

0 comments on commit 5ef22b9

Please sign in to comment.