2008-05-25 Sancho Lerena <slerena@artica.es>

* linux/pandora_agent: New cron mode, new ftp mode that do not use
        .netrc anymore, uses password embedded into .conf. Also a few fixes
        and removed checksum mode (deprecated!).

        * linux/pandora_agent.conf: Updated .conf



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@838 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2008-05-26 20:45:11 +00:00
parent 2c8242b6fc
commit a35cec0511
3 changed files with 77 additions and 132 deletions

View File

@ -1,3 +1,11 @@
2008-05-25 Sancho Lerena <slerena@artica.es>
* linux/pandora_agent: New cron mode, new ftp mode that do not use
.netrc anymore, uses password embedded into .conf. Also a few fixes
and removed checksum mode (deprecated!).
* linux/pandora_agent.conf: Updated .conf
2008-05-19 Ramon Novoa <rnovoa@artica.es> 2008-05-19 Ramon Novoa <rnovoa@artica.es>
* linux/pandora_agent_installer: Added plugin installation. * linux/pandora_agent_installer: Added plugin installation.

View File

@ -1,14 +1,14 @@
#!/bin/bash #!/bin/bash
# ********************************************************************** # **********************************************************************
# Pandora FMS Generic Host Agent # Pandora FMS Generic Host Agent
# GNU/Linux version 1.3 # GNU/Linux version 2.0
# (c) 2003-2007 Sancho Lerena <slerena@gmail.com> # (c) 2003-2008 Sancho Lerena <slerena@gmail.com>
# with the help of many people. Please see http://pandora.sourceforge.net # with the help of many people. Please see http://pandora.sourceforge.net
# This code is licensed under GPL 2.0 license. # This code is licensed under GPL 2.0 license.
# ********************************************************************** # **********************************************************************
AGENT_VERSION=1.3 AGENT_VERSION=2.0
AGENT_BUILD=070725 AGENT_BUILD=080525
if [ -z "$1" ] if [ -z "$1" ]
then then
@ -38,13 +38,13 @@ TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
IFS=$'\n' IFS=$'\n'
# Default values # Default values
CHECKSUM_MODE=1
DEBUG_MODE=0 DEBUG_MODE=0
DELAYED_STARTUP=0 DELAYED_STARTUP=0
SERVER_PORT=22 SERVER_PORT=22
PANDORA_NICE=0 PANDORA_NICE=0
INTERVAL=300 INTERVAL=300
TRANSFER_MODE=ssh TRANSFER_MODE=ssh
CRON_MODE=0
if [ -z "`echo $LANG | grep '\.'`" ] if [ -z "`echo $LANG | grep '\.'`" ]
then then
ENCODING="iso-8859-1" ENCODING="iso-8859-1"
@ -97,11 +97,7 @@ do
DEBUG_MODE=`echo $a | awk '{ print $2 }' ` DEBUG_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Debug mode is $DEBUG_MODE " >> $PANDORA_LOGFILE echo "$TIMESTAMP - [SETUP] - Debug mode is $DEBUG_MODE " >> $PANDORA_LOGFILE
fi fi
if [ ! -z "`echo $a | grep -e '^checksum'`" ]
then
CHECKSUM_MODE=`echo $a | awk '{ print $2 }' `
echo "$TIMESTAMP - [SETUP] - Checksum is $CHECKSUM_MODE " >> $PANDORA_LOGFILE
fi
# Contribution of daggett # Contribution of daggett
if [ ! -z "`echo $a | grep -e '^server_port'`" ] if [ ! -z "`echo $a | grep -e '^server_port'`" ]
then then
@ -137,7 +133,7 @@ do
if [ ! -z "$SERVER_PWD" ] if [ ! -z "$SERVER_PWD" ]
then then
TENTACLE_OPTS="-x $SERVER_PWD $TENTACLE_OPTS" TENTACLE_OPTS="-x $SERVER_PWD $TENTACLE_OPTS"
echo "$TIMESTAMP - [SETUP] - Tentacle server password set" >> $PANDORA_LOGFILE echo "$TIMESTAMP - [SETUP] - Server password set (FTP/Tentacle)" >> $PANDORA_LOGFILE
fi fi
fi fi
if [ ! -z "`echo $a | grep -e '^server_ssl'`" ] if [ ! -z "`echo $a | grep -e '^server_ssl'`" ]
@ -149,6 +145,11 @@ do
echo "$TIMESTAMP - [SETUP] - OpenSSL enabled for Tentacle" >> $PANDORA_LOGFILE echo "$TIMESTAMP - [SETUP] - OpenSSL enabled for Tentacle" >> $PANDORA_LOGFILE
fi fi
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'`" ] if [ ! -z "`echo $a | grep -e '^server_opts'`" ]
then then
SERVER_OPTS=`echo $a | awk -F'"' '{ print $2 }' ` SERVER_OPTS=`echo $a | awk -F'"' '{ print $2 }' `
@ -192,22 +193,26 @@ else
fi fi
fi fi
# Script banner at start if [ "$CRON_MODE" == "0" ]
echo "Pandora FMS Agent $AGENT_VERSION (c) Sancho Lerena 2007" then
echo "This program is licensed under GPL2 Terms. http://pandora.sf.net" # Script banner at start
echo "Running in $NOMBRE_HOST at $TIMESTAMP" echo "Pandora FMS Agent $AGENT_VERSION (c) Sancho Lerena 2003-2008"
echo " " 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 # 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" ] if [ "$DEBUG_MODE" == "1" ]
then then
@ -223,7 +228,7 @@ then
fi fi
# Renice me # Renice me
renice $PANDORA_NICE $$ renice $PANDORA_NICE $$ 2> /dev/null > /dev/null
# MAIN Program loop begin # MAIN Program loop begin
@ -239,8 +244,6 @@ do
# File names # File names
DATA=$TEMP/$NOMBRE_HOST.$SERIAL.data DATA=$TEMP/$NOMBRE_HOST.$SERIAL.data
DATA2=$TEMP/$NOMBRE_HOST.$SERIAL.data_temp DATA2=$TEMP/$NOMBRE_HOST.$SERIAL.data_temp
CHECKSUM=$TEMP/$NOMBRE_HOST.$SERIAL.checksum
PANDORA_FILES="$TEMP/$NOMBRE_HOST.$SERIAL.*"
# Makes data packet # Makes data packet
echo "<?xml version=\"1.0\" encoding=\"$ENCODING\"?> " > $DATA echo "<?xml version=\"1.0\" encoding=\"$ENCODING\"?> " > $DATA
@ -356,18 +359,6 @@ do
CONTADOR=0 CONTADOR=0
fi fi
# Checking MD5
if [ "$CHECKSUM_MODE" == "1" ]
then
# Calculate Checksum and prepare MD5 file
CHECKSUM_DATA=`md5sum $DATA`
echo $CHECKSUM_DATA > $CHECKSUM
else
CHECKSUM_DATA="No valid checksum"
echo $CHECKSUM_DATA > $CHECKSUM
fi
# Finish data packet # Finish data packet
echo "</agent_data>" >> $DATA echo "</agent_data>" >> $DATA
echo "" >> $DATA echo "" >> $DATA
@ -388,26 +379,39 @@ do
# Send packets to server and delete it # Send packets to server and delete it
if [ "$TRANSFER_MODE" == "tentacle" ] if [ "$TRANSFER_MODE" == "tentacle" ]
then then
eval tentacle_client -v -a $SERVER_IP -p $SERVER_PORT $TENTACLE_OPTS $PANDORA_FILES > /dev/null 2> $PANDORA_LOGFILE.err eval tentacle_client -v -a $SERVER_IP -p $SERVER_PORT $TENTACLE_OPTS $DATA > /dev/null 2> $PANDORA_LOGFILE.err
fi fi
if [ "$TRANSFER_MODE" == "ssh" ] if [ "$TRANSFER_MODE" == "ssh" ]
then then
scp -P $SERVER_PORT $PANDORA_FILES pandora@$SERVER_IP:$SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err scp -P $SERVER_PORT $DATA pandora@$SERVER_IP:$SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
fi fi
if [ "$TRANSFER_MODE" == "ftp" ] if [ "$TRANSFER_MODE" == "ftp" ]
then then
ftp $SERVER_IP > /dev/null 2> $PANDORA_LOGFILE.err 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 fi
if [ "$TRANSFER_MODE" == "local" ] if [ "$TRANSFER_MODE" == "local" ]
then then
cp $PANDORA_FILES $SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err cp $DATA $SERVER_PATH > /dev/null 2> $PANDORA_LOGFILE.err
fi fi
# Delete data # Delete data
rm -f $PANDORA_FILES> /dev/null 2> $PANDORA_LOGFILE.err rm -f $DATA > /dev/null 2> $PANDORA_LOGFILE.err
# Cron mode
if [ "$CRON_MODE" == "1" ]
then
exit
fi
# Go to bed :-) # Go to bed :-)
sleep $INTERVAL sleep $INTERVAL

