How to setup an alert to know about server crash situation ?

Many times our server crashes and reboots and we remain unaware about the situation.

To know this situation, we cam setup alerts on our server and take corrective action immediately in case of issues.

Setup Script to send email about any server crash Situation

1. Verify Path of crash dump.
First lets verify the path of crash dump.

[root@ngelinux]# cat /etc/kdump.conf  | grep -I path
# Currently only one dump target and path may be configured at a time. If dump
# path  		- Append path to the filesystem device which you are
#			  //%HOST-%DATE/, supports DNS.
#			  :/%HOST-%DATE/ via SSH,
#		 	  /proc/vmcore to /mnt//127.0.0.1-%DATE/.
# 			  non-boot-path dump targets that might otherwise
# sshkey 
#			- Specifies the path of the ssh identity file you want
path /var/crash
[root@ngelinux]# 

2. Now create your command to search for vmcore.
I have searched for vmcore files created in last 60 minutes.

[root@ngelinux crash]# find /var/crash -mmin -60 -type f -name *vmcore*
/var/crash/vmcore-2132131

3. Create below script and place in /etc/cron.hourly.

[root@ngelinux cron.hourly]# vim crash_mail.sh

[root@ngelinux cron.hourly]# cat crash_mail.sh 
#!/bin/bash
getfiles=`find /var/crash -mmin -60 -type f -name *vmcore*`
if [[ $getfiles == "" ]]; then
echo 
else
      echo "Your Server \"$(hostname)\" encountered a suspected crash situation. Please Check " | mail -s "Alarm: Check Your Server $(hostname)" root@localhost
fi

[root@ngelinux cron.hourly]# 

Make the script executable.

[root@ngelinux cron.hourly]# 
[root@ngelinux cron.hourly]# chmod +x crash_mail.sh 
[root@ngelinux cron.hourly]# 

4. Now you will get mail in case there is any vmcore file is generated in last 60 minutes.

Leave a Reply

avatar
  Subscribe  
Notify of