From 7bcf6f642c72be135765227ff463d79cea3b9d56 Mon Sep 17 00:00:00 2001 From: Ramon Novoa Date: Wed, 10 Dec 2008 12:32:55 +0000 Subject: [PATCH] 2008-12-10 Ramon Novoa * linux/pandora_agent, linux/pandora_agent.conf: Added support for a secondary server. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1283 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/linux/pandora_agent | 151 ++++++++++++++++++------ pandora_agents/linux/pandora_agent.conf | 15 +++ 2 files changed, 130 insertions(+), 36 deletions(-) diff --git a/pandora_agents/linux/pandora_agent b/pandora_agents/linux/pandora_agent index 8df1124be6..9c54f203dc 100755 --- a/pandora_agents/linux/pandora_agent +++ b/pandora_agents/linux/pandora_agent @@ -8,7 +8,7 @@ # ********************************************************************** AGENT_VERSION=2.0 -AGENT_BUILD=080529 +AGENT_BUILD=081210 # ********************************************************************** # function configure_agent() @@ -25,68 +25,55 @@ function configure_agent { 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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -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'`" ] + elif [ ! -z "`echo $a | grep -e '^server_pwd'`" ] then SERVER_PWD=`echo $a | awk '{ print $2 }' ` if [ ! -z "$SERVER_PWD" ] @@ -94,8 +81,7 @@ function configure_agent { 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'`" ] + elif [ ! -z "`echo $a | grep -e '^server_ssl'`" ] then SERVER_SSL=`echo $a | awk '{ print $2 }' ` if [ "$SERVER_SSL" == "yes" ] @@ -103,13 +89,11 @@ function configure_agent { 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 + elif [ ! -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'`" ] + elif [ ! -z "`echo $a | grep -e '^server_opts'`" ] then SERVER_OPTS=`echo $a | cut -d" " -f2-` if [ ! -z "$SERVER_OPTS" ] @@ -117,15 +101,59 @@ function configure_agent { 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'`" ] + elif [ ! -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 + # Secondary server configuration + elif [ ! -z "`echo $a | grep -e '^secondary_mode'`" ] + then + SECONDARY_MODE=`echo $a | awk '{ print $2 }' ` + echo "$TIMESTAMP - [SETUP] - Secondary server mode is '$SECONDARY_MODE'" >> $PANDORA_LOGFILE + elif [ ! -z "`echo $a | grep -e '^secondary_transfer_mode'`" ] + then + SECONDARY_TRANSFER_MODE=`echo $a | awk '{ print $2 }' ` + echo "$TIMESTAMP - [SETUP] - Secondary transfer Mode is $SECONDARY_TRANSFER_MODE" >> $PANDORA_LOGFILE + elif [ ! -z "`echo $a | grep -e '^secondary_server_ip'`" ] + then + SECONDARY_SERVER_IP=`echo $a | awk '{ print $2 }' ` + echo "$TIMESTAMP - [SETUP] - Secondary server IP Address is $SECONDARY_SERVER_IP" >> $PANDORA_LOGFILE + elif [ ! -z "`echo $a | grep -e '^secondary_server_path'`" ] + then + SECONDARY_SERVER_PATH=`echo $a | awk '{ print $2 }' ` + echo "$TIMESTAMP - [SETUP] - Secondary server Path is $SECONDARY_SERVER_PATH" >> $PANDORA_LOGFILE + elif [ ! -z "`echo $a | grep -e '^secondary_server_port'`" ] + then + SECONDARY_SERVER_PORT=`echo $a | awk '{ print $2 }' ` + echo "$TIMESTAMP - [SETUP] - Secondary server Port is $SECONDARY_SERVER_PORT" >> $PANDORA_LOGFILE + elif [ ! -z "`echo $a | grep -e '^secondary_server_pwd'`" ] + then + SECONDARY_SERVER_PWD=`echo $a | awk '{ print $2 }' ` + if [ ! -z "$SECONDARY_SERVER_PWD" ] + then + SECONDARY_TENTACLE_OPTS="-x $SECONDARY_SERVER_PWD $SECONDARY_TENTACLE_OPTS" + echo "$TIMESTAMP - [SETUP] - Secondary server password set (FTP/Tentacle)" >> $PANDORA_LOGFILE + fi + elif [ ! -z "`echo $a | grep -e '^secondary_server_ssl'`" ] + then + SECONDARY_SERVER_SSL=`echo $a | awk '{ print $2 }' ` + if [ "$SECONDARY_SERVER_SSL" == "yes" ] + then + SECONDARY_TENTACLE_OPTS="-c $SECONDARY_TENTACLE_OPTS" + echo "$TIMESTAMP - [SETUP] - OpenSSL enabled for secondary Tentacle" >> $PANDORA_LOGFILE + fi + elif [ ! -z "`echo $a | grep -e '^secondary_server_opts'`" ] + then + SECONDARY_SERVER_OPTS=`echo $a | cut -d" " -f2-` + if [ ! -z "$SERVER_OPTS" ] + then + SECONDARY_TENTACLE_OPTS="$SECONDARY_SERVER_OPTS $SECONDARY_TENTACLE_OPTS" + echo "$TIMESTAMP - [SETUP] - Extra options for the secondary Tentacle client $SECONDARY_SERVER_OPTS" >> $PANDORA_LOGFILE + fi fi done @@ -210,6 +238,34 @@ FEOF1 return 1 } +# ********************************************************************** +# function send_file_secure(file) +# Sends the file to the available server. +# ********************************************************************** +function send_file_secure { + FILE="$1" + + send_file "$FILE" + RC=$? + + # Always send the file to the secondary server + if [ "$SECONDARY_MODE" = "always" ]; then + switch_servers + send_file "$FILE" + switch_servers + # Send the file to the secondary server only if something went wrong + elif [ "$SECONDARY_MODE" = "on_error" ]; then + if [ $RC != 0 ]; then + switch_servers + send_file "$FILE" + RC=$? + switch_servers + fi + fi + + return $RC +} + # ********************************************************************** # function recv_file(file) # Gets a file from the server and saves it under $TEMP. Paths are not @@ -256,6 +312,29 @@ FEOF1 return 1 } +# ********************************************************************** +# function switch(var1, var2) +# Switches the values of var1 and var2 +# ********************************************************************** +function switch { + eval "TEMP=\"\$$1\"" + eval "$1=\"\$$2\"" + eval "$2=\"\$TEMP\"" +} + +# ********************************************************************** +# function switch_servers() +# Switches the target server +# ********************************************************************** +function switch_servers { + switch TRANSFER_MODE SECONDARY_TRANSFER_MODE + switch SERVER_IP SECONDARY_SERVER_IP + switch SERVER_PORT SECONDARY_SERVER_PORT + switch TENTACLE_OPTS SECONDARY_TENTACLE_OPTS + switch SERVER_PATH SECONDARY_SERVER_PATH + switch SERVER_PWD SECONDARY_SERVER_PWD +} + # ********************************************************************** # function check_remote_config() # Checks for a newer remote configuration file. @@ -557,7 +636,7 @@ do fi # Send packets to server and delete it - send_file $DATA + send_file_secure $DATA # Delete data rm -f $DATA > /dev/null 2> $PANDORA_LOGFILE.err diff --git a/pandora_agents/linux/pandora_agent.conf b/pandora_agents/linux/pandora_agent.conf index 2187f66569..3f9872bb32 100755 --- a/pandora_agents/linux/pandora_agent.conf +++ b/pandora_agents/linux/pandora_agent.conf @@ -59,6 +59,21 @@ transfer_mode tentacle # If set to 1 allows the agent to be configured via the web console. # remote_config 0 +# Secondary server configuration +# ============================== + +# If secondary_mode is set to on_error, data files are copied to the secondary +# server only if the primary server fails. If set to always, data files are +# always copied to the secondary server. +# secondary_mode on_error +# secondary_server_ip localhost +# secondary_server_path /var/spool/pandora/data_in +# secondary_server_port 41121 +# secondary_transfer_mode tentacle +# secondary_server_pwd mypassword +# secondary_server_ssl no +# secondary_server_opts + # Module Definition # =================