Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class MyDatabases is not a subclass of Monitoring::GLPlugin #31

Open
bunghi opened this issue Dec 19, 2017 · 10 comments
Open

Class MyDatabases is not a subclass of Monitoring::GLPlugin #31

bunghi opened this issue Dec 19, 2017 · 10 comments

Comments

@bunghi
Copy link

bunghi commented Dec 19, 2017

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..

@lausser
Copy link
Owner

lausser commented Dec 19, 2017 via email

@bunghi
Copy link
Author

bunghi commented Dec 19, 2017

Just sent you an email.

@lausser
Copy link
Owner

lausser commented Dec 19, 2017

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

@bunghi
Copy link
Author

bunghi commented Dec 19, 2017 via email

@lausser
Copy link
Owner

lausser commented Dec 19, 2017

--with-mymodules-dyn-dir /usr/local/nagios/libexec/conf
should do the trick.

@bunghi
Copy link
Author

bunghi commented Dec 19, 2017 via email

@lausser
Copy link
Owner

lausser commented Dec 19, 2017

mv CheckMSSQLHealthExt1.pm CheckMssqlHealthExt1.pm
The naming became more strict.

@bunghi
Copy link
Author

bunghi commented Dec 20, 2017 via email

@bunghi
Copy link
Author

bunghi commented Sep 17, 2019

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

@bunghi
Copy link
Author

bunghi commented Sep 17, 2019

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants