~ubuntu-branches/ubuntu/trusty/nagios-plugins-contrib/trusty-proposed

« back to all changes in this revision

Viewing changes to check_mysql_health/check_mysql_health-2.1.8.2/plugins-scripts/check_mysql_health.pl

  • Committer: Package Import Robot
  • Author(s): Bernd Zeimetz
  • Date: 2013-05-21 22:11:50 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130521221150-k5bda5v5euvt7wg9
Tags: 6.20130521
* [e68c82e1] check_raid: do not run hpacucli if cciss_vol_status is available.
* [4a1c57e8] Also support tw-cli as additional name for the 3ware binary.
  Thanks to Dennis Hoppe
* [eb5e1c7c] Add /run/ to the check_libs ignore file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
package main;
 
3
 
 
4
use strict;
 
5
use Getopt::Long qw(:config no_ignore_case);
 
6
use File::Basename;
 
7
use lib dirname($0);
 
8
use Nagios::DBD::MySQL::Server;
 
9
use Nagios::DBD::MySQL::Cluster;
 
10
 
 
11
 
 
12
my %ERRORS=( OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 );
 
13
my %ERRORCODES=( 0 => 'OK', 1 => 'WARNING', 2 => 'CRITICAL', 3 => 'UNKNOWN' );
 
14
 
 
15
use vars qw ($PROGNAME $REVISION $CONTACT $TIMEOUT $STATEFILESDIR $needs_restart %commandline);
 
16
 
 
17
$PROGNAME = "check_mysql_health";
 
18
$REVISION = '$Revision: #PACKAGE_VERSION# $';
 
19
$CONTACT = 'gerhard.lausser@consol.de';
 
20
$TIMEOUT = 60;
 
21
$STATEFILESDIR = '#STATEFILES_DIR#';
 
22
$needs_restart = 0;
 
23
 
 
24
my @modes = (
 
25
  ['server::connectiontime',
 
26
      'connection-time', undef,
 
27
      'Time to connect to the server' ],
 
28
  ['server::uptime',
 
29
      'uptime', undef,
 
30
      'Time the server is running' ],
 
31
  ['server::instance::connectedthreads',
 
32
      'threads-connected', undef,
 
33
      'Number of currently open connections' ],
 
34
  ['server::instance::threadcachehitrate',
 
35
      'threadcache-hitrate', undef,
 
36
      'Hit rate of the thread-cache' ],
 
37
  ['server::instance::createdthreads',
 
38
      'threads-created', undef,
 
39
      'Number of threads created per sec' ],
 
40
  ['server::instance::runningthreads',
 
41
      'threads-running', undef,
 
42
      'Number of currently running threads' ],
 
43
  ['server::instance::cachedthreads',
 
44
      'threads-cached', undef,
 
45
      'Number of currently cached threads' ],
 
46
  ['server::instance::abortedconnects',
 
47
      'connects-aborted', undef,
 
48
      'Number of aborted connections per sec' ],
 
49
  ['server::instance::abortedclients',
 
50
      'clients-aborted', undef,
 
51
      'Number of aborted connections (because the client died) per sec' ],
 
52
  ['server::instance::replication::slavelag',
 
53
      'slave-lag', ['replication-slave-lag'],
 
54
      'Seconds behind master' ],
 
55
  ['server::instance::replication::slaveiorunning',
 
56
      'slave-io-running', ['replication-slave-io-running'],
 
57
      'Slave io running: Yes' ],
 
58
  ['server::instance::replication::slavesqlrunning',
 
59
      'slave-sql-running', ['replication-slave-sql-running'],
 
60
      'Slave sql running: Yes' ],
 
61
  ['server::instance::querycachehitrate',
 
62
      'qcache-hitrate', ['querycache-hitrate'],
 
63
      'Query cache hitrate' ],
 
64
  ['server::instance::querycachelowmemprunes',
 
65
      'qcache-lowmem-prunes', ['querycache-lowmem-prunes'],
 
66
      'Query cache entries pruned because of low memory' ],
 
67
  ['server::instance::myisam::keycache::hitrate',
 
68
      'keycache-hitrate', ['myisam-keycache-hitrate'],
 
69
      'MyISAM key cache hitrate' ],
 
70
  ['server::instance::innodb::bufferpool::hitrate',
 
71
      'bufferpool-hitrate', ['innodb-bufferpool-hitrate'],
 
72
      'InnoDB buffer pool hitrate' ],
 
73
  ['server::instance::innodb::bufferpool::waitfree',
 
74
      'bufferpool-wait-free', ['innodb-bufferpool-wait-free'],
 
75
      'InnoDB buffer pool waits for clean page available' ],
 
76
  ['server::instance::innodb::logwaits',
 
77
      'log-waits', ['innodb-log-waits'],
 
78
      'InnoDB log waits because of a too small log buffer' ],
 
79
  ['server::instance::tablecachehitrate',
 
80
      'tablecache-hitrate', undef,
 
81
      'Table cache hitrate' ],
 
82
  ['server::instance::tablelockcontention',
 
83
      'table-lock-contention', undef,
 
84
      'Table lock contention' ],
 
85
  ['server::instance::tableindexusage',
 
86
      'index-usage', undef,
 
87
      'Usage of indices' ],
 
88
  ['server::instance::tabletmpondisk',
 
89
      'tmp-disk-tables', undef,
 
90
      'Percent of temp tables created on disk' ],
 
91
  ['server::instance::needoptimize',
 
92
      'table-fragmentation', undef,
 
93
      'Show tables which should be optimized' ],
 
94
  ['server::instance::openfiles',
 
95
      'open-files', undef,
 
96
      'Percent of opened files' ],
 
97
  ['server::instance::slowqueries',
 
98
      'slow-queries', undef,
 
99
      'Slow queries' ],
 
100
  ['server::instance::longprocs',
 
101
      'long-running-procs', undef,
 
102
      'long running processes' ],
 
103
  ['cluster::ndbdrunning',
 
104
      'cluster-ndbd-running', undef,
 
105
      'ndnd nodes are up and running' ],
 
106
  ['server::sql',
 
107
      'sql', undef,
 
108
      'any sql command returning a single number' ],
 
109
);
 
