-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_gitlabupdate
executable file
·102 lines (87 loc) · 2.61 KB
/
check_gitlabupdate
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
#!/usr/bin/perl -w
use strict;
#check_gitlabupdate.pl
#Nagios plugin to check if there is a new GitLab version available
#Version: 20140207
#Author: Christoph Hoth <[email protected]>
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#The Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#configuration
my $gitlab_path="/home/git/gitlab";
my $spoolfile="/var/spool/check_gitlabupdate";
my $allowed_lastcron_days=5;
my $debug=0;
#declare variables
my $cur_version;
my $new_version;
my $lastcron;
#get current version
open(VERSIONFILE,"< $gitlab_path/VERSION") or die "Unable to open $gitlab_path/VERSION";
while(<VERSIONFILE>){
if($_=~/^([\d\.]+)$/){
$cur_version=$1;
last;
}
}
close(VERSIONFILE);
#cancel if current version couldn't be determined
if(!$cur_version){
print "UNKNOWN Unable to determine current version\n";
exit 3;
}
$debug && print "Current version: $cur_version\n";
#read latest version from spoolfile
if(!open(SPOOLFILE,"<$spoolfile")){
print "UNKNOWN Unable to open $spoolfile to get latest version number";
exit 3;
}
while(<SPOOLFILE>){
if($_=~/^(\d+) ([\d\.]+)$/){
$lastcron=$1;
$new_version=$2;
last;
}
}
close(SPOOLFILE);
#cancel if no latest tag found
if(!$new_version){
print "UNKNOWN Unable to retrieve latest version number from spoolfile\n";
exit 3;
}
$debug && print "Latest version: $new_version\n";
#compare versions
my @cur=split(/\./,$cur_version);
my @new=split(/\./,$new_version);
my $arraycount=0;
if(@cur gt @new){$arraycount=@cur;}
else{$arraycount=@new;}
my $found=0;
for(my $i=0;$i<$arraycount;$i++){
if($cur[$i]<$new[$i]){
$found=1;
last;
}
}
if($found){
print "WARNING New version available $new_version (current: $cur_version)\n";
exit 1;
}else{
#check if last cronjob check was running within the allowed time difference
if($lastcron<(time()-$allowed_lastcron_days*86400)){
print "WARNING Last successful check was running more than $allowed_lastcron_days days ago at ".localtime($lastcron)." (current version $cur_version)\n";
exit 1;
}else{
print "OK GitLab is up to date ($cur_version)\n";
exit 0;
}
}