#!/bin/bash
#################################################################################
# Name:        Supportconfig Plugin for GroupWise
# Description: Gathers important troubleshooting information
#              about GroupWise Agents, Monitor, GWIA and 
#              WebAccess.
# License:     GPLv2
# Author:      Jason Record (jrecord@novell.com)
# Modified:    2010 Oct 14
# Requires:    supportutils package with supportconfig-plugin-resource
#################################################################################

SVER=2.0.2
LOG_LINES=0	#0 means include the entire file
LOG_DIR=/var/log/novell/groupwise
CONF_DIR=/etc/opt/novell/groupwise
CONF_SHARE=/opt/novell/groupwise/agents/share
RCFILE="/usr/lib/supportconfig/resources/scplugin.rc"

[ -s $RCFILE ] && . $RCFILE || { echo "ERROR: Initializing resource file: $RCFILE"; exit 1; }

section_header "Supportconfig Plugin for GroupWise, v${SVER}"

RPMLIST=$(rpm -qa | egrep -i "groupwise" | grep -v supportutils-plugin-groupwise | sort)
RPMERROR=$?
if [ $RPMERROR -gt 0 ]; then
	echo "ERROR: GroupWise RPM Packages not installed"
	echo
	exit 111 #skip not installed
else
	plugin_command 'rpm -qa | egrep -i "groupwise" | sort'
fi

for i in grpwise grpwise-ma
do
	if [ -f /etc/init.d/$i ]; then
		plugin_command "chkconfig -l $i"
		plugin_command "/etc/init.d/$i status"
		echo
	fi
done

plugin_command 'ntpq -p'

GRPCOREDIR="/opt/novell/groupwise/agents/bin"
plugin_command "ls -l /core /core\.* ${GRPCOREDIR}/core ${GRPCOREDIR}/core\.* 2>/dev/null"

if [ -d ${GRPCOREDIR}/ ]; then
	FILES1="$(ls -l /core /core\.* 2>/dev/null)"
	FILES2="$(ls -l ${GRPCOREDIR}/core ${GRPCOREDIR}/core\.* 2>/dev/null)"
	if [ -n "$FILES1" -a -n "$FILES2" ]; then
		FILES="$FILES1 $FILES2"
	elif [ -n "$FILES1" -a -z "$FILES2" ]; then
		FILES=$FILES1
	elif [ -z "$FILES1" -a -n "$FILES2" ]; then
		FILES=$FILES2
	fi
else
	FILES="$(ls -l /core /core\.* 2>/dev/null)"
fi

if [ -n "$FILES" ]; then
	for i in $FILES
	do
		if [ -f $i ]; then
			plugin_command "file $i"
		fi
	done
fi

plugin_command 'ps axwwo user,pid,ppid,%cpu,%mem,vsz,rss,stat,time,cmd | grep -E "gwmta|gwpoa|gwinter|gwdva|gwia|gwmon" | grep -v grep'
plugin_command 'netstat -nlp | grep -E "gwmta|gwpoa|gwinter|gwdva|gwia|gwmon"'

if [ -d $CONF_DIR ]; then
	GWHA=${CONF_DIR}/gwha.conf
	pconf_files $GWHA
fi
if [ -d $CONF_SHARE ]; then
	FILES=$(find $CONF_SHARE -maxdepth 1 -type f)
	pconf_files $FILES
fi

for THISRPM in $RPMLIST
do
	validate_rpm $THISRPM
done

if [ -d $LOG_DIR ]; then
	FILES=$(find $LOG_DIR -type f | grep output)
	plog_files $LOG_LINES $FILES
fi


if [ -d $LOG_DIR ]; then
	FILES=$(find $LOG_DIR -type f | grep pid$)
	plog_files $LOG_LINES $FILES

	section_header "Log Files"
	for GDIR in $(\ls -A1 $LOG_DIR | sort )
	do
		test "$GDIR" == ".mta" && continue
		GLOG="$LOG_DIR/$GDIR"
		if [ -d $GLOG ]; then
			plog_files $LOG_LINES $(find $GLOG -type f | sort | grep -E '[[:digit:]]$' | tail -1)
		fi
	done
fi