110
 
 
111
# rrd data store names are limited to 19 characters
 
112
my %labels = (
 
113
  bufferpool_hitrate => {
 
114
    groundwork => 'bp_hitrate',
 
115
  },
 
116
  bufferpool_hitrate_now => {
 
117
    groundwork => 'bp_hitrate_now',
 
118
  },
 
119
  bufferpool_free_waits_rate => {
 
120
    groundwork => 'bp_freewaits',
 
121
  },
 
122
  innodb_log_waits_rate => {
 
123
    groundwork => 'inno_log_waits',
 
124
  },
 
125
  keycache_hitrate => {
 
126
    groundwork => 'kc_hitrate',
 
127
  },
 
128
  keycache_hitrate_now => {
 
129
    groundwork => 'kc_hitrate_now',
 
130
  },
 
131
  threads_created_per_sec => {
 
132
    groundwork => 'thrds_creat_per_s',
 
133
  },
 
134
  connects_aborted_per_sec => {
 
135
    groundwork => 'conn_abrt_per_s',
 
136
  },
 
137
  clients_aborted_per_sec => {
 
138
    groundwork => 'clnt_abrt_per_s',
 
139
  },
 
140
  thread_cache_hitrate => {
 
141
    groundwork => 'tc_hitrate',
 
142
  },
 
143
  thread_cache_hitrate_now => {
 
144
    groundwork => 'tc_hitrate_now',
 
145
  },
 
146
  qcache_lowmem_prunes_rate => {
 
147
    groundwork => 'qc_lowm_prnsrate',
 
148
  },
 
149
  slow_queries_rate => {
 
150
    groundwork => 'slow_q_rate',
 
151
  },
 
152
  tablecache_hitrate => {
 
153
    groundwork => 'tac_hitrate',
 
154
  },
 
155
  tablecache_fillrate => {
 
156
    groundwork => 'tac_fillrate',
 
157
  },
 
158
  tablelock_contention => {
 
159
    groundwork => 'tl_contention',
 
160
  },
 
161
  tablelock_contention_now => {
 
162
    groundwork => 'tl_contention_now',
 
163
  },
 
164
  pct_tmp_table_on_disk => {
 
165
    groundwork => 'tmptab_on_disk',
 
166
  },
 
167
  pct_tmp_table_on_disk_now => {
 
168
    groundwork => 'tmptab_on_disk_now',
 
169
  },
 
170
);
 
