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/BatterySubsystem.pm
blob: 82da78daf5833526774f6cf18d12b78dd40fcfc2 (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
package HP::Proliant::Component::BatterySubsystem;
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},
    sysbatteries => [],
    blacklisted => 0,
    info => undef,
    extendedinfo => undef,
  };
  bless $self, $class;
  if ($self->{method} eq 'snmp') {
    return HP::Proliant::Component::BatterySubsystem::SNMP->new(%params);
  } elsif ($self->{method} eq 'cli') {
    #return HP::Proliant::Component::BatterySubsystem::CLI->new(%params);
  } else {
    die "unknown method";
  }
  return $self;
}

sub check {
  my $self = shift;
  my $errorfound = 0;
  $self->add_info('checking sysbatteries');
  if (scalar (@{$self->{sysbatteries}}) == 0) {
    #$self->overall_check(); 
    $self->add_info('no sysbatteries found');
  } else {
    foreach (sort { $a->{cpqHeSysBatteryIndex} <=> $b->{cpqHeSysBatteryIndex}}
        @{$self->{sysbatteries}}) {
      $_->check();
    }
  }
}

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


package HP::Proliant::Component::BatterySubsystem::Battery;
our @ISA = qw(HP::Proliant::Component::BatterySubsystem);

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

sub new {
  my $class = shift;
  my %params = @_;
  my $self = {
    runtime => $params{runtime},
    cpqHeSysBatteryChassis => $params{cpqHeSysBatteryChassis},
    cpqHeSysBatteryIndex => $params{cpqHeSysBatteryIndex},
    cpqHeSysBatteryPresent => $params{cpqHeSysBatteryPresent},
    cpqHeSysBatteryCondition => $params{cpqHeSysBatteryCondition},
    cpqHeSysBatteryStatus => $params{cpqHeSysBatteryStatus},
    cpqHeSysBatteryCapacityMaximum => $params{cpqHeSysBatteryCapacityMaximum},
    cpqHeSysBatteryProductName => $params{cpqHeSysBatteryProductName},
    cpqHeSysBatteryModel => $params{cpqHeSysBatteryModel},
    cpqHeSysBatterySerialNumber => $params{cpqHeSysBatterySerialNumber},
    cpqHeSysBatteryFirmwareRev => $params{cpqHeSysBatteryFirmwareRev},
    cpqHeSysBatterySparePartNum => $params{cpqHeSysBatterySparePartNum},
    blacklisted => 0,
    info => undef,
    extendedinfo => undef,
  };
  $self->{name} = $params{name} ||
      $self->{cpqHeSysBatteryChassis}.':'.$self->{cpqHeSysBatteryIndex};
  bless $self, $class;
  return $self;
}

sub check {
  my $self = shift;
  $self->blacklist('sba', $self->{name});
  my $info = sprintf "battery %s/%s has condition %s and status %s",
      $self->{cpqHeSysBatteryChassis},
      $self->{cpqHeSysBatteryIndex},
      $self->{cpqHeSysBatteryCondition},
      $self->{cpqHeSysBatteryStatus};
  if ($self->{cpqHeSysBatteryCondition} eq "ok") {
  } elsif ($self->{cpqHeSysBatteryCondition} eq "degraded") {
    $self->add_info($info);
    $self->add_message(WARNING, $self->{info});
  } elsif ($self->{cpqHeSysBatteryCondition} eq "failed") {
    $self->add_info($info);
    $self->add_message(CRITICAL, $self->{info});
  } else {
    $self->add_info($info);
    $self->add_message(UNKNOWN, $self->{info});
  }
}

sub dump { 
  my $self = shift;
  printf "[SYSBATTERY_%s_%s]\n", $self->{cpqHeSysBatteryChassis},
      $self->{cpqHeSysBatteryIndex};
  foreach (qw(cpqHeSysBatteryChassis cpqHeSysBatteryIndex
      cpqHeSysBatteryPresent cpqHeSysBatteryCondition cpqHeSysBatteryStatus
      cpqHeSysBatteryCapacityMaximum cpqHeSysBatteryProductName
      cpqHeSysBatteryModel cpqHeSysBatterySerialNumber
      cpqHeSysBatteryFirmwareRev cpqHeSysBatterySparePartNum)) {
    printf "%s: %s\n", $_, $self->{$_};
  }
  printf "info: %s\n\n", $self->{info};
}


1;