Skip to content

Commit 4eb861d

Browse files
committed
fix(zypper.sh): remove lint problems
Signed-off-by: Wabri <[email protected]>
1 parent 810711b commit 4eb861d

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

Diff for: zypper.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
Description: Expose metrics from zypper updates and patches.
55
6-
The script can take 2 arguments: `--more` and `--less`.
6+
The script can take 2 arguments: `--more` and `--less`.
77
The selection of the arguments change how many informations are going to be printed.
88
99
The `--more` is by default.
@@ -113,8 +113,8 @@ def print_reboot_required():
113113
stderr=subprocess.DEVNULL,
114114
check=False)
115115

116-
print('# HELP node_reboot_required Node require reboot to activate installed updates or '\
117-
'patches. (0 = not needed, 1 = needed)')
116+
print('# HELP node_reboot_required Node require reboot to activate installed updates or '
117+
'patches. (0 = not needed, 1 = needed)')
118118
print('# TYPE node_reboot_required gauge')
119119
if result.returncode == 0:
120120
print('node_reboot_required 0')
@@ -228,7 +228,7 @@ def main(argv: Sequence[str] | None = None) -> int:
228228
).stdout.decode('utf-8')
229229
data_zypper_orphaned = __extract_orphaned_data(raw_zypper_orphaned)
230230

