Update to 2.0. Also new installer

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@919 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
guruevi 2008-07-02 19:25:25 +00:00
parent 2a4b624826
commit 698973343a
5 changed files with 666 additions and 290 deletions

View File

@ -1,2 +1,3 @@
Sancho Lerena <slerena@gmail.com>
Evi Vanoost <vanooste@rcbi.rochester.edu>
Manuel Arostegui <manuel.arostegui@artica.es>
Evi Vanoost <vanooste@rcbi.rochester.edu>

View File

@ -1,15 +1,330 @@
#!/bin/bash
#!/bin/bash
# **********************************************************************
# Pandora FMS Generic Host Agent
# macOS version 1.3.1
# GNU/Linux version 2.0
# (c) 2003-2008 Sancho Lerena <slerena@gmail.com>
# (c) 2007-2008 Evi Vanoost <vanooste@rcbi.rochester.edu>
# with the help of many people. Please see http://pandora.sourceforge.net
# This code is licensed under GPL 2.0 license.
# **********************************************************************
AGENT_VERSION=1.3.1
AGENT_BUILD=080111
AGENT_VERSION=2.0
AGENT_BUILD=080619
# **********************************************************************
# 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
@ -39,13 +354,13 @@ TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
IFS=$'\n'
# Default values
CHECKSUM_MODE=1
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"
@ -58,163 +373,48 @@ 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
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
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] - Tentacle server password set" >> $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 '^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 Distro type and version
if [ $OS_NAME = "Darwin" ]
# Get Linux Distro type and version
if [ -f "/etc/SuSE-release" ]
then
LINUX_DISTRO="Mac OS X"
OS_VERSION=`sw_vers | awk 'NR==2 {print $2}'`
OS_VERSION=`cat /etc/SuSE-release | grep VERSION | cut -f 3 -d " "`
LINUX_DISTRO=SUSE
elif [ -f "/etc/lsb-release" ]
then
OS_VERSION=`cat /etc/lsb-release | grep DISTRIB_RELEASE | cut -f 2 -d "="`
LINUX_DISTRO=UBUNTU
OS_VERSION="UBUNTU $OS_VERSION"
elif [ -f "/etc/debian_version" ]
then
OS_VERSION=`cat /etc/debian_version`
OS_VERSION="DEBIAN $OS_VERSION"
LINUX_DISTRO=DEBIAN
elif [ -f "/etc/fedora-release" ]
then
OS_VERSION=`cat /etc/fedora-release | cut -f 4 -d " "`
OS_VERSION="FEDORA $OS_VERSION"
LINUX_DISTRO=FEDORA
elif [ $OS_NAME = "Darwin" ]
then
LINUX_DISTRO="Mac OS X"
OS_VERSION=`sw_vers | awk 'NR==2 {print $2}'`
else
LINUX_DISTRO=$OS_NAME
OS_VERSION=`uname -r`
LINUX_DISTRO=$OS_NAME
OS_VERSION=`uname -r`
fi
# Script banner at start
echo "Pandora FMS Agent $AGENT_VERSION (c) Sancho Lerena 2004-2008"
echo "This program is licensed under GPL2 Terms. http://pandora.sf.net"
echo "Running in $NOMBRE_HOST at $TIMESTAMP"
echo " "
# 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
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
if [ "$PANDORA_NICE" != "0" ]
then
renice $PANDORA_NICE $$ 2> /dev/null > /dev/null
fi
# Configure this agent
configure_agent
# MAIN Program loop begin
while [ "1" == "1" ]
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"`
@ -222,8 +422,6 @@ do
# File names
DATA=$TEMP/$NOMBRE_HOST.$SERIAL.data
DATA2=$TEMP/$NOMBRE_HOST.$SERIAL.data_temp
CHECKSUM=$TEMP/$NOMBRE_HOST.$SERIAL.checksum
PANDORA_FILES="$TEMP/$NOMBRE_HOST.$SERIAL.*"
# Makes data packet
echo "<?xml version=\"1.0\" encoding=\"$ENCODING\"?> " > $DATA
@ -305,6 +503,19 @@ do
EXECUTE=`expr \( $CONTADOR + 1 \) % $MODULEINTERVAL`
fi
# Plugin execution
if [ ! -z "`echo $a | grep '^module_plugin'`" ]
then
PLUGIN=`echo $a | cut -d" " -f2`
PARAMS=`echo $a | cut -d" " -f3-`
if [ -f $PANDORA_HOME/plugins/$PLUGIN ]
then
eval $PANDORA_HOME/plugins/$PLUGIN $PARAMS >> $DATA
else
echo "$TIMESTAMP - Plugin $PANDORA_HOME/plugins/$PLUGIN not found" > $PANDORA_LOGFILE.err
fi
fi
# If module ends, and execute for this module is enabled
# then write
@ -326,23 +537,6 @@ do
CONTADOR=0
fi
# Call for user-defined script for data adquisition
if [ -f "$PANDORA_HOME/pandora_user.conf" ]
then
/bin/bash $PANDORA_HOME/pandora_user.conf >> $DATA
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
echo "</agent_data>" >> $DATA
echo "" >> $DATA
@ -361,28 +555,16 @@ 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 $PANDORA_FILES > /dev/null 2> $PANDORA_LOGFILE.err
fi
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
send_file $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 :-)
sleep $INTERVAL

