2009-08-11 Sancho Lerena <slerena@artica.es>

* linux/pandora_agent_installer: Some fixes and support for Ubuntu/SUSE
	specific installer.
	
	* linux/plugins/grep_log: Support for more than module over the same file.
	
	* linux/pandora_agent_daemon: Fixed problems with PID control, rewrite
	function, now should works on any linux distro. 
	
	* linux/pandora_agent.conf: Added new inventory plugin and minor changes in
	default modules.

	* linux/pandora_agent: Updated version and build 



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1841 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2009-08-11 16:58:01 +00:00
parent c1ca842e3e
commit c345808b70
6 changed files with 172 additions and 93 deletions

View File

@ -1,3 +1,18 @@
2009-08-11 Sancho Lerena <slerena@artica.es>
* linux/pandora_agent_installer: Some fixes and support for Ubuntu/SUSE
specific installer.
* linux/plugins/grep_log: Support for more than module over the same file.
* linux/pandora_agent_daemon: Fixed problems with PID control, rewrite
function, now should works on any linux distro.
* linux/pandora_agent.conf: Added new inventory plugin and minor changes in
default modules.
* linux/pandora_agent: Updated version and build
2009-08-11 Miguel de Dios <miguel.dedios@artica.es> 2009-08-11 Miguel de Dios <miguel.dedios@artica.es>
* ChangeLog: sorry, I had got a mistake with copy&paste. * ChangeLog: sorry, I had got a mistake with copy&paste.

View File

@ -1,14 +1,13 @@
#!/bin/bash #!/bin/bash
# ********************************************************************** # **********************************************************************
# Pandora FMS Generic Host Agent # Pandora FMS Generic Linux Agent
# GNU/Linux version 2.0 # (c) 2009 Artica Soluciones Tecnológicas SL
# (c) 2003-2008 Sancho Lerena <slerena@gmail.com> # with the help of many people. Please see http://pandorafms.org
# 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=2.0 AGENT_VERSION=3.0
AGENT_BUILD=081210 AGENT_BUILD=090608
# ********************************************************************** # **********************************************************************
# function configure_agent() # function configure_agent()

View File

@ -1,8 +1,7 @@
# Base config file for Pandora FMS agents # Base config file for Pandora FMS agents
# Version 2.0 # Version 3.0
# Licensed under GPL license v2, # Licensed under GPL license v2,
# (c) 2003-2008 Artica Soluciones Tecnologicas # (c) 2003-2009 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
@ -56,8 +55,8 @@ transfer_mode tentacle
# is much more safe. # is much more safe.
# cron_mode # cron_mode
# If set to 1 allows the agent to be configured via the web console. # If set to 1 allows the agent to be configured via the web console (Only Enterprise version)
# remote_config 0 # remote_config 1
# Secondary server configuration # Secondary server configuration
# ============================== # ==============================
@ -91,12 +90,10 @@ module_description User CPU Usage (%)
module_end module_end
module_begin module_begin
module_name cpu_sys module_name Load Average
module_type generic_data module_type generic_data
module_exec vmstat 1 2 | tail -1 | awk '{ print $14 }' module_exec uptime | awk '{ print $10 }' | cut -f 1 -d ","
module_max 100 module_description Average process in CPU (Last minute)
module_min 0
module_description System CPU Usage (%)
module_end module_end
module_begin module_begin
@ -109,15 +106,6 @@ module_description Free disk Percentage of root partition
module_end module_end
module_begin
module_name disk_var_free
module_type generic_data
module_exec df -kh /var | tail -1 | awk '{ print 100-$5 }'
module_max 100
module_min 0
module_description Free disk Percentage of var partition
module_end
module_begin module_begin
module_name memfree module_name memfree
module_type generic_data module_type generic_data
@ -152,16 +140,13 @@ module_type async_string
module_exec last | head -1 module_exec last | head -1
module_end module_end
#SNMPget module example
##module_begin
##module_name Remote_Cisco_Port14_status
##module_type generic_proc
##module_exec snmpget -v 1 -c artica06 192.168.50.250 IF-MIB::ifOperStatus.13
##module_end
# Plugin example # Plugin example
# This parses /var/log/syslog file, under the module name "syslog" # This parses /var/log/syslog file, under the module name "syslog"
# And search for "ssh" string into it, sending only that information. # And search for "ssh" string into it, sending only that information.
module_plugin grep_log /var/log/syslog Syslog ssh module_plugin grep_log /var/log/syslog Syslog ssh
# Plugin for inventory on the agent (Only Enterprise)
# module_plugin inventory 1 cpu ram video nic hd cdrom software

