2014-08-13 Koichiro Kikuchi <koichiro@rworks.jp>

* FreeBSD/pandora_agent: Small fixes: use proper rc variables,
	 remove obsolete function "set_rcvar" call and use "daemon" command
	 to start pandora_agent.

	* pandora_agent_installer: Refactored implementation and added
	 "fakeroot" installation support.

	* plugins/who.sh: Converted to bourne shell script.

	* pandora_agent_daemon: Small bug fixes and refactorings.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@10414 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
koichirok 2014-08-13 14:53:16 +00:00
parent 486afe5124
commit c9c7bc2873
5 changed files with 258 additions and 333 deletions

View File

@ -1,3 +1,16 @@
2014-08-13 Koichiro Kikuchi <koichiro@rworks.jp>
* FreeBSD/pandora_agent: Small fixes: use proper rc variables,
remove obsolete function "set_rcvar" call and use "daemon" command
to start pandora_agent.
* pandora_agent_installer: Refactored implementation and added
"fakeroot" installation support.
* plugins/who.sh: Converted to bourne shell script.
* pandora_agent_daemon: Small bug fixes and refactorings.
2014-08-12 Ramon Novoa <rnovoa@artica.es> 2014-08-12 Ramon Novoa <rnovoa@artica.es>
* pandora_agent: Fixed to make the 'Command Snapshot' feature work. * pandora_agent: Fixed to make the 'Command Snapshot' feature work.

View File

