Debian Codegraph @

check_hpasm/src/plugins-scripts/HP/Proliant/Component/DiskSubsystem.pm

raw
1 package HP::Proliant::Component::DiskSubsystem;
2 our @ISA = qw(HP::Proliant::Component);
3
4 use strict;
5 use constant { OK => 0, WARNING => 1, CRITICAL => 2, UNKNOWN => 3 };
6
7 sub new {
8 my $class = shift;
9 my %params = @_;
10 my $self = {
11 runtime => $params{runtime},
12 rawdata => $params{rawdata},
13 method => $params{method},
14 da_subsystem => undef,
15 sas_da_subsystem => undef,
16 ide_da_subsystem => undef,
17 fca_da_subsystem => undef,
18 scsi_da_subsystem => undef,
19 condition => $params{condition},
20 blacklisted => 0,
21 };
22 bless $self, $class;
23 $self->init();
24 return $self;
25 }
26
27 sub init {
28 my $self = shift;
29 $self->{da_subsystem} = HP::Proliant::Component::DiskSubsystem::Da->new(
30 runtime => $self->{runtime},
31 rawdata => $self->{rawdata},
32 method => $self->{method},
33 );
34 $self->{sas_subsystem} = HP::Proliant::Component::DiskSubsystem::Sas->new(
35 runtime => $self->{runtime},
36 rawdata => $self->{rawdata},
37 method => $self->{method},
38 );
39 $self->{scsi_subsystem} = HP::Proliant::Component::DiskSubsystem::Scsi->new(
40 runtime => $self->{runtime},
41 rawdata => $self->{rawdata},
42 method => $self->{method},
43 );
44 $self->{ide_subsystem} = HP::Proliant::Component::DiskSubsystem::Ide->new(
45 runtime => $self->{runtime},
46 rawdata => $self->{rawdata},
47 method => $self->{method},
48 );
49 $self->{fca_subsystem} = HP::Proliant::Component::DiskSubsystem::Fca->new(
50 runtime => $self->{runtime},
51 rawdata => $self->{rawdata},
52 method => $self->{method},
53 );
54 }
55
56 sub check {
57 my $self = shift;
58 $self->add_info('checking disk subsystem');
59 $self->{da_subsystem}->check();
60 $self->{sas_subsystem}->check();
61 $self->{scsi_subsystem}->check();
62 $self->{ide_subsystem}->check();
63 $self->{fca_subsystem}->check();
64 $self->disk_summary();
65 }
66
67 sub dump {
68 my $self = shift;
69 $self->{da_subsystem}->dump();
70 $self->{sas_subsystem}->dump();
71 $self->{scsi_subsystem}->dump();
72 $self->{ide_subsystem}->dump();
73 $self->{fca_subsystem}->dump();
74 }
75
76 sub disk_summary {
77 my $self = shift;
78 foreach my $subsys (qw(da sas scsi ide fca)) {
79 if (my $pd = $self->{$subsys.'_subsystem'}->has_physical_drives()) {
80 my $ld = $self->{$subsys.'_subsystem'}->has_logical_drives();
81 $self->add_summary(sprintf '%s: %d logical drives, %d physical drives',
82 $subsys, $ld, $pd);
83 }
84 }
85 }
86
87 sub assemble {
88 my $self = shift;
89 $self->trace(3, sprintf "%s controllers und platten zusammenfuehren",
90 ref($self));
91 $self->trace(3, sprintf "has %d controllers",
92 scalar(@{$self->{controllers}}));
93 $self->trace(3, sprintf "has %d accelerators",
94 scalar(@{$self->{accelerators}})) if exists $self->{accelerators};
95 $self->trace(3, sprintf "has %d enclosures",
96 scalar(@{$self->{enclosures}}));
97 $self->trace(3, sprintf "has %d physical_drives",
98 scalar(@{$self->{physical_drives}}));
99 $self->trace(3, sprintf "has %d logical_drives",
100 scalar(@{$self->{logical_drives}}));
101 $self->trace(3, sprintf "has %d spare_drives",
102 scalar(@{$self->{spare_drives}}));
103 my $found = {
104 accelerators => {},
105 enclosures => {},
106 logical_drives => {},
107 physical_drives => {},
108 spare_drives => {},
109 };
110 # found->{komponente}->{controllerindex} ist ein array
111 # von teilen, die zu einem controller gehoeren
112 foreach my $item (qw(accelerators enclosures logical_drives physical_drives spare_drives)) {
113 next if ($item eq "enclosures" && ! exists $self->{$item});
114 foreach (@{$self->{$item}}) {
115 $found->{item}->{$_->{controllerindex}} = []
116 unless exists $found->{$item}->{$_->{controllerindex}};
117 push(@{$found->{$item}->{$_->{controllerindex}}}, $_);
118 }
119 }
120 foreach my $item (qw(accelerators enclosures logical_drives physical_drives spare_drives)) {
121 foreach (@{$self->{controllers}}) {
122 if (exists $found->{$item}->{$_->{controllerindex}}) {
123 $_->{$item} = $found->{$item}->{$_->{controllerindex}};
124 delete $found->{$item}->{$_->{controllerindex}};
125 } else {
126 $_->{$item} = []; # z.b. ein leerer controller: physical_drives = []
127 }
128 }
129 }
130 # was jetzt noch in $found uebrig ist, gehoert zu keinem controller
131 # d.h. komponenten mit ungueltigen cnrtlindex wurden gefunden
132 }
133
134 sub has_controllers {
135 my $self = shift;
136 return scalar(@{$self->{controllers}});
137 }
138
139 sub has_accelerators {
140 my $self = shift;
141 return exists $self->{accelerators} ? scalar(@{$self->{accelerators}}) : 0;
142 }
143
144 sub has_physical_drives {
145 my $self = shift;
146 return scalar(@{$self->{physical_drives}});
147 }
148
149 sub has_logical_drives {
150 my $self = shift;
151 return scalar(@{$self->{logical_drives}});
152 }
153
154 sub has_enclosures {
155 my $self = shift;
156 return scalar(@{$self->{enclosures}});
157 }
158
159 1;