171
 
 
172
sub print_usage () {
 
173
  print <<EOUS;
 
174
  Usage:
 
175
    $PROGNAME [-v] [-t <timeout>] [[--hostname <hostname>] 
 
176
        [--port <port> | --socket <socket>]
 
177
        --username <username> --password <password>] --mode <mode>
 
178
        [--method mysql]
 
179
    $PROGNAME [-h | --help]
 
180
    $PROGNAME [-V | --version]
 
181
 
 
182
  Options:
 
183
    --hostname
 
184
       the database server's hostname
 
185
    --port
 
186
       the database's port. (default: 3306)
 
187
    --socket
 
188
       the database's unix socket.
 
189
    --username
 
190
       the mysql db user
 
191
    --password
 
192
       the mysql db user's password
 
193
    --database
 
194
       the database's name. (default: information_schema)
 
195
    --warning
 
196
       the warning range
 
197
    --critical
 
198
       the critical range
 
199
    --mode
 
200
       the mode of the plugin. select one of the following keywords:
 
201
EOUS
 
202
  my $longest = length ((reverse sort {length $a <=> length $b} map { $_->[1] } @modes)[0]);
 
203
  my $format = "       %-".
 
204
  (length ((reverse sort {length $a <=> length $b} map { $_->[1] } @modes)[0])).
 
205
  "s\t(%s)\n";
 
206
  foreach (@modes) {
 
207
    printf $format, $_->[1], $_->[3];
 
208
  }
 
209
  printf "\n";
 
210
  print <<EOUS;
 
211
    --name
 
212
       the name of something that needs to be further specified,
 
213
       currently only used for sql statements
 
214
    --name2
 
215
       if name is a sql statement, this statement would appear in
 
216
       the output and the performance data. This can be ugly, so 
 
217
       name2 can be used to appear instead.
 
218
    --regexp
 
219
       if this parameter is used, name will be interpreted as a 
 
220
       regular expression.
 
221
    --units
 
222
       one of %, KB, MB, GB. This is used for a better output of mode=sql
 
223
       and for specifying thresholds for mode=tablespace-free
 
224
    --labelformat
 
225
       one of pnp4nagios (which is the default) or groundwork.
 
226
       It is used to shorten performance data labels to 19 characters.
 
227
 
 
228
  In mode sql you can url-encode the statement so you will not have to mess
 
229
  around with special characters in your Nagios service definitions.
 
230
  Instead of 
 
231
  --name="select count(*) from v\$session where status = 'ACTIVE'"
 
232
  you can say 
 
233
  --name=select%20count%28%2A%29%20from%20v%24session%20where%20status%20%3D%20%27ACTIVE%27
 
234
  For your convenience you can call check_mysql_health with the --mode encode
 
235
  option and it will encode the standard input.
 
236
 
 
237
  You can find the full documentation at 
 
238
  http://www.consol.de/opensource/nagios/check-mysql-health
 
239
 
 
240
EOUS
 
241
  
 
242
}
 
243
 
 
244
sub print_help () {
 
245
  print "Copyright (c) 2009 Gerhard Lausser\n\n";
 
246
  print "\n";
 
247
  print "  Check various parameters of MySQL databases \n";
 
248
  print "\n";
 
249
  print_usage();
 
250
  support();
 
251
}
 
252
 
 
253
 
 
254
sub print_revision ($$) {
 
255
  my $commandName = shift;
 
256
  my $pluginRevision = shift;
 
257
  $pluginRevision =~ s/^\$Revision: //;
 
258
  $pluginRevision =~ s/ \$\s*$//;
 
259
  print "$commandName ($pluginRevision)\n";
 
260
  print "This nagios plugin comes with ABSOLUTELY NO WARRANTY. You may redistribute\ncopies of this plugin under the terms of the GNU General Public License.\n";
 
261
}
 
