git.lirion.de

Of git, get, and gud

summaryrefslogtreecommitdiffstats
path: root/nagios-plugins-contrib-24.20190301~bpo9+1/check_hpasm/check_hpasm-4.8/plugins-scripts/HP/StorageWorks.pm
blob: 5792961e713656623650e80f85a98a229d689534 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package HP::StorageWorks;

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

our  _æ_ ISA = qw(HP::Server);

sub init {
  my $self = shift;
  $self->{serial} = 'unknown';
  $self->{product} = 'unknown';
  $self->{romversion} = 'unknown';
  $self->collect();
  if (! $self->{runtime}->{plugin}->check_messages()) {
    $self->set_serial();
    $self->overall_init();
    $self->overall_check();
  }
}

sub overall_init {
  my $self = shift;
  my %params =  _æ_ _;
  my $snmpwalk = $self->{rawdata};
  my $cpqHoMibStatusArray = '1.3.6.1.4.1.232.11.2.10.1.0';
  $self->{cpqHoMibStatusArray} = SNMP::Utils::get_object(
      $snmpwalk, $cpqHoMibStatusArray);
  if ($self->{cpqHoMibStatusArray} =~ /^(\d+)\s+(\d+)\s+(\d+)\s+(\d+)/) {
    $self->{cpqHoMibStatusArray} = 1 * $2;
  } elsif ($self->{cpqHoMibStatusArray} =~ /^0x.*(\d\d)(\d\d)(\d\d)(\d\d)$/) {
    $self->{cpqHoMibStatusArray} = 1 * $2;
  }
}

sub overall_check {
  my $self = shift;
  if ($self->{cpqHoMibStatusArray} == 4) {
    $self->add_info('overall status is failed');
    $self->add_message(CRITICAL, 'overall status is failed');
  } elsif ($self->{cpqHoMibStatusArray} == 3) {
    $self->add_info('overall status is degraded');
    $self->add_message(WARNING, 'overall status is degraded');
  } elsif ($self->{cpqHoMibStatusArray} == 2) {
    $self->add_info('overall status is ok');
    $self->add_message(OK, 'overall status is ok');
  } elsif ($self->{cpqHoMibStatusArray} == 1) {
    $self->add_info('overall status is other');
    $self->add_message(UNKNOWN, 'overall status is other');
  }
}

sub identify {
  my $self = shift;
  return $self->{productname};
}

sub dump {
  my $self = shift;
  printf STDERR "serial %s\n", $self->{serial};
  printf STDERR "product %s\n", $self->{product};
  printf STDERR "romversion %s\n", $self->{romversion};
  printf STDERR "%s\n", Data::Dumper::Dumper($self->{components});
}

sub collect {
  my $self = shift;
  if ($self->{runtime}->{plugin}->opts->snmpwalk) {
    my $cpqHoMibStatusArray = '1.3.6.1.4.1.232.11.2.10.1.0';
    if (! exists $self->{rawdata}->{$cpqHoMibStatusArray}) {
        $self->add_message(CRITICAL,
            'snmpwalk returns no health data (cpqhost-mib)');
    }
  } else {
    my $net_snmp_version = Net::SNMP->VERSION(); # 5.002000 or 6.000000
    #$params{'-translate'} = [
    #  -all => 0x0
    #];
    my ($session, $error) = 
        Net::SNMP->session(%{$self->{runtime}->{snmpparams}});
    if (! defined $session) {
      $self->{plugin}->add_message(CRITICAL, 'cannot create session object');
      $self->trace(1, Data::Dumper::Dumper($self->{runtime}->{snmpparams}));
    }
    if (! $self->{runtime}->{plugin}->check_messages()) {
      # snmp peer is alive
      $self->trace(2, sprintf "Protocol is %s", 
          $self->{runtime}->{snmpparams}->{'-version'});
      my $cpqHoMibStatusArray = '1.3.6.1.4.1.232.11.2.10.1.0';
      $session->translate;
      my $tic = time;
      my $response = $session->get_request(
          -varbindlist => [$cpqHoMibStatusArray]
      );
      my $tac = time;
      $self->trace(2, sprintf "%03d seconds for walk cpqHoMibStatusArray (%d oids)",
          $tac - $tic, scalar(keys %{$response}));
      $session->close;
      map { $response->{$_} =~ s/^\s+//; $response->{$_} =~ s/\s+$//; }
          keys %$response;
      $self->{rawdata} = $response;
    }
  }
  return $self->{runtime}->{plugin}->check_messages();
}

sub set_serial {
  my $self = shift;
  my $snmpwalk = $self->{rawdata};
  my  _æ_ serials = ();
  my  _æ_ models = ();
  my  _æ_ fws = ();
  my $cpqSsBackplaneEntry = '1.3.6.1.4.1.232.8.2.2.6.1';
  my $cpqSsBackplaneFWRev = '1.3.6.1.4.1.232.8.2.2.6.1.3';
  my $cpqSsBackplaneModel = '1.3.6.1.4.1.232.8.2.2.6.1.9';
  my $cpqSsBackplaneSerialNumber = '1.3.6.1.4.1.232.8.2.2.6.1.13';
  # INDEX { cpqSsBackplaneChassisIndex, cpqSsBackplaneIndex }
  my  _æ_ indexes = SNMP::Utils::get_indices($snmpwalk,
      $cpqSsBackplaneEntry);
  foreach ( _æ_ indexes) {
    my($idx1, $idx2) = ($_->[0], $_->[1]);
    my $fw = SNMP::Utils::get_object($snmpwalk,
        $cpqSsBackplaneFWRev, $idx1, $idx2);
    my $model = SNMP::Utils::get_object($snmpwalk,
        $cpqSsBackplaneModel, $idx1, $idx2);
    my $serial = SNMP::Utils::get_object($snmpwalk,
        $cpqSsBackplaneSerialNumber, $idx1, $idx2);
    push( _æ_ serials, $serial);
    push( _æ_ models, $model);
    push( _æ_ fws, $fw);
  }
  
  $self->{serial} = join('/',  _æ_ serials);
  $self->{product} = join('/',  _æ_ models);
  $self->{romversion} = join('/',  _æ_ fws);
  $self->{runtime}->{product} = $self->{product};
}



















1;