diff options
Diffstat (limited to 'contrib/check_sybase')
-rwxr-xr-x | contrib/check_sybase | 63 |
1 files changed, 49 insertions, 14 deletions
diff --git a/contrib/check_sybase b/contrib/check_sybase index 1f1cbf8..74cf17a 100755 --- a/contrib/check_sybase +++ b/contrib/check_sybase | |||
@@ -1,22 +1,27 @@ | |||
1 | #!/usr/bin/perl -w | 1 | #!/usr/bin/perl |
2 | # check_sybase | 2 | # check_sybase |
3 | # A nagios plugin that connects to a Sybase database and checks free space. | 3 | # A nagios plugin that connects to a Sybase database and checks free space. |
4 | # | 4 | # |
5 | # Copyright 2004 Simon Bellwood, NetMan Network Management and IT Services GmbH | 5 | # Copyright 2004-2005 Simon Bellwood, NetMan Network Management and IT |
6 | # Services GmbH | ||
6 | # Portions Copyright 2001 Michael Peppler. | 7 | # Portions Copyright 2001 Michael Peppler. |
7 | # License: GPL | 8 | # License: GPL |
8 | # | 9 | # |
9 | # Bugs and feedback to simon.bellwood@nospam.net-man.at | 10 | # Bugs and feedback to simon.bellwood@NOSPAM.net-man.at |
10 | # Latest version available from: | 11 | # Latest version available from: |
11 | # http://www.net-man.at/software/check_sybase-LATEST.zip | 12 | # http://www.net-man.at/software/check_sybase-LATEST.zip |
12 | # | 13 | # |
13 | # Revision history: | 14 | # Revision history: |
14 | # 0.1 01-OCT-2004 Initial version. | 15 | # 0.1 01-OCT-2004 Initial version. |
15 | # 0.2 08-NOV-2004 Initial release. | 16 | # 0.2 08-NOV-2004 Initial release. |
16 | # 0.3 13-JAN-2004 Fixed lib path, improved timeouts. | 17 | # 0.3 13-JAN-2005 Fixed lib path, improved timeouts. |
17 | # 0.4 26-JAN-2004 Added loginTimeout. | 18 | # 0.4 26-JAN-2005 Added loginTimeout. |
18 | my $VERSION = "0.4"; | 19 | # 0.5 04-FEB-2005 Fixed dates in history. Oops. |
19 | 20 | # 0.6 29-MAR-2005 Added --explain option. | |
21 | # 0.7 08-APR-2005 Added initial performance data support. | ||
22 | my $VERSION = "0.7"; | ||
23 | |||
24 | #use warnings; | ||
20 | use strict; | 25 | use strict; |
21 | use DBI; | 26 | use DBI; |
22 | use Getopt::Long; | 27 | use Getopt::Long; |
@@ -30,8 +35,8 @@ my $DEFAULT_WARNING = "25"; | |||
30 | my $DEFAULT_CRITICAL = "10"; | 35 | my $DEFAULT_CRITICAL = "10"; |
31 | my $DEFAULT_TIMEOUT = "30"; | 36 | my $DEFAULT_TIMEOUT = "30"; |
32 | 37 | ||
33 | my ($user, $pass, $dbsvr, $dbname, $config, $checktype, $warn, $crit, $timeout, | 38 | my ($user, $pass, $dbsvr, $dbname, $config, $checktype, $explain, |
34 | $help, $version); | 39 | $warn, $crit, $timeout, $help, $version); |
35 | 40 | ||
36 | my $options_okay = GetOptions( | 41 | my $options_okay = GetOptions( |
37 | "U|user=s" => \$user, | 42 | "U|user=s" => \$user, |
@@ -40,6 +45,7 @@ my $options_okay = GetOptions( | |||
40 | "D|dbname=s" => \$dbname, | 45 | "D|dbname=s" => \$dbname, |
41 | "config=s" => \$config, | 46 | "config=s" => \$config, |
42 | "checktype=s" => \$checktype, | 47 | "checktype=s" => \$checktype, |
48 | "explain" => \$explain, | ||
43 | "w|warning=i" => \$warn, | 49 | "w|warning=i" => \$warn, |
44 | "c|critical=i" => \$crit, | 50 | "c|critical=i" => \$crit, |
45 | "t|timeout=i" => \$timeout, | 51 | "t|timeout=i" => \$timeout, |
@@ -127,6 +133,7 @@ sub check_space | |||
127 | &connect; | 133 | &connect; |
128 | 134 | ||
129 | # Most of this sub based on Michael Peppler's check-space.pl | 135 | # Most of this sub based on Michael Peppler's check-space.pl |
136 | # For debugging purposes, more values are collected than needed. | ||
130 | 137 | ||
131 | $dbh->{syb_do_proc_status} = 1; | 138 | $dbh->{syb_do_proc_status} = 1; |
132 | 139 | ||
@@ -148,6 +155,7 @@ sub check_space | |||
148 | } | 155 | } |
149 | else | 156 | else |
150 | { | 157 | { |
158 | # Reserved, data, index, unused | ||
151 | foreach (@$d) | 159 | foreach (@$d) |
152 | { | 160 | { |
153 | s/\D//g; | 161 | s/\D//g; |
@@ -157,10 +165,17 @@ sub check_space | |||
157 | $dbinfo->{reserved} = $d->[0] / 1024; | 165 | $dbinfo->{reserved} = $d->[0] / 1024; |
158 | $dbinfo->{data} = $d->[1] / 1024; | 166 | $dbinfo->{data} = $d->[1] / 1024; |
159 | $dbinfo->{index} = $d->[2] / 1024; | 167 | $dbinfo->{index} = $d->[2] / 1024; |
168 | $dbinfo->{unused} = $d->[3] / 1024; | ||
160 | } | 169 | } |
161 | } | 170 | } |
162 | } while($sth->{syb_more_results}); | 171 | } while($sth->{syb_more_results}); |
163 | 172 | ||
173 | &explain("db size: ".$dbinfo->{size}); | ||
174 | &explain("reserved: ".$dbinfo->{reserved}); | ||
175 | &explain(" data: ".$dbinfo->{data}); | ||
176 | &explain(" index: ".$dbinfo->{index}); | ||
177 | &explain(" unused: ".$dbinfo->{unused}); | ||
178 | |||
164 | # Get the actual device usage from sp_helpdb to get the free log space | 179 | # Get the actual device usage from sp_helpdb to get the free log space |
165 | $sth = $dbh->prepare("sp_helpdb $dbname") | 180 | $sth = $dbh->prepare("sp_helpdb $dbname") |
166 | or &nunk("Failed to call sp_helpdb $dbname on '$dbsvr'"); | 181 | or &nunk("Failed to call sp_helpdb $dbname on '$dbsvr'"); |
@@ -186,27 +201,38 @@ sub check_space | |||
186 | } | 201 | } |
187 | } while($sth->{syb_more_results}); | 202 | } while($sth->{syb_more_results}); |
188 | 203 | ||
204 | &explain("log: ".$dbinfo->{log}); | ||
205 | &explain("logfree: ".$dbinfo->{logfree}); | ||
206 | |||
189 | # Subtract the log size from the database size | 207 | # Subtract the log size from the database size |
190 | $dbinfo->{size} -= $dbinfo->{log}; | 208 | $dbinfo->{realsize} = $dbinfo->{size} - $dbinfo->{log}; |
209 | &explain("realsize (i.e. size - log) = ".$dbinfo->{realsize}); | ||
191 | 210 | ||
192 | # The "reserved" space is free for use by the table that freed it, so | 211 | # The "reserved" space is free for use by the table that freed it, so |
193 | # it is not truly free space. To be safe, our calculation ignores it. | 212 | # it is not truly free space. To be safe, our calculation ignores it. |
194 | my $free = ($dbinfo->{size} - $dbinfo->{reserved}) / $dbinfo->{size}; | 213 | my $free = ($dbinfo->{realsize} - $dbinfo->{reserved})/$dbinfo->{realsize}; |
195 | $free = sprintf("%.2f", $free*100); | 214 | $free = sprintf("%.2f", $free*100); |
196 | 215 | ||
216 | &explain("(realsize-reserved)/realsize = $free%"); | ||
217 | &explain("For safety, this calculation assumes no log space reuse. ". | ||
218 | "Because of this, you may get negative values."); | ||
219 | |||
197 | 220 | ||
198 | if ($free < $crit) | 221 | if ($free < $crit) |
199 | { | 222 | { |
200 | &ncrit("Free space is $free%! (critical threshold is $crit%)"); | 223 | &ncrit("Free space is $free%! (critical threshold is $crit%)". |
224 | "|free_space=$free%"); | ||
201 | } | 225 | } |
202 | 226 | ||
203 | if ($free < $warn) | 227 | if ($free < $warn) |
204 | { | 228 | { |
205 | &nwarn("Free space is $free%! (warning threshold is $warn%)"); | 229 | &nwarn("Free space is $free%! (warning threshold is $warn%)". |
230 | "|free_space=$free%"); | ||
206 | } | 231 | } |
207 | 232 | ||
208 | 233 | ||
209 | &nok("Free space within thresholds ($free% free)"); | 234 | &nok("Free space within thresholds ($free% free)". |
235 | "|free_space=$free%"); | ||
210 | } | 236 | } |
211 | 237 | ||
212 | sub read_config | 238 | sub read_config |
@@ -261,6 +287,7 @@ Mandatory arguments to long options are mandatory for short options too. | |||
261 | -D, --dbname Database name to check. | 287 | -D, --dbname Database name to check. |
262 | --config=FILE Config file (see SECURITY below) | 288 | --config=FILE Config file (see SECURITY below) |
263 | --checktype=TYPE Type of check to run (see TYPEs below) | 289 | --checktype=TYPE Type of check to run (see TYPEs below) |
290 | --explain Explains how we calculated the free space. | ||
264 | -w, --warning Warning threshold, in percent (default 25) | 291 | -w, --warning Warning threshold, in percent (default 25) |
265 | -c, --critical Critical threshold, in percent (default 10) | 292 | -c, --critical Critical threshold, in percent (default 10) |
266 | -t, --timeout Timeout value, in seconds (default 30) | 293 | -t, --timeout Timeout value, in seconds (default 30) |
@@ -290,6 +317,14 @@ _HELP_ | |||
290 | 317 | ||
291 | } | 318 | } |
292 | 319 | ||
320 | sub explain | ||
321 | { | ||
322 | return unless $explain; | ||
323 | |||
324 | my $msg = shift; | ||
325 | print "$msg\n"; | ||
326 | } | ||
327 | |||
293 | 328 | ||
294 | 329 | ||
295 | # Some wrappers.. | 330 | # Some wrappers.. |