2008-06-09 Ramon Novoa <rnovoa@artica.es>
* linux/plugins/grep_log: Fixed command line parameter check. * linux/pandora_agent: Added support for remote configuration. * linux/pandora_agent.conf: Added remote_config option git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@843 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
cc2f81acb4
commit
390e5932c4
|
@ -1,3 +1,9 @@
|
|||
2008-06-09 Ramon Novoa <rnovoa@artica.es>
|
||||
|
||||
* linux/plugins/grep_log: Fixed command line parameter check.
|
||||
* linux/pandora_agent: Added support for remote configuration.
|
||||
* linux/pandora_agent.conf: Added remote_config option.
|
||||
|
||||
2008-05-29 Sancho Lerena <slerena@gmail.com>
|
||||
|
||||
* openWRT/README.openwrt: Some additional information about wput command
|
||||
|
|
|
@ -8,54 +8,13 @@
|
|||
# **********************************************************************
|
||||
|
||||
AGENT_VERSION=2.0
|
||||
AGENT_BUILD=080525
|
||||
AGENT_BUILD=080529
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo " "
|
||||
echo "Fatal error: I need an argument to Pandora FMS Agent config directory"
|
||||
echo " "
|
||||
echo " example: pandora_agent /etc/pandora "
|
||||
echo " "
|
||||
exit -1
|
||||
else
|
||||
PANDORA_HOME=$1
|
||||
fi
|
||||
|
||||
if [ ! -f $PANDORA_HOME/pandora_agent.conf ]
|
||||
then
|
||||
echo " "
|
||||
echo "FATAL ERROR: Cannot load $PANDORA_HOME/pandora_agent.conf"
|
||||
echo " "
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# Init internal variables
|
||||
CONTADOR=0
|
||||
EXECUTE=1
|
||||
MODULE_END=0
|
||||
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
|
||||
IFS=$'\n'
|
||||
|
||||
# Default values
|
||||
DEBUG_MODE=0
|
||||
DELAYED_STARTUP=0
|
||||
SERVER_PORT=22
|
||||
PANDORA_NICE=0
|
||||
INTERVAL=300
|
||||
TRANSFER_MODE=ssh
|
||||
CRON_MODE=0
|
||||
if [ -z "`echo $LANG | grep '\.'`" ]
|
||||
then
|
||||
ENCODING="iso-8859-1"
|
||||
else
|
||||
ENCODING=`echo $LANG | cut -f 2 -d "."`
|
||||
fi
|
||||
|
||||
NOMBRE_HOST=`/bin/hostname`
|
||||
OS_NAME=`uname -s`
|
||||
PANDORA_LOGFILE=/var/log/pandora/pandora_agent.log
|
||||
TEMP=/tmp
|
||||
# **********************************************************************
|
||||
# function configure_agent()
|
||||
# Parses the configuration file and configures the agent.
|
||||
# **********************************************************************
|
||||
function configure_agent {
|
||||
|
||||
# Read config file
|
||||
for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v -e "^#" | grep -v -e "^module" `
|
||||
|
@ -152,15 +111,267 @@ do
|
|||
fi
|
||||
if [ ! -z "`echo $a | grep -e '^server_opts'`" ]
|
||||
then
|
||||
SERVER_OPTS=`echo $a | awk -F'"' '{ print $2 }' `
|
||||
SERVER_OPTS=`echo $a | cut -d" " -f2-`
|
||||
if [ ! -z "$SERVER_OPTS" ]
|
||||
then
|
||||
TENTACLE_OPTS="$SERVER_OPTS $TENTACLE_OPTS"
|
||||
echo "$TIMESTAMP - [SETUP] - Extra options for the Tentacle client $SERVER_OPTS" >> $PANDORA_LOGFILE
|
||||
fi
|
||||
fi
|
||||
# Remote configuration
|
||||
if [ ! -z "`echo $a | grep -e '^remote_config'`" ]
|
||||
then
|
||||
REMOTE_CONFIG=`echo $a | awk '{ print $2 }'`
|
||||
if [ "$REMOTE_CONFIG" == "1" ]
|
||||
then
|
||||
echo "$TIMESTAMP - [SETUP] - Remote configuration enabled" >> $PANDORA_LOGFILE
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$CRON_MODE" == "0" ]
|
||||
then
|
||||
# Script banner at start
|
||||
echo "Pandora FMS Agent $AGENT_VERSION (c) Sancho Lerena 2003-2008"
|
||||
echo "This program is licensed under GPL2 Terms. http://pandora.sf.net"
|
||||
echo "Running in $NOMBRE_HOST at $TIMESTAMP"
|
||||
echo " "
|
||||
else
|
||||
# Checks if there is another instance running
|
||||
PID_RUNNING=`pidof -x pandora_agent`
|
||||
PID_ME=$$
|
||||
if [ "$PID_ME" != "$PID_RUNNING" ]
|
||||
then
|
||||
echo "Aborting execution. Another instance of Pandora FMS running"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
# Make some checks
|
||||
|
||||
if [ "$DEBUG_MODE" == "1" ]
|
||||
then
|
||||
echo "(**) Warning: Running in DEBUG mode"
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
# Renice me
|
||||
renice $PANDORA_NICE $$ 2> /dev/null > /dev/null
|
||||
}
|
||||
|
||||
# **********************************************************************
|
||||
# function send_file(file)
|
||||
# Sends a file to the server.
|
||||
# **********************************************************************
|
||||
function send_file {
|
||||
FILE="$1"
|
||||
|
||||
if [ "$TRANSFER_MODE" == "tentacle" ]
|
||||
then
|
||||
eval tentacle_client -v -a $SERVER_IP -p $SERVER_PORT $TENTACLE_OPTS $FILE > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ "$TRANSFER_MODE" == "ssh" ]
|
||||
then
|
||||
scp -P $SERVER_PORT $FILE pandora@$SERVER_IP:$SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ "$TRANSFER_MODE" == "ftp" ]
|
||||
then
|
||||
BASENAME=`basename $FILE`
|
||||
DIRNAME=`dirname $FILE`
|
||||
|
||||
ftp -n $SERVER_IP $SERVER_PORT > /dev/null 2> $PANDORA_LOGFILE.err <<FEOF1
|
||||
quote USER pandora
|
||||
quote PASS $SERVER_PWD
|
||||
lcd "$DIRNAME"
|
||||
cd "$SERVER_PATH"
|
||||
put "$BASENAME"
|
||||
quit
|
||||
FEOF1
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ "$TRANSFER_MODE" == "local" ]
|
||||
then
|
||||
cp $FILE $SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
return $?
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# **********************************************************************
|
||||
# function recv_file(file)
|
||||
# Gets a file from the server and saves it under $TEMP. Paths are not
|
||||
# allowed.
|
||||
# **********************************************************************
|
||||
function recv_file {
|
||||
FILE="$1"
|
||||
|
||||
if [ "$TRANSFER_MODE" == "tentacle" ]
|
||||
then
|
||||
WD=`pwd`
|
||||
cd $TEMP
|
||||
eval tentacle_client -v -g -a $SERVER_IP -p $SERVER_PORT $TENTACLE_OPTS $FILE > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
STATUS=$?
|
||||
cd $WD
|
||||
return $STATUS
|
||||
fi
|
||||
|
||||
if [ "$TRANSFER_MODE" == "ssh" ]
|
||||
then
|
||||
scp -P $SERVER_PORT pandora@$SERVER_IP:$SERVER_PATH/$FILE $TEMP > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ "$TRANSFER_MODE" == "ftp" ]
|
||||
then
|
||||
ftp -n $SERVER_IP $SERVER_PORT > /dev/null 2> $PANDORA_LOGFILE.err <<FEOF1
|
||||
quote USER pandora
|
||||
quote PASS $SERVER_PWD
|
||||
lcd "$TEMP"
|
||||
cd "$SERVER_PATH"
|
||||
get "$FILE"
|
||||
quit
|
||||
FEOF1
|
||||
return $?
|
||||
fi
|
||||
|
||||
if [ "$TRANSFER_MODE" == "local" ]
|
||||
then
|
||||
cp $SERVER_PATH/$FILE $TEMP > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
return $?
|
||||
fi
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
# **********************************************************************
|
||||
# function check_remote_config()
|
||||
# Checks for a newer remote configuration file.
|
||||
# **********************************************************************
|
||||
function check_remote_config {
|
||||
|
||||
if [ "$REMOTE_CONFIG" != "1" ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Disabled in DEBUG mode
|
||||
if [ "$DEBUG_MODE" == "1" ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Agent name md5sum
|
||||
AGENT_MD5=`echo -n $NOMBRE_HOST | md5sum | cut -d" " -f1`
|
||||
CONFIG_FILE="$AGENT_MD5.conf"
|
||||
MD5_FILE="$AGENT_MD5.md5"
|
||||
|
||||
# Local config file md5sum
|
||||
CONFIG_MD5=`md5sum $PANDORA_HOME/pandora_agent.conf | cut -d" " -f1`
|
||||
|
||||
# Get remote config file md5sum
|
||||
recv_file "$MD5_FILE"
|
||||
|
||||
# Configuration has not been uploaded to the server
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo "$TIMESTAMP - Uploading configuration for the first time" >> $PANDORA_LOGFILE
|
||||
cp "$PANDORA_HOME/pandora_agent.conf" "$TEMP/$CONFIG_FILE"
|
||||
echo "$CONFIG_MD5" > "$TEMP/$MD5_FILE"
|
||||
send_file "$TEMP/$CONFIG_FILE"
|
||||
send_file "$TEMP/$MD5_FILE"
|
||||
rm -f "$TEMP/$CONFIG_FILE"
|
||||
rm -f "$TEMP/$MD5_FILE"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Check for configuration changes
|
||||
REMOTE_MD5=`cat $TEMP/$MD5_FILE`
|
||||
rm -f "$TEMP/$MD5_FILE"
|
||||
if [ "$REMOTE_MD5" == "$CONFIG_MD5" ]
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "$TIMESTAMP - Configuration has changed" >> $PANDORA_LOGFILE
|
||||
recv_file "$CONFIG_FILE"
|
||||
|
||||
if [ $? != 0 ]
|
||||
then
|
||||
echo "$TIMESTAMP - Error retrieving configuration file" > $PANDORA_LOGFILE.err
|
||||
return 1
|
||||
fi
|
||||
|
||||
mv "$TEMP/$CONFIG_FILE" "$PANDORA_HOME/pandora_agent.conf"
|
||||
|
||||
# Reload configuration
|
||||
configure_agent
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
# **********************************************************************
|
||||
# Main
|
||||
# **********************************************************************
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo " "
|
||||
echo "Fatal error: I need an argument to Pandora FMS Agent config directory"
|
||||
echo " "
|
||||
echo " example: pandora_agent /etc/pandora "
|
||||
echo " "
|
||||
exit -1
|
||||
else
|
||||
PANDORA_HOME=$1
|
||||
fi
|
||||
|
||||
if [ ! -f $PANDORA_HOME/pandora_agent.conf ]
|
||||
then
|
||||
echo " "
|
||||
echo "FATAL ERROR: Cannot load $PANDORA_HOME/pandora_agent.conf"
|
||||
echo " "
|
||||
exit -1
|
||||
fi
|
||||
|
||||
# Init internal variables
|
||||
CONTADOR=0
|
||||
EXECUTE=1
|
||||
MODULE_END=0
|
||||
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
|
||||
IFS=$'\n'
|
||||
|
||||
# Default values
|
||||
DEBUG_MODE=0
|
||||
DELAYED_STARTUP=0
|
||||
SERVER_PORT=22
|
||||
PANDORA_NICE=0
|
||||
INTERVAL=300
|
||||
TRANSFER_MODE=ssh
|
||||
CRON_MODE=0
|
||||
if [ -z "`echo $LANG | grep '\.'`" ]
|
||||
then
|
||||
ENCODING="iso-8859-1"
|
||||
else
|
||||
ENCODING=`echo $LANG | cut -f 2 -d "."`
|
||||
fi
|
||||
|
||||
NOMBRE_HOST=`/bin/hostname`
|
||||
OS_NAME=`uname -s`
|
||||
PANDORA_LOGFILE=/var/log/pandora/pandora_agent.log
|
||||
TEMP=/tmp
|
||||
|
||||
# Get Linux Distro type and version
|
||||
if [ -f "/etc/SuSE-release" ]
|
||||
|
@ -193,42 +404,8 @@ else
|
|||
fi
|
||||
fi
|
||||
|
||||
if [ "$CRON_MODE" == "0" ]
|
||||
then
|
||||
# Script banner at start
|
||||
echo "Pandora FMS Agent $AGENT_VERSION (c) Sancho Lerena 2003-2008"
|
||||
echo "This program is licensed under GPL2 Terms. http://pandora.sf.net"
|
||||
echo "Running in $NOMBRE_HOST at $TIMESTAMP"
|
||||
echo " "
|
||||
else
|
||||
# Checks if there is another instance running
|
||||
PID_RUNNING=`pidof -x pandora_agent`
|
||||
PID_ME=$$
|
||||
if [ "$PID_ME" != "$PID_RUNNING" ]
|
||||
then
|
||||
echo "Aborting execution. Another instance of Pandora FMS running"
|
||||
exit
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Make some checks
|
||||
|
||||
if [ "$DEBUG_MODE" == "1" ]
|
||||
then
|
||||
echo "(**) Warning: Running in DEBUG mode"
|
||||
fi
|
||||
|
||||
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
|
||||
|
||||
# Renice me
|
||||
renice $PANDORA_NICE $$ 2> /dev/null > /dev/null
|
||||
# Configure this agent
|
||||
configure_agent
|
||||
|
||||
# MAIN Program loop begin
|
||||
|
||||
|
@ -237,6 +414,9 @@ do
|
|||
# Deleted debug / error info on each run to avoid giant logs
|
||||
rm -Rf $PANDORA_LOGFILE.err 2> /dev/null
|
||||
|
||||
# Check for configuration changes if remote_config is enabled
|
||||
check_remote_config
|
||||
|
||||
# Date and time, SERIAL is number of seconds since 1/1/1970, for every packet.
|
||||
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
|
||||
SERIAL=`date +"%s"`
|
||||
|
@ -334,7 +514,7 @@ do
|
|||
then
|
||||
eval $PANDORA_HOME/plugins/$PLUGIN $PARAMS >> $DATA
|
||||
else
|
||||
echo "$PANDORA_HOME/plugins/$PLUGIN not found"
|
||||
echo "$TIMESTAMP - Plugin $PANDORA_HOME/plugins/$PLUGIN not found" > $PANDORA_LOGFILE.err
|
||||
fi
|
||||
fi
|
||||
|
||||
|
@ -377,32 +557,7 @@ do
|
|||
fi
|
||||
|
||||
# Send packets to server and delete it
|
||||
if [ "$TRANSFER_MODE" == "tentacle" ]
|
||||
then
|
||||
eval tentacle_client -v -a $SERVER_IP -p $SERVER_PORT $TENTACLE_OPTS $DATA > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
fi
|
||||
|
||||
if [ "$TRANSFER_MODE" == "ssh" ]
|
||||
then
|
||||
scp -P $SERVER_PORT $DATA pandora@$SERVER_IP:$SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
fi
|
||||
|
||||
if [ "$TRANSFER_MODE" == "ftp" ]
|
||||
then
|
||||
ftp -n $SERVER_IP $SERVER_PORT > /dev/null 2> $PANDORA_LOGFILE.err <<FEOF1
|
||||
quote USER pandora
|
||||
quote PASS $SERVER_PWD
|
||||
lcd "$TEMP"
|
||||
cd "$SERVER_PATH"
|
||||
put "$NOMBRE_HOST.$SERIAL.data"
|
||||
quit
|
||||
FEOF1
|
||||
fi
|
||||
|
||||
if [ "$TRANSFER_MODE" == "local" ]
|
||||
then
|
||||
cp $DATA $SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
fi
|
||||
send_file $DATA
|
||||
|
||||
# Delete data
|
||||
rm -f $DATA > /dev/null 2> $PANDORA_LOGFILE.err
|
||||
|
|
|
@ -56,6 +56,9 @@ transfer_mode tentacle
|
|||
# is much more safe.
|
||||
# cron_mode
|
||||
|
||||
# If set to 1 allows the agent to be configured via the web console.
|
||||
# remote_config 0
|
||||
|
||||
# Module Definition
|
||||
# =================
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ sub parse_log () {
|
|||
###############################################################################
|
||||
|
||||
# Check command line parameters
|
||||
if ($#ARGV != 1) {
|
||||
if ($#ARGV != 2) {
|
||||
print_help();
|
||||
exit 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue