forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_datastax_opscenter_cassandra_alerts.pl
executable file
·74 lines (56 loc) · 1.58 KB
/
check_datastax_opscenter_cassandra_alerts.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
#!/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/events_alerts.html#events-alerts
$DESCRIPTION = "Nagios Plugin to check DataStax OpsCenter alerts for a given cluster via the DataStax OpsCenter Rest API
Requires the DataStax Enterprise
Tested on DataStax OpsCenter 5.0.0 with DataStax Enterprise Server 4.5.1";
$VERSION = "0.2";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
use HariSekhon::DataStax::OpsCenter;
use Data::Dumper;
use LWP::Simple '$ua';
$ua->agent("Hari Sekhon $progname version $main::VERSION");
%options = (
%hostoptions,
%useroptions,
%clusteroption,
);
get_options();
$host = validate_host($host);
$port = validate_port($port);
$user = validate_user($user);
$password = validate_password($password);
validate_cluster();
vlog2;
set_timeout();
set_http_timeout($timeout-1);
$ua->show_progress(1) if $debug;
$status = "OK";
list_clusters();
$json = curl_opscenter "$cluster/alerts/fired";
vlog3 Dumper($json);
isArray($json) or quit "UNKNOWN", "non-array returned. $nagios_plugins_support_msg_api";
# TODO: Improve this when I actually have some alerts to evaluate
if(@{$json}){
critical;
$msg .= scalar @{$json} . " ";
} else {
$msg .= "no ";
}
$msg .= "alerts fired in DataStax OpsCenter for cluster '$cluster'";
vlog2;
quit $status, $msg;