-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_buildbot_slave
More file actions
executable file
·89 lines (78 loc) · 1.94 KB
/
check_buildbot_slave
File metadata and controls
executable file
·89 lines (78 loc) · 1.94 KB
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
#!/usr/bin/perl -w
# nagios: -epn
# Check that a Buildbot slave is connected to its master
#
# Authors: Hubert Chathi <hubert@muchlearning.org>
#
# License: GPL v2 or later
use strict;
use warnings;
use Locale::gettext;
use Nagios::Plugin;
use LWP::UserAgent;
use MIME::Base64;
use JSON;
my $VERSION = '0.1';
my $np = Nagios::Plugin->new(
version => $VERSION,
blurb => _gt('Check that a Buildbot slave is connected to its master'),
usage => "Usage: %s <options>",
extra => &showExtra()
);
$np->add_arg(
spec => 'url|u=s',
help => _gt('Base URL for Buildbot master'),
required => 1
);
$np->add_arg(
spec => 'name|n=s',
help => _gt('Slave name'),
required => 1
);
$np->add_arg(
spec => 'authorization|a=s',
help => _gt('Username:password on sites with basic authentication')
);
$np->getopts();
my $ua = LWP::UserAgent->new();
my %params = ();
if ($np->opts->get('authorization'))
{
$params{'Authorization'} = "Basic ${\(encode_base64($np->opts->get('authorization')))}";
}
my $response = $ua->get("${\($np->opts->get('url'))}/json/slaves/${\($np->opts->get('name'))}?numbuilds=0", %params);
sub trim {
return $_[0] =~ s/^\s+|\s+$//rg;
}
if ($response->is_success) {
my $result = decode_json $response->decoded_content;
if (${$result}{"connected"} == JSON::true)
{
$np->add_message(OK, "version ${$result}{'version'}");
}
else
{
$np->add_message(CRITICAL, "not connected");
}
}
else
{
$np->add_message(CRITICAL, "HTTP error: " . $response->status_line);
}
my ($status, $message) = $np->check_messages('join' => ' - ');
$np->nagios_exit($status, $message);
sub logD {
print STDERR 'DEBUG: '.$_[0]."\n" if ($np->opts->verbose);
}
sub logW {
print STDERR 'WARNING: '.$_[0]."\n" if ($np->opts->verbose);
}
# Gettext wrapper
sub _gt {
return gettext($_[0]);
}
sub showExtra {
return <<TEXT;
Copyright (c) 2015-2016 Hubert Chathi
TEXT
}