View File

@ -1,8 +1,11 @@
#!/bin/bash #!/bin/bash
# Init script for Pandora FMS agent
# Generic GNU/Linux version # Pandora FMS Linux Agent, startup script
# Sancho Lerena, <slerena@gmail.com> # Copyright (c) 2006-2009 Artica ST, <info@artica.es>
# v3.0 # Linux Version (generic), for SuSe and Debian/Ubuntu.
# other Linux distros could not work properly without modifications
# v3.0 Build 090810
# http://www.pandorafms.com
### BEGIN INIT INFO ### BEGIN INIT INFO
# Provides: pandora_agent # Provides: pandora_agent
@ -16,9 +19,15 @@
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
PANDORA_PATH=/etc/pandora PANDORA_PATH=/etc/pandora
DAEMON=/usr/bin/pandora_agent DAEMON=/usr/bin/pandora_agent
PIDFILE=/var/run/pandora_agent.pid
LOGFILE=/var/log/pandora_agent.log LOGFILE=/var/log/pandora_agent.log
# This function replace pidof, not working in the same way in different linux distros
function pidof_pandora () (
PANDORA_PID=`ps aux | grep $DAEMON | grep -v grep | head -1 | awk '{ print $2 }'`
echo $PANDORA_PID
)
if [ ! -f $DAEMON ] if [ ! -f $DAEMON ]
then then
echo "Pandora FMS Agent not found at $DAEMON, please check setup" echo "Pandora FMS Agent not found at $DAEMON, please check setup"
@ -26,37 +35,51 @@ then
fi fi
case "$1" in case "$1" in
start) start)
PANDORA_PID=$(pidof -x $DAEMON) PANDORA_PID=`pidof_pandora`
if [ ! -z "$PANDORA_PID" ] if [ ! -z "$PANDORA_PID" ]
then then
echo "Pandora FMS Agent is currently running on this machine with PID $PANDORA_PID" echo "Pandora FMS Agent is currently running on this machine with PID $PANDORA_PID"
echo "Cannot launch again. Aborting." echo "Cannot launch again. Aborting."
exit 1 exit 1
fi fi
nohup $DAEMON $PANDORA_PATH 2> $LOGFILE & PANDORA_PID=$! nohup $DAEMON $PANDORA_PATH 2> $LOGFILE &
echo $PANDORA_PID > $PIDFILE sleep 1
echo "Pandora FMS Agent is now running with PID $PANDORA_PID" PANDORA_PID=`pidof_pandora`
;; echo "Pandora FMS Agent is now running with PID $PANDORA_PID"
stop) ;;
PANDORA_PID=$(pidof -x $DAEMON)
if [ -z "$PANDORA_PID" ] stop)
then PANDORA_PID=`pidof_pandora`
echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..." if [ -z "$PANDORA_PID" ]
exit 1 then
else echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..."
echo "Stopping Pandora Agent." exit 1
kill $PANDORA_PID > /dev/null 2>&1 else
rm -f $PANDORA_PID echo "Stopping Pandora Agent."
fi kill $PANDORA_PID > /dev/null 2>&1
;; fi
force-reload|restart) ;;
$0 stop
sleep 3 status)
$0 start PANDORA_PID=`pidof_pandora`
;; if [ -z "$PANDORA_PID" ]
*) then
echo "Uso: /etc/init.d/pandora_agent_daemon {start|stop|restart|force-reload}" echo "Pandora FMS Agent is not running."
else
echo "Pandora FMS Agent is running with PID $PANDORA_PID."
fi
exit 0
;;
force-reload|restart)
$0 stop
sleep 2
$0 start
;;
*)
echo "Uso: /etc/init.d/pandora_agent_daemon {start|stop|restart|status|force-reload}"
exit 1 exit 1
esac esac

View File