262
 
 
263
sub support () {
 
264
  my $support='Send email to gerhard.lausser@consol.de if you have questions\nregarding use of this software. \nPlease include version information with all correspondence (when possible,\nuse output from the --version option of the plugin itself).\n';
 
265
  $support =~ s/@/\@/g;
 
266
  $support =~ s/\\n/\n/g;
 
267
  print $support;
 
268
}
 
269
 
 
270
sub contact_author ($$) {
 
271
  my $item = shift;
 
272
  my $strangepattern = shift;
 
273
  if ($commandline{verbose}) {
 
274
    printf STDERR
 
275
        "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n".
 
276
        "You found a line which is not recognized by %s\n".
 
277
        "This means, certain components of your system cannot be checked.\n".
 
278
        "Please contact the author %s and\nsend him the following output:\n\n".
 
279
        "%s /%s/\n\nThank you!\n".
 
280
        "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n",
 
281
            $PROGNAME, $CONTACT, $item, $strangepattern;
 
282
  }
 
283
}
 
284
 
 
285
%commandline = ();
 
286
my @params = (
 
287
    "timeout|t=i",
 
288
    "version|V",
 
289
    "help|h",
 
290
    "verbose|v",
 
291
    "debug|d",
 
292
    "hostname|H=s",
 
293
    "database=s",
 
294
    "port|P=s",
 
295
    "socket|S=s",
 
296
    "username|u=s",
 
297
    "password|p=s",
 
298
    "mycnf=s",
 
299
    "mycnfgroup=s",
 
300
    "mode|m=s",
 
301
    "name=s",
 
302
    "name2=s",
 
303
    "regexp",
 
304
    "perfdata",
 
305
    "warning=s",
 
306
    "critical=s",
 
307
    "dbthresholds:s",
 
308
    "absolute|a",
 
309
    "environment|e=s%",
 
310
    "method=s",
 
311
    "runas|r=s",
 
312
    "scream",
 
313
    "shell",
 
314
    "eyecandy",
 
315
    "encode",
 
316
    "units=s",
 
317
    "lookback=i",
 
318
    "3",
 
319
    "statefilesdir=s",
 
320
    "with-mymodules-dyn-dir=s",
 
321
    "report=s",
 
322
    "labelformat=s",
 
323
    "extra-opts:s");
 
324
 
 
325
if (! GetOptions(\%commandline, @params)) {
 
326
  print_help();
 
327
  exit $ERRORS{UNKNOWN};
 
328
}
 
329
 
 
330
if (exists $commandline{'extra-opts'}) {
 
331
  # read the extra file and overwrite other parameters
 
332
  my $extras = Extraopts->new(file => $commandline{'extra-opts'}, commandline =>
 
333
 \%commandline);
 
334
  if (! $extras->is_valid()) {
 
335
    printf "extra-opts are not valid: %s\n", $extras->{errors};
 
336
    exit $ERRORS{UNKNOWN};
 
337
  } else {
 
338
    $extras->overwrite();
 
339
  }
 
340
}
 
341
 
 
342
if (exists $commandline{version}) {
 
343
  print_revision($PROGNAME, $REVISION);
 
344
  exit $ERRORS{OK};
 
345
}
 
346
 
 
347
if (exists $commandline{help}) {
 
348
  print_help();
 
349
  exit $ERRORS{OK};
 
350
} elsif (! exists $commandline{mode}) {
 
351
  printf "Please select a mode\n";
 
352
  print_help();
 
353
  exit $ERRORS{OK};
 
354
}
 
355
 
 
356
if ($commandline{mode} eq "encode") {
 
357
  my $input = <>;
 
358
  chomp $input;
 
359
  $input =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
 
360
  printf "%s\n", $input;
 
361
  exit $ERRORS{OK};
 
362
}
 
363
 
 
364
if (exists $commandline{3}) {
 
365
  $ENV{NRPE_MULTILINESUPPORT} = 1;
 
366
}
 
