-
Notifications
You must be signed in to change notification settings - Fork 8
/
check_tidal_status.pl
executable file
·143 lines (123 loc) · 5.59 KB
/
check_tidal_status.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/perl
##################################################################################
# check_tidal_status.pl Copyright (C) 2012 Jason Antman <jason@jasonantman.com>
# Tidal Enterprise Scheduler (TES) CLI status check
##################################################################################
#
# 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, pursuant
# to the additional terms listed below.
#
# 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 (or with Nagios); if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA
#
# ADDITIONAL LICENSE TERMS (pursuant to GPLv3 Section 7):
# 1) All author attributions, copyright notices, and changelogs must
# remain intact and unchanged.
# 2) Any modified versions must be clearly marked as such.
#
# Additionally, I *request* that any modifications/patches be sent back
# to me for inclusion in the canonical version.
#
##################################################################################
# The authoritative version of this script lives at:
# <https://github.com/jantman/nagios-scripts>
#
# Please submit bug/feature requests or questions using
# the issue tracker there. Feedback, and patches (preferred
# as a GitHub pull request, but emailed diffs are also
# accepted) are strongly encouraged.
#
# Licensed under GNU GPLv3 - see the LICENSE file in the git repository.
#
##################################################################################
use strict;
use warnings;
use Nagios::Plugin;
my $LOCKFILE = "/tmp/check_tidal_status.lock";
my $VERSION = "v1";
my $BLURB = "Tidal Enterprise Scheduler (TES) master/CM status check script. Checks status of Tidal Master and Client Manager via cm/tesm programs.";
my $EXTRA = "
This plugin uses the TIDAL/master/bin/tesm and TIDAL/ClientManager/bin/cm program 'status' calls to check the
status of the Master and Client Manager locally.
This plugin must run locally on the master or client manager host, respectively.
Please be sure to configure the CM_COMMAND and TESM_COMMAND variables in the plugin, to call the commands correctly
Note - please check Perl dependencies. This plugin uses Nagios::Plugin.
";
my $np = Nagios::Plugin->new(
version => $VERSION,
url => "http://svn.jasonantman.com/public-nagios/check_tidal_status.pl",
blurb => $BLURB,
extra => $EXTRA,
usage => "Usage: %s [-v|--verbose] [-t <timeout>] -T <cm|master>",
);
$np->add_arg(spec => 'type|T=s', help => '-T --type . Type of host to check - "master" or "cm".', required => 1);
$np->getopts;
# Configure the exact command required to run the status script as the user your plugin runs as (nagios)
# Be warned, these are passed through backtick execs as-is
# ex.: $CM_COMMAND = "su - nagios /opt/TIDAL/master/bin/tesm status"
my $CM_COMMAND = "export PATH=/apps/java/bin:\$PATH; sudo -u tidal /apps/tidal/TIDAL/ClientManager/bin/cm status";
my $TESM_COMMAND = "export PATH=/apps/java/bin:\$PATH; sudo -u tidal /apps/tidal/TIDAL/master/bin/tesm status";
my ($cmd, $name);
if ( $np->opts->type eq 'master' ) {
$cmd = $TESM_COMMAND;
$name = "Tidal Master";
}
elsif ( $np->opts->type eq 'cm') {
$cmd = $CM_COMMAND;
$name = "Tidal ClientManager";
}
else {
# validate type
$np->nagios_die("Invalid argument for -T/--type. Must be 'cm' or 'master'.");
}
if ( -e $LOCKFILE ) {
$np->nagios_die("Check plugin already running, or lockfile ($LOCKFILE) not cleaned up.");
}
# touch lockfile
open(FH, ">", $LOCKFILE) or $np->nagios_die("Could not create lockfile ($LOCKFILE).");
close(FH);
# do the actual request
alarm $np->opts->timeout;
my @output = `$cmd`;
my $rcode = $?;
alarm 0;
unlink($LOCKFILE) or $np->nagios_die("Unable to remove lockfile ($LOCKFILE).");
$np->nagios_die("UNKNOWN: $cmd exited $rcode.") if $rcode != 0;
my $running = 0;
my ($hung, $total, $ver);
foreach my $line (@output) {
chomp $line;
if ($line =~ /Server is running./) { $running = 1; next;}
if ($line =~ /TIDAL Product Name: (.+)/) { $name = $1; next;}
if ($line =~ /TIDAL Product Version: (.+)/) { $ver = $1; next;}
if ($line =~ /Message threads: (\d+) of (\d+) appear hung./) {
$hung = $1;
$total = $2;
$np->add_perfdata(label => "hung_threads", value => $hung);
$np->add_perfdata(label => "total_threads", value => $total);
next;
}
if ($line =~ /Message performance: average message time = (\d+) milliseconds; max = (\d+) milliseconds for last 100 messages./) {
$np->add_perfdata(label => "message_avg_time", value => $1, uom => "ms");
$np->add_perfdata(label => "message_max_time", value => $2, uom => "ms");
}
if ($line =~ /Database performance: average operation time = (\d+) milliseconds; max = (\d+) milliseconds for last 100 operations./) {
$np->add_perfdata(label => "db_avg_time", value => $1, uom => "ms");
$np->add_perfdata(label => "db_max_time", value => $2, uom => "ms");
}
}
$np->nagios_exit('CRITICAL', "$name not running.") if $running == 0;
# else
$np->nagios_exit('WARNING', "$name $ver - $hung of $total message threads hung.") if $hung > 0;
# else
$np->nagios_exit('OK', "$name $ver - running, $hung of $total message threads hung.");