forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_datastax_opscenter_cassandra_space.pl
executable file
·86 lines (65 loc) · 2.22 KB
/
check_datastax_opscenter_cassandra_space.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
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
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2013-10-18 18:44:35 +0100 (Fri, 18 Oct 2013)
#
# https://github.com/harisekhon/nagios-plugins
#
# License: see accompanying LICENSE file
#
# http://www.datastax.com/documentation/opscenter/5.0/api/docs/cluster_info.html#storage-capacity
$DESCRIPTION = "Nagios Plugin to check Cassandra storage capacity % used via DataStax OpsCenter Rest API
Tested on DataStax OpsCenter 3.2.2 and 5.0.0";
$VERSION = "0.3";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use HariSekhon::DataStax::OpsCenter;
use LWP::Simple '$ua';
$ua->agent("Hari Sekhon $progname version $main::VERSION");
set_threshold_defaults(80, 90);
%options = (
%hostoptions,
%useroptions,
%clusteroption,
%thresholdoptions,
);
get_options();
$host = validate_host($host);
$port = validate_port($port);
$user = validate_user($user);
$password = validate_password($password);
validate_cluster();
validate_thresholds(1, 1, { "simple" => "upper", "integer" => 0, "positive" => 1, "min" => 0, "max" => 100 });
vlog2;
set_timeout();
set_http_timeout($timeout-1);
$ua->show_progress(1) if $debug;
$status = "OK";
list_clusters();
$json = curl_opscenter "$cluster/storage-capacity";
my $free_gb = get_field_int("free_gb");
my $used_gb = get_field_int("used_gb");
my $reporting_nodes = get_field_int("reporting_nodes");
vlog2 "free_gb: $free_gb";
vlog2 "used_gb: $used_gb";
my $total_gb = $free_gb + $used_gb;
vlog2 "total_gb: $total_gb";
my $pc_used;
if($total_gb == 0 or $reporting_nodes == 0){
quit "UNKNOWN", "total space = ${total_gb} GB across $reporting_nodes reporting nodes";
} else {
$pc_used = sprintf("%.2f", $used_gb / $total_gb * 100);
}
$msg = "$pc_used% space used in cassandra cluster '$cluster' [" . human_units($used_gb * 1024 * 1024 * 1024) . "/" . human_units($total_gb * 1024 * 1024 * 1024) . "]";
check_thresholds($pc_used);
$msg .= " across $reporting_nodes reporting nodes | '% space used'=$pc_used%";
msg_perf_thresholds();
$msg .= " 'space used'=${used_gb}GB 'space free'=${free_gb}GB 'space total'=${total_gb}GB 'reporting nodes'=$reporting_nodes";
vlog2;
quit $status, $msg;