367
 
 
368
if (exists $commandline{timeout}) {
 
369
  $TIMEOUT = $commandline{timeout};
 
370
}
 
371
 
 
372
if (exists $commandline{verbose}) {
 
373
  $DBD::MySQL::Server::verbose = exists $commandline{verbose};
 
374
}
 
375
 
 
376
if (exists $commandline{scream}) {
 
377
#  $DBD::MySQL::Server::hysterical = exists $commandline{scream};
 
378
}
 
379
 
 
380
if (exists $commandline{method}) {
 
381
  # snmp or mysql cmdline
 
382
} else {
 
383
  $commandline{method} = "dbi";
 
384
}
 
385
 
 
386
if (exists $commandline{report}) {
 
387
  # short, long, html
 
388
} else {
 
389
  $commandline{report} = "long";
 
390
}
 
391
 
 
392
if (exists $commandline{labelformat}) {
 
393
  # groundwork
 
394
} else {
 
395
  $commandline{labelformat} = "pnp4nagios";
 
396
}
 
397
 
 
398
if (exists $commandline{'with-mymodules-dyn-dir'}) {
 
399
  $DBD::MySQL::Server::my_modules_dyn_dir = $commandline{'with-mymodules-dyn-dir'};
 
400
} else {
 
401
  $DBD::MySQL::Server::my_modules_dyn_dir = '#MYMODULES_DYN_DIR#';
 
402
}
 
403
 
 
404
if (exists $commandline{environment}) {
 
405
  # if the desired environment variable values are different from
 
406
  # the environment of this running script, then a restart is necessary.
 
407
  # because setting $ENV does _not_ change the environment of the running script.
 
408
  foreach (keys %{$commandline{environment}}) {
 
409
    if ((! $ENV{$_}) || ($ENV{$_} ne $commandline{environment}->{$_})) {
 
410
      $needs_restart = 1;
 
411
      $ENV{$_} = $commandline{environment}->{$_};
 
412
      printf STDERR "new %s=%s forces restart\n", $_, $ENV{$_} 
 
413
          if $DBD::MySQL::Server::verbose;
 
414
    }
 
415
  }
 
416
  # e.g. called with --runas dbnagio. shlib_path environment variable is stripped
 
417
  # during the sudo.
 
418
  # so the perl interpreter starts without a shlib_path. but --runas cares for
 
419
  # a --environment shlib_path=...
 
420
  # so setting the environment variable in the code above and restarting the 
 
421
  # perl interpreter will help it find shared libs
 
422
}
 
423
 
 
424
if (exists $commandline{runas}) {
 
425
  # remove the runas parameter
 
426
  # exec sudo $0 ... the remaining parameters
 
427
  $needs_restart = 1;
 
428
  # if the calling script has a path for shared libs and there is no --environment
 
429
  # parameter then the called script surely needs the variable too.
 
430
  foreach my $important_env (qw(LD_LIBRARY_PATH SHLIB_PATH 
 
431
      ORACLE_HOME TNS_ADMIN ORA_NLS ORA_NLS33 ORA_NLS10)) {
 
432
    if ($ENV{$important_env} && ! scalar(grep { /^$important_env=/ } 
 
433
        keys %{$commandline{environment}})) {
 
434
      $commandline{environment}->{$important_env} = $ENV{$important_env};
 
435
      printf STDERR "add important --environment %s=%s\n", 
 
436
          $important_env, $ENV{$important_env} if $DBD::MySQL::Server::verbose;
 
437
    }
 
438
  }
 
439
}
 
