Earlier this year I posted a script which sends email alerts from Dell servers using the alerting system built into Dell Openmanage. However, that script will only work on Windows systems.
A visitor to the blog called Steve has kindly posted some code on that post which enables the same functionality in Linux and I think it is worthy of its own post.
Before attempting to use the script you will need to download this perl script called sendEmail and that you have unix2dos installed.
The script accepts two arguments, which are setup or show.
“setup” will set the alerts action to the value of $alert_script which should be the full path to the script itself.
“show” will print the current alert settings for the system to the screen.
The code of the script is as follows, or you can download from here:
#!/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;
A good way to test the script is to temporarily set the “Temperature Maximum” to something low like 12 to trigger an alert.
Unfortunately all of my Linux machines are virtual machines so I cannot test or modify this script, so if anyone wants to give me SSH access to a server running OMSA, be my guest. 🙂
Again, big thanks to Steve for posting this and I am sure it will be useful to lots of people. This has also inspired me to make some improvements to my original Windows version.
Kamran says
Dear Paulie,
I read your both post but i m finding hard time to understand ur this post.. will u pls help me, i m really interesting to implement this script on my linux machines. i have some questions if u r intersting to answer those.
thanks in advanse
Marcus Bointon says
In recent Ubuntu releases (e.g. Lucid), unix2dos has changed name. You’ll find it in the ‘tofrodos’ package, and you can symlink it to the name this script is expecting like this:
ln -s /usr/bin/todos /usr/bin/unix2dos
Marcus Bointon says
There’s one small bug to fix in this script. There’s a $ missing from line 53, which should read:
$alert_list = `$omconfig system alertaction 2>/dev/null | cut -f2 -d””`;
Kamran says
Dear Marcus,
Did u try to run this script with linux sendmail utility rather than sendemail utility. Could u pls explain some of the initail steps to run this script, it would be very helpful for all user who read this post.
Kamran says
Hello,
I receive following messages when i run the script from my server after setting up the path. These messages displayed more than once.
[root@opt]# ./send_alert.pl setup
ERROR Set didnt return expected value ()
Steve says
Hi Kamran,
Alter this line
$unix2dos = ‘/usr/bin/unix2dos’;
To point at /usr/bin/todos like this
$unix2dos = ‘/usr/bin/todos’;
Please provide the output from these two commands.
/opt/dell/srvadmin/bin/omconfig alertaction
/opt/dell/srvadmin/bin/omconfig system alertaction event=powersupply execappath=”/opt/asx_scripts/send_alert.pl”
So that we can work out why you are getting ERROR Set didnt return expected value().
Also please provide your version of OMSA.
Marcus your right that line should have a $ infront of that variable.
$alert_list = `$omconfig system alertaction 2>/dev/null | cut -f2 -d””`;
Kamran says
Hello Steve,
I am using RHEL 4 Update 5 x86 and OMSA 6.2.. In this OS there is no file with name “todo” in /usr/bin/ but “unix2dos” is present there. The “omconfig” file location is /opt/dell/srvadmin/sbin/ and the command you mentioned to check is i think “/opt/dell/srvadmin/sbin/omconfig system alertaction” which displayed following message..
[root@cdb9i opt]# /opt/dell/srvadmin/sbin/omconfig system alertaction
Error! Command incomplete: event=
Also 2nd command which u mentioned displayed
[root@cdb9i opt]# /opt/dell/srvadmin/sbin/omconfig system alertaction event=powersupply execappath=./opt/send_alert.pl
Alert action(s) configured successfully.
I am also adding some of the lines of send_alert.pl
#!/usr/bin/perl
########
#
# Alter these setting to suit your system
$alert_script=’/opt/send_alert.pl’;
$argument = 0;
$argument = $ARGV[0];
$omreport = ‘/opt/dell/srvadmin/sbin/omreport’;
$omconfig = ‘/opt/dell/srvadmin/sbin/omconfig’;
$sendemail = ‘/usr/bin/sendEmail’;
$toname = ”;
$fromname = ”;
$domain = ”;
$tmp_path = ‘/tmp’;
$mail_gateway = ”;
$unix2dos = ‘/usr/bin/unix2dos’;
Now i hope this would explain some of the things… I m w8ing for the response. I m still receiving the same error messages when i run “setup” command with script.
Thanks..
Martins says
Please,
Sombody got to configure the mail sender in a LInux? I did the procedure on Windows Servers, but I didn’t understende the procedure on Linux.
Could you help me?
I have a lot of Red Hat servers.
Thanks
Martins
Kamran says
Well another issue.. 1st of all suddenly the script stop working on the server which i implemented on, i tried to reconfigure on same server but unable to do so.. so i implement the same script on anther machine where its mailing functionality is not working.. and on this new server i did not use setup command with the script as i was getting errors with this command which is not resolved yet.. please help me in this regard..
thanks..
Paulie says
Marcus/Steve – I have updated the code in the post to include the missing $ on line 53. Thanks
Kamran says
Hello all,
I am on the last stage as all the errors have been remove and now the setup command of the script is also working on another server and set all the alert actions, now when I am unplugging the power supply from the server it generate the logs in OMSA Log but I am unable to receive an email notification.. I have set all the parameters including domain name and getway in the script.. the sendEmail utility is working fine and I am also receiving mail when I run it standalone from the console but on any occurred event the script is not calling it and there is also no activity in “maillog” file… any help or guide line in this regard will be appreciated.
Kamran says
Dear Paulie..
I am still unable to receive mails from this script.. can any one plz help me. I am also confuse about this line
$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”`;
In which $send function or veriable not define, is this the reason that i am unable to receive mail?? plz plz help me…..
Steve says
In this line
the ` quotes tell perl to open a shell and execute the containing command
so
$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”`;
The standard output from
$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”
is stored inside the $send variable.
steve says
Hi,
Just a quick update on Kamran’s problems above, I’ve helped him work through them offline and he is using the original script with success.
I had some problems myself with OMSA 6.2 and found that running
/opt/dell/srvadmin/sbin/srvadmin-services.sh start
fixed up the issues i was having. I believe that kamran’s initial issues were due to OMSA not working correctly. Then his subsequent issue was that he had added debugging to the perl script that was causing some issues.
Specifically this command and result suggest’s that OMSA is not working correctly and the above command should be run.
[root@cdb9i opt]# /opt/dell/srvadmin/sbin/omconfig system alertaction
Error! Command incomplete: event=
If OMSA is working correctly then the result should look like this.
[root@cdb9i opt]# /opt/dell/srvadmin/sbin/omconfig system alertaction
The above command return something similar to below:
Error! Command incomplete: event=
This is how the script get’s a list of the available item’s to setup when setup is passed as switch.
steve says
In my above post it’s deleted some of the output during submitting.
Error! Command incomplete: event= powersupply|tempwarn|tempfail|fanwarn|fanfail|voltwarn|voltfail|systempowerwarn|systempowerfail|intrusion|redundegrad|redunlost|memprefail|memfail|powersupplywarn|hardwarelogwarn|hardwarelogfull|processorwarn|processorfail|watchdogasr|batterywarn|batteryfail|systempeakpower|removableflashmediapresent|removableflashmediaremoved|removableflashmediafail|storagesyswarn|storagesysfail|storagectrlwarn|storagectrlfail|pdiskwarn|pdiskfail|vdiskwarn|vdiskfail|enclosurewarn|enclosurefail|storagectrlbatterywarn|storagectrlbatteryfail
upen says
Perfect, thanks!
jb says
have the same problem as Kamran
getting the below error when run
./send_alert.pl setup
getting this error
ERROR Set didnt return expected value ()
ERROR Set didnt return expected value ()
ERROR Set didnt return expected value ()
ERROR Set didnt return expected value ()
ERROR Set didnt return expected value ()
ERROR Set didnt return expected value ()
please help
jb says
please ignore my post figure it out
jb says
Dear Paulie..
I am unable to receive mails from this script.. can any one plz help me.
John says
Thank you for the fantastic script – it works great, and totally meets our needs. Just one quick suggestion:
In testing the script, I tried your suggestion of changing the temperature maximum, however that triggered the server’s thermal shutdown protection, which resulted in the server shutting itself down, with no events sent.
A more harmless way to test the script is simply to pop open the case, which will trigger the chassis intrusion event.
Saman Behnam says
Hi there,
I have reworked the script to work with Bash-Shell under Linux.
########################################################################
cat /opt/dell/srvadmin/bin/omsendmail
#!/bin/bash
# By [email protected]
# Dell srvadmin Hardware Email Alert
# Chnage the mail recipinet variable to the user of your needs.
MAIL_RECIPIENT=”root”
HOST_LOCATION=”Hausverwaltung imogmbh MUC”
# You may not change these variables!
SCRIPTNAME=”omsendmail”
TEST_MAIL_CONTENT=”Testing Dell hardware alert warnings…”
HOST_NAME=”$(hostname)”
DEVNULL=”/dev/null”
show_help( ){
echo -e “”
echo -e “Please invoke like follows”
echo -e “”
echo ‘* ‘$SCRIPTNAME’ –option [“optional text”] *’
echo -e “”
echo -e “The following options are allowed: \”–enable [alert1 alert2|all]\” \”–disable [alert1 alert2|all]\””
echo -e ” \”–listalerts\” \”–mail [“mail content text”]\” \”–testmail\””
echo -e “”
echo -e “Explanation of the options:”
echo -e “”
echo -e ” 1) –enable [alert1 alert2|all]”
echo -e ” If \”–enable\” is specified then \”srvadmin\” is configured to send mail allerts on hardware issues.”
echo -e ” This must be done just once upon fresh installing or reinstalling the \”srvadmin\” software.”
echo -e ” Also if you change the name or the file system location of the \”$SCRIPTNAME\” script”
echo -e ” You can specify a single alert or a space separated list of alerts or \”all\” to enable mail”
echo -e ” notification for the specified alerts.”
echo -e ” To get a list of valid alerts please invoke \”$SCRIPTNAME –listalerts\””
echo -e “”
echo -e ” 2) –disable [alert1 alert2|all]”
echo -e ” If \”–disable\” is specified then specified alert is disabled and no mail notification.”
echo -e ” ist sent for the specified alert. You can specify a single alert or a space separated list”
echo -e ” of alerts or \”all\” to disable mail notification for the specified alerts.”
echo -e ” To get a list of valid alerts please invoke \”$SCRIPTNAME –listalerts\””
echo -e “”
echo -e ” 3) –listalerts”
echo -e ” If \”–listalerts\” is specified then a all supported \”srvadmin\” alerts on this system are listed.”
echo -e “”
echo -e ” 4) –mail [mail text]”
echo -e ” If \”–mail\” is specified then a mail is sent to the recipient secified in the \”MAIL_RECIPIENT\” variable.”
echo -e ” The content of the mail is specified in the string [\”mail text\”] following the \”–mail\” option.”
echo -e “”
echo -e ” 5) –testmail”
echo -e ” If \”–testmail\” is specified then a testmail with following content is sent:”
echo -e ” \”Testing Dell hardware alert warnings…\””
echo -e ” The \”–testmail\” can not take more arguments”
echo -e “”
}
send_alert_mail_and_log( ){
ALERT_MESSAGE=”$(echo $@|awk ‘{print substr($0, index($0,$2)) }’)”
echo -e “$ALERT_MESSAGE”|mail -s “Hardware alert of Server $HOST_NAME at $HOST_LOCATION” “$MAIL_RECIPIENT”
logger -t “$SCRIPTNAME” “$ALERT_MESSAGE”
}
send_test_mail_and_log( ){
echo -e “$TEST_MAIL_CONTENT”|mail -s “Hardware alert of Server $HOST_NAME at $HOST_LOCATION” “$MAIL_RECIPIENT”
logger -t “$SCRIPTNAME” “$TEST_MAIL_CONTENT”
}
list_supported_alerts( ){
omconfig system alertaction 2>”$DEVNULL”|cut -f2 -d””|sed ‘s/|/ /g’
}
get_alert_list( ){
# Check if alert is valid and build alert list
ALERT_LIST=”$(echo “$@”|awk ‘{print substr($0, index($0,$2)) }’)”
if [ “$ALERT_LIST” = all ] ; then
VALID_ALERT_LIST=$(list_supported_alerts)
else
for ALERT in $ALERT_LIST; do
if list_supported_alerts|grep -q $ALERT; then
VALID_ALERT_LIST=”$VALID_ALERT_LIST $ALERT”
else
echo -e “\n”
echo -e “The specified alert \””$ALERT”\” does not exist.”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
fi
done
fi
}
enable_alertmail( ){
get_alert_list “$@” || return 1
# Enable alert after user confirmation
echo “Warning! You are about to change your \”srvadmin\” software configuration.”
echo -e “\n”
echo “* Your original \”srvadmin\” configuration will be kept as is. *”
echo “* Additonally \”srvadmin\” will send mails on hardware alerts! *”
echo -e “\n”
echo “If you are shure you want to activate alert mails then”
echo “press\” yes \” , any other key to abort!”
read -n 4 CONFIRMATION
case “$CONFIRMATION” in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execappath=”$SCRIPTNAME –mail $VALID_ALERT” > “$DEVNULL” 2>&1; then
echo “Alert \”$VALID_ALERT\” configured successfully.”
logger -t “$SCRIPTNAME” “Alert \”$VALID_ALERT\” configured successfully.”
else
echo “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
logger -t “$SCRIPTNAME” “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
fi
done
;;
*)
echo -e “\n”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
;;
esac
}
disable_alertmail( ){
get_alert_list “$@” || return 1
# Disable alert after user confirmation
echo “Warning! You are about to change your \”srvadmin\” software configuration.”
echo -e “\n”
echo “* Your original \”srvadmin\” configuration will be kept as is. *”
echo “* Additonally \”srvadmin\” will stop sending mails on hardware alerts! *”
echo -e “\n”
echo “If you are shure you want to disable alert mails then”
echo “press\” yes \” , any other key to abort!”
read -n 4 CONFIRMATION
case $CONFIRMATION in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execapp=false > “$DEVNULL” 2>&1; then
#if omconfig system alertaction event=$VALID_ALERT clearall=true > “$DEVNULL” 2>&1; then
echo “Alert \”$VALID_ALERT\” disabled successfully.”
logger -t “$SCRIPTNAME” “Alert \”$VALID_ALERT\” disabled successfully.”
else
echo “Error! The specified alert \”$VALID_ALERT\” is not supported on this system.”
logger -t “$SCRIPTNAME” “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
fi
done
;;
*)
echo -e “\n”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
;;
esac
}
# here comes the main program
if [ -z $1 ] ; then
show_help
exit 1
else
ARG=(“$@”)
case “${ARG[0]}” in
–enable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
enable_alertmail “$@” || exit 1
fi
;;
–disable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
disable_alertmail “$@” || exit 1
fi
;;
–mail)
send_alert_mail_and_log
;;
–testmail)
if [ ! -z ${ARG[1]} ] ; then
show_help
exit 1
else
send_test_mail_and_log
fi
;;
–listalerts)
list_supported_alerts
;;
*)
show_help
exit 1
;;
esac
fi
########################################################################
have fun!
Saman Behnam says
Sorry I had an error in the first post, which would cause not sending mail content.
Here again.
– You can individually disable or enable mail alerts with this script
– Also you can list all supported alerts, to make it easy to disable or enable them individually
########################################################################
cat /opt/dell/srvadmin/bin/omsendmail
#!/bin/bash
# By [email protected]
# Dell srvadmin Hardware Email Alert
# Chnage the mail recipinet variable to the user of your needs.
MAIL_RECIPIENT=”root”
HOST_LOCATION=”Hausverwaltung imogmbh MUC”
# You may not change these variables!
SCRIPTNAME=”omsendmail”
TEST_MAIL_CONTENT=”Testing Dell hardware alert warnings…”
HOST_NAME=”$(hostname)”
DEVNULL=”/dev/null”
show_help( ){
echo -e “”
echo -e “Please invoke like follows”
echo -e “”
echo ‘* ‘$SCRIPTNAME’ –option [“optional text”] *’
echo -e “”
echo -e “The following options are allowed: \”–enable [alert1 alert2|all]\” \”–disable [alert1 alert2|all]\””
echo -e ” \”–listalerts\” \”–mail [“mail content text”]\” \”–testmail\””
echo -e “”
echo -e “Explanation of the options:”
echo -e “”
echo -e ” 1) –enable [alert1 alert2|all]”
echo -e ” If \”–enable\” is specified then \”srvadmin\” is configured to send mail allerts on hardware issues.”
echo -e ” This must be done just once upon fresh installing or reinstalling the \”srvadmin\” software.”
echo -e ” Also if you change the name or the file system location of the \”$SCRIPTNAME\” script”
echo -e ” You can specify a single alert or a space separated list of alerts or \”all\” to enable mail”
echo -e ” notification for the specified alerts.”
echo -e ” To get a list of valid alerts please invoke \”$SCRIPTNAME –listalerts\””
echo -e “”
echo -e ” 2) –disable [alert1 alert2|all]”
echo -e ” If \”–disable\” is specified then specified alert is disabled and no mail notification.”
echo -e ” ist sent for the specified alert. You can specify a single alert or a space separated list”
echo -e ” of alerts or \”all\” to disable mail notification for the specified alerts.”
echo -e ” To get a list of valid alerts please invoke \”$SCRIPTNAME –listalerts\””
echo -e “”
echo -e ” 3) –listalerts”
echo -e ” If \”–listalerts\” is specified then a all supported \”srvadmin\” alerts on this system are listed.”
echo -e “”
echo -e ” 4) –mail [mail text]”
echo -e ” If \”–mail\” is specified then a mail is sent to the recipient secified in the \”MAIL_RECIPIENT\” variable.”
echo -e ” The content of the mail is specified in the string [\”mail text\”] following the \”–mail\” option.”
echo -e “”
echo -e ” 5) –testmail”
echo -e ” If \”–testmail\” is specified then a testmail with following content is sent:”
echo -e ” \”Testing Dell hardware alert warnings…\””
echo -e ” The \”–testmail\” can not take more arguments”
echo -e “”
}
send_alert_mail_and_log( ){
ALERT_MESSAGE=”$(echo $@|awk ‘{print substr($0, index($0,$2)) }’)”
echo -e “$ALERT_MESSAGE”|mail -s “Hardware alert of Server $HOST_NAME at $HOST_LOCATION” “$MAIL_RECIPIENT”
logger -t “$SCRIPTNAME” “$ALERT_MESSAGE”
}
send_test_mail_and_log( ){
echo -e “$TEST_MAIL_CONTENT”|mail -s “Hardware alert of Server $HOST_NAME at $HOST_LOCATION” “$MAIL_RECIPIENT”
logger -t “$SCRIPTNAME” “$TEST_MAIL_CONTENT”
}
list_supported_alerts( ){
omconfig system alertaction 2>”$DEVNULL”|cut -f2 -d””|sed ‘s/|/ /g’
}
get_alert_list( ){
# Check if alert is valid and build alert list
ALERT_LIST=”$(echo “$@”|awk ‘{print substr($0, index($0,$2)) }’)”
if [ “$ALERT_LIST” = all ] ; then
VALID_ALERT_LIST=$(list_supported_alerts)
else
for ALERT in $ALERT_LIST; do
if list_supported_alerts|grep -q $ALERT; then
VALID_ALERT_LIST=”$VALID_ALERT_LIST $ALERT”
else
echo -e “\n”
echo -e “The specified alert \””$ALERT”\” does not exist.”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
fi
done
fi
}
enable_alertmail( ){
get_alert_list “$@” || return 1
# Enable alert after user confirmation
echo “Warning! You are about to change your \”srvadmin\” software configuration.”
echo -e “\n”
echo “* Your original \”srvadmin\” configuration will be kept as is. *”
echo “* Additonally \”srvadmin\” will send mails on hardware alerts! *”
echo -e “\n”
echo “If you are shure you want to activate alert mails then”
echo “press\” yes \” , any other key to abort!”
read -n 4 CONFIRMATION
case “$CONFIRMATION” in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execappath=”$SCRIPTNAME –mail $VALID_ALERT” > “$DEVNULL” 2>&1; then
echo “Alert \”$VALID_ALERT\” configured successfully.”
logger -t “$SCRIPTNAME” “Alert \”$VALID_ALERT\” configured successfully.”
else
echo “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
logger -t “$SCRIPTNAME” “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
fi
done
;;
*)
echo -e “\n”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
;;
esac
}
disable_alertmail( ){
get_alert_list “$@” || return 1
# Disable alert after user confirmation
echo “Warning! You are about to change your \”srvadmin\” software configuration.”
echo -e “\n”
echo “* Your original \”srvadmin\” configuration will be kept as is. *”
echo “* Additonally \”srvadmin\” will stop sending mails on hardware alerts! *”
echo -e “\n”
echo “If you are shure you want to disable alert mails then”
echo “press\” yes \” , any other key to abort!”
read -n 4 CONFIRMATION
case $CONFIRMATION in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execapp=false > “$DEVNULL” 2>&1; then
#if omconfig system alertaction event=$VALID_ALERT clearall=true > “$DEVNULL” 2>&1; then
echo “Alert \”$VALID_ALERT\” disabled successfully.”
logger -t “$SCRIPTNAME” “Alert \”$VALID_ALERT\” disabled successfully.”
else
echo “Error! The specified alert \”$VALID_ALERT\” is not supported on this system.”
logger -t “$SCRIPTNAME” “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
fi
done
;;
*)
echo -e “\n”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
;;
esac
}
# here comes the main program
if [ -z $1 ] ; then
show_help
exit 1
else
ARG=(“$@”)
case “${ARG[0]}” in
–enable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
enable_alertmail “$@” || exit 1
fi
;;
–disable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
disable_alertmail “$@” || exit 1
fi
;;
–mail)
send_alert_mail_and_log “$@”
;;
–testmail)
if [ ! -z ${ARG[1]} ] ; then
show_help
exit 1
else
send_test_mail_and_log
fi
;;
–listalerts)
list_supported_alerts
;;
*)
show_help
exit 1
;;
esac
fi
########################################################################
have fun!
David Downs says
Thank you very much, Saman Behnam, for the BASH conversion.
I found one issue with a missing cut (I think – though this site’s WordPress is converting quotes and greater than and less than symbols to “clean HTML”, so it may have been “eaten” – converting this all back after the copy and paste was “fun”.
I made a few other changes so I will post the whole thing again. Most are personal preferences, but the path handling is pretty important (otherwise people need to remember to run the script with the full path – an admin best practice, but often forgotten)
Let’s see if WordPress converts my quotes, et al.
#!/bin/bash
########################################################################
# /opt/dell/srvadmin/bin/omsendmail
# By [email protected]
# Dell srvadmin Hardware Email Alert
# Modified:
#
# 2011/10/16 – cut line needed additional cut to remove trailing ‘>’ when parsing avail alerts – DRD
# – the way the script finds its name and location since OMSA needs full path in alert config
# – changed message subject and a few typos
# – changed message to contain the full alert log
# Change the mail recipinet variable to the user of your needs.
MAIL_RECIPIENT=”root”
HOST_LOCATION=”Comp RM Rack 6 U15″
# You may not change these variables!
SCRIPTNAME=”`basename \”$0\”`”
TEST_MAIL_CONTENT=”Testing Dell hardware alert warnings…”
HOST_NAME=”$(hostname)”
DEVNULL=”/dev/null”
DEFAULT_OMSA_BIN=”/opt/dell/srvadmin/bin”
# Determine path to this script since OMSA requires full path, yet you may run it as ./SCRIPTNAME, etc.
SCRIPT_PATH=”${BASH_SOURCE[0]}”;
if ([ -h “${SCRIPT_PATH}” ]) then
while([ -h “${SCRIPT_PATH}” ]) do SCRIPT_PATH=`readlink “${SCRIPT_PATH}”`; done fi pushd . > /dev/null cd `dirname ${SCRIPT_PATH}` > /dev/null SCRIPT_PATH=`pwd`; popd > /dev/null # Thanks http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
# Overload SCRIPTNAME to full path
SCRIPTNAME=”$SCRIPT_PATH/$SCRIPTNAME”
# Verify we have the OMSA tools we use in our PATH env or the default location for TOOL in omconfig omreport; do if [ ! `which omconfig >/dev/null 2>&1` ]; then
if [ ! -x “$DEFAULT_OMSA_BIN/$TOOL” ]; then
echo $SCRIPTNAME ERROR: Cannot find executable Dell OMSA utilities in PATH or $DEFAULT_OMSA_BIN
exit 1
fi
# Add the default to the script path for use below
PATH=${PATH}:${DEFAULT_OMSA_BIN}
fi
done
show_help( ){
echo -e “”
echo -e “Please invoke like follows”
echo -e “”
echo ‘* ‘$SCRIPTNAME’ -option [“optional text”] *’
echo -e “”
echo -e “The following options are allowed: \”-enable [alert1 alert2|all]\” \”-disable [alert1 alert2|all]\””
echo -e ” \”-listalerts\” \”-mail [“mail content text”]\” \”-testmail\””
echo -e “”
echo -e “Explanation of the options:”
echo -e “”
echo -e ” 1) -enable [alert1 alert2|all]”
echo -e ” If \”-enable\” is specified then \”srvadmin\” is configured to send mail allerts on hardware issues.”
echo -e ” This must be done just once upon fresh installing or reinstalling the \”srvadmin\” software.”
echo -e ” Also if you change the name or the file system location of the \”$SCRIPTNAME\” script”
echo -e ” You can specify a single alert or a space separated list of alerts or \”all\” to enable mail”
echo -e ” notification for the specified alerts.”
echo -e ” To get a list of valid alerts please invoke \”$SCRIPTNAME -listalerts\””
echo -e “”
echo -e ” 2) -disable [alert1 alert2|all]”
echo -e ” If \”-disable\” is specified then specified alert is disabled and no mail notification.”
echo -e ” ist sent for the specified alert. You can specify a single alert or a space separated list”
echo -e ” of alerts or \”all\” to disable mail notification for the specified alerts.”
echo -e ” To get a list of valid alerts please invoke \”$SCRIPTNAME -listalerts\””
echo -e “”
echo -e ” 3) -listalerts”
echo -e ” If \”-listalerts\” is specified then a all supported \”srvadmin\” alerts on this system are listed.”
echo -e “”
echo -e ” 4) -mail [mail text]”
echo -e ” If \”-mail\” is specified then a mail is sent to the recipient secified in the \”MAIL_RECIPIENT\” variable.”
echo -e ” The content of the mail is specified in the string [\”mail text\”] following the \”-mail\” option.”
echo -e “”
echo -e ” 5) -testmail”
echo -e ” If \”-testmail\” is specified then a testmail with following content is sent:”
echo -e ” \”Testing Dell hardware alert warnings…\””
echo -e ” The \”-testmail\” can not take more arguments”
echo -e “”
}
send_alert_mail_and_log( ){
ALERT_MESSAGE=”$(echo $@|awk ‘{print substr($0, index($0,$2)) }’)”
omreport system alertlog|mail -s “Hardware alert on Host $HOST_NAME at $HOST_LOCATION” “$MAIL_RECIPIENT”
#echo -e “$ALERT_MESSAGE”|mail -s “Hardware alert of Server $HOST_NAME at $HOST_LOCATION” “$MAIL_RECIPIENT”
logger -t “$SCRIPTNAME” “$ALERT_MESSAGE”
}
send_test_mail_and_log( ){
echo -e “$TEST_MAIL_CONTENT”|mail -s “Hardware alert of Server $HOST_NAME at $HOST_LOCATION” “$MAIL_RECIPIENT”
logger -t “$SCRIPTNAME” “$TEST_MAIL_CONTENT”
}
list_supported_alerts( ){
omconfig system alertaction 2>”$DEVNULL”| cut -f2 -d” | sed ‘s/|/ /g’
}
get_alert_list( ){
# Check if alert is valid and build alert list
ALERT_LIST=”$(echo “$@”|awk ‘{print substr($0, index($0,$2)) }’)”
if [ “$ALERT_LIST” = all ] ; then
VALID_ALERT_LIST=$(list_supported_alerts)
else
for ALERT in $ALERT_LIST; do
if list_supported_alerts|grep -q $ALERT; then
VALID_ALERT_LIST=”$VALID_ALERT_LIST $ALERT”
else
echo -e “\n”
echo -e “The specified alert \””$ALERT”\” does not exist.”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
fi
done
fi
}
enable_alertmail( ){
get_alert_list “$@” || return 1
# Enable alert after user confirmation
echo “Warning! You are about to change your \”srvadmin\” software configuration.”
echo -e “\n”
echo “* Your original \”srvadmin\” configuration will be kept as is. *”
echo “* Additonally \”srvadmin\” will send mails on hardware alerts! *”
echo -e “\n”
echo “If you are sure you want to activate alert e-mails then”
echo “type \”yes\”, any other key to abort!”
read -n 4 CONFIRMATION
case “$CONFIRMATION” in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execappath=”$SCRIPTNAME -mail $VALID_ALERT” > “$DEVNULL” 2>&1; then
echo “Alert \”$VALID_ALERT\” configured successfully.”
logger -t “$SCRIPTNAME” “Alert \”$VALID_ALERT\” configured successfully.”
else
echo “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
logger -t “$SCRIPTNAME” “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
fi
done
;;
*)
echo -e “\n”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
;;
esac
}
disable_alertmail( ){
get_alert_list “$@” || return 1
# Disable alert after user confirmation
echo “Warning! You are about to change your \”srvadmin\” software configuration.”
echo -e “\n”
echo “* Your original \”srvadmin\” configuration will be kept as is. *”
echo “* Additonally \”srvadmin\” will stop sending mails on hardware alerts! *”
echo -e “\n”
echo “If you are shure you want to disable alert mails then”
echo “press\” yes \” , any other key to abort!”
read -n 4 CONFIRMATION
case $CONFIRMATION in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execapp=false > “$DEVNULL” 2>&1; then
#if omconfig system alertaction event=$VALID_ALERT clearall=true > “$DEVNULL” 2>&1; then
echo “Alert \”$VALID_ALERT\” disabled successfully.”
logger -t “$SCRIPTNAME” “Alert \”$VALID_ALERT\” disabled successfully.”
else
echo “Error! The specified alert \”$VALID_ALERT\” is not supported on this system.”
logger -t “$SCRIPTNAME” “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
fi
done
;;
*)
echo -e “\n”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
;;
esac
}
# here comes the main program
if [ -z $1 ] ; then
show_help
exit 1
else
ARG=(“$@”)
case “${ARG[0]}” in
-enable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
enable_alertmail “$@” || exit 1
fi
;;
-disable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
disable_alertmail “$@” || exit 1
fi
;;
-mail)
send_alert_mail_and_log “$@”
;;
-testmail)
if [ ! -z ${ARG[1]} ] ; then
show_help
exit 1
else
send_test_mail_and_log
fi
;;
-listalerts)
list_supported_alerts
;;
*)
show_help
exit 1
;;
esac
fi
########################################################################
error 651 says
I will right away take hold of your rss feed as I can not in finding your e-mail subscription link or e-newsletter service. Do you’ve any? Please permit me understand in order that I could subscribe. Thanks.
Brian says
Paulie,
I think that everything is configured correctly – however when testing by pulling out a power supply I do not recieve an email alert. I am very much a linux newbie so any help you could offer would be appreciated.
The setup and show commands list all of the correct information.
Thanks in advance for any help,
Brian
Paul says
This perl script works great. I have one issue – I get double emails for every alert. Any ideas?
Brian says
Paul,
I cannot get the email alert to fire – it works if I run it manually. Getting 2 alerts would be better 🙂
Brian
Rolf says
Just spent a lot of time getting the bash version to work.
#!/bin/bash
########################################################################
# /opt/dell/srvadmin/bin/omsendmail
# By [email protected]
# Dell srvadmin Hardware Email Alert
# Modified:
#
# 2011/10/16 – cut line needed additional cut to remove trailing `>` when parsing avail alerts – DRD
# – the way the script finds its name and location since OMSA needs full path in alert config
# – changed message subject and a few typos
# – changed message to contain the full alert log
# somewhat more informational subject line in email
# modified to work under ubuntu precise (had to fix broken formatting from copying from web page)
# Change the mail recipinet variable to the user of your needs.
MAIL_RECIPIENT=”youremail@yourdomain”
HOST_LOCATION=”Earth”
# You may not change these variables!
SCRIPTNAME=”`basename \”$0\”`”
TEST_MAIL_CONTENT=”Testing Dell hardware alert warnings…”
HOST_NAME=”$(hostname -f)”
DEVNULL=”/dev/null”
DEFAULT_OMSA_BIN=”/opt/dell/srvadmin/bin”
# Determine path to this script since OMSA requires full path, yet you may run it as ./SCRIPTNAME, etc.
SCRIPT_PATH=”${BASH_SOURCE[0]}”;
if ([ -h “${SCRIPT_PATH}” ]) then
while([ -h “${SCRIPT_PATH}” ]) do SCRIPT_PATH=`readlink “${SCRIPT_PATH}”`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`; popd > /dev/null
# Thanks http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
# Overload SCRIPTNAME to full path
SCRIPTNAME=”$SCRIPT_PATH/$SCRIPTNAME”
# Verify we have the OMSA tools we use in our PATH env or the default location
for TOOL in omconfig omreport; do
if [ ! `which omconfig >/dev/null 2>&1` ]; then
if [ ! -x “$DEFAULT_OMSA_BIN/$TOOL” ]; then
echo “$SCRIPTNAME ERROR: Cannot find executable Dell OMSA utilities in PATH or $DEFAULT_OMSA_BIN”
exit 1
fi
# Add the default to the script path for use below
PATH=${PATH}:${DEFAULT_OMSA_BIN}
fi
done
show_help( ){
echo -e ” ”
echo -e “Please invoke like follows”
echo -e ” ”
echo -e “* “$SCRIPTNAME” -option [\”optional text\”] *”
echo -e ” ”
echo -e “The following options are allowed: \”–enable [alert1 alert2|all]\” \”–disable [alert1 alert2|all]\””
echo -e ” \”-listalerts\” \”-mail [\”mail content text\”]\” \”-testmail\””
echo -e ” ”
echo -e “Explanation of the options:”
echo -e ” ”
echo -e ” 1) -enable [alert1 alert2|all]”
echo -e ” If \”-enable\” is specified then \”srvadmin\” is configured to send mail allerts on hardware issues.”
echo -e ” This must be done just once upon fresh installing or reinstalling the \”srvadmin\” software.”
echo -e ” Also if you change the name or the file system location of the \”$SCRIPTNAME\” script”
echo -e ” You can specify a single alert or a space separated list of alerts or \”all\” to enable mail”
echo -e ” notification for the specified alerts.”
echo -e ” To get a list of valid alerts please invoke \”$SCRIPTNAME -listalerts\””
echo -e ” ”
echo -e ” 2) -disable [alert1 alert2|all]”
echo -e ” If \”-disable\” is specified then specified alert is disabled and no mail notification.”
echo -e ” ist sent for the specified alert. You can specify a single alert or a space separated list”
echo -e ” of alerts or \”all\” to disable mail notification for the specified alerts.”
echo -e ” To get a list of valid alerts please invoke \”$SCRIPTNAME -listalerts\””
echo -e ” ”
echo -e ” 3) -listalerts”
echo -e ” If \”-listalerts\” is specified then a all supported \”srvadmin\” alerts on this system are listed.”
echo -e ” ”
echo -e ” 4) -mail [mail text]”
echo -e ” If \”-mail\” is specified then a mail is sent to the recipient secified in the \”MAIL_RECIPIENT\” variable.”
echo -e ” The content of the mail is specified in the string [\”mail text\”] following the \”-mail\” option.”
echo -e ” ”
echo -e ” 5) -testmail”
echo -e ” If \”-testmail\” is specified then a testmail with following content is sent:”
echo -e ” \”Testing Dell hardware alert warnings…\””
echo -e ” The \”-testmail\” can not take more arguments”
echo -e ” ”
}
send_alert_mail_and_log( ){
ALERT_MESSAGE=”$(echo $@|awk ‘{print substr($0, index($0,$2)) }’)”
omreport system alertlog|mail -s “Hardware alert (\”$ALERT_MESSAGE\”) on Host \”$HOST_NAME\” at $HOST_LOCATION” “$MAIL_RECIPIENT”
#echo -e “$ALERT_MESSAGE”|mail -s “Hardware alert of Server $HOST_NAME at $HOST_LOCATION” “$MAIL_RECIPIENT”
logger -t “$SCRIPTNAME” “$ALERT_MESSAGE”
}
send_test_mail_and_log( ){
echo -e “$TEST_MAIL_CONTENT”|mail -s “Hardware alert of Server $HOST_NAME at $HOST_LOCATION” “$MAIL_RECIPIENT”
logger -t “$SCRIPTNAME” “$TEST_MAIL_CONTENT”
}
list_supported_alerts( ){
# omconfig system alertaction 2>”$DEVNULL”| cut -f2 -d” | sed `s/|/ /g`
# /opt/dell/srvadmin/bin/omconfig system alertaction 2 > “$DEVNULL” | cut -f2 -d”” | sed ‘s/|/ /g’
/opt/dell/srvadmin/bin/omconfig system alertaction | cut -f2 -d”” | sed ‘s/|/ /g’
}
get_alert_list( ){
# Check if alert is valid and build alert list
ALERT_LIST=”$(echo “$@”|awk ‘{print substr($0, index($0,$2)) }’)”
if [ “$ALERT_LIST” = all ] ; then
VALID_ALERT_LIST=$(list_supported_alerts)
else
for ALERT in $ALERT_LIST; do
if list_supported_alerts|grep -q $ALERT; then
VALID_ALERT_LIST=”$VALID_ALERT_LIST $ALERT”
else
echo -e “\n”
echo -e “The specified alert \””$ALERT”\” does not exist.”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
fi
done
fi
}
enable_alertmail( ){
get_alert_list “$@” || return 1
# Enable alert after user confirmation
echo “Warning! You are about to change your \”srvadmin\” software configuration.”
echo -e “\n”
echo “* Your original \”srvadmin\” configuration will be kept as is. *”
echo “* Additonally \”srvadmin\” will send mails on hardware alerts! *”
echo -e “\n”
echo “If you are sure you want to activate alert e-mails then”
echo “type \”yes\”, any other key to abort!”
read -n 4 CONFIRMATION
case “$CONFIRMATION” in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execappath=”$SCRIPTNAME -mail $VALID_ALERT” > “$DEVNULL” 2>&1; then
echo “Alert \”$VALID_ALERT\” configured successfully.”
logger -t “$SCRIPTNAME” “Alert \”$VALID_ALERT\” configured successfully.”
else
echo “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
logger -t “$SCRIPTNAME” “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
fi
done
;;
*)
echo -e “\n”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
;;
esac
}
disable_alertmail( ){
get_alert_list “$@” || return 1
# Disable alert after user confirmation
echo “Warning! You are about to change your \”srvadmin\” software configuration.”
echo -e “\n”
echo “* Your original \”srvadmin\” configuration will be kept as is. *”
echo “* Additonally \”srvadmin\” will stop sending mails on hardware alerts! *”
echo -e “\n”
echo “If you are shure you want to disable alert mails then”
echo “press\” yes \” , any other key to abort!”
read -n 4 CONFIRMATION
case $CONFIRMATION in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execapp=false > “$DEVNULL” 2>&1; then
#if omconfig system alertaction event=$VALID_ALERT clearall=true > “$DEVNULL” 2>&1; then
echo “Alert \”$VALID_ALERT\” disabled successfully.”
logger -t “$SCRIPTNAME” “Alert \”$VALID_ALERT\” disabled successfully.”
else
echo “Error! The specified alert \”$VALID_ALERT\” is not supported on this system.”
logger -t “$SCRIPTNAME” “Error! The specified alert \”$VALID_ALERT\” is not supported on this system!”
fi
done
;;
*)
echo -e “\n”
echo “Nothing has been changed. Exiting!”
echo -e “\n”
return 1
;;
esac
}
# here comes the main program
if [ -z $1 ] ; then
show_help
exit 1
else
ARG=(“$@”)
case “${ARG[0]}” in
-enable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
enable_alertmail “$@” || exit 1
fi
;;
-disable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
disable_alertmail “$@” || exit 1
fi
;;
-mail)
send_alert_mail_and_log “$@”
;;
-testmail)
if [ ! -z ${ARG[1]} ] ; then
show_help
exit 1
else
send_test_mail_and_log
fi
;;
-listalerts)
list_supported_alerts
;;
*)
show_help
exit 1
;;
esac
fi
########################################################################
Rolf says
Test Code ' ` "
Rolf says
another attemt:
#!/bin/bash
########################################################################
# /opt/dell/srvadmin/bin/omsendmail
# By [email protected]
# Dell srvadmin Hardware Email Alert
# Modified:
#
# 2011/10/16 – cut line needed additional cut to remove trailing `>` when parsing avail alerts – DRD
# – the way the script finds its name and location since OMSA needs full path in alert config
# – changed message subject and a few typos
# – changed message to contain the full alert log
# somewhat more informational subject line in email
# modified to work under ubuntu precise (had to fix broken formatting from copying from web page)
# Change the mail recipinet variable to the user of your needs.
MAIL_RECIPIENT="youremail@yourdomain"
HOST_LOCATION="Earth"
# You may not change these variables!
SCRIPTNAME="`basename \"$0\"`"
TEST_MAIL_CONTENT="Testing Dell hardware alert warnings..."
HOST_NAME="$(hostname -f)"
DEVNULL="/dev/null"
DEFAULT_OMSA_BIN="/opt/dell/srvadmin/bin"
# Determine path to this script since OMSA requires full path, yet you may run it as ./SCRIPTNAME, etc.
SCRIPT_PATH="${BASH_SOURCE[0]}";
if ([ -h "${SCRIPT_PATH}" ]) then
while([ -h "${SCRIPT_PATH}" ]) do SCRIPT_PATH=`readlink "${SCRIPT_PATH}"`; done
fi
pushd . > /dev/null
cd `dirname ${SCRIPT_PATH}` > /dev/null
SCRIPT_PATH=`pwd`; popd > /dev/null
# Thanks http://stackoverflow.com/questions/59895/can-a-bash-script-tell-what-directory-its-stored-in
# Overload SCRIPTNAME to full path
SCRIPTNAME="$SCRIPT_PATH/$SCRIPTNAME"
# Verify we have the OMSA tools we use in our PATH env or the default location
for TOOL in omconfig omreport; do
if [ ! `which omconfig >/dev/null 2>&1` ]; then
if [ ! -x "$DEFAULT_OMSA_BIN/$TOOL" ]; then
echo "$SCRIPTNAME ERROR: Cannot find executable Dell OMSA utilities in PATH or $DEFAULT_OMSA_BIN"
exit 1
fi
# Add the default to the script path for use below
PATH=${PATH}:${DEFAULT_OMSA_BIN}
fi
done
show_help( ){
echo -e " "
echo -e "Please invoke like follows"
echo -e " "
echo -e "* "$SCRIPTNAME" -option [\"optional text\"] *"
echo -e " "
echo -e "The following options are allowed: \"–enable [alert1 alert2|all]\" \"–disable [alert1 alert2|all]\""
echo -e " \"-listalerts\" \"-mail [\"mail content text\"]\" \"-testmail\""
echo -e " "
echo -e "Explanation of the options:"
echo -e " "
echo -e " 1) -enable [alert1 alert2|all]"
echo -e " If \"-enable\" is specified then \"srvadmin\" is configured to send mail allerts on hardware issues."
echo -e " This must be done just once upon fresh installing or reinstalling the \"srvadmin\" software."
echo -e " Also if you change the name or the file system location of the \"$SCRIPTNAME\" script"
echo -e " You can specify a single alert or a space separated list of alerts or \"all\" to enable mail"
echo -e " notification for the specified alerts."
echo -e " To get a list of valid alerts please invoke \"$SCRIPTNAME -listalerts\""
echo -e " "
echo -e " 2) -disable [alert1 alert2|all]"
echo -e " If \"-disable\" is specified then specified alert is disabled and no mail notification."
echo -e " ist sent for the specified alert. You can specify a single alert or a space separated list"
echo -e " of alerts or \"all\" to disable mail notification for the specified alerts."
echo -e " To get a list of valid alerts please invoke \"$SCRIPTNAME -listalerts\""
echo -e " "
echo -e " 3) -listalerts"
echo -e " If \"-listalerts\" is specified then a all supported \"srvadmin\" alerts on this system are listed."
echo -e " "
echo -e " 4) -mail [mail text]"
echo -e " If \"-mail\" is specified then a mail is sent to the recipient secified in the \"MAIL_RECIPIENT\" variable."
echo -e " The content of the mail is specified in the string [\"mail text\"] following the \"-mail\" option."
echo -e " "
echo -e " 5) -testmail"
echo -e " If \"-testmail\" is specified then a testmail with following content is sent:"
echo -e " \"Testing Dell hardware alert warnings…\""
echo -e " The \"-testmail\" can not take more arguments"
echo -e " "
}
send_alert_mail_and_log( ){
ALERT_MESSAGE="$(echo $@|awk '{print substr($0, index($0,$2)) }')"
omreport system alertlog|mail -s "Hardware alert (\"$ALERT_MESSAGE\") on Host \"$HOST_NAME\" at $HOST_LOCATION" "$MAIL_RECIPIENT"
#echo -e "$ALERT_MESSAGE"|mail -s "Hardware alert of Server $HOST_NAME at $HOST_LOCATION" "$MAIL_RECIPIENT"
logger -t "$SCRIPTNAME" "$ALERT_MESSAGE"
}
send_test_mail_and_log( ){
echo -e "$TEST_MAIL_CONTENT"|mail -s "Hardware alert of Server $HOST_NAME at $HOST_LOCATION" "$MAIL_RECIPIENT"
logger -t "$SCRIPTNAME" "$TEST_MAIL_CONTENT"
}
list_supported_alerts( ){
# omconfig system alertaction 2>"$DEVNULL"| cut -f2 -d" | sed `s/|/ /g`
# /opt/dell/srvadmin/bin/omconfig system alertaction 2 > "$DEVNULL" | cut -f2 -d"" | sed 's/|/ /g'
/opt/dell/srvadmin/bin/omconfig system alertaction | cut -f2 -d"" | sed 's/|/ /g'
}
get_alert_list( ){
# Check if alert is valid and build alert list
ALERT_LIST="$(echo "$@"|awk '{print substr($0, index($0,$2)) }')"
if [ "$ALERT_LIST" = all ] ; then
VALID_ALERT_LIST=$(list_supported_alerts)
else
for ALERT in $ALERT_LIST; do
if list_supported_alerts|grep -q $ALERT; then
VALID_ALERT_LIST="$VALID_ALERT_LIST $ALERT"
else
echo -e "\n"
echo -e "The specified alert \""$ALERT"\" does not exist."
echo "Nothing has been changed. Exiting!"
echo -e "\n"
return 1
fi
done
fi
}
enable_alertmail( ){
get_alert_list "$@" || return 1
# Enable alert after user confirmation
echo "Warning! You are about to change your \"srvadmin\" software configuration."
echo -e "\n"
echo "* Your original \"srvadmin\" configuration will be kept as is. *"
echo "* Additonally \"srvadmin\" will send mails on hardware alerts! *"
echo -e "\n"
echo "If you are sure you want to activate alert e-mails then"
echo "type \"yes\", any other key to abort!"
read -n 4 CONFIRMATION
case "$CONFIRMATION" in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execappath="$SCRIPTNAME -mail $VALID_ALERT" > "$DEVNULL" 2>&1; then
echo "Alert \"$VALID_ALERT\" configured successfully."
logger -t "$SCRIPTNAME" "Alert \"$VALID_ALERT\" configured successfully."
else
echo "Error! The specified alert \"$VALID_ALERT\" is not supported on this system!"
logger -t "$SCRIPTNAME" "Error! The specified alert \"$VALID_ALERT\" is not supported on this system!"
fi
done
;;
*)
echo -e "\n"
echo "Nothing has been changed. Exiting!"
echo -e "\n"
return 1
;;
esac
}
disable_alertmail( ){
get_alert_list "$@" || return 1
# Disable alert after user confirmation
echo "Warning! You are about to change your \"srvadmin\" software configuration."
echo -e "\n"
echo "* Your original \"srvadmin\" configuration will be kept as is. *"
echo "* Additonally \"srvadmin\" will stop sending mails on hardware alerts! *"
echo -e "\n"
echo "If you are shure you want to disable alert mails then"
echo "press\" yes \" , any other key to abort!"
read -n 4 CONFIRMATION
case $CONFIRMATION in
yes|Yes|YES)
for VALID_ALERT in $VALID_ALERT_LIST; do
if omconfig system alertaction event=$VALID_ALERT execapp=false > "$DEVNULL" 2>&1; then
#if omconfig system alertaction event=$VALID_ALERT clearall=true > "$DEVNULL" 2>&1; then
echo "Alert \"$VALID_ALERT\" disabled successfully."
logger -t "$SCRIPTNAME" "Alert \"$VALID_ALERT\" disabled successfully."
else
echo "Error! The specified alert \"$VALID_ALERT\" is not supported on this system."
logger -t "$SCRIPTNAME" "Error! The specified alert \"$VALID_ALERT\" is not supported on this system!"
fi
done
;;
*)
echo -e "\n"
echo "Nothing has been changed. Exiting!"
echo -e "\n"
return 1
;;
esac
}
# here comes the main program
if [ -z $1 ] ; then
show_help
exit 1
else
ARG=("$@")
case "${ARG[0]}" in
-enable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
enable_alertmail "$@" || exit 1
fi
;;
-disable)
if [ -z ${ARG[1]} ] ; then
show_help
exit 1
else
disable_alertmail "$@" || exit 1
fi
;;
-mail)
send_alert_mail_and_log "$@"
;;
-testmail)
if [ ! -z ${ARG[1]} ] ; then
show_help
exit 1
else
send_test_mail_and_log
fi
;;
-listalerts)
list_supported_alerts
;;
*)
show_help
exit 1
;;
esac
fi
########################################################################