forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_mongodb_master_rest.pl
executable file
·56 lines (41 loc) · 1.1 KB
/
check_mongodb_master_rest.pl
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
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2013-12-17 22:35:14 +0000 (Tue, 17 Dec 2013)
#
# https://github.com/harisekhon/nagios-plugins
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check a given MongoD is Master via REST API
Authentication not supported yet, and Rest API is not recommended anyway.
Tested on MongoDB 2.6.1, 3.2.1";
$VERSION = "0.1";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use HariSekhon::MongoDB;
use LWP::Simple '$ua';
set_port_default(28017);
%options = (
%hostoptions,
# %useroptions,
);
get_options();
$host = validate_host($host);
$port = validate_port($port);
#$user = validate_user($user) if defined($user) and defined($password);
#$password = validate_password($password) if defined($password);
vlog2;
set_timeout();
$status = "OK";
$json = curl_mongo "isMaster?text=1";
my $ismaster = get_field("ismaster") ? "true" : "false";
$msg = "mongodb://$host:$port ismaster: $ismaster";
critical unless $ismaster eq "true";
quit $status, $msg;