440
 
 
441
if ($needs_restart) {
 
442
  my @newargv = ();
 
443
  my $runas = undef;
 
444
  if (exists $commandline{runas}) {
 
445
    $runas = $commandline{runas};
 
446
    delete $commandline{runas};
 
447
  }
 
448
  foreach my $option (keys %commandline) {
 
449
    if (grep { /^$option/ && /=/ } @params) {
 
450
      if (ref ($commandline{$option}) eq "HASH") {
 
451
        foreach (keys %{$commandline{$option}}) {
 
452
          push(@newargv, sprintf "--%s", $option);
 
453
          push(@newargv, sprintf "%s=%s", $_, $commandline{$option}->{$_});
 
454
        }
 
455
      } else {
 
456
        push(@newargv, sprintf "--%s", $option);
 
457
        push(@newargv, sprintf "%s", $commandline{$option});
 
458
      }
 
459
    } else {
 
460
      push(@newargv, sprintf "--%s", $option);
 
461
    }
 
462
  }
 
463
  if ($runas) {
 
464
    exec "sudo", "-S", "-u", $runas, $0, @newargv;
 
465
  } else {
 
466
    exec $0, @newargv;  
 
467
    # this makes sure that even a SHLIB or LD_LIBRARY_PATH are set correctly
 
468
    # when the perl interpreter starts. Setting them during runtime does not
 
469
    # help loading e.g. libclntsh.so
 
470
  }
 
471
  exit;
 
472
}
 
473
 
 
474
if (exists $commandline{shell}) {
 
475
  # forget what you see here.
 
476
  system("/bin/sh");
 
477
}
 
478
 
 
479
if (! exists $commandline{statefilesdir}) {
 
480
  if (exists $ENV{OMD_ROOT}) {
 
481
    $commandline{statefilesdir} = $ENV{OMD_ROOT}."/var/tmp/check_mysql_health";
 
482
  } else {
 
483
    $commandline{statefilesdir} = $STATEFILESDIR;
 
484
  }
 
485
}
 
486
 
 
487
if (exists $commandline{name}) {
 
488
  if ($^O =~ /MSWin/ && $commandline{name} =~ /^'(.*)'$/) {
 
489
    # putting arguments in single ticks under Windows CMD leaves the ' intact
 
490
    # we remove them
 
491
    $commandline{name} = $1;
 
492
  }
 
493
  # objects can be encoded like an url
 
494
  # with s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
 
495
  if (($commandline{mode} ne "sql") || 
 
496
      (($commandline{mode} eq "sql") &&
 
497
       ($commandline{name} =~ /select%20/i))) { # protect ... like '%cac%' ... from decoding
 
498
    $commandline{name} =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
 
499
  }
 
500
  if ($commandline{name} =~ /^0$/) {
 
501
    # without this, $params{selectname} would be treated like undef
 
502
    $commandline{name} = "00";
 
503
  } 
 
504
}
 
505
 
 
506
$SIG{'ALRM'} = sub {
 
507
  printf "UNKNOWN - %s timed out after %d seconds\n", $PROGNAME, $TIMEOUT;
 
508
  exit $ERRORS{UNKNOWN};
 
509
};
 
510
alarm($TIMEOUT);
 
511
 
 
512
my $nagios_level = $ERRORS{UNKNOWN};
 
513
my $nagios_message = "";
 
514
my $perfdata = "";
 
515
if ($commandline{mode} =~ /^my-([^\-.]+)/) {
 
516
  my $param = $commandline{mode};
 
517
  $param =~ s/\-/::/g;
 
518
  push(@modes, [$param, $commandline{mode}, undef, 'my extension']);
 
519
} elsif ((! grep { $commandline{mode} eq $_ } map { $_->[1] } @modes) &&
 
520
    (! grep { $commandline{mode} eq $_ } map { defined $_->[2] ? @{$_->[2]} : () } @modes)) {
 
521
  printf "UNKNOWN - mode %s\n", $commandline{mode};
 
522
  print_usage();
 
523
  exit 3;
 
524
}
 