View File

@ -1,13 +1,14 @@
# Base config file for Pandora FMS agents # Base config file for Pandora FMS agents
# Version 1.2 # Version 2.0
# Licensed under GPL license v2, # Licensed under GPL license v2,
# (c) 2003-2007 Sancho Lerena and others. # (c) 2003-2008 Artica Soluciones Tecnologicas
# (c) 2003-2008 Sancho Lerena <slerena@gmail.com>
# please visit http://pandora.sourceforge.net # please visit http://pandora.sourceforge.net
# General Parameters # General Parameters
# ================== # ==================
server_ip 192.168.50.1 server_ip localhost
server_path /var/spool/pandora/data_in server_path /var/spool/pandora/data_in
temporal /var/spool/pandora/data_out temporal /var/spool/pandora/data_out
logfile /var/log/pandora/pandora_agent.log logfile /var/log/pandora/pandora_agent.log
@ -19,39 +20,41 @@ interval 300
# and does not copy XML to server. # and does not copy XML to server.
debug 0 debug 0
# By default is activated
checksum 0
# By default, agent takes machine name # By default, agent takes machine name
#agent_name adama #agent_name adama
# By default agent try to take default encoding defined in host. # By default agent try to take default encoding defined in host.
# encoding iso-8859-15 # encoding iso-8859-15
# By default is 22 (for ssh) # Listening TCP port for remote server. By default is 41121 (for tentacle)
#server_port 22 # if you want to use SSH use 22, and FTP uses 21.
server_port 21
# tentacle, ftp, ssh or local # Transfer mode: tentacle, ftp, ssh or local
transfer_mode ssh transfer_mode tentacle
# Tentacle server password. Leave empty for no password (default). # Server password (Tentacle or FTP). Leave empty for no password (default).
#server_pwd # server_pwd mypassword
# Set to yes/no to enable/disable OpenSSL support for Tentacle (disabled by default). # Set to yes/no to enable/disable OpenSSL support for Tentacle (disabled by default).
#server_ssl no # server_ssl no
# Extra options for the Tentacle client (for example, server_opts "-v -r 5"). # Extra options for the Tentacle client (for example, server_opts "-v -r 5").
# server_opts # server_opts
# delayed_startup defines number of MINUTES before start execution # delayed_startup defines number of MINUTES before start execution
# for first time when startup Pandora Agent # for first time when startup Pandora FMS Agent
# delayed_startup 10
#delayed_startup 90
#Pandora nice defines priority of execution. Less priority means more intensive execution #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 #A recommended value is 10. 0 priority means no Pandora CPU protection enabled (default)
#pandora_nice 0 # pandora_nice 0
# Cron mode replace Pandora FMS own task schedule each XX interval seconds by the use
# of old style cron. You should add to crontab Pandora FMS agent script to use this mode.
# This is disabled by default, and is not recommended. Use Pandora FMS internal scheduler
# is much more safe.
# cron_mode
# Module Definition # Module Definition
# ================= # =================
@ -117,80 +120,10 @@ module_end
# Process information # Process information
module_begin
module_name apache
module_type generic_proc
module_exec ps -Af | grep apache | grep -v "grep" | wc -l
module_end
module_begin module_begin
module_name sshDaemon module_name sshDaemon
module_type generic_proc module_type generic_proc
module_exec ps -Af | grep sshd | grep -v "grep" | wc -l module_exec ps -Af | grep sshd | grep -v "grep" | wc -l
module_end module_end
# Informational stuff
module_begin
module_name last_syslog
module_type generic_data_string
module_exec tail -1 /var/log/syslog
module_description Last line of syslog
module_end
module_begin
module_name last_login
module_type generic_data_string
module_exec last | head -1
module_description Last connected to system
module_end
# Networking
module_begin
module_name incoming_pkt
module_type generic_data_inc
module_exec netstat -as | grep "incoming packets delivered" | awk '{ print $1 }'
module_description Incoming packets arriving to system
module_end
module_begin
module_name outbound_pkt
module_type generic_data_inc
module_exec netstat -as | grep "requests sent out" | awk '{ print $1 }'
module_description Outbound Packets sent by system
module_end
module_begin
module_name conn_resets
module_type generic_data_inc
module_exec netstat -as | grep "connections reset due to unexpected SYN" | awk '{ print $1 }'
module_description Resets due to unexpected SYN
module_end
module_begin
module_name PandoraNetwork_RAM
module_exec ps aux | grep pandora_network | head -1 | awk '{ print $6 }'
module_type generic_data
module_end
module_begin
module_name PandoraNetwork_CPU
module_exec ps aux | grep pandora_network | head -1 | awk '{print $3}'
module_type generic_data
module_end
module_begin
module_name PandoraDS_RAM
module_exec ps aux | grep pandora_server | head -1 | awk '{ print $6 }'
module_type generic_data
module_end
module_begin
module_name PandoraDS_CPU
module_exec ps aux | grep pandora_server | head -1 | awk '{print $3}'
module_type generic_data
module_end