zarzuelo cb50725bae 2011-01-26 Sergio Martin <sergio.martin@artica.es>
* android
	bsd-ipso
	bsd-ipso/AUTHORS
	bsd-ipso/pandora_agent_daemon
	bsd-ipso/pandora_agent.conf
	bsd-ipso/pandora_user.conf
	bsd-ipso/COPYING
	bsd-ipso/pandora_agent.sh
	bsd-ipso/README
	aix
	aix/pandora_agent_installer
	aix/pandora_agent
	aix/AUTHORS
	aix/pandora_agent_daemon
	aix/pandora_agent.conf
	aix/pandora_user.conf
	aix/COPYING
	aix/README
	mac_osx
	mac_osx/pandora_agent_installer
	mac_osx/plugins
	mac_osx/plugins/ipmi2xml
	mac_osx/plugins/ipmi2xml/ipmi2xml.php
	mac_osx/plugins/ipmi2xml/README.txt
	mac_osx/plugins/XServeRAID
	mac_osx/plugins/XServeRAID/xserve-raid-tools-1.2-1.uwhep.sl4.i386.rpm
	mac_osx/plugins/XServeRAID/xserve-raid-tools-1.2-1.rhel3.i386.rpm
	mac_osx/plugins/XServeRAID/pandora_agent.conf
	mac_osx/plugins/XServeRAID/check_xserve
	mac_osx/plugins/XServeRAID/xserve-raid-tools-1.2.tar.gz
	mac_osx/plugins/XServeRAID/README.txt
	mac_osx/plugins/SGE
	mac_osx/plugins/SGE/SGEStatus.sh
	mac_osx/plugins/SGE/README
	mac_osx/plugins/grep_log
	mac_osx/plugins/ppc_sensors
	mac_osx/pandora_agent
	mac_osx/AUTHORS
	mac_osx/pandora_agent.conf
	mac_osx/ChangeLog
	mac_osx/COPYING
	mac_osx/pandora_fms
	mac_osx/pandora_fms/StartupParameters.plist
	mac_osx/pandora_fms/pandora_fms
	mac_osx/Pandora FMS.pmdoc
	mac_osx/Pandora FMS.pmdoc/01pandora-contents.xml
	mac_osx/Pandora FMS.pmdoc/01pandora.xml
	mac_osx/Pandora FMS.pmdoc/index.xml
	mac_osx/README
	mac_osx/tentacle_client
	shellscript
	shellscript/linux
	shellscript/bsd-ipso
	shellscript/hp-ux
	shellscript/aix
	shellscript/meta_agent
	shellscript/mac_osx
	shellscript/solaris
	shellscript/openWRT
	openWRT
	openWRT/pandora_agent_async
	openWRT/pandora_serialread
	openWRT/contrib
	openWRT/contrib/pandora_agent_installer
	openWRT/contrib/S55pandora
	openWRT/contrib/pandora_agent_daemon
	openWRT/pandora_getsync
	openWRT/pandora_agent
	openWRT/AUTHORS
	openWRT/pandora_agent.conf
	openWRT/pandora_arduino.c
	openWRT/pandora_user.conf
	openWRT/COPYING
	openWRT/README.openwrt
	openWRT/README
	linux
	linux/pandora_agent_installer
	linux/plugins
	linux/plugins/inventory
	linux/plugins/pandora_df
	linux/plugins/grep_log
	linux/DEBIAN
	linux/DEBIAN/control
	linux/DEBIAN/postinst
	linux/DEBIAN/prerm
	linux/DEBIAN/conffiles
	linux/DEBIAN/make_deb_package.sh
	linux/DEBIAN/md5sums
	linux/pandora_agent
	linux/AUTHORS
	linux/pandora_agent_daemon
	linux/pandora_agent.conf
	linux/COPYING
	linux/pandora_agent.spec
	linux/README
	linux/tentacle_client
	hp-ux
	hp-ux/pandora_agent_installer
	hp-ux/pandora_agent
	hp-ux/AUTHORS
	hp-ux/pandora_agent_daemon
	hp-ux/pandora_agent.conf
	hp-ux/COPYING
	hp-ux/README
	meta_agent
	meta_agent/data_out
	meta_agent/pandora_agent_sim.sh
	meta_agent/AUTHORS
	meta_agent/pandora_agent_daemon
	meta_agent/INSTALL
	meta_agent/pandora_agent_1.conf
	meta_agent/pandora_agent_2.conf
	meta_agent/COPYING
	meta_agent/pandora_agent_3.conf
	meta_agent/pandora_agent_4.conf
	meta_agent/pandora_agent_5.conf
	meta_agent/README
	meta_agent/muestra_config.sh
	solaris
	solaris/pandora_agent_installer
	solaris/data_out
	solaris/pandora_agent
	solaris/AUTHORS
	solaris/pandora_agent_daemon
	solaris/pandora_agent.conf
	solaris/pandora_user.conf
	solaris/COPYING
	solaris/README: Reorganise the shellscript moving
	all the sh scripts to one folder



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@3778 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
2011-01-26 19:07:43 +00:00