View File

@ -1,13 +1,14 @@
# Base config file for Pandora FMS agents
# Version 1.2
# Version 2.0
# 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
# General Parameters
# ==================
server_ip skull
server_ip localhost
server_path /var/spool/pandora/data_in
temporal /var/spool/pandora/data_out
logfile /var/log/pandora/pandora_agent.log
@ -17,10 +18,7 @@ interval 300
# Debug mode only generate XML, and stop after first execution,
# and does not copy XML to server.
debug 0
# By default is activated
checksum 0
debug 1
# By default, agent takes machine name
#agent_name adama
@ -28,29 +26,46 @@ checksum 0
# By default agent try to take default encoding defined in host.
# encoding iso-8859-15
# By default is 22 (for ssh)
#server_port 22
# Listening TCP port for remote server. By default is 41121 (for tentacle)
# if you want to use SSH use 22, and FTP uses 21.
server_port 41121
# ftp, ssh or local
transfer_mode ssh
# Transfer mode: tentacle, ftp, ssh or local
transfer_mode tentacle
# Server password (Tentacle or FTP). Leave empty for no password (default).
# server_pwd mypassword
# Set to yes/no to enable/disable OpenSSL support for Tentacle (disabled by default).
# server_ssl no
# Extra options for the Tentacle client (for example, server_opts "-v -r 5").
# server_opts
# 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
# A recommended value is 10. 0 priority means no Pandora CPU protection enabled (default)
# pandora_nice 0
#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
#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
# If set to 1 allows the agent to be configured via the web console.
# remote_config 0
# Module Definition
# =================
# System information
# System information for clients
module_begin
module_name cpu_user
module_begin
module_name CPU (User)
module_type generic_data
module_interval 1
module_exec iostat -C | tail -1 | awk '{ print $10 }'
@ -59,8 +74,8 @@ module_min 0
module_descripcion User CPU Usage (%)
module_end
module_begin
module_name cpu_sys
module_begin
module_name CPU (System)
module_type generic_data
module_exec iostat -C | tail -1 | awk '{ print $11 }'
module_max 100
@ -68,8 +83,8 @@ module_min 0
module_description System CPU Usage (%)
module_end
module_begin
module_name disk_root_free
module_begin
module_name Disk Space on / (Available)
module_type generic_data
module_exec df -kh / | tail -1 | awk '{ print 100-$5 }'
module_max 100
@ -78,37 +93,39 @@ module_description Free disk Percentage of root partition
module_end
module_begin
module_name memused
module_name Physical Memory (Total)
module_type generic_data
module_exec sysctl -n hw.physmem
module_exec sysctl -n hw.memsize
module_description Used Physical Memory
module_end
module_begin
module_name memfree
module_name Physical Memory (Used)
module_type generic_data
module_exec echo `sysctl -n hw.memsize` - `sysctl -n hw.physmem` | bc
module_exec top -l 1 | grep PhysMem | awk '{gsub("M","",$8)} {print $8}'
module_description Used Physical Memory
module_end
module_begin
module_name proctotal
module_name Processes Total
module_type generic_data
module_exec ps -A | wc -l
module_description Total Processes
module_description Total Number of Processes
module_end
# Hardware information
module_begin
module_name numprocs
module_name CPUs (Number)
module_type generic_data
module_exec system_profiler -detailLevel mini | grep -i "Number of CPUs:" | awk '{ print $4}'
module_max 8
module_min 0
module_exec sysctl -n hw.ncpu
module_max 8
module_min 1
module_description Number of Processors
module_end
module_begin
module_name arch
module_name Architecture
module_type generic_data_string
module_exec arch
module_description Architecture
@ -117,39 +134,227 @@ module_end
# Informational stuff
module_begin
module_name last_syslog
module_name Syslog (Last string)
module_type generic_data_string
module_exec tail -1 /var/log/system.log
module_description Last line of syslog
module_end
module_begin
module_name last_login
module_name Login (Last)
module_type generic_data_string
module_exec last | head -1
module_description Last connected to system
module_end
# Networking
# Networking
module_begin
module_name incoming_pkt
module_name Network Packets (Incoming)
module_type generic_data_inc
module_exec netstat -as | grep "total packets received" | awk '{ print $1 }' | head -1
module_description Incoming packets arriving to system
module_end
module_begin
module_name outbound_pkt
module_name Network Packets (Outgoing)
module_type generic_data_inc
module_exec netstat -as | grep "packets sent from this host" | awk '{ print $1 }' | head -1
module_description Outbound Packets sent by system
module_end
module_begin
module_name conn_resets
module_name Network Packets (Connection Reset)
module_type generic_data_inc
module_exec netstat -as | grep "bad reset" | awk '{ print $1 }'
module_description Bad Resets
module_end
module_begin
module_name Network Adapter en0 Status
module_type generic_proc
module_exec ifconfig en0 | grep status | awk '{ if($6=="active") { print 1}; if($6!="active") {print 0}}'
module_description Ethernet Link 0
module_end
# You should have alerts in case the number of rules change
#module_begin
#module_name Firewall Status
#module_type generic_data
#module_exec ipfw show | wc -l
#module_description Firewall (number of rules)
#module_end
#######################################################################
# #
# The following is for use if you have services (or a server) running #
# This works for most services both in Leopard and Tiger #
# #
#######################################################################
## Uncomment/Comment as you go
#module_begin
#module_name Web (Apache) Status
#module_type generic_proc
#module_exec ps -A | grep "bin\/httpd" | wc -l
#module_description Webserver
#module_end
#module_begin
#module_name AFP
#module_type generic_proc
#module_exec ps -A | grep "sbin\/AppleFileServer" | wc -l
#module_description Apple File Server
#module_end
#module_begin
#module_name Application Server
#module_type generic_proc
#module_exec ps -A | grep "/Library/JBoss/3.2/bin/run.sh" | wc -l
#module_description Application Server (Tomcat & JBoss)
#module_end
#module_begin
#module_name DHCP
#module_type generic_proc
#module_exec ps -A | grep "bootp" | wc -l
#module_description DHCP & BOOTP server
#module_end
#module_begin
#module_name DNS
#module_type generic_proc
#module_exec ps auxw | grep "sbin\/named" | wc -l
#module_description DNS Server
#module_end
#module_begin
#module_name FTP
#module_type generic_proc
#module_exec ps -A | grep "LaunchDaemons\/ftp.plist" | wc -l
#module_description FTP Server
#module_end
#module_begin
#module_name iChat
#module_type generic_proc
#module_exec ps -A | grep "jabberd -c \/etc" | wc -l
#module_description iChat (jabber) Server
#module_end
#module_begin
#module_name Mail (SMTP)
#module_type generic_proc
#module_exec ps -axu | grep "postfix" | grep -v "grep" | wc -l
#module_description Mail - SMTP Server (postfix)
#module_end
#module_begin
#module_name Mail (IMAP)
#module_type generic_proc
#module_exec ps -axu | grep "master" | grep "cyrus" | grep -v "grep" | wc -l
#module_description Mail - IMAP Server (cyrus)
#module_end
#module_begin
#module_name Mail (AV/AS)
#module_type generic_proc
#module_exec ps -A | grep "amavisd (master)" | grep -v "grep" | wc -l
#module_description Mail - Antivirus/Antispam (amavisd)
#module_end
#module_begin
#module_name Mail - ClamAV
#module_type generic_proc
#module_exec ps -A | grep "clamd" | grep -v "grep" | wc -l
#module_description Mail - Antivirus (clamav)
#module_end
#module_begin
#module_name Mail (Mailing Lists)
#module_type generic_proc
#module_exec ps -A | grep "bin\/mailmanctl" | wc -l
#module_description Mail - Mailing Lists (mailman)
#module_end
#module_begin
#module_name NAT
#module_type generic_proc
#module_exec ps -A | grep "sbin\/natd" | wc -l
#module_description NAT Service
#module_end
#module_begin
#module_name NFS
#module_type generic_proc
#module_exec ps auxw | grep "nfsd-master" | grep -v "grep" | wc -l
#module_description NFS File Server
#module_end
#module_begin
#module_name Open Directory
#module_type generic_proc
#module_exec ps auxw | grep "krb5kdc" | grep -v "grep" | wc -l
#module_description Open Directory
#module_end
#module_begin
#module_name Print
#module_type generic_proc
#module_exec echo 0
#module_description Print Service
#module_end
#module_begin
#module_name QuickTime Streaming
#module_type generic_proc
#module_exec ps -A | grep "sbin\/QuickTimeStreamingServer" | wc -l
#module_description QT Streaming Service
#module_end
#module_begin
#module_name Software Update
#module_type generic_proc
#module_exec if [ `ps -A | grep "etc\/swupd" | wc -l` -gt "1" ]; then echo 1; else echo 0; fi
#module_description Software Update
#module_end
#module_begin
#module_name VPN
#module_type generic_proc
#module_exec echo 0
#module_description VPN
#module_end
#module_begin
#module_name WebObjects
#module_type generic_proc
#module_exec echo 0
#module_description WebObjects
#module_end
#module_begin
#module_name Windows (SMB daemon)
#module_type generic_proc
#module_exec ps -A | grep "sbin\/smbd" | wc -l
#module_description Windows Services (Samba)
#module_end
#module_begin
#module_name Windows (NMB daemon)
#module_type generic_proc
#module_exec ps -A | grep "sbin\/nmbd" | wc -l
#module_description Windows Services (Name Resolution)
#module_end
#module_begin
#module_name XGrid
#module_type generic_proc
#module_exec echo 0
#module_description XGrid
#module_end
# Plugin example (new in Pandora 2.0)
module_plugin grep_log /var/log/syslog Syslog ssh

