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/Proliant/Component/NicSubsystem.pm
blob: 02e5703309066e1a406b086b7bdc8e138ebd6aec (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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
package HP::Proliant::Component::NicSubsystem;
our @ISA = qw(HP::Proliant::Component);

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

sub new {
  my $class = shift;
  my %params = @_;
  my $self = {
    runtime => $params{runtime},
    rawdata => $params{rawdata},
    method => $params{method},
    condition => $params{condition},
    status => $params{status},
    logical_nics => [],
    physical_nics => [],
    blacklisted => 0,
    info => undef,
    extendedinfo => undef,
  };
  bless $self, $class;
  if ($self->{method} eq 'snmp') {
    return HP::Proliant::Component::NicSubsystem::SNMP->new(%params);
  } elsif ($self->{method} eq 'cli') {
    return HP::Proliant::Component::NicSubsystem::CLI->new(%params);
  } else {
    die "unknown method";
  }
  return $self;
}

sub check {
  my $self = shift;
  my $errorfound = 0;
  $self->add_info('checking nic teams');
  if (scalar (@{$self->{logical_nics}}) == 0) {
    $self->add_info('no logical nics found');
    $self->overall_check();
  } else {
    foreach (@{$self->{logical_nics}}) {
      $_->check();
    }
  }
  if (scalar (@{$self->{physical_nics}}) == 0) {
    $self->add_info('no physical nics found. do you connect with slip?');
  } else {
    foreach (@{$self->{physical_nics}}) {
      $_->check();
    }
  }
}

sub num_logical_nics {
  my $self = shift;
  return scalar @{$self->{logical_nics}};
}

sub num_physical_nics {
  my $self = shift;
  return scalar @{$self->{physical_nics}};
}

sub dump {
  my $self = shift;
  foreach (@{$self->{logical_nics}}) {
    $_->dump();
  }
  foreach (@{$self->{physical_nics}}) {
    $_->dump();
  }
}

sub overall_check {
  my $self = shift;
  if ($self->{lognicstatus} ne "ok") {
    $self->add_info(sprintf 'overall logical nic status is %s',
        $self->{lognicstatus});
  }
}


package HP::Proliant::Component::NicSubsystem::LogicalNic;
our @ISA = qw(HP::Proliant::Component::NicSubsystem);

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

sub new {
  my $class = shift;
  my %params = @_;
  my $self = {
    runtime => $params{runtime},
    blacklisted => 0,
    info => undef,
    extendedinfo => undef,
  };
  foreach (qw(cpqNicIfLogMapIndex cpqNicIfLogMapIfNumber cpqNicIfLogMapDescription cpqNicIfLogMapGroupType cpqNicIfLogMapAdapterCount cpqNicIfLogMapAdapterOKCount cpqNicIfLogMapPhysicalAdapters cpqNicIfLogMapSwitchoverMode cpqNicIfLogMapCondition cpqNicIfLogMapStatus cpqNicIfLogMapNumSwitchovers cpqNicIfLogMapHwLocation cpqNicIfLogMapSpeed cpqNicIfLogMapVlanCount cpqNicIfLogMapVlans)) {
    $self->{$_} = $params{$_};
  }
  bless $self, $class;
  return $self;
}

sub check {
  my $self = shift;
  $self->blacklist('lni', $self->{cpqNicIfLogMapIndex});
  if ($self->{cpqNicIfLogMapAdapterCount} > 0) {
    if ($self->{cpqNicIfLogMapCondition} eq "other") {
      # simply ignore this. if there is a physical nic
      # it is usually unknown/other/scheissegal
      $self->add_info(sprintf "logical nic %d (%s) is %s",
          $self->{cpqNicIfLogMapIndex}, $self->{cpqNicIfLogMapDescription},
          $self->{cpqNicIfLogMapCondition});
    } elsif ($self->{cpqNicIfLogMapCondition} ne "ok") {
      $self->add_info(sprintf "logical nic %d (%s) is %s (%s)",
          $self->{cpqNicIfLogMapIndex}, $self->{cpqNicIfLogMapDescription},
          $self->{cpqNicIfLogMapCondition}, $self->{cpqNicIfLogMapStatus});
      $self->add_message(CRITICAL, $self->{info});
    } else {
      $self->add_info(sprintf "logical nic %d (%s) is %s",
          $self->{cpqNicIfLogMapIndex}, $self->{cpqNicIfLogMapDescription},
          $self->{cpqNicIfLogMapCondition});
    }
  } else {
    $self->add_info(sprintf "logical nic %d (%s) has 0 physical nics",
        $self->{cpqNicIfLogMapIndex}, $self->{cpqNicIfLogMapDescription});
  }
}

sub dump {
  my $self = shift;
  printf "[LNIC_%s]\n", $self->{cpqNicIfLogMapIndex};
  foreach (qw(cpqNicIfLogMapIndex cpqNicIfLogMapIfNumber cpqNicIfLogMapDescription cpqNicIfLogMapAdapterCount cpqNicIfLogMapGroupType cpqNicIfLogMapSwitchoverMode cpqNicIfLogMapCondition cpqNicIfLogMapStatus cpqNicIfLogMapNumSwitchovers cpqNicIfLogMapHwLocation cpqNicIfLogMapSpeed)) {
    printf "%s: %s\n", $_, $self->{$_};
  }
  printf "info: %s\n", $self->{info};
  printf "\n";
}


package HP::Proliant::Component::NicSubsystem::PhysicalNic;
our @ISA = qw(HP::Proliant::Component::NicSubsystem);

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

sub new {
  my $class = shift;
  my %params = @_;
  my $self = {
    runtime => $params{runtime},
    blacklisted => 0,
    info => undef,
    extendedinfo => undef,
  };
  foreach (qw(cpqNicIfPhysAdapterIndex cpqNicIfPhysAdapterIfNumber cpqNicIfPhysAdapterRole cpqNicIfPhysAdapterDuplexState cpqNicIfPhysAdapterCondition cpqNicIfPhysAdapterState cpqNicIfPhysAdapterStatus cpqNicIfPhysAdapterBadTransmits cpqNicIfPhysAdapterBadReceives)) {
    $self->{$_} = $params{$_};
  }
  bless $self, $class;
  return $self;
}

sub check {
  my $self = shift;
  $self->blacklist('pni', $self->{cpqNicIfPhysAdapterIndex});
  if ($self->{cpqNicIfPhysAdapterCondition} eq "other") {
    # hp doesnt output a clear status. i am optimistic, unknown/other
    # means "dont care"
    $self->add_info(sprintf "physical nic %d (%s) is %s",
        $self->{cpqNicIfPhysAdapterIndex}, $self->{cpqNicIfPhysAdapterRole},
        $self->{cpqNicIfPhysAdapterCondition});
  } elsif ($self->{cpqNicIfPhysAdapterCondition} ne "ok") {
    $self->add_info(sprintf "physical nic %d (%s) is %s (%s,%s)",
        $self->{cpqNicIfPhysAdapterIndex}, $self->{cpqNicIfPhysAdapterRole},
        $self->{cpqNicIfPhysAdapterCondition},
        $self->{cpqNicIfPhysAdapterState}, $self->{cpqNicIfPhysAdapterStatus});
    $self->add_message(CRITICAL, $self->{info});
  } else {
    if ($self->{cpqNicIfPhysAdapterDuplexState} ne "full") {
      $self->add_info(sprintf "physical nic %d (%s) is %s duplex",
          $self->{cpqNicIfPhysAdapterIndex}, $self->{cpqNicIfPhysAdapterRole},
          $self->{cpqNicIfPhysAdapterDuplexState});
    } else {
      $self->add_info(sprintf "physical nic %d (%s) is %s",
          $self->{cpqNicIfPhysAdapterIndex}, $self->{cpqNicIfPhysAdapterRole},
          $self->{cpqNicIfPhysAdapterCondition});
    }
  }
}

sub dump {
  my $self = shift;
  printf "[PNIC_%s]\n", $self->{cpqNicIfPhysAdapterIndex};
  foreach (qw(cpqNicIfPhysAdapterIndex cpqNicIfPhysAdapterIfNumber cpqNicIfPhysAdapterRole cpqNicIfPhysAdapterDuplexState cpqNicIfPhysAdapterCondition cpqNicIfPhysAdapterState cpqNicIfPhysAdapterStatus cpqNicIfPhysAdapterBadTransmits cpqNicIfPhysAdapterBadReceives)) {
    printf "%s: %s\n", $_, $self->{$_};
  }
  printf "info: %s\n", $self->{info};
  printf "\n";
}