2 do 'smart-status-lib.pl';
4 # status_monitor_list()
5 # Just one type is supported
6 sub status_monitor_list
8 if (&has_command($config{'smartctl'})) {
9 return ( [ "smart", $text{'monitor_type'} ] );
16 # status_monitor_status(type, &monitor, from-ui)
17 # Check the drive status
18 sub status_monitor_status
20 local @drives = &list_smart_disks_partitions();
21 local ($d) = grep { ($_->{'device'} eq $_[1]->{'drive'} ||
22 $_->{'id'} eq $_[1]->{'drive'}) &&
23 $_->{'subdisk'} eq $_[1]->{'subdisk'} } @drives;
27 'desc' => $text{'monitor_nosuch'} };
29 local $st = &get_drive_status($d->{'device'}, $d);
31 # Record number of errors since last time
33 local $errors_file = "$module_config_directory/last-errors";
34 &read_file($errors_file, \%errors);
35 local %lasterrors = %errors;
36 $errors{$_[1]->{'drive'}} = $st->{'errors'};
37 &write_file($errors_file, \%errors);
39 if (!$st->{'support'} || !$st->{'enabled'}) {
40 # SMART not enabled on device
42 'desc' => $text{'monitor_nosmart'} };
44 elsif (!$st->{'check'}) {
48 elsif ($st->{'errors'} && $_[1]->{'errors'} == 1) {
49 # Errors found, and failing on any errors
51 'desc' => &text('monitor_errorsfound', $st->{'errors'}) };
53 elsif ($st->{'errors'} && $_[1]->{'errors'} == 2 &&
54 $st->{'errors'} > $lasterrors{$_[1]->{'drive'}}) {
55 # Errors found and have increased
57 'desc' => &text('monitor_errorsinced', $st->{'errors'},
58 $lasterrors{$_[1]->{'drive'}}) };
66 # status_monitor_dialog(type, &monitor)
67 # Return form for selecting a drive
68 sub status_monitor_dialog
71 local @drives = &list_smart_disks_partitions();
72 local ($inlist) = grep { ($_->{'device'} eq $_[1]->{'drive'} ||
73 $_->{'id'} eq $_[1]->{'drive'}) &&
74 $_->{'subdisk'} eq $_[1]->{'subdisk'} } @drives;
75 $inlist = 1 if (!$_[1]->{'drive'});
76 $rv .= &ui_table_row($text{'monitor_drive'},
78 !$_[1]->{'drive'} ? $drives[0]->{'device'} :
79 $inlist ? ($inlist->{'id'} || $inlist->{'device'}).':'.
80 $inlist->{'subdisk'} :
82 [ (map { [ ($_->{'id'} || $_->{'device'}).':'.$_->{'subdisk'},
83 $_->{'desc'}.($_->{'model'} ?
84 " ($_->{'model'})" : "") ] } @drives),
85 [ "", $text{'monitor_other'} ] ]).
86 &ui_textbox("other", $inlist ? "" : $_[1]->{'drive'}, 15), 3);
88 $rv .= &ui_table_row($text{'monitor_errors'},
89 &ui_radio("errors", $_[1]->{'errors'} || 0,
90 [ [ 1, $text{'yes'} ], [ 0, $text{'no'} ],
91 [ 2, $text{'monitor_errorsinc'} ] ]));
95 # status_monitor_parse(type, &monitor, &in)
96 # Parse form for selecting a rule
97 sub status_monitor_parse
99 if ($_[2]->{'drive'}) {
100 ($_[1]->{'drive'}, $_[1]->{'subdisk'}) = split(/:/, $_[2]->{'drive'});
103 $_[1]->{'drive'} = $_[2]->{'other'};
104 $_[1]->{'subdisk'} = undef;
105 $_[1]->{'drive'} =~ /^\S+$/ || &error($text{'monitor_edrive'});
107 $_[1]->{'errors'} = $_[2]->{'errors'};