#! /usr/bin/perl -w
# nagios: -epn

package Monitoring::GLPlugin::Commandline::Extraopts;
use strict;
use File::Basename;
use strict;

sub new {
  my $class = shift;
  my %params = @_;
  my $self = {
    file => $params{file},
    commandline => $params{commandline},
    config => {},
    section => 'default_no_section',
  };
  bless $self, $class;
  $self->prepare_file_and_section();
  $self->init();
  return $self;
}

sub prepare_file_and_section {
  my $self = shift;
  if (! defined $self->{file}) {
    # ./check_stuff --extra-opts
    $self->{section} = basename($0);
    $self->{file} = $self->get_default_file();
  } elsif ($self->{file} =~ /^[^@]+$/) {
    # ./check_stuff --extra-opts=special_opts
    $self->{section} = $self->{file};
    $self->{file} = $self->get_default_file();
  } elsif ($self->{file} =~ /^@(.*)/) {
    # ./check_stuff --extra-opts=@/etc/myconfig.ini
    $self->{section} = basename($0);
    $self->{file} = $1;
  } elsif ($self->{file} =~ /^(.*?)@(.*)/) {
    # ./check_stuff --extra-opts=special_opts@/etc/myconfig.ini
    $self->{section} = $1;
    $self->{file} = $2;
  }
}

sub get_default_file {
  my $self = shift;
  foreach my $default (qw(/etc/nagios/plugins.ini
      /usr/local/nagios/etc/plugins.ini
      /usr/local/etc/nagios/plugins.ini
      /etc/opt/nagios/plugins.ini
      /etc/nagios-plugins.ini
      /usr/local/etc/nagios-plugins.ini
      /etc/opt/nagios-plugins.ini)) {
    if (-f $default) {
      return $default;
    }
  }
  return undef;
}

sub init {
  my $self = shift;
  if (! defined $self->{file}) {
    $self->{errors} = sprintf 'no extra-opts file specified and no default file found';
  } elsif (! -f $self->{file}) {
    $self->{errors} = sprintf 'could not open %s', $self->{file};
  } else {
    my $data = do { local (@ARGV, $/) = $self->{file}; <> };
    my $in_section = 'default_no_section';
    foreach my $line (split(/\n/, $data)) {
      if ($line =~ /\[(.*)\]/) {
        $in_section = $1;
      } elsif ($line =~ /(.*?)\s*=\s*(.*)/) {
        $self->{config}->{$in_section}->{$1} = $2;
      }
    }
  }
}

sub is_valid {
  my $self = shift;
  return ! exists $self->{errors};
}

sub overwrite {
  my $self = shift;
  if (scalar(keys %{$self->{config}->{default_no_section}}) > 0) {
    foreach (keys %{$self->{config}->{default_no_section}}) {
      $self->{commandline}->{$_} = $self->{config}->{default_no_section}->{$_};
    }
  }
  if (exists $self->{config}->{$self->{section}}) {
    foreach (keys %{$self->{config}->{$self->{section}}}) {
      $self->{commandline}->{$_} = $self->{config}->{$self->{section}}->{$_};
    }
  }
}

sub errors {
  my $self = shift;
  return $self->{errors} || "";
}



package Monitoring::GLPlugin::Commandline::Getopt;
use strict;
use File::Basename;
use Getopt::Long qw(:config no_ignore_case bundling);

# Standard defaults
my %DEFAULT = (
  timeout => 15,
  verbose => 0,
  license =>
"This monitoring plugin is free software, and comes with ABSOLUTELY NO WARRANTY.
It may be used, redistributed and/or modified under the terms of the GNU
General Public Licence (see http://www.fsf.org/licensing/licenses/gpl.txt).",
);
# Standard arguments
my @ARGS = ({
    spec => 'usage|?',
    help => "-?, --usage\n   Print usage information",
  }, {
    spec => 'help|h',
    help => "-h, --help\n   Print detailed help screen",
  }, {
    spec => 'version|V',
    help => "-V, --version\n   Print version information",
  }, {
    #spec => 'extra-opts:s@',
    #help => "--extra-opts=[<section>[@<config_file>]]\n   Section and/or config_file from which to load extra options (may repeat)",
  }, {
    spec => 'timeout|t=i',
    help => sprintf("-t, --timeout=INTEGER\n   Seconds before plugin times out (default: %s)", $DEFAULT{timeout}),
    default => $DEFAULT{timeout},
  }, {
    spec => 'verbose|v+',
    help => "-v, --verbose\n   Show details for command-line debugging (can repeat up to 3 times)",
    default => $DEFAULT{verbose},
  },
);
# Standard arguments we traditionally display last in the help output
my %DEFER_ARGS = map { $_ => 1 } qw(timeout verbose);

sub _init {
  my ($self, %params) = @_;
  # Check params
  my %attr = (
    usage => 1,
    version => 0,
    url => 0,
    plugin => { default => $Monitoring::GLPlugin::pluginname },
    blurb => 0,
    extra => 0,
    'extra-opts' => 0,
    license => { default => $DEFAULT{license} },
    timeout => { default => $DEFAULT{timeout} },
  );

  # Add attr to private _attr hash (except timeout)
  $self->{timeout} = delete $attr{timeout};
  $self->{_attr} = { %attr };
  foreach (keys %{$self->{_attr}}) {
    if (exists $params{$_}) {
      $self->{_attr}->{$_} = $params{$_};
    } else {
      $self->{_attr}->{$_} = $self->{_attr}->{$_}->{default}
          if ref ($self->{_attr}->{$_}) eq 'HASH' &&
              exists $self->{_attr}->{$_}->{default};
    }
  }
  # Chomp _attr values
  chomp foreach values %{$self->{_attr}};

  # Setup initial args list
  $self->{_args} = [ grep { exists $_->{spec} } @ARGS ];

  $self
}

sub new {
  my ($class, @params) = @_;
  require Monitoring::GLPlugin::Commandline::Extraopts
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::Commandline::Extraopts::;
  my $self = bless {}, $class;
  $self->_init(@params);
}

sub add_arg {
  my ($self, %arg) = @_;
  push (@{$self->{_args}}, \%arg);
}

sub mod_arg {
  my ($self, $argname, %arg) = @_;
  foreach my $old_arg (@{$self->{_args}}) {
    next unless $old_arg->{spec} =~ /(\w+).*/ && $argname eq $1;
    foreach my $key (keys %arg) {
      $old_arg->{$key} = $arg{$key};
    }
  }
}

sub getopts {
  my ($self) = @_;
  my %commandline = ();
  $self->{opts}->{all_my_opts} = {};
  my @params = map { $_->{spec} } @{$self->{_args}};
  if (! GetOptions(\%commandline, @params)) {
    $self->print_help();
    exit 3;
  } else {
    no strict 'refs';
    no warnings 'redefine';
    if (exists $commandline{'extra-opts'}) {
      # read the extra file and overwrite other parameters
      my $extras = Monitoring::GLPlugin::Commandline::Extraopts->new(
          file => $commandline{'extra-opts'},
          commandline => \%commandline
      );
      if (! $extras->is_valid()) {
        printf "UNKNOWN - extra-opts are not valid: %s\n", $extras->errors();
        exit 3;
      } else {
        $extras->overwrite();
      }
    }
    do { $self->print_help(); exit 0; } if $commandline{help};
    do { $self->print_version(); exit 0 } if $commandline{version};
    do { $self->print_usage(); exit 3 } if $commandline{usage};
    foreach (map { $_->{spec} =~ /^([\w\-]+)/; $1; } @{$self->{_args}}) {
      my $field = $_;
      *{"$field"} = sub {
        return $self->{opts}->{$field};
      };
    }
    *{"all_my_opts"} = sub {
      return $self->{opts}->{all_my_opts};
    };
    foreach (map { $_->{spec} =~ /^([\w\-]+)/; $1; }
        grep { exists $_->{required} && $_->{required} } @{$self->{_args}}) {
      do { $self->print_usage(); exit 3 } if ! exists $commandline{$_};
    }
    foreach (grep { exists $_->{default} } @{$self->{_args}}) {
      $_->{spec} =~ /^([\w\-]+)/;
      my $spec = $1;
      $self->{opts}->{$spec} = $_->{default};
    }
    foreach (keys %commandline) {
      $self->{opts}->{$_} = $commandline{$_};
      $self->{opts}->{all_my_opts}->{$_} = $commandline{$_};
    }
    foreach (grep { exists $_->{env} } @{$self->{_args}}) {
      $_->{spec} =~ /^([\w\-]+)/;
      my $spec = $1;
      if (exists $ENV{'NAGIOS__HOST'.$_->{env}}) {
        $self->{opts}->{$spec} = $ENV{'NAGIOS__HOST'.$_->{env}};
      }
      if (exists $ENV{'NAGIOS__SERVICE'.$_->{env}}) {
        $self->{opts}->{$spec} = $ENV{'NAGIOS__SERVICE'.$_->{env}};
      }
    }
    foreach (grep { exists $_->{aliasfor} } @{$self->{_args}}) {
      my $field = $_->{aliasfor};
      $_->{spec} =~ /^([\w\-]+)/;
      my $aliasfield = $1;
      next if $self->{opts}->{$field};
      *{"$field"} = sub {
        return $self->{opts}->{$aliasfield};
      };
    }
  }
}

sub create_opt {
  my ($self, $key) = @_;
  no strict 'refs';
  *{"$key"} = sub {
      return $self->{opts}->{$key};
  };
}

sub override_opt {
  my ($self, $key, $value) = @_;
  $self->{opts}->{$key} = $value;
}

sub get {
  my ($self, $opt) = @_;
  return $self->{opts}->{$opt};
}

sub print_help {
  my ($self) = @_;
  $self->print_version();
  printf "\n%s\n", $self->{_attr}->{license};
  printf "\n%s\n\n", $self->{_attr}->{blurb};
  $self->print_usage();
  foreach (grep {
      ! (exists $_->{hidden} && $_->{hidden}) 
  } @{$self->{_args}}) {
    printf " %s\n", $_->{help};
  }
}

sub print_usage {
  my ($self) = @_;
  printf $self->{_attr}->{usage}, $self->{_attr}->{plugin};
  print "\n";
}

sub print_version {
  my ($self) = @_;
  printf "%s %s", $self->{_attr}->{plugin}, $self->{_attr}->{version};
  printf " [%s]", $self->{_attr}->{url} if $self->{_attr}->{url};
  print "\n";
}

sub print_license {
  my ($self) = @_;
  printf "%s\n", $self->{_attr}->{license};
  print "\n";
}



package Monitoring::GLPlugin::Commandline;
use strict;
use IO::File;
use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3, DEPENDENT => 4 };
our %ERRORS = (
    'OK'        => OK,
    'WARNING'   => WARNING,
    'CRITICAL'  => CRITICAL,
    'UNKNOWN'   => UNKNOWN,
    'DEPENDENT' => DEPENDENT,
);

our %STATUS_TEXT = reverse %ERRORS;
our $AUTOLOAD;


sub new {
  my ($class, %params) = @_;
  require Monitoring::GLPlugin::Commandline::Getopt
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::Commandline::Getopt::;
  my $self = {
       perfdata => [],
       messages => {
         ok => [],
         warning => [],
         critical => [],
         unknown => [],
       },
       args => [],
       opts => Monitoring::GLPlugin::Commandline::Getopt->new(%params),
       modes => [],
       statefilesdir => undef,
  };
  foreach (qw(shortname usage version url plugin blurb extra
      license timeout)) {
    $self->{$_} = $params{$_};
  }
  bless $self, $class;
  $self->{plugin} ||= $Monitoring::GLPlugin::pluginname;
  $self->{name} = $self->{plugin};
  $Monitoring::GLPlugin::plugin = $self;
}

sub AUTOLOAD {
  my ($self, @params) = @_;
  return if ($AUTOLOAD =~ /DESTROY/);
  $self->debug("AUTOLOAD %s\n", $AUTOLOAD)
        if $self->{opts}->verbose >= 2;
  if ($AUTOLOAD =~ /^.*::(add_arg|override_opt|create_opt)$/) {
    $self->{opts}->$1(@params);
  }
}

sub DESTROY {
  my ($self) = @_;
  # ohne dieses DESTROY rennt nagios_exit in obiges AUTOLOAD rein
  # und fliegt aufs Maul, weil {opts} bereits nicht mehr existiert.
  # Unerklaerliches Verhalten.
}

sub debug {
  my ($self, $format, @message) = @_;
  my $tracefile = "/tmp/".$Monitoring::GLPlugin::pluginname.".trace";
  $self->{trace} = -f $tracefile ? 1 : 0;
  if ($self->opts->verbose && $self->opts->verbose > 10) {
    printf("%s: ", scalar localtime);
    printf($format, @message);
    printf "\n";
  }
  if ($self->{trace}) {
    my $logfh = IO::File->new();
    $logfh->autoflush(1);
    if ($logfh->open($tracefile, "a")) {
      $logfh->printf("%s: ", scalar localtime);
      $logfh->printf($format, @message);
      $logfh->printf("\n");
      $logfh->close();
    }
  }
}

sub opts {
  my ($self) = @_;
  return $self->{opts};
}

sub getopts {
  my ($self) = @_;
  $self->opts->getopts();
}

sub add_message {
  my ($self, $code, @messages) = @_;
  $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/;
  $code = lc $code;
  push @{$self->{messages}->{$code}}, @messages;
}

sub selected_perfdata {
  my ($self, $label) = @_;
  if ($self->opts->can("selectedperfdata") && $self->opts->selectedperfdata) {
    my $pattern = $self->opts->selectedperfdata;
    return ($label =~ /$pattern/i) ? 1 : 0;
  } else {
    return 1;
  }
}

sub add_perfdata {
  my ($self, %args) = @_;
#printf "add_perfdata %s\n", Data::Dumper::Dumper(\%args);
#printf "add_perfdata %s\n", Data::Dumper::Dumper($self->{thresholds});
#
# wenn warning, critical, dann wird von oben ein expliziter wert mitgegeben
# wenn thresholds
#  wenn label in 
#    warningx $self->{thresholds}->{$label}->{warning} existiert
#  dann nimm $self->{thresholds}->{$label}->{warning}
#  ansonsten thresholds->default->warning
#

  my $label = $args{label};
  my $value = $args{value};
  my $uom = $args{uom} || "";
  my $format = '%d';

  if ($self->opts->can("morphperfdata") && $self->opts->morphperfdata) {
    # 'Intel [R] Interface (\d+) usage'='nic$1'
    foreach my $key (keys %{$self->opts->morphperfdata}) {
      if ($label =~ /$key/) {
        my $replacement = '"'.$self->opts->morphperfdata->{$key}.'"';
        my $oldlabel = $label;
        $label =~ s/$key/$replacement/ee;
        if (exists $self->{thresholds}->{$oldlabel}) {
          %{$self->{thresholds}->{$label}} = %{$self->{thresholds}->{$oldlabel}};
        }
      }
    }
  }
  if ($value =~ /\./) {
    if (defined $args{places}) {
      $value = sprintf '%.'.$args{places}.'f', $value;
    } else {
      $value = sprintf "%.2f", $value;
    }
  } else {
    $value = sprintf "%d", $value;
  }
  my $warn = "";
  my $crit = "";
  my $min = defined $args{min} ? $args{min} : "";
  my $max = defined $args{max} ? $args{max} : "";
  if ($args{thresholds} || (! exists $args{warning} && ! exists $args{critical})) {
    if (exists $self->{thresholds}->{$label}->{warning}) {
      $warn = $self->{thresholds}->{$label}->{warning};
    } elsif (exists $self->{thresholds}->{default}->{warning}) {
      $warn = $self->{thresholds}->{default}->{warning};
    }
    if (exists $self->{thresholds}->{$label}->{critical}) {
      $crit = $self->{thresholds}->{$label}->{critical};
    } elsif (exists $self->{thresholds}->{default}->{critical}) {
      $crit = $self->{thresholds}->{default}->{critical};
    }
  } else {
    if ($args{warning}) {
      $warn = $args{warning};
    }
    if ($args{critical}) {
      $crit = $args{critical};
    }
  }
  if ($uom eq "%") {
    $min = 0;
    $max = 100;
  }
  if (defined $args{places}) {
    # cut off excessive decimals which may be the result of a division
    # length = places*2, no trailing zeroes
    if ($warn ne "") {
      $warn = join("", map {
          s/\.0+$//; $_
      } map {
          s/(\.[1-9]+)0+$/$1/; $_
      } map {
          /[\+\-\d\.]+/ ? sprintf '%.'.2*$args{places}.'f', $_ : $_;
      } split(/([\+\-\d\.]+)/, $warn));
    }
    if ($crit ne "") {
      $crit = join("", map {
          s/\.0+$//; $_
      } map {
          s/(\.[1-9]+)0+$/$1/; $_
      } map {
          /[\+\-\d\.]+/ ? sprintf '%.'.2*$args{places}.'f', $_ : $_;
      } split(/([\+\-\d\.]+)/, $crit));
    }
    if ($min ne "") {
      $min = join("", map {
          s/\.0+$//; $_
      } map {
          s/(\.[1-9]+)0+$/$1/; $_
      } map {
          /[\+\-\d\.]+/ ? sprintf '%.'.2*$args{places}.'f', $_ : $_;
      } split(/([\+\-\d\.]+)/, $min));
    }
    if ($max ne "") {
      $max = join("", map {
          s/\.0+$//; $_
      } map {
          s/(\.[1-9]+)0+$/$1/; $_
      } map {
          /[\+\-\d\.]+/ ? sprintf '%.'.2*$args{places}.'f', $_ : $_;
      } split(/([\+\-\d\.]+)/, $max));
    }
  }
  push @{$self->{perfdata}}, sprintf("'%s'=%s%s;%s;%s;%s;%s",
      $label, $value, $uom, $warn, $crit, $min, $max)
      if $self->selected_perfdata($label);
}

sub add_pandora {
  my ($self, %args) = @_;
  my $label = $args{label};
  my $value = $args{value};

  if ($args{help}) {
    push @{$self->{pandora}}, sprintf("# HELP %s %s", $label, $args{help});
  }
  if ($args{type}) {
    push @{$self->{pandora}}, sprintf("# TYPE %s %s", $label, $args{type});
  }
  if ($args{labels}) {
    push @{$self->{pandora}}, sprintf("%s{%s} %s", $label,
        join(",", map {
            sprintf '%s="%s"', $_, $args{labels}->{$_};
        } keys %{$args{labels}}),
        $value);
  } else {
    push @{$self->{pandora}}, sprintf("%s %s", $label, $value);
  }
}

sub add_html {
  my ($self, $line) = @_;
  push @{$self->{html}}, $line;
}

sub suppress_messages {
  my ($self) = @_;
  $self->{suppress_messages} = 1;
}

sub clear_messages {
  my ($self, $code) = @_;
  $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/;
  $code = lc $code;
  $self->{messages}->{$code} = [];
}

sub reduce_messages_short {
  my ($self, $message) = @_;
  $message ||= "no problems";
  if ($self->opts->report && $self->opts->report eq "short") {
    $self->clear_messages(OK);
    $self->add_message(OK, $message) if ! $self->check_messages();
  }
}

sub reduce_messages {
  my ($self, $message) = @_;
  $message ||= "no problems";
  $self->clear_messages(OK);
  $self->add_message(OK, $message) if ! $self->check_messages();
}

sub check_messages {
  my ($self, %args) = @_;

  # Add object messages to any passed in as args
  for my $code (qw(critical warning unknown ok)) {
    my $messages = $self->{messages}->{$code} || [];
    if ($args{$code}) {
      unless (ref $args{$code} eq 'ARRAY') {
        if ($code eq 'ok') {
          $args{$code} = [ $args{$code} ];
        }
      }
      push @{$args{$code}}, @$messages;
    } else {
      $args{$code} = $messages;
    }
  }
  my %arg = %args;
  $arg{join} = ' ' unless defined $arg{join};

  # Decide $code
  my $code = OK;
  $code ||= CRITICAL  if @{$arg{critical}};
  $code ||= WARNING   if @{$arg{warning}};
  $code ||= UNKNOWN   if @{$arg{unknown}};
  return $code unless wantarray;

  # Compose message
  my $message = '';
  if ($arg{join_all}) {
      $message = join( $arg{join_all},
          map { @$_ ? join( $arg{'join'}, @$_) : () }
              $arg{critical},
              $arg{warning},
              $arg{unknown},
              $arg{ok} ? (ref $arg{ok} ? $arg{ok} : [ $arg{ok} ]) : []
      );
  }

  else {
      $message ||= join( $arg{'join'}, @{$arg{critical}} )
          if $code == CRITICAL;
      $message ||= join( $arg{'join'}, @{$arg{warning}} )
          if $code == WARNING;
      $message ||= join( $arg{'join'}, @{$arg{unknown}} )
          if $code == UNKNOWN;
      $message ||= ref $arg{ok} ? join( $arg{'join'}, @{$arg{ok}} ) : $arg{ok}
          if $arg{ok};
  }

  return ($code, $message);
}

sub status_code {
  my ($self, $code) = @_;
  $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/;
  $code = uc $code;
  $code = $ERRORS{$code} if defined $code && exists $ERRORS{$code};
  $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code};
  return "$STATUS_TEXT{$code}";
}

sub perfdata_string {
  my ($self) = @_;
  if (scalar (@{$self->{perfdata}})) {
    return join(" ", @{$self->{perfdata}});
  } else {
    return "";
  }
}

sub metrics_string {
  my ($self) = @_;
  if (scalar (@{$self->{metrics}})) {
    return join("\n", @{$self->{metrics}});
  } else {
    return "";
  }
}

sub html_string {
  my ($self) = @_;
  if (scalar (@{$self->{html}})) {
    return join(" ", @{$self->{html}});
  } else {
    return "";
  }
}

sub nagios_exit {
  my ($self, $code, $message, $arg) = @_;
  $code = $ERRORS{$code} if defined $code && exists $ERRORS{$code};
  $code = UNKNOWN unless defined $code && exists $STATUS_TEXT{$code};
  $message = '' unless defined $message;
  if (ref $message && ref $message eq 'ARRAY') {
      $message = join(' ', map { chomp; $_ } @$message);
  } else {
      chomp $message;
  }
  if ($self->opts->negate) {
    my $original_code = $code;
    foreach my $from (keys %{$self->opts->negate}) {
      if ((uc $from) =~ /^(OK|WARNING|CRITICAL|UNKNOWN)$/ &&
          (uc $self->opts->negate->{$from}) =~ /^(OK|WARNING|CRITICAL|UNKNOWN)$/) {
        if ($original_code == $ERRORS{uc $from}) {
          $code = $ERRORS{uc $self->opts->negate->{$from}};
        }
      }
    }
  }
  my $output = "$STATUS_TEXT{$code}";
  $output .= " - $message" if defined $message && $message ne '';
  if ($self->opts->can("morphmessage") && $self->opts->morphmessage) {
    # 'Intel [R] Interface (\d+) usage'='nic$1'
    # '^OK.*'="alles klar"   '^CRITICAL.*'="alles hi"
    foreach my $key (keys %{$self->opts->morphmessage}) {
      if ($output =~ /$key/) {
        my $replacement = '"'.$self->opts->morphmessage->{$key}.'"';
        $output =~ s/$key/$replacement/ee;
      }
    }
  }
  if ($self->opts->negate) {
    # negate again: --negate "UNKNOWN - no peers"=ok
    my $original_code = $code;
    foreach my $from (keys %{$self->opts->negate}) {
      if ((uc $from) !~ /^(OK|WARNING|CRITICAL|UNKNOWN)$/ &&
          (uc $self->opts->negate->{$from}) =~ /^(OK|WARNING|CRITICAL|UNKNOWN)$/) {
        if ($output =~ /$from/) {
          $code = $ERRORS{uc $self->opts->negate->{$from}};
          $output =~ s/^.*? -/$STATUS_TEXT{$code} -/;
        }
      }
    }
  }
  $output =~ s/\|/!/g if $output;
  if (scalar (@{$self->{perfdata}})) {
    $output .= " | ".$self->perfdata_string();
  }
  $output .= "\n";
  if ($self->opts->can("isvalidtime") && ! $self->opts->isvalidtime) {
    $code = OK;
    $output = "OK - outside valid timerange. check results are not relevant now. original message was: ".
        $output;
  }
  if (! exists $self->{suppress_messages}) {
    print $output;
  }
  exit $code;
}

sub set_thresholds {
  my ($self, %params) = @_;
  if (exists $params{metric}) {
    my $metric = $params{metric};
    # erst die hartcodierten defaultschwellwerte
    $self->{thresholds}->{$metric}->{warning} = $params{warning};
    $self->{thresholds}->{$metric}->{critical} = $params{critical};
    # dann die defaultschwellwerte von der kommandozeile
    if (defined $self->opts->warning) {
      $self->{thresholds}->{$metric}->{warning} = $self->opts->warning;
    }
    if (defined $self->opts->critical) {
      $self->{thresholds}->{$metric}->{critical} = $self->opts->critical;
    }
    # dann die ganz spezifischen schwellwerte von der kommandozeile
    if ($self->opts->warningx) { # muss nicht auf defined geprueft werden, weils ein hash ist
      # Erst schauen, ob einer * beinhaltet. Von denen wird vom Laengsten
      # bis zum Kuerzesten probiert, ob die matchen. Der laengste Match
      # gewinnt.
      my @keys = keys %{$self->opts->warningx};
      my @stringkeys = ();
      my @regexkeys = ();
      foreach my $key (sort { length($b) > length($a) } @keys) {
        if ($key =~ /\*/) {
          push(@regexkeys, $key);
        } else {
          push(@stringkeys, $key);
        }
      }
      foreach my $key (@regexkeys) {
        next if $metric !~ /$key/;
        $self->{thresholds}->{$metric}->{warning} = $self->opts->warningx->{$key};
        last;
      }
      # Anschliessend nochmal schauen, ob es einen nicht-Regex-Volltreffer gibt
      foreach my $key (@stringkeys) {
        next if $key ne $metric;
        $self->{thresholds}->{$metric}->{warning} = $self->opts->warningx->{$key};
        last;
      }
    }
    if ($self->opts->criticalx) {
      my @keys = keys %{$self->opts->criticalx};
      my @stringkeys = ();
      my @regexkeys = ();
      foreach my $key (sort { length($b) > length($a) } @keys) {
        if ($key =~ /\*/) {
          push(@regexkeys, $key);
        } else {
          push(@stringkeys, $key);
        }
      }
      foreach my $key (@regexkeys) {
        next if $metric !~ /$key/;
        $self->{thresholds}->{$metric}->{critical} = $self->opts->criticalx->{$key};
        last;
      }
      # Anschliessend nochmal schauen, ob es einen nicht-Regex-Volltreffer gibt
      foreach my $key (@stringkeys) {
        next if $key ne $metric;
        $self->{thresholds}->{$metric}->{critical} = $self->opts->criticalx->{$key};
        last;
      }
    }
  } else {
    $self->{thresholds}->{default}->{warning} =
        defined $self->opts->warning ? $self->opts->warning : defined $params{warning} ? $params{warning} : 0;
    $self->{thresholds}->{default}->{critical} =
        defined $self->opts->critical ? $self->opts->critical : defined $params{critical} ? $params{critical} : 0;
  }
}

sub force_thresholds {
  my ($self, %params) = @_;
  if (exists $params{metric}) {
    my $metric = $params{metric};
    $self->{thresholds}->{$metric}->{warning} = $params{warning} || 0;
    $self->{thresholds}->{$metric}->{critical} = $params{critical} || 0;
  } else {
    $self->{thresholds}->{default}->{warning} = $params{warning} || 0;
    $self->{thresholds}->{default}->{critical} = $params{critical} || 0;
  }
}

sub get_thresholds {
  my ($self, @params) = @_;
  if (scalar(@params) > 1) {
    my %params = @params;
    my $metric = $params{metric};
    return ($self->{thresholds}->{$metric}->{warning},
        $self->{thresholds}->{$metric}->{critical});
  } else {
    return ($self->{thresholds}->{default}->{warning},
        $self->{thresholds}->{default}->{critical});
  }
}

sub check_thresholds {
  my ($self, @params) = @_;
  my $level = $ERRORS{OK};
  my $warningrange;
  my $criticalrange;
  my $value;
  if (scalar(@params) > 1) {
    my %params = @params;
    $value = $params{value};
    my $metric = $params{metric};
    if ($metric ne 'default') {
      $warningrange = exists $self->{thresholds}->{$metric}->{warning} ?
          $self->{thresholds}->{$metric}->{warning} :
          $self->{thresholds}->{default}->{warning};
      $criticalrange = exists $self->{thresholds}->{$metric}->{critical} ?
          $self->{thresholds}->{$metric}->{critical} :
          $self->{thresholds}->{default}->{critical};
    } else {
      $warningrange = (defined $params{warning}) ?
          $params{warning} : $self->{thresholds}->{default}->{warning};
      $criticalrange = (defined $params{critical}) ?
          $params{critical} : $self->{thresholds}->{default}->{critical};
    }
  } else {
    $value = $params[0];
    $warningrange = $self->{thresholds}->{default}->{warning};
    $criticalrange = $self->{thresholds}->{default}->{critical};
  }
  if (! defined $warningrange) {
    # there was no set_thresholds for defaults, no --warning, no --warningx
  } elsif ($warningrange =~ /^([-+]?[0-9]*\.?[0-9]+)$/) {
    # warning = 10, warn if > 10 or < 0
    $level = $ERRORS{WARNING}
        if ($value > $1 || $value < 0);
  } elsif ($warningrange =~ /^([-+]?[0-9]*\.?[0-9]+):$/) {
    # warning = 10:, warn if < 10
    $level = $ERRORS{WARNING}
        if ($value < $1);
  } elsif ($warningrange =~ /^~:([-+]?[0-9]*\.?[0-9]+)$/) {
    # warning = ~:10, warn if > 10
    $level = $ERRORS{WARNING}
        if ($value > $1);
  } elsif ($warningrange =~ /^([-+]?[0-9]*\.?[0-9]+):([-+]?[0-9]*\.?[0-9]+)$/) {
    # warning = 10:20, warn if < 10 or > 20
    $level = $ERRORS{WARNING}
        if ($value < $1 || $value > $2);
  } elsif ($warningrange =~ /^@([-+]?[0-9]*\.?[0-9]+):([-+]?[0-9]*\.?[0-9]+)$/) {
    # warning = @10:20, warn if >= 10 and <= 20
    $level = $ERRORS{WARNING}
        if ($value >= $1 && $value <= $2);
  }
  if (! defined $criticalrange) {
    # there was no set_thresholds for defaults, no --critical, no --criticalx
  } elsif ($criticalrange =~ /^([-+]?[0-9]*\.?[0-9]+)$/) {
    # critical = 10, crit if > 10 or < 0
    $level = $ERRORS{CRITICAL}
        if ($value > $1 || $value < 0);
  } elsif ($criticalrange =~ /^([-+]?[0-9]*\.?[0-9]+):$/) {
    # critical = 10:, crit if < 10
    $level = $ERRORS{CRITICAL}
        if ($value < $1);
  } elsif ($criticalrange =~ /^~:([-+]?[0-9]*\.?[0-9]+)$/) {
    # critical = ~:10, crit if > 10
    $level = $ERRORS{CRITICAL}
        if ($value > $1);
  } elsif ($criticalrange =~ /^([-+]?[0-9]*\.?[0-9]+):([-+]?[0-9]*\.?[0-9]+)$/) {
    # critical = 10:20, crit if < 10 or > 20
    $level = $ERRORS{CRITICAL}
        if ($value < $1 || $value > $2);
  } elsif ($criticalrange =~ /^@([-+]?[0-9]*\.?[0-9]+):([-+]?[0-9]*\.?[0-9]+)$/) {
    # critical = @10:20, crit if >= 10 and <= 20
    $level = $ERRORS{CRITICAL}
        if ($value >= $1 && $value <= $2);
  }
  return $level;
}

sub strequal {
  my($self, $str1, $str2) = @_;
  return 1 if ! defined $str1 && ! defined $str2;
  return 0 if ! defined $str1 && defined $str2;
  return 0 if defined $str1 && ! defined $str2;
  return 1 if $str1 eq $str2;
  return 0;
}



package Monitoring::GLPlugin;

=head1 Monitoring::GLPlugin

Monitoring::GLPlugin - infrastructure functions to build a monitoring plugin

=cut

use strict;
use IO::File;
use File::Basename;
use Digest::MD5 qw(md5_hex);
use Errno;
use Data::Dumper;
our $AUTOLOAD;
*VERSION = \'2.4.14.8';

use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };

{
  our $mode = undef;
  our $plugin = undef;
  our $pluginname = basename($ENV{'NAGIOS_PLUGIN'} || $0);
  our $blacklist = undef;
  our $info = [];
  our $extendedinfo = [];
  our $summary = [];
  our $variables = {};
  our $survive_sudo_env = ["LD_LIBRARY_PATH", "SHLIB_PATH"];
}

sub new {
  my ($class, %params) = @_;
  my $self = {};
  bless $self, $class;
  require Monitoring::GLPlugin::Commandline
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::Commandline::;
  require Monitoring::GLPlugin::Item
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::Item::;
  require Monitoring::GLPlugin::TableItem
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::TableItem::;
  $Monitoring::GLPlugin::plugin = Monitoring::GLPlugin::Commandline->new(%params);
  return $self;
}

sub rebless {
  my ($self, $class) = @_;
  bless $self, $class;
  $self->debug('using '.$class);
  # gilt nur fuer "echte" Fabrikate mit "Classes::" vorndran
  $self->{classified_as} = ref($self) if $class !~ /^Monitoring::GLPlugin/;
}

sub init {
  my ($self) = @_;
  if ($self->opts->can("blacklist") && $self->opts->blacklist &&
      -f $self->opts->blacklist) {
    $self->opts->blacklist = do {
        local (@ARGV, $/) = $self->opts->blacklist; <> };
  }
}

sub dumper {
  my ($self, $object) = @_;
  my $run = $object->{runtime};
  delete $object->{runtime};
  printf STDERR "%s\n", Data::Dumper::Dumper($object);
  $object->{runtime} = $run;
}

sub no_such_mode {
  my ($self) = @_;
  printf "Mode %s is not implemented for this type of device\n",
      $self->opts->mode;
  exit 3;
}

#########################################################
# framework-related. setup, options
#
sub add_default_args {
  my ($self) = @_;
  $self->add_arg(
      spec => 'mode=s',
      help => "--mode
   A keyword which tells the plugin what to do",
      required => 1,
  );
  $self->add_arg(
      spec => 'regexp',
      help => "--regexp
   Parameter name/name2/name3 will be interpreted as (perl) regular expression",
      required => 0,);
  $self->add_arg(
      spec => 'warning=s',
      help => "--warning
   The warning threshold",
      required => 0,);
  $self->add_arg(
      spec => 'critical=s',
      help => "--critical
   The critical threshold",
      required => 0,);
  $self->add_arg(
      spec => 'warningx=s%',
      help => '--warningx
   The extended warning thresholds
   e.g. --warningx db_msdb_free_pct=6: to override the threshold for a
   specific item ',
      required => 0,
  );
  $self->add_arg(
      spec => 'criticalx=s%',
      help => '--criticalx
   The extended critical thresholds',
      required => 0,
  );
  $self->add_arg(
      spec => 'units=s',
      help => "--units
   One of %, B, KB, MB, GB, Bit, KBi, MBi, GBi. (used for e.g. mode interface-usage)",
      required => 0,
  );
  $self->add_arg(
      spec => 'name=s',
      help => "--name
   The name of a specific component to check",
      required => 0,
  );
  $self->add_arg(
      spec => 'name2=s',
      help => "--name2
   The secondary name of a component",
      required => 0,
  );
  $self->add_arg(
      spec => 'name3=s',
      help => "--name3
   The tertiary name of a component",
      required => 0,
  );
  $self->add_arg(
      spec => 'extra-opts=s',
      help => "--extra-opts
   read command line arguments from an external file",
      required => 0,
  );
  $self->add_arg(
      spec => 'blacklist|b=s',
      help => '--blacklist
   Blacklist some (missing/failed) components',
      required => 0,
      default => '',
  );
  $self->add_arg(
      spec => 'mitigation=s',
      help => "--mitigation
   The parameter allows you to change a critical error to a warning.",
      required => 0,
  );
  $self->add_arg(
      spec => 'lookback=s',
      help => "--lookback
   The amount of time you want to look back when calculating average rates.
   Use it for mode interface-errors or interface-usage. Without --lookback
   the time between two runs of check_nwc_health is the base for calculations.
   If you want your checkresult to be based for example on the past hour,
   use --lookback 3600. ",
      required => 0,
  );
  $self->add_arg(
      spec => 'environment|e=s%',
      help => "--environment
   Add a variable to the plugin's environment",
      required => 0,
  );
  $self->add_arg(
      spec => 'negate=s%',
      help => "--negate
   Emulate the negate plugin. --negate warning=critical --negate unknown=critical",
      required => 0,
  );
  $self->add_arg(
      spec => 'morphmessage=s%',
      help => '--morphmessage
   Modify the final output message',
      required => 0,
  );
  $self->add_arg(
      spec => 'morphperfdata=s%',
      help => "--morphperfdata
   The parameter allows you to change performance data labels.
   It's a perl regexp and a substitution.
   Example: --morphperfdata '(.*)ISATAP(.*)'='\$1patasi\$2'",
      required => 0,
  );
  $self->add_arg(
      spec => 'selectedperfdata=s',
      help => "--selectedperfdata
   The parameter allows you to limit the list of performance data. It's a perl regexp.
   Only matching perfdata show up in the output",
      required => 0,
  );
  $self->add_arg(
      spec => 'report=s',
      help => "--report
   Can be used to shorten the output",
      required => 0,
      default => 'long',
  );
  $self->add_arg(
      spec => 'multiline',
      help => '--multiline
   Multiline output',
      required => 0,
  );
  $self->add_arg(
      spec => 'with-mymodules-dyn-dir=s',
      help => "--with-mymodules-dyn-dir
   Add-on modules for the my-modes will be searched in this directory",
      required => 0,
  );
  $self->add_arg(
      spec => 'statefilesdir=s',
      help => '--statefilesdir
   An alternate directory where the plugin can save files',
      required => 0,
      env => 'STATEFILESDIR',
  );
  $self->add_arg(
      spec => 'isvalidtime=i',
      help => '--isvalidtime
   Signals the plugin to return OK if now is not a valid check time',
      required => 0,
      default => 1,
  );
  $self->add_arg(
      spec => 'reset',
      help => "--reset
   remove the state file",
      required => 0,
      hidden => 1,
  );
  $self->add_arg(
      spec => 'runas=s',
      help => "--runas
   run as a different user",
      required => 0,
      hidden => 1,
  );
  $self->add_arg(
      spec => 'shell',
      help => "--shell
   forget what you see",
      required => 0,
      hidden => 1,
  );
  $self->add_arg(
      spec => 'drecksptkdb=s',
      help => "--drecksptkdb
   This parameter must be used instead of --name, because Devel::ptkdb is stealing the latter from the command line",
      aliasfor => "name",
      required => 0,
      hidden => 1,
  );
  $self->add_arg(
      spec => 'tracefile=s',
      help => "--tracefile
   Write debugging-info to this file (if it exists)",
      required => 0,
      hidden => 1,
  );
}

sub add_modes {
  my ($self, $modes) = @_;
  my $modestring = "";
  my @modes = @{$modes};
  my $longest = length ((reverse sort {length $a <=> length $b} map { $_->[1] } @modes)[0]);
  my $format = "       %-".
      (length ((reverse sort {length $a <=> length $b} map { $_->[1] } @modes)[0])).
      "s\t(%s)\n";
  foreach (@modes) {
    $modestring .= sprintf $format, $_->[1], $_->[3];
  }
  $modestring .= sprintf "\n";
  $Monitoring::GLPlugin::plugin->{modestring} = $modestring;
}

sub add_arg {
  my ($self, %args) = @_;
  if ($args{help} =~ /^--mode/) {
    $args{help} .= "\n".$Monitoring::GLPlugin::plugin->{modestring};
  }
  $Monitoring::GLPlugin::plugin->{opts}->add_arg(%args);
}

sub mod_arg {
  my ($self, @arg) = @_;
  $Monitoring::GLPlugin::plugin->{opts}->mod_arg(@arg);
}

sub add_mode {
  my ($self, %args) = @_;
  push(@{$Monitoring::GLPlugin::plugin->{modes}}, \%args);
  my $longest = length ((reverse sort {length $a <=> length $b} map { $_->{spec} } @{$Monitoring::GLPlugin::plugin->{modes}})[0]);
  my $format = "       %-".
      (length ((reverse sort {length $a <=> length $b} map { $_->{spec} } @{$Monitoring::GLPlugin::plugin->{modes}})[0])).
      "s\t(%s)\n";
  $Monitoring::GLPlugin::plugin->{modestring} = "";
  foreach (@{$Monitoring::GLPlugin::plugin->{modes}}) {
    $Monitoring::GLPlugin::plugin->{modestring} .= sprintf $format, $_->{spec}, $_->{help};
  }
  $Monitoring::GLPlugin::plugin->{modestring} .= "\n";
}

sub validate_args {
  my ($self) = @_;
  if ($self->opts->mode =~ /^my-([^\-.]+)/) {
    my $param = $self->opts->mode;
    $param =~ s/\-/::/g;
    $self->add_mode(
        internal => $param,
        spec => $self->opts->mode,
        alias => undef,
        help => 'my extension',
    );
  } elsif ($self->opts->mode eq 'encode') {
    my $input = <>;
    chomp $input;
    $input =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg;
    printf "%s\n", $input;
    exit 0;
  } elsif ($self->opts->mode eq 'decode') {
    if (! -t STDIN) {
      my $input = <>;
      chomp $input;
      $input =~ s/%([A-Za-z0-9]{2})/chr(hex($1))/seg;
      printf "%s\n", $input;
      exit OK;
    } else {
      if ($self->opts->name) {
        my $input = $self->opts->name;
        $input =~ s/%([A-Za-z0-9]{2})/chr(hex($1))/seg;
        printf "%s\n", $input;
        exit OK;
      } else {
        printf "i can't find your encoded statement. use --name or pipe it in my stdin\n";
        exit UNKNOWN;
      }
    }
  } elsif ((! grep { $self->opts->mode eq $_ } map { $_->{spec} } @{$Monitoring::GLPlugin::plugin->{modes}}) &&
      (! grep { $self->opts->mode eq $_ } map { defined $_->{alias} ? @{$_->{alias}} : () } @{$Monitoring::GLPlugin::plugin->{modes}})) {
    printf "UNKNOWN - mode %s\n", $self->opts->mode;
    $self->opts->print_help();
    exit 3;
  }
  if ($self->opts->name && $self->opts->name =~ /(%22)|(%27)/) {
    my $name = $self->opts->name;
    $name =~ s/\%([A-Fa-f0-9]{2})/pack('C', hex($1))/seg;
    $self->override_opt('name', $name);
  }
  $Monitoring::GLPlugin::mode = (
      map { $_->{internal} }
      grep {
         ($self->opts->mode eq $_->{spec}) ||
         ( defined $_->{alias} && grep { $self->opts->mode eq $_ } @{$_->{alias}})
      } @{$Monitoring::GLPlugin::plugin->{modes}}
  )[0];
  if ($self->opts->multiline) {
    $ENV{NRPE_MULTILINESUPPORT} = 1;
  } else {
    $ENV{NRPE_MULTILINESUPPORT} = 0;
  }
  if ($self->opts->can("statefilesdir") && ! $self->opts->statefilesdir) {
    if ($^O =~ /MSWin/) {
      if (defined $ENV{TEMP}) {
        $self->override_opt('statefilesdir', $ENV{TEMP}."/".$Monitoring::GLPlugin::plugin->{name});
      } elsif (defined $ENV{TMP}) {
        $self->override_opt('statefilesdir', $ENV{TMP}."/".$Monitoring::GLPlugin::plugin->{name});
      } elsif (defined $ENV{windir}) {
        $self->override_opt('statefilesdir', File::Spec->catfile($ENV{windir}, 'Temp')."/".$Monitoring::GLPlugin::plugin->{name});
      } else {
        $self->override_opt('statefilesdir', "C:/".$Monitoring::GLPlugin::plugin->{name});
      }
    } elsif (exists $ENV{OMD_ROOT}) {
      $self->override_opt('statefilesdir', $ENV{OMD_ROOT}."/var/tmp/".$Monitoring::GLPlugin::plugin->{name});
    } else {
      $self->override_opt('statefilesdir', "/var/tmp/".$Monitoring::GLPlugin::plugin->{name});
    }
  }
  $Monitoring::GLPlugin::plugin->{statefilesdir} = $self->opts->statefilesdir
      if $self->opts->can("statefilesdir");
  if ($self->opts->can("warningx") && $self->opts->warningx) {
    foreach my $key (keys %{$self->opts->warningx}) {
      $self->set_thresholds(metric => $key,
          warning => $self->opts->warningx->{$key});
    }
  }
  if ($self->opts->can("criticalx") && $self->opts->criticalx) {
    foreach my $key (keys %{$self->opts->criticalx}) {
      $self->set_thresholds(metric => $key,
          critical => $self->opts->criticalx->{$key});
    }
  }
  $self->set_timeout_alarm() if ! $SIG{'ALRM'};
}

sub set_timeout_alarm {
  my ($self, $timeout, $handler) = @_;
  $timeout ||= $self->opts->timeout;
  $handler ||= sub {
    $self->nagios_exit(UNKNOWN,
        sprintf("%s timed out after %d seconds\n",
            $Monitoring::GLPlugin::plugin->{name}, $self->opts->timeout)
    );
  };
  use POSIX ':signal_h';
  if ($^O =~ /MSWin/) {
    local $SIG{'ALRM'} = $handler;
  } else {
    my $mask = POSIX::SigSet->new( SIGALRM );
    my $action = POSIX::SigAction->new(
        $handler, $mask
    );   
    my $oldaction = POSIX::SigAction->new();
    sigaction(SIGALRM ,$action ,$oldaction );
  }    
  alarm(int($timeout)); # 1 second before the global unknown timeout
}

#########################################################
# global helpers
#
sub set_variable {
  my ($self, $key, $value) = @_;
  $Monitoring::GLPlugin::variables->{$key} = $value;
}

sub get_variable {
  my ($self, $key, $fallback) = @_;
  return exists $Monitoring::GLPlugin::variables->{$key} ?
      $Monitoring::GLPlugin::variables->{$key} : $fallback;
}

sub debug {
  my ($self, $format, @message) = @_;
  my $tracefile = $self->opts->tracefile ?
      $self->opts->tracefile :
      "/tmp/".$Monitoring::GLPlugin::pluginname.".trace";
  $self->{trace} = -f $tracefile ? 1 : 0;
  if ($self->get_variable("verbose") &&
      $self->get_variable("verbose") > $self->get_variable("verbosity", 10)) {
    printf("%s: ", scalar localtime);
    printf($format, @message);
    printf "\n";
  }
  if ($self->{trace}) {
    my $logfh = IO::File->new();
    $logfh->autoflush(1);
    if ($logfh->open($tracefile, "a")) {
      $logfh->printf("%s: ", scalar localtime);
      $logfh->printf($format, @message);
      $logfh->printf("\n");
      $logfh->close();
    }
  }
}

sub filter_namex {
  my ($self, $opt, $name) = @_;
  if ($opt) {
    if ($self->opts->regexp) {
      if ($name =~ /$opt/i) {
        return 1;
      }
    } else {
      if (lc $opt eq lc $name) {
        return 1;
      }
    }
  } else {
    return 1;
  }
  return 0;
}

sub filter_name {
  my ($self, $name) = @_;
  return $self->filter_namex($self->opts->name, $name);
}

sub filter_name2 {
  my ($self, $name) = @_;
  return $self->filter_namex($self->opts->name2, $name);
}

sub filter_name3 {
  my ($self, $name) = @_;
  return $self->filter_namex($self->opts->name3, $name);
}

sub version_is_minimum {
  my ($self, $version) = @_;
  my $installed_version;
  my $newer = 1;
  if ($self->get_variable("version")) {
    $installed_version = $self->get_variable("version");
  } elsif (exists $self->{version}) {
    $installed_version = $self->{version};
  } else {
    return 0;
  }
  my @v1 = map { $_ eq "x" ? 0 : $_ } split(/\./, $version);
  my @v2 = split(/\./, $installed_version);
  if (scalar(@v1) > scalar(@v2)) {
    push(@v2, (0) x (scalar(@v1) - scalar(@v2)));
  } elsif (scalar(@v2) > scalar(@v1)) {
    push(@v1, (0) x (scalar(@v2) - scalar(@v1)));
  }
  foreach my $pos (0..$#v1) {
    if ($v2[$pos] > $v1[$pos]) {
      $newer = 1;
      last;
    } elsif ($v2[$pos] < $v1[$pos]) {
      $newer = 0;
      last;
    }
  }
  return $newer;
}

sub accentfree {
  my ($self, $text) = @_;
  # thanks mycoyne who posted this accent-remove-algorithm
  # http://www.experts-exchange.com/Programming/Languages/Scripting/Perl/Q_23275533.html#a21234612
  my @transformed;
  my %replace = (
    '9a' => 's', '9c' => 'oe', '9e' => 'z', '9f' => 'Y', 'c0' => 'A', 'c1' => 'A',
    'c2' => 'A', 'c3' => 'A', 'c4' => 'A', 'c5' => 'A', 'c6' => 'AE', 'c7' => 'C',
    'c8' => 'E', 'c9' => 'E', 'ca' => 'E', 'cb' => 'E', 'cc' => 'I', 'cd' => 'I',
    'ce' => 'I', 'cf' => 'I', 'd0' => 'D', 'd1' => 'N', 'd2' => 'O', 'd3' => 'O',
    'd4' => 'O', 'd5' => 'O', 'd6' => 'O', 'd8' => 'O', 'd9' => 'U', 'da' => 'U',
    'db' => 'U', 'dc' => 'U', 'dd' => 'Y', 'e0' => 'a', 'e1' => 'a', 'e2' => 'a',
    'e3' => 'a', 'e4' => 'a', 'e5' => 'a', 'e6' => 'ae', 'e7' => 'c', 'e8' => 'e',
    'e9' => 'e', 'ea' => 'e', 'eb' => 'e', 'ec' => 'i', 'ed' => 'i', 'ee' => 'i',
    'ef' => 'i', 'f0' => 'o', 'f1' => 'n', 'f2' => 'o', 'f3' => 'o', 'f4' => 'o',
    'f5' => 'o', 'f6' => 'o', 'f8' => 'o', 'f9' => 'u', 'fa' => 'u', 'fb' => 'u',
    'fc' => 'u', 'fd' => 'y', 'ff' => 'y',
  );
  my @letters = split //, $text;;
  for (my $i = 0; $i <= $#letters; $i++) {
    my $hex = sprintf "%x", ord($letters[$i]);
    $letters[$i] = $replace{$hex} if (exists $replace{$hex});
  }
  push @transformed, @letters;
  return join '', @transformed;
}

sub dump {
  my ($self, $indent) = @_;
  $indent = $indent ? " " x $indent : "";
  my $class = ref($self);
  $class =~ s/^.*:://;
  if (exists $self->{flat_indices}) {
    printf "%s[%s_%s]\n", $indent, uc $class, $self->{flat_indices};
  } else {
    printf "%s[%s]\n", $indent, uc $class;
  }
  foreach (grep !/^(info|trace|warning|critical|blacklisted|extendedinfo|flat_indices|indices)$/, sort keys %{$self}) {
    printf "%s%s: %s\n", $indent, $_, $self->{$_} if defined $self->{$_} && ref($self->{$_}) ne "ARRAY";
  }
  if ($self->{info}) {
    printf "%sinfo: %s\n", $indent, $self->{info};
  }
  foreach (grep !/^(info|trace|warning|critical|blacklisted|extendedinfo|flat_indices|indices)$/, sort keys %{$self}) {
    if (defined $self->{$_} && ref($self->{$_}) eq "ARRAY") {
      my $have_flat_indices = 1;
      foreach my $obj (@{$self->{$_}}) {
        $have_flat_indices = 0 if (ref($obj) ne "HASH" || ! exists $obj->{flat_indices});
      }
      if ($have_flat_indices) {
        foreach my $obj (sort {
            join('', map { sprintf("%30d",$_) } split( /\./, $a->{flat_indices})) cmp
            join('', map { sprintf("%30d",$_) } split( /\./, $b->{flat_indices}))
        } @{$self->{$_}}) {
          $obj->dump();
        }
      } else {
        foreach my $obj (@{$self->{$_}}) {
          $obj->dump() if UNIVERSAL::can($obj, "isa") && $obj->can("dump");
        }
      }
    } elsif (defined $self->{$_} && ref($self->{$_}) =~ /^Classes::/) {
      $self->{$_}->dump(2) if UNIVERSAL::can($self->{$_}, "isa") && $self->{$_}->can("dump");
    }
  }
  printf "\n";
}

sub table_ascii {
  my ($self, $table, $titles) = @_;
  my $text = "";
  my $column_length = {};
  my $column = 0;
  foreach (@{$titles}) {
    $column_length->{$column++} = length($_);
  }
  foreach my $tr (@{$table}) {
    @{$tr} = map { ref($_) eq "ARRAY" ? $_->[0] : $_; } @{$tr};
    $column = 0;
    foreach my $td (@{$tr}) {
      if (length($td) > $column_length->{$column}) {
        $column_length->{$column} = length($td);
      }
      $column++;
    }
  }
  $column = 0;
  foreach (@{$titles}) {
    $column_length->{$column} = "%".($column_length->{$column} + 3)."s";
    $column++;
  }
  $column = 0;
  foreach (@{$titles}) {
    $text .= sprintf $column_length->{$column++}, $_;
  }
  $text .= "\n";
  foreach my $tr (@{$table}) {
    $column = 0;
    foreach my $td (@{$tr}) {
      $text .= sprintf $column_length->{$column++}, $td;
    }
    $text .= "\n";
  }
  return $text;
}

sub table_html {
  my ($self, $table, $titles) = @_;
  my $text = "";
  $text .= "<table style=\"border-collapse:collapse; border: 1px solid black;\">";
  $text .= "<tr>";
  foreach (@{$titles}) {
    $text .= sprintf "<th style=\"text-align: left; padding-left: 4px; padding-right: 6px;\">%s</th>", $_;
  }
  $text .= "</tr>";
  foreach my $tr (@{$table}) {
    $text .= "<tr>";
    foreach my $td (@{$tr}) {
      my $class = "statusOK";
      if (ref($td) eq "ARRAY") {
        $class = {
          0 => "statusOK",
          1 => "statusWARNING",
          2 => "statusCRITICAL",
          3 => "statusUNKNOWN",
        }->{$td->[1]};
        $td = $td->[0];
      }
      $text .= sprintf "<td style=\"text-align: left; padding-left: 4px; padding-right: 6px;\" class=\"%s\">%s</td>", $class, $td;
    }
    $text .= "</tr>";
  }
  $text .= "</table>";
  return $text;
}

sub load_my_extension {
  my ($self) = @_;
  if ($self->opts->mode =~ /^my-([^-.]+)/) {
    my $class = $1;
    my $loaderror = undef;
    substr($class, 0, 1) = uc substr($class, 0, 1);
    if (! $self->opts->get("with-mymodules-dyn-dir")) {
      $self->override_opt("with-mymodules-dyn-dir", "");
    }
    my $plugin_name = $Monitoring::GLPlugin::pluginname;
    $plugin_name =~ /check_(.*?)_health/;
    my $deprecated_class = "DBD::".(uc $1)."::Server";
    $plugin_name = "Check".uc(substr($1, 0, 1)).substr($1, 1)."Health";
    foreach my $libpath (split(":", $self->opts->get("with-mymodules-dyn-dir"))) {
      foreach my $extmod (glob $libpath."/".$plugin_name."*.pm") {
        my $stderrvar;
        *SAVEERR = *STDERR;
        open OUT ,'>',\$stderrvar;
        *STDERR = *OUT;
        eval {
          $self->debug(sprintf "loading module %s", $extmod);
          require $extmod;
        };
        *STDERR = *SAVEERR;
        if ($@) {
          $loaderror = $extmod;
          $self->debug(sprintf "failed loading module %s: %s", $extmod, $@);
        }
      }
    }
    my $original_class = ref($self);
    my $original_init = $self->can("init");
    $self->compatibility_class() if $self->can('compatibility_class');
    bless $self, "My$class";
    $self->compatibility_methods() if $self->can('compatibility_methods') &&
        $self->isa($deprecated_class);
    if ($self->isa("Monitoring::GLPlugin")) {
      my $new_init = $self->can("init");
      if ($new_init == $original_init) {
          $self->add_unknown(
              sprintf "Class %s needs an init() method", ref($self));
      } else {
        # now go back to check_*_health.pl where init() will be called
      }
    } else {
      bless $self, $original_class;
      $self->add_unknown(
          sprintf "Class %s is not a subclass of Monitoring::GLPlugin%s",
              "My$class",
              $loaderror ? sprintf " (syntax error in %s?)", $loaderror : "" );
      my ($code, $message) = $self->check_messages(join => ', ', join_all => ', ');
      $self->nagios_exit($code, $message);
    }
  }
}

sub decode_password {
  my ($self, $password) = @_;
  if ($password && $password =~ /^rfc3986:\/\/(.*)/) {
    $password = $1;
    $password =~ s/%([A-Za-z0-9]{2})/chr(hex($1))/seg;
  }
  return $password;
}

sub number_of_bits {
  my ($self, $unit) = @_;
  # https://en.wikipedia.org/wiki/Data_rate_units
  my $bits = {
    'bit' => 1,			# Bit per second
    'B' => 8,			# Byte per second, 8 bits per second
    'kbit' => 1000,		# Kilobit per second, 1,000 bits per second
    'kb' => 1000,		# Kilobit per second, 1,000 bits per second
    'Kibit' => 1024,		# Kibibit per second, 1,024 bits per second
    'kB' => 8000,		# Kilobyte per second, 8,000 bits per second
    'KiB' => 8192,		# Kibibyte per second, 1,024 bytes per second
    'Mbit' => 1000000,		# Megabit per second, 1,000,000 bits per second
    'Mb' => 1000000,		# Megabit per second, 1,000,000 bits per second
    'Mibit' => 1048576,		# Mebibit per second, 1,024 kibibits per second
    'MB' => 8000000,		# Megabyte per second, 1,000 kilobytes per second
    'MiB' => 8388608,		# Mebibyte per second, 1,024 kibibytes per second
    'Gbit' => 1000000000,	# Gigabit per second, 1,000 megabits per second
    'Gb' => 1000000000,		# Gigabit per second, 1,000 megabits per second
    'Gibit' => 1073741824,	# Gibibit per second, 1,024 mebibits per second
    'GB' => 8000000000,		# Gigabyte per second, 1,000 megabytes per second
    'GiB' => 8589934592,	# Gibibyte per second, 8192 mebibits per second
    'Tbit' => 1000000000000,	# Terabit per second, 1,000 gigabits per second
    'Tb' => 1000000000000,	# Terabit per second, 1,000 gigabits per second
    'Tibit' => 1099511627776,	# Tebibit per second, 1,024 gibibits per second
    'TB' => 8000000000000,	# Terabyte per second, 1,000 gigabytes per second
    # eigene kreationen
    'Bits' => 1,
    'Bit' => 1,			# Bit per second
    'KB' => 1024,		# Kilobyte (like disk kilobyte)
    'KBi' => 1024,		# -"-
    'MBi' => 1024 * 1024,	# Megabyte (like disk megabyte)
    'GBi' => 1024 * 1024 * 1024, # Gigybate (like disk gigybyte)
  };
  if (exists $bits->{$unit}) {
    return $bits->{$unit};
  } else {
    return 0;
  }
}


#########################################################
# runtime methods
#
sub mode : lvalue {
  my ($self) = @_;
  $Monitoring::GLPlugin::mode;
}

sub statefilesdir {
  my ($self) = @_;
  return $Monitoring::GLPlugin::plugin->{statefilesdir};
}

sub opts { # die beiden _nicht_ in AUTOLOAD schieben, das kracht!
  my ($self) = @_;
  return $Monitoring::GLPlugin::plugin->opts();
}

sub getopts {
  my ($self, $envparams) = @_;
  $envparams ||= [];
  my $needs_restart = 0;
  my @restart_opts = ();
  $Monitoring::GLPlugin::plugin->getopts();
  # es kann sein, dass beim aufraeumen zum schluss als erstes objekt
  # das $Monitoring::GLPlugin::plugin geloescht wird. in anderen destruktoren
  # (insb. fuer dbi disconnect) steht dann $self->opts->verbose
  # nicht mehr zur verfuegung bzw. $Monitoring::GLPlugin::plugin->opts ist undef.
  $self->set_variable("verbose", $self->opts->verbose);
  #
  # die gueltigkeit von modes wird bereits hier geprueft und nicht danach
  # in validate_args. (zwischen getopts und validate_args wird
  # normalerweise classify aufgerufen, welches bereits eine verbindung
  # zum endgeraet herstellt. bei falschem mode waere das eine verschwendung
  # bzw. durch den exit3 ein evt. unsauberes beenden der verbindung.
  if ((! grep { $self->opts->mode eq $_ } map { $_->{spec} } @{$Monitoring::GLPlugin::plugin->{modes}}) &&
      (! grep { $self->opts->mode eq $_ } map { defined $_->{alias} ? @{$_->{alias}} : () } @{$Monitoring::GLPlugin::plugin->{modes}})) {
    if ($self->opts->mode !~ /^my-/) {
      printf "UNKNOWN - mode %s\n", $self->opts->mode;
      $self->opts->print_help();
      exit 3;
    }
  }
  if ($self->opts->environment) {
    # wenn die gewuenschten Environmentvariablen sich von den derzeit
    # gesetzten unterscheiden, dann restart. Denn $ENV aendert
    # _nicht_ das Environment des laufenden Prozesses. 
    # $ENV{ZEUGS} = 1 bedeutet lediglich, dass $ENV{ZEUGS} bei weiterer
    # Verwendung 1 ist, bedeutet aber _nicht_, dass diese Variable 
    # im Environment des laufenden Prozesses existiert.
    foreach (keys %{$self->opts->environment}) {
      if ((! $ENV{$_}) || ($ENV{$_} ne $self->opts->environment->{$_})) {
        $needs_restart = 1;
        $ENV{$_} = $self->opts->environment->{$_};
        $self->debug(sprintf "new %s=%s forces restart\n", $_, $ENV{$_});
      }
    }
  }
  if ($self->opts->runas) {
    # exec sudo $0 ... und dann ohne --runas
    $needs_restart = 1;
    # wenn wir environmentvariablen haben, die laut survive_sudo_env als
    # wichtig erachtet werden, dann muessen wir die ueber einen moeglichen
    # sudo-aufruf rueberretten, also in zusaetzliche --environment umwandenln.
    # sudo putzt das Environment naemlich aus.
    foreach my $survive_env (@{$Monitoring::GLPlugin::survive_sudo_env}) {
      if ($ENV{$survive_env} && ! scalar(grep { /^$survive_env=/ }
          keys %{$self->opts->environment})) {
        $self->opts->environment->{$survive_env} = $ENV{$survive_env};
        printf STDERR "add important --environment %s=%s\n",
            $survive_env, $ENV{$survive_env} if $self->opts->verbose >= 2;
        push(@restart_opts, '--environment');
        push(@restart_opts, sprintf '%s=%s',
            $survive_env, $ENV{$survive_env});
      }
    }
  }
  if ($needs_restart) {
    foreach my $option (keys %{$self->opts->all_my_opts}) {
      # der fliegt raus, sonst gehts gleich wieder in needs_restart rein
      next if $option eq "runas";
      foreach my $spec (map { $_->{spec} } @{$Monitoring::GLPlugin::plugin->opts->{_args}}) {
        if ($spec =~ /^(\w+)=(.*)/) {
          if ($1 eq $option && $2 =~ /s%/) {
            foreach (keys %{$self->opts->$option()}) {
              push(@restart_opts, sprintf "--%s", $option);
              push(@restart_opts, sprintf "%s=%s", $_, $self->opts->$option()->{$_});
            }
          } elsif ($1 eq $option) {
            push(@restart_opts, sprintf "--%s", $option);
            push(@restart_opts, sprintf "%s", $self->opts->$option());
          }
        } elsif ($spec eq $option) {
          push(@restart_opts, sprintf "--%s", $option);
        }
      }
    }
    if ($self->opts->runas && ($> == 0)) {
      # Ja, es gibt so Narrische, die gehen mit check_by_ssh als root
      # auf Datenbankmaschinen drauf und lassen dann dort check_oracle_health
      # laufen. Damit OPS$-Anmeldung dann funktioniert, wird mit --runas
      # auf eine andere Kennung umgeschwenkt. Diese Kennung gleich fuer
      # ssh zu verwenden geht aus Sicherheitsgruenden nicht. Narrische halt.
      exec "su", "-c", sprintf("%s %s", $0, join(" ", @restart_opts)), "-", $self->opts->runas;
    } elsif ($self->opts->runas) {
      exec "sudo", "-S", "-u", $self->opts->runas, $0, @restart_opts;
    } else {
      exec $0, @restart_opts;
      # dadurch werden SHLIB oder LD_LIBRARY_PATH sauber gesetzt, damit beim
      # erneuten Start libclntsh.so etc. gefunden werden.
    }
    exit;
  }
  if ($self->opts->shell) {
    # So komme ich bei den Narrischen zu einer root-Shell.
    system("/bin/sh");
  }
}


sub add_ok {
  my ($self, $message) = @_;
  $message ||= $self->{info};
  $self->add_message(OK, $message);
}

sub add_warning {
  my ($self, $message) = @_;
  $message ||= $self->{info};
  $self->add_message(WARNING, $message);
}

sub add_critical {
  my ($self, $message) = @_;
  $message ||= $self->{info};
  $self->add_message(CRITICAL, $message);
}

sub add_unknown {
  my ($self, $message) = @_;
  $message ||= $self->{info};
  $self->add_message(UNKNOWN, $message);
}

sub add_ok_mitigation {
  my ($self, $message) = @_;
  if (defined $self->opts->mitigation()) {
    $self->add_message($self->opts->mitigation(), $message);
  } else {
    $self->add_ok($message);
  }
}

sub add_warning_mitigation {
  my ($self, $message) = @_;
  if (defined $self->opts->mitigation()) {
    $self->add_message($self->opts->mitigation(), $message);
  } else {
    $self->add_warning($message);
  }
}

sub add_critical_mitigation {
  my ($self, $message) = @_;
  if (defined $self->opts->mitigation()) {
    $self->add_message($self->opts->mitigation(), $message);
  } else {
    $self->add_critical($message);
  }
}

sub add_unknown_mitigation {
  my ($self, $message) = @_;
  if (defined $self->opts->mitigation()) {
    $self->add_message($self->opts->mitigation(), $message);
  } else {
    $self->add_unknown($message);
  }
}

sub add_message {
  my ($self, $level, $message) = @_;
  $message ||= $self->{info};
  $Monitoring::GLPlugin::plugin->add_message($level, $message)
      unless $self->is_blacklisted();
  if (exists $self->{failed}) {
    if ($level == UNKNOWN && $self->{failed} == OK) {
      $self->{failed} = $level;
    } elsif ($level > $self->{failed}) {
      $self->{failed} = $level;
    }
  }
}

sub clear_ok {
  my ($self) = @_;
  $self->clear_messages(OK);
}

sub clear_warning {
  my ($self) = @_;
  $self->clear_messages(WARNING);
}

sub clear_critical {
  my ($self) = @_;
  $self->clear_messages(CRITICAL);
}

sub clear_unknown {
  my ($self) = @_;
  $self->clear_messages(UNKNOWN);
}

sub clear_all { # deprecated, use clear_messages
  my ($self) = @_;
  $self->clear_ok();
  $self->clear_warning();
  $self->clear_critical();
  $self->clear_unknown();
}

sub set_level {
  my ($self, $code) = @_;
  $code = (qw(ok warning critical unknown))[$code] if $code =~ /^\d+$/;
  $code = lc $code;
  if (! exists $self->{tmp_level}) {
    $self->{tmp_level} = {
      ok => 0,
      warning => 0,
      critical => 0,
      unknown => 0,
    };
  }
  $self->{tmp_level}->{$code}++;
}

sub get_level {
  my ($self) = @_;
  return OK if ! exists $self->{tmp_level};
  my $code = OK;
  $code ||= CRITICAL if $self->{tmp_level}->{critical};
  $code ||= WARNING  if $self->{tmp_level}->{warning};
  $code ||= UNKNOWN  if $self->{tmp_level}->{unknown};
  return $code;
}

#########################################################
# blacklisting
#
sub blacklist {
  my ($self) = @_;
  $self->{blacklisted} = 1;
}

sub add_blacklist {
  my ($self, $list) = @_;
  $Monitoring::GLPlugin::blacklist = join('/',
      (split('/', $self->opts->blacklist), $list));
}

sub is_blacklisted {
  my ($self) = @_;
  if (! $self->opts->can("blacklist")) {
    return 0;
  }
  if (! exists $self->{blacklisted}) {
    $self->{blacklisted} = 0;
  }
  if (exists $self->{blacklisted} && $self->{blacklisted}) {
    return $self->{blacklisted};
  }
  # FAN:459,203/TEMP:102229/ENVSUBSYSTEM
  # FAN_459,FAN_203,TEMP_102229,ENVSUBSYSTEM
  if ($self->opts->blacklist =~ /_/) {
    foreach my $bl_item (split(/,/, $self->opts->blacklist)) {
      if ($bl_item eq $self->internal_name()) {
        $self->{blacklisted} = 1;
      }
    }
  } else {
    foreach my $bl_items (split(/\//, $self->opts->blacklist)) {
      if ($bl_items =~ /^(\w+):([\:\d\-,]+)$/) {
        my $bl_type = $1;
        my $bl_names = $2;
        foreach my $bl_name (split(/,/, $bl_names)) {
          if ($bl_type."_".$bl_name eq $self->internal_name()) {
            $self->{blacklisted} = 1;
          }
        }
      } elsif ($bl_items =~ /^(\w+)$/) {
        if ($bl_items eq $self->internal_name()) {
          $self->{blacklisted} = 1;
        }
      }
    }
  }
  return $self->{blacklisted};
}

#########################################################
# additional info
#
sub add_info {
  my ($self, $info) = @_;
  $info = $self->is_blacklisted() ? $info.' (blacklisted)' : $info;
  $self->{info} = $info;
  push(@{$Monitoring::GLPlugin::info}, $info);
}

sub annotate_info {
  my ($self, $annotation) = @_;
  my $lastinfo = pop(@{$Monitoring::GLPlugin::info});
  $lastinfo .= sprintf ' (%s)', $annotation;
  $self->{info} = $lastinfo;
  push(@{$Monitoring::GLPlugin::info}, $lastinfo);
}

sub add_extendedinfo {  # deprecated
  my ($self, $info) = @_;
  $self->{extendedinfo} = $info;
  return if ! $self->opts->extendedinfo;
  push(@{$Monitoring::GLPlugin::extendedinfo}, $info);
}

sub get_info {
  my ($self, $separator) = @_;
  $separator ||= ' ';
  return join($separator , @{$Monitoring::GLPlugin::info});
}

sub get_last_info {
  my ($self) = @_;
  return pop(@{$Monitoring::GLPlugin::info});
}

sub get_extendedinfo {
  my ($self, $separator) = @_;
  $separator ||= ' ';
  return join($separator, @{$Monitoring::GLPlugin::extendedinfo});
}

sub add_summary {  # deprecated
  my ($self, $summary) = @_;
  push(@{$Monitoring::GLPlugin::summary}, $summary);
}

sub get_summary {
  my ($self) = @_;
  return join(', ', @{$Monitoring::GLPlugin::summary});
}

#########################################################
# persistency
#
sub valdiff {
  my ($self, $pparams, @keys) = @_;
  my %params = %{$pparams};
  my $now = time;
  my $newest_history_set = {};
  $params{freeze} = 0 if ! $params{freeze};
  my $mode = "normal";
  if ($self->opts->lookback && $self->opts->lookback == 99999 && $params{freeze} == 0) {
    $mode = "lookback_freeze_chill";
  } elsif ($self->opts->lookback && $self->opts->lookback == 99999 && $params{freeze} == 1) {
    $mode = "lookback_freeze_shockfrost";
  } elsif ($self->opts->lookback && $self->opts->lookback == 99999 && $params{freeze} == 2) {
    $mode = "lookback_freeze_defrost";
  } elsif ($self->opts->lookback) {
    $mode = "lookback";
  }
  # lookback=99999, freeze=0(default)
  #  nimm den letzten lauf und schreib ihn nach {cold}
  #  vergleich dann
  #    wenn es frozen gibt, vergleich frozen und den letzten lauf
  #    sonst den letzten lauf und den aktuellen lauf
  # lookback=99999, freeze=1
  #  wird dann aufgerufen,wenn nach dem freeze=0 ein problem festgestellt wurde
  #     (also als 2.valdiff hinterher)
  #  schreib cold nach frozen
  # lookback=99999, freeze=2
  #  wird dann aufgerufen,wenn nach dem freeze=0 wieder alles ok ist
  #     (also als 2.valdiff hinterher)
  #  loescht frozen
  #
  my $last_values = $self->load_state(%params) || eval {
    my $empty_events = {};
    foreach (@keys) {
      if (ref($self->{$_}) eq "ARRAY") {
        $empty_events->{$_} = [];
      } else {
        $empty_events->{$_} = 0;
      }
    }
    $empty_events->{timestamp} = 0;
    if ($mode eq "lookback") {
      $empty_events->{lookback_history} = {};
    } elsif ($mode eq "lookback_freeze_chill") {
      $empty_events->{cold} = {};
      $empty_events->{frozen} = {};
    }
    $empty_events;
  };
  $self->{'delta_timestamp'} = $now - $last_values->{timestamp};
  foreach (@keys) {
    if ($mode eq "lookback_freeze_chill") {
      # die werte vom letzten lauf wegsichern.
      # vielleicht gibts gleich einen freeze=1, dann muessen die eingefroren werden
      if (exists $last_values->{$_}) {
        if (ref($self->{$_}) eq "ARRAY") {
          $last_values->{cold}->{$_} = [];
          foreach my $value (@{$last_values->{$_}}) {
            push(@{$last_values->{cold}->{$_}}, $value);
          }
        } else {
          $last_values->{cold}->{$_} = $last_values->{$_};
        }
      } else {
        if (ref($self->{$_}) eq "ARRAY") {
          $last_values->{cold}->{$_} = [];
        } else {
          $last_values->{cold}->{$_} = 0;
        }
      }
      # es wird so getan, als sei der frozen wert vom letzten lauf
      if (exists $last_values->{frozen}->{$_}) {
        if (ref($self->{$_}) eq "ARRAY") {
          $last_values->{$_} = [];
          foreach my $value (@{$last_values->{frozen}->{$_}}) {
            push(@{$last_values->{$_}}, $value);
          }
        } else {
          $last_values->{$_} = $last_values->{frozen}->{$_};
        }
      }
    } elsif ($mode eq "lookback") {
      # find a last_value in the history which fits lookback best
      # and overwrite $last_values->{$_} with historic data
      if (exists $last_values->{lookback_history}->{$_}) {
        foreach my $date (sort {$a <=> $b} keys %{$last_values->{lookback_history}->{$_}}) {
            $newest_history_set->{$_} = $last_values->{lookback_history}->{$_}->{$date};
            $newest_history_set->{timestamp} = $date;
        }
        foreach my $date (sort {$a <=> $b} keys %{$last_values->{lookback_history}->{$_}}) {
          if ($date >= ($now - $self->opts->lookback)) {
            $last_values->{$_} = $last_values->{lookback_history}->{$_}->{$date};
            $last_values->{timestamp} = $date;
            $self->{'delta_timestamp'} = $now - $last_values->{timestamp};
            if (ref($last_values->{$_}) eq "ARRAY") {
              $self->debug(sprintf "oldest value of %s within lookback is size %s (age %d)",
                  $_, scalar(@{$last_values->{$_}}), $now - $date);
            } else {
              $self->debug(sprintf "oldest value of %s within lookback is %s (age %d)",
                  $_, $last_values->{$_}, $now - $date);
            }
            last;
          } else {
            $self->debug(sprintf "deprecate %s of age %d", $_, time - $date);
            delete $last_values->{lookback_history}->{$_}->{$date};
          }
        }
      }
    }
    if ($mode eq "normal" || $mode eq "lookback" || $mode eq "lookback_freeze_chill") {
      if (exists $self->{$_} && defined $self->{$_} && $self->{$_} =~ /^\d+\.*\d*$/) {
        $last_values->{$_} = 0 if ! (exists $last_values->{$_} && defined $last_values->{$_});
        if ($self->{$_} >= $last_values->{$_}) {
          $self->{'delta_'.$_} = $self->{$_} - $last_values->{$_};
        } elsif ($self->{$_} eq $last_values->{$_}) {
          # dawischt! in einem fall wurde 131071.999023438 >= 131071.999023438 da oben nicht erkannt
          # subtrahieren ging auch daneben, weil ein winziger negativer wert rauskam.
          $self->{'delta_'.$_} = 0;
        } else {
          if ($mode =~ /lookback_freeze/) {
            # hier koennen delta-werte auch negativ sein, wenn z.b. peers verschwinden
            $self->{'delta_'.$_} = $self->{$_} - $last_values->{$_};
          } elsif (exists $params{lastarray}) {
            $self->{'delta_'.$_} = $self->{$_} - $last_values->{$_};
          } else {
            # vermutlich db restart und zaehler alle auf null
            $self->{'delta_'.$_} = $self->{$_};
          }
        }
        $self->debug(sprintf "delta_%s %f", $_, $self->{'delta_'.$_});
        $self->{$_.'_per_sec'} = $self->{'delta_timestamp'} ?
            $self->{'delta_'.$_} / $self->{'delta_timestamp'} : 0;
      } elsif (ref($self->{$_}) eq "ARRAY") {
        if ((! exists $last_values->{$_} || ! defined $last_values->{$_}) && exists $params{lastarray}) {
          # innerhalb der lookback-zeit wurde nichts in der lookback_history
          # gefunden. allenfalls irgendwas aelteres. normalerweise
          # wuerde jetzt das array als [] initialisiert.
          # d.h. es wuerde ein delta geben, @found s.u.
          # wenn man das nicht will, sondern einfach aktuelles array mit
          # dem array des letzten laufs vergleichen will, setzt man lastarray
          $last_values->{$_} = %{$newest_history_set} ?
              $newest_history_set->{$_} : []
        } elsif ((! exists $last_values->{$_} || ! defined $last_values->{$_}) && ! exists $params{lastarray}) {
          $last_values->{$_} = [] if ! exists $last_values->{$_};
        } elsif (exists $last_values->{$_} && ! defined $last_values->{$_}) {
          # $_ kann es auch ausserhalb des lookback_history-keys als normalen
          # key geben. der zeigt normalerweise auf den entspr. letzten
          # lookback_history eintrag. wurde der wegen ueberalterung abgeschnitten
          # ist der hier auch undef.
          $last_values->{$_} = %{$newest_history_set} ?
              $newest_history_set->{$_} : []
        }
        my %saved = map { $_ => 1 } @{$last_values->{$_}};
        my %current = map { $_ => 1 } @{$self->{$_}};
        my @found = grep(!defined $saved{$_}, @{$self->{$_}});
        my @lost = grep(!defined $current{$_}, @{$last_values->{$_}});
        $self->{'delta_found_'.$_} = \@found;
        $self->{'delta_lost_'.$_} = \@lost;
      } else {
        # nicht ganz sauber, aber das artet aus, wenn man jedem uninitialized hinterherstochert.
        # wem das nicht passt, der kann gerne ein paar tage debugging beauftragen.
        # das kostet aber mehr als drei kugeln eis.
        $last_values->{$_} = 0 if ! (exists $last_values->{$_} && defined $last_values->{$_});
        $self->{$_} = 0 if ! (exists $self->{$_} && defined $self->{$_});
        $self->{'delta_'.$_} = 0;
      }
    }
  }
  $params{save} = eval {
    my $empty_events = {};
    foreach (@keys) {
      $empty_events->{$_} = $self->{$_};
      if ($mode =~ /lookback_freeze/) {
        if (exists $last_values->{frozen}->{$_}) {
          if (ref($last_values->{frozen}->{$_}) eq "ARRAY") {
            @{$empty_events->{cold}->{$_}} = @{$last_values->{frozen}->{$_}};
          } else {
            $empty_events->{cold}->{$_} = $last_values->{frozen}->{$_};
          }
        } else {
          if (ref($last_values->{cold}->{$_}) eq "ARRAY") {
            @{$empty_events->{cold}->{$_}} = @{$last_values->{cold}->{$_}};
          } else {
            $empty_events->{cold}->{$_} = $last_values->{cold}->{$_};
          }
        }
        $empty_events->{cold}->{timestamp} = $last_values->{cold}->{timestamp};
      }
      if ($mode eq "lookback_freeze_shockfrost") {
        if (ref($empty_events->{cold}->{$_}) eq "ARRAY") {
          @{$empty_events->{frozen}->{$_}} = @{$empty_events->{cold}->{$_}};
        } else {
          $empty_events->{frozen}->{$_} = $empty_events->{cold}->{$_};
        }
        $empty_events->{frozen}->{timestamp} = $now;
      }
    }
    $empty_events->{timestamp} = $now;
    if ($mode eq "lookback") {
      $empty_events->{lookback_history} = $last_values->{lookback_history};
      foreach (@keys) {
        if (ref($self->{$_}) eq "ARRAY") {
          @{$empty_events->{lookback_history}->{$_}->{$now}} = @{$self->{$_}};
        } else {
          $empty_events->{lookback_history}->{$_}->{$now} = $self->{$_};
        }
      }
    }
    if ($mode eq "lookback_freeze_defrost") {
      delete $empty_events->{freeze};
    }
    $empty_events;
  };
  $self->save_state(%params);
}

sub create_statefilesdir {
  my ($self) = @_;
  if (! -d $self->statefilesdir()) {
    eval {
      use File::Path;
      mkpath $self->statefilesdir();
    };
    if ($@ || ! -w $self->statefilesdir()) {
      $self->add_message(UNKNOWN,
        sprintf "cannot create status dir %s! check your filesystem (permissions/usage/integrity) and disk devices", $self->statefilesdir());
    }
  } elsif (! -w $self->statefilesdir()) {
    $self->add_message(UNKNOWN,
        sprintf "cannot write status dir %s! check your filesystem (permissions/usage/integrity) and disk devices", $self->statefilesdir());
  }
}

sub create_statefile {
  my ($self, %params) = @_;
  my $extension = "";
  $extension .= $params{name} ? '_'.$params{name} : '';
  $extension =~ s/\//_/g;
  $extension =~ s/\(/_/g;
  $extension =~ s/\)/_/g;
  $extension =~ s/\*/_/g;
  $extension =~ s/\s/_/g;
  return sprintf "%s/%s%s", $self->statefilesdir(),
      $self->clean_path($self->mode), $self->clean_path(lc $extension);
}

sub clean_path {
  my ($self, $path) = @_;
  if ($^O =~ /MSWin/) {
    $path =~ s/:/_/g;
  }
  return $path;
}

sub schimpf {
  my ($self) = @_;
  printf "statefilesdir %s is not writable.\nYou didn't run this plugin as root, didn't you?\n", $self->statefilesdir();
}

# $self->protect_value('1.1-flat_index', 'cpu_busy', 'percent');
sub protect_value {
  my ($self, $ident, $key, $validfunc) = @_;
  if (ref($validfunc) ne "CODE" && $validfunc eq "percent") {
    $validfunc = sub {
      my $value = shift;
      return 0 if ! defined $value;
      return 0 if $value !~ /^[-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
      return ($value < 0 || $value > 100) ? 0 : 1;
    };
  } elsif (ref($validfunc) ne "CODE" && $validfunc eq "positive") {
    $validfunc = sub {
      my $value = shift;
      return 0 if ! defined $value;
      return 0 if $value !~ /^[-+]?([0-9]+(\.[0-9]+)?|\.[0-9]+)$/;
      return ($value < 0) ? 0 : 1;
    };
  }
  if (&$validfunc($self->{$key})) {
    $self->save_state(name => 'protect_'.$ident.'_'.$key, save => {
        $key => $self->{$key},
        exception => 0,
    });
  } else {
    # if the device gives us an clearly wrong value, simply use the last value.
    my $laststate = $self->load_state(name => 'protect_'.$ident.'_'.$key);
    $self->debug(sprintf "self->{%s} is %s and invalid for the %dth time",
        $key, $self->{$key}, $laststate->{exception} + 1);
    if ($laststate->{exception} <= 5) {
      # but only 5 times.
      # if the error persists, somebody has to check the device.
      $self->{$key} = $laststate->{$key};
    }
    $self->save_state(name => 'protect_'.$ident.'_'.$key, save => {
        $key => $laststate->{$key},
        exception => ++$laststate->{exception},
    });
  }
}

sub save_state {
  my ($self, %params) = @_;
  $self->create_statefilesdir();
  my $statefile = $self->create_statefile(%params);
  my $tmpfile = $self->statefilesdir().'/check__health_tmp_'.$$;
  if ((ref($params{save}) eq "HASH") && exists $params{save}->{timestamp}) {
    $params{save}->{localtime} = scalar localtime $params{save}->{timestamp};
  }
  my $seekfh = IO::File->new();
  if ($seekfh->open($tmpfile, "w")) {
    $seekfh->printf("%s", Data::Dumper::Dumper($params{save}));
    $seekfh->flush();
    $seekfh->close();
    $self->debug(sprintf "saved %s to %s",
        Data::Dumper::Dumper($params{save}), $statefile);
  }
  if (! rename $tmpfile, $statefile) {
    $self->add_message(UNKNOWN,
        sprintf "cannot write status file %s! check your filesystem (permissions/usage/integrity) and disk devices", $statefile);
  }
}

sub load_state {
  my ($self, %params) = @_;
  my $statefile = $self->create_statefile(%params);
  if ( -f $statefile) {
    our $VAR1;
    eval {
      delete $INC{$statefile} if exists $INC{$statefile}; # else unit tests fail
      require $statefile;
    };
    if($@) {
      printf "rumms\n";
    }
    $self->debug(sprintf "load %s from %s", Data::Dumper::Dumper($VAR1), $statefile);
    return $VAR1;
  } else {
    return undef;
  }
}

#########################################################
# daemon mode
#
sub check_pidfile {
  my ($self) = @_;
  my $fh = IO::File->new();
  if ($fh->open($self->{pidfile}, "r")) {
    my $pid = $fh->getline();
    $fh->close();
    if (! $pid) {
      $self->debug("Found pidfile %s with no valid pid. Exiting.",
          $self->{pidfile});
      return 0;
    } else {
      $self->debug("Found pidfile %s with pid %d", $self->{pidfile}, $pid);
      kill 0, $pid;
      if ($! == Errno::ESRCH) {
        $self->debug("This pidfile is stale. Writing a new one");
        $self->write_pidfile();
        return 1;
      } else {
        $self->debug("This pidfile is held by a running process. Exiting");
        return 0;
      }
    }
  } else {
    $self->debug("Found no pidfile. Writing a new one");
    $self->write_pidfile();
    return 1;
  }
}

sub write_pidfile {
  my ($self) = @_;
  if (! -d dirname($self->{pidfile})) {
    eval "require File::Path;";
    if (defined(&File::Path::mkpath)) {
      import File::Path;
      eval { mkpath(dirname($self->{pidfile})); };
    } else {
      my @dirs = ();
      map {
          push @dirs, $_;
          mkdir(join('/', @dirs))
              if join('/', @dirs) && ! -d join('/', @dirs);
      } split(/\//, dirname($self->{pidfile}));
    }
  }
  my $fh = IO::File->new();
  $fh->autoflush(1);
  if ($fh->open($self->{pidfile}, "w")) {
    $fh->printf("%s", $$);
    $fh->close();
  } else {
    $self->debug("Could not write pidfile %s", $self->{pidfile});
    die "pid file could not be written";
  }
}

sub system_vartmpdir {
  my ($self) = @_;
  if ($^O =~ /MSWin/) {
    return $self->system_tmpdir();
  } else {
    return "/var/tmp/".$Monitoring::GLPlugin::pluginname;
  }
}

sub system_tmpdir {
  my ($self) = @_;
  if ($^O =~ /MSWin/) {
    return $ENV{TEMP} if defined $ENV{TEMP};
    return $ENV{TMP} if defined $ENV{TMP};
    return File::Spec->catfile($ENV{windir}, 'Temp')
        if defined $ENV{windir};
    return 'C:\Temp';
  } else {
    return "/tmp";
  }
}

sub convert_scientific_numbers {
  my ($self, $n) = @_;
  # mostly used to convert numbers in scientific notation
  if ($n =~ /^\s*\d+\s*$/) {
    return $n;
  } elsif ($n =~ /^\s*([-+]?)(\d*[\.,]*\d*)[eE]{1}([-+]?)(\d+)\s*$/) {
    my ($vor, $num, $sign, $exp) = ($1, $2, $3, $4);
    $n =~ s/E/e/g;
    $n =~ s/,/\./g;
    $num =~ s/,/\./g;
    my $sig = $sign eq '-' ? "." . ($exp - 1 + length $num) : '';
    my $dec = sprintf "%${sig}f", $n;
    $dec =~ s/\.[0]+$//g;
    return $dec;
  } elsif ($n =~ /^\s*([-+]?)(\d+)[\.,]*(\d*)\s*$/) {
    return $1.$2.".".$3;
  } elsif ($n =~ /^\s*(.*?)\s*$/) {
    return $1;
  } else {
    return $n;
  }
}

sub compatibility_methods {
  my ($self) = @_;
  # add_perfdata
  # add_message
  # nagios_exit
  # ->{warningrange}
  # ->{criticalrange}
  # ...
  $self->{warningrange} = ($self->get_thresholds())[0];
  $self->{criticalrange} = ($self->get_thresholds())[1];
  my $old_init = $self->can('init');
  my %params = (
    'mode' => join('::', split(/-/, $self->opts->mode)),
    'name' => $self->opts->name,
    'name2' => $self->opts->name2,
  );
  {
    no strict 'refs';
    no warnings 'redefine';
    *{ref($self).'::init'} = sub {
      $self->$old_init(%params);
      $self->nagios(%params);
    };
    *{ref($self).'::add_nagios'} = \&{"Monitoring::GLPlugin::add_message"};
    *{ref($self).'::add_nagios_ok'} = \&{"Monitoring::GLPlugin::add_ok"};
    *{ref($self).'::add_nagios_warning'} = \&{"Monitoring::GLPlugin::add_warning"};
    *{ref($self).'::add_nagios_critical'} = \&{"Monitoring::GLPlugin::add_critical"};
    *{ref($self).'::add_nagios_unknown'} = \&{"Monitoring::GLPlugin::add_unknown"};
    *{ref($self).'::add_perfdata'} = sub {
      my $self = shift;
      my $message = shift;
      foreach my $perfdata (split(/\s+/, $message)) {
      my ($label, $perfstr) = split(/=/, $perfdata);
      my ($value, $warn, $crit, $min, $max) = split(/;/, $perfstr);
      $value =~ /^([\d\.\-\+]+)(.*)$/;
      $value = $1;
      my $uom = $2;
      $Monitoring::GLPlugin::plugin->add_perfdata(
        label => $label,
        value => $value,
        uom => $uom,
        warn => $warn,
        crit => $crit,
        min => $min,
        max => $max,
      );
      }
    };
    *{ref($self).'::check_thresholds'} = sub {
      my $self = shift;
      my $value = shift;
      my $defaultwarningrange = shift;
      my $defaultcriticalrange = shift;
      $Monitoring::GLPlugin::plugin->set_thresholds(
          metric => 'default',
          warning => $defaultwarningrange,
          critical => $defaultcriticalrange,
      );
      $self->{warningrange} = ($self->get_thresholds())[0];
      $self->{criticalrange} = ($self->get_thresholds())[1];
      return $Monitoring::GLPlugin::plugin->check_thresholds(
          metric => 'default',
          value => $value,
          warning => $defaultwarningrange,
          critical => $defaultcriticalrange,
      );
    };
  }
}

sub AUTOLOAD {
  my ($self, @params) = @_;
  return if ($AUTOLOAD =~ /DESTROY/);
  $self->debug("AUTOLOAD %s\n", $AUTOLOAD)
        if $self->opts->verbose >= 2;
  if ($AUTOLOAD =~ /^(.*)::analyze_and_check_(.*)_subsystem$/) {
    my $class = $1;
    my $subsystem = $2;
    my $analyze = sprintf "analyze_%s_subsystem", $subsystem;
    my $check = sprintf "check_%s_subsystem", $subsystem;
    if (@params) {
      # analyzer class
      my $subsystem_class = shift @params;
      $self->{components}->{$subsystem.'_subsystem'} = $subsystem_class->new();
      $self->debug(sprintf "\$self->{components}->{%s_subsystem} = %s->new()",
          $subsystem, $subsystem_class);
    } else {
      $self->$analyze();
      $self->debug("call %s()", $analyze);
    }
    $self->$check();
  } elsif ($AUTOLOAD =~ /^(.*)::check_(.*)_subsystem$/) {
    my $class = $1;
    my $subsystem = sprintf "%s_subsystem", $2;
    $self->{components}->{$subsystem}->check();
    $self->{components}->{$subsystem}->dump()
        if $self->opts->verbose >= 2;
  } elsif ($AUTOLOAD =~ /^.*::(status_code|check_messages|nagios_exit|html_string|perfdata_string|selected_perfdata|check_thresholds|get_thresholds|opts|pandora_string|strequal)$/) {
    return $Monitoring::GLPlugin::plugin->$1(@params);
  } elsif ($AUTOLOAD =~ /^.*::(reduce_messages|reduce_messages_short|clear_messages|suppress_messages|add_html|add_perfdata|override_opt|create_opt|set_thresholds|force_thresholds|add_pandora)$/) {
    $Monitoring::GLPlugin::plugin->$1(@params);
  } elsif ($AUTOLOAD =~ /^.*::mod_arg_(.*)$/) {
    return $Monitoring::GLPlugin::plugin->mod_arg($1, @params);
  } else {
    $self->debug("AUTOLOAD: class %s has no method %s\n",
        ref($self), $AUTOLOAD);
  }
}



package Monitoring::GLPlugin::Item;
our @ISA = qw(Monitoring::GLPlugin);

use strict;

sub new {
  my ($class, %params) = @_;
  my $self = {
    blacklisted => 0,
    info => undef,
    extendedinfo => undef,
  };
  bless $self, $class;
  $self->init(%params);
  return $self;
}

sub check {
  my ($self, $lists) = @_;
  my @lists = $lists ? @{$lists} : grep { ref($self->{$_}) eq "ARRAY" } keys %{$self};
  foreach my $list (@lists) {
    $self->add_info('checking '.$list);
    foreach my $element (@{$self->{$list}}) {
      $element->blacklist() if $self->is_blacklisted();
      $element->check();
    }
  }
}



package Monitoring::GLPlugin::TableItem;
our @ISA = qw(Monitoring::GLPlugin::Item);

use strict;

sub new {
  my ($class, %params) = @_;
  my $self = {};
  bless $self, $class;
  foreach (keys %params) {
    $self->{$_} = $params{$_};
  }
  if ($self->can("finish")) {
    $self->finish(%params);
  }
  return $self;
}

sub check {
  my ($self) = @_;
  # some tableitems are not checkable, they are only used to enhance other
  # items (e.g. sensorthresholds enhance sensors)
  # normal tableitems should have their own check-method
}



package Monitoring::GLPlugin::SNMP;
our @ISA = qw(Monitoring::GLPlugin);
# ABSTRACT: helper functions to build a snmp-based monitoring plugin

use strict;
use File::Basename;
use Digest::MD5 qw(md5_hex);
use Module::Load;
use AutoLoader;
our $AUTOLOAD;

use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };

{
  our $mode = undef;
  our $plugin = undef;
  our $blacklist = undef;
  our $session = undef;
  our $rawdata = {};
  our $tablecache = {};
  our $info = [];
  our $extendedinfo = [];
  our $summary = [];
  our $oidtrace = [];
  our $uptime = 0;
}

sub new {
  my ($class, %params) = @_;
  require Monitoring::GLPlugin
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::;
  require Monitoring::GLPlugin::SNMP::MibsAndOids
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::SNMP::MibsAndOids::;
  require Monitoring::GLPlugin::SNMP::CSF
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::SNMP::CSF::;
  require Monitoring::GLPlugin::SNMP::Item
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::SNMP::Item::;
  require Monitoring::GLPlugin::SNMP::TableItem
      if ! grep /BEGIN/, keys %Monitoring::GLPlugin::SNMP::TableItem::;
  my $self = Monitoring::GLPlugin->new(%params);
  bless $self, $class;
  return $self;
}

sub v2tov3 {
  my ($self) = @_;
  if ($self->opts->community && $self->opts->community =~ /^snmpv3(.)(.+)/) {
    my $separator = $1;
    my ($authprotocol, $authpassword, $privprotocol, $privpassword,
        $username, $contextengineid, $contextname) = split(/$separator/, $2);
    $self->override_opt('authprotocol', $authprotocol)
        if defined($authprotocol) && $authprotocol;
    $self->override_opt('authpassword', $authpassword)
        if defined($authpassword) && $authpassword;
    $self->override_opt('privprotocol', $privprotocol)
        if defined($privprotocol) && $privprotocol;
    $self->override_opt('privpassword', $privpassword)
        if defined($privpassword) && $privpassword;
    $self->override_opt('username', $username) 
        if defined($username) && $username;
    $self->override_opt('contextengineid', $contextengineid)
        if defined($contextengineid) && $contextengineid;
    $self->override_opt('contextname', $contextname)
        if defined($contextname) && $contextname;
    $self->override_opt('community', undef) ;
    $self->override_opt('protocol', '3') ;
  }
  if (($self->opts->authpassword || $self->opts->authprotocol ||
      $self->opts->privpassword || $self->opts->privprotocol) && 
      $self->opts->protocol ne '3') {
    $self->override_opt('protocol', '3') ;
  }
  if ($self->opts->community2 && $self->opts->community2 =~ /^snmpv3(.)(.+)/) {
    my $separator = $1;
    $self->create_opt('authprotocol2');
    $self->create_opt('authpassword2');
    $self->create_opt('privprotocol2');
    $self->create_opt('privpassword2');
    $self->create_opt('username2');
    $self->create_opt('contextengineid2');
    $self->create_opt('contextname2');
    my ($authprotocol, $authpassword, $privprotocol, $privpassword,
        $username, $contextengineid, $contextname) = split(/$separator/, $2);
    $self->override_opt('authprotocol2', $authprotocol)
        if defined($authprotocol) && $authprotocol;
    $self->override_opt('authpassword2', $authpassword)
        if defined($authpassword) && $authpassword;
    $self->override_opt('privprotocol2', $privprotocol)
        if defined($privprotocol) && $privprotocol;
    $self->override_opt('privpassword2', $privpassword)
        if defined($privpassword) && $privpassword;
    $self->override_opt('username2', $username)
        if defined($username) && $username;
    $self->override_opt('contextengineid2', $contextengineid)
        if defined($contextengineid) && $contextengineid;
    $self->override_opt('contextname2', $contextname)
        if defined($contextname) && $contextname;
    $self->override_opt('community2', undef);
  }
}

sub add_snmp_modes {
  my ($self) = @_;
  $self->add_mode(
      internal => 'device::uptime',
      spec => 'uptime',
      alias => undef,
      help => 'Check the uptime of the device',
  );
  $self->add_mode(
      internal => 'device::walk',
      spec => 'walk',
      alias => undef,
      help => 'Show snmpwalk command with the oids necessary for a simulation',
  );
  $self->add_mode(
      internal => 'device::walkbulk',
      spec => 'bulkwalk',
      alias => undef,
      help => 'Show snmpbulkwalk command with the oids necessary for a simulation',
      hidden => 1,
  );
  $self->add_mode(
      internal => 'device::supportedmibs',
      spec => 'supportedmibs',
      alias => undef,
      help => 'Shows the names of the mibs which this devices has implemented (only lausser may run this command)',
  );
  $self->add_mode(
      internal => 'device::supportedoids',
      spec => 'supportedoids',
      alias => undef,
      help => 'Shows the names of the oids which this devices has implemented (only lausser may run this command)',
  );
}

sub add_snmp_args {
  my ($self) = @_;
  $self->add_arg(
      spec => 'hostname|H=s',
      help => '--hostname
   Hostname or IP-address of the switch or router',
      required => 0,
      env => 'HOSTNAME',
  );
  $self->add_arg(
      spec => 'port=i',
      help => '--port
   The SNMP port to use (default: 161)',
      required => 0,
      default => 161,
  );
  $self->add_arg(
      spec => 'domain=s',
      help => '--domain
   The transport domain to use (default: udp/ipv4, other possible values: udp6, udp/ipv6, tcp, tcp4, tcp/ipv4, tcp6, tcp/ipv6)',
      required => 0,
      default => 'udp',
  );
  $self->add_arg(
      spec => 'protocol|P=s',
      help => '--protocol
   The SNMP protocol to use (default: 2c, other possibilities: 1,3)',
      required => 0,
      default => '2c',
  );
  $self->add_arg(
      spec => 'community|C=s',
      help => '--community
   SNMP community of the server (SNMP v1/2 only)',
      required => 0,
      default => 'public',
  );
  $self->add_arg(
      spec => 'username:s',
      help => '--username
   The securityName for the USM security model (SNMPv3 only)',
      required => 0,
  );
  $self->add_arg(
      spec => 'authpassword:s',
      help => '--authpassword
   The authentication password for SNMPv3',
      required => 0,
  );
  $self->add_arg(
      spec => 'authprotocol:s',
      help => '--authprotocol
   The authentication protocol for SNMPv3 (md5|sha)',
      required => 0,
  );
  $self->add_arg(
      spec => 'privpassword:s',
      help => '--privpassword
   The password for authPriv security level',
      required => 0,
  );
  $self->add_arg(
      spec => 'privprotocol=s',
      help => '--privprotocol
   The private protocol for SNMPv3 (des|aes|aes128|3des|3desde)',
      required => 0,
  );
  $self->add_arg(
      spec => 'contextengineid=s',
      help => '--contextengineid
   The context engine id for SNMPv3 (10 to 64 hex characters)',
      required => 0,
  );
  $self->add_arg(
      spec => 'contextname=s',
      help => '--contextname
   The context name for SNMPv3 (empty represents the "default" context)',
      required => 0,
  );
  $self->add_arg(
      spec => 'community2=s',
      help => '--community2
   SNMP community which can be used to switch the context during runtime',
      required => 0,
  );
  $self->add_arg(
      spec => 'snmpwalk=s',
      help => '--snmpwalk
   A file with the output of a snmpwalk (used for simulation)
   Use it instead of --hostname',
      required => 0,
      env => 'SNMPWALK',
  );
  $self->add_arg(
      spec => 'servertype=s',
      help => '--servertype
     The type of the network device: cisco (default). Use it if auto-detection
     is not possible',
      required => 0,
  );
  $self->add_arg(
      spec => 'oids=s',
      help => '--oids
   A list of oids which are downloaded and written to a cache file.
   Use it together with --mode oidcache',
      required => 0,
  );
  $self->add_arg(
      spec => 'offline:i',
      help => '--offline
   The maximum number of seconds since the last update of cache file before
   it is considered too old',
      required => 0,
      env => 'OFFLINE',
  );
}

sub validate_args {
  my ($self) = @_;
  $self->SUPER::validate_args();
  if ($self->opts->mode =~ /^(bulk)*walk/) {
    if ($self->opts->snmpwalk && $self->opts->hostname) {
      if ($self->check_messages == CRITICAL) {
        # gemecker vom super-validierer, der sicherstellt, dass die datei
        # snmpwalk existiert. in diesem fall wird sie aber erst neu angelegt,
        # also schnauze.
        my ($code, $message) = $self->check_messages;
        if ($message eq sprintf("file %s not found", $self->opts->snmpwalk)) {
          $self->clear_critical;
        }
      }
      # snmp agent wird abgefragt, die ergebnisse landen in einem file
      # opts->snmpwalk ist der filename. da sich die ganzen get_snmp_table/object-aufrufe
      # an das walkfile statt an den agenten halten wuerden, muss opts->snmpwalk geloescht
      # werden. stattdessen wird opts->snmpdump als traeger des dateinamens mitgegeben.
      # nur sinnvoll mit mode=walk
      $self->create_opt('snmpdump');
      $self->override_opt('snmpdump', $self->opts->snmpwalk);
      $self->override_opt('snmpwalk', undef);
    } elsif (! $self->opts->snmpwalk && $self->opts->hostname) {
      # snmp agent wird abgefragt, die ergebnisse landen in einem file, dessen name
      # nicht vorgegeben ist
      $self->create_opt('snmpdump');
    }
  } else {    
    if ($self->opts->snmpwalk && ! $self->opts->hostname) {
      # normaler aufruf, mode != walk, oid-quelle ist eine datei
      $self->override_opt('hostname', 'snmpwalk.file'.md5_hex($self->opts->snmpwalk))
    } elsif ($self->opts->snmpwalk && $self->opts->hostname) {
      # snmpwalk hat vorrang
      $self->override_opt('hostname', undef);
    }
  }
}

sub init {
  my ($self) = @_;
  if ($self->mode =~ /device::(bulk)*walk/) {
    my @trees = ();
    my $name = $Monitoring::GLPlugin::pluginname;
    $name =~ s/.*\///g;
    $name = sprintf "/tmp/snmpwalk_%s_%s", $name, $self->opts->hostname;
    if ($self->opts->oids) {
      # create pid filename
      # already running?;x
      @trees = split(",", $self->opts->oids);

    } elsif ($self->can("trees")) {
      @trees = $self->trees;
      push(@trees, "1.3.6.1.2.1.1");
    } else {
      @trees = ("1.3.6.1.2.1", "1.3.6.1.4.1");
    }
    if ($self->opts->snmpdump) {
      $name = $self->opts->snmpdump;
    }
    $self->opts->override_opt("protocol", $1) if $self->opts->protocol =~ /^v(.*)/;
    if (defined $self->opts->offline) {
      $self->{pidfile} = $name.".pid";
      if (! $self->check_pidfile()) {
        $self->debug("Exiting because another walk is already running");
        printf STDERR "Exiting because another walk is already running\n";
        exit 3;
      }
      $self->write_pidfile();
      my $timedout = 0;
      my $snmpwalkpid = 0;
      $SIG{'ALRM'} = sub {
        $timedout = 1;
        printf "UNKNOWN - %s timed out after %d seconds\n",
            $Monitoring::GLPlugin::plugin->{name}, $self->opts->timeout;
        kill 9, $snmpwalkpid;
      };
      alarm($self->opts->timeout);
      unlink $name.".partial";
      while (! $timedout && @trees) {
        my $tree = shift @trees;
        $SIG{CHLD} = 'IGNORE';
        my $cmd = sprintf "%s -ObentU -v%s -c %s %s %s >> %s",
            ($self->mode =~ /bulk/) ? "snmpbulkwalk" : "snmpwalk",
            $self->opts->protocol,
            $self->opts->community,
            $self->opts->hostname,
            $tree, $name.".partial";
        $self->debug($cmd);
        $snmpwalkpid = fork;
        if (not $snmpwalkpid) {
          exec($cmd);
        } else {
          wait();
        }
      }
      rename $name.".partial", $name if ! $timedout;
      -f $self->{pidfile} && unlink $self->{pidfile};
      if ($timedout) {
        printf "CRITICAL - timeout. There are still %d snmpwalks left\n", scalar(@trees);
        exit 3;
      } else {
        printf "OK - all requested oids are in %s\n", $name;
      }
    } else {
      printf "rm -f %s\n", $name;
      foreach (@trees) {
        printf "%s -ObentU -v%s -c %s %s %s >> %s\n",
            ($self->mode =~ /bulk/) ? "snmpbulkwalk -t 15 -r 20" : "snmpwalk",
            $self->opts->protocol,
            $self->opts->community,
            $self->opts->hostname,
            $_, $name;
      }
    }
    exit 0;
  } elsif ($self->mode =~ /device::uptime/) {
    $self->add_info(sprintf 'device is up since %s',
        $self->human_timeticks($self->{uptime}));
    $self->set_thresholds(warning => '15:', critical => '5:');
    $self->add_message($self->check_thresholds($self->{uptime} / 60));
    $self->add_perfdata(
        label => 'uptime',
        value => $self->{uptime} / 60,
        places => 0,
    );
    if ($self->opts->report ne 'short') {
      $self->add_ok($self->pretty_sysdesc($self->{productname}));
    }
    my ($code, $message) = $self->check_messages(join => ', ', join_all => ', ');
    $Monitoring::GLPlugin::plugin->nagios_exit($code, $message);
  } elsif ($self->mode =~ /device::supportedmibs/) {
    our $mibdepot = [];
    my $unknowns = {};
    my @outputlist = ();
    %{$unknowns} = %{$self->rawdata};
    if ($self->opts->name && -f $self->opts->name) {
      eval { require $self->opts->name };
      $self->add_critical($@) if $@;
    } elsif ($self->opts->name && ! -f $self->opts->name) {
      $self->add_unknown("where is --name mibdepotfile?");
    }
    push(@{$mibdepot}, ['1.3.6.1.2.1.60', 'ietf', 'v2', 'ACCOUNTING-CONTROL-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.238', 'ietf', 'v2', 'ADSL2-LINE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.238.2', 'ietf', 'v2', 'ADSL2-LINE-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.94.3', 'ietf', 'v2', 'ADSL-LINE-EXT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.94', 'ietf', 'v2', 'ADSL-LINE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.94.2', 'ietf', 'v2', 'ADSL-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.74', 'ietf', 'v2', 'AGENTX-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.123', 'ietf', 'v2', 'AGGREGATE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.118', 'ietf', 'v2', 'ALARM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.23', 'ietf', 'v2', 'APM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.3', 'ietf', 'v2', 'APPC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.13.1', 'ietf', 'v1', 'APPLETALK-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.27', 'ietf', 'v2', 'APPLICATION-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.62', 'ietf', 'v2', 'APPLICATION-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.5', 'ietf', 'v2', 'APPN-DLUR-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.4', 'ietf', 'v2', 'APPN-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.4', 'ietf', 'v2', 'APPN-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.4.0', 'ietf', 'v2', 'APPN-TRAP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.49', 'ietf', 'v2', 'APS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.117', 'ietf', 'v2', 'ARC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.37.1.14', 'ietf', 'v2', 'ATM2-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.59', 'ietf', 'v2', 'ATM-ACCOUNTING-INFORMATION-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.37', 'ietf', 'v2', 'ATM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.37', 'ietf', 'v2', 'ATM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.37.3', 'ietf', 'v2', 'ATM-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.15', 'ietf', 'v2', 'BGP4-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.15', 'ietf', 'v2', 'BGP4-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.122', 'ietf', 'v2', 'BLDG-HVAC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.17.1', 'ietf', 'v1', 'BRIDGE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.17', 'ietf', 'v2', 'BRIDGE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.19', 'ietf', 'v2', 'CHARACTER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.94', 'ietf', 'v2', 'CIRCUIT-IF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.1.1', 'ietf', 'v1', 'CLNS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.1.1', 'ietf', 'v1', 'CLNS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.132', 'ietf', 'v2', 'COFFEE-POT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.89', 'ietf', 'v2', 'COPS-CLIENT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.18.1', 'ietf', 'v1', 'DECNET-PHIV-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.21', 'ietf', 'v2', 'DIAL-CONTROL-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.108', 'ietf', 'v2', 'DIFFSERV-CONFIG-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.97', 'ietf', 'v2', 'DIFFSERV-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.66', 'ietf', 'v2', 'DIRECTORY-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.88', 'ietf', 'v2', 'DISMAN-EVENT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.90', 'ietf', 'v2', 'DISMAN-EXPRESSION-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.82', 'ietf', 'v2', 'DISMAN-NSLOOKUP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.82', 'ietf', 'v2', 'DISMAN-NSLOOKUP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.80', 'ietf', 'v2', 'DISMAN-PING-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.80', 'ietf', 'v2', 'DISMAN-PING-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.63', 'ietf', 'v2', 'DISMAN-SCHEDULE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.63', 'ietf', 'v2', 'DISMAN-SCHEDULE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.64', 'ietf', 'v2', 'DISMAN-SCRIPT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.64', 'ietf', 'v2', 'DISMAN-SCRIPT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.81', 'ietf', 'v2', 'DISMAN-TRACEROUTE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.81', 'ietf', 'v2', 'DISMAN-TRACEROUTE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.46', 'ietf', 'v2', 'DLSW-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.32.2', 'ietf', 'v2', 'DNS-RESOLVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.32.1', 'ietf', 'v2', 'DNS-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.127.5', 'ietf', 'v2', 'DOCS-BPI-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.69', 'ietf', 'v2', 'DOCS-CABLE-DEVICE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.69', 'ietf', 'v2', 'DOCS-CABLE-DEVICE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.126', 'ietf', 'v2', 'DOCS-IETF-BPI2-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.132', 'ietf', 'v2', 'DOCS-IETF-CABLE-DEVICE-NOTIFICATION-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.127', 'ietf', 'v2', 'DOCS-IETF-QOS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.125', 'ietf', 'v2', 'DOCS-IETF-SUBMGT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.127', 'ietf', 'v2', 'DOCS-IF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.127', 'ietf', 'v2', 'DOCS-IF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.45', 'ietf', 'v2', 'DOT12-IF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.53', 'ietf', 'v2', 'DOT12-RPTR-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.155', 'ietf', 'v2', 'DOT3-EPON-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.158', 'ietf', 'v2', 'DOT3-OAM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.4.1.2.2.1.1', 'ietf', 'v1', 'DPI20-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.82', 'ietf', 'v2', 'DS0BUNDLE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.81', 'ietf', 'v2', 'DS0-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.18', 'ietf', 'v2', 'DS1-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.18', 'ietf', 'v2', 'DS1-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.18', 'ietf', 'v2', 'DS1-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.30', 'ietf', 'v2', 'DS3-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.30', 'ietf', 'v2', 'DS3-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.29', 'ietf', 'v2', 'DSA-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.26', 'ietf', 'v2', 'DSMON-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.7', 'ietf', 'v2', 'EBN-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.167', 'ietf', 'v2', 'EFM-CU-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.47', 'ietf', 'v2', 'ENTITY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.47', 'ietf', 'v2', 'ENTITY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.47', 'ietf', 'v2', 'ENTITY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.99', 'ietf', 'v2', 'ENTITY-SENSOR-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.131', 'ietf', 'v2', 'ENTITY-STATE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.130', 'ietf', 'v2', 'ENTITY-STATE-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.70', 'ietf', 'v2', 'ETHER-CHIPSET-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.7', 'ietf', 'v1', 'EtherLike-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.7', 'ietf', 'v1', 'EtherLike-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.35', 'ietf', 'v2', 'EtherLike-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.35', 'ietf', 'v2', 'EtherLike-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.35', 'ietf', 'v2', 'EtherLike-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.35', 'ietf', 'v2', 'EtherLike-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.224', 'ietf', 'v2', 'FCIP-MGMT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.56', 'ietf', 'v2', 'FC-MGMT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.15.73.1', 'ietf', 'v1', 'FDDI-SMT73-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.75', 'ietf', 'v2', 'FIBRE-CHANNEL-FE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.111', 'ietf', 'v2', 'Finisher-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.40', 'ietf', 'v2', 'FLOW-METER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.40', 'ietf', 'v2', 'FLOW-METER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.32', 'ietf', 'v2', 'FRAME-RELAY-DTE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.86', 'ietf', 'v2', 'FR-ATM-PVC-SERVICE-IWF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.47', 'ietf', 'v2', 'FR-MFR-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.44', 'ietf', 'v2', 'FRNETSERV-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.44', 'ietf', 'v2', 'FRNETSERV-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.44', 'ietf', 'v2', 'FRNETSERV-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.95', 'ietf', 'v2', 'FRSLD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.16', 'ietf', 'v2', 'GMPLS-LABEL-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.15', 'ietf', 'v2', 'GMPLS-LSR-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.12', 'ietf', 'v2', 'GMPLS-TC-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.13', 'ietf', 'v2', 'GMPLS-TE-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.98', 'ietf', 'v2', 'GSMP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.29', 'ietf', 'v2', 'HC-ALARM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.107', 'ietf', 'v2', 'HC-PerfHist-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.20.5', 'ietf', 'v2', 'HC-RMON-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.25.1', 'ietf', 'v1', 'HOST-RESOURCES-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.25.1', 'ietf', 'v2', 'HOST-RESOURCES-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.6.1.5', 'ietf', 'v2', 'HPR-IP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.6', 'ietf', 'v2', 'HPR-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.106', 'ietf', 'v2', 'IANA-CHARSET-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.110', 'ietf', 'v2', 'IANA-FINISHER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.152', 'ietf', 'v2', 'IANA-GMPLS-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.30', 'ietf', 'v2', 'IANAifType-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.128', 'ietf', 'v2', 'IANA-IPPM-METRICS-REGISTRY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.119', 'ietf', 'v2', 'IANA-ITU-ALARM-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.154', 'ietf', 'v2', 'IANA-MAU-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.109', 'ietf', 'v2', 'IANA-PRINTER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.4.1.2.6.2.13.1.1', 'ietf', 'v1', 'IBM-6611-APPN-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.166', 'ietf', 'v2', 'IF-CAP-STACK-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.230', 'ietf', 'v2', 'IFCP-MGMT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.77', 'ietf', 'v2', 'IF-INVERTED-STACK-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.31', 'ietf', 'v2', 'IF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.31', 'ietf', 'v2', 'IF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.31', 'ietf', 'v2', 'IF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.85', 'ietf', 'v2', 'IGMP-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.76', 'ietf', 'v2', 'INET-ADDRESS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.76', 'ietf', 'v2', 'INET-ADDRESS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.76', 'ietf', 'v2', 'INET-ADDRESS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.52.5', 'ietf', 'v2', 'INTEGRATED-SERVICES-GUARANTEED-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.52', 'ietf', 'v2', 'INTEGRATED-SERVICES-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.27', 'ietf', 'v2', 'INTERFACETOPN-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.17', 'ietf', 'v2', 'IPATM-IPMC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.57', 'ietf', 'v2', 'IPATM-IPMC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.4.24', 'ietf', 'v2', 'IP-FORWARD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.4.24', 'ietf', 'v2', 'IP-FORWARD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.168', 'ietf', 'v2', 'IPMCAST-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.48', 'ietf', 'v2', 'IP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.48', 'ietf', 'v2', 'IP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.83', 'ietf', 'v2', 'IPMROUTE-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.46', 'ietf', 'v2', 'IPOA-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.141', 'ietf', 'v2', 'IPS-AUTH-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.153', 'ietf', 'v2', 'IPSEC-SPD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.103', 'ietf', 'v2', 'IPV6-FLOW-LABEL-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.56', 'ietf', 'v2', 'IPV6-ICMP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.55', 'ietf', 'v2', 'IPV6-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.91', 'ietf', 'v2', 'IPV6-MLD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.86', 'ietf', 'v2', 'IPV6-TCP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.87', 'ietf', 'v2', 'IPV6-UDP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.142', 'ietf', 'v2', 'ISCSI-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.20', 'ietf', 'v2', 'ISDN-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.138', 'ietf', 'v2', 'ISIS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.163', 'ietf', 'v2', 'ISNS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.121', 'ietf', 'v2', 'ITU-ALARM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.120', 'ietf', 'v2', 'ITU-ALARM-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.4.1.2699.1.1', 'ietf', 'v2', 'Job-Monitoring-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.95', 'ietf', 'v2', 'L2TP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.165', 'ietf', 'v2', 'LANGTAG-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.227', 'ietf', 'v2', 'LMP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.227', 'ietf', 'v2', 'LMP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.101', 'ietf', 'v2', 'MALLOC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.26.1', 'ietf', 'v1', 'MAU-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.26.6', 'ietf', 'v2', 'MAU-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.26.6', 'ietf', 'v2', 'MAU-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.26.6', 'ietf', 'v2', 'MAU-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.26.6', 'ietf', 'v2', 'MAU-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.171', 'ietf', 'v2', 'MIDCOM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.38.1', 'ietf', 'v1', 'MIOX25-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.44', 'ietf', 'v2', 'MIP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.133', 'ietf', 'v2', 'MOBILEIPV6-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.38', 'ietf', 'v2', 'Modem-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.8', 'ietf', 'v2', 'MPLS-FTN-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.11', 'ietf', 'v2', 'MPLS-L3VPN-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.9', 'ietf', 'v2', 'MPLS-LC-ATM-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.10', 'ietf', 'v2', 'MPLS-LC-FR-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.5', 'ietf', 'v2', 'MPLS-LDP-ATM-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.6', 'ietf', 'v2', 'MPLS-LDP-FRAME-RELAY-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.7', 'ietf', 'v2', 'MPLS-LDP-GENERIC-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.4.1.9.10.65', 'ietf', 'v2', 'MPLS-LDP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.4', 'ietf', 'v2', 'MPLS-LDP-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.2', 'ietf', 'v2', 'MPLS-LSR-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.1', 'ietf', 'v2', 'MPLS-TC-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.166.3', 'ietf', 'v2', 'MPLS-TE-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.92', 'ietf', 'v2', 'MSDP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.28', 'ietf', 'v2', 'MTA-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.28', 'ietf', 'v2', 'MTA-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.28', 'ietf', 'v2', 'MTA-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.123', 'ietf', 'v2', 'NAT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.27', 'ietf', 'v2', 'NETWORK-SERVICES-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.27', 'ietf', 'v2', 'NETWORK-SERVICES-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.71', 'ietf', 'v2', 'NHRP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.92', 'ietf', 'v2', 'NOTIFICATION-LOG-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.133', 'ietf', 'v2', 'OPT-IF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.14', 'ietf', 'v2', 'OSPF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.14', 'ietf', 'v2', 'OSPF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.14.16', 'ietf', 'v2', 'OSPF-TRAP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.14.16', 'ietf', 'v2', 'OSPF-TRAP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.34', 'ietf', 'v2', 'PARALLEL-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.17.6', 'ietf', 'v2', 'P-BRIDGE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.58', 'ietf', 'v2', 'PerfHist-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.58', 'ietf', 'v2', 'PerfHist-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.172', 'ietf', 'v2', 'PIM-BSR-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.61', 'ietf', 'v2', 'PIM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.157', 'ietf', 'v2', 'PIM-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.93', 'ietf', 'v2', 'PINT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.140', 'ietf', 'v2', 'PKTC-IETF-MTA-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.169', 'ietf', 'v2', 'PKTC-IETF-SIG-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.124', 'ietf', 'v2', 'POLICY-BASED-MANAGEMENT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.105', 'ietf', 'v2', 'POWER-ETHERNET-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.23.4', 'ietf', 'v1', 'PPP-BRIDGE-NCP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.23.3', 'ietf', 'v1', 'PPP-IP-NCP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.23.1.1', 'ietf', 'v1', 'PPP-LCP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.23.2', 'ietf', 'v1', 'PPP-SEC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.43', 'ietf', 'v2', 'Printer-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.43', 'ietf', 'v2', 'Printer-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.79', 'ietf', 'v2', 'PTOPO-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.17.7', 'ietf', 'v2', 'Q-BRIDGE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.67.2.2', 'ietf', 'v2', 'RADIUS-ACC-CLIENT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.67.2.2', 'ietf', 'v2', 'RADIUS-ACC-CLIENT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.67.2.1', 'ietf', 'v2', 'RADIUS-ACC-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.67.2.1', 'ietf', 'v2', 'RADIUS-ACC-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.67.1.2', 'ietf', 'v2', 'RADIUS-AUTH-CLIENT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.67.1.2', 'ietf', 'v2', 'RADIUS-AUTH-CLIENT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.67.1.1', 'ietf', 'v2', 'RADIUS-AUTH-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.67.1.1', 'ietf', 'v2', 'RADIUS-AUTH-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.145', 'ietf', 'v2', 'RADIUS-DYNAUTH-CLIENT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.146', 'ietf', 'v2', 'RADIUS-DYNAUTH-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.31', 'ietf', 'v2', 'RAQMON-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.32', 'ietf', 'v2', 'RAQMON-RDS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.39', 'ietf', 'v2', 'RDBMS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.1', 'ietf', 'v1', 'RFC1066-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.1', 'ietf', 'v1', 'RFC1156-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.1', 'ietf', 'v1', 'RFC1158-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.1', 'ietf', 'v1', 'RFC1213-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.12', 'ietf', 'v1', 'RFC1229-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.7', 'ietf', 'v1', 'RFC1230-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.9', 'ietf', 'v1', 'RFC1231-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.2', 'ietf', 'v1', 'RFC1232-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.15', 'ietf', 'v1', 'RFC1233-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.13.1', 'ietf', 'v1', 'RFC1243-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.13.1', 'ietf', 'v1', 'RFC1248-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.13.1', 'ietf', 'v1', 'RFC1252-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.14.1', 'ietf', 'v1', 'RFC1253-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.15', 'ietf', 'v1', 'RFC1269-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.1', 'ietf', 'v1', 'RFC1271-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.7', 'ietf', 'v1', 'RFC1284-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.15.1', 'ietf', 'v1', 'RFC1285-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.17.1', 'ietf', 'v1', 'RFC1286-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.18.1', 'ietf', 'v1', 'RFC1289-phivMIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.31', 'ietf', 'v1', 'RFC1304-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.32', 'ietf', 'v1', 'RFC1315-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.19', 'ietf', 'v1', 'RFC1316-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.33', 'ietf', 'v1', 'RFC1317-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.34', 'ietf', 'v1', 'RFC1318-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.20.2', 'ietf', 'v1', 'RFC1353-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.4.24', 'ietf', 'v1', 'RFC1354-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.16', 'ietf', 'v1', 'RFC1381-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.5', 'ietf', 'v1', 'RFC1382-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.23.1', 'ietf', 'v1', 'RFC1389-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.7', 'ietf', 'v1', 'RFC1398-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.18', 'ietf', 'v1', 'RFC1406-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.30', 'ietf', 'v1', 'RFC1407-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.24.1', 'ietf', 'v1', 'RFC1414-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.23', 'ietf', 'v2', 'RIPv2-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16', 'ietf', 'v2', 'RMON2-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16', 'ietf', 'v2', 'RMON2-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.1', 'ietf', 'v1', 'RMON-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.20.8', 'ietf', 'v2', 'RMON-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.112', 'ietf', 'v2', 'ROHC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.114', 'ietf', 'v2', 'ROHC-RTP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.113', 'ietf', 'v2', 'ROHC-UNCOMPRESSED-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.33', 'ietf', 'v2', 'RS-232-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.134', 'ietf', 'v2', 'RSTP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.51', 'ietf', 'v2', 'RSVP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.87', 'ietf', 'v2', 'RTP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.139', 'ietf', 'v2', 'SCSI-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.104', 'ietf', 'v2', 'SCTP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.4.1.4300.1', 'ietf', 'v2', 'SFLOW-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.149', 'ietf', 'v2', 'SIP-COMMON-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.36', 'ietf', 'v2', 'SIP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.151', 'ietf', 'v2', 'SIP-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.148', 'ietf', 'v2', 'SIP-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.150', 'ietf', 'v2', 'SIP-UA-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.88', 'ietf', 'v2', 'SLAPM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.22', 'ietf', 'v2', 'SMON-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.4.1.4.4', 'ietf', 'v1', 'SMUX-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34', 'ietf', 'v2', 'SNA-NAU-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34', 'ietf', 'v2', 'SNA-NAU-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.41', 'ietf', 'v2', 'SNA-SDLC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.18', 'ietf', 'v2', 'SNMP-COMMUNITY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.18', 'ietf', 'v2', 'SNMP-COMMUNITY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.10', 'ietf', 'v2', 'SNMP-FRAMEWORK-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.10', 'ietf', 'v2', 'SNMP-FRAMEWORK-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.10', 'ietf', 'v2', 'SNMP-FRAMEWORK-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.21', 'ietf', 'v2', 'SNMP-IEEE802-TM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.11', 'ietf', 'v2', 'SNMP-MPD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.11', 'ietf', 'v2', 'SNMP-MPD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.11', 'ietf', 'v2', 'SNMP-MPD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.13', 'ietf', 'v2', 'SNMP-NOTIFICATION-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.13', 'ietf', 'v2', 'SNMP-NOTIFICATION-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.13', 'ietf', 'v2', 'SNMP-NOTIFICATION-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.14', 'ietf', 'v2', 'SNMP-PROXY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.14', 'ietf', 'v2', 'SNMP-PROXY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.14', 'ietf', 'v2', 'SNMP-PROXY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.22.1.1', 'ietf', 'v1', 'SNMP-REPEATER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.22.1.1', 'ietf', 'v1', 'SNMP-REPEATER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.22.5', 'ietf', 'v2', 'SNMP-REPEATER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.12', 'ietf', 'v2', 'SNMP-TARGET-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.12', 'ietf', 'v2', 'SNMP-TARGET-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.12', 'ietf', 'v2', 'SNMP-TARGET-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.15', 'ietf', 'v2', 'SNMP-USER-BASED-SM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.15', 'ietf', 'v2', 'SNMP-USER-BASED-SM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.15', 'ietf', 'v2', 'SNMP-USER-BASED-SM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.20', 'ietf', 'v2', 'SNMP-USM-AES-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.101', 'ietf', 'v2', 'SNMP-USM-DH-OBJECTS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.2', 'ietf', 'v2', 'SNMPv2-M2M-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.1', 'ietf', 'v2', 'SNMPv2-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.1', 'ietf', 'v2', 'SNMPv2-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.1', 'ietf', 'v2', 'SNMPv2-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.3', 'ietf', 'v2', 'SNMPv2-PARTY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.6', 'ietf', 'v2', 'SNMPv2-USEC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.16', 'ietf', 'v2', 'SNMP-VIEW-BASED-ACM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.16', 'ietf', 'v2', 'SNMP-VIEW-BASED-ACM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.6.3.16', 'ietf', 'v2', 'SNMP-VIEW-BASED-ACM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.39', 'ietf', 'v2', 'SONET-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.39', 'ietf', 'v2', 'SONET-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.39', 'ietf', 'v2', 'SONET-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.17.3', 'ietf', 'v1', 'SOURCE-ROUTING-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.28', 'ietf', 'v2', 'SSPM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.54', 'ietf', 'v2', 'SYSAPPL-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.137', 'ietf', 'v2', 'T11-FC-FABRIC-ADDR-MGR-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.162', 'ietf', 'v2', 'T11-FC-FABRIC-CONFIG-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.159', 'ietf', 'v2', 'T11-FC-FABRIC-LOCK-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.143', 'ietf', 'v2', 'T11-FC-FSPF-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.135', 'ietf', 'v2', 'T11-FC-NAME-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.144', 'ietf', 'v2', 'T11-FC-ROUTE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.161', 'ietf', 'v2', 'T11-FC-RSCN-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.176', 'ietf', 'v2', 'T11-FC-SP-AUTHENTICATION-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.178', 'ietf', 'v2', 'T11-FC-SP-POLICY-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.179', 'ietf', 'v2', 'T11-FC-SP-SA-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.175', 'ietf', 'v2', 'T11-FC-SP-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.177', 'ietf', 'v2', 'T11-FC-SP-ZONING-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.147', 'ietf', 'v2', 'T11-FC-VIRTUAL-FABRIC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.160', 'ietf', 'v2', 'T11-FC-ZONE-SERVER-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.136', 'ietf', 'v2', 'T11-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.156', 'ietf', 'v2', 'TCP-ESTATS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.4.1.23.2.29.1', 'ietf', 'v1', 'TCPIPX-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.49', 'ietf', 'v2', 'TCP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.49', 'ietf', 'v2', 'TCP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.200', 'ietf', 'v2', 'TE-LINK-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.122', 'ietf', 'v2', 'TE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.3.124', 'ietf', 'v2', 'TIME-AGGREGATE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.8', 'ietf', 'v2', 'TN3270E-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.34.9', 'ietf', 'v2', 'TN3270E-RT-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.9', 'ietf', 'v2', 'TOKENRING-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.9', 'ietf', 'v2', 'TOKENRING-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.1', 'ietf', 'v1', 'TOKEN-RING-RMON-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.42', 'ietf', 'v2', 'TOKENRING-STATION-SR-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.16.30', 'ietf', 'v2', 'TPM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.100', 'ietf', 'v2', 'TRANSPORT-ADDRESS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.116', 'ietf', 'v2', 'TRIP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.115', 'ietf', 'v2', 'TRIP-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.131', 'ietf', 'v2', 'TUNNEL-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.131', 'ietf', 'v2', 'TUNNEL-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.170', 'ietf', 'v2', 'UDPLITE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.50', 'ietf', 'v2', 'UDP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.50', 'ietf', 'v2', 'UDP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.33', 'ietf', 'v2', 'UPS-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.164', 'ietf', 'v2', 'URI-TC-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.229', 'ietf', 'v2', 'VDSL-LINE-EXT-MCM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.228', 'ietf', 'v2', 'VDSL-LINE-EXT-SCM-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.10.97', 'ietf', 'v2', 'VDSL-LINE-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.129', 'ietf', 'v2', 'VPN-TC-STD-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.68', 'ietf', 'v2', 'VRRP-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.2.1.65', 'ietf', 'v2', 'WWW-MIB']);
    push(@{$mibdepot}, ['1.3.6.1.4.1.8072', 'net-snmp', 'v2', 'NET-SNMP-MIB']);
    my $oids = $self->get_entries_by_walk(-varbindlist => [
        '1.3.6.1.2.1', '1.3.6.1.4.1',
    ]);
    foreach my $mibinfo (@{$mibdepot}) {
      next if $self->opts->protocol eq "1" && $mibinfo->[2] ne "v1";
      next if $self->opts->protocol ne "1" && $mibinfo->[2] eq "v1";
      $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mibinfo->[3]} = $mibinfo->[0];
    }
    $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{'MIB-2-MIB'} = "1.3.6.1.2.1";
    foreach my $mib (keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids}) {
      if ($self->implements_mib($mib)) {
        push(@outputlist, [$mib, $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib}]);
        $unknowns = {@{[map {
            $_, $self->rawdata->{$_}
        } grep {
            substr($_, 0, length($Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib})) ne
                $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib} || (
            substr($_, 0, length($Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib})) eq
                $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib} &&
            substr($_, length($Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib}), 1) ne ".")
        } keys %{$unknowns}]}};
      }
    }
    my $toplevels = {};
    map {
        /^(1\.3\.6\.1\.(\d+)\.(\d+)\.\d+\.\d+)\./; $toplevels->{$1} = 1; 
    } keys %{$unknowns};
    foreach (sort {$a cmp $b} keys %{$toplevels}) {
      push(@outputlist, ["<unknown>", $_]);
    }
    foreach (sort {$a->[0] cmp $b->[0]} @outputlist) {
      printf "implements %s %s\n", $_->[0], $_->[1];
    }
    $self->add_ok("have fun");
    my ($code, $message) = $self->check_messages(join => ', ', join_all => ', ');
    $Monitoring::GLPlugin::plugin->nagios_exit($code, $message);
  } elsif ($self->mode =~ /device::supportedoids/) {
    my $unknowns = {};
    %{$unknowns} = %{$self->rawdata};
    my $confirmed = {};
    foreach my $mib (keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids}) {
      foreach my $sym (keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}}) {
        if (my $obj = $self->get_snmp_object($mib, $sym)) {
          my $oid = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$sym};
          if (exists $unknowns->{$oid}) {
            $confirmed->{$oid} = sprintf '%s::%s = %s', $mib, $sym, $obj;
            delete $unknowns->{$oid};
          } elsif (exists $unknowns->{$oid.'.0'}) {
            $confirmed->{$oid.'.0'} = sprintf '%s::%s = %s', $mib, $sym, $obj;
            delete $unknowns->{$oid.'.0'};
          }
        }
        if ($sym =~ /Table$/) {
          if (my @table = $self->get_snmp_table_objects($mib, $sym)) {
            my $oid = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$sym};
            $confirmed->{$oid} = sprintf '%s::%s', $mib, $sym;
            $self->add_rawdata($oid, '--------------------');
            foreach my $line (@table) {
              if ($line->{flat_indices}) {
                foreach my $column (grep !/(flat_indices)|(indices)/, keys %{$line}) {
                  my $oid = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$column};
                  if (exists $unknowns->{$oid.'.'.$line->{flat_indices}}) {
                    $confirmed->{$oid.'.'.$line->{flat_indices}} = 
                        sprintf '%s::%s.%s = %s', $mib, $column, $line->{flat_indices}, $line->{$column};
                    delete $unknowns->{$oid.'.'.$line->{flat_indices}};
                  }
                }
              }
            }
          }
        }
      }
    }
    my @sortedoids = $self->sort_oids([keys %{$self->rawdata}]);
    foreach (@sortedoids) {
      if (exists $confirmed->{$_}) {
        printf "%s\n", $confirmed->{$_};
      } else {
        printf "%s = %s\n", $_, $unknowns->{$_};
      }
    }
  }
}

sub check_snmp_and_model {
  my ($self) = @_;
  if ($self->opts->snmpwalk) {
    my $response = {};
    if (! -f $self->opts->snmpwalk) {
      $self->add_message(CRITICAL, 
          sprintf 'file %s not found',
          $self->opts->snmpwalk);
    } elsif (-x $self->opts->snmpwalk) {
      my $cmd = sprintf "%s -ObentU -v%s -c%s %s 1.3.6.1.4.1 2>&1",
          $self->opts->snmpwalk,
          $self->opts->protocol,
          $self->opts->community,
          $self->opts->hostname;
      open(WALK, "$cmd |");
      while (<WALK>) {
        if (/^([\.\d]+) = .*?: (\-*\d+)/) {
          $response->{$1} = $2;
        } elsif (/^([\.\d]+) = .*?: "(.*?)"/) {
          $response->{$1} = $2;
          $response->{$1} =~ s/\s+$//;
        }
      }
      close WALK;
    } else {
      if (defined $self->opts->offline && $self->opts->mode ne 'walk') {
        if ((time - (stat($self->opts->snmpwalk))[9]) > $self->opts->offline) {
          $self->add_message(UNKNOWN,
              sprintf 'snmpwalk file %s is too old', $self->opts->snmpwalk);
        }
      }
      $self->opts->override_opt('hostname', 'walkhost') if $self->opts->mode ne 'walk';
      open(MESS, $self->opts->snmpwalk);
      while(<MESS>) {
        # SNMPv2-SMI::enterprises.232.6.2.6.7.1.3.1.4 = INTEGER: 6
        if (/^([\d\.]+) = .*?INTEGER: .*\((\-*\d+)\)/) {
          # .1.3.6.1.2.1.2.2.1.8.1 = INTEGER: down(2)
          $response->{$1} = $2;
        } elsif (/^([\d\.]+) = .*?Opaque:.*?Float:.*?([\-\.\d]+)/) {
          # .1.3.6.1.4.1.2021.10.1.6.1 = Opaque: Float: 0.938965
          $response->{$1} = $2;
        } elsif (/^([\d\.]+) = STRING:\s*$/) {
          $response->{$1} = "";
        } elsif (/^([\d\.]+) = Network Address: (.*)/) {
          $response->{$1} = $2;
        } elsif (/^([\d\.]+) = Hex-STRING: (.*)/) {
          my $k = $1;
          my $h = $2;
          $h =~ s/\s+//g;
          $response->{$k} = pack('H*', $h);
        } elsif (/^([\d\.]+) = \w+: (\-*\d+)\s*$/) {
          $response->{$1} = $2;
        } elsif (/^([\d\.]+) = \w+: "(.*?)"/) {
          $response->{$1} = $2;
          $response->{$1} =~ s/\s+$//;
        } elsif (/^([\d\.]+) = \w+: (.*)/) {
          $response->{$1} = $2;
          $response->{$1} =~ s/\s+$//;
        } elsif (/^([\d\.]+) = (\-*\d+)/) {
          $response->{$1} = $2;
        } elsif (/^([\d\.]+) = "(.*?)"/) {
          $response->{$1} = $2;
          $response->{$1} =~ s/\s+$//;
        }
      }
      close MESS;
    }
    foreach my $oid (keys %$response) {
      if ($oid =~ /^\./) {
        my $nodot = $oid;
        $nodot =~ s/^\.//g;
        $response->{$nodot} = $response->{$oid};
        delete $response->{$oid};
      }
    }
    map { $response->{$_} =~ s/^\s+//; $response->{$_} =~ s/\s+$//; }
        keys %$response;
    $self->set_rawdata($response);
  } else {
    $self->establish_snmp_session();
  }
  if (! $self->check_messages()) {
    my $tic = time;
    # Datatype TimeTicks = 1/100s
    my $sysUptime = $self->get_snmp_object('MIB-2-MIB', 'sysUpTime', 0);
    # Datatype Integer32 = 1s
    my $snmpEngineTime = $self->get_snmp_object('SNMP-FRAMEWORK-MIB', 'snmpEngineTime');
    # Datatype TimeTicks = 1/100s
    my $hrSystemUptime = $self->get_snmp_object('HOST-RESOURCES-MIB', 'hrSystemUptime');
    my $sysDescr = $self->get_snmp_object('MIB-2-MIB', 'sysDescr', 0);
    my $tac = time;
    if (defined $hrSystemUptime && $hrSystemUptime =~ /^\d+$/ && $hrSystemUptime > 0) {
      $hrSystemUptime = $self->timeticks($hrSystemUptime);
      $self->debug(sprintf 'hrSystemUptime says: up since: %s / %s',
          scalar localtime (time -  $hrSystemUptime),
          $self->human_timeticks($hrSystemUptime));
    } else {
      $hrSystemUptime = undef;
    }
    if (defined $snmpEngineTime && $snmpEngineTime =~ /^\d+$/ && $snmpEngineTime > 0) {
      $snmpEngineTime = $snmpEngineTime;
      $self->debug(sprintf 'snmpEngineTime says: up since: %s / %s',
          scalar localtime (time - $snmpEngineTime),
          $self->human_timeticks($snmpEngineTime));
    } else {
      # drecksschrott asa liefert negative werte
      # und drecksschrott socomec liefert: wrong type (should be INTEGER): NULL
      $snmpEngineTime = undef;
    }
    if (defined $sysUptime) {
      $sysUptime = $self->timeticks($sysUptime);
      $self->debug(sprintf 'sysUptime says:      up since: %s / %s',
          scalar localtime (time - $sysUptime),
          $self->human_timeticks($sysUptime));
    }
    if (defined $sysUptime && defined $sysDescr) {
      if ($hrSystemUptime) {
        # Bei Linux-basierten Geraeten wird snmpEngineTime viel zu haeufig
        # durchgestartet, also lieber das hier.
        $self->{uptime} = $hrSystemUptime;
        # Es sei denn, snmpEngineTime ist tatsaechlich groesser, dann gilt
        # wiederum dieses. Mag sein, dass der zahlenwert hier manchmal huepft
        # und ein Performancegraph Zacken bekommt, aber das ist mir egal.
        # es geht nicht um Graphen in Form einer ansteigenden Geraden, sondern
        # um das Erkennen von spontanen Reboots und das Vermeiden von
        # falschen Alarmen.
        if ($snmpEngineTime && $snmpEngineTime > $hrSystemUptime) {
          $self->{uptime} = $snmpEngineTime;
        }
      } elsif ($snmpEngineTime) {
        $self->{uptime} = $snmpEngineTime;
      } else {
        $self->{uptime} = $sysUptime;
      }
      $self->{productname} = $sysDescr;
      $self->{sysobjectid} = $self->get_snmp_object('MIB-2-MIB', 'sysObjectID', 0);
      $self->debug(sprintf 'uptime: %s', $self->{uptime});
      $self->debug(sprintf 'up since: %s',
          scalar localtime (time - $self->{uptime}));
      $Monitoring::GLPlugin::SNMP::uptime = $self->{uptime};
      $self->debug('whoami: '.$self->{productname});
    } else {
      if ($tac - $tic >= $Monitoring::GLPlugin::SNMP::session->timeout) {
        $self->add_message(UNKNOWN,
            'could not contact snmp agent, timeout during snmp-get sysUptime');
      } else {
        $self->add_message(UNKNOWN,
            'got neither sysUptime nor sysDescr, is this snmp agent working correctly?');
      }
      $Monitoring::GLPlugin::SNMP::session->close if $Monitoring::GLPlugin::SNMP::session;
    }
  }
}

sub pretty_sysdesc {
  my ($self, $sysDesc) = @_;
  my $prettySysDescription = undef;
  if (exists $self->{classified_as}) {
    my $now_class = ref($self);
    my $now_pretty_sysdesc = $self->can("pretty_sysdesc");
    bless $self, $self->{classified_as};
    my $classified_pretty_sysdesc = $self->can("pretty_sysdesc");
    if ($now_pretty_sysdesc && $classified_pretty_sysdesc && $now_pretty_sysdesc ne $classified_pretty_sysdesc) {
      $prettySysDescription = $self->pretty_sysdesc($sysDesc);
    } elsif (! $now_pretty_sysdesc && $classified_pretty_sysdesc) {
      $prettySysDescription = $self->pretty_sysdesc($sysDesc);
    }
    bless $self, $now_class;
  }
  return $prettySysDescription ? $prettySysDescription : $sysDesc;
}

sub establish_snmp_session {
  my ($self) = @_;
  $self->set_timeout_alarm();
  if (eval "require Net::SNMP") {
    my %params = ();
    my $net_snmp_version = Net::SNMP->VERSION(); # 5.002000 or 6.000000
    $params{'-translate'} = [ # because we see "NULL" coming from socomec devices
      -all => 0x0,
      -nosuchobject => 1,
      -nosuchinstance => 1,
      -endofmibview => 1,
      -unsigned => 1,
    ];
    $params{'-hostname'} = $self->opts->hostname;
    $params{'-version'} = $self->opts->protocol;
    if ($self->opts->port) {
      $params{'-port'} = $self->opts->port;
    }
    if ($self->opts->domain) {
      $params{'-domain'} = $self->opts->domain;
    }
    $self->v2tov3;
    if ($self->opts->protocol eq '3') {
      $params{'-version'} = $self->opts->protocol;
      $params{'-username'} = $self->opts->username;
      if ($self->opts->authpassword) {
        $params{'-authpassword'} = 
            $self->decode_password($self->opts->authpassword);
      }
      if ($self->opts->authprotocol) {
        $params{'-authprotocol'} = $self->opts->authprotocol;
      }
      if ($self->opts->privpassword) {
        $params{'-privpassword'} = 
            $self->decode_password($self->opts->privpassword);
      }
      if ($self->opts->privprotocol) {
        $params{'-privprotocol'} = $self->opts->privprotocol;
      }
      # context hat in der session nix verloren, sondern wird
      # als zusatzinfo bei den requests mitgeschickt
      #if ($self->opts->contextengineid) {
      #  $params{'-contextengineid'} = $self->opts->contextengineid;
      #}
      #if ($self->opts->contextname) {
      #  $params{'-contextname'} = $self->opts->contextname;
      #}
    } else {
      $params{'-community'} = 
          $self->decode_password($self->opts->community);
    }
    # breaks cisco wlc $params{'-timeout'} = $self->opts->timeout() > 60 ?
    #    15 : $self->opts->timeout() - 1;
    my ($session, $error) = Net::SNMP->session(%params);
    if (! defined $session) {
      $self->add_message(CRITICAL, 
          sprintf 'cannot create session object: %s', $error);
      $self->debug(Data::Dumper::Dumper(\%params));
    } else {
      my $max_msg_size = $session->max_msg_size();
      #$session->max_msg_size(4 * $max_msg_size);
      $Monitoring::GLPlugin::SNMP::max_msg_size = $max_msg_size;
      $Monitoring::GLPlugin::SNMP::session = $session;
    }
  } else {
    $self->add_message(CRITICAL,
        'could not find Net::SNMP module');
  }
}

sub session_translate {
  my ($self, $translation) = @_;
  $Monitoring::GLPlugin::SNMP::session->translate($translation) if
      $Monitoring::GLPlugin::SNMP::session;
}

sub establish_snmp_secondary_session {
  my ($self) = @_;
  if ($self->opts->protocol eq '3' && (
      defined $self->opts->authprotocol2 ||
      defined $self->opts->authpassword2 ||
      defined $self->opts->privprotocol2 ||
      defined $self->opts->privpassword2 ||
      defined $self->opts->username2 ||
      defined $self->opts->contextengineid2 ||
      defined $self->opts->contextname2
  )) {
    my $relogin = 0;
    # bei --community2="snmpv3,..." wurde alles in xyz2 per override gesteckt
    $relogin = 1 if ! $self->strequal($self->opts->authprotocol,
        $self->opts->authprotocol2);
    $relogin = 1 if ! $self->strequal($self->opts->authpassword,
        $self->opts->authpassword2);
    $relogin = 1 if ! $self->strequal($self->opts->privprotocol,
        $self->opts->privprotocol2);
    $relogin = 1 if ! $self->strequal($self->opts->privpassword,
        $self->opts->privpassword2);
    $relogin = 1 if ! $self->strequal($self->opts->username,
        $self->opts->username2);
    if ($relogin) {
      $Monitoring::GLPlugin::SNMP::session = undef;
      $self->opts->override_opt('authprotocol',
          $self->decode_password($self->opts->authprotocol2));
      $self->opts->override_opt('authpassword',
          $self->decode_password($self->opts->authpassword2));
      $self->opts->override_opt('privprotocol',
          $self->decode_password($self->opts->privprotocol2));
      $self->opts->override_opt('privpassword',
          $self->decode_password($self->opts->privpassword2));
      $self->opts->override_opt('username',
          $self->decode_password($self->opts->username2));
      $self->establish_snmp_session;
    }
    $self->opts->override_opt('contextengineid',
        $self->decode_password($self->opts->contextengineid2));
    $self->opts->override_opt('contextname',
        $self->decode_password($self->opts->contextname2));
    return 1;
  } else {
    if (defined $self->opts->community2 &&
        $self->decode_password($self->opts->community2) ne
        $self->decode_password($self->opts->community)) {
      $Monitoring::GLPlugin::SNMP::session = undef;
      $self->opts->override_opt('community',
          $self->decode_password($self->opts->community2)) ;
      $self->establish_snmp_session;
      return 1;
    }
  }
  return 0;
}

sub reset_snmp_max_msg_size {
  my ($self) = @_;
  $self->debug(sprintf "reset snmp_max_msg_size to %s",
      $Monitoring::GLPlugin::SNMP::max_msg_size);
  $Monitoring::GLPlugin::SNMP::session->max_msg_size($Monitoring::GLPlugin::SNMP::max_msg_size) if $Monitoring::GLPlugin::SNMP::session;
}

sub mult_snmp_max_msg_size {
  my ($self, $factor) = @_;
  $factor ||= 10;
  $self->debug(sprintf "raise snmp_max_msg_size %d * %d", 
      $factor, $Monitoring::GLPlugin::SNMP::session->max_msg_size()) if $Monitoring::GLPlugin::SNMP::session;
  $Monitoring::GLPlugin::SNMP::session->max_msg_size($factor * $Monitoring::GLPlugin::SNMP::session->max_msg_size()) if $Monitoring::GLPlugin::SNMP::session;
}

sub no_such_model {
  my ($self) = @_;
  printf "Model %s is not implemented\n", $self->{productname};
  exit 3;
}

sub no_such_mode {
  my ($self) = @_;
  if (ref($self) eq "Classes::Generic") {
    $self->init();
  } elsif (ref($self) eq "Classes::Device") {
    $self->add_message(UNKNOWN, 'the device did not implement the mibs this plugin is asking for');
    $self->add_message(UNKNOWN,
        sprintf('unknown device%s', $self->{productname} eq 'unknown' ?
            '' : '('.$self->{productname}.')'));
  } elsif (ref($self) eq "Monitoring::GLPlugin::SNMP") {
    # uptime, offline
    $self->init();
  } else {
    eval {
      bless $self, "Classes::Generic";
      $self->init();
    };
    if ($@) {
      bless $self, "Monitoring::GLPlugin::SNMP";
      $self->init();
    }
  }
  if (ref($self) eq "Monitoring::GLPlugin::SNMP") {
    printf "Mode %s is not implemented for this type of device\n",
        $self->opts->mode;
    exit 3;
  }
}

sub uptime {
  my ($self) = @_;
  return $Monitoring::GLPlugin::SNMP::uptime;
}

sub map_oid_to_class {
  my ($self, $oid, $class) = @_;
  $Monitoring::GLPlugin::SNMP::MibsAndOids::discover_ids->{$oid} = $class;
}

sub discover_suitable_class {
  my ($self) = @_;
  my $sysobj = $self->get_snmp_object('MIB-2-MIB', 'sysObjectID', 0);
  $sysobj =~ s/^\.//g;
  foreach my $oid (keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::discover_ids}) {
    if ($sysobj && $oid eq $sysobj) {
      return $Monitoring::GLPlugin::SNMP::MibsAndOids::discover_ids->{$sysobj};
    }
  }
}

sub require_mib {
  my ($self, $mib) = @_;
  my $package = uc $mib;
  $package =~ s/-//g;
  if (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib} ||
      exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib}) {
    $self->debug("i know package "."Monitoring::GLPlugin::SNMP::MibsAndOids::".$package);
    return;
  } else {
    eval {
      my @oldkeys = ();
      $self->set_variable("verbosity", 2);
      if ($self->get_variable("verbose")) {
        my @oldkeys = exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib} ?
            keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids} : 0;
      }
      $self->debug("load mib "."Monitoring::GLPlugin::SNMP::MibsAndOids::".$package);
      load "Monitoring::GLPlugin::SNMP::MibsAndOids::".$package;
      if ($self->get_variable("verbose")) {
        my @newkeys = exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib} ?
            keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids} : 0;
        $self->debug(sprintf "now i know: %s", join(" ", sort @newkeys));
        $self->debug(sprintf "now i know %d keys.", scalar(@newkeys));
        if (scalar(@newkeys) <= scalar(@oldkeys)) {
          $self->debug(sprintf "from %d to %d keys. why did we load?",
              scalar(@oldkeys), scalar(@newkeys));
        }
      }
    };
    if ($@) {
      $self->debug("failed to load "."Monitoring::GLPlugin::SNMP::MibsAndOids::".$package);
    } else {
      if (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::requirements->{$mib}) {
        foreach my $submib (@{$Monitoring::GLPlugin::SNMP::MibsAndOids::requirements->{$mib}}) {
          $self->require_mib($submib);
        }
      }
    }
  }
}

sub implements_mib {
  my ($self, $mib) = @_;
  $self->require_mib($mib);
  if (! exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib}) {
    return 0;
  }
  my $sysobj = $self->get_snmp_object('MIB-2-MIB', 'sysObjectID', 0);
  $sysobj =~ s/^\.// if $sysobj;
  if ($sysobj && $sysobj eq $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib}) {
    $self->debug(sprintf "implements %s (sysobj exact)", $mib);
    return 1;
  }
  if ($sysobj && $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib} eq
      substr $sysobj, 0, length $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib}) {
    $self->debug(sprintf "implements %s (sysobj)", $mib);
    return 1;
  }
  # some mibs are only composed of tables
  my $traces;
  if ($self->opts->snmpwalk) {
    my @matches;  
    # exact match  
    push(@matches, @{[map {  
        $_, $self->rawdata->{$_}  
    } grep {  
        $_ eq $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib}  
    } keys %{$self->rawdata}]});  
  
    # partial match (add trailing dot)  
    my $check = $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib};  
    $check =~ s/\.?$/./;  
    push(@matches, @{[map {  
        $_, $self->rawdata->{$_}  
    } grep {
        substr($_, 0, length($check)) eq $check  
    } keys %{$self->rawdata}]});  
    $traces = {@matches};  
  } else {
    my %params = (
        -varbindlist => [
            $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib}
        ]
    );
    if ($Monitoring::GLPlugin::SNMP::session->version() == 3) {
      $params{-contextengineid} = $self->opts->contextengineid if $self->opts->contextengineid;
      $params{-contextname} = $self->opts->contextname if $self->opts->contextname;
    }
    $traces = $Monitoring::GLPlugin::SNMP::session->get_next_request(%params);
  }
  if ($traces && # must find oids following to the ident-oid
      ! exists $traces->{$Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib}} && # must not be the ident-oid
      grep { # following oid is inside this tree
          substr($_, 0, length($Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib})) eq $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{$mib};
      } keys %{$traces}) {
    $self->debug(sprintf "implements %s (found traces)", $mib);
    return 1;
  }
}

sub timeticks {
  my ($self, $timestr) = @_;
  if ($timestr =~ /\((\d+)\)/) {
    # Timeticks: (20718727) 2 days, 9:33:07.27
    $timestr = $1 / 100;
  } elsif ($timestr =~ /(\d+)\s*day[s]*.*?(\d+):(\d+):(\d+)\.(\d+)/) {
    # Timeticks: 2 days, 9:33:07.27
    $timestr = $1 * 24 * 3600 + $2 * 3600 + $3 * 60 + $4;
  } elsif ($timestr =~ /(\d+):(\d+):(\d+):(\d+)\.(\d+)/) {
    # Timeticks: 0001:03:18:42.77
    $timestr = $1 * 3600 * 24 + $2 * 3600 + $3 * 60 + $4;
  } elsif ($timestr =~ /(\d+):(\d+):(\d+)\.(\d+)/) {
    # Timeticks: 9:33:07.27
    $timestr = $1 * 3600 + $2 * 60 + $3;
  } elsif ($timestr =~ /(\d+)\s*hour[s]*.*?(\d+):(\d+)\.(\d+)/) {
    # Timeticks: 3 hours, 42:17.98
    $timestr = $1 * 3600 + $2 * 60 + $3;
  } elsif ($timestr =~ /(\d+)\s*minute[s]*.*?(\d+)\.(\d+)/) {
    # Timeticks: 36 minutes, 01.96
    $timestr = $1 * 60 + $2;
  } elsif ($timestr =~ /(\d+)\.\d+\s*second[s]/) {
    # Timeticks: 01.02 seconds
    $timestr = $1;
  } elsif ($timestr =~ /^(\d+)$/) {
    $timestr = $1 / 100;
  }
  return $timestr;
}

sub human_timeticks {
  my ($self, $timeticks) = @_;
  my $days = int($timeticks / 86400);
  $timeticks -= ($days * 86400);
  my $hours = int($timeticks / 3600);
  $timeticks -= ($hours * 3600);
  my $minutes = int($timeticks / 60);
  my $seconds = $timeticks % 60;
  $days = $days < 1 ? '' : $days .'d ';
  return $days . sprintf "%dh %dm %ds", $hours, $minutes, $seconds;
}

sub internal_name {
  my ($self) = @_;
  my $class = ref($self);
  $class =~ s/^.*:://;
  if (exists $self->{flat_indices}) {
    return sprintf "%s_%s", uc $class, $self->{flat_indices};
  } else {
    return sprintf "%s", uc $class;
  }
}

################################################################
# file-related functions
#
sub create_interface_cache_file {
  my ($self) = @_;
  my $extension = "";
  if ($self->opts->snmpwalk && ! $self->opts->hostname) {
    $self->opts->override_opt('hostname',
        'snmpwalk.file'.md5_hex($self->opts->snmpwalk))
  }
  if ($self->opts->community) { 
    $extension .= md5_hex($self->opts->community);
  }
  $extension =~ s/\//_/g;
  $extension =~ s/\(/_/g;
  $extension =~ s/\)/_/g;
  $extension =~ s/\*/_/g;
  $extension =~ s/\s/_/g;
  return sprintf "%s/%s_interface_cache_%s", $self->statefilesdir(),
      $self->opts->hostname, lc $extension;
}

sub create_entry_cache_file {
  my ($self, $mib, $table, $key_attr_id) = @_;
  return lc sprintf "%s_%s_%s_%s_cache",
      $self->create_interface_cache_file(),
      $mib, $table, $key_attr_id;
}

sub update_entry_cache {
  my ($self, $force, $mib, $table, $key_attrs) = @_;
  my $update_deadline = time - 3600;
  my $must_update = 0;
  if (ref($key_attrs) ne "ARRAY") {
    if ($key_attrs eq 'flat_indices') {
      # wird nur 1x verwendet bisher, bei OLD-CISCO-INTERFACES-MIB etherstats
      #my $entry = $table =~ s/Table/Entry/gr; # zu neu fuer centos6
      my $entry = $table;
      $entry =~ s/Table/Entry/g;
      my @sortednames = map {
          $_->[0]
      } sort {
          $a->[1] cmp $b->[1]
      } map {
          [$_, join '', map {
              sprintf("%30d", $_)
          } split( /\./, $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$_})];
      } grep {
          $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$_} =~ /^$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$entry}\./;
      } keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}};
      $key_attrs = $sortednames[0];
    }
    $key_attrs = [$key_attrs];
  }
  my $key_attr_id = join('#', @{$key_attrs});
  my $cache = sprintf "%s_%s_%s_cache", $mib, $table, $key_attr_id;
  my $statefile = $self->create_entry_cache_file($mib, $table, $key_attr_id);
  if ($force == -1 && -f $statefile) {
    $must_update = 1;
    # brauchts unter keinen umstaenden.
    # z.b. wenn ein vorhergehender update_interfaces_cache keine aenderungen
    # angezeigt hat, dann spart man sich hier den etherlike-update o.ae.
    $self->debug(sprintf 'skip update of %s %s %s %s cache',
        $self->opts->hostname, $self->opts->mode, $mib, $table);
  } elsif ($force != 0 || ! -f $statefile || ((stat $statefile)[9]) < ($update_deadline)) {
    $must_update = 1;
    $self->debug(sprintf 'force update of %s %s %s %s cache',
        $self->opts->hostname, $self->opts->mode, $mib, $table);
    $self->{$cache} = {};
    foreach my $entry ($self->get_snmp_table_objects($mib, $table, undef, $key_attrs)) {
      my $key = join('#', map { $entry->{$_} } @{$key_attrs});
      my $hash = $key . '-//-' . join('.', @{$entry->{indices}});
      $self->{$cache}->{$hash} = $entry->{indices};
    }
    $self->save_cache($mib, $table, $key_attrs);
  }
  $self->load_cache($mib, $table, $key_attrs);
  return $must_update;
}

sub save_cache {
  my ($self, $mib, $table, $key_attrs) = @_;
  my $cache = sprintf "%s_%s_%s_cache", $mib, $table, join('#', @{$key_attrs});
  $self->create_statefilesdir();
  my $statefile = $self->create_entry_cache_file($mib, $table, join('#', @{$key_attrs}));
  open(STATE, ">".$statefile.".".$$);
  printf STATE Data::Dumper::Dumper($self->{$cache});
  close STATE;
  rename $statefile.".".$$, $statefile;
  $self->debug(sprintf "saved %s to %s",
      Data::Dumper::Dumper($self->{$cache}), $statefile);
}

sub load_cache {
  my ($self, $mib, $table, $key_attrs) = @_;
  my $cache = sprintf "%s_%s_%s_cache", $mib, $table, join('#', @{$key_attrs});
  my $statefile = $self->create_entry_cache_file($mib, $table, join('#', @{$key_attrs}));
  $self->{$cache} = {};
  if ( -f $statefile) {
    our $VAR1;
    our $VAR2;
    eval {
      require $statefile;
    };
    if($@) {
      printf "rumms\n";
    }
    # keinesfalls mehr require verwenden!!!!!!
    # beim require enthaelt VAR1 andere werte als beim slurp
    # und zwar diejenigen, die beim letzten save_cache geschrieben wurden.
    my $content = do { local (@ARGV, $/) = $statefile; my $x = <>; close ARGV; $x };
    $VAR1 = eval "$content";
    $self->debug(sprintf "load %s", Data::Dumper::Dumper($VAR1));
    $self->{$cache} = $VAR1;
  }
}


################################################################
# top-level convenience functions
#
sub get_snmp_objects {
  my ($self, $mib, @mos) = @_;
  foreach (@mos) {
    #my $value = $self->get_snmp_object($mib, $_, 0);
    #if (defined $value) {
    #  $self->{$_} = $value;
    #} else {
      my $value = $self->get_snmp_object($mib, $_);
      if (defined $value) {
        $self->{$_} = $value;
      }
    #}
  }
}

sub get_snmp_tables {
  my ($self, $mib, $infos) = @_;
  foreach my $info (@{$infos}) {
    my $arrayname = $info->[0];
    my $table = $info->[1];
    my $class = $info->[2];
    my $filter = $info->[3];
    my $rows = $info->[4];
    $self->{$arrayname} = [] if ! exists $self->{$arrayname};
    if (! exists $Monitoring::GLPlugin::SNMP::tablecache->{$mib} || ! exists $Monitoring::GLPlugin::SNMP::tablecache->{$mib}->{$table}) {
      $Monitoring::GLPlugin::SNMP::tablecache->{$mib}->{$table} = [];
      foreach ($self->get_snmp_table_objects($mib, $table, undef, $rows)) {
        push(@{$Monitoring::GLPlugin::SNMP::tablecache->{$mib}->{$table}}, $_);
        my $new_object = $class->new(%{$_});
        next if (defined $filter && ! &$filter($new_object));
        push(@{$self->{$arrayname}}, $new_object);
      }
    } else {
      $self->debug(sprintf "get_snmp_tables %s %s cache hit", $mib, $table);
      foreach (@{$Monitoring::GLPlugin::SNMP::tablecache->{$mib}->{$table}}) {
        my $new_object = $class->new(%{$_});
        next if (defined $filter && ! &$filter($new_object));
        push(@{$self->{$arrayname}}, $new_object);
      }
    }
  }
}

sub merge_tables {
  my ($self, $into, @from) = @_;
  my $into_indices = {};
  map { $into_indices->{$_->{flat_indices}} = $_ } @{$self->{$into}};
  foreach (@from) {
    foreach my $element (@{$self->{$_}}) {
      if (exists $into_indices->{$element->{flat_indices}}) {
        foreach my $key (keys %{$element}) {
          $into_indices->{$element->{flat_indices}}->{$key} = $element->{$key};
        }
      }
    }
    delete $self->{$_};
  }
}

sub merge_tables_with_code {
  my ($self, $into, @from) = @_;
  my $into_indices = {};
  my @to_del = ();
  foreach my $into_elem (@{$self->{$into}}) {
    for (my $i = 0; $i < @from; $i += 2) {
      my ($from_elems, $func) = @from[$i, $i+1];
      foreach my $from_elem (@{$self->{$from_elems}}) {
        if (&$func($into_elem, $from_elem)) {
          foreach my $key (grep !/^(info|trace|warning|critical|blacklisted|extendedinfo|flat_indices|indices)/, sort keys %{$from_elem}) {
            $into_elem->{$key} = $from_elem->{$key};
          }
        }
      }
    }
  }
  for (my $i = 0; $i < @from; $i += 2) {
    my ($from_elems, $func) = @from[$i, $i+1];
    delete $self->{$from_elems};
  }
}

sub mibs_and_oids_definition {
  my ($self, $mib, $definition, @values) = @_;
  if (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib} &&
      exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}) {
    if (ref($Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}) eq "CODE") {
      return $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}->(@values);
    } elsif (ref($Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}) eq "HASH") {
      return $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}->{$values[0]};
    }
  } else {
    return "unknown_".$definition;
  }
}

sub clear_table_cache {
  my ($self, $mib, $table) = @_;
  if ($table && exists $Monitoring::GLPlugin::SNMP::tablecache->{$mib}) {
    delete $Monitoring::GLPlugin::SNMP::tablecache->{$mib}->{$table};
  } elsif ($mib) {
    delete $Monitoring::GLPlugin::SNMP::tablecache->{$mib};
  } else {
    $Monitoring::GLPlugin::SNMP::tablecache = {};
  }
}

################################################################
# 2nd level 
#
sub get_snmp_object {
  my ($self, $mib, $mo, $index) = @_;
  $self->require_mib($mib);
  if (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib} &&
      exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$mo}) {
    my $oid = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$mo}.
        (defined $index ? '.'.$index : '');
    my $response = $self->get_request(-varbindlist => [$oid]);
    if (defined $response->{$oid}) {
      if ($response->{$oid} eq 'noSuchInstance' || $response->{$oid} eq 'noSuchObject') {
        $response->{$oid} = undef;
      } elsif (my @symbols = $self->make_symbolic($mib, $response, [[$index]])) {
        $response->{$oid} = $symbols[0]->{$mo};
      }
    }
    $self->debug(sprintf "GET: %s::%s (%s) : %s", $mib, $mo, $oid, defined $response->{$oid} ? $response->{$oid} : "<undef>");
    if (! defined $response->{$oid} && ! defined $index) {
      return $self->get_snmp_object($mib, $mo, 0);
    }
    return $response->{$oid};
  }
  return undef;
}

sub get_snmp_table_objects_with_cache {
  my ($self, $mib, $table, $key_attr, $rows, $force) = @_;
  $force ||= 0;
  $self->update_entry_cache($force, $mib, $table, $key_attr);
  my @indices = $self->get_cache_indices($mib, $table, $key_attr);
  my @entries = ();
  foreach ($self->get_snmp_table_objects($mib, $table, \@indices, $rows)) {
    push(@entries, $_);
  }
  return @entries;
}

sub get_table_row_oids {
  my ($self, $mib, $table, $rows) = @_;
  $self->require_mib($mib);
  my $entry = $table;
  $entry =~ s/Table/Entry/g;
  my $eoid = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$entry}.'.';
  my $eoidlen = length($eoid);
  my @columns = scalar(@{$rows}) ?
  grep {
      substr($_, 0, $eoidlen) eq $eoid
  } map {
      $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$_}
  } @{$rows}
  :
  grep {
      substr($_, 0, $eoidlen) eq $eoid
  } map {
      $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$_}
  } keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}};
  return @columns;
}

# get_snmp_table_objects('MIB-Name', 'Table-Name', 'Table-Entry', [indices])
# returns array of hashrefs
sub get_snmp_table_objects {
  my ($self, $mib, $table, $indices, $rows) = @_;
  $indices ||= [];
  $rows ||= [];
  $self->require_mib($mib);
  my @entries = ();
  my $augmenting_table;
  $self->debug(sprintf "get_snmp_table_objects %s %s", $mib, $table);
  if ($table =~ /^(.*?)\+(.*)/) {
    $table = $1;
    $augmenting_table = $2;
  }
  my $entry = $table;
  $entry =~ s/Table/Entry/g;
  if (! exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib} ||
      ! exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$table}) {
    return @entries;
  }
  if (! exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$entry}) {
    $self->debug(sprintf "table %s::%s has no entry oid", $mib, $table);
    return @entries;
  }
  my @columns = $self->get_table_row_oids($mib, $table, $rows);
  my @augmenting_columns = ();
  if($augmenting_table) {
    @augmenting_columns = $self->get_table_row_oids($mib, $augmenting_table, $rows);
  }
  if (scalar(@{$indices}) == 1 && $indices->[0] == -1) {
    # get mini-version of a table
    my $result = $self->get_entries(
        -columns => \@columns,
    );
    if ($augmenting_table) {
      my $augmenting_result = $self->get_entries(
          -columns => \@augmenting_columns,
      );
      map { $result->{$_} = $augmenting_result->{$_} }
          keys %{$augmenting_result};
    }
    my @indices = 
        $self->get_indices(
            -baseoid => $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$entry},
            -oids => [keys %{$result}]);
    @entries = $self->make_symbolic($mib, $result, \@indices);
    @entries = map { $_->{indices} = shift @indices; $_ } @entries;
    $self->debug(sprintf "get_snmp_table_objects mini returns %d entries",
        scalar(@entries));
  } elsif (scalar(@{$indices}) == 1) {
    my $index = join('.', @{$indices->[0]});
    my $result = $self->get_entries(
        -startindex => $index,
        -endindex => $index,
        -columns => \@columns,
    );
    if ($augmenting_table) {
      my $augmenting_result = $self->get_entries(
          -startindex => $index,
          -endindex => $index,
          -columns => \@augmenting_columns,
      );
      map { $result->{$_} = $augmenting_result->{$_} }
          keys %{$augmenting_result};
    }
    @entries = $self->make_symbolic($mib, $result, $indices);
    @entries = map { $_->{indices} = shift @{$indices}; $_ } @entries;
    $self->debug(sprintf "get_snmp_table_objects single returns %d entries",
        scalar(@entries));
  } elsif (scalar(@{$indices}) > 1) {
    my $result = {};
    my @sortedindices = $self->sort_indices($indices);
    my $startindex = $sortedindices[0];
    my $endindex = $sortedindices[$#sortedindices];
    if (0) {
      # holzweg. dicke ciscos liefern unvollstaendiges resultat, d.h.
      # bei 138,19,157 kommt nur 138..144, dann ist schluss.
      # maxrepetitions bringt nichts.
      $result = $self->get_entries(
          -startindex => $startindex,
          -endindex => $endindex,
          -columns => \@columns,
      );
    } else {
      foreach my $idx (@sortedindices) {
        my $tmp_result = $self->get_entries(
            -startindex => $idx,
            -endindex => $idx,
            -columns => \@columns,
        );
        map { $result->{$_} = $tmp_result->{$_} }
            keys %{$tmp_result};
      }
    }
    if ($augmenting_table) {
      foreach my $idx (@sortedindices) {
        my $tmp_result = $self->get_entries(
            -startindex => $idx,
            -endindex => $idx,
            -columns => \@augmenting_columns,
        );
        map { $result->{$_} = $tmp_result->{$_} }
            keys %{$tmp_result};
      }
    }
    # now we have numerical_oid+index => value
    # needs to become symboic_oid => value
    #my @indices =
    # $self->get_indices($Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$entry});
    @entries = $self->make_symbolic($mib, $result, $indices);
    @entries = map { $_->{indices} = shift @{$indices}; $_ } @entries;
    $self->debug(sprintf "get_snmp_table_objects single returns %d entries",
        scalar(@entries));
  } elsif (scalar(@{$rows})) {
    my $result = $self->get_entries(
        -columns => \@columns,
    );
    if ($augmenting_table) {
      my $augmenting_result = $self->get_entries(
          -columns => \@augmenting_columns,
      );
      map { $result->{$_} = $augmenting_result->{$_} }
          keys %{$augmenting_result};
    }
    my @indices =
        $self->get_indices(
            -baseoid => $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$entry},
            -oids => [keys %{$result}]);
    @entries = $self->make_symbolic($mib, $result, \@indices);
    @entries = map { $_->{indices} = shift @indices; $_ } @entries;
    $self->debug(sprintf "get_snmp_table_objects rows returns %d entries",
        scalar(@entries));
  } else {
    my $result = $self->get_table(
        -baseoid => $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$table});
    if ($augmenting_table) {
      my $augmenting_result = $self->get_entries(
          -columns => \@augmenting_columns,
      );
      map { $result->{$_} = $augmenting_result->{$_} }
          keys %{$augmenting_result};
    }
    # now we have numerical_oid+index => value
    # needs to become symboic_oid => value
    my @indices = 
        $self->get_indices(
            -baseoid => $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$entry},
            -oids => [keys %{$result}]);
    @entries = $self->make_symbolic($mib, $result, \@indices);
    @entries = map { $_->{indices} = shift @indices; $_ } @entries;
    $self->debug(sprintf "get_snmp_table_objects default returns %d entries",
        scalar(@entries));
  }
  @entries = map { $_->{flat_indices} = join(".", @{$_->{indices}}); $_ } @entries;
  return @entries;
}

sub bulk_is_baeh {
  my ($self, $maxrepetitions) = @_;
  $maxrepetitions ||= 1;
  $Monitoring::GLPlugin::SNMP::maxrepetitions = $maxrepetitions;
}

################################################################
# 3rd level functions. calling net::snmp-functions
# 
sub get_request {
  my ($self, %params) = @_;
  my @notcached = ();
  foreach my $oid (@{$params{'-varbindlist'}}) {
    $self->add_oidtrace($oid);
    if (! exists $Monitoring::GLPlugin::SNMP::rawdata->{$oid}) {
      push(@notcached, $oid);
    }
  }
  if (! $self->opts->snmpwalk && (scalar(@notcached) > 0)) {
    my %params = ();
    if ($Monitoring::GLPlugin::SNMP::session->version() == 0) {
      $params{-varbindlist} = \@notcached;
    } elsif ($Monitoring::GLPlugin::SNMP::session->version() == 1) {
      $params{-varbindlist} = \@notcached;
      #$params{-nonrepeaters} = scalar(@notcached);
    } elsif ($Monitoring::GLPlugin::SNMP::session->version() == 3) {
      $params{-varbindlist} = \@notcached;
      $params{-contextengineid} = $self->opts->contextengineid if $self->opts->contextengineid;
      $params{-contextname} = $self->opts->contextname if $self->opts->contextname;
    }
    my $result = $Monitoring::GLPlugin::SNMP::session->get_request(%params);
    # so, und jetzt gibts stinkstiefel, die kriegen
    # params{-varbindlist => [1.3.6.1.4.1.318.1.1.1.1.1.1]
    # und result ist
    # { 1.3.6.1.4.1.318.1.1.1.1.1.1.0 => "Smart-UPS RT 10000 XL" }
    # letzteres kommt in raw_data
    # und beim abschliessenden map wirds natuerlich nicht mehr gefunden 
    # also leeres return. <<kraftausdruck>>
    foreach my $key (%{$result}) {
      # so, und zwei jahre spaeter kommt man drauf, dass es viele sorten 
      # von stinkstiefeln gibt. die fragt man nach 1.3.6.1.4.1.13885.120.1.3.1
      # und kriegt als antwort 1.3.6.1.4.1.13885.120.1.3.1.0=[noSuchInstance]
      # bis zum 11.10.16 wurde das in den cache geschrieben. eine etage hoeher
      # wird aber dann nach 1.3.6.1.4.1.13885.120.1.3.1.0 gefallbacked, was
      # dann prompt aus dem cache gefischt wird, anstatt den agenten zu fragen,
      # der in diesem fall eine saubere antwort liefern wuerde.
      # ergo: keine fehlermeldungen in den chache
      $self->add_rawdata($key, $result->{$key}) if defined $result->{$key} && $result->{$key} ne 'noSuchInstance';
    }
  }
  my $result = {};
  map {
      $result->{$_} = exists $Monitoring::GLPlugin::SNMP::rawdata->{$_} ?
          $Monitoring::GLPlugin::SNMP::rawdata->{$_} :
      exists $Monitoring::GLPlugin::SNMP::rawdata->{$_.'.0'} ?
          $Monitoring::GLPlugin::SNMP::rawdata->{$_.'.0'} : undef;
  } @{$params{'-varbindlist'}};
  return $result;
}

sub get_entries_get_bulk {
  my ($self, %params) = @_;
  my $result = {};
  $self->debug(sprintf "get_entries_get_bulk %s", Data::Dumper::Dumper(\%params));
  my %newparams = ();
  $newparams{'-maxrepetitions'} = 3;
  $newparams{'-startindex'} = $params{'-startindex'}
      if defined $params{'-startindex'};
  $newparams{'-endindex'} = $params{'-endindex'}
      if defined $params{'-endindex'};
  $newparams{'-columns'} = $params{'-columns'};
  if ($Monitoring::GLPlugin::SNMP::session->version() == 3) {
    $newparams{-contextengineid} = $self->opts->contextengineid if $self->opts->contextengineid;
    $newparams{-contextname} = $self->opts->contextname if $self->opts->contextname;
  }
  $result = $Monitoring::GLPlugin::SNMP::session->get_entries(%newparams);
  return $result;
}

sub get_entries_get_next {
  my ($self, %params) = @_;
  my $result = {};
  $self->debug(sprintf "get_entries_get_next %s", Data::Dumper::Dumper(\%params));
  my %newparams = ();
  $newparams{'-maxrepetitions'} = 0;
  $newparams{'-startindex'} = $params{'-startindex'}
      if defined $params{'-startindex'};
  $newparams{'-endindex'} = $params{'-endindex'}
      if defined $params{'-endindex'};
  $newparams{'-columns'} = $params{'-columns'};
  if ($Monitoring::GLPlugin::SNMP::session->version() == 3) {
    $newparams{-contextengineid} = $self->opts->contextengineid if $self->opts->contextengineid;
    $newparams{-contextname} = $self->opts->contextname if $self->opts->contextname;
  }
  $result = $Monitoring::GLPlugin::SNMP::session->get_entries(%newparams);
  return $result;
}

sub get_entries_get_next_1index {
  my ($self, %params) = @_;
  my $result = {};
  $self->debug(sprintf "get_entries_get_next_1index %s", Data::Dumper::Dumper(\%params));
  my %newparams = ();
  $newparams{'-startindex'} = $params{'-startindex'}
      if defined $params{'-startindex'};
  $newparams{'-endindex'} = $params{'-endindex'}
      if defined $params{'-endindex'};
  $newparams{'-columns'} = $params{'-columns'};
  my %singleparams = ();
  $singleparams{'-maxrepetitions'} = 0;
  if ($Monitoring::GLPlugin::SNMP::session->version() == 3) {
    $singleparams{-contextengineid} = $self->opts->contextengineid if $self->opts->contextengineid;
    $singleparams{-contextname} = $self->opts->contextname if $self->opts->contextname;
  }
  foreach my $index ($newparams{'-startindex'}..$newparams{'-endindex'}) {
    foreach my $oid (@{$newparams{'-columns'}}) {
      $singleparams{'-columns'} = [$oid];
      $singleparams{'-startindex'} = $index;
      $singleparams{'-endindex'} =$index;
      my $singleresult = $Monitoring::GLPlugin::SNMP::session->get_entries(%singleparams);
      foreach my $key (keys %{$singleresult}) {
        $result->{$key} = $singleresult->{$key};
      }
    }
  }
  return $result;
}

sub get_entries_get_simple {
  my ($self, %params) = @_;
  my $result = {};
  $self->debug(sprintf "get_entries_get_simple %s", Data::Dumper::Dumper(\%params));
  my %newparams = ();
  $newparams{'-startindex'} = $params{'-startindex'}
      if defined $params{'-startindex'};
  $newparams{'-endindex'} = $params{'-endindex'}
      if defined $params{'-endindex'};
  $newparams{'-columns'} = $params{'-columns'};
  my %singleparams = ();
  if ($Monitoring::GLPlugin::SNMP::session->version() == 3) {
    $singleparams{-contextengineid} = $self->opts->contextengineid if $self->opts->contextengineid;
    $singleparams{-contextname} = $self->opts->contextname if $self->opts->contextname;
  }
  foreach my $index ($newparams{'-startindex'}..$newparams{'-endindex'}) {
    foreach my $oid (@{$newparams{'-columns'}}) {
      $singleparams{'-varbindlist'} = [$oid.".".$index];
      my $singleresult = $Monitoring::GLPlugin::SNMP::session->get_request(%singleparams);
      foreach my $key (keys %{$singleresult}) {
        if ($singleresult->{$key} eq "noSuchObject" ||
            $singleresult->{$key} eq "noSuchInstance" ||
            $singleresult->{$key} eq "endOfMibView") {
          $result->{$key} = undef;
        } else {
          $result->{$key} = $singleresult->{$key};
        }
      }
    }
  }
  return $result;
}

sub get_entries {
  my ($self, %params) = @_;
  # [-startindex]
  # [-endindex]
  # -columns
  $params{'-columns'} = [$self->sort_oids($params{'-columns'})];
  my $result = {};
  $self->debug(sprintf "get_entries %s", Data::Dumper::Dumper(\%params));
  if (! $self->opts->snmpwalk) {
    if (scalar (@{$params{'-columns'}}) < 5 && $params{'-endindex'} && $params{'-startindex'} eq $params{'-endindex'}) {
      $result = $self->get_entries_get_simple(%params);
    } else {
      $result = $self->get_entries_get_bulk(%params);
      if (! $result) {
        $self->debug("bulk failed, retry simple");
        if ($Monitoring::GLPlugin::SNMP::session->error() =~ /The message size exceeded the buffer maxMsgSize of (\d+)/i) {
          $self->debug(sprintf "buffer exceeded. raise *5 for next try");
          $self->mult_snmp_max_msg_size(5);
        } else {
          $self->debug($Monitoring::GLPlugin::SNMP::session->error());
        }
        if (defined $params{'-endindex'} && defined $params{'-startindex'}) {
          $result = $self->get_entries_get_simple(%params);
        } else {
          $result = $self->get_entries_get_next(%params);
        }
      }
    }
    if (! $result) {
      $result = $self->get_entries_get_next(%params);
      if (! $result && defined $params{'-startindex'} && $params{'-startindex'} !~ /\./) {
        # compound indexes cannot continue, as these two methods iterate numerically
        if ($Monitoring::GLPlugin::SNMP::session->error() =~ /tooBig/i) {
          $self->debug(sprintf "answer too big");
          $result = $self->get_entries_get_next_1index(%params);
        }
        if (! $result) {
          $result = $self->get_entries_get_simple(%params);
        }
        if (! $result) {
          $self->debug(sprintf "nutzt nix\n");
        }
      }
    }
    foreach my $key (keys %{$result}) {
      if (substr($key, -1) eq " ") {
        my $value = $result->{$key};
        delete $result->{$key};
        $key =~ s/\s+$//g;
        $result->{$key} = $value;
        #
        # warum?
        #
        # %newparams ist:
        #  '-columns' => [
        #                  '1.3.6.1.2.1.2.2.1.8',
        #                  '1.3.6.1.2.1.2.2.1.13',
        #                  ...
        #                  '1.3.6.1.2.1.2.2.1.16'
        #                ],
        #  '-startindex' => '2',
        #  '-endindex' => '2'
        #
        # und $result ist:
        #  ...
        #  '1.3.6.1.2.1.2.2.1.2.2' => 'Adaptive Security Appliance \'outside\' interface',
        #  '1.3.6.1.2.1.2.2.1.16.2 ' => 4281465004,
        #  '1.3.6.1.2.1.2.2.1.13.2' => 0,
        #  ...
        #
        # stinkstiefel!
        #
      }
      $self->add_rawdata($key, $result->{$key});
    }
  } else {
    my $preresult = $self->get_matching_oids(
        -columns => $params{'-columns'});
    foreach (keys %{$preresult}) {
      $result->{$_} = $preresult->{$_};
    }
    my @sortedkeys = $self->sort_oids([keys %{$result}]);
    my @to_del = ();
    if ($params{'-startindex'}) {
      foreach my $resoid (@sortedkeys) {
        foreach my $oid (@{$params{'-columns'}}) {
          my $poid = $oid.'.';
          my $lpoid = length($poid);
          if (substr($resoid, 0, $lpoid) eq $poid) {
            my $oidpattern = $poid;
            $oidpattern =~ s/\./\\./g;
            if ($resoid =~ /^$oidpattern(.+)$/) {
              if ($1 lt $params{'-startindex'}) {
                push(@to_del, $oid.'.'.$1);
              }
            }
          }
        }
      }
    }
    if ($params{'-endindex'}) {
      foreach my $resoid (@sortedkeys) {
        foreach my $oid (@{$params{'-columns'}}) {
          my $poid = $oid.'.';
          my $lpoid = length($poid);
          if (substr($resoid, 0, $lpoid) eq $poid) {
            my $oidpattern = $poid;
            $oidpattern =~ s/\./\\./g;
            if ($resoid =~ /^$oidpattern(.+)$/) {
              if ($1 gt $params{'-endindex'}) {
                push(@to_del, $oid.'.'.$1);
              }
            }
          }
        }
      }
    }
    foreach (@to_del) {
      delete $result->{$_};
    }
  }
  return $result;
}

sub get_entries_by_walk {
  my ($self, %params) = @_;
  if (! $self->opts->snmpwalk) {
    $self->add_ok("if you get this crap working correctly, let me know");
    if ($Monitoring::GLPlugin::SNMP::session->version() == 3) {
      $params{-contextengineid} = $self->opts->contextengineid if $self->opts->contextengineid;
      $params{-contextname} = $self->opts->contextname if $self->opts->contextname;
    }
    $self->debug(sprintf "get_tree %s", Data::Dumper::Dumper(\%params));
    my @baseoids = @{$params{-varbindlist}};
    delete $params{-varbindlist};
    if ($Monitoring::GLPlugin::SNMP::session->version() == 0) {
      foreach my $baseoid (@baseoids) {
        $params{-varbindlist} = [$baseoid];
        while (my $result = $Monitoring::GLPlugin::SNMP::session->get_next_request(%params)) {
          $params{-varbindlist} = [($Monitoring::GLPlugin::SNMP::session->var_bind_names)[0]];
        }
      }
    } else {
      $params{-maxrepetitions} = 200;
      foreach my $baseoid (@baseoids) {
        $params{-varbindlist} = [$baseoid];
        while (my $result = $Monitoring::GLPlugin::SNMP::session->get_bulk_request(%params)) {
          my @names = $Monitoring::GLPlugin::SNMP::session->var_bind_names();
          my @oids = $self->sort_oids(\@names);
          $params{-varbindlist} = [pop @oids];
        }
      }
    }
  } else {
    return $self->get_matching_oids(
        -columns => $params{-varbindlist});
  }
}

sub get_table {
  my ($self, %params) = @_;
  $self->add_oidtrace($params{'-baseoid'});
  if (! $self->opts->snmpwalk) {
    my @notcached = ();
    if ($Monitoring::GLPlugin::SNMP::session->version() == 3) {
      $params{-contextengineid} = $self->opts->contextengineid if $self->opts->contextengineid;
      $params{-contextname} = $self->opts->contextname if $self->opts->contextname;
    }
    if ($Monitoring::GLPlugin::SNMP::maxrepetitions) {
      # some devices (Bintec) don't like bulk-requests. They call bulk_is_baeh(), so
      # we immediately send get-next
      $params{'-maxrepetitions'} = $Monitoring::GLPlugin::SNMP::maxrepetitions;
    }
    $self->debug(sprintf "get_table %s", Data::Dumper::Dumper(\%params));
    my $result = $Monitoring::GLPlugin::SNMP::session->get_table(%params);
    $self->debug(sprintf "get_table returned %d oids", scalar(keys %{$result}));
    if (scalar(keys %{$result}) == 0) {
      $self->debug(sprintf "get_table error: %s", 
          $Monitoring::GLPlugin::SNMP::session->error());
      if ($Monitoring::GLPlugin::SNMP::session->error() =~ /The message size exceeded the buffer maxMsgSize of (\d+)/i) {
        # bei irrsinnigen maxrepetitions
        $self->debug(sprintf "buffer exceeded");
        #$self->reset_snmp_max_msg_size();
        if ($params{'-maxrepetitions'}) {
          $params{'-maxrepetitions'} = int($params{'-maxrepetitions'} / 2);
          $self->debug(sprintf "reduce maxrepetitions to %d",
              $params{'-maxrepetitions'});
        } else {
          $self->mult_snmp_max_msg_size(2);
        }
      }
      $self->debug("get_table error: try fallback");
      $self->debug(sprintf "get_table %s", Data::Dumper::Dumper(\%params));
      $result = $Monitoring::GLPlugin::SNMP::session->get_table(%params);
      $self->debug(sprintf "get_table returned %d oids", scalar(keys %{$result}));
      if (scalar(keys %{$result}) == 0) {
        $self->debug(sprintf "get_table error: %s", 
            $Monitoring::GLPlugin::SNMP::session->error());
        if (exists $params{'-maxrepetitions'} && $params{'-maxrepetitions'} > 1) {
          $params{'-maxrepetitions'} = 1;
          $self->debug("get_table error: try getnext fallback");
          $self->debug(sprintf "get_table %s", Data::Dumper::Dumper(\%params));
          $result = $Monitoring::GLPlugin::SNMP::session->get_table(%params);
          $self->debug(sprintf "get_table returned %d oids", scalar(keys %{$result}));
        }
        if (scalar(keys %{$result}) == 0) {
          $self->debug("get_table error: no more fallbacks. Try --protocol 1");
        }
      }
    }
    # Drecksstinkstiefel Net::SNMP
    # '1.3.6.1.2.1.2.2.1.22.4 ' => 'endOfMibView',
    # '1.3.6.1.2.1.2.2.1.22.4' => '0.0',
    foreach my $key (keys %{$result}) {
      if (substr($key, -1) eq " ") {
        my $value = $result->{$key};
        delete $result->{$key};
        (my $shortkey = $key) =~ s/\s+$//g;
        if (! exists $result->{shortkey}) {
          $result->{$shortkey} = $value;
        }
        $self->add_rawdata($key, $result->{$key}) if exists $result->{$key};
      } else {
        $self->add_rawdata($key, $result->{$key});
      }
    }
  }
  return $self->get_matching_oids(
      -columns => [$params{'-baseoid'}]);
}

################################################################
# helper functions
# 
sub valid_response {
  my ($self, $mib, $mo, $index) = @_;
  $self->require_mib($mib);
  if (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib} &&
      exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$mo}) {
    # make it numerical
    my $oid = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$mo};
    if (defined $index) {
      $oid .= '.'.$index;
    }
    my $result = $self->get_request(
        -varbindlist => [$oid]
    );
    if (!defined($result) ||
        ! defined $result->{$oid} ||
        $result->{$oid} eq 'noSuchInstance' ||
        $result->{$oid} eq 'noSuchObject' ||
        $result->{$oid} eq 'endOfMibView') {
      $self->debug(sprintf "GET: %s::%s (%s) : %s", $mib, $mo, $oid, defined $result->{$oid} ? $result->{$oid} : "<undef>");
      return undef;
    } else {
      $self->debug(sprintf "GET: %s::%s (%s) : %s", $mib, $mo, $oid, defined $result->{$oid} ? $result->{$oid} : "<undef>");
      $self->add_rawdata($oid, $result->{$oid});
      return $result->{$oid};
    }
  } else {
    return undef;
  }
}

sub get_symbol {
  my ($self, $mib, $oid) = @_;
  # "LIEBERT-GP-ENVIRONMENTAL-MIB", "1.3.6.1.4.1.476.1.42.3.4.1.1.4"
  # dahinter steckt
  # lgpEnvSupplyAirTemperature => '1.3.6.1.4.1.476.1.42.3.4.1.1.3'
  # lgpAmbientTemperature => '1.3.6.1.4.1.476.1.42.3.4.1.1.4'
  # und als info vom geraet
  # LgpEnvTemperatureMeasurementDegC = '1.3.6.1.4.1.476.1.42.3.4.1.1.4'
  # der name des temp. sensor wird ueber die oid mitgeteilt
  $self->require_mib($mib);
  foreach my $symoid
      (keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}}) {
    if ($oid eq $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid}) {
      return $symoid;
    }
  }
  return undef;
}

# make_symbolic
# mib is the name of a mib (must be in mibs_and_oids)
# result is a hash-key oid->value
# indices is a array ref of array refs. [[1],[2],...] or [[1,0],[1,1],[2,0]..
sub make_symbolic {
  my ($self, $mib, $result, $indices) = @_;
  $self->require_mib($mib);
  my @entries = ();
  if (! wantarray && ref(\$result) eq "SCALAR" && ref(\$indices) eq "SCALAR") {
    # $self->make_symbolic('CISCO-IETF-NAT-MIB', 'cnatProtocolStatsName', $self->{cnatProtocolStatsName});
    my $oid = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$result};
    $result = { $oid => $self->{$result} };
    $indices = [[]];
  }
  foreach my $index (@{$indices}) {
    # skip [], [[]], [[undef]]
    if (ref($index) eq "ARRAY") {
      if (scalar(@{$index}) == 0) {
        next;
      } elsif (!defined $index->[0]) {
        next;
      }
    }
    my $mo = {};
    my $idx = join('.', @{$index}); # index can be multi-level
    foreach my $symoid
        (keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}}) {
      my $oid = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid};
      if (ref($oid) ne 'HASH') {
        my $fulloid = $oid . '.'.$idx;
        if (exists $result->{$fulloid}) {
          if (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}) {
            if (ref($Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}) eq 'HASH') {
              if (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}->{$result->{$fulloid}}) {
                $mo->{$symoid} = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}->{$result->{$fulloid}};
              } else {
                $mo->{$symoid} = 'unknown_'.$result->{$fulloid};
              }
            } elsif ($Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'} =~ /^OID::(.*)/) {
              my $othermib = $1;
              if (! exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$othermib}) {
                # may point to another mib's definitions, which hasn't 
                # been used yet.
                $self->require_mib($othermib);
              }
              my $value_which_is_a_oid = $result->{$fulloid};
              $value_which_is_a_oid =~ s/^\.//g;
              my @result = grep { $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$othermib}->{$_} eq $value_which_is_a_oid } keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$othermib}};
              if (scalar(@result)) {
                $mo->{$symoid} = $result[0];
              } else {
                $mo->{$symoid} = 'unknown_'.$result->{$fulloid};
              }
            } elsif ($Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'} =~ /^(.*?)::(.*)/) {
              my $mib = $1;
              my $definition = $2;
              if (! exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}) {
                # may point to another mib's definitions, which hasn't 
                # been used yet.
                $self->require_mib($mib);
              }
              if  (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib} &&
                  exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition} &&
                  ref($Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}) eq 'CODE') {
                $mo->{$symoid} = $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}->($result->{$fulloid});
              } elsif  (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib} &&
                  exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition} &&
                  ref($Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}) eq 'HASH' &&
                  exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}->{$result->{$fulloid}}) {
                $mo->{$symoid} = $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}->{$result->{$fulloid}};
              } else {
                $mo->{$symoid} = 'unknown_'.$result->{$fulloid};
              }
            } else {
              $mo->{$symoid} = 'unknown_'.$result->{$fulloid};
              # oder $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}?
            }
          } else {
            $mo->{$symoid} = $result->{$fulloid};
          }
        }
      }
    }
    push(@entries, $mo);
  }
  if (@{$indices} and scalar(@{$indices}) == 1 and !defined $indices->[0]->[0]) {
    my $mo = {};
    foreach my $symoid
        (keys %{$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}}) {
      my $oid = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid};
      if (ref($oid) ne 'HASH') {
        if (exists $result->{$oid}) {
          if (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}) {
            if (ref($Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}) eq 'HASH') {
              if (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}->{$result->{$oid}}) {
                $mo->{$symoid} = $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}->{$result->{$oid}};
                push(@entries, $mo);
              }
            } elsif ($Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'} =~ /^(.*?)::(.*)/) {
              my $mib = $1;
              my $definition = $2;
              if  (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib} &&
                  exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition} &&
                  ref($Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}) eq 'CODE') {
                $mo->{$symoid} = $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}->($result->{$oid});
              } elsif  (exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib} &&
                  exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition} &&
                  ref($Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}) eq 'HASH' &&
                  exists $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}->{$result->{$oid}}) {
                $mo->{$symoid} = $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{$mib}->{$definition}->{$result->{$oid}};
              } else {
                $mo->{$symoid} = 'unknown_'.$result->{$oid};
              }
            } else {
              $mo->{$symoid} = 'unknown_'.$result->{$oid};
              # oder $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$symoid.'Definition'}?
            }
          }
        }
      }
    }
    push(@entries, $mo) if keys %{$mo};
  }
  if (wantarray) {
    return @entries;
  } else {
    foreach my $entry (@entries) {
      foreach my $key (keys %{$entry}) {
        $self->{$key} = $entry->{$key};
      }
    }
  }
}

sub sort_oids {
  my ($self, $oids) = @_;
  $oids ||= [];
  my @sortedkeys = map { $_->[0] }
      sort { $a->[1] cmp $b->[1] }
          map { [$_,
                  join '', map { sprintf("%30d",$_) } split( /\./, $_)
                ] } @{$oids};
  return @sortedkeys;
}

sub sort_indices {
  my ($self, $indices) = @_;
  my @sortedindices = map { $_->[0] } 
      sort { $a->[1] cmp $b->[1] } 
          map { [$_, 
              join '', map { sprintf("%30d",$_) } split( /\./, $_) 
          ] } map { join('.', @{$_})} @{$indices}; 
  return @sortedindices;
}


sub get_matching_oids {
  my ($self, %params) = @_;
  my $result = {};
  $self->debug(sprintf "get_matching_oids %s", Data::Dumper::Dumper(\%params));
  foreach my $oid (@{$params{'-columns'}}) {
    my $oidpattern = $oid;
    $oidpattern =~ s/\./\\./g;
    map { $result->{$_} = $Monitoring::GLPlugin::SNMP::rawdata->{$_} }
        grep /^$oidpattern(?=\.|$)/, keys %{$Monitoring::GLPlugin::SNMP::rawdata};
  }
  $self->debug(sprintf "get_matching_oids returns %d from %d oids", 
      scalar(keys %{$result}), scalar(keys %{$Monitoring::GLPlugin::SNMP::rawdata}));
  return $result;
}

sub get_indices {
  my ($self, %params) = @_;
  # -baseoid : entry
  # find all oids beginning with $entry
  # then skip one field for the sequence
  # then read the next numindices fields
  my $entrypat = $params{'-baseoid'};
  $entrypat =~ s/\./\\\./g;
  my @indices = map {
      /^$entrypat\.\d+\.(.*)/ && $1;
  } grep {
      /^$entrypat/
  } keys %{$Monitoring::GLPlugin::SNMP::rawdata};
  my %seen = ();
  my @o = map {[split /\./]} sort grep !$seen{$_}++, @indices;
  return @o;
}

# this flattens a n-dimensional array and returns the absolute position
# of the element at position idx1,idx2,...,idxn
# element 1,2 in table 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 is at pos 6
sub get_number {
  my ($self, $indexlists, @element) = @_;
  # $indexlists = zeiger auf array aus [1, 2]
  my $dimensions = scalar(@{$indexlists->[0]});
  my @sorted = ();
  my $number = 0;
  if ($dimensions == 1) {
    @sorted =
        sort { $a->[0] <=> $b->[0] } @{$indexlists};
  } elsif ($dimensions == 2) {
    @sorted =
        sort { $a->[0] <=> $b->[0] || $a->[1] <=> $b->[1] } @{$indexlists};
  } elsif ($dimensions == 3) {
    @sorted =
        sort { $a->[0] <=> $b->[0] ||
               $a->[1] <=> $b->[1] ||
               $a->[2] <=> $b->[2] } @{$indexlists};
  }
  foreach (@sorted) {
    if ($dimensions == 1) {
      if ($_->[0] == $element[0]) {
        last;
      }
    } elsif ($dimensions == 2) {
      if ($_->[0] == $element[0] && $_->[1] == $element[1]) {
        last;
      }
    } elsif ($dimensions == 3) {
      if ($_->[0] == $element[0] &&
          $_->[1] == $element[1] &&
          $_->[2] == $element[2]) {
        last;
      }
    }
    $number++;
  }
  return ++$number;
}

################################################################
# caching functions
# 
sub set_rawdata {
  my ($self, $rawdata) = @_;
  $Monitoring::GLPlugin::SNMP::rawdata = $rawdata;
}

sub add_rawdata {
  my ($self, $oid, $value) = @_;
  $Monitoring::GLPlugin::SNMP::rawdata->{$oid} = $value;
}

sub rawdata {
  my ($self) = @_;
  return $Monitoring::GLPlugin::SNMP::rawdata;
}

sub add_oidtrace {
  my ($self, $oid) = @_;
  $self->debug("cache: ".$oid);
  push(@{$Monitoring::GLPlugin::SNMP::oidtrace}, $oid);
}

#  $self->update_entry_cache(0, $mib, $table, $key_attr);
#  my @indices = $self->get_cache_indices();
sub get_cache_indices {
  my ($self, $mib, $table, $key_attr) = @_;
  # get_cache_indices is only used by get_snmp_table_objects_with_cache
  # so if we dont use --name returning all the indices would result
  # in a step-by-step get_table_objecs(index 1...n) which could take long
  # time when used with nexus or f5 pools
  # returning () forces get_snmp_table_objects to use get_tables
  return () if ! $self->opts->name;
  if (ref($key_attr) ne "ARRAY") {
    $key_attr = [$key_attr];
  }
  my $cache = sprintf "%s_%s_%s_cache", 
      $mib, $table, join('#', @{$key_attr});
  my @indices = ();
  foreach my $key (keys %{$self->{$cache}}) {
    my ($descr, $index) = split('-//-', $key, 2);
    if ($self->opts->name) {
      if ($self->opts->regexp) {
        my $pattern = $self->opts->name;
        if ($descr =~ /$pattern/i) {
          push(@indices, $self->{$cache}->{$key});
        }
      } else {
        if ($self->opts->name =~ /^\d+$/) {
          if ($index == 1 * $self->opts->name) {
            push(@indices, [1 * $self->opts->name]);
          }
        } else {
          if (lc $descr eq lc $self->opts->name) {
            push(@indices, $self->{$cache}->{$key});
          }
        }
      }
    } else {
      push(@indices, $self->{$cache}->{$key});
    }
  }
  return @indices;
  return map { join('.', ref($_) eq "ARRAY" ? @{$_} : $_) } @indices;
}

sub get_entities {
  my ($self, $class, $filter) = @_;
  foreach ($self->get_sub_table('ENTITY-MIB', [
    'entPhysicalDescr',
    'entPhysicalName',
    'entPhysicalClass',
  ])) {
    my $new_object = $class->new(%{$_});
    next if (defined $filter && ! &$filter($new_object));
    push @{$self->{entities}}, $new_object;
  }
}

sub get_sub_table {
  my ($self, $mib, $names) = @_;
  $self->require_mib($mib);
  my @oids = map {
    $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{$mib}->{$_}
  } @$names;
  my $result = $self->get_entries(
    -columns => \@oids
  );
  my $indices = ();
  map { if ($_ =~ /\.(\d+)$/) { $indices->{$1} = [ $1 ]; } } keys %$result;
  my @indices = values %$indices;
  my @entries = $self->make_symbolic($mib, $result, \@indices);
  @entries = map { $_->{indices} = shift @indices; $_ } @entries;
  @entries = map { $_->{flat_indices} = join(".", @{$_->{indices}}); $_ } @entries;
  return @entries;
}

sub join_table {
  my ($self, $to, $from) = @_;
  my $to_i = {};
  foreach (@$to) {
    my $i = $_->{flat_indices};
    $to_i->{$i} = $_;
  }
  foreach my $f (@$from) {
    my $i = $f->{flat_indices};
    if (exists $to_i->{$i}) {
      foreach (keys %$f) {
        next if $_ =~ /indices/;
        $to_i->{$i}->{$_} = $f->{$_};
      }
    }
  }
}




package Monitoring::GLPlugin::SNMP::MibsAndOids;
our @ISA = qw(Monitoring::GLPlugin::SNMP);

{
  no warnings qw(once);
  $Monitoring::GLPlugin::SNMP::MibsAndOids::discover_ids = {};
  $Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids = {};
  $Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids = {};
  $Monitoring::GLPlugin::SNMP::MibsAndOids::definitions = {};
  $Monitoring::GLPlugin::SNMP::MibsAndOids::origin = {};
}



package Monitoring::GLPlugin::SNMP::MibsAndOids::MIB2MIB;

$Monitoring::GLPlugin::SNMP::MibsAndOids::origin->{'MIB-2-MIB'} = {
  url => "",
  name => "MIB-2-MIB",
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{'MIB-2-MIB'} = {
  sysDescr => '1.3.6.1.2.1.1.1',
  sysObjectID => '1.3.6.1.2.1.1.2',
  sysUpTime => '1.3.6.1.2.1.1.3',
  sysName => '1.3.6.1.2.1.1.5',
  sysORTable => '1.3.6.1.2.1.1.9',
  sysOREntry => '1.3.6.1.2.1.1.9.1',
  sysORIndex => '1.3.6.1.2.1.1.9.1.1',
  sysORID => '1.3.6.1.2.1.1.9.1.2',
  sysORDescr => '1.3.6.1.2.1.1.9.1.3',
  sysORUpTime => '1.3.6.1.2.1.1.9.1.4',
};



package Monitoring::GLPlugin::SNMP::MibsAndOids::MMBCOMMIB;

$Monitoring::GLPlugin::SNMP::MibsAndOids::origin->{'MMB-COM-MIB'} = {
  url => 'http://jp.fujitsu.com/platform/server/primequest/download/2000/mib/PQ2000_MIBs-20150407.zip',
  name => 'MMB-COM-MIB',
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{'MMB-COM-MIB'} =
    '1.3.6.1.4.1.211.1.31.1.1';

$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{'MMB-COM-MIB'} = {
  fujitsu => '1.3.6.1.4.1.211',
  products => '1.3.6.1.4.1.211.1',
  iaServer => '1.3.6.1.4.1.211.1.31',
  primequest => '1.3.6.1.4.1.211.1.31.1',
  mmb => '1.3.6.1.4.1.211.1.31.1.1',
  sysInfo => '1.3.6.1.4.1.211.1.31.1.1.1',
  agentInfo => '1.3.6.1.4.1.211.1.31.1.1.1.1',
  agentId => '1.3.6.1.4.1.211.1.31.1.1.1.1.1',
  agentCompany => '1.3.6.1.4.1.211.1.31.1.1.1.1.2',
  agentVersion => '1.3.6.1.4.1.211.1.31.1.1.1.1.3',
  agentBuild => '1.3.6.1.4.1.211.1.31.1.1.1.1.4',
  agentWriteAllowed => '1.3.6.1.4.1.211.1.31.1.1.1.1.5',
  agentWriteAllowedDefinition => 'MMB-COM-MIB::agentWriteAllowed',
  agentShutdownAllowed => '1.3.6.1.4.1.211.1.31.1.1.1.1.6',
  agentShutdownAllowedDefinition => 'MMB-COM-MIB::agentShutdownAllowed',
  unitInformation => '1.3.6.1.4.1.211.1.31.1.1.1.2',
  localServerUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.2.1',
  psPowerSupplyLoad => '1.3.6.1.4.1.211.1.31.1.1.1.2.1.6',
  numberUnits => '1.3.6.1.4.1.211.1.31.1.1.1.2.2',
  unitTable => '1.3.6.1.4.1.211.1.31.1.1.1.2.3',
  unitEntry => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1',
  units => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1',
  uUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.1',
  unitClass => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.2',
  unitClassDefinition => 'MMB-COM-MIB::unitClass',
  unitCainetNr => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.3',
  unitDesignation => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.4',
  unitModelName => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.5',
  unitManufacturer => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.6',
  unitSerialNumber => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.7',
  unitLocation => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.8',
  unitContact => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.9',
  unitAdminURL => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.10',
  frontDoorStatus => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.11',
  frontDoorStatusDefinition => 'MMB-COM-MIB::frontDoorStatus',
  housingOpenStatus => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.12',
  housingOpenStatusDefinition => 'MMB-COM-MIB::housingOpenStatus',
  msgLogLanguages => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.13',
  unitWorldWideName => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.14',
  remcsId => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.15',
  assetTag => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.16',
  unitManagementIpAddress => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.18',
  unitManagementIpAddressV6 => '1.3.6.1.4.1.211.1.31.1.1.1.2.3.1.20',
  unitTableUpdateCount => '1.3.6.1.4.1.211.1.31.1.1.1.2.4',
  unitParentTable => '1.3.6.1.4.1.211.1.31.1.1.1.2.5',
  unitParentEntry => '1.3.6.1.4.1.211.1.31.1.1.1.2.5.1',
  unitParents => '1.3.6.1.4.1.211.1.31.1.1.1.2.5.1',
  pUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.2.5.1.1',
  pParentNr => '1.3.6.1.4.1.211.1.31.1.1.1.2.5.1.2',
  parentUnit => '1.3.6.1.4.1.211.1.31.1.1.1.2.5.1.3',
  parentUnitClass => '1.3.6.1.4.1.211.1.31.1.1.1.2.5.1.4',
  parentUnitClassDefinition => 'MMB-COM-MIB::parentUnitClass',
  unitChildTable => '1.3.6.1.4.1.211.1.31.1.1.1.2.6',
  unitChildEntry => '1.3.6.1.4.1.211.1.31.1.1.1.2.6.1',
  unitChilds => '1.3.6.1.4.1.211.1.31.1.1.1.2.6.1',
  cUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.2.6.1.1',
  cChildNr => '1.3.6.1.4.1.211.1.31.1.1.1.2.6.1.2',
  childUnit => '1.3.6.1.4.1.211.1.31.1.1.1.2.6.1.3',
  childUnitClass => '1.3.6.1.4.1.211.1.31.1.1.1.2.6.1.4',
  childUnitClassDefinition => 'MMB-COM-MIB::childUnitClass',
  parentChildTableUpdateCount => '1.3.6.1.4.1.211.1.31.1.1.1.2.7',
  management => '1.3.6.1.4.1.211.1.31.1.1.1.3',
  managementNodeTable => '1.3.6.1.4.1.211.1.31.1.1.1.3.1',
  managementNodeEntry => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1',
  managementNodes => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1',
  mnUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.1',
  mnNodeNr => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.2',
  unitNodeIfType => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.3',
  unitNodeIfTypeDefinition => 'MMB-COM-MIB::unitNodeIfType',
  unitNodeAddress => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.4',
  unitNodeIpNetmask => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.5',
  unitNodeGateway => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.6',
  unitNodeName => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.7',
  unitNodeClass => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.8',
  unitNodeClassDefinition => 'MMB-COM-MIB::unitNodeClass',
  unitNodeMacAddress => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.9',
  unitNodeUseDHCP => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.10',
  unitNodeUseDHCPDefinition => 'MMB-COM-MIB::unitNodeUseDHCP',
  unitNodeControllerType => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.11',
  unitNodeControllerModel => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.12',
  unitNodeControllerFWVersion => '1.3.6.1.4.1.211.1.31.1.1.1.3.1.1.13',
  nodeTableUpdateCount => '1.3.6.1.4.1.211.1.31.1.1.1.3.2',
  managementChannelType => '1.3.6.1.4.1.211.1.31.1.1.1.3.3',
  managementChannelTypeDefinition => 'MMB-COM-MIB::managementChannelType',
  managementProcessorTable => '1.3.6.1.4.1.211.1.31.1.1.1.3.4',
  managementProcessorEntry => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1',
  managementProcessors => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1',
  spUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1.1',
  spProcessorNr => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1.2',
  spModelName => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1.3',
  spFirmwareVersion => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1.4',
  spBatteryStatus => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1.5',
  spBatteryStatusDefinition => 'MMB-COM-MIB::spBatteryStatus',
  spBatteryDischargeTime => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1.6',
  spTimeOnBattery => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1.7',
  spDoBatteryChargeCycle => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1.8',
  spBatteryChargeLevel => '1.3.6.1.4.1.211.1.31.1.1.1.3.4.1.9',
  managedUpsNodeTable => '1.3.6.1.4.1.211.1.31.1.1.1.3.5',
  managedUpsNodeEntry => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1',
  managedUpsNodes => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1',
  upsUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1.1',
  upsNr => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1.2',
  upsVendorName => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1.3',
  upsModelName => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1.4',
  upsIpAddress => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1.5',
  upsMibRoot => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1.6',
  upsSnmpCommunity => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1.7',
  upsHttpPort => '1.3.6.1.4.1.211.1.31.1.1.1.3.5.1.8',
  managementTimeZone => '1.3.6.1.4.1.211.1.31.1.1.1.3.6',
  serverInformation => '1.3.6.1.4.1.211.1.31.1.1.1.4',
  serverTable => '1.3.6.1.4.1.211.1.31.1.1.1.4.1',
  serverEntry => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1',
  servers => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1',
  srvUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.1',
  srvPhysicalMemory => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.2',
  srvLastBootResult => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.3',
  srvLastBootResultDefinition => 'MMB-COM-MIB::srvLastBootResult',
  srvCurrentBootStatus => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.4',
  srvCurrentBootStatusDefinition => 'MMB-COM-MIB::srvCurrentBootStatus',
  srvShutdownCommand => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.5',
  srvShutdownCommandDefinition => 'MMB-COM-MIB::srvShutdownCommand',
  srvShutdownDelay => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.6',
  srvUUID => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.7',
  srvPhysicalMemoryOs => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.8',
  srvTpmMode => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.9',
  srvTpmModeDefinition => 'MMB-COM-MIB::srvTpmMode',
  srvManagementIP => '1.3.6.1.4.1.211.1.31.1.1.1.4.1.1.10',
  unitPowerOnOffTable => '1.3.6.1.4.1.211.1.31.1.1.1.4.2',
  unitPowerOnOffEntry => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1',
  unitPowerOnOff => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1',
  ooUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.1',
  powerOnOffStatus => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.2',
  powerOnOffStatusDefinition => 'MMB-COM-MIB::powerOnOffStatus',
  lastPowerOffSource => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.3',
  lastPowerOffSourceDefinition => 'MMB-COM-MIB::lastPowerOffSource',
  lastPowerOnSource => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.4',
  lastPowerOnSourceDefinition => 'MMB-COM-MIB::lastPowerOnSource',
  lastPowerOnTime => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.5',
  powerOnCounts => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.6',
  powerOnDuration => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.7',
  powerOffDuration => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.8',
  powerFailRecovery => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.9',
  powerFailRecoveryDefinition => 'MMB-COM-MIB::powerFailRecovery',
  powerCommand => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.10',
  powerCommandDefinition => 'MMB-COM-MIB::powerCommand',
  powerSupplyRedundancy => '1.3.6.1.4.1.211.1.31.1.1.1.4.2.1.11',
  performanceTable => '1.3.6.1.4.1.211.1.31.1.1.1.4.3',
  performanceEntry => '1.3.6.1.4.1.211.1.31.1.1.1.4.3.1',
  performance => '1.3.6.1.4.1.211.1.31.1.1.1.4.3.1',
  perfUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.4.3.1.1',
  perfNr => '1.3.6.1.4.1.211.1.31.1.1.1.4.3.1.2',
  perfType => '1.3.6.1.4.1.211.1.31.1.1.1.4.3.1.3',
  perfTypeDefinition => 'MMB-COM-MIB::perfType',
  performanceValue => '1.3.6.1.4.1.211.1.31.1.1.1.4.3.1.4',
  performanceName => '1.3.6.1.4.1.211.1.31.1.1.1.4.3.1.5',
  timerOnOffTable => '1.3.6.1.4.1.211.1.31.1.1.1.4.4',
  timerOnOffEntry => '1.3.6.1.4.1.211.1.31.1.1.1.4.4.1',
  timerOnOff => '1.3.6.1.4.1.211.1.31.1.1.1.4.4.1',
  tooUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.4.4.1.1',
  tooDayOfWeek => '1.3.6.1.4.1.211.1.31.1.1.1.4.4.1.2',
  onTime => '1.3.6.1.4.1.211.1.31.1.1.1.4.4.1.3',
  offTime => '1.3.6.1.4.1.211.1.31.1.1.1.4.4.1.4',
  powerMonitoringTable => '1.3.6.1.4.1.211.1.31.1.1.1.4.5',
  powerMonitoringEntry => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1',
  powerMonitoring => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1',
  pmUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1.1',
  pmCurrentPowerMonitoringAvailable => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1.2',
  pmCurrentPowerMonitoringAvailableDefinition => 'MMB-COM-MIB::TrueFalse',
  pmCurrentPowerMonitoringEnabled => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1.3',
  pmCurrentPowerMonitoringEnabledDefinition => 'MMB-COM-MIB::TrueFalse',
  pmNominalPowerConsumption => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1.4',
  pmCurrentPowerConsumption => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1.5',
  pmCurrentPowerControl => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1.6',
  pmCurrentPowerControlDefinition => 'MMB-COM-MIB::pmCurrentPowerControl',
  pmPowerLimitThreshold => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1.8',
  pmPowerControlMode => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1.11',
  pmPowerControlModeDefinition => 'MMB-COM-MIB::pmPowerControlMode',
  pmPowerDisplayUnit => '1.3.6.1.4.1.211.1.31.1.1.1.4.5.1.12',
  pmPowerDisplayUnitDefinition => 'MMB-COM-MIB::pmPowerDisplayUnit',
  utilizationHistoryTable => '1.3.6.1.4.1.211.1.31.1.1.1.4.6',
  utilizationHistoryEntry => '1.3.6.1.4.1.211.1.31.1.1.1.4.6.1',
  utilizationHistory => '1.3.6.1.4.1.211.1.31.1.1.1.4.6.1',
  uthUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.4.6.1.1',
  uthEntity => '1.3.6.1.4.1.211.1.31.1.1.1.4.6.1.2',
  uthEntityDefinition => 'MMB-COM-MIB::uthEntity',
  uthTimeStamp => '1.3.6.1.4.1.211.1.31.1.1.1.4.6.1.3',
  uthHardwareUUID => '1.3.6.1.4.1.211.1.31.1.1.1.4.6.1.4',
  uthAverageValue => '1.3.6.1.4.1.211.1.31.1.1.1.4.6.1.5',
  uthMinValue => '1.3.6.1.4.1.211.1.31.1.1.1.4.6.1.6',
  uthMaxValue => '1.3.6.1.4.1.211.1.31.1.1.1.4.6.1.7',
  powerSourceInformationTable => '1.3.6.1.4.1.211.1.31.1.1.1.4.7',
  powerSourceInformationEntry => '1.3.6.1.4.1.211.1.31.1.1.1.4.7.1',
  powerSourceInformation => '1.3.6.1.4.1.211.1.31.1.1.1.4.7.1',
  psiUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.4.7.1.1',
  psiPowerSourceType => '1.3.6.1.4.1.211.1.31.1.1.1.4.7.1.2',
  psiPowerSourcePhase => '1.3.6.1.4.1.211.1.31.1.1.1.4.7.1.3',
  psiPowerSourcePhaseDefinition => 'MMB-COM-MIB::psiPowerSourcePhase',
  psiPowerSourceVoltage => '1.3.6.1.4.1.211.1.31.1.1.1.4.7.1.4',
  environment => '1.3.6.1.4.1.211.1.31.1.1.1.5',
  temperatureSensorTable => '1.3.6.1.4.1.211.1.31.1.1.1.5.1',
  temperatureSensorEntry => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1',
  temperatureSensors => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1',
  tempUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1.1',
  tempSensorNr => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1.2',
  tempSensorDesignation => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1.3',
  tempSensorIdentifier => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1.4',
  tempSensorStatus => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1.5',
  tempSensorStatusDefinition => 'MMB-COM-MIB::tempSensorStatus',
  tempCurrentTemperature => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1.6',
  tempWarningLevel => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1.7',
  tempCriticalLevel => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1.8',
  tempCriticalReaction => '1.3.6.1.4.1.211.1.31.1.1.1.5.1.1.9',
  tempCriticalReactionDefinition => 'MMB-COM-MIB::tempCriticalReaction',
  fanTable => '1.3.6.1.4.1.211.1.31.1.1.1.5.2',
  fanEntry => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1',
  fans => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1',
  fanUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1.1',
  fanNr => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1.2',
  fanDesignation => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1.3',
  fanIdentifier => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1.4',
  fanStatus => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1.5',
  fanStatusDefinition => 'MMB-COM-MIB::fanStatus',
  fanCurrentSpeed => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1.6',
  fanQuality => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1.7',
  fanFailReaction => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1.8',
  fanFailReactionDefinition => 'MMB-COM-MIB::fanFailReaction',
  fanFailShutdownDelay => '1.3.6.1.4.1.211.1.31.1.1.1.5.2.1.9',
  airflowTable => '1.3.6.1.4.1.211.1.31.1.1.1.5.3',
  airflowEntry => '1.3.6.1.4.1.211.1.31.1.1.1.5.3.1',
  airflow => '1.3.6.1.4.1.211.1.31.1.1.1.5.3.1',
  afUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.5.3.1.1',
  afExhaustAirflowVolume => '1.3.6.1.4.1.211.1.31.1.1.1.5.3.1.2',
  afExhaustAirflowVolumeUnit => '1.3.6.1.4.1.211.1.31.1.1.1.5.3.1.3',
  hardware => '1.3.6.1.4.1.211.1.31.1.1.1.6',
  systemBoardTable => '1.3.6.1.4.1.211.1.31.1.1.1.6.1',
  systemBoardEntry => '1.3.6.1.4.1.211.1.31.1.1.1.6.1.1',
  systemBoard => '1.3.6.1.4.1.211.1.31.1.1.1.6.1.1',
  sbUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.6.1.1.1',
  systemBoardModelName => '1.3.6.1.4.1.211.1.31.1.1.1.6.1.1.2',
  systemBoardProductNumber => '1.3.6.1.4.1.211.1.31.1.1.1.6.1.1.3',
  systemBoardRevision => '1.3.6.1.4.1.211.1.31.1.1.1.6.1.1.4',
  systemBoardSerialNumber => '1.3.6.1.4.1.211.1.31.1.1.1.6.1.1.5',
  powerSupplyTable => '1.3.6.1.4.1.211.1.31.1.1.1.6.2',
  powerSupplyEntry => '1.3.6.1.4.1.211.1.31.1.1.1.6.2.1',
  powerSupply => '1.3.6.1.4.1.211.1.31.1.1.1.6.2.1',
  psUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.6.2.1.1',
  psPowerSupplyNr => '1.3.6.1.4.1.211.1.31.1.1.1.6.2.1.2',
  powerSupplyDesignation => '1.3.6.1.4.1.211.1.31.1.1.1.6.2.1.3',
  powerSupplyIdentifier => '1.3.6.1.4.1.211.1.31.1.1.1.6.2.1.4',
  powerSupplyStatus => '1.3.6.1.4.1.211.1.31.1.1.1.6.2.1.5',
  powerSupplyStatusDefinition => 'MMB-COM-MIB::powerSupplyStatus',
  voltageTable => '1.3.6.1.4.1.211.1.31.1.1.1.6.3',
  voltageEntry => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1',
  voltages => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1',
  voUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1.1',
  voSensorNr => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1.2',
  voltageDesignation => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1.3',
  voltageStatus => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1.4',
  voltageStatusDefinition => 'MMB-COM-MIB::voltageStatus',
  voltageCurrentValue => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1.5',
  voltageNominalValue => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1.6',
  voltageMinimumLevel => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1.7',
  voltageMaximumLevel => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1.8',
  voltageCurrentLoad => '1.3.6.1.4.1.211.1.31.1.1.1.6.3.1.9',
  cpuTable => '1.3.6.1.4.1.211.1.31.1.1.1.6.4',
  cpuEntry => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1',
  cpus => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1',
  cpuUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.1',
  cpuNr => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.2',
  cpuDesignation => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.3',
  cpuStatus => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.4',
  cpuStatusDefinition => 'MMB-COM-MIB::cpuStatus',
  cpuModelName => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.5',
  cpuManufacturer => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.6',
  cpuStep => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.7',
  cpuCurrentSpeed => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.8',
  cpuNumberLogicals => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.9',
  cpuCacheL1Size => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.10',
  cpuCacheL2Size => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.11',
  cpuCacheL3Size => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.12',
  cpuNumberCores => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.13',
  cpuFamily => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.14',
  cpuEnabledCores => '1.3.6.1.4.1.211.1.31.1.1.1.6.4.1.15',
  memoryModuleTable => '1.3.6.1.4.1.211.1.31.1.1.1.6.5',
  memoryModuleEntry => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1',
  memoryModules => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1',
  memUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.1',
  memModuleNr => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.2',
  memModuleDesignation => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.3',
  memModuleStatus => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.4',
  memModuleStatusDefinition => 'MMB-COM-MIB::memModuleStatus',
  memModuleBank => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.5',
  memModuleCapacity => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.6',
  memModuleStartAddress => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.7',
  memModuleForm => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.8',
  memModuleType => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.9',
  memModuleCorrErrors => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.10',
  memModuleUncorrErrors => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.11',
  memModuleApproved => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.12',
  memModuleApprovedDefinition => 'MMB-COM-MIB::memModuleApproved',
  memModuleConfiguration => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.13',
  memModuleConfigurationDefinition => 'MMB-COM-MIB::memModuleConfiguration',
  memModuleFrequency => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.14',
  memModuleMaxFrequency => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.15',
  memModuleVoltInterface => '1.3.6.1.4.1.211.1.31.1.1.1.6.5.1.16',
  cpuMultithreadEnable => '1.3.6.1.4.1.211.1.31.1.1.1.6.6',
  cpuMultithreadEnableDefinition => 'MMB-COM-MIB::cpuMultithreadEnable',
  componentPowerConsumptionTable => '1.3.6.1.4.1.211.1.31.1.1.1.6.7',
  componentPowerConsumptionEntry => '1.3.6.1.4.1.211.1.31.1.1.1.6.7.1',
  componentPowerConsumption => '1.3.6.1.4.1.211.1.31.1.1.1.6.7.1',
  cpcUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.6.7.1.1',
  cpcComponentClass => '1.3.6.1.4.1.211.1.31.1.1.1.6.7.1.2',
  cpcComponentClassDefinition => 'MMB-COM-MIB::cpcComponentClass',
  cpcComponentIndex => '1.3.6.1.4.1.211.1.31.1.1.1.6.7.1.3',
  cpcDesignation => '1.3.6.1.4.1.211.1.31.1.1.1.6.7.1.4',
  cpcCurrentValue => '1.3.6.1.4.1.211.1.31.1.1.1.6.7.1.5',
  trustedPlatformModuleTable => '1.3.6.1.4.1.211.1.31.1.1.1.6.8',
  trustedPlatformModuleEntry => '1.3.6.1.4.1.211.1.31.1.1.1.6.8.1',
  trustedPlatformModule => '1.3.6.1.4.1.211.1.31.1.1.1.6.8.1',
  tpmUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.6.8.1.1',
  tpmHardwareAvailable => '1.3.6.1.4.1.211.1.31.1.1.1.6.8.1.2',
  tpmHardwareAvailableDefinition => 'MMB-COM-MIB::TrueFalseUnknown',
  tpmBiosEnabled => '1.3.6.1.4.1.211.1.31.1.1.1.6.8.1.3',
  tpmBiosEnabledDefinition => 'MMB-COM-MIB::TrueFalseUnknown',
  tpmEnabled => '1.3.6.1.4.1.211.1.31.1.1.1.6.8.1.4',
  tpmEnabledDefinition => 'MMB-COM-MIB::TrueFalseUnknown',
  tpmActivated => '1.3.6.1.4.1.211.1.31.1.1.1.6.8.1.5',
  tpmActivatedDefinition => 'MMB-COM-MIB::TrueFalseUnknown',
  tpmOwnership => '1.3.6.1.4.1.211.1.31.1.1.1.6.8.1.6',
  tpmOwnershipDefinition => 'MMB-COM-MIB::TrueFalseUnknown',
  recovery => '1.3.6.1.4.1.211.1.31.1.1.1.7',
  messageLogTable => '1.3.6.1.4.1.211.1.31.1.1.1.7.1',
  messageLogEntry => '1.3.6.1.4.1.211.1.31.1.1.1.7.1.1',
  messageLogs => '1.3.6.1.4.1.211.1.31.1.1.1.7.1.1',
  msgUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.7.1.1.1',
  msgLogEntryNr => '1.3.6.1.4.1.211.1.31.1.1.1.7.1.1.2',
  msgLogEntryData => '1.3.6.1.4.1.211.1.31.1.1.1.7.1.1.3',
  watchdogTable => '1.3.6.1.4.1.211.1.31.1.1.1.7.2',
  watchdogEntry => '1.3.6.1.4.1.211.1.31.1.1.1.7.2.1',
  watchdogs => '1.3.6.1.4.1.211.1.31.1.1.1.7.2.1',
  wdUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.7.2.1.1',
  watchdogType => '1.3.6.1.4.1.211.1.31.1.1.1.7.2.1.2',
  watchdogTypeDefinition => 'MMB-COM-MIB::watchdogType',
  watchdogStatus => '1.3.6.1.4.1.211.1.31.1.1.1.7.2.1.3',
  watchdogStatusDefinition => 'MMB-COM-MIB::watchdogStatus',
  watchdogEnable => '1.3.6.1.4.1.211.1.31.1.1.1.7.2.1.4',
  watchdogEnableDefinition => 'MMB-COM-MIB::watchdogEnable',
  watchdogTime => '1.3.6.1.4.1.211.1.31.1.1.1.7.2.1.5',
  watchdogAction => '1.3.6.1.4.1.211.1.31.1.1.1.7.2.1.6',
  watchdogActionDefinition => 'MMB-COM-MIB::watchdogAction',
  recoverySettingTable => '1.3.6.1.4.1.211.1.31.1.1.1.7.3',
  recoverySettingEntry => '1.3.6.1.4.1.211.1.31.1.1.1.7.3.1',
  recoverySettings => '1.3.6.1.4.1.211.1.31.1.1.1.7.3.1',
  asrUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.7.3.1.1',
  asrNrRebootRetries => '1.3.6.1.4.1.211.1.31.1.1.1.7.3.1.2',
  asrDefaultRebootRetries => '1.3.6.1.4.1.211.1.31.1.1.1.7.3.1.3',
  asrNextBootSource => '1.3.6.1.4.1.211.1.31.1.1.1.7.3.1.4',
  asrNextBootSourceDefinition => 'MMB-COM-MIB::asrNextBootSource',
  asrRebootFailAction => '1.3.6.1.4.1.211.1.31.1.1.1.7.3.1.5',
  asrRebootFailActionDefinition => 'MMB-COM-MIB::asrRebootFailAction',
  asrRestartDelay => '1.3.6.1.4.1.211.1.31.1.1.1.7.3.1.6',
  asrPostErrorHalt => '1.3.6.1.4.1.211.1.31.1.1.1.7.3.1.7',
  asrPostErrorHaltDefinition => 'MMB-COM-MIB::asrPostErrorHalt',
  messageTextLogTable => '1.3.6.1.4.1.211.1.31.1.1.1.7.4',
  messageTextLogEntry => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1',
  messageTextLogs => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1',
  msgTextLogUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1.1',
  msgTextLogLanguage => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1.2',
  msgTextLogSeqNr => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1.3',
  msgTextLogTimestamp => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1.4',
  msgTextLogMessage => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1.5',
  msgTextLogErrorCode => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1.6',
  msgTextLogSeverity => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1.7',
  msgTextLogSeverityDefinition => 'MMB-COM-MIB::msgTextLogSeverity',
  msgTextLogCSSComponent => '1.3.6.1.4.1.211.1.31.1.1.1.7.4.1.8',
  msgTextLogCSSComponentDefinition => 'MMB-COM-MIB::TrueFalse',
  messageLogActionHintTable => '1.3.6.1.4.1.211.1.31.1.1.1.7.5',
  messageLogActionHintEntry => '1.3.6.1.4.1.211.1.31.1.1.1.7.5.1',
  messageLogActionHints => '1.3.6.1.4.1.211.1.31.1.1.1.7.5.1',
  mlaLanguage => '1.3.6.1.4.1.211.1.31.1.1.1.7.5.1.1',
  mlaErrorCode => '1.3.6.1.4.1.211.1.31.1.1.1.7.5.1.2',
  mlaType => '1.3.6.1.4.1.211.1.31.1.1.1.7.5.1.3',
  mlaTypeDefinition => 'MMB-COM-MIB::mlaType',
  mlaIndex => '1.3.6.1.4.1.211.1.31.1.1.1.7.5.1.4',
  mlaMessage => '1.3.6.1.4.1.211.1.31.1.1.1.7.5.1.5',
  status => '1.3.6.1.4.1.211.1.31.1.1.1.8',
  agentStatus => '1.3.6.1.4.1.211.1.31.1.1.1.8.1',
  agentStatusDefinition => 'MMB-COM-MIB::agentStatus',
  statusComponentTable => '1.3.6.1.4.1.211.1.31.1.1.1.8.2',
  statusComponentEntry => '1.3.6.1.4.1.211.1.31.1.1.1.8.2.1',
  statusComponents => '1.3.6.1.4.1.211.1.31.1.1.1.8.2.1',
  csUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.8.2.1.1',
  csType => '1.3.6.1.4.1.211.1.31.1.1.1.8.2.1.2',
  csTypeDefinition => 'MMB-COM-MIB::csType',
  componentStatusValue => '1.3.6.1.4.1.211.1.31.1.1.1.8.2.1.3',
  componentStatusValueDefinition => 'MMB-COM-MIB::componentStatusValue',
  componentStatusSensorTable => '1.3.6.1.4.1.211.1.31.1.1.1.8.3',
  componentStatusSensorEntry => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1',
  componentStatusSensors => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1',
  cssUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1.1',
  cssSensorNumber => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1.2',
  cssSensorDesignation => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1.3',
  cssSensorDevice => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1.4',
  cssSensorDeviceInstance => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1.5',
  cssSensorPhysicalLed => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1.6',
  cssSensorPhysicalLedDefinition => 'MMB-COM-MIB::TrueFalse',
  cssSensorCssComponent => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1.7',
  cssSensorCssComponentDefinition => 'MMB-COM-MIB::TrueFalse',
  cssSensorStatus => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1.8',
  cssSensorStatusDefinition => 'MMB-COM-MIB::cssSensorStatus',
  cssComponentServicePartId => '1.3.6.1.4.1.211.1.31.1.1.1.8.3.1.9',
  cssTableSize => '1.3.6.1.4.1.211.1.31.1.1.1.8.4',
  maintenance => '1.3.6.1.4.1.211.1.31.1.1.1.9',
  maintenanceObjectTable => '1.3.6.1.4.1.211.1.31.1.1.1.9.1',
  maintenanceObjectEntry => '1.3.6.1.4.1.211.1.31.1.1.1.9.1.1',
  maintenanceObjects => '1.3.6.1.4.1.211.1.31.1.1.1.9.1.1',
  mtUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.9.1.1.1',
  errorCounterStartTime => '1.3.6.1.4.1.211.1.31.1.1.1.9.1.1.2',
  sendTestTrap => '1.3.6.1.4.1.211.1.31.1.1.1.9.1.1.3',
  addTrapDestination => '1.3.6.1.4.1.211.1.31.1.1.1.9.1.1.4',
  mtMaintenanceStatus => '1.3.6.1.4.1.211.1.31.1.1.1.9.1.1.5',
  mtMaintenanceStatusDefinition => 'MMB-COM-MIB::mtMaintenanceStatus',
  firmwareVersionTable => '1.3.6.1.4.1.211.1.31.1.1.1.9.2',
  firmwareVersionEntry => '1.3.6.1.4.1.211.1.31.1.1.1.9.2.1',
  firmwareVersions => '1.3.6.1.4.1.211.1.31.1.1.1.9.2.1',
  fwUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.9.2.1.1',
  fwType => '1.3.6.1.4.1.211.1.31.1.1.1.9.2.1.2',
  fwTypeDefinition => 'MMB-COM-MIB::fwType',
  fwModelName => '1.3.6.1.4.1.211.1.31.1.1.1.9.2.1.3',
  fwVersion => '1.3.6.1.4.1.211.1.31.1.1.1.9.2.1.4',
  fwLocation => '1.3.6.1.4.1.211.1.31.1.1.1.9.2.1.5',
  deployment => '1.3.6.1.4.1.211.1.31.1.1.1.10',
  deployInfoTable => '1.3.6.1.4.1.211.1.31.1.1.1.10.1',
  deployInfoEntry => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1',
  deployInfo => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1',
  dplInfoUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.1',
  deployInfoChassisId => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.2',
  deployInfoMacAddr1 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.3',
  deployInfoMacAddr2 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.4',
  deployInfoMacAddr3 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.5',
  deployInfoMacAddr4 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.6',
  deployInfoIpAddr1 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.7',
  deployInfoIpAddr2 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.8',
  deployInfoIpAddr3 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.9',
  deployInfoIpAddr4 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.10',
  deployInfoNetMask1 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.11',
  deployInfoNetMask2 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.12',
  deployInfoNetMask3 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.13',
  deployInfoNetMask4 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.14',
  deployInfoGateway1 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.15',
  deployInfoGateway2 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.16',
  deployInfoGateway3 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.17',
  deployInfoGateway4 => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.18',
  deployInfoHostname => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.19',
  deployInfoMasterImageReference => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.20',
  deployInfoStatusOfBlade => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.21',
  deployInfoStatusOfBladeDefinition => 'MMB-COM-MIB::deployInfoStatusOfBlade',
  deployInfoLanStatusOfSlot => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.22',
  deployInfoLanStatusOfSlotDefinition => 'MMB-COM-MIB::deployInfoLanStatusOfSlot',
  deployInfoAutomaticRecovery => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.23',
  deployInfoAutomaticRecoveryDefinition => 'MMB-COM-MIB::deployInfoAutomaticRecovery',
  deployInfoStatusOfCloning => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.24',
  deployInfoStatusOfCloningDefinition => 'MMB-COM-MIB::deployInfoStatusOfCloning',
  deployInfoBootMode => '1.3.6.1.4.1.211.1.31.1.1.1.10.1.1.25',
  deployInfoBootModeDefinition => 'MMB-COM-MIB::deployInfoBootMode',
  oemDeployInfoTable => '1.3.6.1.4.1.211.1.31.1.1.1.10.2',
  oemDeployInfoEntry => '1.3.6.1.4.1.211.1.31.1.1.1.10.2.1',
  oemDeployInfo => '1.3.6.1.4.1.211.1.31.1.1.1.10.2.1',
  odplInfoUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.10.2.1.1',
  odplParamId => '1.3.6.1.4.1.211.1.31.1.1.1.10.2.1.2',
  oemDeployInfoParamData => '1.3.6.1.4.1.211.1.31.1.1.1.10.2.1.3',
  deployLanInterfaceTable => '1.3.6.1.4.1.211.1.31.1.1.1.10.3',
  deployLanInterfaceEntry => '1.3.6.1.4.1.211.1.31.1.1.1.10.3.1',
  deployLanInterfaces => '1.3.6.1.4.1.211.1.31.1.1.1.10.3.1',
  dplLanUnitId => '1.3.6.1.4.1.211.1.31.1.1.1.10.3.1.1',
  dplLanInterfaceNr => '1.3.6.1.4.1.211.1.31.1.1.1.10.3.1.2',
  dplLanMacAddress => '1.3.6.1.4.1.211.1.31.1.1.1.10.3.1.3',
  partition => '1.3.6.1.4.1.211.1.31.1.2',
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{'MMB-COM-MIB'} = {
  tempSensorStatus => {
    '1' => 'unknown',
    '2' => 'not-available',
    '3' => 'ok',
    '5' => 'failed',
    '6' => 'temperature-warning',
    '7' => 'temperature-critical',
  },
  unitNodeIfType => {
    '1' => 'unknown',
    '2' => 'ip',
    '3' => 'ipx',
    '4' => 'ipv6-ip',
    '5' => 'virtual-ip',
    '6' => 'ipv6-virtual-ip',
  },
  watchdogEnable => {
    '1' => 'unknown',
    '2' => 'disable',
    '3' => 'enable',
  },
  asrRebootFailAction => {
    '1' => 'unknown',
    '2' => 'switch-off',
    '3' => 'boot-diag-system',
    '4' => 'no-diag-system',
  },
  fwType => {
    '1' => 'bios',
    '2' => 'management-controller',
    '3' => 'remote-management-controller',
    '4' => 'pal',
    '5' => 'sal',
    '6' => 'efi',
    '7' => 'baseboard-management-controller',
    '8' => 'gswb-offline0',
    '9' => 'gswb-offline1',
    '10' => 'gswb-online0',
    '11' => 'gswb-online1',
    '20' => 'total',
  },
  deployInfoStatusOfCloning => {
    '1' => 'unknown',
    '2' => 'not-cloned',
    '3' => 'cloning',
    '4' => 'cloned',
  },
  srvShutdownCommand => {
    '1' => 'unknown',
    '2' => 'power-off',
    '3' => 'power-on',
    '4' => 'power-cycle',
    '5' => 'shutdown-and-off',
    '6' => 'shutdown-and-reset',
    '7' => 'shutdown-and-power-cycle',
    '8' => 'raise-nmi',
    '9' => 'abort-pending-command',
    '10' => 'reset',
  },
  perfType => {
    '1' => 'cpu',
    '2' => 'cpu-pverall',
    '3' => 'pci-load',
    '4' => 'pci-efficiency',
    '5' => 'pci-transfer',
    '6' => 'memory-physical',
    '7' => 'memory-total',
    '8' => 'memory-percent',
  },
  tempCriticalReaction => {
    '1' => 'unknown',
    '2' => 'continue',
    '3' => 'shutdown-and-poweroff',
  },
  csType => {
    '1' => 'system-boot',
    '2' => 'power',
    '3' => 'temperatures',
    '4' => 'fans',
    '5' => 'power-supplies',
    '6' => 'voltages',
    '7' => 'cpus',
    '8' => 'memory-modules',
    '9' => 'total',
    '10' => 'fan-redundancy',
    '11' => 'power-supply-redundancy',
  },
  unitClass => {
    '1' => 'chassis',
    '2' => 'partition',
    '3' => 'free-pool',
    '4' => 'sb',
    '7' => 'iou',
    '8' => 'iou-divided',
    '9' => 'iou-nodivided',
    '10' => 'pci-box',
    '17' => 'fan-tray',
    '20' => 'op-panel',
    '21' => 'mmb',
    '28' => 'gspb',
    '29' => 'gspb-divided',
    '30' => 'gspb-nodivided',
    '31' => 'sas-unit',
    '32' => 'psu',
    '33' => 'dvdb',
    '34' => 'lpci-box',
    '35' => 'fan',
    '36' => 'du',
  },
  srvCurrentBootStatus => {
    '1' => 'unknown',
    '2' => 'off',
    '3' => 'no-boot-cpu',
    '4' => 'self-test',
    '5' => 'setup',
    '6' => 'os-boot',
    '7' => 'diagnostic-boot',
    '8' => 'os-running',
    '9' => 'diagnostic-running',
    '10' => 'os-shutdown',
    '11' => 'diagnostic-shutdown',
    '12' => 'reset',
    '13' => 'panic',
    '14' => 'check-stop',
    '15' => 'dumping',
    '16' => 'halt',
    '17' => 'extended-partitioning-firmware-running',
  },
  deployInfoLanStatusOfSlot => {
    '1' => 'unknown',
    '2' => 'false',
    '3' => 'true',
  },
  srvTpmMode => {
    '1' => 'disable',
    '2' => 'enable',
  },
  asrPostErrorHalt => {
    '1' => 'unknown',
    '2' => 'halt-on-any-error',
    '3' => 'no-halt-on-any-error',
    '4' => 'other',
  },
  unitNodeUseDHCP => {
    '1' => 'unknown',
    '2' => 'use-fixed-address',
    '3' => 'use-dhcp',
  },
  deployInfoAutomaticRecovery => {
    '1' => 'unknown',
    '2' => 'false',
    '3' => 'true',
  },
  agentWriteAllowed => {
    '1' => 'unknown',
    '2' => 'write-not-allowed',
    '3' => 'write-allowed',
  },
  parentUnitClass => {
    '1' => 'chassis',
    '2' => 'partition',
    '3' => 'free-pool',
    '4' => 'sb',
    '7' => 'iou',
    '8' => 'iou-divided',
    '9' => 'iou-nodivided',
    '10' => 'pci-box',
    '17' => 'fan-tray',
    '20' => 'op-panel',
    '21' => 'mmb',
    '28' => 'gspb',
    '29' => 'gspb-divided',
    '30' => 'gspb-nodivided',
    '31' => 'sas-unit',
    '32' => 'psu',
    '33' => 'dvdb',
    '34' => 'lpci-box',
    '35' => 'fan',
    '36' => 'du',
  },
  unitNodeClass => {
    '1' => 'unknown',
    '2' => 'primery',
    '3' => 'secondary',
    '4' => 'manegement-blade',
    '5' => 'secondary-remote',
    '6' => 'secondary-remote-backup',
    '7' => 'baseboard-controller',
    '8' => 'secondary-manegement-blade',
  },
  cpuStatus => {
    '1' => 'unknown',
    '2' => 'not-present',
    '3' => 'ok',
    '4' => 'disabled',
    '5' => 'error',
    '6' => 'failed',
    '7' => 'missing-termination',
    '8' => 'prefailed-warning',
  },
  watchdogStatus => {
    '1' => 'unknown',
    '2' => 'disable',
    '3' => 'enable',
    '4' => 'not-available',
  },
  pmCurrentPowerControl => {
    '1' => 'unknown',
    '2' => 'disabled',
    '3' => 'best-performance',
    '4' => 'minimum-power',
    '5' => 'automatic',
    '6' => 'scheduled',
    '7' => 'limited',
  },
  psiPowerSourcePhase => {
    '1' => 'unknown',
    '2' => 'single-phase',
    '3' => 'three-phase',
  },
  cpcComponentClass => {
    '3' => 'processor',
    '4' => 'disk',
    '8' => 'memory-unit',
    '9' => 'processor-module',
    '23' => 'chassis',
    '24' => 'sub-chassis',
    '26' => 'disk-bay',
    '29' => 'cooling-device',
    '30' => 'cooling-unit',
    '32' => 'memory-device',
  },
  TrueFalse => {
    '1' => 'false',
    '2' => 'true',
  },
  deployInfoStatusOfBlade => {
    '1' => 'unknown',
    '2' => 'power-down',
    '3' => 'standby',
    '4' => 'system-boot-failure',
    '5' => 'bios-setup',
    '6' => 'booting',
  },
  spBatteryStatus => {
    '1' => 'unknown',
    '2' => 'not-present',
    '3' => 'ok',
    '4' => 'on-battery',
    '5' => 'recharging',
    '6' => 'failed',
    '7' => 'discharging',
  },
  agentShutdownAllowed => {
    '1' => 'unknown',
    '2' => 'shutdown-not-allowed',
    '3' => 'shutdown-allowed',
  },
  uthEntity => {
    '1' => 'powerConsumptionDay',
    '2' => 'powerConsumptionMonth',
    '3' => 'powerConsumptionYear',
  },
  pmPowerDisplayUnit => {
    '1' => 'unknown',
    '2' => 'watt',
    '3' => 'btu',
  },
  memModuleStatus => {
    '1' => 'unknown',
    '2' => 'not-present',
    '3' => 'ok',
    '4' => 'failed-disabled',
    '5' => 'error',
    '7' => 'warning',
    '8' => 'hot-spare',
    '9' => 'configuration-error',
  },
  cssSensorStatus => {
    '1' => 'unknown',
    '2' => 'ok',
    '3' => 'identify',
    '4' => 'prefailure-warning',
    '5' => 'failure',
    '6' => 'not-present',
  },
  memModuleApproved => {
    '1' => 'unknown',
    '2' => 'no',
    '3' => 'yes',
  },
  msgTextLogSeverity => {
    '1' => 'informational',
    '2' => 'minor',
    '3' => 'major',
    '4' => 'critical',
  },
  agentStatus => {
    '1' => 'ok',
    '2' => 'degraded',
    '3' => 'error',
    '4' => 'failed',
    '5' => 'unknown',
  },
  managementChannelType => {
    '1' => 'unknown',
    '2' => 'primery',
    '3' => 'secondary',
  },
  housingOpenStatus => {
    '1' => 'unknown',
    '2' => 'open',
    '3' => 'close',
    '4' => 'opened-and-closed',
  },
  watchdogType => {
    '1' => 'other',
    '2' => 'hardware',
    '3' => 'software',
    '4' => 'bios',
    '5' => 'boot',
    '6' => 'management-controller',
    '7' => 'remote-management-controller',
    '8' => 'management-soft',
  },
  watchdogAction => {
    '1' => 'unknown',
    '2' => 'continue',
    '3' => 'reboot',
    '4' => 'nmi',
    '5' => 'power-cycle',
    '6' => 'power-down',
    '7' => 'hardware-reset',
  },
  srvLastBootResult => {
    '1' => 'unknown',
    '2' => 'os-boot-successful',
    '3' => 'diagnostic-boot-successful',
    '4' => 'no-boot-cpu',
    '5' => 'no-bootable-media',
    '6' => 'os-failed-load',
    '7' => 'diagnostic-boot-failed',
    '8' => 'hardware-failure',
  },
  TrueFalseUnknown => {
    '1' => 'false',
    '2' => 'true',
    '3' => 'unknown',
  },
  powerCommand => {
    '1' => 'unknown',
    '2' => 'off',
    '3' => 'on',
    '4' => 'power-cycle',
  },
  lastPowerOffSource => {
    '1' => 'unknown',
    '2' => 'swoff-command',
    '3' => 'power-button',
    '4' => 'ac-fail',
    '5' => 'clock',
    '6' => 'fan-fail',
    '7' => 'temperature-critical',
    '8' => 'temperature-damage',
    '9' => 'power-supply-failure',
    '10' => 'watchdog',
    '11' => 'remote-off',
    '12' => 'hardware-fail',
    '13' => 'peripheral-bus-error',
    '14' => 'cpu-error',
    '20' => 'nmi',
    '23' => 'hardware-reset',
    '24' => 'warmstart',
    '25' => 'reset-button',
    '26' => 'ac-fail-reboot',
    '29' => 'keyboard',
    '31' => 'remote-manager',
    '32' => 'remote-manager-reset',
    '35' => 'power-limiting',
    '36' => 'mmb-continuous-operation',
    '37' => 'watchdog-power-cycle',
    '242' => 'firmware-restart',
    '243' => 'housing-opened',
  },
  powerOnOffStatus => {
    '1' => 'unknown',
    '2' => 'off',
    '3' => 'on',
  },
  powerFailRecovery => {
    '1' => 'unknown',
    '2' => 'not-available',
    '3' => 'as-before',
    '4' => 'remain-off',
    '5' => 'switch-on',
    '6' => 'schedule-sync',
  },
  deployInfoBootMode => {
    '1' => 'unknown',
    '2' => 'normal',
    '3' => 'pxeBiosSetup',
    '4' => 'pxeLan0',
    '5' => 'pxeLan1',
    '6' => 'pxeLan2',
    '7' => 'pxeLan3',
  },
  mtMaintenanceStatus => {
    '1' => 'off',
    '2' => 'on',
  },
  powerSupplyStatus => {
    '1' => 'unknown',
    '2' => 'not-present',
    '3' => 'ok',
    '4' => 'failed',
    '5' => 'ac-fail',
    '6' => 'dc-fail',
    '7' => 'critical-temperature',
    '8' => 'not-manageable',
    '9' => 'predictive-fail',
  },
  mlaType => {
    '1' => 'summary',
    '2' => 'cause',
    '3' => 'resolution',
  },
  fanStatus => {
    '1' => 'unknown',
    '2' => 'disabled',
    '3' => 'ok',
    '4' => 'failed',
    '5' => 'prefailed-predicted',
    '6' => 'redundant-fan-failed',
    '7' => 'not-manageable',
    '8' => 'not-present',
  },
  fanFailReaction => {
    '1' => 'unknown',
    '2' => 'continue',
    '3' => 'shutdown-and-poweroff',
  },
  childUnitClass => {
    '1' => 'chassis',
    '2' => 'partition',
    '3' => 'free-pool',
    '4' => 'sb',
    '7' => 'iou',
    '8' => 'iou-divided',
    '9' => 'iou-nodivided',
    '10' => 'pci-box',
    '17' => 'fan-tray',
    '20' => 'op-panel',
    '21' => 'mmb',
    '28' => 'gspb',
    '29' => 'gspb-divided',
    '30' => 'gspb-nodivided',
    '31' => 'sas-unit',
    '32' => 'psu',
    '33' => 'dvdb',
    '34' => 'lpci-box',
    '35' => 'fan',
    '36' => 'du',
  },
  memModuleConfiguration => {
    '1' => 'unknown',
    '2' => 'normal',
    '3' => 'disabled',
    '4' => 'hotSpare',
    '5' => 'mirror',
    '6' => 'raid',
    '7' => 'notUsable',
  },
  cpuMultithreadEnable => {
    '1' => 'unknown',
    '2' => 'disabled',
    '3' => 'enabled',
  },
  voltageStatus => {
    '1' => 'unknown',
    '2' => 'not-available',
    '3' => 'ok',
    '4' => 'too-low',
    '5' => 'too-high',
    '6' => 'sensor-failed',
    '7' => 'low-warning',
    '8' => 'high-warning',
  },
  frontDoorStatus => {
    '1' => 'unknown',
    '2' => 'open',
    '3' => 'close',
  },
  pmPowerControlMode => {
    '1' => 'unknown',
    '2' => 'disabled',
    '3' => 'best-performance',
    '4' => 'minimum-power',
    '5' => 'automatic',
    '6' => 'scheduled',
    '7' => 'limited',
    '8' => 'low-noise',
  },
  componentStatusValue => {
    '1' => 'ok',
    '2' => 'degraded',
    '3' => 'error',
    '4' => 'failed',
    '5' => 'unknown',
  },
  asrNextBootSource => {
    '1' => 'unknown',
    '2' => 'operating-system',
    '3' => 'reserved',
    '4' => 'diag-system',
    '5' => 'remote-disk',
  },
  lastPowerOnSource => {
    '1' => 'unknown',
    '2' => 'swoff-command',
    '3' => 'power-button',
    '4' => 'ac-fail',
    '5' => 'clock',
    '6' => 'fan-fail',
    '7' => 'temperature-critical',
    '8' => 'temperature-damage',
    '9' => 'power-supply-failure',
    '10' => 'watchdog',
    '11' => 'remote-on',
    '12' => 'hardware-fail',
    '13' => 'peripheral-bus-error',
    '14' => 'cpu-error',
    '20' => 'nmi',
    '23' => 'hardware-reset',
    '24' => 'warmstart',
    '25' => 'reset-button',
    '26' => 'ac-fail-reboot',
    '27' => 'mgmt-processor-fail',
    '28' => 'pci-pme',
    '29' => 'keyboard',
    '30' => 'chipcard-reader',
    '31' => 'remote-manager',
    '32' => 'remote-manager-reset',
    '33' => 'power-cycle',
    '242' => 'firmware-restart',
    '243' => 'housing-opened',
  },
};
package Monitoring::GLPlugin::SNMP::MibsAndOids::SNMPFRAMEWORKMIB;

$Monitoring::GLPlugin::SNMP::MibsAndOids::origin->{'SNMP-FRAMEWORK-MIB'} = {
  url => "",
  name => "MIB-II",
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{'SNMP-FRAMEWORK-MIB'} = {
  snmpEngineID => '1.3.6.1.6.3.10.2.1.1.0',
  snmpEngineBoots => '1.3.6.1.6.3.10.2.1.2.0',
  snmpEngineTime => '1.3.6.1.6.3.10.2.1.3.0',
  snmpEngineMaxMessageSize => '1.3.6.1.6.3.10.2.1.4.0',
};



package Monitoring::GLPlugin::SNMP::MibsAndOids::FSCRAIDMIB;

$Monitoring::GLPlugin::SNMP::MibsAndOids::origin->{'FSC-RAID-MIB'} = {
  url => '',
  name => 'FSC-RAID-MIB',
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{'FSC-RAID-MIB'} = 
  '1.3.6.1.4.1.231.2.49';

$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{'FSC-RAID-MIB'} = {
  'fscRAIDMIB' => '1.3.6.1.4.1.231.2.49',
  'svrObjects' => '1.3.6.1.4.1.231.2.49.1',
  'svrAgentInfo' => '1.3.6.1.4.1.231.2.49.1.1',
  'svrAgentId' => '1.3.6.1.4.1.231.2.49.1.1.1',
  'svrAgentCompany' => '1.3.6.1.4.1.231.2.49.1.1.2',
  'svrAgentVersion' => '1.3.6.1.4.1.231.2.49.1.1.3',
  'svrAgentBuild' => '1.3.6.1.4.1.231.2.49.1.1.4',
  'svrAgentOptions' => '1.3.6.1.4.1.231.2.49.1.2',
  'svrStatus' => '1.3.6.1.4.1.231.2.49.1.3',
  'svrStatusLogicalDrives' => '1.3.6.1.4.1.231.2.49.1.3.1',
  'svrStatusLogicalDrivesDefinition' => {
    '1' => 'ok',
    '2' => 'prefailure',
    '3' => 'failure',
  },
  'svrStatusPhysicalDevices' => '1.3.6.1.4.1.231.2.49.1.3.2',
  'svrStatusPhysicalDevicesDefinition' => {
    '1' => 'ok',
    '2' => 'prefailure',
    '3' => 'failure',
  },
  'svrStatusControllers' => '1.3.6.1.4.1.231.2.49.1.3.3',
  'svrStatusControllersDefinition' => {
    '1' => 'ok',
    '2' => 'prefailure',
    '3' => 'failure',
  },
  'svrStatusOverall' => '1.3.6.1.4.1.231.2.49.1.3.4',
  'svrStatusOverallDefinition' => {
    '1' => 'ok',
    '2' => 'prefailure',
    '3' => 'failure',
  },
  'svrControllerInfo' => '1.3.6.1.4.1.231.2.49.1.4',
  'svrNumberRaidControllers' => '1.3.6.1.4.1.231.2.49.1.4.1',
  'svrCtrlTable' => '1.3.6.1.4.1.231.2.49.1.4.2',
  'svrCtrlEntry' => '1.3.6.1.4.1.231.2.49.1.4.2.1',
  'svrCtrlNr' => '1.3.6.1.4.1.231.2.49.1.4.2.1.1',
  'svrCtrlModelName' => '1.3.6.1.4.1.231.2.49.1.4.2.1.2',
  'svrCtrlManufacturerName' => '1.3.6.1.4.1.231.2.49.1.4.2.1.3',
  'svrCtrlBusLocation' => '1.3.6.1.4.1.231.2.49.1.4.2.1.4',
  'svrCtrlBusLocationText' => '1.3.6.1.4.1.231.2.49.1.4.2.1.5',
  'svrCtrlHardwareRevision' => '1.3.6.1.4.1.231.2.49.1.4.2.1.6',
  'svrCtrlFirmwareRevision' => '1.3.6.1.4.1.231.2.49.1.4.2.1.7',
  'svrCtrlBiosRevision' => '1.3.6.1.4.1.231.2.49.1.4.2.1.8',
  'svrCtrlNumberChannels' => '1.3.6.1.4.1.231.2.49.1.4.2.1.9',
  'svrCtrlMaxChannelInUse' => '1.3.6.1.4.1.231.2.49.1.4.2.1.10',
  'svrCtrlNumberPhysDisks' => '1.3.6.1.4.1.231.2.49.1.4.2.1.11',
  'svrCtrlNumberLogicalDrives' => '1.3.6.1.4.1.231.2.49.1.4.2.1.12',
  'svrCtrlCacheSize' => '1.3.6.1.4.1.231.2.49.1.4.2.1.13',
  'svrCtrlBBUStatus' => '1.3.6.1.4.1.231.2.49.1.4.2.1.14',
  'svrCtrlBBUStatusDefinition' => {
    '1' => 'not Available',
    '2' => 'on Line',
    '3' => 'on Battery',
    '4' => 'on Battery Low',
    '5' => 'charging',
    '6' => 'discharging',
    '7' => 'failed',
  },
  'svrCtrlStatus' => '1.3.6.1.4.1.231.2.49.1.4.2.1.15',
  'svrCtrlStatusDefinition' => {
    '1' => 'ok',
    '2' => 'prefailure',
    '3' => 'failure',
  },
  'svrCtrlInterface' => '1.3.6.1.4.1.231.2.49.1.4.2.1.16',
  'svrCtrlBusLocationBus' => '1.3.6.1.4.1.231.2.49.1.4.2.1.17',
  'svrCtrlBusLocationDevice' => '1.3.6.1.4.1.231.2.49.1.4.2.1.18',
  'svrCtrlBusLocationFunction' => '1.3.6.1.4.1.231.2.49.1.4.2.1.19',
  'svrCtrlBusLocationSlot' => '1.3.6.1.4.1.231.2.49.1.4.2.1.20',
  'svrCtrlSerialNo' => '1.3.6.1.4.1.231.2.49.1.4.2.1.21',
  'svrCtrlDriverName' => '1.3.6.1.4.1.231.2.49.1.4.2.1.22',
  'svrCtrlDriverRevision' => '1.3.6.1.4.1.231.2.49.1.4.2.1.23',
  'svrCtrlBBUStatusEx' => '1.3.6.1.4.1.231.2.49.1.4.2.1.24',
  'svrCtrlDisplayName' => '1.3.6.1.4.1.231.2.49.1.4.2.1.25',
  'svrCtrlHostName' => '1.3.6.1.4.1.231.2.49.1.4.2.1.26',
  'svrCtrlUEFIDriverRevision' => '1.3.6.1.4.1.231.2.49.1.4.2.1.27',
  'svrPhysicalDeviceInfo' => '1.3.6.1.4.1.231.2.49.1.5',
  'svrNumberPhysicalDevices' => '1.3.6.1.4.1.231.2.49.1.5.1',
  'svrPhysicalDeviceTable' => '1.3.6.1.4.1.231.2.49.1.5.2',
  'svrPhysicalDeviceEntry' => '1.3.6.1.4.1.231.2.49.1.5.2.1',
  'svrPhysicalDeviceCtrlNr' => '1.3.6.1.4.1.231.2.49.1.5.2.1.1',
  'svrPhysicalDeviceChannel' => '1.3.6.1.4.1.231.2.49.1.5.2.1.2',
  'svrPhysicalDeviceTarget' => '1.3.6.1.4.1.231.2.49.1.5.2.1.3',
  'svrPhysicalDeviceLUN' => '1.3.6.1.4.1.231.2.49.1.5.2.1.4',
  'svrPhysicalDeviceModelName' => '1.3.6.1.4.1.231.2.49.1.5.2.1.5',
  'svrPhysicalDeviceVendorName' => '1.3.6.1.4.1.231.2.49.1.5.2.1.6',
  'svrPhysicalDeviceCapacity' => '1.3.6.1.4.1.231.2.49.1.5.2.1.7',
  'svrPhysicalDeviceMaxTransferRate' => '1.3.6.1.4.1.231.2.49.1.5.2.1.8',
  'svrPhysicalDeviceType' => '1.3.6.1.4.1.231.2.49.1.5.2.1.9',
  'svrPhysicalDeviceTypeDefinition' => {
    '1' => 'other',
    '2' => 'SCSI',
    '3' => 'IDE',
    '4' => '1394',
    '5' => 'SATA',
    '6' => 'SAS',
    '7' => 'FC',
  },
  'svrPhysicalDeviceConfiguredDisk' => '1.3.6.1.4.1.231.2.49.1.5.2.1.10',
  'svrPhysicalDeviceInterface' => '1.3.6.1.4.1.231.2.49.1.5.2.1.11',
  'svrPhysicalDeviceErrors' => '1.3.6.1.4.1.231.2.49.1.5.2.1.12',
  'svrPhysicalDeviceNrBadBlocks' => '1.3.6.1.4.1.231.2.49.1.5.2.1.13',
  'svrPhysicalDeviceSmartStatus' => '1.3.6.1.4.1.231.2.49.1.5.2.1.14',
  'svrPhysicalDeviceSmartStatusDefinition' => {
    '1' => 'ok',
    '2' => 'failure Predicted',
    '3' => 'N/A',
    '4' => 'SMART monitoring disabled',
  },
  'svrPhysicalDeviceStatus' => '1.3.6.1.4.1.231.2.49.1.5.2.1.15',
  'svrPhysicalDeviceStatusDefinition' => {
    '2' => 'is not a hard disk',
    '3' => 'online',
    '4' => 'can be used for new configuration',
    '5' => 'is available but no longer working',
    '6' => 'rebuilding',
    '7' => 'is a hot spare device for use in any array',
    '8' => 'is a hot spare device for use in a dedicated array',
    '9' => 'is set to non-working state',
    '10' => 'is not configured but a failure has occured',
    '12' => 'is not available or not responding',
    '15' => 'is currently being formatted',
  },
  'svrPhysicalDeviceFirmwareRevision' => '1.3.6.1.4.1.231.2.49.1.5.2.1.16',
  'svrPhysicalDeviceSerialNumber' => '1.3.6.1.4.1.231.2.49.1.5.2.1.17',
  'svrPhysicalDeviceForeignConfig' => '1.3.6.1.4.1.231.2.49.1.5.2.1.18',
  'svrPhysicalDeviceIdx' => '1.3.6.1.4.1.231.2.49.1.5.2.1.19',
  'svrPhysicalDeviceStatusEx' => '1.3.6.1.4.1.231.2.49.1.5.2.1.20',
  'svrPhysicalDeviceCapacityMB' => '1.3.6.1.4.1.231.2.49.1.5.2.1.21',
  'svrPhysicalDeviceEnclosureNumber' => '1.3.6.1.4.1.231.2.49.1.5.2.1.22',
  'svrPhysicalDeviceSlot' => '1.3.6.1.4.1.231.2.49.1.5.2.1.23',
  'svrPhysicalDeviceDisplayName' => '1.3.6.1.4.1.231.2.49.1.5.2.1.24',
  'svrPhysicalDevicePowerStatus' => '1.3.6.1.4.1.231.2.49.1.5.2.1.25',
  'svrLogicalDriveInfo' => '1.3.6.1.4.1.231.2.49.1.6',
  'svrNumberLogicalDrives' => '1.3.6.1.4.1.231.2.49.1.6.1',
  'svrLogicalDriveTable' => '1.3.6.1.4.1.231.2.49.1.6.2',
  'svrLogicalDriveEntry' => '1.3.6.1.4.1.231.2.49.1.6.2.1',
  'svrLogicalDriveCtrlNr' => '1.3.6.1.4.1.231.2.49.1.6.2.1.1',
  'svrLogicalDriveNr' => '1.3.6.1.4.1.231.2.49.1.6.2.1.2',
  'svrLogicalDriveArraySize' => '1.3.6.1.4.1.231.2.49.1.6.2.1.3',
  'svrLogicalDriveTotalSize' => '1.3.6.1.4.1.231.2.49.1.6.2.1.4',
  'svrLogicalDriveRaidLevel' => '1.3.6.1.4.1.231.2.49.1.6.2.1.5',
  'svrLogicalDriveRaidLevelStr' => '1.3.6.1.4.1.231.2.49.1.6.2.1.6',
  'svrLogicalDriveStripeSize' => '1.3.6.1.4.1.231.2.49.1.6.2.1.7',
  'svrLogicalDriveWriteMode' => '1.3.6.1.4.1.231.2.49.1.6.2.1.8',
  'svrLogicalDriveProgress' => '1.3.6.1.4.1.231.2.49.1.6.2.1.9',
  'svrLogicalDriveStatus' => '1.3.6.1.4.1.231.2.49.1.6.2.1.10',
  'svrLogicalDriveStatusDefinition' => {
    '2' => 'drive is OK, all disks working properly',
    '3' => 'one disk in this array failed, redundancy lost',
    '4' => 'too many disks in this array failed, drive no longer available',
    '5' => 'is currently rebuilding (new disk added)',
    '6' => 'is currently executing a consistency check',
    '7' => 'was just created and is currently being initialized',
    '8' => 'is currently being modified (online RAID extension)',
    '9' => 'one disk in this array failed, reduced redundancy still available',
  },
  'svrLogicalDriveName' => '1.3.6.1.4.1.231.2.49.1.6.2.1.11',
  'svrLogicalDriveArraySizeMB' => '1.3.6.1.4.1.231.2.49.1.6.2.1.12',
  'svrLogicalDriveTotalSizeMB' => '1.3.6.1.4.1.231.2.49.1.6.2.1.13',
  'svrLogicalDriveOSDeviceName' => '1.3.6.1.4.1.231.2.49.1.6.2.1.14',
  'svrLogicalDriveReadMode' => '1.3.6.1.4.1.231.2.49.1.6.2.1.15',
  'svrLogicalDriveCacheMode' => '1.3.6.1.4.1.231.2.49.1.6.2.1.16',
  'svrLogicalDriveDiskCacheMode' => '1.3.6.1.4.1.231.2.49.1.6.2.1.17',
  'svrLogicalDriveInitStatus' => '1.3.6.1.4.1.231.2.49.1.6.2.1.18',
  'svrLogicalDriveStatusEx' => '1.3.6.1.4.1.231.2.49.1.6.2.1.19',
  'svrLogicalDriveDisplayName' => '1.3.6.1.4.1.231.2.49.1.6.2.1.20',
  'svrLogicalDriveContentsTable' => '1.3.6.1.4.1.231.2.49.1.6.3',
  'svrLogicalDriveContentsEntry' => '1.3.6.1.4.1.231.2.49.1.6.3.1',
  'svrLogicalDriveContentsCtrlNr' => '1.3.6.1.4.1.231.2.49.1.6.3.1.1',
  'svrLogicalDriveContentsLogicalDriveNr' => '1.3.6.1.4.1.231.2.49.1.6.3.1.2',
  'svrLogicalDriveContentsNr' => '1.3.6.1.4.1.231.2.49.1.6.3.1.3',
  'svrLogicalDriveContentsChannel' => '1.3.6.1.4.1.231.2.49.1.6.3.1.4',
  'svrLogicalDriveContentsTarget' => '1.3.6.1.4.1.231.2.49.1.6.3.1.5',
  'svrLogicalDriveContentsLUN' => '1.3.6.1.4.1.231.2.49.1.6.3.1.6',
  'svrLogicalDriveContentsIdx' => '1.3.6.1.4.1.231.2.49.1.6.3.1.7',
  'svrLogicalDriveContentsSpanNr' => '1.3.6.1.4.1.231.2.49.1.6.3.1.8',
};




package Monitoring::GLPlugin::SNMP::MibsAndOids::SERVERVIEWSTATUSMIB;

$Monitoring::GLPlugin::SNMP::MibsAndOids::origin->{'SERVERVIEW-STATUS-MIB'} = {
  url => '',
  name => 'SERVERVIEW-STATUS-MIB',
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{'SERVERVIEW-STATUS-MIB'} = 
  '1.3.6.1.4.1.231.2.10.2.11';

$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{'SERVERVIEW-STATUS-MIB'} = {
  'sieStAgentInfo' => '1.3.6.1.4.1.231.2.10.2.11.1',
  'sieStAgentId' => '1.3.6.1.4.1.231.2.10.2.11.1.1',
  'sieStSystemStatus' => '1.3.6.1.4.1.231.2.10.2.11.2',
  'sieStSystemStatusValue' => '1.3.6.1.4.1.231.2.10.2.11.2.1',
  'sieStSystemStatusValueDefinition' => {
    '1' => 'ok',
    '2' => 'warning',
    '3' => 'error',
    '5' => 'unknown',
  },
  'sieStSystemLastErrorMessage' => '1.3.6.1.4.1.231.2.10.2.11.2.2',
  'sieStSubsystemList' => '1.3.6.1.4.1.231.2.10.2.11.2.3',
  'sieStSystemIdentify' => '1.3.6.1.4.1.231.2.10.2.11.2.4',
  'sieStSubsystemStatus' => '1.3.6.1.4.1.231.2.10.2.11.3',
  'sieStSubsystemTable' => '1.3.6.1.4.1.231.2.10.2.11.3.1',
  'sieStSubsystemEntry' => '1.3.6.1.4.1.231.2.10.2.11.3.1.1',
  'sieStSubsystems' => '1.3.6.1.4.1.231.2.10.2.11.3.1.1',
  'sieStSubsystemNumber' => '1.3.6.1.4.1.231.2.10.2.11.3.1.1.1',
  'sieStSubsystemName' => '1.3.6.1.4.1.231.2.10.2.11.3.1.1.2',
  'sieStSubsystemStatusValue' => '1.3.6.1.4.1.231.2.10.2.11.3.1.1.3',
  'sieStSubsystemStatusValueDefinition' => {
    '1' => 'ok',
    '2' => 'warning',
    '3' => 'error',
    '5' => 'unknown',
  },
  'sieStSubsystemLastErrorMessage' => '1.3.6.1.4.1.231.2.10.2.11.3.1.1.4',
  'sieStSubsystemComponents' => '1.3.6.1.4.1.231.2.10.2.11.3.1.1.5',
  'sieStSubsystemDisplayName' => '1.3.6.1.4.1.231.2.10.2.11.3.1.1.6',
  'sieStNumberSubsystems' => '1.3.6.1.4.1.231.2.10.2.11.3.2',
  'sieStComponentStatus' => '1.3.6.1.4.1.231.2.10.2.11.4',
  'sieStComponentTable' => '1.3.6.1.4.1.231.2.10.2.11.4.1',
  'sieStComponentEntry' => '1.3.6.1.4.1.231.2.10.2.11.4.1.1',
  'sieStComponents' => '1.3.6.1.4.1.231.2.10.2.11.4.1.1',
  'sieStComponentNumber' => '1.3.6.1.4.1.231.2.10.2.11.4.1.1.1',
  'sieStComponentName' => '1.3.6.1.4.1.231.2.10.2.11.4.1.1.2',
  'sieStComponentStatusValue' => '1.3.6.1.4.1.231.2.10.2.11.4.1.1.3',
  'sieStComponentStatusValueDefinition' => {
    '1' => 'ok',
    '2' => 'warning',
    '3' => 'error',
    '5' => 'unknown',
    '6' => 'unknown',
  },
  'sieStComponentLastErrorMessage' => '1.3.6.1.4.1.231.2.10.2.11.4.1.1.4',
  'sieStComponentDisplayName' => '1.3.6.1.4.1.231.2.10.2.11.4.1.1.5',
  'sieStComponentConfirmFailure' => '1.3.6.1.4.1.231.2.10.2.11.4.1.1.6',
  'sieStNumberComponents' => '1.3.6.1.4.1.231.2.10.2.11.4.2',
  'sieStAgentParameters' => '1.3.6.1.4.1.231.2.10.2.11.5',
  'sieStAgentType' => '1.3.6.1.4.1.231.2.10.2.11.5.1',
  'sieStTrapParameters' => '1.3.6.1.4.1.231.2.10.2.11.10',
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{'SERVERVIEW-STATUS-MIB'} = {
};



package Monitoring::GLPlugin::SNMP::MibsAndOids::UCDDISKIOMIB;

$Monitoring::GLPlugin::SNMP::MibsAndOids::origin->{'UCD-DISKIO-MIB'} = {
  url => 'http://www.circitor.fr/Mibs/Files/UCD-DISKIO-MIB.mib',
  name => 'UCD-DISKIO-MIB',
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{'UCD-DISKIO-MIB'} =
    '1.3.6.1.4.1.2021.13.15';

$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{'UCD-DISKIO-MIB'} = {
  ucdDiskIOMIB => '1.3.6.1.4.1.2021.13.15',
  diskIOTable => '1.3.6.1.4.1.2021.13.15.1',
  diskIOEntry => '1.3.6.1.4.1.2021.13.15.1.1',
  diskIOIndex => '1.3.6.1.4.1.2021.13.15.1.1.1',
  diskIODevice => '1.3.6.1.4.1.2021.13.15.1.1.2',
  diskIONRead => '1.3.6.1.4.1.2021.13.15.1.1.3',
  diskIONWritten => '1.3.6.1.4.1.2021.13.15.1.1.4',
  diskIOReads => '1.3.6.1.4.1.2021.13.15.1.1.5',
  diskIOWrites => '1.3.6.1.4.1.2021.13.15.1.1.6',
  diskIOLA1 => '1.3.6.1.4.1.2021.13.15.1.1.9',
  diskIOLA5 => '1.3.6.1.4.1.2021.13.15.1.1.10',
  diskIOLA15 => '1.3.6.1.4.1.2021.13.15.1.1.11',
  diskIONReadX => '1.3.6.1.4.1.2021.13.15.1.1.12',
  diskIONWrittenX => '1.3.6.1.4.1.2021.13.15.1.1.13',
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{'UCD-DISKIO-MIB'} = {
};
package Monitoring::GLPlugin::SNMP::MibsAndOids::UCDSNMPMIB;

$Monitoring::GLPlugin::SNMP::MibsAndOids::origin->{'UCD-SNMP-MIB'} = {
  url => '',
  name => 'UCD-SNMP-MIB',
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::mib_ids->{'UCD-SNMP-MIB'} =
    '1.3.6.1.4.1.2021';

$Monitoring::GLPlugin::SNMP::MibsAndOids::mibs_and_oids->{'UCD-SNMP-MIB'} = {
  ucdavis => '1.3.6.1.4.1.2021',
  prTable => '1.3.6.1.4.1.2021.2',
  prEntry => '1.3.6.1.4.1.2021.2.1',
  prIndex => '1.3.6.1.4.1.2021.2.1.1',
  prNames => '1.3.6.1.4.1.2021.2.1.2',
  prMin => '1.3.6.1.4.1.2021.2.1.3',
  prMax => '1.3.6.1.4.1.2021.2.1.4',
  prCount => '1.3.6.1.4.1.2021.2.1.5',
  prErrorFlag => '1.3.6.1.4.1.2021.2.1.100',
  prErrorFlagDefinition => 'UCD-SNMP-MIB::UCDErrorFlag',
  prErrMessage => '1.3.6.1.4.1.2021.2.1.101',
  prErrFix => '1.3.6.1.4.1.2021.2.1.102',
  prErrFixDefinition => 'UCD-SNMP-MIB::UCDErrorFix',
  prErrFixCmd => '1.3.6.1.4.1.2021.2.1.103',
  memory => '1.3.6.1.4.1.2021.4',
  memIndex => '1.3.6.1.4.1.2021.4.1',
  memErrorName => '1.3.6.1.4.1.2021.4.2',
  memTotalSwap => '1.3.6.1.4.1.2021.4.3',
  memAvailSwap => '1.3.6.1.4.1.2021.4.4',
  memTotalReal => '1.3.6.1.4.1.2021.4.5',
  memAvailReal => '1.3.6.1.4.1.2021.4.6',
  memTotalSwapTXT => '1.3.6.1.4.1.2021.4.7',
  memAvailSwapTXT => '1.3.6.1.4.1.2021.4.8',
  memTotalRealTXT => '1.3.6.1.4.1.2021.4.9',
  memAvailRealTXT => '1.3.6.1.4.1.2021.4.10',
  memTotalFree => '1.3.6.1.4.1.2021.4.11',
  memMinimumSwap => '1.3.6.1.4.1.2021.4.12',
  memShared => '1.3.6.1.4.1.2021.4.13',
  memBuffer => '1.3.6.1.4.1.2021.4.14',
  memCached => '1.3.6.1.4.1.2021.4.15',
  memUsedSwapTXT => '1.3.6.1.4.1.2021.4.16',
  memUsedRealTXT => '1.3.6.1.4.1.2021.4.17',
  memSwapError => '1.3.6.1.4.1.2021.4.100',
  memSwapErrorDefinition => 'UCD-SNMP-MIB::UCDErrorFlag',
  memSwapErrorMsg => '1.3.6.1.4.1.2021.4.101',
  extTable => '1.3.6.1.4.1.2021.8',
  extEntry => '1.3.6.1.4.1.2021.8.1',
  extIndex => '1.3.6.1.4.1.2021.8.1.1',
  extNames => '1.3.6.1.4.1.2021.8.1.2',
  extCommand => '1.3.6.1.4.1.2021.8.1.3',
  extResult => '1.3.6.1.4.1.2021.8.1.100',
  extOutput => '1.3.6.1.4.1.2021.8.1.101',
  extErrFix => '1.3.6.1.4.1.2021.8.1.102',
  extErrFixDefinition => 'UCD-SNMP-MIB::UCDErrorFix',
  extErrFixCmd => '1.3.6.1.4.1.2021.8.1.103',
  dskTable => '1.3.6.1.4.1.2021.9',
  dskEntry => '1.3.6.1.4.1.2021.9.1',
  dskIndex => '1.3.6.1.4.1.2021.9.1.1',
  dskPath => '1.3.6.1.4.1.2021.9.1.2',
  dskDevice => '1.3.6.1.4.1.2021.9.1.3',
  dskMinimum => '1.3.6.1.4.1.2021.9.1.4',
  dskMinPercent => '1.3.6.1.4.1.2021.9.1.5',
  dskTotal => '1.3.6.1.4.1.2021.9.1.6',
  dskAvail => '1.3.6.1.4.1.2021.9.1.7',
  dskUsed => '1.3.6.1.4.1.2021.9.1.8',
  dskPercent => '1.3.6.1.4.1.2021.9.1.9',
  dskPercentNode => '1.3.6.1.4.1.2021.9.1.10',
  dskTotalLow => '1.3.6.1.4.1.2021.9.1.11',
  dskTotalHigh => '1.3.6.1.4.1.2021.9.1.12',
  dskAvailLow => '1.3.6.1.4.1.2021.9.1.13',
  dskAvailHigh => '1.3.6.1.4.1.2021.9.1.14',
  dskUsedLow => '1.3.6.1.4.1.2021.9.1.15',
  dskUsedHigh => '1.3.6.1.4.1.2021.9.1.16',
  dskErrorFlag => '1.3.6.1.4.1.2021.9.1.100',
  dskErrorFlagDefinition => 'UCD-SNMP-MIB::UCDErrorFlag',
  dskErrorMsg => '1.3.6.1.4.1.2021.9.1.101',
  laTable => '1.3.6.1.4.1.2021.10',
  laEntry => '1.3.6.1.4.1.2021.10.1',
  laIndex => '1.3.6.1.4.1.2021.10.1.1',
  laNames => '1.3.6.1.4.1.2021.10.1.2',
  laLoad => '1.3.6.1.4.1.2021.10.1.3',
  laConfig => '1.3.6.1.4.1.2021.10.1.4',
  laLoadInt => '1.3.6.1.4.1.2021.10.1.5',
  laLoadFloat => '1.3.6.1.4.1.2021.10.1.6',
  laErrorFlag => '1.3.6.1.4.1.2021.10.1.100',
  laErrorFlagDefinition => 'UCD-SNMP-MIB::UCDErrorFlag',
  laErrMessage => '1.3.6.1.4.1.2021.10.1.101',
  systemStats => '1.3.6.1.4.1.2021.11',
  ssIndex => '1.3.6.1.4.1.2021.11.1',
  ssErrorName => '1.3.6.1.4.1.2021.11.2',
  ssSwapIn => '1.3.6.1.4.1.2021.11.3',
  ssSwapOut => '1.3.6.1.4.1.2021.11.4',
  ssIOSent => '1.3.6.1.4.1.2021.11.5',
  ssIOReceive => '1.3.6.1.4.1.2021.11.6',
  ssSysInterrupts => '1.3.6.1.4.1.2021.11.7',
  ssSysContext => '1.3.6.1.4.1.2021.11.8',
  ssCpuUser => '1.3.6.1.4.1.2021.11.9',
  ssCpuSystem => '1.3.6.1.4.1.2021.11.10',
  ssCpuIdle => '1.3.6.1.4.1.2021.11.11',
  ssCpuRawUser => '1.3.6.1.4.1.2021.11.50',
  ssCpuRawNice => '1.3.6.1.4.1.2021.11.51',
  ssCpuRawSystem => '1.3.6.1.4.1.2021.11.52',
  ssCpuRawIdle => '1.3.6.1.4.1.2021.11.53',
  ssCpuRawWait => '1.3.6.1.4.1.2021.11.54',
  ssCpuRawKernel => '1.3.6.1.4.1.2021.11.55',
  ssCpuRawInterrupt => '1.3.6.1.4.1.2021.11.56',
  ssIORawSent => '1.3.6.1.4.1.2021.11.57',
  ssIORawReceived => '1.3.6.1.4.1.2021.11.58',
  ssRawInterrupts => '1.3.6.1.4.1.2021.11.59',
  ssRawContexts => '1.3.6.1.4.1.2021.11.60',
  ssCpuRawSoftIRQ => '1.3.6.1.4.1.2021.11.61',
  ssRawSwapIn => '1.3.6.1.4.1.2021.11.62',
  ssRawSwapOut => '1.3.6.1.4.1.2021.11.63',
  ssCpuRawSteal => '1.3.6.1.4.1.2021.11.64',
  ssCpuRawGuest => '1.3.6.1.4.1.2021.11.65',
  ssCpuRawGuestNice => '1.3.6.1.4.1.2021.11.66',
  ssCpuNumCpus => '1.3.6.1.4.1.2021.11.67',
  ucdInternal => '1.3.6.1.4.1.2021.12',
  ucdExperimental => '1.3.6.1.4.1.2021.13',
  fileTable => '1.3.6.1.4.1.2021.15',
  fileEntry => '1.3.6.1.4.1.2021.15.1',
  fileIndex => '1.3.6.1.4.1.2021.15.1.1',
  fileName => '1.3.6.1.4.1.2021.15.1.2',
  fileSize => '1.3.6.1.4.1.2021.15.1.3',
  fileMax => '1.3.6.1.4.1.2021.15.1.4',
  fileErrorFlag => '1.3.6.1.4.1.2021.15.1.100',
  fileErrorFlagDefinition => 'UCD-SNMP-MIB::UCDErrorFlag',
  fileErrorMsg => '1.3.6.1.4.1.2021.15.1.101',
  logMatch => '1.3.6.1.4.1.2021.16',
  logMatchMaxEntries => '1.3.6.1.4.1.2021.16.1',
  logMatchTable => '1.3.6.1.4.1.2021.16.2',
  logMatchEntry => '1.3.6.1.4.1.2021.16.2.1',
  logMatchIndex => '1.3.6.1.4.1.2021.16.2.1.1',
  logMatchName => '1.3.6.1.4.1.2021.16.2.1.2',
  logMatchFilename => '1.3.6.1.4.1.2021.16.2.1.3',
  logMatchRegEx => '1.3.6.1.4.1.2021.16.2.1.4',
  logMatchGlobalCounter => '1.3.6.1.4.1.2021.16.2.1.5',
  logMatchGlobalCount => '1.3.6.1.4.1.2021.16.2.1.6',
  logMatchCurrentCounter => '1.3.6.1.4.1.2021.16.2.1.7',
  logMatchCurrentCount => '1.3.6.1.4.1.2021.16.2.1.8',
  logMatchCounter => '1.3.6.1.4.1.2021.16.2.1.9',
  logMatchCount => '1.3.6.1.4.1.2021.16.2.1.10',
  logMatchCycle => '1.3.6.1.4.1.2021.16.2.1.11',
  logMatchErrorFlag => '1.3.6.1.4.1.2021.16.2.1.100',
  logMatchErrorFlagDefinition => 'UCD-SNMP-MIB::UCDErrorFlag',
  logMatchRegExCompilation => '1.3.6.1.4.1.2021.16.2.1.101',
  version => '1.3.6.1.4.1.2021.100',
  versionIndex => '1.3.6.1.4.1.2021.100.1',
  versionTag => '1.3.6.1.4.1.2021.100.2',
  versionDate => '1.3.6.1.4.1.2021.100.3',
  versionCDate => '1.3.6.1.4.1.2021.100.4',
  versionIdent => '1.3.6.1.4.1.2021.100.5',
  versionConfigureOptions => '1.3.6.1.4.1.2021.100.6',
  versionClearCache => '1.3.6.1.4.1.2021.100.10',
  versionUpdateConfig => '1.3.6.1.4.1.2021.100.11',
  versionRestartAgent => '1.3.6.1.4.1.2021.100.12',
  versionSavePersistentData => '1.3.6.1.4.1.2021.100.13',
  versionDoDebugging => '1.3.6.1.4.1.2021.100.20',
  snmperrs => '1.3.6.1.4.1.2021.101',
  snmperrIndex => '1.3.6.1.4.1.2021.101.1',
  snmperrNames => '1.3.6.1.4.1.2021.101.2',
  snmperrErrorFlag => '1.3.6.1.4.1.2021.101.100',
  snmperrErrorFlagDefinition => 'UCD-SNMP-MIB::UCDErrorFlag',
  snmperrErrMessage => '1.3.6.1.4.1.2021.101.101',
  mrTable => '1.3.6.1.4.1.2021.102',
  mrEntry => '1.3.6.1.4.1.2021.102.1',
  mrIndex => '1.3.6.1.4.1.2021.102.1.1',
  mrModuleName => '1.3.6.1.4.1.2021.102.1.2',
  ucdSnmpAgent => '1.3.6.1.4.1.2021.250',
  hpux9 => '1.3.6.1.4.1.2021.250.1',
  sunos4 => '1.3.6.1.4.1.2021.250.2',
  solaris => '1.3.6.1.4.1.2021.250.3',
  osf => '1.3.6.1.4.1.2021.250.4',
  ultrix => '1.3.6.1.4.1.2021.250.5',
  hpux10 => '1.3.6.1.4.1.2021.250.6',
  netbsd1 => '1.3.6.1.4.1.2021.250.7',
  freebsd => '1.3.6.1.4.1.2021.250.8',
  irix => '1.3.6.1.4.1.2021.250.9',
  linux => '1.3.6.1.4.1.2021.250.10',
  bsdi => '1.3.6.1.4.1.2021.250.11',
  openbsd => '1.3.6.1.4.1.2021.250.12',
  win32 => '1.3.6.1.4.1.2021.250.13',
  hpux11 => '1.3.6.1.4.1.2021.250.14',
  aix => '1.3.6.1.4.1.2021.250.15',
  macosx => '1.3.6.1.4.1.2021.250.16',
  dragonfly => '1.3.6.1.4.1.2021.250.17',
  unknown => '1.3.6.1.4.1.2021.250.255',
  ucdTraps => '1.3.6.1.4.1.2021.251',
};

$Monitoring::GLPlugin::SNMP::MibsAndOids::definitions->{'UCD-SNMP-MIB'} = {
  UCDErrorFix => {
    '0' => 'noError',
    '1' => 'runFix',
  },
  UCDErrorFlag => {
    '0' => 'noError',
    '1' => 'error',
  },
};
package Monitoring::GLPlugin::SNMP::CSF;
#our @ISA = qw(Monitoring::GLPlugin::SNMP);
use Digest::MD5 qw(md5_hex);
use strict;

sub create_statefile {
  my ($self, %params) = @_;
  my $extension = "";
  $extension .= $params{name} ? '_'.$params{name} : '';
  if ($self->opts->community) {
    $extension .= md5_hex($self->opts->community);
  }
  $extension =~ s/\//_/g;
  $extension =~ s/\(/_/g;
  $extension =~ s/\)/_/g;
  $extension =~ s/\*/_/g;
  $extension =~ s/\s/_/g;
  if ($self->opts->snmpwalk && ! $self->opts->hostname) {
    return sprintf "%s/%s_%s%s", $self->statefilesdir(),
        'snmpwalk.file'.md5_hex($self->opts->snmpwalk),
        $self->clean_path($self->mode), $self->clean_path(lc $extension);
  } elsif ($self->opts->snmpwalk && $self->opts->hostname eq "walkhost") {
    return sprintf "%s/%s_%s%s", $self->statefilesdir(),
        'snmpwalk.file'.md5_hex($self->opts->snmpwalk),
        $self->clean_path($self->mode), $self->clean_path(lc $extension);
  } else {
    return sprintf "%s/%s_%s%s", $self->statefilesdir(),
        $self->opts->hostname,
        $self->clean_path($self->mode), $self->clean_path(lc $extension);
  }
}



package Monitoring::GLPlugin::SNMP::Item;
our @ISA = qw(Monitoring::GLPlugin::SNMP::CSF Monitoring::GLPlugin::Item Monitoring::GLPlugin::SNMP);
use strict;



package Monitoring::GLPlugin::SNMP::TableItem;
our @ISA = qw(Monitoring::GLPlugin::SNMP::CSF Monitoring::GLPlugin::TableItem Monitoring::GLPlugin::SNMP);
use strict;

sub ensure_index {
  my ($self, $key) = @_;
  $self->{$key} ||= $self->{flat_indices};
}

sub unhex_ip {
  my ($self, $value) = @_;
  if ($value && $value =~ /^0x(\w{8})/) {
    $value = join(".", unpack "C*", pack "H*", $1);
  } elsif ($value && $value =~ /^0x(\w{2} \w{2} \w{2} \w{2})/) {
    $value = $1;
    $value =~ s/ //g;
    $value = join(".", unpack "C*", pack "H*", $value);
  } elsif ($value && $value =~ /^([A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2})/i) {
    $value = $1;
    $value =~ s/ //g;
    $value = join(".", unpack "C*", pack "H*", $value);
  } elsif ($value && unpack("H8", $value) =~ /(\w{2})(\w{2})(\w{2})(\w{2})/) {
    $value = join(".", map { hex($_) } ($1, $2, $3, $4));
  }
  return $value;
}

sub _compact_v6 {
  my ($self, $addr) = @_;

  my @o = split /:/, $addr;
  return $addr unless @o and grep { $_ =~ m/^0+$/ } @o;

  my @candidates	= ();
  my $start		= undef;

  for my $i (0 .. $#o) {
    if (defined $start) {
      if ($o[$i] !~ m/^0+$/) {
        push @candidates, [ $start, $i - $start ];
        $start = undef;
      }
    } else {
      $start = $i if $o[$i] =~ m/^0+$/;
    }
  }

  push @candidates, [$start, 8 - $start] if defined $start;

  my $l = (sort { $b->[1] <=> $a->[1] } @candidates)[0];

  return $addr unless defined $l;

  $addr = $l->[0] == 0 ? '' : join ':', @o[0 .. $l->[0] - 1];
  $addr .= '::';
  $addr .= join ':', @o[$l->[0] + $l->[1] .. $#o];
  $addr =~ s/(^|:)0{1,3}/$1/g;

  return $addr;
}

sub unhex_ipv6 {
  my ($self, $value) = @_;
  if ($value && $value =~ /^0x(\w{32})/) {
    $value = join(":", unpack "C*", pack "H*", $1);
  } elsif ($value && $value =~ /^0x(\w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2} \w{2})/) {
    $value = $1;
    $value =~ s/ //g;
    $value = join(":", unpack "C*", pack "H*", $value);
  } elsif ($value && $value =~ /^([A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2} [A-Z0-9]{2})/i) {
    $value = $1;
    $value =~ s/ //g;
    $value = join(":", unpack "C*", pack "H*", $value);
  } elsif ($value && unpack("H32", $value) =~ /(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})(\w{4})/) {
    $value = join(":", $1, $2, $3, $4, $5, $6, $7, $8);
  }
  return $self->_compact_v6($value);
}

sub unhex_mac {
  my ($self, $value) = @_;
  if ($value && $value =~ /^0x(\w{12})/) {
    $value = join(".", unpack "C*", pack "H*", $1);
  } elsif ($value && $value =~ /^0x(\w{2}\s*\w{2}\s*\w{2}\s*\w{2}\s*\w{2}\s*\w{2})/) {
    $value = $1;
    $value =~ s/ //g;
    $value = join(":", unpack "C*", pack "H*", $value);
  } elsif ($value && unpack("H12", $value) =~ /(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})(\w{2})/) {
    $value = join(":", map { hex($_) } ($1, $2, $3, $4, $5, $6));
  }
  return $value;
}

sub unhex_octet_string {
  my ($self, $value) = @_;
  my $original = $value;
  $value =~ s/ //g;
  if ($value && $value =~ /^0x([0-9a-zA-Z]+)$/) {
    $value = join("", unpack "A*", pack "H*", $1);
  } elsif ($value && $value =~ /^([0-9a-zA-Z]+)$/) {
    $value = join("", unpack "A*", pack "H*", $1);
  } else {
    $value = $original;
  }
  return $value;
}



package Classes::Fujitsu::FscRaid::Components::RaidSubsystem;
our @ISA = qw(Monitoring::GLPlugin::SNMP::Item);
use strict;

sub init {
  my $self = shift;
  $self->get_snmp_objects('FSC-RAID-MIB', qw(svrStatus svrStatusLogicalDrives 
      svrStatusPhysicalDevices svrStatusControllers svrStatusOverall
      svrControllerInfo));
  $self->get_snmp_tables('FSC-RAID-MIB', [
      ['controllers', 'svrCtrlTable', 'Classes::Fujitsu::FscRaid::Components::RaidSubsystem::Controller'],
      ['physical_devices', 'svrPhysicalDeviceTable', 'Classes::Fujitsu::FscRaid::Components::RaidSubsystem::PhysicalDevice'],
      ['logical_drives', 'svrLogicalDriveTable', 'Classes::Fujitsu::FscRaid::Components::RaidSubsystem::LogicalDrive'],
  ]);
}

sub check {
  my $self = shift;
  foreach (@{$self->{controllers}}) {
    $_->check();
  }
  foreach (@{$self->{logical_drives}}) {
    $_->check();
  }
  foreach (@{$self->{physical_devices}}) {
    $_->check();
  }
  if (! $self->check_messages()) {
    $self->add_ok('raid hardware working fine');
  }
return;
  my $info = sprintf 'global system status is %s', $self->{sieStSystemStatusValue};
  if ($self->{sieStSystemLastErrorMessage} && $self->{sieStSystemLastErrorMessage} ne "<<not supported>>") {
    $info .= ', '.$self->{sieStSystemLastErrorMessage};
  }
  $self->add_info($info);
  if ($self->{sieStSystemStatusValue} eq "warning") {
    $self->add_warning();
  } elsif ($self->{sieStSystemStatusValue} eq "error") {
    $self->add_critical();
  } elsif ($self->{sieStSystemStatusValue} eq "unknown") {
    # ignore
  }
}


package Classes::Fujitsu::FscRaid::Components::RaidSubsystem::Controller;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf "BBU %s status is %s",
      $self->{flat_indices},
      $self->{svrCtrlBBUStatus});
  if ($self->{svrCtrlBBUStatus} eq "failed") {
    $self->add_critical();
  } elsif ($self->{svrCtrlBBUStatus} =~ /(on Battery Low)|(discharging)/) {
    $self->add_warning();
  }
  $self->add_info(sprintf "Controller %s status is %s",
      $self->{flat_indices},
      $self->{svrCtrlStatus});
  if ($self->{svrCtrlStatus} eq "failed") {
    $self->add_critical();
  } elsif ($self->{svrCtrlStatus} eq "prefailure") {
    $self->add_warning();
  }
}


package Classes::Fujitsu::FscRaid::Components::RaidSubsystem::LogicalDrive;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf "logical drive %s (%s) status is %s",
      $self->{flat_indices},
      $self->{svrLogicalDriveRaidLevelStr},
      $self->{svrLogicalDriveStatus});
  if ($self->{svrLogicalDriveStatus} =~ /(redundancy lost)|(drive no longer available)/) {
    $self->add_critical();
  } if ($self->{svrLogicalDriveStatus} =~ /(reduced redundancy still available)|(is currently being modified)|(currently being initialized)|(rebuilding)/) {
    $self->add_warning();
  }
  if ($self->{svrLogicalDriveStatus} =~ /rebuilding/) {
    $self->add_ok(sprintf "%s%%", $self->{svrLogicalDriveProgress});
  }
}


package Classes::Fujitsu::FscRaid::Components::RaidSubsystem::PhysicalDevice;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf "physical drive %s s.m.a.r.t status is %s",
      $self->{flat_indices},
      $self->{svrPhysicalDeviceSmartStatus});
  if ($self->{svrPhysicalDeviceSmartStatus} =~ /(failure)/) {
    $self->add_warning();
  }
  $self->add_info(sprintf "physical drive %s (%s) status is %s",
      $self->{flat_indices},
      $self->{svrPhysicalDeviceType},
      $self->{svrPhysicalDeviceStatus});
  if ($self->{svrPhysicalDeviceStatus} =~ /(no longer working)|(non-working state)|(a failure has occured)|(not available or not responding)/) {
    $self->add_critical();
  } elsif ($self->{svrPhysicalDeviceStatus} =~ /(rebuilding)/) {
    $self->add_warning();
  }
  
}


package Classes::Fujitsu::FscRaid;
our @ISA = qw(Classes::Device);
use strict;

sub init {
  my $self = shift;
  if ($self->mode =~ /device::hardware::health/) {
    $self->analyze_and_check_environmental_subsystem('Classes::Fujitsu::FscRaid::Components::RaidSubsystem');
  } else {
    $self->no_such_mode();
  }
}

package Classes::Fujitsu::ServerView::Components::EnvironmentalSubsystem;
our @ISA = qw(Monitoring::GLPlugin::SNMP::Item);
use strict;

sub init {
  my $self = shift;
  $self->get_snmp_objects('SERVERVIEW-STATUS-MIB', qw(sieStSystemStatusValue sieStSystemLastErrorMessage));
  $self->get_snmp_tables('SERVERVIEW-STATUS-MIB', [
      ['subsystems', 'sieStSubsystemTable', 'Classes::Fujitsu::ServerView::Components::Subsystem', sub { my $o = shift; $self->filter_name($o->{sieStSubsystemName})}],
      ['components', 'sieStComponentTable', 'Classes::Fujitsu::ServerView::Components::SubsystemComponent'],
  ]);
  foreach my $component (@{$self->{components}}) {
    foreach my $subsystem (@{$self->{subsystems}}) {
      foreach my $comp (split(/\s+/, $subsystem->{sieStSubsystemComponents})) {
        if ($component->{sieStComponentName} eq $comp) {
          push(@{$subsystem->{components}}, $component);
        }
      }
    }
  }
  delete $self->{components};
}

sub check {
  my $self = shift;
  my $info = sprintf 'global system status is %s', $self->{sieStSystemStatusValue};
  if ($self->{sieStSystemLastErrorMessage} && $self->{sieStSystemLastErrorMessage} ne "<<not supported>>") {
    $info .= ', '.$self->{sieStSystemLastErrorMessage};
  }
  $self->add_info($info);
  if ($self->{sieStSystemStatusValue} eq "warning") {
    $self->add_warning();
  } elsif ($self->{sieStSystemStatusValue} eq "error") {
    $self->add_critical();
  } elsif ($self->{sieStSystemStatusValue} eq "unknown") {
    # ignore
  }
  foreach (@{$self->{subsystems}}) {
    $_->check();
  }
  if (! $self->check_messages()) {
    $self->add_ok('hardware working fine');
  }
}


package Classes::Fujitsu::ServerView::Components::Subsystem;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf 'checking subsystem %s', $self->{sieStSubsystemName});
  my $info = sprintf 'subsys %s status is %s', $self->{sieStSubsystemName}, $self->{sieStSubsystemStatusValue};
  if ($self->{sieStSubsystemLastErrorMessage} && $self->{sieStSubsystemLastErrorMessage} ne "<<not supported>>") {
    $info .= ', '.$self->{sieStSubsystemLastErrorMessage};
  }
  $self->add_info($info);
  if ($self->{sieStSubsystemStatusValue} eq "warning") {
    $self->add_warning();
  } elsif ($self->{sieStSubsystemStatusValue} eq "error") {
    $self->add_critical();
  } elsif ($self->{sieStSubsystemStatusValue} eq "unknown") {
    # DESCRIPTION "Subsystem status value:
    # unknown(5):  none of the components had a valid status (e.g. during initialization);
    #              this status can be ignored
  }
  foreach (@{$self->{components}}) {
    $_->check();
  }
}


package Classes::Fujitsu::ServerView::Components::SubsystemComponent;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  my $info = sprintf 'component %s status is %s', $self->{sieStComponentDisplayName}, $self->{sieStComponentStatusValue};
  if ($self->{sieStComponentLastErrorMessage} && $self->{sieStComponentLastErrorMessage} ne "<<not supported>>") {
    $info .= ', '.$self->{sieStComponentLastErrorMessage};
  }
  $self->add_info($info);
  if ($self->{sieStComponentStatusValue} eq "warning") {
    $self->add_warning();
  } elsif ($self->{sieStComponentStatusValue} eq "error") {
    $self->add_critical();
  } elsif ($self->{sieStComponentStatusValue} eq "unknown") {
  # can be ignored
  }
}


package Classes::Fujitsu::ServerView;
our @ISA = qw(Classes::Device);
use strict;

sub init {
  my $self = shift;
  if ($self->mode =~ /device::hardware::health/) {
    $self->analyze_and_check_environmental_subsystem('Classes::Fujitsu::ServerView::Components::EnvironmentalSubsystem');
    if ($self->implements_mib('FSC-RAID-MIB')) {
      $self->analyze_and_check_environmental_subsystem('Classes::Fujitsu::FscRaid::Components::RaidSubsystem');
    }
  } else {
    $self->no_such_mode();
  }
}

package Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem;
our @ISA = qw(Monitoring::GLPlugin::SNMP::Item);
use strict;

sub init {
  my $self = shift;
  $self->get_snmp_objects('MMB-COM-MIB', qw(agentId agentCompany agentVersion 
      localServerUnitId numberUnits  unitTableUpdateCount
      agentStatus 
  ));
  $self->get_snmp_tables('MMB-COM-MIB', [
      #['units', 'unitTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['unitparents', 'unitParentTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['unitchilds', 'unitChildTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['managementnodes', 'managementNodeTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      ['managementprocessors', 'managementProcessorTable', 'Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::ManagementProcessor'],
      ##['ups', 'managedUpsNodeTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['servers', 'serverTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['poweronoffs', 'unitPowerOnOffTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['performances', 'performanceTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['powermonitorings', 'powerMonitoringTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['powersources', 'powerSourceInformationTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      ['temperatures', 'temperatureSensorTable', 'Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Temperature'],
      ['fans', 'fanTable', 'Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Fan'],
      ##['airflows', 'airflowTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['systemboards', 'systemBoardTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      ['powersupplies', 'powerSupplyTable', 'Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::PowerSupply'],
      ['voltages', 'voltageTable', 'Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Voltage'],
      ['cpus', 'cpuTable', 'Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Cpu'],
      ['memorymodules', 'memoryModuleTable', 'Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::MemoryModule'],
      #['componentpowerconsumptions', 'componentPowerConsumptionTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['logs', 'messageLogTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['msgtexts', 'messageTextLogTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      ['componentstatus', 'statusComponentTable', 'Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Component'],
      #['componentsensors', 'componentStatusSensorTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['firmwares', 'firmwareVersionTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['deploys', 'deployInfoTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['oemdeploys', 'oemDeployInfoTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['landeploys', 'deployLanInterfaceTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
      #['msgtexts', 'messageTextLogTable', 'Monitoring::GLPlugin::SNMP::TableItem'],
  ]);
  foreach my $key (keys %{$self}) {
    if (ref($self->{$key}) eq "ARRAY") {
      foreach my $item (@{$self->{$key}}) {
        $item->{origin} = $key;
      }
    }
  }
}

sub check {
  my $self = shift;
  $self->add_info(sprintf 'agent status is %s', $self->{agentStatus});
  if ($self->{agentStatus} eq "degraded") {
    $self->add_warning();
  } elsif ($self->{agentStatus} eq "error") {
    $self->add_critical();
  } elsif ($self->{agentStatus} eq "failed") {
    $self->add_critical();
  } elsif ($self->{agentStatus} eq "unknown") {
    $self->add_unknown();
  } else {
    $self->add_ok();
  }
  $self->SUPER::check();
  if (! $self->check_messages()) {
    $self->add_ok('hardware working fine');
  }
}


package Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::ManagementProcessor;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  # batteryzeugs
  $self->add_info(
      sprintf 'service processor %s at unit %s battery status is %s',
      $self->{spProcessorNr}, $self->{spUnitId}, $self->{spBatteryStatus});
  if ($self->{spBatteryStatus} eq "not-present") {
  } elsif ($self->{spBatteryStatus} eq "ok" ||
      $self->{spBatteryStatus} eq "recharging" ||
      $self->{spBatteryStatus} eq "on-battery") { # oder warning?
    $self->add_ok();
  } elsif ($self->{spBatteryStatus} eq "discharging") {
    $self->add_warning();
  } elsif ($self->{spBatteryStatus} eq "failed") {
    $self->add_critical();
  } else {
    $self->add_unknown();
  }
}


package Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Temperature;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf 'temperature %s is %s',
      $self->{tempSensorDesignation}, $self->{tempSensorStatus});
  if ($self->{tempSensorStatus} eq "ok" ||
      $self->{tempSensorStatus} eq "not-available") {
    $self->add_ok();
  } elsif ($self->{tempSensorStatus} eq "temperature-warning") {
    $self->add_warning();
  } elsif ($self->{tempSensorStatus} eq "temperature-critical" ||
      $self->{tempSensorStatus} eq "failed") {
    $self->add_critical();
  } else {
    $self->add_unknown();
  }
  $self->add_perfdata(
    label => 'temp_'.$self->{tempSensorDesignation},
    value => $self->{tempCurrentTemperature},
    warning => $self->{tempWarningLevel},
    critical => $self->{tempCriticalLevel},
  );
}


package Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Fan;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf 'fan %s status is %s',
      $self->{fanDesignation}, $self->{fanStatus});
  if ($self->{fanStatus} eq "not-present") {
  } elsif ($self->{fanStatus} eq "ok" ||
      $self->{fanStatus} eq "not-manageable" || # koennte auch ein error sein
      $self->{fanStatus} eq "disabled") {
    $self->add_ok();
  } elsif ($self->{fanStatus} eq "prefailed-predicted" ||
      $self->{fanStatus} eq "redundant-fan-failed") {
    $self->add_warning();
  } elsif ($self->{fanStatus} eq "failed") {
    $self->add_critical();
  } else {
    $self->add_unknown();
  }
}


package Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::PowerSupply;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf 'ps %s status is %s',
      $self->{powerSupplyDesignation}, $self->{powerSupplyStatus});
  if ($self->{powerSupplyStatus} eq "not-present") {
  } elsif ($self->{powerSupplyStatus} eq "ok") {
    $self->add_ok();
  } elsif ($self->{powerSupplyStatus} eq "predictive-fail" ||
      $self->{powerSupplyStatus} eq "ac-fail" ||
      $self->{powerSupplyStatus} eq "critical-temperature") {
    $self->add_warning();
  } elsif ($self->{powerSupplyStatus} eq "failed" ||
      $self->{powerSupplyStatus} eq "not-manageable" ||
      $self->{powerSupplyStatus} eq "dc-fail") {
    $self->add_critical();
  } else {
    $self->add_unknown();
  }
}


package Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Voltage;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf 'voltage %s status is %s',
      $self->{voltageDesignation}, $self->{voltageStatus});
  if ($self->{voltageStatus} eq "not-available") {
  } elsif ($self->{voltageStatus} eq "ok") {
    $self->add_ok();
  } elsif ($self->{voltageStatus} eq "low-warning" ||
      $self->{voltageStatus} eq "high-warning") {
    $self->add_warning();
  } elsif ($self->{voltageStatus} eq "too-low" ||
      $self->{voltageStatus} eq "too-high" ||
      $self->{voltageStatus} eq "sensor-failed") {
    $self->add_critical();
  } else {
    $self->add_unknown();
  }
}


package Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Cpu;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf 'cpu %s status is %s',
      $self->{cpuDesignation}, $self->{cpuStatus});
  if ($self->{cpuStatus} eq "not-present") {
  } elsif ($self->{cpuStatus} eq "ok") {
    $self->add_ok();
  } elsif ($self->{cpuStatus} eq "disabled" ||
      $self->{cpuStatus} eq "prefailed-warning" ||
      $self->{cpuStatus} eq "missing-termination") {
    $self->add_warning();
  } elsif ($self->{cpuStatus} eq "error" ||
      $self->{cpuStatus} eq "failed") {
    $self->add_critical();
  } else {
    $self->add_unknown();
  }
}


package Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::MemoryModule;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf 'memModule %s status is %s',
      $self->{memModuleDesignation}, $self->{memModuleStatus});
  if ($self->{memModuleStatus} eq "not-present") {
  } elsif ($self->{memModuleStatus} eq "ok") {
    $self->add_ok();
  } elsif ($self->{memModuleStatus} eq "failed-disabled" ||
      $self->{memModuleStatus} eq "warning" ||
      $self->{memModuleStatus} eq "hot-spare") {
    $self->add_warning();
  } elsif ($self->{memModuleStatus} eq "error" ||
      $self->{memModuleStatus} eq "configuration-error") {
    $self->add_critical();
  } else {
    $self->add_unknown();
  }
}


package Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem::Component;
our @ISA = qw(Monitoring::GLPlugin::SNMP::TableItem);
use strict;

sub check {
  my $self = shift;
  $self->add_info(sprintf '%s component status is %s',
      $self->{csType}, $self->{componentStatusValue});
  if ($self->{componentStatusValue} eq "ok") {
    $self->add_ok();
  } elsif ($self->{componentStatusValue} eq "failed" ||
      $self->{componentStatusValue} eq "degraded") {
    $self->add_warning();
  } elsif ($self->{componentStatusValue} eq "error") {
    $self->add_critical();
  } else {
    $self->add_unknown();
  }
}


package Classes::Fujitsu::PRIMEQUEST;
our @ISA = qw(Classes::Device);
use strict;

sub init {
  my $self = shift;
  if ($self->mode =~ /device::hardware::health/) {
    $self->analyze_and_check_environmental_subsystem('Classes::Fujitsu::PRIMEQUEST::Components::EnvironmentalSubsystem');
  } else {
    $self->no_such_mode();
  }
}

sub pretty_sysdesc {
  my ($self) = @_;
  $self->get_snmp_objects('MMB-COM-MIB', qw(agentId agentCompany agentVersion
    localServerUnitId numberUnits  unitTableUpdateCount
    agentStatus
  ));
  $self->get_snmp_tables('MMB-COM-MIB', [
      ['units', 'unitTable', 'Monitoring::GLPlugin::SNMP::TableItem', undef, ['unitModelName', 'unitClass']],
      ['mmps', 'managementProcessorTable', 'Monitoring::GLPlugin::SNMP::TableItem', undef, ['spUnitId', 'spFirmwareVersion']],
  ]);
  my $infos = {};
  foreach my $unit (@{$self->{units}}) {
    if ($unit->{unitClass} eq "chassis") {
      $infos->{chassis_model} = $unit->{unitModelName};
      $infos->{chassis_index} = $unit->{flat_indices};
    } elsif ($unit->{unitClass} eq "mmb") {
      $infos->{mmb_model} = $unit->{unitModelName};
      $infos->{mmb_index} = $unit->{flat_indices};
    }
  }
  foreach my $mmp (@{$self->{mmps}}) {
    if ($mmp->{spUnitId} == $infos->{mmb_index}) {
      $infos->{mmb_firmware} = $mmp->{spFirmwareVersion};
    }
  }
  return sprintf "%s@%s (FW: %s)", $infos->{mmb_model},
      $infos->{chassis_model}, $infos->{mmb_firmware};
}

package Classes::Device;
our @ISA = qw(Monitoring::GLPlugin::SNMP);
use strict;

sub classify {
  my $self = shift;
  if (! ($self->opts->hostname || $self->opts->snmpwalk)) {
    $self->add_unknown('either specify a hostname or a snmpwalk file');
  } else {
    $self->check_snmp_and_model();
    if (! $self->check_messages()) {
      if ($self->opts->verbose && $self->opts->verbose) {
        printf "I am a %s\n", $self->{productname};
      }
      if ($self->implements_mib('MMB-COM-MIB')) {
        $self->rebless('Classes::Fujitsu::PRIMEQUEST');
      } elsif ($self->{productname} =~ /Fujitsu ServerView /) {
        $self->rebless('Classes::Fujitsu::ServerView');
      } elsif ($self->implements_mib('SERVERVIEW-STATUS-MIB')) {
        $self->rebless('Classes::Fujitsu::ServerView');
      } elsif ($self->get_snmp_object('SERVERVIEW-STATUS-MIB', 'sieStAgentId', 0)) {
        $self->rebless('Classes::Fujitsu::ServerView');
      } elsif ($self->implements_mib('FSC-RAID-MIB')) {
        $self->rebless('Classes::Fujitsu::FscRaid');
      } else {
        if (my $class = $self->discover_suitable_class()) {
          $self->rebless($class);
        } else {
          $self->rebless('Classes::Generic');
        }
      }
    }
  }
  return $self;
}


package Classes::Generic;
our @ISA = qw(Classes::Device);
use strict;

sub init {
  my $self = shift;
  if ($self->mode =~ /something specific/) {
  } else {
    bless $self, 'Monitoring::GLPlugin::SNMP';
    $self->no_such_mode();
  }
}
package main;
#! /usr/bin/perl

use strict;
no warnings qw(once);

if ( ! grep /BEGIN/, keys %Monitoring::GLPlugin::) {
  eval {
    require Monitoring::GLPlugin;
    require Monitoring::GLPlugin::SNMP;
  };
  if ($@) {
    printf "UNKNOWN - module Monitoring::GLPlugin was not found. Either build a standalone version of this plugin or set PERL5LIB\n";
    printf "%s\n", $@;
    exit 3;
  }
}

my $plugin = Classes::Device->new(
    shortname => '',
    usage => 'Usage: %s [ -v|--verbose ] [ -t <timeout> ] '.
        '--mode <what-to-do> '.
        '--hostname <network-component> --community <snmp-community>'.
        '  ...]',
    version => '$Revision: 1.5.0.1 $',
    blurb => 'This plugin checks various parameters of network components ',
    url => 'http://labs.consol.de/nagios/check_fujitsu_health',
    timeout => 60,
    plugin => $Monitoring::GLPlugin::pluginname,
);
$plugin->add_mode(
    internal => 'device::hardware::health',
    spec => 'hardware-health',
    alias => undef,
    help => 'Check the status of environmental equipment (fans, temperatures, power, selftests)',
);
$plugin->add_snmp_modes();
$plugin->add_snmp_args();
$plugin->add_default_args();

$plugin->getopts();
$plugin->classify();
$plugin->validate_args();

if (! $plugin->check_messages()) {
  $plugin->init();
  if (! $plugin->check_messages()) {
    $plugin->add_ok($plugin->get_summary())
        if $plugin->get_summary();
    $plugin->add_ok($plugin->get_extendedinfo(" "))
        if $plugin->get_extendedinfo();
  }
} elsif ($plugin->opts->snmpwalk && $plugin->opts->offline) {
  ;
} else {
  ;
}
my ($code, $message) = $plugin->opts->multiline ?
    $plugin->check_messages(join => "\n", join_all => ', ') :
    $plugin->check_messages(join => ', ', join_all => ', ');
$message .= sprintf "\n%s\n", $plugin->get_info("\n")
    if $plugin->opts->verbose >= 1;

$plugin->nagios_exit($code, $message);
