Hey guys, are you looking for on how to keep track your Xenserver status of Raid Disk and want to make it in a daily checking and alerting by send email? Take it easy, let follow this short tip.
My system:
- Xenserver 6.2
- Server Raid M5110
- Raid 1
To begin you must to know at least basic CentOS command.
Install and enable ssmtp on your Server
First, We need to download the mailx from CentOS repository then install it by doing some command below:
1 2 3 4 5 6 7 |
// Get Mailx installation source wget http://mirror.centos.org/centos-5/5.11/os/i386/CentOS/mailx-8.1.1-44.2.2.i386.rpm // Install Mailx rpm –hiv mailx-8.1.1-44.2.2.i386.rpm |
Once it done, go to edit ssmtp.conf:
1 |
nano /etc/ssmtp/ssmtp.conf |
Edit and un-comment line, I’m added
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# # /etc/ssmtp.conf -- a config file for sSMTP sendmail. # # The person who gets all mail for userids < 500 # Make this empty to disable rewriting. Jacky=Administrator AuthUser=repoter@example.com AuthPass=12345678 # The place where the mail goes. The actual machine name is required # no MX records are consulted. Commonly mailhosts are named mail.domain.com # The example will fit if you are in domain.com and your mailhub is so named. mailhub=mail # Example for SMTP port number 2525 # mailhub=mail.your.domain:2525 # Example for SMTP port number 25 (Standard/RFC) mailhub=mail.example.com # Example for SSL encrypted connection # mailhub=mail.your.domain:465 # Where will the mail seem to come from? rewriteDomain=mail.example.com # The full hostname hostname=example.com # Set this to never rewrite the "From:" line (unless not given) and to # use that address in the "from line" of the envelope. FromLineOverride=YES # Use SSL/TLS to send secure messages to server. #UseTLS=YES useSTARTTLS=YES # Use SSL/TLS certificate to authenticate against smtp host. #UseTLSCert=YES # Use this RSA certificate. #TLSCert=/etc/ssl/certs/ssmtp.pem # Get enhanced (*really* enhanced) debugging information in the logs # If you want to have debugging of the config file parsing, move this option # to the top of the config file and uncomment #Debug=YES |
The configuration for ssmtp almost done, let do a simple test send mail by:
1 |
ssmtp youremail@example.com </etc/ssmtp/ssmtp.conf |
How to call your Raid adapter information?
You need to install the Megacli utility, this tool will call information about the Raid adapter. Megacli Cheat I’ll mention in other post.
Download the Megacli utility and copy to your server
This package included 2 files: Lib_Utils-1.00-09.noarch.rpm and MegaCli-8.04.10-1.noarch.rpm
Follow the command below to install the Megacli:
1 2 3 4 |
//Install the Lib_Utils first rpm –U Lib_Utils-1.00-09.noarch.rpm rpm –U MegaCli-8.04.10-1.noarch.rpm |
It’ll be installed to:
1 |
/opt/MegaRAID/MegaCli |
Create a shell script and put it to cron job for daily checking.
I’m put the running script in /var/script/ and place the name checkraid.sh and also create emailmessage.txt with blank content.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#! /bin/bash # checkraid.sh checkraid=`/opt/MegaRAID/MegaCli/MegaCli -LDInfo -Lall -aALL | grep DEGRADED` if [ "$checkraid" == "" ]; then echo "Everything ok" else echo "Error, array DEGRADED"; SUBJECT="RAID ARRAY DEGRADED! *** Xenserver ***" EMAIL="youremail@example.com" EMAILMESSAGE="/var/script/emailmessage.txt" echo "Below is the output of the error on Xenserver:"> $EMAILMESSAGE echo "Time: `date`">> $EMAILMESSAGE echo `/opt/MegaRAID/MegaCli/MegaCli -LDInfo -Lall -aALL` >>$EMAILMESSAGE /bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE fi |
Create cron job for daily check:
1 2 3 4 5 |
crontab –e // Put the running job */20 * * * * /var/script/checkraid.sh >/dev/null 2>&1 |
It’ll check every 20 mins and only send mail if it degraded.
Hope it help.
Leave a Reply