Azmawee 127.0.0.1

"Mauiwagen. Das Server." – pub 4096R/712DAA69

Bad disk detached and I wonder why, why, why, why, why.

freebsd_logoIn the last few days (or weeks, I’m not sure how long), one of my hard drive from one or the mirror array has been detached without my knowledge in my home FreeBSD server, acting as my NAS Storage. Luckly it was just a sata connection issue, after a quick fix, re-attaching back the lost drive was a breeze without any issue.

Learning from that event, where I am not sure how long the disk been detached, I came out with my own simple health check script that checks what I want and email me the result. Of cause to check the disk mirror status, most critical hardware and some services as well.

As usual, I would love to share this with the world.healthchecking You can use it as a base for your health check script and modify how you want.

However, it required another script, hdd-temp-maui.sh.txt which originally created by cytopia{at}everythingcli.org. It was an awesome script that can retrieve all of your disks information, including the temperature (using smartctl tool). I also done some minor fix and modification to the original script (hdd-temp.sh) to support data gathering on SSD as well, hence the script new name with my alias in it.

Direct fetch for both script here healthcheck.sh.txt and hdd-temp-maui.sh.txt

Maybe you been wonder why I didn’t use the more elegant Nagios monitoring for this. Reason is, I wanted to save all the resources as much as possible on the server.

Peek-a-boo of the script.

#!/bin/sh

# maui[at]mybsd.org.my, azmawee[at]azmawee.com azmawee[at]yahoo.com
# Copyright (c) 2016 - https://azmawee.com
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.

# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.

# Changelog:
# Version 1.0 - 20 Sep 2016 - Script lived.
# Version 1.1 - 21 Sep 2016 - Added APC and dmesg to the report.

# Script requirement:
# 1. hdd-temp-maui.sh script, original source from hdd-temp.sh by <cytopia@everythingcli.org>.
# 2. smartctl tools (from smartmontools).
# 3. Mutt email client (Optional if you enable email notification).

# Notes.
# Run with option "--debug" to ignore email notification and only display report on screen for debugging.
# example: ./healthcheck.sh --debug

# Email notification, 1 to enable, 0 to disable.
email_notification="1"

# Working path, default is in current directory (pwd)
#wpath="`pwd`"
wpath="/root/healthcheck"

# Log file
log_file=report.txt
log="$wpath/$log_file"

# dmesg log file
dmesg_file=dmesg.txt
dmesglog="$wpath/$dmesg_file"

# Location to mutt
_mail="/usr/local/bin/mutt"

# List of emails
# Multiple recipients example : email_list="azmawee@domain1.com,azmawee@domain2.com,maui@domain3.com"
email_list="azmawee@yahoo.com"

#echo option/flag
show="echo -e"

$show "`date` - Script started.\n" > $log

# General info
$show "`hostname` `ifconfig ng0 | grep inet | awk '{ print $2 }' | tail -1` `uname -r -i`\n" >> $log

# Check APC UPS
$show "apcaccess status | grep -i -e status -e lastxfer:\n`apcaccess status | grep -i -e status -e lastxfer`\n" >> $log

# Check gmirror status
$show "gmirror status:\n`gmirror status`\n" >> $log
$show "gmirror list | grep -i name:\n`gmirror list | grep -i name:`\n" >> $log

# Check current attached disk(s)
$show "Current attached disk(s):\n`$wpath/hdd-temp-maui.sh`\n" >> $log

# Check diskspace
$show "df -H:\n`df -H`\n" >> $log

# Check squid status
$show "service squid status:\n`sh /rc.d/squid status` Background pid check for squid is `ps auwx | grep "(squid)" | head -1 | awk '{print $2}'`.\n" >> $log

# Check samba status
$show "service samba_server status:\n`service samba_server status | grep nmbd` Background pid check for nmdb is `ps auwx | grep nmbd | head -1 | awk '{print $2}'`." >> $log
$show "`service samba_server status | grep smbd` Background pid check for smbd is `ps auwx | grep smbd | head -1 | awk '{print $2}'`.\n" >> $log

# Check Apache(httpd) status
$show "service apache22 status:\n`service apache22 status` Background pid check for apache is `ps auwx | grep /usr/local/sbin/httpd | head -1 | awk '{print $2}'`.\n" >> $log

# Check MariaDB/Mysql server status
$show "service mysql-server status:\n`service mysql-server status` Background pid check for mysqld is `ps auwx | grep /usr/local/libexec/mysqld | head -1 | awk '{print $2}'`.\n" >> $log

# Check named status
$show "service named status:\n`service named status` Background pid check for named is `ps auwx | grep /usr/local/sbin/named | head -1 | awk '{print $2}'`.\n" >> $log

# grep 30 current dmesg
$show "dmesg | tail -30:\n`dmesg | tail -30`\n" >> $log

$show "`date` - Script ended." >> $log

if [ "$1" == "--debug" ]; then
	cat $log
else
	# Email the report
	if [ "$email_notification" == "1" ]; then
		$_mail -s "azmawee.com server check" -- $email_list < $log
	fi
fi

 

, , , , , , , , , , , , , ,

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz
MaUi^ - pub 4096R/712DAA69
Fingerprint 8BF7 D0AF CA45 5313 A3BF ACFB B90B 66C7 712D AA69

0110010101100001011100110111010001100101011100100010000001100101011001110110011100100000011011100110111100101110001000000011000000110110