[SunHELP] Disk mirror monitor

Tim Conrad sunhelp at sunhelp.org
Wed Mar 21 13:40:13 CST 2001


This is a multi-part message in MIME format.
--------------D5A8245833E93F3755464D62
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

While my script is a bit more detailed than that, I have a script that
does basically the same thing, but also adds in some other things.
Basically, this script was designed to be ran once a week to keep tabs
on boxes that I'm not remotely close to. Plus, this script ALWAYS sends
email, not if certian criteria apply.

If you use my script, and aren't using Netscape Messenger, you may want
to make SENDMAILQ to 0 instead of 1.

Don't laugh too hard at the 'security check' portion. I was going to
make it do a lot more, search for suid apps, check for 'strange' things
like a file/directory named '...'.

Plus, the 'df' portion of it is kind of hacky. It just assumes that the
df installed in /usr/local/bin/df is GNU df. Doesn't do a version check
or anything like that. For some reason, Sun doesn't put the --version
option into much of anything. (I suppose, for the extra 3 lines of code
that it would take to do...)

Unfortunatly, it's designed to be ran from cron, and not when Disk Suite
sees something go awry. 

The script only works on Solaris, and I don't know if it will work on
Solaris for x86.

This script is released AS IS. I make no warranty for it. Especially if
your wife leaves you for the plumber, it's not my fault. I don't even
really have time to support the script, or do anything neat like that.

So. Anyways. Your Milage May, (and most likely will) Vary.

Tim

-Mark- wrote:
> 
> This is the cron entry I use - real basic
> 
> 0 8 * * * /usr/opt/SUNWmd/sbin/metastat|mailx -s
> servername admin at mycompany.com >/dev/null 2>&1
> 
> --- Tim Longo <tlongo at avaya.com> wrote:
> >
> > Greetings,
> >
> > I'm using DiskSuite to mirror many server root
> > disks, and this seems to work
> > great.  I would be interested in hearing how other
> > admins monitor the status
> > of the disks.  I currently use a script that runs
> > metastat, and I look for a
> > message like "Maintenance Needed", or anything other
> > than "OK".
> >
> > I know that when a mirror disk fails, and entry goes
> > into the syslog, and
> > displayed on the console, but is there an easy way
> > to have this message
> > mailed to root?
> >
> > Thanks.
> >
\
--------------D5A8245833E93F3755464D62
Content-Type: application/x-sh;
 name="host_stats.sh"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="host_stats.sh"

#!/bin/sh

####
#
# host_stats.sh - File to mail someone stats about a host.
# Tim Conrad - tconrad at edisonschools.com
#
# Version .01 Tue Sep 19 10:43:29 EDT 2000
#	- only mailed disk stats.
# Version .02 Tue Sep 19 10:53:23 EDT 2000
#	- Modified to send more stats about the host.
#	- Still very Solaris-centric.
# 	- Made each check switchable
#
VERSION=02
#
####

####
#
# Script variables. Most of them are 0/1 switches. Change it to 0 if you don't want
# That tad bit of info.
#
####

# Who to send output of this report to. 
MAILTO="tconrad at edisonschools.com"

# Do you want to send mail? You may not for testing purposes or whatever.
SENDMAIL=1

# Do some very brief security checks. Nothing spectacular. Might catch a clumsy skript kiddy tho.
SECURITY=1

# Do a 'metastat' and send it's output. 
SENDDISKSUITE=1

# Do a 'df' and send it's output. Does a df -k in the Solaris DF, and df -h in GNU df. 
SENDDF=1

# Do a netstat -i and send it's output
SENDISTAT=1

# Do a  netstat -s and send its output.
SENDPROTSTAT=1

# Send the last lines of the syslog.
SENDSYSLOG=1

# How many lines of syslog to send?
SYSLOGLEN=20

# Send the output of last
SENDLAST=1

# How many lines of it to send?
SENDLASTLEN=5

# Check to see if Netscape Messenger has been installed, and if it has
# Send the results of /etc/mailbin/MailQueue
SENDMAILQ=1 

####
#
# Shouldn't need to edit anything below this line.
#
####

HOSTNAME=`uname -n`
PATH=/usr/bin:/bin:/usr/sbin:/usr/opt/SUNWmd/sbin:/etc/mailbin
MESSAGE=/tmp/.statmsg

if [ -f ${MESSAGE} ] ; then
	rm ${MESSAGE}
fi

if [ -x /usr/bin/mailx ] ; then
	MAIL=/usr/bin/mailx
else
	echo "Erk. No mailx. Die Die Die!\n"
	exit
fi	

