From 019f6b6e28a0ecff94a22ef82e5489c7a43e931a Mon Sep 17 00:00:00 2001 From: guruevi Date: Fri, 25 Sep 2009 13:35:51 +0000 Subject: [PATCH] 2009-09-25 Evi Vanoost * mac_osx/pandora_fms/pandora_fms, mac_osx/pandora_fms/StartupParameters.plist: Updated for 3.0 * mac_osx/tentacle_client: Added for 3.0 * mac_osx/pandora_agent: Copied from Linux and modified * mac_osx/pandora_agent.conf: Slight modifications for 3.0 * mac_osx/pandora_agent_installer: Copied from Linux and modified * mac_osx/Pandora FMS.pmdoc: PackageMaker definition file to create Mac Packages for easy (automatic) deployment * mac_osx/Pandora Agent 3.0 for Mac: Package (installer) for Mac. This is an easy (click-to-run) package. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1975 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_agents/ChangeLog | 21 + .../Pandora FMS.pmdoc/01pandora-contents.xml | 1 + .../mac_osx/Pandora FMS.pmdoc/01pandora.xml | 1 + .../mac_osx/Pandora FMS.pmdoc/index.xml | 120 +++ pandora_agents/mac_osx/pandora_agent | 114 +-- pandora_agents/mac_osx/pandora_agent.conf | 106 +-- .../mac_osx/pandora_agent_installer | 126 ++-- .../pandora_fms/StartupParameters.plist | 2 +- .../mac_osx/pandora_fms/pandora_fms | 22 +- pandora_agents/mac_osx/tentacle_client | 682 ++++++++++++++++++ 10 files changed, 1031 insertions(+), 164 deletions(-) create mode 100644 pandora_agents/mac_osx/Pandora FMS.pmdoc/01pandora-contents.xml create mode 100644 pandora_agents/mac_osx/Pandora FMS.pmdoc/01pandora.xml create mode 100644 pandora_agents/mac_osx/Pandora FMS.pmdoc/index.xml create mode 100755 pandora_agents/mac_osx/tentacle_client diff --git a/pandora_agents/ChangeLog b/pandora_agents/ChangeLog index 4170e4b347..cc7229b3eb 100644 --- a/pandora_agents/ChangeLog +++ b/pandora_agents/ChangeLog @@ -1,3 +1,24 @@ +2009-09-25 Evi Vanoost + + * mac_osx/pandora_fms/pandora_fms, + mac_osx/pandora_fms/StartupParameters.plist: Updated for 3.0 + + * mac_osx/tentacle_client: Added for 3.0 + + * mac_osx/pandora_agent: Copied from Linux and modified + + * mac_osx/pandora_agent.conf: Slight modifications for 3.0 + + * mac_osx/pandora_agent_installer: Copied from Linux and + modified + + * mac_osx/Pandora FMS.pmdoc: PackageMaker definition file + to create Mac Packages for easy (automatic) deployment + + * mac_osx/Pandora Agent 3.0 for Mac: Package (installer) for + Mac. This is an easy (click-to-run) package. + + 2009-09-24 Sancho Lerena zslerena@artica.es> * linux/agent_installer: Fixed a typo in old setup backup cmd. diff --git a/pandora_agents/mac_osx/Pandora FMS.pmdoc/01pandora-contents.xml b/pandora_agents/mac_osx/Pandora FMS.pmdoc/01pandora-contents.xml new file mode 100644 index 0000000000..900de2f9c0 --- /dev/null +++ b/pandora_agents/mac_osx/Pandora FMS.pmdoc/01pandora-contents.xml @@ -0,0 +1 @@ +modemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemodemode \ No newline at end of file diff --git a/pandora_agents/mac_osx/Pandora FMS.pmdoc/01pandora.xml b/pandora_agents/mac_osx/Pandora FMS.pmdoc/01pandora.xml new file mode 100644 index 0000000000..1a420c09f0 --- /dev/null +++ b/pandora_agents/mac_osx/Pandora FMS.pmdoc/01pandora.xml @@ -0,0 +1 @@ +org.pandorafms.pandoraAgent30ForMac.pandoraInstaller.pkg1/parentinstallTo01pandora-contents.xml/CVS$/\.svn$/\.cvsignore$/\.cvspass$/\.DS_Store$Pandora Installer \ No newline at end of file diff --git a/pandora_agents/mac_osx/Pandora FMS.pmdoc/index.xml b/pandora_agents/mac_osx/Pandora FMS.pmdoc/index.xml new file mode 100644 index 0000000000..e134ad72c1 --- /dev/null +++ b/pandora_agents/mac_osx/Pandora FMS.pmdoc/index.xml @@ -0,0 +1,120 @@ +Pandora Agent 3.0 for Mac/Volumes/rcbiUsers/vanooste/Pandora/trunk/pandora_agents/mac_osx/Pandora Agent 3.0 for Mac.mpkgorg.pandorafms/Volumes/rcbiUsers/vanooste/Pandora/trunk/pandora_console/images/pandora_logo_head.png01pandora.xmlproperties.customizeOptionextraFilesproperties.titleproperties.systemDomainproperties.anywhereDomain \ No newline at end of file diff --git a/pandora_agents/mac_osx/pandora_agent b/pandora_agents/mac_osx/pandora_agent index 9a774250c5..485599d04b 100755 --- a/pandora_agents/mac_osx/pandora_agent +++ b/pandora_agents/mac_osx/pandora_agent @@ -1,13 +1,13 @@ #!/bin/bash # ********************************************************************** -# Pandora FMS Generic MacOS Agent -# (c) 2009 Artica Soluciones Tecnológicas SL +# Pandora FMS Generic Linux Agent +# (c) 2009 Artica Soluciones Tecnológicas # with the help of many people. Please see http://pandorafms.org # This code is licensed under GPL 2.0 license. # ********************************************************************** -AGENT_VERSION=2.0 -AGENT_BUILD=081211 +AGENT_VERSION=3.0 +AGENT_BUILD=090818 # ********************************************************************** # function configure_agent() @@ -91,7 +91,7 @@ function configure_agent { elif [ ! -z "`echo $a | grep -e '^cron_mode'`" ] then CRON_MODE=1 - echo "$TIMESTAMP - [SETUP] - Scheduled mode enabled" >> $PANDORA_LOGFILE + echo "$TIMESTAMP - [SETUP] - Cronmode enabled" >> $PANDORA_LOGFILE elif [ ! -z "`echo $a | grep -e '^server_opts'`" ] then SERVER_OPTS=`echo $a | cut -d" " -f2-` @@ -153,27 +153,37 @@ function configure_agent { SECONDARY_TENTACLE_OPTS="$SECONDARY_SERVER_OPTS $SECONDARY_TENTACLE_OPTS" echo "$TIMESTAMP - [SETUP] - Extra options for the secondary Tentacle client $SECONDARY_SERVER_OPTS" >> $PANDORA_LOGFILE fi + # Agent description + elif [ ! -z "`echo $a | grep -e '^description'`" ] + then + AGENT_DESCRIPTION=`echo $a | cut -d" " -f2-` + # Agent group + elif [ ! -z "`echo $a | grep -e '^group'`" ] + then + AGENT_GROUP=`echo $a | cut -d" " -f2-` + + # Agent autotime (use always current server time) + elif [ ! -z "`echo $a | grep -e '^autotime'`" ] + then + AGENT_AUTOTIME=`echo $a | cut -d" " -f2-` 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 "Pandora FMS Agent $AGENT_VERSION (c) Artica ST 2003-2009" + echo "This program is licensed under GPL2 Terms. http://pandorafms.org" echo "Running in $NOMBRE_HOST at $TIMESTAMP" echo " " else - # Checks if there is another instance running in cron mode - # there is no pidof in Mac OS X. We use good ol' pid files - PID_RUNNING=`cat /tmp/pandora_agent_cron.pid 2> /dev/null || echo 0` + # 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 - else - echo $PID_ME > /tmp/pandora_agent_cron.pid fi fi @@ -354,15 +364,15 @@ function check_remote_config { return 1 fi - # Agent name md5 (md5sum is not available on Mac OS X except through Fink) - AGENT_MD5=`echo -n $NOMBRE_HOST | md5` + # 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 md5 (md5 has the hash on 4 instead of md5sum's 1) - CONFIG_MD5=`md5 $PANDORA_HOME/pandora_agent.conf | cut -d" " -f4` + # Local config file md5sum + CONFIG_MD5=`md5sum $PANDORA_HOME/pandora_agent.conf | cut -d" " -f1` - # Get remote config file + # Get remote config file md5sum recv_file "$MD5_FILE" # Configuration has not been uploaded to the server @@ -454,33 +464,35 @@ OS_NAME=`uname -s` PANDORA_LOGFILE=/var/log/pandora/pandora_agent.log TEMP=/tmp -# Check version +# 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 -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}'` + OS_VERSION=`cat /etc/SuSE-release | grep VERSION | cut -f 3 -d " "` + LINUX_DISTRO=SUSE else - LINUX_DISTRO=$OS_NAME - OS_VERSION=`uname -r` + 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 # Configure this agent @@ -499,6 +511,11 @@ do # 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"` + if [ "$AGENT_AUTOTIME" == "1" ] + then + TIMESTAMP="AUTO" + fi + # File names DATA=$TEMP/$NOMBRE_HOST.$SERIAL.data @@ -506,7 +523,7 @@ do # Makes data packet echo " " > $DATA - echo "" >> $DATA + echo "" >> $DATA for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v -e "^#" | grep -e "^module" ` do @@ -597,6 +614,13 @@ do fi fi + # Module postprocess info + if [ ! -z "`echo $a | grep -e '^module_postprocess'`" ] + then + pprocess=`echo $a | cut -d" " -f2-` + echo "" >> $DATA2 + fi + # If module ends, and execute for this module is enabled # then write @@ -644,12 +668,10 @@ do # Cron mode if [ "$CRON_MODE" == "1" ] then - #remove pid file first - rm /tmp/pandora_agent_cron.pid - exit + exit fi # Go to bed :-) sleep $INTERVAL done -# This runs forever! +# This runs forever! diff --git a/pandora_agents/mac_osx/pandora_agent.conf b/pandora_agents/mac_osx/pandora_agent.conf index b2d8404839..fe7d07b77d 100755 --- a/pandora_agents/mac_osx/pandora_agent.conf +++ b/pandora_agents/mac_osx/pandora_agent.conf @@ -1,8 +1,7 @@ # Base config file for Pandora FMS agents -# Version 2.0 +# Version 3.0 # Licensed under GPL license v2, -# (c) 2003-2008 Artica Soluciones Tecnologicas -# (c) 2003-2008 Sancho Lerena +# (c) 2003-2009 Artica Soluciones Tecnologicas # please visit http://pandora.sourceforge.net # General Parameters @@ -23,6 +22,17 @@ debug 0 # By default, agent takes machine name #agent_name adama +# Agent description +#description Demo agent + +# Group assigned for this agent (descriptive, p.e: Servers) +#group Servers + +# Autotime: Enforce to server to ignore timestamp coming from this +# agent, used when agents has no timer or it's inestable. 1 to enable +# this feature +# autotime 1 + # By default agent try to take default encoding defined in host. # encoding iso-8859-15 @@ -56,8 +66,8 @@ transfer_mode tentacle # is much more safe. # cron_mode -# If set to 1 allows the agent to be configured via the web console. -# remote_config 0 +# If set to 1 allows the agent to be configured via the web console (Only Enterprise version) +# remote_config 1 # Secondary server configuration # ============================== @@ -82,7 +92,7 @@ transfer_mode tentacle module_begin module_name CPU (User) module_type generic_data -module_exec iostat -C | tail -1 | awk '{ print $10 }' +module_exec iostat -C | tail -1 | awk '{ print $4 }' module_max 100 module_min 0 module_descripcion User CPU Usage (%) @@ -91,37 +101,19 @@ module_end module_begin module_name CPU (System) module_type generic_data -module_exec iostat -C | tail -1 | awk '{ print $11 }' +module_exec iostat -C | tail -1 | awk '{ print $5 }' module_max 100 module_min 0 module_description System CPU Usage (%) module_end module_begin -module_name Disk Space on / (Available) +module_name Disk Space on / (% Available) module_type generic_data module_exec df -kh / | tail -1 | awk '{ print 100-$5 }' module_max 100 module_min 0 -module_description Free disk Percentage of root partition -module_end - -module_begin -module_name Disk Space on /Volumes/Backup (Available) -module_type generic_data -module_exec df -kh /Volumes/Backup | tail -1 | awk '{ print 100-$5 }' -module_max 100 -module_min 0 -module_description Free disk Percentage of /Volumes/Backup partition -module_end - -module_begin -module_name Disk Space on /Volumes/Backup-MJ (Available) -module_type generic_data -module_exec df -kh /Volumes/Backup-MJ | tail -1 | awk '{ print 100-$5 }' -module_max 100 -module_min 0 -module_description Free disk Percentage of /Volumes/Backup-MJ partition +module_description Free disk percentage of root partition module_end module_begin @@ -231,21 +223,21 @@ module_end #module_description DHCP & BOOTP server #module_end -module_begin -module_name DNS -module_type generic_proc -module_exec ps -A | grep "sbin\/named" | wc -l -module_description DNS Server -module_end +#module_begin +#module_name DNS +#module_type generic_proc +#module_exec ps -A | grep "sbin\/named" | wc -l +#module_description DNS Server +#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 +#module_begin +#module_name Firewall Status +#module_type generic_data +#module_exec ipfw show | wc -l +#module_description Firewall (number of rules) +#module_end #module_begin #module_name FTP @@ -318,12 +310,12 @@ module_end #module_description NFS File Server #module_end -module_begin -module_name Open Directory -module_type generic_proc -module_exec ps -A | grep "bin\/krb5kdc" | wc -l -module_description Open Directory -module_end +#module_begin +#module_name Open Directory +#module_type generic_proc +#module_exec ps -A | grep "bin\/krb5kdc" | wc -l +#module_description Open Directory +#module_end #module_begin #module_name Print @@ -339,12 +331,12 @@ module_end #module_description QT Streaming Service #module_end -module_begin -module_name Software Update -module_type generic_proc -module_exec ps -A | grep "etc\/swupd" | wc -l -module_description Software Update -module_end +#module_begin +#module_name Software Update +#module_type generic_proc +#module_exec ps -A | grep "etc\/swupd" | wc -l +#module_description Software Update +#module_end #module_begin #module_name VPN @@ -381,5 +373,13 @@ module_end #module_description XGrid #module_end -# Plugin Section # -module_plugin ppc_sensors +# Plugin example + +# This parses /var/log/syslog file, under the module name "syslog" +# And search for "ssh" string into it, sending only that information. + +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 diff --git a/pandora_agents/mac_osx/pandora_agent_installer b/pandora_agents/mac_osx/pandora_agent_installer index 87c79fe43d..6ce23fc507 100755 --- a/pandora_agents/mac_osx/pandora_agent_installer +++ b/pandora_agents/mac_osx/pandora_agent_installer @@ -1,19 +1,23 @@ #!/bin/bash -# ********************************************************************** -# Pandora FMS Agent - Generic Host Agent Installer -# Mac OS X version -# (c) 2007-2008 Sancho Lerena -# Please see http://pandora.sourceforge.net + +# Pandora FMS Agent Installer (c) 2008-2009 Artica ST +# Linux Version (generic), for SuSe and Debian/Ubuntu only +# other Linux distros could not work properly without modifications +# Please see http://www.pandorafms.org +# v3.0 Build 090810 # This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION=2.0 +PI_VERSION=3.0 PANDORA_BIN=/usr/bin/pandora_agent 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=/Library/StartupItems/pandora_fms +PANDORA_STARTUP=/Library/StartupItems/ +TENTACLE=/usr/bin/tentacle_client +PANDORA_CFG_FILE=/etc/pandora/pandora_agent.conf + FORCE=0 LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"` @@ -27,50 +31,59 @@ then exit 1 fi +get_distro () { + LINUX_DISTRO=`uname -s` + OS_VERSION=`uname -r` + + echo $LINUX_DISTRO +} + uninstall () { echo "Removing Pandora FMS Agent..." rm -Rf $PANDORA_BIN rm -Rf $PANDORA_TEMP - rm -Rf $PANDORA_CFG - rm -Rf $PANDORA_STARTUP + rm -Rf $PANDORA_CFG_FILE + rm -Rf $PANDORA_STARTUP"pandora_fms" rm -Rf $PANDORA_HOME rm -Rf $PANDORA_LOG + rm -Rf $TENTACLE echo "Done" } install () { + + DISTRO=`get_distro` + OLDFILENAMETMP=`date +"%Y-%m-%d"` + + echo "Detected Operating System: $DISTRO" + if [ -f $PANDORA_HOME ] && [ "$FORCE" = "0" ] then echo "Seems that default dir already exists. Please use --force to" - echo "force installer to overwrite $PANDORA_HOME" + echo "force installer to install on $PANDORA_HOME" exit - elif [ "$FORCE" = "1" ] - then - #Trying to create directories in case of upgrade - echo "Checking existing directories..." - mkdir $PANDORA_HOME 2> /dev/null - mkdir $PANDORA_TEMP 2> /dev/null - mkdir $PANDORA_TEMP/data_out 2> /dev/null - mkdir $PANDORA_CFG 2> /dev/null - mkdir /var/log/pandora 2> /dev/null - else - echo "Creating Pandora FMS Agent home directory at $PANDORA_HOME ..." - mkdir $PANDORA_HOME - mkdir $PANDORA_TEMP - mkdir $PANDORA_TEMP/data_out - mkdir $PANDORA_CFG - mkdir /var/log/pandora + else + echo "Checking default dir $PANDORA_HOME..." fi if [ -f $PANDORA_BIN ] && [ "$FORCE" = "0" ] then echo "Seems that $PANDORA_BIN already exists. Please use --force to" - echo "force installer to overwrite it" + echo "force installer to reinstall overwriting it" + echo " " exit else echo "Checking Pandora FMS Agent on $PANDORA_BIN...." fi + # Create directories + echo "Creating Pandora FMS Agent home directory at $PANDORA_HOME ..." + mkdir $PANDORA_HOME 2> /dev/null + mkdir $PANDORA_TEMP 2> /dev/null + mkdir $PANDORA_TEMP/data_out 2> /dev/null + mkdir $PANDORA_CFG 2> /dev/null + mkdir /var/log/pandora 2> /dev/null + # Create logfile if [ ! -z "`touch $PANDORA_LOG`" ] then @@ -84,44 +97,51 @@ install () { # Copying agent and securing it echo "Copying Pandora FMS Agent to $PANDORA_BIN..." cp pandora_agent $PANDORA_BIN - chmod 700 $PANDORA_BIN + #chmod 700 $PANDORA_BIN - echo "Copying Pandora FMS Agent contrib dir to $PANDORA_HOME/..." - cp pandora_agent_daemon $PANDORA_HOME - echo "Copying Pandora FMS Agent configuration file to $PANDORA_HOME/pandora_agent.conf..." - if [ -f $PANDORA_HOME/pandora_agent.conf ] - then - echo "Configuration file already exists. The new config will be in $PANDORA_HOME/pandora_agent.conf.new" - cp pandora_agent.conf $PANDORA_HOME/pandora_agent.conf.new - else - cp pandora_agent.conf $PANDORA_HOME - chmod 600 $PANDORA_HOME/pandora_agent.conf - fi - + if [ -e /etc/pandora/pandora_agent.conf ] + then + cat /etc/pandora/pandora_agent.conf > /etc/pandora/pandora/pandora_agent.conf.$OLDFILENAMETMP + echo "Backing up old configuration file to /etc/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 + echo "Copying Pandora FMS Agent plugins to $PANDORA_HOME/plugins..." cp -r plugins $PANDORA_HOME - chmod -R 700 $PANDORA_HOME/plugins + #chmod -R 700 $PANDORA_HOME/plugins + + echo "Copying tentacle client to $TENTACLE" + cp tentacle_client $TENTACLE + 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..." - 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 "Setting secure permissions and ownership for all Pandora FMS Agent files..." chown -R root $PANDORA_HOME - chmod -R 600 $PANDORA_TEMP/data_out + #chmod -R 600 $PANDORA_TEMP/data_out chmod 640 $PANDORA_LOG - chgrp 3 $PANDORA_LOG - echo "Copying start-up daemon script at $PANDORA_STARTUP"; + chgrp root $PANDORA_LOG + + echo "Linking start-up daemon script at $PANDORA_STARTUP"; cp -R pandora_fms $PANDORA_STARTUP - chown -R root:wheel $PANDORA_STARTUP - chmod -R 744 $PANDORA_STARTUP - chown -R root $PANDORA_BIN + + chown -R root:root $PANDORA_BIN + echo "Done." echo " " echo "You have your startup script ready at $PANDORA_STARTUP" - echo "First you need to copy your public SSH keys ($HOME/.ssh/id_dsa)" + echo " " + 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 "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 " " @@ -137,8 +157,8 @@ help () { # Script banner at start echo " " -echo "Pandora FMS Agent Installer $PI_VERSION (c) 2007 Sancho Lerena" -echo "This program is licensed under GPL2 Terms. http://pandora.sourceforge.net" +echo "Pandora FMS Agent Installer $PI_VERSION (c) 2008-2009 ArticaST" +echo "This program is licensed under GPL2 Terms. http://pandorafms.com" echo " " case "$MODE" in diff --git a/pandora_agents/mac_osx/pandora_fms/StartupParameters.plist b/pandora_agents/mac_osx/pandora_fms/StartupParameters.plist index c0dc234aa4..ba7d8f3464 100644 --- a/pandora_agents/mac_osx/pandora_fms/StartupParameters.plist +++ b/pandora_agents/mac_osx/pandora_fms/StartupParameters.plist @@ -3,7 +3,7 @@ Description - Pandora FMS Agent 2.0 (Mac) + Pandora FMS Agent 3.0 (Mac) OrderPreference None Provides diff --git a/pandora_agents/mac_osx/pandora_fms/pandora_fms b/pandora_agents/mac_osx/pandora_fms/pandora_fms index e6e67f96f8..c4d25e3e90 100755 --- a/pandora_agents/mac_osx/pandora_fms/pandora_fms +++ b/pandora_agents/mac_osx/pandora_fms/pandora_fms @@ -3,7 +3,7 @@ # Generic GNU/Linux version # (c) Sancho Lerena, # (c) Evi Vanoost -# v2.0 +# v3.0 PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin PANDORA_PATH=/etc/pandora @@ -32,8 +32,8 @@ StartService() fi fi - nohup $DAEMON $PANDORA_PATH 2> $LOGFILE & MYPID=$! - echo $MYPID > $PIDFILE + $DAEMON $PANDORA_PATH > $LOGFILE 2>&1 & + echo $! > $PIDFILE echo "Pandora FMS Agent is now running with PID $MYPID" } @@ -41,15 +41,15 @@ StopService() { if [ -f $PIDFILE ] then - echo "Stopping Pandora Agent." - PID_2=`cat $PIDFILE` - if [ ! -z "`ps -A | grep -v grep | grep 'pandora_agent'`" ] - then - kill -9 $PID_2 - fi - rm -f $PIDFILE + echo "Stopping Pandora Agent." + PID_BA=`cat $PIDFILE` + if [ ! -z "`ps -A | grep -v grep | grep 'pandora_agent'`" ] + then + kill $PID_BA + fi + rm -f $PIDFILE else - echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..." + echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..." fi } diff --git a/pandora_agents/mac_osx/tentacle_client b/pandora_agents/mac_osx/tentacle_client new file mode 100755 index 0000000000..2e3e27c7cf --- /dev/null +++ b/pandora_agents/mac_osx/tentacle_client @@ -0,0 +1,682 @@ +#!/usr/bin/perl + +eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' + if 0; # not running under some shell +################################################################################ +# +# Copyright (c) 2007-2008 Ramon Novoa +# Copyright (c) 2007-2008 Artica Soluciones Tecnologicas S.L. +# +# tentacle_client.pl Tentacle Client. See http://www.openideas.info/wiki for +# protocol description. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +################################################################################ + +package tentacle::client; + +use strict; +use File::Basename; +use Getopt::Std; +use IO::Select; +use IO::Socket::INET; + +# Program version +our $VERSION = '0.2.0'; + +# Server address +my $t_address = '127.0.0.1'; + +# Block size for socket read/write operations in bytes +my $t_block_size = 1024; + +# Log messages, 1 enabled, 0 disabled +my $t_log = 0; + +# Server port +my $t_port = 41121; + +# Do not output error messages, 1 enabled, 0 disabled +my $t_quiet = 0; + +# Server password +my $t_pwd = ''; + +# Receive mode, 1 enabled, 0 disabled +my $t_recv = 0; + +# Retries for socket read/write operations +my $t_retries = 3; + +# Select handler +my $t_select; + +# Server socket +my $t_socket; + +# Use SSL, 1 true, 0 false +my $t_ssl = 0; + +# SSL ca certificate file +my $t_ssl_ca = ''; + +# SSL certificate file +my $t_ssl_cert = ''; + +# SSL private key file +my $t_ssl_key = ''; + +# SSL private key file password +my $t_ssl_pwd = ''; + +# Timeout for socket read/write operations in seconds +my $t_timeout = 1; + +################################################################################ +## SUB print_help +## Print help screen. +################################################################################ +sub print_help { + + print ("Usage: $0 [options] [file] [file] ...\n\n"); + print ("Tentacle client v$VERSION. See http://www.openideas.info/wiki for protocol description.\n\n"); + print ("Options:\n"); + print ("\t-a address\tServer address (default $t_address).\n"); + print ("\t-c\t\tEnable SSL without a client certificate.\n"); + print ("\t-e cert\t\tOpenSSL certificate file. Enables SSL.\n"); + print ("\t-f ca\t\tVerify that the peer certificate is signed by a ca.\n"); + print ("\t-g\t\tGet files from the server.\n"); + print ("\t-h\t\tShow help.\n"); + print ("\t-k key\t\tOpenSSL private key file.\n"); + print ("\t-p port\t\tServer port (default $t_port).\n"); + print ("\t-q\t\tQuiet. Do now print error messages.\n"); + print ("\t-r number\tNumber of retries for network operations (default $t_retries).\n"); + print ("\t-t time\t\tTime-out for network operations in seconds (default ${t_timeout}s).\n"); + print ("\t-v\t\tBe verbose.\n"); + print ("\t-w\t\tPrompt for OpenSSL private key password.\n"); + print ("\t-x pwd\t\tServer password.\n\n"); +} + +################################################################################ +## SUB parse_options +## Parse command line options and initialize global variables. +################################################################################ +sub parse_options { + my %opts; + my $tmp; + + # Get options + if (getopts ('a:ce:f:ghk:p:qr:t:vwx:', \%opts) == 0 || defined ($opts{'h'})) { + print_help (); + exit 1; + } + + # Address + if (defined ($opts{'a'})) { + $t_address = $opts{'a'}; + if ($t_address !~ /^[a-zA-Z\.]+$/ && ($t_address !~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/ + || $1 < 0 || $1 > 255 || $2 < 0 || $2 > 255 + || $3 < 0 || $3 > 255 || $4 < 0 || $4 > 255)) { + error ("Address $t_address is not valid."); + } + + } + + # Enable SSL without a client certificate + if (defined ($opts{'c'})) { + require IO::Socket::SSL; + $t_ssl = 1; + } + + # Enable SSL + if (defined ($opts{'e'})) { + + if (defined ($opts{'c'})) { + error ("Flags -c and -e can not be used at the same time."); + } + + require IO::Socket::SSL; + + $t_ssl_cert = $opts{'e'}; + if (! -f $t_ssl_cert) { + error ("File $t_ssl_cert does not exist."); + } + + $t_ssl = 1; + } + + # Verify peer certificate + if (defined ($opts{'f'})) { + + if (! defined ($opts{'e'})) { + error ("Flag -e must be set to enable peer certificate verify."); + } + + $t_ssl_ca = $opts{'f'}; + if (! -f $t_ssl_ca) { + error ("File $t_ssl_ca does not exist."); + } + } + + # Get files + if (defined ($opts{'g'})) { + $t_recv = 1; + } + + # SSL private key file + if (defined ($opts{'k'})) { + + if (! defined ($opts{'e'})) { + error ("Flag -e must be set to use a private key file."); + } + + $t_ssl_key = $opts{'k'}; + if (! -f $t_ssl_key) { + error ("File $t_ssl_key does not exist."); + } + } + + # Port + if (defined ($opts{'p'})) { + $t_port = $opts{'p'}; + if ($t_port !~ /^\d+$/ || $t_port < 1 || $t_port > 65535) { + error ("Port $t_port is not valid."); + } + } + + # Quiet mode + if (defined ($opts{'q'})) { + $t_quiet = 1; + } + + # Retries + if (defined ($opts{'r'})) { + $t_retries = $opts{'r'}; + if ($t_retries !~ /^\d+$/ || $t_retries < 1) { + error ("Invalid number of retries for network operations."); + } + } + + # Timeout + if (defined ($opts{'t'})) { + $t_timeout = $opts{'t'}; + if ($t_timeout !~ /^\d+$/ || $t_timeout < 1) { + error ("Invalid timeout for network operations."); + } + } + + # Be verbose + if (defined ($opts{'v'})) { + $t_log = 1; + } + + # SSL private key password + if (defined ($opts{'w'})) { + + if (! defined ($opts{'e'})) { + error ("Flag -k must be set to provide a private key password."); + } + + $t_ssl_pwd = ask_passwd ("Enter private key file password: ", "Enter private key file password again for confirmation: "); + } + + # Server password + if (defined ($opts{'x'})) { + $t_pwd = $opts{'x'}; + } +} + +################################################################################ +## SUB start_client +## Open the server socket. +################################################################################ +sub start_client { + + # Connect to server + $t_socket = IO::Socket::INET->new ( + PeerAddr => $t_address, + PeerPort => $t_port, + ); + + if (! defined ($t_socket)) { + error ("Cannot connect to $t_address on port $t_port: $!."); + } + + # Add server socket to select queue + $t_select = IO::Select->new (); + $t_select->add ($t_socket); + + print_log ("Connected to $t_address port $t_port"); +} + +################################################################################ +## SUB stop_client +## Close the server socket. +################################################################################ +sub stop_client { + + $t_socket->close (); +} + +################################################################################ +## SUB start_ssl +## Convert the server socket to an IO::Socket::SSL socket. +################################################################################ +sub start_ssl { + my $err; + + if ($t_ssl_cert eq ''){ + IO::Socket::SSL->start_SSL ( + $t_socket, + ); + } + elsif ($t_ssl_ca eq '') { + IO::Socket::SSL->start_SSL ( + $t_socket, + SSL_cert_file => $t_ssl_cert, + SSL_key_file => $t_ssl_key, + SSL_passwd_cb => sub {return $t_ssl_pwd}, + SSL_use_cert =>'1', + # No authentication + SSL_verify_mode => '0x00', + ); + } + else { + IO::Socket::SSL->start_SSL ( + $t_socket, + SSL_ca_file => $t_ssl_ca, + SSL_cert_file => $t_ssl_cert, + SSL_key_file => $t_ssl_key, + SSL_passwd_cb => sub {return $t_ssl_pwd}, + SSL_use_cert =>'1', + # Verify peer + SSL_verify_mode => '0x01', + ); + } + + $err = IO::Socket::SSL::errstr (); + if ($err ne '') { + error ($err); + } +} + +################################################################################ +## SUB auth_pwd +## Authenticate client with server password. +################################################################################ +sub auth_pwd { + my $command; + my $pwd_digest; + + require Digest::MD5; + + $pwd_digest = Digest::MD5::md5 ($t_pwd); + $pwd_digest = Digest::MD5::md5_hex ($pwd_digest); + + send_data ("PASS $pwd_digest\n"); + + $command = recv_command ($t_block_size); + if ($command !~ /^PASS OK$/) { + error ("Authentication failed."); + } +} + +################################################################################ +## SUB recv_file +## Receive a file from the server +################################################################################ +sub recv_file { + my $data = ''; + my $file = $_[0]; + my $response; + my $size; + + # Request file + send_data ("RECV <$file>\n"); + + # Wait for server response + $response = recv_command (); + if ($response !~ /^RECV SIZE (\d+)$/) { + error ("Server responded $response."); + } + + $size = $1; + send_data ("RECV OK\n"); + + # Receive file + $data = recv_data_block ($size); + + # Write it to disk + open (FILE, "> $file") || error ("Cannot open file '$file' for writing."); + binmode (FILE); + print (FILE $data); + close (FILE); + + print_log ("Received file '$file'"); +} + +################################################################################ +## SUB send_file +## Send a file to the server +################################################################################ +sub send_file { + my $base_name; + my $data = ''; + my $response = ''; + my $retries; + my $file = $_[0]; + my $size; + my $written; + + $base_name = basename ($file); + $size = -s $file; + + # Request to send file + send_data ("SEND <$base_name> SIZE $size\n"); + + print_log ("Request to send file '$base_name' size ${size}b"); + + # Wait for server response + $response = recv_command (); + + # Server rejected the file + if ($response ne "SEND OK") { + send_data ("QUIT\n"); + error ("Server responded $response."); + } + + print_log ("Server responded SEND OK"); + + # Send the file + open (FILE, $file) || error ("Cannot open file '$file' for reading."); + binmode (FILE); + + while ($data = ) { + send_data ($data); + } + + close (FILE); + + # Wait for server response + $response = recv_command (); + if ($response ne "SEND OK") { + send_data ("QUIT\n"); + error ("Server responded $response."); + } + + print_log ("File sent"); +} + +################################################################################ +# Common functions +################################################################################ + +################################################################################ +## SUB print_log +## Print log messages. +################################################################################ +sub print_log { + + if ($t_log == 1) { + print (STDOUT "[log] $_[0]\n"); + } +} + +################################################################################ +## SUB error +## Print an error and exit the program. +################################################################################ +sub error { + + if ($t_quiet == 0) { + print (STDERR "[err] $_[0]\n"); + } + + exit 1; +} + +################################################################################ +## SUB recv_data +## Read data from the client socket. Returns the number of bytes read and the +## string of bytes as a two element array. +################################################################################ +sub recv_data { + my $data; + my $read; + my $retries = 0; + my $size = $_[0]; + + while (1) { + + # Try to read data from the socket + if ($t_select->can_read ($t_timeout)) { + + # Read at most $size bytes + $read = sysread ($t_socket, $data, $size); + + # Read error + if (! defined ($read)) { + error ("Read error from " . $t_socket->sockhost () . ": $!."); + } + + # EOF + if ($read == 0) { + error ("Connection from " . $t_socket->sockhost () . " unexpectedly closed."); + } + + return ($read, $data); + } + + # Retry + $retries++; + + # But check for error conditions first + if ($retries > $t_retries) { + error ("Connection from " . $t_socket->sockhost () . " timed out."); + } + } +} + +################################################################################ +## SUB send_data +## Write data to the client socket. +################################################################################ +sub send_data { + my $data = $_[0]; + my $retries = 0; + my $size; + my $total = 0; + my $written; + + $size = length ($data); + + while (1) { + + # Try to write data to the socket + if ($t_select->can_write ($t_timeout)) { + + $written = syswrite ($t_socket, $data, $size - $total, $total); + + # Read error + if (! defined ($written)) { + error ("Connection error from " . $t_socket->sockhost () . ": $!."); + } + + # EOF + if ($written == 0) { + error ("Connection from " . $t_socket->sockhost () . " unexpectedly closed."); + } + + } + + $total += $written; + + # All data was written + if ($total == $size) { + return; + } + + # Retry + $retries++; + + # But check for error conditions first + if ($retries > $t_retries) { + error ("Connection from " . $t_socket->sockhost () . " timed out."); + } + } +} + +################################################################################ +## SUB recv_command +## Read a command from the client, ended by a new line character. +################################################################################ +sub recv_command { + my $buffer; + my $char; + my $command = ''; + my $read; + my $total = 0; + + while (1) { + + ($read, $buffer) = recv_data ($t_block_size); + $command .= $buffer; + $total += $read; + + # Check if the command is complete + $char = chop ($command); + if ($char eq "\n") { + return $command; + } + + $command .= $char; + + # Avoid overflow + if ($total > $t_block_size) { + error ("Received too much data from " . $t_socket->sockhost ()); + } + } +} + +################################################################################ +## SUB recv_data_block +## Read $_[0] bytes of data from the client. +################################################################################ +sub recv_data_block { + my $buffer = ''; + my $data = ''; + my $read; + my $size = $_[0]; + my $total = 0; + + while (1) { + + ($read, $buffer) = recv_data ($size - $total); + $data .= $buffer; + $total += $read; + + # Check if all data has been read + if ($total == $size) { + return $data; + } + } +} + +################################################################################ +## SUB ask_passwd +## Asks the user for a password. +################################################################################ +sub ask_passwd { + my $msg1 = $_[0]; + my $msg2 = $_[1]; + my $pwd1; + my $pwd2; + + require Term::ReadKey; + + # Disable keyboard echo + Term::ReadKey::ReadMode('noecho'); + + # Promt for password + print ($msg1); + $pwd1 = Term::ReadKey::ReadLine(0); + print ("\n$msg2"); + $pwd2 = Term::ReadKey::ReadLine(0); + print ("\n"); + + # Restore original settings + Term::ReadKey::ReadMode('restore'); + + if ($pwd1 ne $pwd2) { + # Call print to bypass quiet mode. + print ("[err] Passwords do not match.\n"); + exit 1; + } + + # Remove the trailing new line character + chop $pwd1; + + return $pwd1; +} + +################################################################################ +# Main +################################################################################ + +my $file; + +# Parse command line options +parse_options (); + +# Check command line arguments +if ($t_recv == 0 && $#ARGV == -1) { + error ("No files to send."); +} + +# Connect to the server +start_client (); + +# Start SSL +if ($t_ssl == 1) { + start_ssl (); +} + +# Authenticate with server +if ($t_pwd ne '') { + auth_pwd (); +} + +if ($t_recv == 0) { + # Check that all files exist before trying to send them + foreach $file (@ARGV) { + if (! -f $file) { + error ("File '$file' does not exist."); + } + } + + # Send the files + foreach $file (@ARGV) { + send_file ($file); + } +} +else { + # Send the files + foreach $file (@ARGV) { + recv_file ($file); + } +} + +# Tell the server that we are finished +send_data ("QUIT\n"); + +stop_client (); + +exit 0;