231-
print('# HELP zypper_update_pending zypper package update available from repository. (0 = not '\
231+
print('# HELP zypper_update_pending zypper package update available from repository. (0 = not '
232232
'available, 1 = available)')
233233
print('# TYPE zypper_update_pending gauge')
234234
print_pending_updates(data_zypper_lu, args.all_info)
@@ -237,7 +237,7 @@ def main(argv: Sequence[str] | None = None) -> int:
237237
print('# TYPE zypper_updates_pending_total counter')
238238
print_updates_sum(data_zypper_lu)
239239

240-
print('# HELP zypper_patch_pending zypper patch available from repository. (0 = not available '\
240+
print('# HELP zypper_patch_pending zypper patch available from repository. (0 = not available '
241241
', 1 = available)')
242242
print('# TYPE zypper_patch_pending gauge')
243243
print_pending_patches(data_zypper_lp, args.all_info)
@@ -246,21 +246,21 @@ def main(argv: Sequence[str] | None = None) -> int:
246246
print('# TYPE zypper_patches_pending_total counter')
247247
print_patches_sum(data_zypper_lp)
248248

249-
print('# HELP zypper_patches_pending_security_total zypper patches available with category '\
249+
print('# HELP zypper_patches_pending_security_total zypper patches available with category '
250250
'security total')
251251
print('# TYPE zypper_patches_pending_security_total counter')
252252
print_patches_sum(data_zypper_lp,
253253
prefix="zypper_patches_pending_security_total",
254254
filters={'Category': 'security'})
255255

256-
print('# HELP zypper_patches_pending_security_important_total zypper patches available with '\
256+
print('# HELP zypper_patches_pending_security_important_total zypper patches available with '
257257
'category security severity important total')
258258
print('# TYPE zypper_patches_pending_security_important_total counter')
259259
print_patches_sum(data_zypper_lp,
260260
prefix="zypper_patches_pending_security_important_total",
261261
filters={'Category': 'security', 'Severity': 'important'})
262262

263-
print('# HELP zypper_patches_pending_reboot_total zypper patches available which require '\
263+
print('# HELP zypper_patches_pending_reboot_total zypper patches available which require '
264264
'reboot total')
265265
print('# TYPE zypper_patches_pending_reboot_total counter')
266266
print_patches_sum(data_zypper_lp,

Diff for: zypper.sh

+15-16
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ set -o nounset # fail if unset variables
1010
set -o pipefail # reflect exit status
1111

1212
if [[ "${1-}" =~ ^-*h(elp)?$ ]]; then
13-
echo """Usage: zypper.sh [OPTION]
13+
# shellcheck disable=SC1078
14+
echo "Usage: zypper.sh [OPTION]
1415
This is an script to extract monitoring values for the zypper package
1516
1617
It work only with root permission!
@@ -21,9 +22,8 @@ Available options:
2122
2223
Examples:
2324
zypper.sh --less
24-
zypper.sh -m
25-
"""
26-
exit
25+
zypper.sh -m"
26+
exit 0
2727
fi
2828

2929
# Check if we are root
@@ -32,6 +32,7 @@ if [ "$EUID" -ne 0 ]; then
3232
exit 1
3333
fi
3434

35+
# shellcheck disable=SC2016
3536
filter_pending_updates='
3637
BEGIN {
3738
FS=" \\| "; # set field separator to " | "
@@ -56,6 +57,7 @@ NR {
5657
}
5758
'
5859

60+
# shellcheck disable=SC2016
5961
filter_pending_patches='
6062
BEGIN {
6163
FS=" \\| "; # set field separator to " | "
@@ -86,6 +88,7 @@ NR {
8688
}
8789
'
8890

91+
# shellcheck disable=SC2016
8992
filter_orphan_packages='
9093
BEGIN {
9194
FS=" \\| "; # set field separator to " | "
@@ -107,10 +110,10 @@ NR {
107110

108111
get_pending_updates() {
109112
if [ -z "$1" ]; then
110-
echo 'zypper_update_pending{repository="",package-name="",available-version=""} 0'
113+
echo "zypper_update_pending{repository=\"\",package-name=\"\",available-version=\"\"} 0"
111114
else
112115
echo "$1" |
113-
awk -v output_format=$2 "$filter_pending_updates"
116+
awk -v output_format="$2" "$filter_pending_updates"
114117
fi
115118
}
116119

@@ -128,10 +131,10 @@ get_updates_sum() {
128131

129132
get_pending_patches() {
130133
if [ -z "$1" ]; then
131-
echo 'zypper_patch_pending{repository="",patch-name="",category="",severity="",interactive="",status=""} 0'
134+
echo "zypper_patch_pending{repository=\"\",patch-name=\"\",category=\"\",severity=\"\",interactive=\"\",status=\"\"} 0"
132135
else
133136
echo "$1" |
134-
awk -v output_format=$2 "$filter_pending_patches"
137+
awk -v output_format="$2" "$filter_pending_patches"
135138
fi
136139
}
137140

@@ -141,8 +144,7 @@ get_pending_security_patches() {
141144
echo "0"
142145
else
143146
echo "$1" |
144-
grep "| security" |
145-
wc -l
147+
grep -c "| security"
146148
fi
147149
} |
148150
awk '{print "zypper_patches_pending_security_total "$1}'
@@ -154,9 +156,7 @@ get_pending_security_important_patches() {
154156
echo "0"
155157
else
156158
echo "$1" |
157-
grep "| security" |
158-
grep important |
159-
wc -l
159+
grep -c "| security.*important"
160160
fi
161161
} |
162162
awk '{print "zypper_patches_pending_security_important_total "$1}'
@@ -168,8 +168,7 @@ get_pending_reboot_patches() {
168168
echo "0"
169169
else
170170
echo "$1" |
171-
grep reboot |
172-
wc -l
171+
grep -c "reboot"
173172
fi
174173
} |
175174
awk '{print "zypper_patches_pending_reboot_total "$1}'
@@ -194,7 +193,7 @@ get_zypper_version() {
194193

195194
get_orphan_packages() {
196195
if [ -z "$1" ]; then
197-
echo 'zypper_package_orphan{package="",installed-version=""} 0'
196+
echo "zypper_package_orphan{package=\"\",installed-version=\"\"} 0"
198197
else
199198
echo "$1" |
200199
awk "$filter_orphan_packages"

0 commit comments

Comments
 (0)