342 lines
9.5 KiB
Bash
Executable File

#!/usr/bin/ksh
# **********************************************************************
# Pandora FMS Solaris Agent
# (c) 2009 Artica Soluciones Tecnológicas SL
# with the help of many people. Please see http://pandorafms.org
# This code is licensed under GPL 2.0 license.
# **********************************************************************
AGENT_VERSION="1.3"
OLDIFS=$IFS
# Stupid trick to use IFS in Solaris/AIX ... doesnt work standard $'\n' :-?
NEWIFS="
"
# Begin cycle for adquire primary config tokens
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
if [ -z "$1" ]
then
echo " "
echo "FATAL ERROR: I need an argument to PANDORA AGENT home path"
echo " "
echo " example: /usr/share/pandora_agent/pandora_agent /etc/pandora "
echo " "
exit
else
PANDORA_HOME=$1
fi
if [ -z "`cat $PANDORA_HOME/pandora_agent.conf`" ]
then
echo " "
echo "FATAL ERROR: Cannot load $PANDORA_HOME/pandora_agent.conf"
echo " "
exit
fi
echo "$TIMESTAMP - Reading general config parameters from .conf file" >> $PANDORA_HOME/pandora.log
# Default values
DEBUG_MODE=0
CHECKSUM_MODE=0
DELAYED_STARTUP=0
SERVER_PORT=22
PANDORA_NICE=20
INTERVAL=300
TRANSFER_MODE=ssh
IFS=$NEWIFS
for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v "^#" | grep -v "^module" `
do
a=`echo $a | tr -s " " " "`
# Get general configuration parameters from config file
if [ ! -z "`echo $a | grep '^server_ip'`" ]
then
SERVER_IP=`echo $a | awk '{ print $2 }'`
echo "$TIMESTAMP - [SETUP] - Server IP Address is $SERVER_IP" >> $PANDORA_HOME/pandora.log
fi
if [ ! -z "`echo $a | grep '^server_path'`" ]
then
SERVER_PATH=`echo $a | awk '{ print $2 }'`
echo "$TIMESTAMP - [SETUP] - Server Path is $SERVER_PATH" >> $PANDORA_HOME/pandora.log
fi
if [ ! -z "`echo $a | grep '^temporal'`" ]
then
TEMP=`echo $a | awk '{ print $2 }'`
echo "$TIMESTAMP - [SETUP] - Temporal Path is $TEMP" >> $PANDORA_HOME/pandora.log
fi
if [ ! -z "`echo $a | grep '^interval'`" ]
then
INTERVAL=`echo $a | awk '{ print $2 }'`
echo "$TIMESTAMP - [SETUP] - Interval is $INTERVAL seconds" >> $PANDORA_HOME/pandora.log
fi
if [ ! -z "`echo $a | grep '^agent_name'`" ]
then
NOMBRE_HOST=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Agent name is $NOMBRE_HOST " >> $PANDORA_HOME/pandora.log
fi
if [ ! -z "`echo $a | grep '^debug'`" ]
then
DEBUG_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Debug mode $DEBUG_MODE " >> $PANDORA_HOME/pandora.log
fi
if [ ! -z "`echo $a | grep '^checksum'`" ]
then
CHECKSUM_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Checksum mode is $CHECKSUM_MODE " >> $PANDORA_HOME/pandora.log
fi
if [ ! -z "`echo $a | grep '^delayed_startup'`" ]
then
DELAYED_STARTUP=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - DELAYED_STARTUP is $DELAYED_STARTUP" >> $PANDORA_LOGFILE
fi
# CPU protection
if [ ! -z "`echo $a | grep '^pandora_nice'`" ]
then
PANDORA_NICE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - PandoraFMS Nice is $PANDORA_NICE" >> $PANDORA_LOGFILE
fi
# Contribution of daggett
if [ ! -z "`echo $a | grep '^server_port'`" ]
then
SERVER_PORT=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server Port is $SERVER_PORT" >> $PANDORA_LOGFILE
fi
# Contribution of daggett
if [ ! -z "`echo $a | grep '^encoding'`" ]
then
ENCODING=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Encoding is $ENCODING" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep '^transfer_mode'`" ]
then
TRANSFER_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Transfer Mode is $TRANSFER_MODE" >> $PANDORA_LOGFILE
fi
done
# Script banner at start
echo "Pandora FMS Agent $AGENT_VERSION (c) Sancho Lerena 2007"
echo "This program is licensed under GPL2 Terms. http://pandora.sf.net"
echo "Running in $NOMBRE_HOST at $TIMESTAMP"
echo " "
if [ $DELAYED_STARTUP != 0 ]
then
echo "Delayed startup in $DELAYED_STARTUP minutes "
echo "Delayed startup in $DELAYED_STARTUP minutes" >> $PANDORA_LOGFILE.err
echo " "
sleep $(($DELAYED_STARTUP*60))
fi
# MAIN Program loop begin
# OS Data
OS_VERSION=`uname -v`
OS_VERSION=$OS_VERSION.`uname -r`
OS_NAME=`uname -s`
# Hostname
if [ -z "$NOMBRE_HOST" ]
then
NOMBRE_HOST=`/bin/hostname`
fi
# Default values
CONTADOR=0
EXECUTE=1
MODULE_END=0
# Renice me
renice $PANDORA_NICE $$
while [ "1" = "1" ]
do
# Fecha y hora. Se genera un serial (numero de segundos desde 1970) para cada paquete generado.
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
SERIAL=`date +"%S%M%m%H"`
# Nombre de los archivos
DATA=$TEMP/$NOMBRE_HOST.$SERIAL.data
CHECKSUM=$TEMP/$NOMBRE_HOST.$SERIAL.checksum
PANDORA_FILES="$TEMP/$NOMBRE_HOST.$SERIAL.*"
DATA2=$TEMP/$NOMBRE_HOST.$SERIAL.data_temp
# Make some checks
if [ "$TRANSFER_MODE" = "ftp" ]
then
if [ ! -f $HOME/.netrc ]
then
echo "(EE) Transfer mode is FTP but there is no usable .netrc file. Aborting."
exit
fi
fi
if [ "$DEBUG_MODE" = "1" ]
then
echo "(**) Warning: Running in DEBUG mode"
fi
# Makes data packet
echo "<agent_data os_name='$OS_NAME' os_version='$OS_VERSION' interval='$INTERVAL' version='$AGENT_VERSION' timestamp='$TIMESTAMP' agent_name='$NOMBRE_HOST'>" > $DATA
if [ "$DEBUG_MODE" = "1" ]
then
echo "$TIMESTAMP - Reading module adquisition data from .conf file" >> $PANDORA_HOME/pandora.log
DEBUGOUTPUT=$PANDORA_HOME/pandora.log
else
DEBUGOUTPUT=/dev/null
fi
for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v "^#" | grep "^module" `
do
a=`echo $a | tr -s " " " "`
if [ ! -z "`echo $a | grep '^module_exec'`" ]
then
if [ $EXECUTE -eq 0 ]
then
execution=`echo $a | cut -c 13-`
res=`eval $execution 2> /dev/null`
if [ -z "$flux_string" ]
then
res=`eval expr $res 2> /dev/null`
fi
echo "<data>$res</data>" >> $DATA2
fi
fi
if [ ! -z "`echo $a | grep '^module_name'`" ]
then
name=`echo $a | cut -c 13-`
echo "<name>$name</name>" >> $DATA2
fi
if [ ! -z "`echo $a | grep '^module_begin'`" ]
then
echo "<module>" >> $DATA2
EXECUTE=0
fi
if [ ! -z "`echo $a | grep '^module_max' `" ]
then
max=`echo $a | awk '{ print $2 }' `
echo "<max>$max</max>" >> $DATA2
fi
if [ ! -z "`echo $a | grep '^module_min'`" ]
then
min=`echo $a | awk '{ print $2 }' `
echo "<min>$min</min>" >> $DATA2
fi
if [ ! -z "`echo $a | grep '^module_description'`" ]
then
desc=`echo $a | cut -c 20- `
echo "<description>$desc</description>" >> $DATA2
fi
if [ ! -z "`echo $a | grep '^module_end'`" ]
then
MODULE_END=1
echo "</module>" >> $DATA2
else
MODULE_END=0
fi
if [ ! -z "`echo $a | grep '^module_type'`" ]
then
mtype=`echo $a | cut -c 13-`
if [ ! -z "`echo $mtype | grep 'generic_data_string'`" ]
then
flux_string=1
else
flux_string=0
unset flux_string
fi
echo "<type>$mtype</type>" >> $DATA2
fi
if [ ! -z "`echo $a | grep '^module_interval'`" ]
then
# Determine if execution is to be done
MODULEINTERVAL=`echo $a | awk '{ print $2 }'`
EXECUTE=`expr \( $CONTADOR + 1 \) % $MODULEINTERVAL`
fi
# If module end, and execute for this module is enabled
# then write
if [ $MODULE_END -eq "1" ]
then
if [ $EXECUTE -eq "0" ]
then
cat $DATA2 >> $DATA
fi
rm -Rf $DATA2 #> /dev/null 2> /dev/null
fi
done
# Count number of agent runs
CONTADOR=`expr $CONTADOR + 1`
# Keep a limit of 100 for overflow reasons
if [ $CONTADOR -eq 100 ]
then
CONTADOR=0
fi
# Call for user-defined script for data adquisition
if [ -f "$PANDORA_HOME/pandora_user.conf" ]
then
/bin/sh $PANDORA_HOME/pandora_user.conf >> $DATA 2> /dev/null
fi
# Finish data packet
echo "</agent_data>" >> $DATA
echo "$TIMESTAMP - Finish writing XML $DATA" >> $DEBUGOUTPUT
# Calculate Checksum and prepare MD5 file
if [ "$CHECKSUM_MODE" = 1 ]
then
CHECKSUM_DATA=`cat $DATA | md5 `
echo $CHECKSUM_DATA $DATA> $CHECKSUM
else
echo "NO MD5 CHECKSUM AVAILABLE" > $CHECKSUM
fi
# Debug mode
if [ "$DEBUG_MODE" = "1" ]
then
echo "$TIMESTAMP - Finish writing XML $DATA" >> $PANDORA_LOGFILE
echo "(**) Data file is at $DATA - Exiting now"
echo " "
exit 0
fi
# Send packets to server and delete it
if [ "$TRANSFER_MODE" = "ssh" ]
then
scp -P $SERVER_PORT $PANDORA_FILES pandora@$SERVER_IP:$SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
fi
if [ "$TRANSFER_MODE" = "ftp" ]
then
ftp $SERVER_IP > /dev/null 2> $PANDORA_LOGFILE.err
fi
if [ "$TRANSFER_MODE" = "local" ]
then
cp $PANDORA_FILES $SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
fi
# Delete data
rm -f $PANDORA_FILES> /dev/null 2> $PANDORA_LOGFILE.err
# Go to bed :-)
sleep $INTERVAL
done
# forever!