#!/usr/bin/perl use strict; use LWP::UserAgent; my $megaraid = 0; my $megaraid_sas = 0; my $threeware = 0; my $servername = `hostname`; my $serverip = `facter ipaddress`; my @output; # grab PCI list to detect type of RAID card my @pciinfo = split("\n", `/sbin/lspci`); $threeware = grep(/3ware\ Inc\ 7xxx\/8xxx/, @pciinfo); $megaraid = grep(/Symbios\ Logic\ MegaRAID\ \(rev\ [0-9]*\)/, @pciinfo); $megaraid_sas = grep(/Symbios\ Logic\ MegaRAID\ SAS/, @pciinfo); if ($threeware == 1) { &check_threeware; } elsif ($megaraid == 1) { &check_megaraid; } elsif ($megaraid_sas == 1) { &check_megaraidsas; } else { exit 0; } sub check_megaraidsas { @output = grep { /\S/ } split("\n", `/opt/MegaRAID/MegaCli/MegaCli -LDInfo -Lall -a0`); unless ( $output[5] =~ m/Optimal/ ) { &send_alert($servername, $serverip, @output); } } sub check_megaraid { @output = split("\n", `/usr/local/bin/megarc -ldInfo -a0 -Lall | tail -20`); if (grep(/DEGRADED/, @output) or grep(/OFFLINE/, @output)) { &send_alert($servername, $serverip, @output); } } sub check_threeware { @output = split("\n", `/usr/local/bin/tw_cli alarms`); if (grep(/ERROR/, @output)) { &send_alert($servername, $serverip, @output); } } sub send_alert { my $ua = LWP::UserAgent->new; my $url = "https://raidalarm.sysres.example.com/"; my $response = $ua->post("$url", [servername => "$servername", serverip => "$serverip", content => join("\n", @output), ], ); }