Last active
September 9, 2020 05:02
-
-
Save SweBarre/19d201546ae15ea4f4166e9af3aa77b4 to your computer and use it in GitHub Desktop.
zypper / prometheus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# | |
# Description: Expose iprometheus metrics from zypper updates and patches | |
# | |
# Author: Jonas Forsberg <barregargamel@gmail.com> | |
set -u -o pipefail | |
tempfile=$(mktemp /tmp/checkupdate.XXXXXX) | |
patch_info="$(zypper list-patches --with-optional)" | |
updates=$(zypper list-updates | grep -E -c "^v") | |
patches="$(echo "${patch_info}" | sed -n 's/^\([0-9]\+\) patch.*/\1/p')" | |
security_patches="$(echo "${patch_info}" | sed -n 's/^[0-9]\+ patch.* (\([0-9]\+\).*/\1/p')" | |
[[ -z "$patches" ]] && patches=0 | |
[[ -z "$security_patches" ]] && security_patches=0 | |
at <<EOF > "$tempfile" | |
# HELP zypper_update_pending Zypper package pending | |
# TYPE zypper_update_pending gauge | |
zypper_update_pending ${updates} | |
# HELP zypper_patch_pending Zypper patch pending | |
# TYPE zypper_patch_pending gauge | |
zypper_patch_pending ${patches} | |
# HELP zypper_security_patch_pending Zypper patch pending | |
# TYPE zypper_security_patch_pending gauge | |
zypper_security_patch_pending ${security_patches} | |
EOF | |
chmod 0644 "$tempfile" | |
mv "$tempfile" /var/lib/node_exporter/textfile/checkupdate.prom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It's good to show your quick fixes to the public, I always find something to polish