View File

@ -1,9 +1,8 @@
#!/bin/bash
# Init script for Pandora FMS agent
# Generic GNU/Linux version
# (c) Sancho Lerena, <slerena@gmail.com>
# (c) Evi Vanoost <vanooste@rcbi.rochester.edu>
# v1.3
# Sancho Lerena, <slerena@gmail.com>
# v1.3.1
### BEGIN INIT INFO
# Provides: pandora_agent
@ -26,45 +25,37 @@ then
exit
fi
. /etc/rc.common
StartService()
{
if [ -f $PIDFILE ]
then
PID_BA=`cat $PIDFILE`
if [ ! -z "`ps -Af | awk '{ print $2 }' | grep $PID_BA`" ]
then
echo "Pandora FMS Agent is currently running on this machine with PID $PID_BA"
echo "Cannot launch again. Aborting."
exit
fi
case "$1" in
start)
PANDORA_PID=$(pidof -x $DAEMON)
if [ ! -z "$PANDORA_PID" ]
then
echo "Pandora FMS Agent is currently running on this machine with PID $PANDORA_PID"
echo "Cannot launch again. Aborting."
exit 1
fi
nohup $DAEMON $PANDORA_PATH 2> $LOGFILE & MYPID=$!
echo $MYPID > $PIDFILE
echo "Pandora FMS Agent is now running with PID $MYPID"
}
StopService()
{
if [ -f $PIDFILE ]
nohup $DAEMON $PANDORA_PATH 2> $LOGFILE & PANDORA_PID=$!
echo $PANDORA_PID > $PIDFILE
echo "Pandora FMS Agent is now running with PID $PANDORA_PID"
;;
stop)
PANDORA_PID=$(pidof -x $DAEMON)
if [ -z "$PANDORA_PID" ]
then
echo "Stopping Pandora Agent."
PID_2=`cat $PIDFILE`
if [ ! -z "`ps -f -p $PID_2 | grep -v grep | grep 'pandora_agent'`" ]
then
kill -9 $PID_2
fi
rm -f $PIDFILE
else
echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..."
fi
}
RestartService()
{
exit 1
else
echo "Stopping Pandora Agent."
kill $PANDORA_PID > /dev/null 2>&1
rm -f $PANDORA_PID
fi
;;
force-reload|restart)
$0 stop
$0 start
}
;;
*)
echo "Uso: /etc/init.d/pandora_agent_daemon {start|stop|restart|force-reload}"
exit 1
esac
RunService "$1"

