-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_os_release
executable file
·141 lines (116 loc) · 3.62 KB
/
check_os_release
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# check_os_release
# https://github.com/hobbyquaker/check_os_release
#
# Simple Nagios/Icinga check for support end of Linux distributions.
#
# Currently only Debian, Raspbian and Ubuntu are supported, Pull Requests welcome!
# MIT Licensed, Copyright 2018, 2019 https://github.com/hobbyquaker
VERSION="2.0.7"
RELEASE_FILE="/etc/os-release"
DEBIAN_URL="https://debian.pages.debian.net/distro-info-data/debian.csv"
UBUNTU_URL="https://debian.pages.debian.net/distro-info-data/ubuntu.csv"
SCHEDULE_FILE="/tmp/os_release_schedule.csv"
SCHEDULE_FILE_MAXAGE=30
WARN_MONTHS=3
CRIT_MONTHS=1
DEB_LTS=0
while getopts 'w:c:lhv' OPT; do
case $OPT in
w) WARN_MONTHS=$OPTARG;;
c) CRIT_MONTHS=$OPTARG;;
h)
echo "usage: $0 [ -w value ] [ -c value ] [ -l ]
-w Warn if supports ends in less then given months [default: 3]
-c Critical if supports ends in less then given months [default: 1]
-l Use Debian LTS [default: false]
-h print this help screen
-v show version
"
exit 0
;;
l) DEB_LTS=1;;
v)
echo "$0 $VERSION"
exit 0
;;
esac
done
WARNING=$(date --date="+$WARN_MONTHS month" +"%Y-%m-%d")
CRITICAL=$(date --date="+$CRIT_MONTHS month" +"%Y-%m-%d")
TODAY=$(date +"%Y-%m-%d")
if [ ! -f $RELEASE_FILE ]; then
echo "UNKNOWN: $RELEASE_FILE missing"
exit 3
fi
source $RELEASE_FILE
case "$ID" in
"ubuntu")
REGEX="^$(echo $VERSION_ID | sed 's/\./\\./g')\s*\(LTS\)\?,"
URL=$UBUNTU_URL
;;
"debian") ;&
"raspbian")
REGEX="^$(echo $VERSION_ID | sed 's/\./\\./g'),"
URL=$DEBIAN_URL
;;
*)
# TODO other Distributions...
echo "UNKNOWN: unknown distribution ID=$ID (ID_LIKE=$ID_LIKE)"
exit 3
;;
esac
if [ ! -s $SCHEDULE_FILE ] ; then
rm -f $SCHEDULE_FILE
fi
if [ ! -f $SCHEDULE_FILE ]; then
wget -q $URL -O $SCHEDULE_FILE.tmp
if [ $? -ne 0 ]; then
echo "UNKNOWN: failed to download release schedule from $URL"
exit 3
else
mv $SCHEDULE_FILE.tmp $SCHEDULE_FILE
touch $SCHEDULE_FILE
fi
elif [[ $(find "$SCHEDULE_FILE" -mtime +$SCHEDULE_FILE_MAXAGE -print) ]]; then
wget -q $URL -O $SCHEDULE_FILE.tmp && mv $SCHEDULE_FILE.tmp $SCHEDULE_FILE && touch $SCHEDULE_FILE
fi
LINE=$(cat $SCHEDULE_FILE | grep $REGEX)
if [ -z "$LINE" ]; then
echo "UNKNOWN: $ID $VERSION_ID not found in release schedule"
exit 3
fi
VERSION=$(echo $LINE | cut -d ',' -f1)
CODENAME=$(echo $LINE | cut -d ',' -f2)
RELEASE=$(echo $LINE | cut -d ',' -f5)
if [ $DEB_LTS -ne 0 ] && [ "$ID" = "debian" ]; then
EOL=$(date --date="$RELEASE+5 years" +"%Y-%m-%d")
ESTIMATE=" (estimated)"
SUPPORT="LTS"
else
EOL=$(echo $LINE | cut -d ',' -f6)
SUPPORT="Support"
fi
if [ -z "$EOL" ] && [ "$ID" = "debian" ]; then
EOL=$(date --date="$RELEASE+3 years" +"%Y-%m-%d")
ESTIMATE=" (estimated)"
elif [ -z "$EOL" ] && [ "$ID_LIKE" = "debian" ]; then
EOL=$(date --date="$RELEASE+3 years" +"%Y-%m-%d")
ESTIMATE=" (estimated)"
elif [ -z "$EOL" ]; then
echo "UNKNOWN: EOL Date for $ID $VERSION_ID not found in release schedule"
exit 3
fi
if [ $EOL \< $TODAY ]; then
echo "CRITICAL: ${SUPPORT} for $NAME $VERSION ($CODENAME) ended $EOL$ESTIMATE"
exit 2
elif [ $EOL \< $CRITICAL ]; then
echo "CRITICAL: ${SUPPORT} for $NAME $VERSION ($CODENAME) ends $EOL$ESTIMATE"
exit 2
elif [ $EOL \< $WARNING ]; then
echo "WARNING: ${SUPPORT} for $NAME $VERSION ($CODENAME) ends $EOL$ESTIMATE"
exit 1
else
echo "OK: ${SUPPORT} for $NAME $VERSION ($CODENAME) ends $EOL$ESTIMATE"
exit 0
fi