Handle hostnames with upper-case letters
[webmin.git] / status / raid-monitor.pl
1 # raid-monitor.pl
2 # Check if some RAID device is reporting errors
3
4 sub get_raid_status
5 {
6 return { 'up' => -1 } if (!&foreign_check("raid"));
7 &foreign_require("raid", "raid-lib.pl");
8 local $conf = &raid::get_raidtab();
9 local ($raid) = grep { $_->{'value'} eq $_[0]->{'device'} } @$conf;
10 if ($raid) {
11         if (ref($raid->{'errors'})) {
12                 local ($bad) = grep { $_ eq "_" } @{$raid->{'errors'}};
13                 if ($bad) {
14                         return { 'up' => 0,
15                                  'desc' => $text{'raid_bad'} };
16                         }
17                 else {
18                         return { 'up' => 1 };
19                         }
20                 }
21         elsif ($raid->{'resync'}) {
22                 return { 'up' => 0,
23                          'desc' => $text{'raid_resync'} };
24                 }
25         else {
26                 return { 'up' => 1 };
27                 }
28         }
29 else {
30         return { 'up' => -1,
31                  'desc' => &text('raid_notfound', $_[0]->{'device'}) };
32         }
33 }
34
35 sub show_raid_dialog
36 {
37 &foreign_require("raid", "raid-lib.pl");
38 local $conf = &raid::get_raidtab();
39 local @opts;
40 foreach my $c (@$conf) {
41         local $lvl = &raid::find_value('raid-level', $c->{'members'});
42         push(@opts, [ $c->{'value'},
43                       $c->{'value'}." - ".
44                       ($lvl eq 'linear' ? $raid::text{'linear'}
45                                         : $raid::text{"raid$lvl"}) ]);
46         }
47 local ($got) = grep { $_->[0] eq $_[0]->{'device'} } @opts;
48 if (!@opts) {
49         print &ui_table_row($text{'raid_device'},
50                             &ui_textbox("other", $_[0]->{'device'}, 10));
51         }
52 else {
53         push(@opts, [ "", $text{'raid_other'} ]);
54         print &ui_table_row($text{'raid_device'},
55                 &ui_select("device", !$_[0]->{'device'} ? $opts[0]->[0] :
56                                      !$got ? "" : $_[0]->{'device'}, \@opts).
57                 " ".&ui_textbox("other", $got ? "" : $_[0]->{'device'}, 10));
58         }
59 }
60
61 sub parse_raid_dialog
62 {
63 &depends_check($_[0], "raid");
64 $_[0]->{'device'} = $in{'device'} || $in{'other'};
65 $_[0]->{'device'} =~ /^\S+$/ || &error($text{'raid_edevice'});
66 }
67