#!/usr/bin/perl ######## # # Alter these setting to suit your system $alert_script='/opt/asx_scripts/send_alert.pl'; $argument = 0; $argument = $ARGV[0]; $omreport = '/opt/dell/srvadmin/bin/omreport'; $omconfig = '/opt/dell/srvadmin/bin/omconfig'; $sendemail = '/opt/asx_scripts/sendEmail'; $toname = 'name'; $fromname = 'name'; $domain = 'domain.com'; $tmp_path = '/tmp'; $mail_gateway = 'ip or name of mailgate'; $unix2dos = '/usr/bin/unix2dos'; # # if("$argument" eq "setup"){ set_available_alerts(); exit; } if("$argument" eq "show"){ display_set_alerts(); exit; } if("$argument" eq "help"){ print "If you need some help read the code\n"; exit; } unless($argument){ $desc=`$omreport system alertlog 2>/dev/null | grep "Description" | head -1 | cut -f2-9 -d: | sed 's/ //'`; chomp($desc); $date=`$omreport system alertlog 2>/dev/null | grep "Date and Time" | head -1 | cut -f2-9 -d: | sed 's/ //g' | sed 's/://g'`; chomp($date); $host=`$omreport system summary 2>/dev/null | grep "Host Name" | head -1 | cut -f2-9 -d: | sed 's/ //'`; chomp($host); $tag=`$omreport system summary 2>/dev/null | grep "Chassis Service Tag" | head -1 | cut -f2-9 -d: | sed 's/ //'`; chomp($tag); $attach="$tmp_path/$date.log"; `$omreport system alertlog > "$attach"`; if( -f "$unix2dos"){ `$unix2dos "$attach" 2>/dev/null`; } $send=`$sendemail -f "$fromname\@$domain" -t "$toname\@$domain" -u "System Error: $host SvcTag: $tag Time: $date" -m "$host SvcTag: $tag Error: $desc Time: $date" -a "$attach" -s "$mail_gateway"`; }else{ print "If you need some help read the code\n"; exit; } sub set_available_alerts { $alert_list = `$omconfig system alertaction 2>/dev/null | cut -f2 -d"<" | cut -f1 -d">"`; chomp($alert_list); chomp($alert_list); @split_alert_list = split(/\|/, $alert_list); foreach my $alert (@split_alert_list){ $set_result = `$omconfig system alertaction event=$alert execappath="$alert_script" 2>/dev/null | head -1`; chomp($set_result); if("$set_result" eq "Alert action(s) configured successfully."){ print "Set Action:\t$alert\n"; }else{ print "ERROR Set didnt return expected value ($set_result)\n"; } } } sub display_set_alerts { $currently_set = `$omreport system alertaction`; print "$currently_set\n"; } exit;