View File

@ -1,9 +1,8 @@
#!/bin/bash
# **********************************************************************
# Pandora FMS Agent - Generic Host Agent Installer
# Mac OS X version
# GNU/Linux version
# (c) 2007 Sancho Lerena <slerena@gmail.com>
# (c) 2007 Evi Vanoost <vanooste@rcbi.rochester.edu>
# Please see http://pandora.sourceforge.net
# This code is licensed under GPL 2.0 license.
# **********************************************************************
@ -14,10 +13,7 @@ PANDORA_HOME=/usr/share/pandora_agent
PANDORA_TEMP=/var/spool/pandora
PANDORA_CFG=/etc/pandora
PANDORA_LOG=/var/log/pandora/pandora_agent.log
PANDORA_STARTUP_FOLDER=/Library/StartupItems/pandora_fms
PANDORA_STARTUP=/Library/StartupItems/pandora_fms/pandora_fms
PANDORA_HOME_DIR=/rcbiUsers/pandora
PANDORA_SERVER=skull
PANDORA_STARTUP=/Library/StartupItems/pandora_fms
FORCE=0
LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
@ -33,13 +29,13 @@ fi
uninstall () {
echo "Removing Pandora FMS Agent..."
rm -f $PANDORA_BIN
rm -Rf $PANDORA_BIN
rm -Rf $PANDORA_TEMP
rm -Rf $PANDORA_CFG
rm -Rf $PANDORA_STARTUP
rm -Rf $PANDORA_HOME
rm -Rf $PANDORA_LOG
rm -Rf $PANDORA_STARTUP_FOLDER
echo "Done"
echo "Done"
}
install () {
@ -63,9 +59,7 @@ install () {
# Create directories
echo "Creating Pandora FMS Agent home directory at $PANDORA_HOME ..."
mkdir $PANDORA_STARTUP_FOLDER
mkdir $PANDORA_HOME
mkdir $PANDORA_HOME
mkdir $PANDORA_TEMP
mkdir $PANDORA_TEMP/data_out
mkdir $PANDORA_CFG
@ -93,9 +87,11 @@ install () {
cp pandora_agent.conf $PANDORA_HOME
chmod 600 $PANDORA_HOME/pandora_agent.conf
echo "Copying Pandora FMS Agent user configuration file to $PANDORA_HOME/pandora_user.conf..."
cp pandora_user.conf $PANDORA_HOME
chmod 700 $PANDORA_HOME/pandora_user.conf
echo "Copying Pandora FMS Agent plugins to $PANDORA_HOME/plugins..."
cp -r plugins $PANDORA_HOME
chmod -R 700 $PANDORA_HOME/plugins
echo "Linking Pandora FMS Agent plugins directory to $PANDORA_CFG/plugins..."
ln -s $PANDORA_HOME/plugins $PANDORA_CFG
echo "Linking Pandora FMS Agent configuration to $PANDORA_CFG/pandora_agent.conf..."
ln -s $PANDORA_HOME/pandora_agent.conf $PANDORA_CFG
@ -108,9 +104,10 @@ install () {
chmod -R 600 $PANDORA_TEMP/data_out
chmod 640 $PANDORA_LOG
chgrp 3 $PANDORA_LOG
echo "Copying start-up daemon script at $PANDORA_STARTUP";
cp pandora_agent_daemon $PANDORA_STARTUP
cp StartupParameters.plist $PANDORA_STARTUP
echo "Copyng start-up daemon script at $PANDORA_STARTUP";
cp -R pandora_fms $PANDORA_STARTUP
chown -R root:wheel $PANDORA_STARTUP
chmod -R 644 $PANDORA_STARTUP
chown -R root $PANDORA_BIN
echo "Done."
echo " "