Commit 86c999d8 authored by Francesco Gionghi's avatar Francesco Gionghi
Browse files

Merge branch 'master' into 'main'

all

See merge request !1
parents 2fe3050f be01d4d5
#!/bin/bash
#
# Description: Expose metrics from apt updates.
#
# Author: Ben Kochie <superq@gmail.com>
PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
upgrades="$(/usr/bin/apt-get --just-print dist-upgrade \
| /usr/bin/awk -F'[()]' \
'/^Inst/ { sub("^[^ ]+ ", "", $2); gsub(" ","",$2);
sub("\\[", " ", $2); sub("\\]", "", $2); print $2 }' \
| /usr/bin/sort \
| /usr/bin/uniq -c \
| awk '{ gsub(/\\\\/, "\\\\", $2); gsub(/"/, "\\\"", $2);
gsub(/\[/, "", $3); gsub(/\]/, "", $3);
print "apt_upgrades_pending{origin=\"" $2 "\",arch=\"" $NF "\"} " $1}'
)"
autoremove="$(/usr/bin/apt-get --just-print autoremove \
| /usr/bin/awk '/^Remv/{a++}END{printf "apt_autoremove_pending %d", a}'
)"
echo '# HELP apt_upgrades_pending Apt package pending updates by origin.'
echo '# TYPE apt_upgrades_pending gauge'
if [[ -n "${upgrades}" ]] ; then
echo "${upgrades}"
else
echo 'apt_upgrades_pending{origin="",arch=""} 0'
fi
echo '# HELP apt_autoremove_pending Apt package pending autoremove.'
echo '# TYPE apt_autoremove_pending gauge'
echo "${autoremove}"
echo '# HELP node_reboot_required Node reboot is required for software updates.'
echo '# TYPE node_reboot_required gauge'
if [[ -f '/run/reboot-required' ]] ; then
echo 'node_reboot_required 1'
else
echo 'node_reboot_required 0'
fi
#!/bin/bash
#
# Description: Expose metrics from yum updates.
#
# Author: Slawomir Gonet <slawek@otwiera.cz>
#
# Based on apt.sh by Ben Kochie <superq@gmail.com>
PATH=$PATH:/usr/lib/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
set -u -o pipefail
# shellcheck disable=SC2016
filter_awk_script='
BEGIN { mute=1 }
/Obsoleting Packages/ {
mute=0
}
mute && /^[[:print:]]+\.[[:print:]]+/ {
print $3
}
'
check_upgrades() {
/usr/bin/yum -q check-update |
/usr/bin/xargs -n3 |
awk "${filter_awk_script}" |
sort |
uniq -c |
awk '{print "yum_upgrades_pending{origin=\""$2"\"} "$1}'
}
upgrades=$(check_upgrades)
echo '# HELP yum_upgrades_pending Yum package pending updates by origin.'
echo '# TYPE yum_upgrades_pending gauge'
if [[ -n "${upgrades}" ]] ; then
echo "${upgrades}"
else
echo 'yum_upgrades_pending{origin=""} 0'
fi
fbkservices_prometheus_pkgs_update:
file.directory:
- name: /etc/fbkservices-prometheus
- user: root
- group: root
check_pkgs_update:
file.managed:
- name: /usr/local/bin/check_pkgs_update.sh
{% if grains['os'] == 'Ubuntu' %}
- source: salt://check_update/files/apt.sh
{% elif grains['os'] == 'RedHat' %}
- source: salt://check_update/files/yum.sh
{% endif %}
- user: root
- group: root
- mode: 755
pkgs_update_logs:
cron.present:
- name: /usr/local/bin/check_pkgs_update.sh > /etc/fbkservices-prometheus/pkgs.prom
- user: root
- minute: random
- hour: '8'
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment