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:
ramonn 2008-06-09 11:27:30 +00:00
parent cc2f81acb4
commit 390e5932c4
4 changed files with 337 additions and 173 deletions

View File

@ -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

View File

@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/bash
# **********************************************************************
# Pandora FMS Generic Host Agent
# GNU/Linux version 2.0
@ -8,7 +8,323 @@
# **********************************************************************
AGENT_VERSION=2.0
AGENT_BUILD=080525
AGENT_BUILD=080529
# **********************************************************************
# 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" `
do
a=`echo $a | tr -s " " " "`
# Get general configuration parameters from config file
if [ ! -z "`echo $a | grep -e '^logfile'`" ]
then
PANDORA_LOGFILE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Pandora Logfile is $PANDORA_LOGFILE" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_ip'`" ]
then
SERVER_IP=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server IP Address is $SERVER_IP" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_path'`" ]
then
SERVER_PATH=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server Path is $SERVER_PATH" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^temporal'`" ]
then
TEMP=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Temporal Path is $TEMP" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^interval'`" ]
then
INTERVAL=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Interval is $INTERVAL seconds" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^agent_name'`" ]
then
NOMBRE_HOST=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Agent name is $NOMBRE_HOST " >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^debug'`" ]
then
DEBUG_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Debug mode is $DEBUG_MODE " >> $PANDORA_LOGFILE
fi
# Contribution of daggett
if [ ! -z "`echo $a | grep -e '^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 -e '^encoding'`" ]
then
ENCODING=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Encoding is $ENCODING" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^transfer_mode'`" ]
then
TRANSFER_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Transfer Mode is $TRANSFER_MODE" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^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 -e '^pandora_nice'`" ]
then
PANDORA_NICE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - PandoraFMS Nice is $PANDORA_NICE" >> $PANDORA_LOGFILE
fi
# Tentacle options
if [ ! -z "`echo $a | grep -e '^server_pwd'`" ]
then
SERVER_PWD=`echo $a | awk '{ print $2 }' `
if [ ! -z "$SERVER_PWD" ]
then
TENTACLE_OPTS="-x $SERVER_PWD $TENTACLE_OPTS"
echo "$TIMESTAMP - [SETUP] - Server password set (FTP/Tentacle)" >> $PANDORA_LOGFILE
fi
fi
if [ ! -z "`echo $a | grep -e '^server_ssl'`" ]
then
SERVER_SSL=`echo $a | awk '{ print $2 }' `
if [ "$SERVER_SSL" == "yes" ]
then
TENTACLE_OPTS="-c $TENTACLE_OPTS"
echo "$TIMESTAMP - [SETUP] - OpenSSL enabled for Tentacle" >> $PANDORA_LOGFILE
fi
fi
if [ ! -z "`echo $a | grep -e '^cron_mode'`" ]
then
CRON_MODE=1
echo "$TIMESTAMP - [SETUP] - Cronmode enabled" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_opts'`" ]
then
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
@ -57,111 +373,6 @@ OS_NAME=`uname -s`
PANDORA_LOGFILE=/var/log/pandora/pandora_agent.log
TEMP=/tmp
# Read config file
for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v -e "^#" | grep -v -e "^module" `
do
a=`echo $a | tr -s " " " "`
# Get general configuration parameters from config file
if [ ! -z "`echo $a | grep -e '^logfile'`" ]
then
PANDORA_LOGFILE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Pandora Logfile is $PANDORA_LOGFILE" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_ip'`" ]
then
SERVER_IP=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server IP Address is $SERVER_IP" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_path'`" ]
then
SERVER_PATH=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Server Path is $SERVER_PATH" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^temporal'`" ]
then
TEMP=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Temporal Path is $TEMP" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^interval'`" ]
then
INTERVAL=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Interval is $INTERVAL seconds" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^agent_name'`" ]
then
NOMBRE_HOST=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Agent name is $NOMBRE_HOST " >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^debug'`" ]
then
DEBUG_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Debug mode is $DEBUG_MODE " >> $PANDORA_LOGFILE
fi
# Contribution of daggett
if [ ! -z "`echo $a | grep -e '^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 -e '^encoding'`" ]
then
ENCODING=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Encoding is $ENCODING" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^transfer_mode'`" ]
then
TRANSFER_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Transfer Mode is $TRANSFER_MODE" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^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 -e '^pandora_nice'`" ]
then
PANDORA_NICE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - PandoraFMS Nice is $PANDORA_NICE" >> $PANDORA_LOGFILE
fi
# Tentacle options
if [ ! -z "`echo $a | grep -e '^server_pwd'`" ]
then
SERVER_PWD=`echo $a | awk '{ print $2 }' `
if [ ! -z "$SERVER_PWD" ]
then
TENTACLE_OPTS="-x $SERVER_PWD $TENTACLE_OPTS"
echo "$TIMESTAMP - [SETUP] - Server password set (FTP/Tentacle)" >> $PANDORA_LOGFILE
fi
fi
if [ ! -z "`echo $a | grep -e '^server_ssl'`" ]
then
SERVER_SSL=`echo $a | awk '{ print $2 }' `
if [ "$SERVER_SSL" == "yes" ]
then
TENTACLE_OPTS="-c $TENTACLE_OPTS"
echo "$TIMESTAMP - [SETUP] - OpenSSL enabled for Tentacle" >> $PANDORA_LOGFILE
fi
fi
if [ ! -z "`echo $a | grep -e '^cron_mode'`" ]
then
CRON_MODE=1
echo "$TIMESTAMP - [SETUP] - Cronmode enabled" >> $PANDORA_LOGFILE
fi
if [ ! -z "`echo $a | grep -e '^server_opts'`" ]
then
SERVER_OPTS=`echo $a | awk -F'"' '{ print $2 }' `
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
done
# Get Linux Distro type and version
if [ -f "/etc/SuSE-release" ]
then
@ -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

View File

@ -46,8 +46,8 @@ transfer_mode tentacle
# for first time when startup Pandora FMS Agent
# delayed_startup 10
#Pandora nice defines priority of execution. Less priority means more intensive execution
#A recommended value is 10. 0 priority means no Pandora CPU protection enabled (default)
# Pandora nice defines priority of execution. Less priority means more intensive execution
# A recommended value is 10. 0 priority means no Pandora CPU protection enabled (default)
# pandora_nice 0
# Cron mode replace Pandora FMS own task schedule each XX interval seconds by the use
@ -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
# =================

View File

@ -205,7 +205,7 @@ sub parse_log () {
###############################################################################
# Check command line parameters
if ($#ARGV != 1) {
if ($#ARGV != 2) {
print_help();
exit 1;
}