check_mssql_health
check_mssql_health copied to clipboard
Class MyDatabases is not a subclass of Monitoring::GLPlugin
Hi,
Since I updated to version 2.6.4.12 the my-databases-dbspace mode is not working anymore, this is the error:
UNKNOWN - Class MyDatabases is not a subclass of Monitoring::GLPlugin
Monitoring::GLPlugin is already installed:
# cpan install Monitoring::GLPlugin
CPAN: Storable loaded ok (v2.39)
Reading '/root/.cpan/Metadata'
Database was generated on Tue, 19 Dec 2017 05:17:03 GMT
CPAN: Module::CoreList loaded ok (v2.25)
Monitoring::GLPlugin is up to date (2.3).
Any idea how to fix it? I googled but didn't find a solution yet..
Hi,
can you mail me your submodule to [email protected] mailto:[email protected] ?
Gerhard
Von: bunghi [mailto:[email protected]] Gesendet: Dienstag, 19. Dezember 2017 09:36 An: lausser/check_mssql_health [email protected] Cc: Subscribed [email protected] Betreff: [lausser/check_mssql_health] Class MyDatabases is not a subclass of Monitoring::GLPlugin (#31)
Hi,
Since I updated to version 2.6.4.12 the my-databases-dbspace mode is not working anymore, this is the error:
UNKNOWN - Class MyDatabases is not a subclass of Monitoring::GLPlugin
Any idea how to fix it? I googled but didn't find a solution yet..
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lausser/check_mssql_health/issues/31 , or mute the thread https://github.com/notifications/unsubscribe-auth/AAMJOIM9BVm01D6I8V0dWCupmGiarxB6ks5tB3VYgaJpZM4RGmvH .
Just sent you an email.
Now i see what's wrong. You updated from a very, very old version. With 2.0 check_mssql_health was completely rewritten and the "api" for my-modules changed. If fact i added some compatibility-routines which should guarantee that also old my-modules can be used, but it does not work with your code. Instead of putitng time in this, i simply changed your module to the new format.
package MyDatabases;
our @ISA = qw(Monitoring::GLPlugin::DB);
# zur Umrechnung in MB
my %tomb = (
'KB' => 1024,
'MB' => 1,
'GB' => 1/1024,
);
sub init {
my $self = shift;
if ($self->mode =~ /my::databases::dbspace/) {
my @dbs = $self->fetchall_array(q{SELECT name FROM master.sys.databases});
my %stats;
my $cmd = "EXEC sp_spaceused";
foreach (@dbs) {
my @dbstat = $self->fetchall_array("USE \"" . $_->[0] . "\" " . $cmd);
$stats{$_->[0]} = {
'dbsize' => $dbstat[0][1],
'unallocated' => $dbstat[0][2],
};
}
$self->{dbstat} = \%stats;
if (keys(%{$self->{dbstat}})) {
while ((my $key, $value) = each(%{$self->{dbstat}})) {
if ($self->opts->regexp) {
next if $key !~ /$self->opts->regexp/;
} elsif ($self->opts->name) {
next if lc $key ne lc $self->opts->name;
}
$value->{'dbsize'} =~ m/(\d+\.?\d*?) (GB|MB|KB)/;
my $totalmb = $1 / $tomb{$2};
$value->{'unallocated'} =~ m/(\d+\.?\d*?) (GB|MB|KB)/;
my $unusedmb = $1 / $tomb{$2};
my $usedmb = $totalmb - $unusedmb;
my $usedpct = ($usedmb / $totalmb) * 100;
$self->add_info(
#$self->check_thresholds($_->[2],80,90),
sprintf("DB \"%s\": %0.2f%% used (%0.2f of %0.2f MB)",
$key, $usedpct, $usedmb, $totalmb)
);
$self->add_ok();
$self->add_perfdata(
label => $key."_mbused",
value => $usedmb,
min => 0,
max => $totalmb,
uom => 'MB',
);
$self->add_perfdata(
label => $key."_mbtotal",
value => $totalmb,
uom => 'MB',
);
}
} else {
$self->add_unknown("No database size information found. ");
}
}
}
There is no more nagios method, only a init(). The fetch*-database-methods belong to $self, no longer to a params{handle}. add_info(takes a string) which is output when you run the plugin with -v. The same string will be used in add_ok, add_warning,... Also, add_perdata takes label,value,warn,crit,min,max,uom instead of a complete string.
Gerhard
Hi Gerhard,
Thanks for your help and time. I still get the same error after replacing the module:
[root@~]# /usr/local/nagios/libexec/check_mssql_health --server host--username user --password='xxxxx' -t 180 --mode my-databases-dbspace --name='^(?!._BK_MQDE01.SPDB0._IB.)' --regexp UNKNOWN - Class MyDatabases is not a subclass of Monitoring::GLPlugin
[root@~]# /usr/local/nagios/libexec/check_mssql_health -V check_mssql_health $Revision: 2.6.4.12 $ [http://labs.consol.de/nagios/check_mss_health]
[root@~]# ll /usr/local/nagios/libexec/conf/*pm -rwxr-xr-x 1 root root 1840 Dec 19 14:58 /usr/local/nagios/libexec/conf/CheckMSSQLHealthExt1.pm lrwxrwxrwx 1 root root 45 Dec 19 08:25 /usr/local/nagios/libexec/conf/GLPlugin.pm -> /usr/local/share/perl5/Monitoring/GLPlugin.pm
Any idea?
--with-mymodules-dyn-dir /usr/local/nagios/libexec/conf should do the trick.
I already tried that:
[root@mqde01icingat01 check_mssql_health-2.6.4.12]# /usr/local/nagios/libexec/check_mssql_health -v --server host--username user --password='pass' -t 180 --mode my-databases-dbspace --name='^(?!._BK_MQDE01.SPDB0._IB.)' --regexp --with-mymodules-dyn-dir /usr/local/nagios/libexec/conf UNKNOWN - Class MyDatabases is not a subclass of Monitoring::GLPlugin
[root@~]# ll /usr/local/nagios/libexec/conf/ total 8 -rwxr-xr-x 1 root root 1840 Dec 19 14:58 CheckMSSQLHealthExt1.pm -rwxr-xr-x 1 root root 1905 Dec 19 14:57 CheckMSSQLHealthExt1.pm.old lrwxrwxrwx 1 root root 45 Dec 19 08:25 GLPlugin.pm -> /usr/local/share/perl5/Monitoring/GLPlugin.pm
mv CheckMSSQLHealthExt1.pm CheckMssqlHealthExt1.pm The naming became more strict.
Hi again,
Now it works but the output is incomplete and I don’t have perfdata anymore:
[root@libexec]# /usr/local/nagios/libexec/check_mssql_health --server host--username user --password='pass' -t 180 --mode my-databases-dbspace --name='^(?!._BK_MQDE01.SPDB0._IB.)' --regexp --with-mymodules-dyn-dir /usr/local/nagios/libexec OK [root@libexec]#
I'm reopening this issue, since ugpraded to script version 2.6.4.15 I have the same problem..
'/usr/lib/nagios/plugins/check_mssql_health' '--commit' '--mode' 'my-databases-dbspace' '--name' '^(?!.*_BK_MQDE01.SPDB0._IB.*)' '--password' 'xxx' '--regexp' '--report' 'short' '--server' 'xxx' '--username' 'xxx' --with-mymodules-dyn-dir /usr/lib/nagios/plugins
UNKNOWN - Class MyDatabases is not a subclass of Monitoring::GLPlugin
After some investigations i found this difference between previous version and this one:
$ diff /usr/lib/nagios/plugins/check_mssql_health /usr/lib/nagios/plugins/check_mssql_health.old | grep pm
< foreach my $extmod (glob $libpath."/".$plugin_name."*.pm") {
> foreach my $extmod (glob $libpath."/CheckMSSQLHealth*.pm") {
Then I have just changed that line with this one:
foreach my $extmod (glob $libpath."/CheckMSSQLHealthExt1.pm") {
Now it finds the module but there is an error:
Can't call method "fetchall_array" on an undefined value at /usr/lib/nagios/plugins/CheckMSSQLHealthExt1.pm line 13.
And this is the content of the file CheckMSSQLHealthExt1.pm:
1 package MyDatabases;
2 our @ISA = qw(DBD::MSSQL::Server);
3 # zur Umrechnung in MB
4 my %tomb = (
5 'KB' => 1024,
6 'MB' => 1,
7 'GB' => 1/1024,
8 );
9 sub init {
10 my $self = shift;
11 my %params = @_;
12 if ($params{mode} =~ /my::databases::dbspace/) {
13 my @dbs = $params{handle}->fetchall_array(q{
14 SELECT name FROM master.sys.databases
15 });
16 my %stats;
17 my $cmd = "EXEC sp_spaceused";
18 foreach (@dbs) {
19 my @dbstat = $params{handle}->fetchall_array("USE " . $_->[0] . " " . $cmd);
20 $stats{$_->[0]} = {
21 'dbsize' => $dbstat[0][1],
22 'unallocated' => $dbstat[0][2],
23 };
24 };
25 $self->{dbstat} = \%stats;
26 }
27 }
28 sub nagios {
29 if ($params{mode} =~ /my::databases::dbspace/) {
30 if (keys(%{$self->{dbstat}})) {
31 while ((my $key, $value) = each(%{$self->{dbstat}})) {
32 if ($params{regexp}) {
33 next if $params{selectname} && $key !~ /$params{selectname}/;
34 } else {
35 next if $params{selectname} && lc $params{selectname} ne lc $key;
36 }
37 $value->{'dbsize'} =~ m/(\d+\.?\d*?) (GB|MB|KB)/;
38 my $totalmb = $1 / $tomb{$2};
39 $value->{'unallocated'} =~ m/(\d+\.?\d*?) (GB|MB|KB)/;
40 my $unusedmb = $1 / $tomb{$2};
41 my $usedmb = $totalmb - $unusedmb;
42 my $usedpct = ($usedmb / $totalmb) * 100;
43 $self->add_nagios(
44 #$self->check_thresholds($_->[2],80,90),
45 0,sprintf("DB \"%s\": %0.2f%% used (%0.2f of %0.2f MB)",
46 $key, $usedpct, $usedmb, $totalmb)
47 );
48 $self->add_perfdata(sprintf("%s=%0.2fMB;;;0;%0.2f",
49 $key."_mbused", $usedmb,$totalmb));
50 $self->add_perfdata(sprintf("%s=%0.2fMB;;;;",
51 $key."_mbtotal", $totalmb));
52 }
53 } else { $self->add_nagios_unknown("No database size information found. ")}
54 }
55 }
Any idea how to fix it?