-
Notifications
You must be signed in to change notification settings - Fork 0
/
yum.sh
executable file
·39 lines (34 loc) · 795 Bytes
/
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
#!/usr/bin/env bash
#
# Description: Expose metrics from yum updates.
#
# Author: Slawomir Gonet <[email protected]>
#
# Based on apt.sh by Ben Kochie <[email protected]>
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