525
my %params = (
 
526
    timeout => $TIMEOUT,
 
527
    mode => (
 
528
        map { $_->[0] }
 
529
        grep {
 
530
           ($commandline{mode} eq $_->[1]) ||
 
531
           ( defined $_->[2] && grep { $commandline{mode} eq $_ } @{$_->[2]})
 
532
        } @modes
 
533
    )[0],
 
534
    cmdlinemode => $commandline{mode},
 
535
    method => $commandline{method} ||
 
536
        $ENV{NAGIOS__SERVICEMYSQL_METH} ||
 
537
        $ENV{NAGIOS__HOSTMYSQL_METH} || 'dbi',
 
538
    hostname => $commandline{hostname} || 
 
539
        $ENV{NAGIOS__SERVICEMYSQL_HOST} ||
 
540
        $ENV{NAGIOS__HOSTMYSQL_HOST} || 'localhost',
 
541
    database => $commandline{database} || 
 
542
        $ENV{NAGIOS__SERVICEMYSQL_DATABASE} ||
 
543
        $ENV{NAGIOS__HOSTMYSQL_DATABASE} || 'information_schema',
 
544
    port => $commandline{port}  || (($commandline{mode} =~ /^cluster/) ?
 
545
        ($ENV{NAGIOS__SERVICENDBMGM_PORT} || $ENV{NAGIOS__HOSTNDBMGM_PORT} || 1186) :
 
546
        ($ENV{NAGIOS__SERVICEMYSQL_PORT} || $ENV{NAGIOS__HOSTMYSQL_PORT} || 3306)),
 
547
    socket => $commandline{socket}  || 
 
548
        $ENV{NAGIOS__SERVICEMYSQL_SOCKET} ||
 
549
        $ENV{NAGIOS__HOSTMYSQL_SOCKET},
 
550
    username => $commandline{username} || 
 
551
        $ENV{NAGIOS__SERVICEMYSQL_USER} ||
 
552
        $ENV{NAGIOS__HOSTMYSQL_USER},
 
553
    password => $commandline{password} || 
 
554
        $ENV{NAGIOS__SERVICEMYSQL_PASS} ||
 
555
        $ENV{NAGIOS__HOSTMYSQL_PASS},
 
556
    mycnf => $commandline{mycnf} || 
 
557
        $ENV{NAGIOS__SERVICEMYSQL_MYCNF} ||
 
558
        $ENV{NAGIOS__HOSTMYSQL_MYCNF},
 
559
    mycnfgroup => $commandline{mycnfgroup} || 
 
560
        $ENV{NAGIOS__SERVICEMYSQL_MYCNFGROUP} ||
 
561
        $ENV{NAGIOS__HOSTMYSQL_MYCNFGROUP},
 
562
    warningrange => $commandline{warning},
 
563
    criticalrange => $commandline{critical},
 
564
    dbthresholds => $commandline{dbthresholds},
 
565
    absolute => $commandline{absolute},
 
566
    lookback => $commandline{lookback},
 
567
    selectname => $commandline{name} || $commandline{tablespace} || $commandline{datafile},
 
568
    regexp => $commandline{regexp},
 
569
    name => $commandline{name},
 
570
    name2 => $commandline{name2} || $commandline{name},
 
571
    units => $commandline{units},
 
572
    lookback => $commandline{lookback} || 0,
 
573
    eyecandy => $commandline{eyecandy},
 
574
    statefilesdir => $commandline{statefilesdir},
 
575
    verbose => $commandline{verbose},
 
576
    report => $commandline{report},
 
577
    labelformat => $commandline{labelformat},
 
578
);
 
579
 
 
580
my $server = undef;
 
581
my $cluster = undef;
 
582
 
 
583
if ($params{mode} =~ /^(server|my)/) {
 
584
  $server = DBD::MySQL::Server->new(%params);
 
585
  $server->nagios(%params);
 
586
  $server->calculate_result(\%labels);
 
587
  $nagios_message = $server->{nagios_message};
 
588
  $nagios_level = $server->{nagios_level};
 
589
  $perfdata = $server->{perfdata};
 
590
} elsif ($params{mode} =~ /^cluster/) {
 
591
  $cluster = DBD::MySQL::Cluster->new(%params);
 
592
  $cluster->nagios(%params);
 
593
  $cluster->calculate_result(\%labels);
 
594
  $nagios_message = $cluster->{nagios_message};
 
595
  $nagios_level = $cluster->{nagios_level};
 
596
  $perfdata = $cluster->{perfdata};
 
597
}
 
598
 
 
599
printf "%s - %s", $ERRORCODES{$nagios_level}, $nagios_message;
 
600
printf " | %s", $perfdata if $perfdata;
 
601
printf "\n";
 
602
exit $nagios_level;
 
603
 
 
604
 
 
605
__END__
 
606
 
 
607