-
Notifications
You must be signed in to change notification settings - Fork 194
/
yum.sh
executable file
·50 lines (44 loc) · 1.14 KB
/
yum.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env bash
#
# Description: Expose metrics from yum updates.
#
# Author: Slawomir Gonet <slawek@otwiera.cz>
#
# Based on apt.sh by Ben Kochie <superq@gmail.com>
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
# If yum-utils/dnf-utils is not installed then we skip rendering this metric
if [[ -x /bin/needs-restarting ]]; then
echo '# HELP node_reboot_required Node reboot is required for software updates.'
echo '# TYPE node_reboot_required gauge'
if /bin/needs-restarting -r >/dev/null 2>&1; then
echo 'node_reboot_required 0'
else
echo 'node_reboot_required 1'
fi
fi