Skip to content

Instantly share code, notes, and snippets.

@SweBarre
Last active September 9, 2020 05:02
Show Gist options
  • Save SweBarre/19d201546ae15ea4f4166e9af3aa77b4 to your computer and use it in GitHub Desktop.
Save SweBarre/19d201546ae15ea4f4166e9af3aa77b4 to your computer and use it in GitHub Desktop.
zypper / prometheus
#!/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
@SweBarre
Copy link
Author

SweBarre commented Sep 9, 2020

It's good to show your quick fixes to the public, I always find something to polish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment