\n \n ";
+ print $q->start_table ({-CLASS => "sme-border", width=>"700"});
+ print $q->Tr(
+ esmith::cgi::genSmallCell($q, $self->localise('STATUS'),"header"),
+ esmith::cgi::genSmallCell($q, $self->localise('RAID'),"header"),
+ esmith::cgi::genSmallCell($q, $self->localise('DEVICECOUNT'),"header"),
+ esmith::cgi::genSmallCell($q, $self->localise('ACTIVEDEVICES'),"header"),
+ esmith::cgi::genSmallCell($q, $self->localise('FAILDDEVICES'),"header"),
+ esmith::cgi::genSmallCell($q, $self->localise('SPAREDEVICES'),"header"));
+
+ ##Start to check linux raid status
+ my $Raidcheck = `/bin/cat /proc/mdstat`;
+ if ( $Raidcheck =~ "raid"){
+
+ my $file = "/proc/mdstat";
+ my $device = "all";
+
+ # Get command line options.
+ GetOptions ('file=s' => \$file,
+ 'device=s' => \$device,
+ 'help' => sub { &usage() } );
+
+ ## Strip leading "/dev/" from --device in case it has been given
+ $device =~ s/^\/dev\///;
+
+ ## Return codes for Nagios
+ my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
+
+ ## This is a global return value - set to the worst result we get overall
+ my $retval = 0;
+
+ my (%active_devs, %failed_devs, %spare_devs);
+
+ open FILE, "< $file" or die "Can't open $file : $!";
+ while () {
+ next if ! /^(md\d+)+\s*:/;
+ next if $device ne "all" and $device ne $1;
+ my $dev = $1;
+ my @array = split(/ /);
+ for $_ (@array) {
+ next if ! /(\w+)\[\d+\](\(.\))*/;
+ if (defined $2){
+ if ($2 eq "(F)") {
+ $failed_devs{$dev} .= "$1,";
+ }
+ elsif ($2 eq "(S)") {
+ $spare_devs{$dev} .= "$1,";
+ }}
+ else {
+ $active_devs{$dev} .= "$1,";
+ }
+ }
+ if (! defined($active_devs{$dev})) { $active_devs{$dev} = "none"; }
+ else { $active_devs{$dev} =~ s/,$//; }
+ if (! defined($spare_devs{$dev})) { $spare_devs{$dev} = "none"; }
+ else { $spare_devs{$dev} =~ s/,$//; }
+ if (! defined($failed_devs{$dev})) { $failed_devs{$dev} = "none"; }
+ else { $failed_devs{$dev} =~ s/,$//; }
+ $_ = ;
+ /\[(\d+)\/(\d+)\]\s+\[(.*)\]$/;
+ my $devs_total = $1;
+ my $devs_up = $2;
+ my $stat = $3;
+ my $result = "OK";
+ if ($devs_total > $devs_up or $failed_devs{$dev} ne "none") {
+ $result = "CRITICAL";
+ $retval = $ERRORS{"CRITICAL"};
+ }
+ my $active=$active_devs{$dev};
+ my $failed=$failed_devs{$dev};
+ my $spare=$spare_devs{$dev};
+ my @raidstatus = "$result - $dev [$stat] has $devs_up of $devs_total devices active (active=$active_devs{$dev} failed=$failed_devs{$dev} spare=$spare_devs{$dev})\n";
+ foreach my $raid (@raidstatus)
+ {
+ if ( $raid =~ ("CRITICAL" && "failed=none") ){
+ if ( $raid =~ "CRITICAL" ){
+ print $q->Tr(
+ $q->td({class=>"sme-border-center", bgcolor=>"orange", align=>"center", width=>"60"}, $result),
+ $q->td({class=>"sme-border-center", width=>"100"}, $dev . " [ " . $stat . " ]"),
+ $q->td({class=>"sme-border-center"}, $devs_up),
+ $q->td({class=>"sme-border-center"}, $active),
+ $q->td({class=>"sme-border-center"}, $failed),
+ $q->td({class=>"sme-border-center"}, $spare),
+ );
+ }
+ else
+ {
+ print $q->Tr(
+ $q->td({class=>"sme-border-center", bgcolor=>"#32CD32", align=>"center", width=>"60"}, $result),
+ $q->td({class=>"sme-border-center", width=>"100"}, $dev . " [ " . $stat . " ]"),
+ $q->td({class=>"sme-border-center"}, $devs_up),
+ $q->td({class=>"sme-border-center"}, $active),
+ $q->td({class=>"sme-border-center"}, $failed),
+ $q->td({class=>"sme-border-center"}, $spare),
+ );
+ }
+ }
+ elsif ( $raid =~ ("CRITICAL" && "_") ){
+ if ( $raid =~ "CRITICAL" ){
+ print $q->Tr(
+ $q->td({class=>"sme-border-center", bgcolor=>"red", align=>"center", width=>"60"}, $result),
+ $q->td({class=>"sme-border-center", width=>"100"}, $dev . " [ " . $stat . " ]"),
+ $q->td({class=>"sme-border-center"}, $devs_up),
+ $q->td({class=>"sme-border-center"}, $active),
+ $q->td({class=>"sme-border-center"}, $failed),
+ $q->td({class=>"sme-border-center"}, $spare),
+ );
+ }
+ else
+ {
+ print $q->Tr(
+ $q->td({class=>"sme-border-center", bgcolor=>"#32CD32", align=>"center", width=>"60"}, $result),
+ $q->td({class=>"sme-border-center", width=>"100"}, $dev . " [ " . $stat . " ]"),
+ $q->td({class=>"sme-border-center"}, $devs_up),
+ $q->td({class=>"sme-border-center"}, $active),
+ $q->td({class=>"sme-border-center"}, $failed),
+ $q->td({class=>"sme-border-center"}, $spare),
+ );
+ }
+ }
+ }
+ }
+ print $q->end_table;
+ print "
\n";
+
+ print $q->start_table ({-CLASS => "sme-border", width=>"700"});
+ print $q->Tr(
+ $q->td({class=>"sme-border", bgcolor=>"#32CD32", align=>"center", width=>"60"}),
+ $q->td({class=>"sme-border"}, $self->localise('DESCRIPTIONGREEN')),
+ );
+ print $q->Tr(
+ $q->td({class=>"sme-border", bgcolor=>"orange", align=>"center", width=>"60"}),
+ $q->td({class=>"sme-border"}, $self->localise('DESCRIPTIONORANGE')),
+ );
+ print $q->Tr(
+ $q->td({class=>"sme-border", bgcolor=>"red", align=>"center", width=>"60"}),
+ $q->td({class=>"sme-border"}, $self->localise('DESCRIPTIONRED')),
+ );
+ print $q->end_table;
+ print "
\n";
+
+ }
+ else
+ {
+ print $q->h3 ($self->localise('NORAID'));
+ print $q->end_table;
+ }
+ return "";
+}
+
+ ##this routine is to save the properties
+ sub apply {
+ my ($self) = @_;
+ my $q = $self->{cgi};
+ $configdb->set_prop('raidstatus', 'mailto', $q->param("mailto"));
+
+ return $self->success('SUCCESS','First');
+ }
+1;
+
diff --git a/smeserver-raidstatus.spec b/smeserver-raidstatus.spec
new file mode 100644
index 0000000..5187c61
--- /dev/null
+++ b/smeserver-raidstatus.spec
@@ -0,0 +1,75 @@
+Summary: SME server Raidstatus
+%define name smeserver-raidstatus
+Name: %{name}
+%define version 0.3
+%define release 4
+Version: %{version}
+Release: %{release}%{?dist}
+License: SWT
+Group: Administration
+Source: %{name}-%{version}.tar.xz
+Packager: Walter Thoss
+BuildRoot: /var/tmp/e-smith-buildroot
+BuildRequires: e-smith-devtools
+BuildArchitectures: noarch
+Requires: e-smith-release >= 10.0
+Provides: perl(esmith::FormMagick::Panel::raidstatus)
+AutoReqProv: no
+
+%changelog
+* Sat Sep 07 2024 cvs2git.sh aka Brian Read 0.3-4.sme
+- Roll up patches and move to git repo [SME: 12338]
+
+* Sat Sep 07 2024 BogusDateBot
+- Eliminated rpmbuild "bogus date" warnings due to inconsistent weekday,
+ by assuming the date is correct and changing the weekday.
+
+* Fri Nov 11 2022 Jean-Philippe Pialasse 0.3-3.sme
+- apply locale 2022-11-11 patch
+
+* Thu Aug 04 2022 Jean-Philippe Pialasse 0.3-2.sme
+- import to SME 10
+
+* Thu Aug 14 2014 Stephane de Labrusse 0.3-1
+- Added 'mailto' db setting in the server-manager panel
+
+* Thu Jun 05 2014 Stephane de Labrusse 0.2-1
+- unitialised value $2
+* Sat Mar 15 2014 Stephane de Labrusse 0.1.8
+- a great big thank to walter who have made the new design and corrected a bug i made
+- back of my weekly mail status
+* Mon Feb 24 2014 Walter Thoss 0.1.6
+- design and change to smeserver standard
+* Wed Feb 05 2014 Stephane de Labrusse 0.1
+- First release
+
+%description
+Display raid status in server-manager
+
+%prep
+%setup
+mkdir -p root/etc/e-smith/events/smeserver-raidstatus-update
+
+%build
+perl createlinks
+
+%install
+rm -rf $RPM_BUILD_ROOT
+(cd root ; find . -depth -print | cpio -dump $RPM_BUILD_ROOT)
+rm -f %{name}-%{version}-filelist
+/sbin/e-smith/genfilelist $RPM_BUILD_ROOT > %{name}-%{version}-filelist
+
+
+%clean
+rm -rf $RPM_BUILD_ROOT
+
+%pre
+
+%preun
+
+%post
+
+%postun
+
+%files -f %{name}-%{version}-filelist
+%defattr(-,root,root)
|