#!/bin/bash
#
# System Event Log (SEL) checking program.
#
# Author:	Haruo Tomita <haruo.tomita@toshiba.co.jp>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# (c) 2008 Copyright TOSHIBA Corporation. All rights reserved. 
#
# Add this to /etc/rc.d/rc.local file or crontab.
#
IPMITOOL_BIN=/usr/bin/ipmitool
IPMIDEV=`ls -d /dev/ipmi* 2> /dev/null`
if [ -f $IPMITOOL_BIN ] && [ "$IPMIDEV" != "" ]; then
	SEL_CLEAR="false"
	OVERFLOW=`$IPMITOOL_BIN sel | grep Overflow | awk '{print $3;}'`
	if [ $OVERFLOW == true ]; then
		SEL_CLEAR="true";
	fi
	PERCENT_USED=`$IPMITOOL_BIN sel | \
			grep "Percent Used" | \
			awk '{print $4;}' | sed -e "s/\%//"`
	if [ $PERCENT_USED -gt 80 ]; then
		SEL_CLEAR="true"
	fi
	
	if [ $SEL_CLEAR == true ]; then
		DATE=`date +%Y-%m%d-%H%M-%S`
		SEL_FILE="/var/log/sel"
		$IPMITOOL_BIN sel writeraw $SEL_FILE-$DATE.log > /dev/null 2>&1
		$IPMITOOL_BIN sel clear
	fi

fi