echo "Host stats for ${HOSTNAME}\nGenerated on `date`\n" > ${MESSAGE}
echo "Host uptime: \n`uptime`\n" >> ${MESSAGE}
echo "Current Users: \n`w`\n" >> ${MESSAGE}
echo "Host info: \n  `uname -a\n\n" >> ${MESSAGE}
echo "----------------------------------------------------------\n" >> ${MESSAGE}

if [ ${SECURITY} = "1" ] ; then
	# Do cheesy security check here!
	echo "Brief security check..." >> ${MESSAGE}
	echo "Users in /etc/passwd with uid 0:" >> ${MESSAGE}
	awk -F: '$3==0 {print $1,$3}' /etc/passwd >> ${MESSAGE}
	echo "\n----------------------------------------------------------\n" >> ${MESSAGE}
fi

if [ ${SENDDISKSUITE} = "1" ] ; then
	# Send output of metastat
	if [ -x /usr/opt/SUNWmd/sbin/metastat ] ; then
		DISKSUITE=1
	else
		DISKSUITE=0
	fi

	if [ ${DISKSUITE} = "1" ] ; then
		echo "Information from DiskSuite: \n" >> ${MESSAGE}
		metastat >> ${MESSAGE}
	fi

	echo "----------------------------------------------------------\n" >> ${MESSAGE}
fi

if [ ${SENDDF} = "1" ] ; then
	# Show output of df.
	echo "Disk Usage Stats:\n" >> ${MESSAGE}
	if [ -x /usr/local/bin/df ] ; then
		# This is VERY Solaris-ized.
		DF=/usr/local/bin/df
		${DF} -h >> ${MESSAGE}
	else
		DF=/usr/bin/df
		${DF} -k >> ${MESSAGE}
	fi
	echo "\n----------------------------------------------------------\n" >> ${MESSAGE}
fi

if [ ${SENDSYSLOG} = "1" ] ; then
	# Send the last X lines of the syslog.
	if [ -f /var/adm/messages ] ; then
		SYSLOG=/var/adm/messages
	fi
	if [ -f /var/log/messages ] ; then
		SYSLOG=/var/log/messages
	fi
	echo "Last ${SYSLOGLEN} lines of ${SYSLOG}:\n" >> ${MESSAGE} 
	tail -${SYSLOGLEN} $SYSLOG >> ${MESSAGE}
	echo "\n----------------------------------------------------------\n" >> ${MESSAGE}
fi

if [ ${SENDISTAT} = "1" ] ; then
	# Use netstat to give statistics on the interfaces.
	if [ -x /usr/bin/netstat ] ; then
		echo "Interface statistics:\n" >> ${MESSAGE}
		netstat -i >> ${MESSAGE}
	fi
	echo "\n----------------------------------------------------------\n" >> ${MESSAGE}
fi

if [ ${SENDPROTSTAT} = "1" ] ; then
	# Use netstat to give per-protocol statistics. Can get long.
	if [ -x /usr/bin/netstat ] ; then
		echo "Per-protocol statistics:\n" >> ${MESSAGE}
		netstat -s >> ${MESSAGE}
	fi
	echo "\n----------------------------------------------------------\n" >> ${MESSAGE}
fi

if [ ${SENDLAST} = "1" ] ; then
	# Just get the first X lines of the 'last' output.
	echo "Last ${SENDLASTLEN} logins:\n" >> ${MESSAGE}
	last | head -${SENDLASTLEN} >> ${MESSAGE}
	echo "\n----------------------------------------------------------\n" >> ${MESSAGE}
fi

if [ ${SENDMAILQ} = "1" ] ; then
	# Send the output of the Mail Queue.
	echo "Messages in the Queue:\n" >> ${MESSAGE}
	MailQueue >> ${MESSAGE}
	echo "\n----------------------------------------------------------\n" >> ${MESSAGE}
fi

echo "\nThis message was auto-generated for your consumption." >> ${MESSAGE}
echo "If you feel you are getting this message in error, I don't know what to tell you." >> ${MESSAGE}
echo "Don't reply to this message. It was sent from an unattached mailbox" >> ${MESSAGE}
echo "Generated by Tim's host_stats script. \nVersion: ${VERSION}" >> ${MESSAGE}
echo "`date`\n" >> ${MESSAGE}

if [ ${SENDMAIL} = "1" ] ; then
	for USER in ${MAILTO}
	do
		cat ${MESSAGE} | mailx -s "Info for host ${HOSTNAME}" -r "host_stats@${HOSTNAME}" ${USER}
	done
fi

if [ -f ${MESSAGE} ] ; then 
	rm ${MESSAGE}
fi



--------------D5A8245833E93F3755464D62--




More information about the SunHELP mailing list