@ -1,13 +1,14 @@
#!/bin/bash #!/bin/bash
# **********************************************************************
# Pandora FMS Agent - Generic Host Agent Installer # Pandora FMS Agent Installer (c) 2008-2009 Artica ST
# GNU/Linux version # Linux Version (generic), for SuSe and Debian/Ubuntu only
# (c) 2007 Sancho Lerena <slerena@gmail.com> # other Linux distros could not work properly without modifications
# Please see http://pandora.sourceforge.net # Please see http://www.pandorafms.org
# v3.0 Build 090810
# This code is licensed under GPL 2.0 license. # This code is licensed under GPL 2.0 license.
# ********************************************************************** # **********************************************************************
PI_VERSION=2.1 PI_VERSION=3.0
PANDORA_BIN=/usr/bin/pandora_agent PANDORA_BIN=/usr/bin/pandora_agent
PANDORA_HOME=/usr/share/pandora_agent PANDORA_HOME=/usr/share/pandora_agent
PANDORA_TEMP=/var/spool/pandora PANDORA_TEMP=/var/spool/pandora
@ -30,6 +31,41 @@ then
exit 1 exit 1
fi fi
get_distro () {
# Get Linux Distro type and version
if [ -f "/etc/SuSE-release" ]
then
OS_VERSION=`cat /etc/SuSE-release | grep VERSION | cut -f 3 -d " "`
LINUX_DISTRO=SUSE
else
if [ -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"
else
if [ -f "/etc/debian_version" ]
then
OS_VERSION=`cat /etc/debian_version`
OS_VERSION="DEBIAN $OS_VERSION"
LINUX_DISTRO=DEBIAN
else
if [ -f "/etc/fedora-release" ]
then
OS_VERSION=`cat /etc/fedora-release | cut -f 4 -d " "`
OS_VERSION="FEDORA $OS_VERSION"
LINUX_DISTRO=FEDORA
else
LINUX_DISTRO=GENERIC
OS_VERSION=`uname -r`
fi
fi
fi
fi
echo $LINUX_DISTRO
}
uninstall () { uninstall () {
echo "Removing Pandora FMS Agent..." echo "Removing Pandora FMS Agent..."
rm -Rf $PANDORA_BIN rm -Rf $PANDORA_BIN
@ -43,6 +79,12 @@ uninstall () {
} }
install () { install () {
DISTRO=`get_distro`
OLDFILENAMETMP=`date +"%Y-%m-%d"`
echo "Detecting Linux distribution: $DISTRO"
if [ -f $PANDORA_HOME ] && [ "$FORCE" = "0" ] if [ -f $PANDORA_HOME ] && [ "$FORCE" = "0" ]
then then
echo "Seems that default dir already exists. Please use --force to" echo "Seems that default dir already exists. Please use --force to"
@ -56,6 +98,7 @@ install () {
then then
echo "Seems that $PANDORA_BIN already exists. Please use --force to" echo "Seems that $PANDORA_BIN already exists. Please use --force to"
echo "force installer to reinstall overwriting it" echo "force installer to reinstall overwriting it"
echo " "
exit exit
else else
echo "Checking Pandora FMS Agent on $PANDORA_BIN...." echo "Checking Pandora FMS Agent on $PANDORA_BIN...."
@ -63,11 +106,11 @@ install () {
# Create directories # Create directories
echo "Creating Pandora FMS Agent home directory at $PANDORA_HOME ..." echo "Creating Pandora FMS Agent home directory at $PANDORA_HOME ..."
mkdir $PANDORA_HOME mkdir $PANDORA_HOME 2> /dev/null
mkdir $PANDORA_TEMP mkdir $PANDORA_TEMP 2> /dev/null
mkdir $PANDORA_TEMP/data_out mkdir $PANDORA_TEMP/data_out 2> /dev/null
mkdir $PANDORA_CFG mkdir $PANDORA_CFG 2> /dev/null
mkdir /var/log/pandora mkdir /var/log/pandora 2> /dev/null
# Create logfile # Create logfile
if [ ! -z "`touch $PANDORA_LOG`" ] if [ ! -z "`touch $PANDORA_LOG`" ]
@ -88,7 +131,14 @@ install () {
cp pandora_agent_daemon $PANDORA_HOME cp pandora_agent_daemon $PANDORA_HOME
echo "Copying Pandora FMS Agent configuration file to $PANDORA_HOME/pandora_agent.conf..." echo "Copying Pandora FMS Agent configuration file to $PANDORA_HOME/pandora_agent.conf..."
cp pandora_agent.conf $PANDORA_HOME if [ -e $PANDORA_HOME/pandora_agent.conf ]
then
cp $PANDORA_HOME/pandora_agent.conf $PANDORA_HOME/pandora_agent.conf.$OLDFILENAMETMP
echo "Backing up old configuration file to $PANDORA_HOME/pandora_agent.conf.$OLDFILENAMETMP"
fi
echo "Copying default agent configuration to $PANDORA_HOME/pandora_agent.conf"
cp pandora_agent.conf $PANDORA_HOME/pandora_agent.conf
chmod 600 $PANDORA_HOME/pandora_agent.conf chmod 600 $PANDORA_HOME/pandora_agent.conf
echo "Copying Pandora FMS Agent plugins to $PANDORA_HOME/plugins..." echo "Copying Pandora FMS Agent plugins to $PANDORA_HOME/plugins..."
@ -99,32 +149,39 @@ install () {
cp tentacle_client $TENTACLE cp tentacle_client $TENTACLE
echo "Linking Pandora FMS Agent plugins directory to $PANDORA_CFG/plugins..." echo "Linking Pandora FMS Agent plugins directory to $PANDORA_CFG/plugins..."
ln -s $PANDORA_HOME/plugins $PANDORA_CFG rm $PANDORA_CFG/plugins 2> /dev/null
ln -s $PANDORA_HOME/plugins $PANDORA_CFG 2> /dev/null
echo "Linking Pandora FMS Agent configuration to $PANDORA_CFG/pandora_agent.conf..." echo "Linking Pandora FMS Agent configuration to $PANDORA_CFG/pandora_agent.conf..."
ln -s $PANDORA_HOME/pandora_agent.conf $PANDORA_CFG rm $PANDORA_CFG/pandora_agent.conf 2> /dev/null
ln -s $PANDORA_HOME/pandora_agent.conf $PANDORA_CFG/pandora_agent.conf
echo "Linking Pandora FMS Agent user configuration to $PANDORA_CFG/pandora_user.conf..."
ln -s $PANDORA_HOME/pandora_user.conf $PANDORA_CFG
echo "Setting secure permissions and ownership for all Pandora FMS Agent files..." echo "Setting secure permissions and ownership for all Pandora FMS Agent files..."
chown -R root $PANDORA_HOME chown -R root $PANDORA_HOME
chmod -R 600 $PANDORA_TEMP/data_out chmod -R 600 $PANDORA_TEMP/data_out
chmod 640 $PANDORA_LOG chmod 640 $PANDORA_LOG
chgrp 3 $PANDORA_LOG chgrp root $PANDORA_LOG
echo "Linking start-up daemon script at $PANDORA_STARTUP"; echo "Linking start-up daemon script at $PANDORA_STARTUP";
cp pandora_agent_daemon $PANDORA_STARTUP cp pandora_agent_daemon $PANDORA_STARTUP
echo "Linking start-up daemon script to /etc/rc2.d"; if [ "$DISTRO" == "UBUNTU" ]
ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent then
echo "Linking start-up daemon script to /etc/rc2.d";
chown -R root $PANDORA_BIN ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent
else
INITLV=`cat /etc/inittab | grep "[0-9]\:initdefault" | cut -f 2 -d ":"`
echo "Linking start-up daemon script to /etc/rc.d/rc$INITLV.d";
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc$INITLV.d/S90pandora_agent
fi
chown -R root:root $PANDORA_BIN
echo "Done." echo "Done."
echo " " echo " "
echo "You have your startup script ready at $PANDORA_STARTUP" echo "You have your startup script ready at $PANDORA_STARTUP"
echo " " echo " "
echo "Tentacle is the default transfer mode" echo "Tentacle is the default transfer mode since 2.0 version."
echo "If you want to use SSH, firstly you need to copy your public SSH keys ($HOME/.ssh/id_dsa)" echo "If you want to use SSH, firstly you need to copy your public SSH keys ($HOME/.ssh/id_dsa)"
echo "under /home/pandora/.ssh/authorized_keys on your Pandora FMS Server host" echo "under /home/pandora/.ssh/authorized_keys on your Pandora FMS Server host"
echo "You also need to setup your $PANDORA_CFG/pandora_agent.conf config file" echo "You also need to setup your $PANDORA_CFG/pandora_agent.conf config file"
@ -141,7 +198,7 @@ help () {
# Script banner at start # Script banner at start
echo " " echo " "
echo "Pandora FMS Agent Installer $PI_VERSION (c) 2009 ArticaST" echo "Pandora FMS Agent Installer $PI_VERSION (c) 2008-2009 ArticaST"
echo "This program is licensed under GPL2 Terms. http://pandorafms.com" echo "This program is licensed under GPL2 Terms. http://pandorafms.com"
echo " " echo " "

View File

@ -226,7 +226,7 @@ if (! -e $Log_file) {
} }
# Create index file if it does not exist # Create index file if it does not exist
$Idx_file=$Idx_dir . basename($Log_file) . ".idx"; $Idx_file=$Idx_dir . $Module_name . "_" . basename($Log_file) . ".idx";
if (! -e $Idx_file) { if (! -e $Idx_file) {
create_idx(); create_idx();
exit 0; exit 0;