@ -3,6 +3,7 @@
# ********************************************************************** # **********************************************************************
# Pandora FMS Agent Daemon launcher for FreeBSD # Pandora FMS Agent Daemon launcher for FreeBSD
# (c) 2010 Junichi Satoh <junichi@rworks.jp> # (c) 2010 Junichi Satoh <junichi@rworks.jp>
# (c) 2014 Koichiro Kikuchi <koichiro@rworks.jp>
# #
# ********************************************************************** # **********************************************************************
@ -18,7 +19,7 @@
. "/etc/rc.subr" . "/etc/rc.subr"
name="pandora_agent" name="pandora_agent"
rcvar=`set_rcvar` rcvar=pandora_agent_enable
# read configuration and set defaults # read configuration and set defaults
pandora_agent_enable=${pandora_agent_enable:-"NO"} pandora_agent_enable=${pandora_agent_enable:-"NO"}
@ -26,22 +27,15 @@ load_rc_config "$name"
PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
command=/usr/local/bin/pandora_agent
command_args="/usr/local/etc/pandora &"
pidfile=/var/run/$name.pid pidfile=/var/run/$name.pid
required_files="/usr/local/etc/pandora/pandora_agent.conf" required_files="/usr/local/etc/pandora/pandora_agent.conf"
start_postcmd=start_postcmd
stop_postcmd=stop_postcmd stop_postcmd=stop_postcmd
procname="/usr/bin/perl" command=/usr/bin/daemon
command_interpreter=/usr/local/bin/perl
procname=/usr/local/bin/pandora_agent
start_postcmd() command_args="-cfp $pidfile $procname /usr/local/etc/pandora"
{
sleep 1
PANDORA_PID=`pgrep -f -j none $name`
echo $PANDORA_PID > $pidfile
}
stop_postcmd() stop_postcmd()
{ {

View File

@ -34,38 +34,39 @@ pidof_pandora () {
OS_NAME=`uname -s` OS_NAME=`uname -s`
if [ $OS_NAME = "HP-UX" ] if [ $OS_NAME = "HP-UX" ]
then then
PANDORA_PID=`ps -ef | grep "/usr/bin/perl /opt/PandoraFMS/usr/bin/pandora_agent" | grep -v grep | awk '{print $2}'` PANDORA_PID=`ps -ef | grep "/usr/bin/perl $DAEMON" | grep -v grep | awk '{print $2}'`
else elif [ "$OS_NAME" = "SunOS" ]
if [ "$OS_NAME" = "SunOS" ] then
ZONENAME_CMD="/bin/zonename"
TRUNCATED_DAEMON=`echo "$DAEMON $PANDORA_PATH" | cut -c1-20`
if [ -x $ZONENAME_CMD ]
then then
ZONENAME_CMD="/bin/zonename" ZONE=`$ZONENAME_CMD`
TRUNCATED_DAEMON=`echo "$DAEMON $PANDORA_PATH" | cut -c1-20`
if [ -x $ZONENAME_CMD ]
then
ZONE=`$ZONENAME_CMD`
else
ZONE=
fi
if [ "$ZONE" = "global" ]
then
PANDORA_PID=`ps -f -z global | grep "$TRUNCATED_DAEMON" | grep -v grep | head -1 | awk '{ print $2 }'`
else
PANDORA_PID=`ps -Af | grep "$TRUNCATED_DAEMON" | grep -v grep | head -1 | awk '{ print $2 }'`
fi
elif [ "$OS_NAME" = "Linux" -a -x /usr/sbin/vzpid ]
then
for _pid in `ps -Af | grep "$DAEMON $PANDORA_PATH" | grep -v grep | awk '{ print $2 }'`
do
_ctid=`/usr/sbin/vzpid $_pid | awk '$1 == '$_pid' { print $2 }'`
if [ "X$_ctid" = "X0" ]
then
PANDORA_PID=$_pid
break
fi
done
else else
PANDORA_PID=`ps -Af | grep "$DAEMON $PANDORA_PATH" | grep -v grep | head -1 | awk '{ print $2 }'` ZONE=
fi fi
if [ "$ZONE" = "global" ]
then
PANDORA_PID=`ps -f -z global | grep "$TRUNCATED_DAEMON" | grep -v grep | head -1 | awk '{ print $2 }'`
else
PANDORA_PID=`ps -Af | grep "$TRUNCATED_DAEMON" | grep -v grep | head -1 | awk '{ print $2 }'`
fi
elif [ "$OS_NAME" = "Linux" ] && [ -x /usr/sbin/vzpid ]
then
# Virtuozzo/OpenVZ
local _pid _ctid _pids
_pids=`ps -Af | grep "$DAEMON $PANDORA_PATH" | grep -v grep | awk '{ print $2 }'`
[ "$_pids" ] && for _pid in $_pids
do
_ctid=`/usr/sbin/vzpid $_pid | awk '$1 == '$_pid' { print $2 }'`
if [ "X$_ctid" = "X0" ]
then
PANDORA_PID=$_pid
break
fi
done
else
PANDORA_PID=`ps -Af | grep "$DAEMON $PANDORA_PATH" | grep -v grep | head -1 | awk '{ print $2 }'`
fi fi
echo $PANDORA_PID echo $PANDORA_PID

View File

@ -15,48 +15,78 @@ OS_NAME=`uname -s`
FORCE=0 FORCE=0
LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"` LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
PANDORA_HOME=/usr/share/pandora_agent
PANDORA_BIN=/usr/bin/pandora_agent PREFIX=/usr
PANDORA_EXEC_BIN=/usr/bin/pandora_agent_exec if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ]
PANDORA_REVENT_BIN=/usr/bin/pandora_revent then
PREFIX=/usr/local
fi
PANDORA_HOME=$PREFIX/share/pandora_agent
PANDORA_BIN=$PREFIX/bin/pandora_agent
PANDORA_EXEC_BIN=$PREFIX/bin/pandora_agent_exec
PANDORA_REVENT_BIN=$PREFIX/bin/pandora_revent
PANDORA_TEMP=/var/spool/pandora PANDORA_TEMP=/var/spool/pandora
PANDORA_CFG=/etc/pandora PANDORA_CFG=/etc/pandora
PANDORA_LOG_DIR=/var/log/pandora PANDORA_LOG_DIR=/var/log/pandora
PANDORA_LOG=pandora_agent.log PANDORA_LOG=pandora_agent.log
TENTACLE=/usr/bin/tentacle_client TENTACLE=$PREFIX/bin/tentacle_client
TENTACLE_SERVER=/usr/bin/tentacle_server TENTACLE_SERVER=$PREFIX/bin/tentacle_server
PANDORA_MAN=/usr/share/man PANDORA_MAN=$PREFIX/share/man
PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon
DAEMON_SCRIPT=pandora_agent_daemon
PANDORA_USER="root"
PANDORA_PERL_PATH="perl"
WITHOUT_TENTACLE_SERVER=0
FAKEROOT=0
# defaults for each platforms
case $OS_NAME in
AIX)
PANDORA_STARTUP=/etc/rc.pandora_agent_daemon
;;
HP-UX)
PANDORA_STARTUP=/sbin/init.d/pandora_agent_daemon
;;
FreeBSD)
PANDORA_CFG=$PREFIX/etc/pandora
PANDORA_MAN=$PREFIX/man
PANDORA_STARTUP=$PREFIX/etc/rc.d/pandora_agent
DAEMON_SCRIPT=$OS_NAME/pandora_agent
PANDORA_PERL_PATH=/usr/local/bin/perl
;;
NetBSD)
PANDORA_CFG=/usr/local/etc/pandora
PANDORA_STARTUP=/etc/rc.d/pandora_agent
DAEMON_SCRIPT=$OS_NAME/pandora_agent
PANDORA_PERL_PATH=/usr/pkg/bin/perl
;;
esac
MODE=$1 MODE=$1
PANDORA_BASE=`echo $2 | sed -e 's/\/$//'`
# options
while :
do
case "$2" in
"--no-tentacle-server") WITHOUT_TENTACLE_SERVER=1;;
"--fakeroot") FAKEROOT=1;;
*) break;;
esac
shift
done
PANDORA_BASE=`echo $2 | sed -e 's|/$||'`
if [ "$3" != "" ] if [ "$3" != "" ]
then then
PANDORA_USER=$3 PANDORA_USER=$3
if [ "$PANDORA_BASE" = "" ] if [ -z "$PANDORA_BASE" ]
then then
echo "When specifying a custom user the agent must be installed to a custom location where that user has write permissions!" echo "When specifying a custom user the agent must be installed to a custom location where that user has write permissions!"
exit 1 exit 1
fi fi
else
PANDORA_USER="root"
fi fi
if [ "$4" != "" ] [ "$4" ] && PANDORA_PERL_PATH=$4
then
PANDORA_PERL_PATH=$4
echo $PANDORA_PERL_PATH > PANDORA_PERL_PATH.temp
sed 's/\//\\\//g' PANDORA_PERL_PATH.temp > PANDORA_PERL_PATH.temp2
PANDORA_PERL_DECODED_PATH=`cat PANDORA_PERL_PATH.temp2`
rm PANDORA_PERL_PATH.temp PANDORA_PERL_PATH.temp2
#PANDORA_PERL_DECODED_PATH=`echo $PANDORA_PERL_PATH | sed -e "s.\/.\\\\\/.g"`
else
PANDORA_PERL_PATH="perl"
if [ "$OS_NAME" = "NetBSD" ]
then
PANDORA_PERL_DECODED_PATH="/usr/pkg/bin/perl"
fi
fi
# Check for Perl 5.6.x or higher available # Check for Perl 5.6.x or higher available
PERL_VERSION=`$PANDORA_PERL_PATH -v | egrep 'v5.6|v5.7|v5.8|v5.9|v5.1[0-9]' | grep perl` PERL_VERSION=`$PANDORA_PERL_PATH -v | egrep 'v5.6|v5.7|v5.8|v5.9|v5.1[0-9]' | grep perl`
@ -69,17 +99,16 @@ then
exit 2 exit 2
fi fi
UNIX_KIND=`uname -s` if [ -z "`echo Linux HP-UX SunOS AIX Solaris Darwin BSD bsd FreeBSD NetBSD | grep \"$OS_NAME\"`" ]
if [ -z "`echo Linux HP-UX SunOS AIX Solaris Darwin BSD bsd FreeBSD NetBSD | grep \"$UNIX_KIND\"`" ]
then then
echo "This system: '$UNIX_KIND' is not supported by this script" echo "This system: '$OS_NAME' is not supported by this script"
echo "Please make the install yourself as it's described in documentation" echo "Please make the install yourself as it's described in documentation"
exit 1 exit 1
fi fi
# check for root to do the install # check for root to do the install
if [ -z "`id | grep \"uid=0(root)\"`" ] if [ $FAKEROOT -ne 1 ] && [ -z "`id | grep \"uid=0(root)\"`" ]
then then
echo "You need to be root to do the install. Please made a manual install" echo "You need to be root to do the install. Please made a manual install"
echo "if you want to install Pandora FMS agent without root" echo "if you want to install Pandora FMS agent without root"
@ -91,7 +120,7 @@ fi
help () { help () {
echo "Syntax": echo "Syntax":
echo " " echo " "
echo " ./pandora_agent_installer < --mode > [ destination_path ] [ user_to_run_as ] [custom_perl_path]" echo " ./pandora_agent_installer < --mode > [ --option ] [ destination_path ] [ user_to_run_as ] [custom_perl_path]"
echo " " echo " "
echo "Modes:" echo "Modes:"
echo " " echo " "
@ -99,6 +128,11 @@ help () {
echo " --install To install Pandora FMS Agent on this system" echo " --install To install Pandora FMS Agent on this system"
echo " --uninstall To uninstall/remove Pandora FMS Agent on this System" echo " --uninstall To uninstall/remove Pandora FMS Agent on this System"
echo " " echo " "
echo "Option:"
echo " "
echo " --no-tentacle-server Skip tentacle server installation (by default tentalce server installed)"
echo " --fakeroot treate \"destination_path\" as root directory"
echo " "
echo "Some exaples of how to use the installer:" echo "Some exaples of how to use the installer:"
echo " " echo " "
echo " ./pandora_agent_installer --install" echo " ./pandora_agent_installer --install"
@ -110,38 +144,12 @@ help () {
} }
uninstall () { uninstall () {
OS_NAME=`uname -s`
if [ "$OS_NAME" = "Darwin" ] if [ "$OS_NAME" = "Darwin" ]
then then
launchctl remove com.pandorafms.pandorafms launchctl remove com.pandorafms.pandorafms
rm /Library/LaunchDaemons/com.pandorafms.pandorafms.plist 2> /dev/null rm /Library/LaunchDaemons/com.pandorafms.pandorafms.plist 2> /dev/null
fi fi
if [ "$OS_NAME" = "FreeBSD" ]
then
PANDORA_HOME=/usr/local/share/pandora_agent
PANDORA_BIN=/usr/local/bin/pandora_agent
PANDORA_EXEC_BIN=/usr/local/bin/pandora_agent_exec
PANDORA_REVENT_BIN=/usr/local/bin/pandora_revent
PANDORA_CFG=/usr/local/etc/pandora
TENTACLE=/usr/local/bin/tentacle_client
TENTACLE_SERVER=/usr/local/bin/tentacle_server
PANDORA_MAN=/usr/local/man
fi
if [ "$OS_NAME" = "NetBSD" ]
then
PANDORA_HOME=/usr/local/share/pandora_agent
PANDORA_BIN=/usr/local/bin/pandora_agent
PANDORA_EXEC_BIN=/usr/local/bin/pandora_agent_exec
PANDORA_REVENT_BIN=/usr/local/bin/pandora_revent
PANDORA_CFG=/usr/local/etc/pandora
TENTACLE=/usr/local/bin/tentacle_client
TENTACLE_SERVER=/usr/local/bin/tentacle_server
PANDORA_MAN=/usr/share/man
fi
echo "Removing Pandora FMS Agent..." echo "Removing Pandora FMS Agent..."
rm -Rf $PANDORA_BASE$PANDORA_BIN 2> /dev/null rm -Rf $PANDORA_BASE$PANDORA_BIN 2> /dev/null
rm -Rf $PANDORA_BASE$PANDORA_EXEC_BIN 2> /dev/null rm -Rf $PANDORA_BASE$PANDORA_EXEC_BIN 2> /dev/null
@ -168,16 +176,19 @@ uninstall () {
rm -Rf $PANDORA_BASE/etc/rc.d/rc?.d/S90pandora_agent_daemon 2> /dev/null rm -Rf $PANDORA_BASE/etc/rc.d/rc?.d/S90pandora_agent_daemon 2> /dev/null
rm -Rf $PANDORA_BASE/etc/rc.d/rc?.d/S90pandora_agent 2> /dev/null rm -Rf $PANDORA_BASE/etc/rc.d/rc?.d/S90pandora_agent 2> /dev/null
rm -Rf $PANDORA_BASE/usr/local/etc/rc.d/pandora_agent 2> /dev/null rm -Rf $PANDORA_BASE/usr/local/etc/rc.d/pandora_agent 2> /dev/null
rm -Rf /etc/init.d/pandora_agent_daemon 2> /dev/null if [ $FAKEROOT -ne 1 ]
rm -Rf /sbin/init.d/pandora_agent_daemon 2> /dev/null then
rm -Rf /etc/rc.pandora_agent_daemon 2> /dev/null rm -Rf /etc/init.d/pandora_agent_daemon 2> /dev/null
rm -Rf /etc/rc?.d/S90pandora_agent_daemon 2> /dev/null rm -Rf /sbin/init.d/pandora_agent_daemon 2> /dev/null
rm -Rf /sbin/rc?.d/S90pandora_agent_daemon 2> /dev/null rm -Rf /etc/rc.pandora_agent_daemon 2> /dev/null
rm -Rf /etc/rc?.d/S90pandora_agent 2> /dev/null rm -Rf /etc/rc?.d/S90pandora_agent_daemon 2> /dev/null
rm -Rf /sbin/rc?.d/S90pandora_agent 2> /dev/null rm -Rf /sbin/rc?.d/S90pandora_agent_daemon 2> /dev/null
rm -Rf /etc/rc.d/rc?.d/S90pandora_agent_daemon 2> /dev/null rm -Rf /etc/rc?.d/S90pandora_agent 2> /dev/null
rm -Rf /etc/rc.d/rc?.d/S90pandora_agent 2> /dev/null rm -Rf /sbin/rc?.d/S90pandora_agent 2> /dev/null
rm -Rf /usr/local/etc/rc.d/pandora_agent 2> /dev/null rm -Rf /etc/rc.d/rc?.d/S90pandora_agent_daemon 2> /dev/null
rm -Rf /etc/rc.d/rc?.d/S90pandora_agent 2> /dev/null
rm -Rf /usr/local/etc/rc.d/pandora_agent 2> /dev/null
fi
rm -Rf $PANDORA_BASE$PANDORA_HOME 2> /dev/null rm -Rf $PANDORA_BASE$PANDORA_HOME 2> /dev/null
rm -Rf $PANDORA_BASE$PANDORA_LOG_DIR 2> /dev/null rm -Rf $PANDORA_BASE$PANDORA_LOG_DIR 2> /dev/null
@ -201,36 +212,48 @@ uninstall () {
echo "Done" echo "Done"
} }
#
# install_perl_script [OPTIONS] SRCFILE DESTFILE
# Install perl script. If PANDORA_PERL_DECODED_PATH is set, path of the perl
# in shebang line is replaced with PANDORA_PERL_DECODED_PATH value.
# OPTIONS:
# -o OWNER owner of the installed script
# -g GROUP group of the installed script
# -m PREM mode of the installed script
#
install_perl_script () {
OWNER=""; GROUP=""; PERM=""
while :
do
case $1 in
-o) OWNER=$2;;
-g) GROUP=$2;;
-m) PERM=$2;;
*) break;;
esac
shift;shift
done
SRC="$1"
DEST="$2"
# do install
if echo $PANDORA_PERL_PATH | grep "/" > /dev/null && [ "$PANDORA_PERL_PATH" != "/usr/bin/perl" ]
then
sed -e "s:^#\!.*:#\!$PANDORA_PERL_PATH:g" $SRC > $DEST
else
cp $SRC $DEST
fi
# set owner, group and permissions
[ "$OWNER" ] && chown $OWNER $DEST 2>/dev/null
[ "$GROUP" ] && chgrp $GROUP $DEST 2>/dev/null
[ "$PERM" ] && chmod $PERM $DEST
}
install () { install () {
OS_VERSION=`uname -r` OS_VERSION=`uname -r`
OS_NAME=`uname -s`
OLDFILENAMETMP=`date +"%Y-%m-%d"` OLDFILENAMETMP=`date +"%Y-%m-%d"`
if [ "$OS_NAME" = "FreeBSD" ]
then
PANDORA_HOME=/usr/local/share/pandora_agent
PANDORA_BIN=/usr/local/bin/pandora_agent
PANDORA_EXEC_BIN=/usr/local/bin/pandora_agent_exec
PANDORA_REVENT_BIN=/usr/local/bin/pandora_revent
PANDORA_CFG=/usr/local/etc/pandora
TENTACLE=/usr/local/bin/tentacle_client
TENTACLE_SERVER=/usr/local/bin/tentacle_server
PANDORA_MAN=/usr/local/man
fi
if [ "$OS_NAME" = "NetBSD" ]
then
PANDORA_HOME=/usr/local/share/pandora_agent
PANDORA_BIN=/usr/local/bin/pandora_agent
PANDORA_EXEC_BIN=/usr/local/bin/pandora_agent_exec
PANDORA_REVENT_BIN=/usr/local/bin/pandora_revent
PANDORA_CFG=/usr/local/etc/pandora
TENTACLE=/usr/local/bin/tentacle_client
TENTACLE_SERVER=/usr/local/bin/tentacle_server
PANDORA_MAN=/usr/share/man
fi
echo "Detecting Unix distribution: $OS_NAME version $OS_VERSION" echo "Detecting Unix distribution: $OS_NAME version $OS_VERSION"
if [ -f $PANDORA_BASE$PANDORA_HOME ] && [ "$FORCE" = "0" ] if [ -f $PANDORA_BASE$PANDORA_HOME ] && [ "$FORCE" = "0" ]
then then
@ -253,87 +276,49 @@ install () {
# Alter dynamically the daemon launcher and setup the new path # Alter dynamically the daemon launcher and setup the new path
# if PANDORA_BASE is customized. # if PANDORA_BASE is customized.
if [ ! -z "$PANDORA_BASE" ] if [ "$PANDORA_BASE" ] && [ $FAKEROOT -ne 1 ]
then then
if [ "$OS_NAME" = "FreeBSD" ] DAEMON_TEMP=pandora_agent_daemon_temp
then
DAEMON_SCRIPT=FreeBSD/pandora_agent
DAEMON_TEMP=pandora_agent_daemon_temp
elif [ "$OS_NAME" = "NetBSD" ]
then
DAEMON_SCRIPT=NetBSD/pandora_agent
DAEMON_TEMP=pandora_agent_daemon_temp
else
DAEMON_SCRIPT=pandora_agent_daemon
DAEMON_TEMP=pandora_agent_daemon_temp
fi
# Backup the daemon script # Backup the daemon script
cp -f "$DAEMON_SCRIPT" "$DAEMON_SCRIPT.bak" cp -f "$DAEMON_SCRIPT" "${DAEMON_SCRIPT}.bak"
AGENT_CFG=$OS_NAME/pandora_agent.conf AGENT_CFG=$OS_NAME/pandora_agent.conf
AGENT_CFG_TEMP=$OS_NAME/pandora_agent.conf.temp AGENT_CFG_TEMP=$OS_NAME/pandora_agent.conf.temp
# Backup the configuration file # Backup the configuration file
cp -f "$AGENT_CFG" "$AGENT_CFG.bak" cp -f "$AGENT_CFG" "${AGENT_CFG}.bak"
echo $PANDORA_BASE > PANDORA_BASE.temp if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ]
sed 's/\//\\\//g' PANDORA_BASE.temp > PANDORA_BASE.temp2
PANDORA_BASE_DECODED=`cat PANDORA_BASE.temp2`
rm PANDORA_BASE.temp PANDORA_BASE.temp2
if [ "$OS_NAME" = "FreeBSD" -o "$OS_NAME" = "NetBSD" ]
then then
sed -e "s/^PATH\=[.]*/PATH\=$PANDORA_BASE_DECODED\/usr\/local\/bin\:/g" $DAEMON_SCRIPT > $DAEMON_TEMP sed -e "\|^PATH=|s|=|=$PANDORA_BASE$PREFIX/bin:|" \
mv $DAEMON_TEMP $DAEMON_SCRIPT -e "s|/usr/local/etc/pandora|$PANDORA_BASE$PANDORA_CFG|g" \
-e "s|/usr/local/bin/pandora_agent|$PANDORA_BASE$PANDORA_BIN|g" \
sed -e "s/^command\=[.]*/command\=$PANDORA_BASE_DECODED/g" $DAEMON_SCRIPT > $DAEMON_TEMP $DAEMON_SCRIPT > $DAEMON_TEMP
mv $DAEMON_TEMP $DAEMON_SCRIPT
sed -e 's/^command_args\=\"[.]*/command_args\=\"$PANDORA_BASE_DECODED/g' $DAEMON_SCRIPT > $DAEMON_TEMP
mv $DAEMON_TEMP $DAEMON_SCRIPT
sed -e 's/^required_files\=\"[.]*/required_files\=\"$PANDORA_BASE_DECODED/g' $DAEMON_SCRIPT > $DAEMON_TEMP
mv $DAEMON_TEMP $DAEMON_SCRIPT mv $DAEMON_TEMP $DAEMON_SCRIPT
else else
sed -e "s/^PATH\=[.]*/PATH\=$PANDORA_BASE_DECODED\/usr\/bin\:/g" $DAEMON_SCRIPT > $DAEMON_TEMP sed -e "\|^PATH=|s|=|=$PANDORA_BASE/usr/bin:|" \
mv $DAEMON_TEMP $DAEMON_SCRIPT -e "\|^PANDORA_PATH=|s|=|=$PANDORA_BASE|" \
-e "\|^LOGFILE=|s|=|=$PANDORA_BASE|" \
sed -e "s/^PANDORA_PATH\=[.]*/PANDORA_PATH\=$PANDORA_BASE_DECODED/g" $DAEMON_SCRIPT > $DAEMON_TEMP -e "\|^DAEMON=|s|=|=$PANDORA_BASE|" \
mv $DAEMON_TEMP $DAEMON_SCRIPT -e "\|^DAEMON_TENTACLE=|s|=|=$PANDORA_BASE|" \
-e "s/^PANDORA_USER=.*/PANDORA_USER=$PANDORA_USER/" \
sed -e "s/^LOGFILE\=[.]*/LOGFILE\=$PANDORA_BASE_DECODED/g" $DAEMON_SCRIPT > $DAEMON_TEMP $DAEMON_SCRIPT > $DAEMON_TEMP
mv $DAEMON_TEMP $DAEMON_SCRIPT
sed -e "s/^DAEMON\=[.]*/DAEMON\=$PANDORA_BASE_DECODED/g" $DAEMON_SCRIPT > $DAEMON_TEMP
mv $DAEMON_TEMP $DAEMON_SCRIPT
sed -e "s/^DAEMON_TENTACLE\=[.]*/DAEMON_TENTACLE\=$PANDORA_BASE_DECODED/g" $DAEMON_SCRIPT > $DAEMON_TEMP
mv $DAEMON_TEMP $DAEMON_SCRIPT
sed -e "s/^PANDORA_USER\=.*/PANDORA_USER\=$PANDORA_USER/g" $DAEMON_SCRIPT > $DAEMON_TEMP
mv $DAEMON_TEMP $DAEMON_SCRIPT mv $DAEMON_TEMP $DAEMON_SCRIPT
fi fi
sed -e "s/^temporal [.]*/temporal $PANDORA_BASE_DECODED/g" $AGENT_CFG > $AGENT_CFG_TEMP sed -e "s|^temporal[ ]*|temporal $PANDORA_BASE|" \
mv $AGENT_CFG_TEMP $AGENT_CFG -e "s|^logfile[ ]*|logfile $PANDORA_BASE|" \
$AGENT_CFG > $AGENT_CFG_TEMP
sed -e "s/^logfile [.]*/logfile $PANDORA_BASE_DECODED/g" $AGENT_CFG > $AGENT_CFG_TEMP
mv $AGENT_CFG_TEMP $AGENT_CFG mv $AGENT_CFG_TEMP $AGENT_CFG
fi fi
echo "Creating Pandora FMS Agent home directory at $PANDORA_BASE$PANDORA_HOME" echo "Creating Pandora FMS Agent home directory at $PANDORA_BASE$PANDORA_HOME"
if [ ! -z "$PANDORA_BASE" ] if [ "$PANDORA_BASE" ]
then then
mkdir -p $PANDORA_BASE 2> /dev/null mkdir -p $PANDORA_BASE 2> /dev/null
mkdir -p $PANDORA_BASE/var/log 2> /dev/null mkdir -p $PANDORA_BASE/var/log 2> /dev/null
mkdir -p $PANDORA_BASE/$PANDORA_MAN/man1 2> /dev/null mkdir -p $PANDORA_BASE/$PANDORA_MAN/man1 2> /dev/null
if [ "$OS_NAME" = "FreeBSD" -o "$OS_NAME" = "NetBSD" ] mkdir -p $PANDORA_BASE$PREFIX/bin 2> /dev/null
then
mkdir -p $PANDORA_BASE/usr/local/bin 2> /dev/null
else
mkdir -p $PANDORA_BASE/usr/bin 2> /dev/null
fi
fi fi
mkdir -p $PANDORA_BASE$PANDORA_HOME 2> /dev/null mkdir -p $PANDORA_BASE$PANDORA_HOME 2> /dev/null
@ -344,14 +329,14 @@ install () {
mkdir -p $PANDORA_BASE$PANDORA_TEMP/data_out 2> /dev/null mkdir -p $PANDORA_BASE$PANDORA_TEMP/data_out 2> /dev/null
mkdir -p $PANDORA_BASE$PANDORA_CFG 2> /dev/null mkdir -p $PANDORA_BASE$PANDORA_CFG 2> /dev/null
mkdir -p $PANDORA_BASE$PANDORA_LOG_DIR 2> /dev/null mkdir -p $PANDORA_BASE$PANDORA_LOG_DIR 2> /dev/null
# Set the user the agent will run as # Set the user the agent will run as
if [ "$PANDORA_USER" != "root" ] if [ "$PANDORA_USER" != "root" ]
then then
sed -e "s/.*pandora_user .*/pandora_user $PANDORA_USER/" $AGENT_CFG > $AGENT_CFG_TEMP 2> /dev/null && \ sed -e "s/.*pandora_user .*/pandora_user $PANDORA_USER/" $AGENT_CFG > $AGENT_CFG_TEMP 2> /dev/null && \
mv $AGENT_CFG_TEMP $AGENT_CFG mv $AGENT_CFG_TEMP $AGENT_CFG
chmod 755 pandora_agent_daemon chmod 755 pandora_agent_daemon
chown -R $PANDORA_USER $PANDORA_BASE chown -R $PANDORA_USER $PANDORA_BASE 2>/dev/null
fi fi
# Create logfile # Create logfile
@ -365,31 +350,9 @@ install () {
# Copying agent and securing it # Copying agent and securing it
echo "Copying Pandora FMS Agent to $PANDORA_BASE$PANDORA_BIN..." echo "Copying Pandora FMS Agent to $PANDORA_BASE$PANDORA_BIN..."
install_perl_script -m 755 -o $PANDORA_USER -g 0 pandora_agent $PANDORA_BASE$PANDORA_BIN
if [ "$PANDORA_PERL_DECODED_PATH" != "" ] install_perl_script -m 755 -o $PANDORA_USER -g 0 pandora_agent_exec $PANDORA_BASE$PANDORA_EXEC_BIN
then install_perl_script -m 755 -o $PANDORA_USER -g 0 pandora_revent $PANDORA_BASE$PANDORA_REVENT_BIN
sed -e "s:^#\!.*:#\!$PANDORA_PERL_DECODED_PATH:g" pandora_agent > $PANDORA_BASE$PANDORA_BIN
else
cp pandora_agent $PANDORA_BASE$PANDORA_BIN
fi
chmod 755 $PANDORA_BASE$PANDORA_BIN
if [ "$PANDORA_PERL_DECODED_PATH" != "" ]
then
sed -e "s:^#\!.*:#\!$PANDORA_PERL_DECODED_PATH:g" pandora_agent_exec > $PANDORA_BASE$PANDORA_EXEC_BIN
else
cp pandora_agent_exec $PANDORA_BASE$PANDORA_EXEC_BIN
fi
chmod 755 $PANDORA_BASE$PANDORA_EXEC_BIN
if [ "$PANDORA_PERL_DECODED_PATH" != "" ]
then
sed -e "s:^#\!.*:#\!$PANDORA_PERL_DECODED_PATH:g" pandora_revent > $PANDORA_BASE$PANDORA_REVENT_BIN
else
cp pandora_revent $PANDORA_BASE$PANDORA_REVENT_BIN
fi
chmod 755 $PANDORA_BASE$PANDORA_REVENT_BIN
chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_BIN
chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_EXEC_BIN
chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_REVENT_BIN
echo "Copying Pandora FMS Agent configuration file to $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf..." echo "Copying Pandora FMS Agent configuration file to $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf..."
if [ -f $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf ] if [ -f $PANDORA_BASE/$PANDORA_CFG/pandora_agent.conf ]
@ -400,49 +363,36 @@ install () {
echo "Copying Pandora FMS Agent plugins to $PANDORA_BASE$PANDORA_HOME/plugins..." echo "Copying Pandora FMS Agent plugins to $PANDORA_BASE$PANDORA_HOME/plugins..."
if [ "$OS_NAME" = "NetBSD" ] [ -d $PANDORA_BASE$PANDORA_HOME/plugins ] || mkdir -p $PANDORA_BASE$PANDORA_HOME/plugins >/dev/null 2>&1
then for PLUGIN in plugins/*
if [ ! -d $PANDORA_BASE$PANDORA_HOME/plugins ] do
if grep '^#!.*/perl' $PLUGIN >/dev/null 2>&1
then then
mkdir -p $PANDORA_BASE$PANDORA_HOME/plugins install_perl_script $PLUGIN $PANDORA_BASE$PANDORA_HOME/$PLUGIN
else
cp $PLUGIN $PANDORA_BASE$PANDORA_HOME/plugins
fi fi
for i in `ls -1 plugins` done
do
sed s:/usr/bin/perl:/usr/pkg/bin/perl: plugins/$i > plugins/$i.tmp
cp plugins/$i.tmp $PANDORA_BASE$PANDORA_HOME/plugins/$i
rm plugins/$i.tmp
done
else
cp -r plugins $PANDORA_BASE$PANDORA_HOME
fi
chmod -R 700 $PANDORA_BASE$PANDORA_HOME/plugins chmod -R 700 $PANDORA_BASE$PANDORA_HOME/plugins
ln -s $PANDORA_BASE$PANDORA_HOME/plugins $PANDORA_BASE$PANDORA_CFG
DESTDIR=""
[ "$PANDORA_BASE" ] && [ $FAKEROOT -eq 1 ] && DESTDIR=$PANDORA_BASE
ln -s $DESTDIR$PANDORA_HOME/plugins $PANDORA_BASE$PANDORA_CFG
echo "Copying Pandora FMS Agent collections to $PANDORA_BASE$PANDORA_HOME/collections..." echo "Copying Pandora FMS Agent collections to $PANDORA_BASE$PANDORA_HOME/collections..."
cp -r collections $PANDORA_BASE$PANDORA_HOME cp -r collections $PANDORA_BASE$PANDORA_HOME
chmod -R 700 $PANDORA_BASE$PANDORA_HOME/collections chmod -R 700 $PANDORA_BASE$PANDORA_HOME/collections
ln -s $PANDORA_BASE$PANDORA_HOME/collections $PANDORA_BASE$PANDORA_CFG ln -s $DESTDIR$PANDORA_HOME/collections $PANDORA_BASE$PANDORA_CFG
echo "Copying tentacle server to $PANDORA_BASE$TENTACLE_SERVER" if [ $WITHOUT_TENTACLE_SERVER -eq 0 ]
if [ "$PANDORA_PERL_DECODED_PATH" != "" ] then
then echo "Copying tentacle server to $PANDORA_BASE$TENTACLE_SERVER"
sed -e "s:^#\!.*:#\!$PANDORA_PERL_DECODED_PATH:g" tentacle_server > $PANDORA_BASE$TENTACLE_SERVER install_perl_script -m 755 -o $PANDORA_USER -g 0 tentacle_server $PANDORA_BASE$TENTACLE_SERVER
else fi
cp tentacle_server $PANDORA_BASE$TENTACLE_SERVER
fi
chmod 755 $PANDORA_BASE$TENTACLE_SERVER
chown $PANDORA_USER:0 $PANDORA_BASE$TENTACLE_SERVER
echo "Copying tentacle client to $PANDORA_BASE$TENTACLE" echo "Copying tentacle client to $PANDORA_BASE$TENTACLE"
if [ "$PANDORA_PERL_DECODED_PATH" != "" ] install_perl_script -m 755 -o $PANDORA_USER -g 0 tentacle_client $PANDORA_BASE$TENTACLE
then
sed -e "s:^#\!.*:#\!$PANDORA_PERL_DECODED_PATH:g" tentacle_client > $PANDORA_BASE$TENTACLE
else
cp tentacle_client $PANDORA_BASE$TENTACLE
fi
chmod 755 $PANDORA_BASE$TENTACLE
chown $PANDORA_USER:0 $PANDORA_BASE$TENTACLE
echo "Installing the Pandora Agent and Tentacle Client manuals" echo "Installing the Pandora Agent and Tentacle Client manuals"
cp man/man1/tentacle_client.1.gz $PANDORA_BASE/$PANDORA_MAN/man1 cp man/man1/tentacle_client.1.gz $PANDORA_BASE/$PANDORA_MAN/man1
@ -451,14 +401,14 @@ install () {
chmod 644 $PANDORA_BASE/$PANDORA_MAN/man1/pandora_agent.1.gz chmod 644 $PANDORA_BASE/$PANDORA_MAN/man1/pandora_agent.1.gz
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 $PANDORA_USER $PANDORA_BASE$PANDORA_HOME chown -R $PANDORA_USER $PANDORA_BASE$PANDORA_HOME 2>/dev/null
chmod -R 700 $PANDORA_BASE$PANDORA_TEMP/data_out chmod -R 700 $PANDORA_BASE$PANDORA_TEMP/data_out
chmod 711 $PANDORA_BASE$PANDORA_LOG_DIR chmod 711 $PANDORA_BASE$PANDORA_LOG_DIR
chmod 640 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG chmod 640 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG
chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG chown $PANDORA_USER:0 $PANDORA_BASE$PANDORA_LOG_DIR/$PANDORA_LOG 2>/dev/null
if [ "$OS_NAME" = "FreeBSD" -o "$OS_NAME" = "NetBSD" ] if [ "$OS_NAME" = "FreeBSD" ] || [ "$OS_NAME" = "NetBSD" ]
then then
chown $PANDORA_USER:daemon $PANDORA_BASE$PANDORA_TEMP chown $PANDORA_USER:daemon $PANDORA_BASE$PANDORA_TEMP 2>/dev/null
chmod -R 770 $PANDORA_BASE$PANDORA_TEMP chmod -R 770 $PANDORA_BASE$PANDORA_TEMP
chmod 775 $PANDORA_BASE$PANDORA_TEMP chmod 775 $PANDORA_BASE$PANDORA_TEMP
fi fi
@ -467,83 +417,50 @@ install () {
cp $OS_NAME/pandora_agent.conf $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf cp $OS_NAME/pandora_agent.conf $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf
chmod 600 $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf chmod 600 $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf
chown $PANDORA_USER $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf chown $PANDORA_USER $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf 2>/dev/null
if [ "$OS_NAME" = "FreeBSD" -o "$OS_NAME" = "NetBSD" ] echo "Linking start-up daemon script '$DAEMON_SCRIPT' on $OS_NAME";
then
echo "Linking start-up daemon script 'pandora_agent' on $OS_NAME";
else
echo "Linking start-up daemon script 'pandora_agent_daemon' on $OS_NAME";
fi
if [ "$OS_NAME" = "Darwin" ] if [ "$OS_NAME" = "Darwin" ]
then then
# Specific service install on Darwin/macOSX # Specific service install on Darwin/macOSX
launchctl load -F Darwin/com.pandorafms.pandorafms.plist launchctl load -F Darwin/com.pandorafms.pandorafms.plist
echo "Start Pandora FMS service with 'launchctl start com.pandorafms.pandorafms'" echo "Start Pandora FMS service with 'launchctl start com.pandorafms.pandorafms'"
echo "This service has been scheduled to launch on each system startup" echo "This service has been scheduled to launch on each system startup"
fi else
cp $DAEMON_SCRIPT $DESTDIR$PANDORA_STARTUP
chmod 755 $DESTDIR$PANDORA_STARTUP
chown root:0 $DESTDIR$PANDORA_STARTUP 2>/dev/null
if [ "$OS_NAME" = "AIX" ] RCDIRS=""
then MSG=""
cp pandora_agent_daemon /etc/rc.pandora_agent_daemon if [ "$OS_NAME" = "AIX" ]
ln -s /etc/rc.pandora_agent_daemon /etc/rc.d/rc2.d/S90pandora_agent_daemon
chmod 755 $PANDORA_STARTUP
chown root:0 $PANDORA_STARTUP
echo "Pandora FMS agent has been included in /etc/rc.d/rc2.d/S90pandora_agent_daemon"
fi
if [ $OS_NAME = "HP-UX" ]
then
PANDORA_STARTUP=/sbin/init.d/pandora_agent_daemon
cp pandora_agent_daemon $PANDORA_STARTUP
ln -s /sbin/init.d/pandora_agent_daemon /sbin/rc3.d/S90pandora_agent_daemon 2> /dev/null
ln -s /sbin/init.d/pandora_agent_daemon /sbin/rc2.d/S90pandora_agent_daemon 2> /dev/null
chmod 755 $PANDORA_STARTUP
chown root:0 $PANDORA_STARTUP
echo "Pandora FMS agent has been included in /sbin/rcX.d/S90pandora_agent_daemon"
fi
if [ $OS_NAME = "SunOS" ]
then
PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon
cp pandora_agent_daemon $PANDORA_STARTUP
ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent_daemon 2> /dev/null
chmod 755 $PANDORA_STARTUP
chown root:0 $PANDORA_STARTUP
echo "Pandora FMS agent has been included in /etc/rc2.d/S90pandora_agent_daemon"
fi
if [ $OS_NAME = "Linux" ]
then
PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon
cp pandora_agent_daemon $PANDORA_STARTUP
if [ -d /etc/rc.d/ ]
then then
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc2.d/S90pandora_agent 2> /dev/null RCDIRS=/etc/rc.d/rc2.d
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc3.d/S90pandora_agent 2> /dev/null MSG="Pandora FMS agent has been included in $DESTDIR/etc/rc.d/rc2.d/S90pandora_agent_daemon"
else elif [ "$OS_NAME" = "HP-UX" ]
ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent 2> /dev/null then
ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent 2> /dev/null RCDIRS="/sbin/rc2.d /sbin/rc3.d"
MSG="Pandora FMS agent has been included in $DESTDIR/sbin/rcX.d/S90pandora_agent_daemon"
elif [ "$OS_NAME" = "SunOS" ]
then
RCDIRS=/etc/rc2.d
MSG="Pandora FMS agent has been included in $DESTDIR/etc/rc2.d/S90pandora_agent_daemon"
elif [ "$OS_NAME" = "Linux" ]
then
if [ -d /etc/rc.d/ ]
then
RCDIRS="/etc/rc.d/rc2.d /etc/rc.d/rc3.d"
else
RCDIRS="/etc/rc2.d /etc/rc3.d"
fi
fi fi
chmod 755 $PANDORA_STARTUP [ "$RCDIRS" ] && for RCDIR in $RCDIRS
chown root:0 $PANDORA_STARTUP do
fi [ $FAKEROOT -eq 1 ] && [ ! -d $DESTDIR$RCDIR ] && mkdir -p $DESTDIR$RCDIR >/dev/null 2>&1
ln -s $PANDORA_STARTUP $DESTDIR$RCDIR/S90pandora_agent 2> /dev/null
if [ "$OS_NAME" = "FreeBSD" ] done
then [ "$MSG" ] && echo "$MSG"
PANDORA_STARTUP=/usr/local/etc/rc.d/pandora_agent
cp FreeBSD/pandora_agent $PANDORA_STARTUP
chmod 555 $PANDORA_STARTUP
chown root:wheel $PANDORA_STARTUP
fi
if [ "$OS_NAME" = "NetBSD" ]
then
PANDORA_STARTUP=/etc/rc.d/pandora_agent
cp NetBSD/pandora_agent $PANDORA_STARTUP
chmod 555 $PANDORA_STARTUP
chown root:wheel $PANDORA_STARTUP
fi fi
echo "Done." echo "Done."
@ -556,7 +473,7 @@ install () {
echo " ($HOME/.ssh/id_dsa) under /home/pandora/.ssh/authorized_keys " echo " ($HOME/.ssh/id_dsa) under /home/pandora/.ssh/authorized_keys "
echo "on your Pandora FMS Server host" echo "on your Pandora FMS Server host"
echo " " echo " "
echo "You also need to setup your $PANDORA_BASE$PANDORA_CFG/pandora_agent.conf config file" echo "You also need to setup your $DESTDIR$PANDORA_CFG/pandora_agent.conf config file"
echo " " echo " "
if [ "$OS_NAME" = "FreeBSD" ] if [ "$OS_NAME" = "FreeBSD" ]
then then

View File

@ -1,10 +1,10 @@
#!/bin/bash #!/bin/sh
echo "<module>"; echo "<module>";
echo "<name>who</name>"; echo "<name>who</name>";
echo "<type>async_string</type>"; echo "<type>async_string</type>";
echo "<data><![CDATA[" echo "<data><![CDATA["
WHO=`who` WHO=`who`
if [ "$WHO" == "" ]; then if [ "$WHO" = "" ]; then
echo "None" echo "None"
else else
echo $WHO echo $WHO