Skip to content

Add text file helper for zypper #114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions zypper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#
# Description: Expose metrics from zypper updates.
#
# Author: Markus Otto <[email protected]>

upgrades="$(/usr/bin/zypper list-updates \
| /usr/bin/awk -F'|' '/^v/ {gsub(/ /,"",$2); print $2 $6}' \
| /usr/bin/sort \
| /usr/bin/uniq -c \
| /usr/bin/awk '{print "zypper_upgrades_pending{origin=\"" $2 "\",arch=\"" $3 "\"} " $1}'
)"

echo '# HELP zypper_upgrades_pending Zypper package pending updates by origin.'
echo '# TYPE zypper_upgrades_pending gauge'
if [[ -n "${upgrades}" ]] ; then
echo "${upgrades}"
else
echo 'zypper_upgrades_pending{origin="",arch=""} 0'
fi

echo '# HELP node_reboot_required Node reboot is required for software updates.'
echo '# TYPE node_reboot_required gauge'
if [[ -f '/run/reboot-needed' ]] ; then
echo 'node_reboot_required 1'
else
echo 'node_reboot_required 0'
fi