Announcement

Collapse
No announcement yet.

plugin for monitoring several hosts with SNMP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • plugin for monitoring several hosts with SNMP

    Hi,

    I have two servers who share access to 4 "ressources" and I try to develop a plugin to get the results of 4 OID SNMP (attached to those resources) from this two in order to add the results but i can't figure out how to declare it.
    I try to use perl centreon plugins snmp but i am forced to use a parameter --hostname and every time it check only one host.
    I'm a beginner in Perl and i don't fully understand the mecanisms of object.

    this is my plugin.pm
    Code:
    package apps::mediant1000::plugin;
    
    use strict;
    use warnings;
    use base qw(centreon::plugins::script_snmp);
    
    sub new {
          my ($class, %options) = @_;
          my $self = $class->SUPER::new(package => __PACKAGE__, %options);
          bless $self, $class;
          $self->{version} = '0.1';
          %{$self->{modes}} = (
                          'connected-users'    => 'apps::mediant1000::mode::connectedusers',
                           );
          return $self;
    }
    
    1;
    and this is the associate mode:
    Code:
    package apps::mediant1000::mode::connectedusers;
    
    use strict;
    use warnings;
    use base qw(centreon::plugins::mode);
    use base qw(centreon::plugins::script_snmp);
    use Data::Dumper;
    
    sub new {
          my ($class, %options) = @_;
          my $self = $class->SUPER::new(package => __PACKAGE__, %options);
          bless $self, $class;
          $self->{version} = '1.0';
          $options{options}->add_options(arguments =>
                                  {
                                    "warning:s" => { name => 'warning', default => '0:20'  },
                                    "critical:s" => { name => 'critical', default => '0:20'  },
                                    "first-gateway:s" => { name => 'gateway1' },
                                    "second-gateway:s" => { name => 'gateway2' },
                                   });
          return $self;
    }
    
    sub check_options {
          my ($self, %options) = @_;
          $self->SUPER::init(%options);
          if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0)
              {
                  $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
                  $self->{output}->option_exit();
              }
          if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0)
             {
                 $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
                 $self->{output}->option_exit();
             }
    }
    
    sub run {
          my $oid_first_T2 = '.1.3.6.1.4.1.5003.10.10.2.21.1.3.0.0';
          my $oid_Second_T2 ='.1.3.6.1.4.1.5003.10.10.2.21.1.3.1.0';
          my $oid_third_T2 = '.1.3.6.1.4.1.5003.10.10.2.21.1.3.2.0';
          my $oid_fourth_T2 = '.1.3.6.1.4.1.5003.10.10.2.21.1.3.3.0';
          my $oids = [$oid_first_T2, $oid_Second_T2, $oid_third_T2, $oid_fourth_T2];
          my ($self, %options) = @_;
          my @hosts = ( $self->{option_results}->{gateway1},$self->{option_results}->{gateway2});
          my $result;
          foreach my $host (@hosts)
          {
             ($self, %options) = @_;
             $options{snmp}->{snmp_params}->{DestHost} = $host;
             $options{snmp}->{session}->{DestHost} = $host.':161';
             $self->{snmp} = $options{snmp};
             $self->{snmp_port} = $self->{snmp}->get_port();
            $result = 0;
            $result = $self->{snmp}->get_leef(oids => $oids, nothing_quit => 1);
            print Dumper($result);
            }
          $self->{output}->display();
          $self->{output}->exit();
    }
    
    1;
    I need to check gateway1 and gateway2 so I try to specify manually in the snmp options of my variable $self but it doesn't work.

    I think it's a misunderstanding of how perl and plugins snmp works... but i can't figure out where...
    Maybe i have to rewrite the constructor new in order to "change" the hostname of my object but how can i do that?

    Could you help me?
Working...
X