Handle operating systems for which we don't have the fdisk module, like FreeBSD
authorJamie Cameron <jcameron@webmin.com>
Tue, 2 Jun 2009 00:59:36 +0000 (00:59 +0000)
committerJamie Cameron <jcameron@webmin.com>
Tue, 2 Jun 2009 00:59:36 +0000 (00:59 +0000)
smart-status/CHANGELOG
smart-status/module.info
smart-status/smart-status-lib.pl

index 962c0a0..c489406 100644 (file)
@@ -12,3 +12,4 @@ The SMART status monitor now has an option to only alert if the error count on a
 Improved support for 3ware and HP RAID devices, so that the underlying disks are now detected and can be reported on separately.
 ---- Changes since 1.470 ----
 Added support for systems with both old and new 3ware cards.
+Added support for FreeBSD and OSX systems, if they have the smartctl package installed.
index 87fd99f..bacfee5 100644 (file)
@@ -1,6 +1,5 @@
 desc=SMART Drive Status
-os_support=*-linux
-depends=fdisk
+os_support=*-linux freebsd macos
 category=hardware
 longdesc=Check the status of IDE drives to detect problems and potential failures.
 desc_sk=SMART stav diskov
index 8213312..cc9868f 100644 (file)
@@ -7,8 +7,6 @@ Functions for getting SMART status
 BEGIN { push(@INC, ".."); };
 use WebminCore;
 &init_config();
-&foreign_require("fdisk");
-
 =head2 get_smart_version()
 
 Returns the version number of the SMART tools on this system
@@ -28,11 +26,28 @@ return $smartctl_version_cache;
 =head2 list_smart_disks_partitions
 
 Returns a sorted list of disks that can support SMART.
-May include faked-up 3ware devices
 
 =cut
 sub list_smart_disks_partitions
 {
+if (&foreign_check("fdisk")) {
+       return &list_smart_disks_partitions_fdisk();
+       }
+elsif (&foreign_check("mount")) {
+       return &list_smart_disks_partitions_fstab();
+       }
+return ( );
+}
+
+=head2 list_smart_disks_partitions_fdisk
+
+Returns a sorted list of disks that can support SMART, using the Linux fdisk
+module. May include faked-up 3ware devices.
+
+=cut
+sub list_smart_disks_partitions_fdisk
+{
+&foreign_require("fdisk");
 local @rv;
 local %tcount = ( "/dev/twe", 0, "/dev/twa", 0 );
 foreach my $d (&fdisk::list_disks_partitions()) {
@@ -99,6 +114,41 @@ while(1) {
 return $count;
 }
 
+=head2 list_smart_disks_partitions_fstab
+
+Returns a list of disks on which we can use SMART, taken from /etc/fstab.
+
+=cut
+sub list_smart_disks_partitions_fstab
+{
+&foreign_require("mount");
+my @rv;
+foreach my $m (&mount::list_mounted(1)) {
+       if ($m->[1] =~ /^(\/dev\/(da|ad)[0-9])/ &&
+           $m->[2] ne 'cd9660') {
+               # FreeBSD-style disk name
+               push(@rv, { 'device' => $1,
+                           'desc' => $1 });
+               }
+       elsif ($m->[1] =~ /^(\/dev\/disk\d+)/ &&
+              ($m->[2] eq 'ufs' || $m->[2] eq 'hfs')) {
+               # MacOS disk name
+               push(@rv, { 'device' => $1,
+                           'desc' => $1 });
+               }
+       elsif ($m->[1] =~ /^(\/dev\/([hs])d([a-z]))/ &&
+              $m->[2] ne 'iso9660') {
+               # Linux disk name
+               push(@rv, { 'device' => $1,
+                           'desc' => ($2 eq 'h' ? 'IDE' : 'SCSI').
+                                     ' disk '.uc($3) });
+               }
+       }
+my %done;
+@rv = grep { !$done{$_->{'device'}}++ } @rv;
+return @rv;
+}
+
 =head2 get_drive_status(device-name, [&drive])
 
 Returns a hash reference containing the status of some drive