#!/bin/bash
#############################################################
# Name:        Supportconfig Plugin for NOWS SBE OpenVPN
# Description: Gathers open virtual private network
#              troubleshooting information
# License:     GPLv2
# Author:      Randy Goddard (randage@gmail.com)
#              Jason Record (jrecord@novell.com)
# Modified:    2010 Oct 21
#############################################################

SVER=2.02
RCFILE="/usr/lib/supportconfig/resources/scplugin.rc"
LOG_LINES=0	#0 means include the entire file
LOG_DIR=/etc/openvpn
CONF_DIR=/etc/openvpn

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

section_header "Supportconfig Plugin for NOWS SBE OpenVPN, v${SVER}"

plugin_command "rpm -qa | egrep -i 'openvpn' | sort"
RPMLIST=$(rpm -qa | egrep -i "openvpn" | sort)
if [ -z "$RPMLIST" ]; then
  echo "ERROR: OpenVPN package(s) not installed"
  echo
  exit 111
fi

for THISRPM in $RPMLIST
do
   validate_rpm $THISRPM
done

section_header Checking OpenVPN Configuration
for i in openvpn
do
	if [ -s /etc/init.d/$i ]; then
		plugin_command "chkconfig -l $i"
		plugin_command "/etc/init.d/$i status"
	fi
done

plugin_command "ps axwwo user,pid,ppid,%cpu,%mem,vsz,rss,stat,time,cmd | egrep 'openvpn' | egrep -v 'nowsbe_|grep'"
plugin_command "netstat -nlp | egrep '1194|openvpn'"
pconf_files $CONF_DIR/server.conf
plog_files $LOG_LINES $LOG_DIR/openvpn-status.log

