diff --git a/pandora_agents/unix/ChangeLog b/pandora_agents/unix/ChangeLog new file mode 100644 index 0000000000..8b527c02a7 --- /dev/null +++ b/pandora_agents/unix/ChangeLog @@ -0,0 +1,11 @@ +2009-11-05 Sancho Lerena + + * pandora_agent_installer: Added a common installer for all systems. + + * Deleted daemon script for all systems, creaded a general one. + + * Modified HPUX to HP-UX directory. + + * Updated some .conf + + diff --git a/pandora_agents/unix/HPUX/pandora_agent.conf b/pandora_agents/unix/HP-UX/pandora_agent.conf similarity index 79% rename from pandora_agents/unix/HPUX/pandora_agent.conf rename to pandora_agents/unix/HP-UX/pandora_agent.conf index 7490874624..33a3eec156 100755 --- a/pandora_agents/unix/HPUX/pandora_agent.conf +++ b/pandora_agents/unix/HP-UX/pandora_agent.conf @@ -88,26 +88,46 @@ transfer_mode tentacle # ================= # System information +# All this commands has been tested on a Standard HP-UX B.11.31 module_begin module_name disk_root_free module_type generic_data -module_exec df -k / | tail -1 | tr -d "%" | awk '{ print 100-$5 }' +module_exec df -k / | tail -1 | tr -d "%" | awk '{ print 100-$1 }' module_max 100 module_min 0 module_description Free disk Percentage of root partition module_end +module_begin +module_name disk_var_free +module_type generic_data +module_exec df -k /var | tail -1 | tr -d "%" | awk '{ print 100-$1 }' +module_max 100 +module_min 0 +module_description Free disk Percentage of /var partition +module_end + +module_begin +module_name disk_usr_free +module_type generic_data +module_exec df -k /usr | tail -1 | tr -d "%" | awk '{ print 100-$1 }' +module_max 100 +module_min 0 +module_description Free disk Percentage of /usr partition +module_end + + module_begin module_name proctotal module_type generic_data -module_exec ps -Alf | wc -l | awk '{ print $1 }' +module_exec ps -ex | wc -l | awk '{ print $1 }' module_end module_begin module_name sshDaemon module_type generic_proc -module_exec ps -Af | grep sshd | grep -v "grep" | wc -l | awk '{ print $1 }' +module_exec ps -ex | grep sshd | grep -v "grep" | wc -l | awk '{ print $1 }' module_end # Async data example @@ -121,46 +141,32 @@ module_end module_begin module_name Swap_Free module_type generic_data -module_exec vmstat 1 2 | tail -1 | awk '{ print $4 }' +module_exec swapinfo | grep memory | tr -d "%" | awk '{ print 100-$5 }' module_description Unused swap memory module_end module_begin module_name RAM_Free module_type generic_data -module_exec vmstat 1 2 | tail -1 | awk '{ print $5 }' +module_exec dmesg | awk '/Physical:/ && /Kbytes/ {print $8}' module_description Unused RAM memory module_end module_begin module_name CPU_User module_type generic_data -module_exec vmstat 1 2 | tail -1 | awk '{ print $20 }' +module_exec vmstat 1 2 | tail -1 | awk '{ print $16 }' module_description % of USER CPU module_end module_begin module_name CPU_System module_type generic_data -module_exec vmstat 1 2 | tail -1 | awk '{ print $21 }' +module_exec vmstat 1 2 | tail -1 | awk '{ print $17 }' module_description % of system CPU module_end -module_begin -module_name Disk_Seek_Operations -module_type generic_data -module_exec vmstat 1 2 | tail -1 | awk '{ print $14 }' -module_description Disk Seek operations -module_end - -module_begin -module_name Pandora_Agent_RAM -module_ẗype generic_data -module_exec ps -Afly | grep perl | grep -v grep | awk '{ print $9 }' -module_description Return size in KB of memory used by process Pandora -module_end - -module_plugin grep_log /var/adm/syslog Syslog . +module_plugin grep_log /var/adm/syslog/syslog.log Syslog . diff --git a/pandora_agents/unix/HPUX/pandora_agent_daemon b/pandora_agents/unix/HPUX/pandora_agent_daemon deleted file mode 100755 index adc04e496f..0000000000 --- a/pandora_agents/unix/HPUX/pandora_agent_daemon +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh - -# Pandora FMS HP-UX Agent, startup script -# Copyright (c) 2006-2009 Artica ST, -# HP-UX Version (generic) -# v3.0.1 Build 091104 -# http://www.pandorafms.com - - -PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin -PANDORA_PATH=/etc/pandora -DAEMON=/usr/bin/pandora_agent -LOGFILE=/var/log/pandora_agent.log - -# This function replace pidof, not working in the same way in different UNIX - -function pidof_pandora { - PANDORA_PID=`ps -Af | grep $DAEMON | grep -v grep | head -1 | awk '{ print $2 }'` - echo $PANDORA_PID -} - -if [ ! -f $DAEMON ] -then - echo "Pandora FMS Agent not found at $DAEMON, please check setup" - exit -fi - -case "$1" in - start) - PANDORA_PID=`pidof_pandora` - 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 & - sleep 1 - PANDORA_PID=`pidof_pandora` - echo "Pandora FMS Agent is now running with PID $PANDORA_PID" - ;; - - stop) - PANDORA_PID=`pidof_pandora` - if [ -z "$PANDORA_PID" ] - then - echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..." - exit 1 - else - echo "Stopping Pandora Agent." - kill $PANDORA_PID > /dev/null 2>&1 - fi - ;; - - status) - PANDORA_PID=`pidof_pandora` - if [ -z "$PANDORA_PID" ] - then - 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 "Usage: /etc/init.d/pandora_agent_daemon {start|stop|restart|status|force-reload}" - exit 1 -esac - diff --git a/pandora_agents/unix/Linux/pandora_agent_daemon b/pandora_agents/unix/Linux/pandora_agent_daemon deleted file mode 100755 index 5cd2595ecc..0000000000 --- a/pandora_agents/unix/Linux/pandora_agent_daemon +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash - -# Pandora FMS Linux Agent, startup script -# Copyright (c) 2006-2009 Artica ST, -# Linux Version (generic), for SuSe and Debian/Ubuntu. -# other Linux distros could not work properly without modifications -# v3.0.1 Build 091104 -# http://www.pandorafms.com - -### BEGIN INIT INFO -# Provides: pandora_agent -# Required-Start: $network -# Required-Stop: $network -# Default-Start: S 2 3 4 5 -# Default-Stop: 0 1 6 -# Short-Description: Startup script daemon for Pandora FMS agent -### END INIT INFO - -PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin -PANDORA_PATH=/etc/pandora -DAEMON=/usr/bin/pandora_agent -LOGFILE=/var/log/pandora_agent.log - -# This function replace pidof, not working in the same way in different Linux distros - -function pidof_pandora () ( - COLUMNS=250 - PANDORA_PID=`ps aux | grep $DAEMON | grep -v grep | head -1 | awk '{ print $2 }'` - echo $PANDORA_PID -) - -if [ ! -f $DAEMON ] -then - echo "Pandora FMS Agent not found at $DAEMON, please check setup" - exit -fi - -case "$1" in - start) - PANDORA_PID=`pidof_pandora` - 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 & - sleep 1 - PANDORA_PID=`pidof_pandora` - echo "Pandora FMS Agent is now running with PID $PANDORA_PID" - ;; - - stop) - PANDORA_PID=`pidof_pandora` - if [ -z "$PANDORA_PID" ] - then - echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..." - exit 1 - else - echo "Stopping Pandora Agent." - kill $PANDORA_PID > /dev/null 2>&1 - fi - ;; - - status) - PANDORA_PID=`pidof_pandora` - if [ -z "$PANDORA_PID" ] - then - 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 "Usage: /etc/init.d/pandora_agent_daemon {start|stop|restart|status|force-reload}" - exit 1 -esac - diff --git a/pandora_agents/unix/SunOS/pandora_agent_daemon b/pandora_agents/unix/SunOS/pandora_agent_daemon deleted file mode 100755 index 18223534eb..0000000000 --- a/pandora_agents/unix/SunOS/pandora_agent_daemon +++ /dev/null @@ -1,75 +0,0 @@ -#!/bin/sh - -# Pandora FMS SunOS Agent, startup script -# Copyright (c) 2006-2009 Artica ST, -# SunOS Version (generic) -# v3.0.1 Build 091104 -# http://www.pandorafms.com - -PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin -PANDORA_PATH=/etc/pandora -DAEMON=/usr/bin/pandora_agent -LOGFILE=/var/log/pandora_agent.log - -# This function replace pidof, not working in the same way in different UNIX - -function pidof_pandora { - PANDORA_PID=`ps -Af | grep $DAEMON | grep -v grep | head -1 | awk '{ print $2 }'` - echo $PANDORA_PID -} - -if [ ! -f $DAEMON ] -then - echo "Pandora FMS Agent not found at $DAEMON, please check setup" - exit -fi - -case "$1" in - start) - PANDORA_PID=`pidof_pandora` - 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 & - sleep 1 - PANDORA_PID=`pidof_pandora` - echo "Pandora FMS Agent is now running with PID $PANDORA_PID" - ;; - - stop) - PANDORA_PID=`pidof_pandora` - if [ -z "$PANDORA_PID" ] - then - echo "Pandora FMS Agent is not running, cannot stop it. Aborting now..." - exit 1 - else - echo "Stopping Pandora Agent." - kill $PANDORA_PID > /dev/null 2>&1 - fi - ;; - - status) - PANDORA_PID=`pidof_pandora` - if [ -z "$PANDORA_PID" ] - then - 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 "Usage: /etc/init.d/pandora_agent_daemon {start|stop|restart|status|force-reload}" - exit 1 -esac - diff --git a/pandora_agents/unix/pandora_agent b/pandora_agents/unix/pandora_agent index dd72cd28d3..9c9e65ed65 100755 --- a/pandora_agents/unix/pandora_agent +++ b/pandora_agents/unix/pandora_agent @@ -15,7 +15,7 @@ use File::Basename; use File::Copy; use constant AGENT_VERSION => '3.0'; -use constant AGENT_BUILD => '090831'; +use constant AGENT_BUILD => '091103'; # OS and OS version my $OS = $^O; diff --git a/pandora_agents/unix/AIX/pandora_agent_daemon b/pandora_agents/unix/pandora_agent_daemon similarity index 60% rename from pandora_agents/unix/AIX/pandora_agent_daemon rename to pandora_agents/unix/pandora_agent_daemon index 03c8002205..eb71a47dae 100755 --- a/pandora_agents/unix/AIX/pandora_agent_daemon +++ b/pandora_agents/unix/pandora_agent_daemon @@ -1,21 +1,32 @@ #!/bin/sh -# Pandora FMS AIX Agent, startup script -# Copyright (c) 2006-2009 Artica ST, -# AIX 5.x Version (generic), -# v3.0.1 Build 091104 -# http://www.pandorafms.com - +# ********************************************************************** +# Pandora FMS Agent Daemon launcher for Unix (AIX, HP-UX, SunOS, Linux) +# (c) 2008-2009 Artica ST +# (c) 2008-2009 Sancho Lerena +# +# Please see http://www.pandorafms.org +# v3.0 Build 091103 +# This code is licensed under GPL 2.0 license. +# ********************************************************************** PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin PANDORA_PATH=/etc/pandora DAEMON=/usr/bin/pandora_agent LOGFILE=/var/log/pandora_agent.log -# This function replace pidof, not working in the same way in different UNIX +# This function replace pidof, not working in the same way in different linux distros -function pidof_pandora { - PANDORA_PID=`ps -Alf | grep $DAEMON | grep -v grep | head -1 | awk '{ print $4 }'` +pidof_pandora () { + COLUMNS=300 + OS_NAME=`uname -s` + if [ $OS_NAME = "HP-UX" ] + then + PANDORA_PID=`ps -ex | grep "$DAEMON $PANDORA_PATH" | grep -v grep | head -1 | awk '{ print $1 }'` + else + PANDORA_PID=`ps -Af | grep "$DAEMON $PANDORA_PATH" | grep -v grep | head -1 | awk '{ print $2 }'` + fi + echo $PANDORA_PID } @@ -35,7 +46,8 @@ case "$1" in exit 1 fi nohup $DAEMON $PANDORA_PATH 2> $LOGFILE & - sleep 1 + rm nohup.out 2> /dev/null + sleep 2 PANDORA_PID=`pidof_pandora` echo "Pandora FMS Agent is now running with PID $PANDORA_PID" ;; @@ -70,7 +82,7 @@ case "$1" in ;; *) - echo "Usage: /etc/rc.pandora_agent_daemon {start|stop|restart|status|force-reload}" + echo "Uso: /etc/init.d/pandora_agent_daemon {start|stop|restart|status}" exit 1 esac diff --git a/pandora_agents/unix/pandora_agent_installer b/pandora_agents/unix/pandora_agent_installer index 1228477b06..e62b02f868 100755 --- a/pandora_agents/unix/pandora_agent_installer +++ b/pandora_agents/unix/pandora_agent_installer @@ -1,179 +1,274 @@ -#!/bin/bash +#!/bin/sh -# 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 +# ********************************************************************** +# Pandora FMS Agent Installer for Unix (generic installer) +# (c) 2008-2009 Artica ST +# (c) 2008-2009 Sancho Lerena +# +# This is a generic installer for all Unix-like systems.(AIX, HP-UX, SunOS, Linux) # Please see http://www.pandorafms.org -# v3.0 Build 090810 +# v3.0 Build 091103 # This code is licensed under GPL 2.0 license. # ********************************************************************** -PI_VERSION=3.0 -PANDORA_BIN=/usr/bin/pandora_agent +PI_VERSION=3.0.0 +PI_BUILD=091105 +OS_NAME=`uname -s` + PANDORA_HOME=/usr/share/pandora_agent +PANDORA_BIN=/usr/bin/pandora_agent PANDORA_TEMP=/var/spool/pandora PANDORA_CFG=/etc/pandora -PANDORA_LOG=/var/log/pandora/pandora_agent.log -PANDORA_STARTUP=/etc/init.d/pandora_agent_daemon +PANDORA_LOG_DIR=/var/log/pandora +PANDORA_LOG=pandora_agent.log TENTACLE=/usr/bin/tentacle_client -PANDORA_CFG_FILE=/etc/pandora/pandora_agent.conf - FORCE=0 +USE_LINKS=0 + LOG_TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"` MODE=$1 +if [ ! -z "$2" ] +then + PANDORA_HOME=$2 +fi + +# Check for Perl 5.8.x available +PERL_VERSION=`perl -v | egrep 'v5.8|v5.9|v5.1[0-9]' | grep perl` + +if [ -z "$PERL_VERSION" ] +then + echo "Perl 5.8.x is not detected. This is required for Pandora FMS" + echo "Detected: $PERL_VERSION " + echo "Aborting install..." + exit 2 +fi + +UNIX_KIND=`uname -s` +if [ -z "`echo Linux HP-UX SunOS AIX Solaris | grep \"$UNIX_KIND\"`" ] +then + echo "This system: '$UNIX_KIND' is not supported by this script" + echo "Please make the install yourself as it's described in documentation" + exit 1 +fi + + +# check for root to do the install +if [ -z "`id | grep \"uid=0(root)\"`" ] +then + 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 " " + echo "Aborting install" + exit 2 +fi + if [ ! -f "pandora_agent" ] then echo " " - echo "You need to place pandora_agent file on main distribution directory before install" + echo "Execute installer from the directory where you have your files. For example:" + echo " " + echo " cd /tmp/pandora_install " + echo " ./pandora_agent_installer --install" + echo " ./pandora_agent_installer --install-with-links /var/opt/PandoraFMS" echo " " exit 1 fi -uninstall { - echo "Removing Pandora FMS Agent..." - rm -Rf $PANDORA_BIN - rm -Rf $PANDORA_TEMP - rm -Rf $PANDORA_CFG_FILE - rm -Rf $PANDORA_STARTUP - rm -Rf $PANDORA_HOME - rm -Rf $PANDORA_LOG - rm -Rf $TENTACLE - echo "Done" +uninstall () { + echo "Removing Pandora FMS Agent..." + rm -Rf $PANDORA_BIN + rm -Rf $PANDORA_TEMP + rm -Rf $PANDORA_CFG/pandora_agent.conf + + rm -Rf /etc/init.d/pandora_agent_daemon 2> /dev/null + rm -Rf /sbin/init.d/pandora_agent_daemon 2> /dev/null + rm -Rf /etc/rc.pandora_agent_daemon 2> /dev/null + rm -Rf /etc/rc?.d/S90pandora_agent_daemon 2> /dev/null + rm -Rf /sbin/rc?.d/S90pandora_agent_daemon 2> /dev/null + + rm -Rf $PANDORA_HOME + rm -Rf $PANDORA_LOG_DIR + rm -Rf $TENTACLE + + # Skip delete of /etc/pandora if exists configuration of a server + if [ ! -f /etc/pandora/pandora_server.conf ] + then + rm -Rf /etc/pandora + fi + + echo "If you install Pandora FMS agent in a custom directory, you should" + echo " delete it yourself with command rm -Rf , for example:" + echo " " + echo " rm -Rf /opt/software/pandora" + echo " " + echo "Done" } install () { - OS_VERSION=`uname -r` - OS_NAME=`uname -s` - - OLDFILENAMETMP=`date +"%Y-%m-%d"` - - echo "Detecting Unix distribution: $OS_NAME version $OS_VERSION" - - if [ -f $PANDORA_HOME ] && [ "$FORCE" = "0" ] - then - echo "Seems that default dir already exists. Please use --force to" - echo "force installer to install on $PANDORA_HOME" - exit - else - echo "Checking default dir $PANDORA_HOME..." - fi + OS_VERSION=`uname -r` + OS_NAME=`uname -s` + OLDFILENAMETMP=`date +"%Y-%m-%d"` + echo "Detecting Unix distribution: $OS_NAME version $OS_VERSION" + if [ -f $PANDORA_HOME ] && [ "$FORCE" = "0" ] + then + echo "Seems that default dir already exists. Please use --force to" + echo "force installer to install on $PANDORA_HOME" + exit + 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 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 - echo "Seems to be a problem generating logfile ($PANDORA_LOG) please check it"; - else - echo "Creating logfile at $PANDORA_LOG..." - fi - - echo "$LOG_TIMESTAMP Pandora FMS installer has created this file at startup" > $PANDORA_LOG - - # Copying agent and securing it - echo "Copying Pandora FMS Agent to $PANDORA_BIN..." - cp pandora_agent $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 [ -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 $OS_NAME/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 - - echo "Copying tentacle client to $TENTACLE" - cp tentacle_client $TENTACLE - - echo "Linking Pandora FMS Agent plugins directory to $PANDORA_CFG/plugins..." - 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..." - 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 640 $PANDORA_LOG - chgrp root $PANDORA_LOG - - echo "Linking start-up daemon script at $PANDORA_STARTUP"; - - if [ "$OS_NAME" == "AIX" ] - then - cp $OS_NAME/pandora_agent_daemon /etc/rc.pandora_agent_daemon - else - cp $OS_NAME/pandora_agent_daemon $PANDORA_STARTUP - fi - - if [ "$OS_NAME" == "AIX" ] - then - echo "Linking start-up daemon script to /etc/rc2.d"; - ln -s /etc/rc.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 " " - echo "You have your startup script ready at $PANDORA_STARTUP" + if [ -f $PANDORA_BIN ] && [ "$FORCE" = "0" ] + then + echo "Seems that $PANDORA_BIN already exists. Please use --force to" + echo "force installer to reinstall overwriting it" 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 " " - echo "Take a look of your - echo " " + exit + else + echo "Checking Pandora FMS Agent on $PANDORA_BIN...." + fi + + echo "Creating Pandora FMS Agent home directory at $PANDORA_HOME ..." + mkdir -p $PANDORA_HOME 2> /dev/null + + # IF USE_LINKS = 1 then append HOME to other paths + if [ "$USE_LINKS" = 1 ] + then + mkdir -p $PANDORA_HOME/$PANDORA_TEMP/data_out 2> /dev/null + mkdir -p $PANDORA_LOG_DIR 2> /dev/null + + ln -s $PANDORA_HOME /etc/pandora + ln -s $PANDORA_HOME/$PANDORA_TEMP /var/spool/pandora + else + # Create directories on / + mkdir -p $PANDORA_TEMP/data_out 2> /dev/null + mkdir -p $PANDORA_CFG 2> /dev/null + mkdir -p $PANDORA_LOG_DIR 2> /dev/null + fi + + # Create logfile + if [ ! -z "`touch $PANDORA_LOG_DIR/$PANDORA_LOG`" ] + then + echo "Seems to be a problem generating logfile ($PANDORA_LOG_DIR/$PANDORA_LOG) please check it"; + else + echo "Created logfile at $PANDORA_LOG_DIR/$PANDORA_LOG..." + fi + + echo "$LOG_TIMESTAMP Pandora FMS installer has created this file at startup" > $PANDORA_LOG_DIR/$PANDORA_LOG + + # Copying agent and securing it + echo "Copying Pandora FMS Agent to $PANDORA_BIN..." + cp pandora_agent $PANDORA_BIN + chmod 755 $PANDORA_BIN + chown root:root $PANDORA_BIN + + echo "Copying Pandora FMS Agent configuration file to $PANDORA_HOME/pandora_agent.conf..." + if [ -f /etc/pandora/pandora_agent.conf ] + then + cat /etc/pandora/pandora_agent.conf > /etc/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 $OS_NAME/pandora_agent.conf $PANDORA_HOME/pandora_agent.conf + chmod 600 $PANDORA_HOME/pandora_agent.conf + chown root $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 + + echo "Copying tentacle client to $TENTACLE" + cp tentacle_client $TENTACLE + chmod 755 $TENTACLE + + if [ "$USE_LINKS" != 1 ] + then + echo "Linking Pandora FMS Agent plugins directory to $PANDORA_CFG/plugins..." + rm $PANDORA_CFG/plugins 2> /dev/null + ln -s $PANDORA_HOME/plugins $PANDORA_CFG/plugins 2> /dev/null + + echo "Linking Pandora FMS Agent configuration to $PANDORA_CFG/pandora_agent.conf..." + rm $PANDORA_CFG/pandora_agent.conf 2> /dev/null + ln -s $PANDORA_HOME/pandora_agent.conf $PANDORA_CFG/pandora_agent.conf + fi + + echo "Setting secure permissions and ownership for all Pandora FMS Agent files..." + chown -R root $PANDORA_HOME + chmod -R 600 $PANDORA_TEMP + chown root $PANDORA_TEMP + chmod 640 $PANDORA_LOG_DIR/$PANDORA_LOG + chown root:root $PANDORA_LOG_DIR/$PANDORA_LOG + + echo "Linking start-up daemon script 'pandora_agent_daemon' on $OS_NAME"; + + if [ "$OS_NAME" = "AIX" ] + then + cp pandora_agent_daemon /etc/rc.pandora_agent_daemon + ln -s /etc/rc.pandora_agent_daemon /etc/rc.d/rc2.d/S90pandora_agent_daemon + echo "Pandora FMS agent has been included in /etc/rc.d/rc2.d/S90pandora_agent_daemon" + fi + + if [ $OS_NAME = "HP-UX" ] + then + cp pandora_agent_daemon /sbin/init.d/pandora_agent_daemon + ln -s /sbin/init.d/pandora_agent_daemon /sbin/rc3.d/S90pandora_agent_daemon + ln -s /sbin/init.d/pandora_agent_daemon /sbin/rc2.d/S90pandora_agent_daemon + echo "Pandora FMS agent has been included in /sbin/rcX.d/S90pandora_agent_daemon" + fi + + if [ $OS_NAME = "SunOS" ] + then + cp pandora_agent_daemon /etc/init.d/pandora_agent_daemon + ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent_daemon + echo "Pandora FMS agent has been included in /etc/rc2.d/S90pandora_agent_daemon" + fi + + if [ $OS_NAME = "Linux" ] + then + cp pandora_agent_daemon /etc/init.d/pandora_agent_daemon + if [ -d /etc/rc.d/ ] + then + ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc2.d/S90pandora_agent + ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc3.d/S90pandora_agent + else + ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent + ln -s /etc/init.d/pandora_agent_daemon /etc/rc2.d/S90pandora_agent + fi + fi + + echo "Done." + echo " " + echo "You have your startup script ready at $PANDORA_STARTUP" + 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 " + echo " ($HOME/.ssh/id_dsa) under /home/pandora/.ssh/authorized_keys " + echo "on your Pandora FMS Server host" + echo " " + echo "You also need to setup your $PANDORA_CFG/pandora_agent.conf config file" + echo " " + echo "Check your startup configuration to be sure Pandora FMS Agent is ready " + echo "to start automatically when system restarts": } help () { - echo " --force-install To force installation if already installed on system " - echo " --install To install Pandora FMS Agent on this system" - echo " --uninstall To uninstall and remove Pandora FMS Agent on this System" - echo " " + echo " --force-install To force installation if already installed on system" + echo " --install To install Pandora FMS Agent on this system" + echo " --uninstall To uninstall/remove Pandora FMS Agent on this System" + echo " --install-with-links " + echo " To install Pandora FMS in a defined dir " + echo " and set all Pandora FMS directories as links to this" + echo " " } # Script banner at start echo " " -echo "Pandora FMS Agent Installer $PI_VERSION (c) 2008-2009 ArticaST" +echo "Pandora FMS Agent UNIX Installer $PI_VERSION $PI_BUILD (c) 2008-2009 ArticaST" echo "This program is licensed under GPL2 Terms. http://pandorafms.com" echo " " @@ -190,6 +285,12 @@ case "$MODE" in exit ;; +'--install-with-links') + USE_LINKS=1 + install + exit + ;; + '--uninstall') uninstall exit @@ -197,5 +298,6 @@ case "$MODE" in *) help + ;; esac diff --git a/pandora_agents/unix/plugins/grep_log b/pandora_agents/unix/plugins/grep_log new file mode 100755 index 0000000000..2e46fbbdac --- /dev/null +++ b/pandora_agents/unix/plugins/grep_log @@ -0,0 +1,241 @@ +#!/usr/bin/perl +############################################################################### +# +# Copyright (c) 2008 Ramon Novoa +# Copyright (c) 2008 Artica Soluciones Tecnologicas S.L. +# +# grep_log Perl script to search log files for a matching pattern. The last +# searched position is saved in an index file so that consecutive +# runs do not return the same results. The log file inode number is +# also saved to detect log rotation. +# +# 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. +# +############################################################################### + +use strict; +use File::Basename; + +# Be verbose +my $Verbose = 0; + +# Index file storage directory, with a trailing '/' +my $Idx_dir='/tmp/'; + +# Log file +my $Log_file = ''; + +# Module name +my $Module_name = "default_log"; + +# Index file +my $Idx_file = ''; + +# Log file position index +my $Idx_pos = 0; + +# Log file inode number +my $Idx_ino = ''; + +# Regular expression to be matched +my $Reg_exp = ''; + +############################################################################### +# SUB error_msg +# Print an error message and exit. +############################################################################### +sub error_msg ($) { + my $err_msg = $_[0]; + + if (! -z $err_msg) { + print(stderr "[error] $err_msg.\n"); + } + + exit 1; +} + +############################################################################### +# SUB print_help +# Print a help message. +############################################################################### +sub print_help () { + print "Usage: $0 \n"; +} + +############################################################################### +# SUB log_msg +# Print a log message. +############################################################################### +sub log_msg ($) { + my $log_msg = $_[0]; + + if (! -z $log_msg && $Verbose == 1) { + print(stdout "[log] $log_msg.\n"); + } +} + +############################################################################### +# SUB load_idx +# Load index file. +############################################################################### +sub load_idx () { + my $line; + my $current_ino; + + log_msg("Loading index file $Idx_file"); + + open(IDXFILE, $Idx_file) || error_msg("Error opening file $Idx_file: " . + $!); + + # Read position and date + $line = ; + ($Idx_pos, $Idx_ino) = split(' ', $line); + + close(IDXFILE); + + # Reset the file index if the file has changed + $current_ino = (stat($Log_file))[1]; + if ($current_ino != $Idx_ino) { + log_msg("File changed, resetting index"); + + $Idx_pos = 0; + $Idx_ino = $current_ino; + } + + return; +} + +############################################################################### +# SUB save_idx +# Save index file. +############################################################################### +sub save_idx () { + + log_msg("Saving index file $Idx_file"); + + open(IDXFILE, "> $Idx_file") || error_msg("Error opening file $Idx_file: " + . $!); + print (IDXFILE $Idx_pos . " " . $Idx_ino); + close(IDXFILE); + + return; +} + +############################################################################### +# SUB create_idx +# Create index file. +############################################################################### +sub create_idx () { + my $first_line; + + log_msg("Creating index file $Idx_file"); + + open(LOGFILE, $Log_file) || error_msg("Error opening file $Log_file: " . + $!); + + # Go to EOF and save the position + seek(LOGFILE, 0, 2); + $Idx_pos = tell(LOGFILE); + + close(LOGFILE); + + # Save the file inode number + $Idx_ino = (stat($Log_file))[1]; + + # Save the index file + save_idx(); + + return; +} + +############################################################################### +# SUB parse_log +# Parse log file starting from position $Idx_pos. +############################################################################### +sub parse_log () { + my $line; + + log_msg("Parsing log file $Log_file"); + + # Open log file for reading + open(LOGFILE, $Log_file) || error_msg("Error opening file $Log_file: " . + $!); + + # Go to starting position + seek(LOGFILE, $Idx_pos, 0); + + print (stdout "\n"); + print (stdout "\n"); + print (stdout "\n"); + print (stdout "\n"); + + # Parse log file + while ($line = ) { + if ($line =~ m/$Reg_exp/i) { + # Remove the trailing '\n' + chop($line); + + print (stdout "\n"); + } + } + + print (stdout "\n"); + print (stdout "\n"); + + $Idx_pos = tell(LOGFILE); + close(LOGFILE); + + # Save the index file + save_idx(); + + return; +} + +############################################################################### +############################################################################### +## Main +############################################################################### +############################################################################### + +# Check command line parameters +if ($#ARGV != 2) { + print_help(); + exit 1; +} + +$Log_file = $ARGV[0]; +$Module_name = $ARGV[1]; +$Reg_exp = $ARGV[2]; + +# Create index file storage directory +if ( ! -d $Idx_dir) { + mkdir($Idx_dir) || error_msg("Error creating directory $Idx_dir: " + . $!); +} + +# Check that log file exists +if (! -e $Log_file) { + error_msg("File $Log_file does not exist"); +} + +# Create index file if it does not exist +$Idx_file=$Idx_dir . $Module_name . "_" . basename($Log_file) . ".idx"; +if (! -e $Idx_file) { + create_idx(); + exit 0; +} + +# Load index file +load_idx(); + +# Parse log file +parse_log(); + +exit 0; diff --git a/pandora_agents/unix/plugins/inventory b/pandora_agents/unix/plugins/inventory new file mode 100755 index 0000000000..56d64e26b8 --- /dev/null +++ b/pandora_agents/unix/plugins/inventory @@ -0,0 +1,282 @@ +#!/usr/bin/perl +############################################################################### +# +# Copyright (c) 2009 Artica Soluciones Tecnologicas S.L. +# +# inventory Generate a hardware/software inventory. +# +# Sample usage: ./inventory [cpu] [ram] [video] [nic] [hd] [cdrom] [software] [init_services] [filesystem] [process] [users] +# +# 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. +# +############################################################################### + +use strict; +use constant TSTAMP_FILE => '/tmp/pandora_inventory.tstamp'; + +# Parse module information +sub get_module_data ($$$$) { + my ($name, $hwinfo, $keys, $modules) = @_; + my %module; + + # Parse module data + while (my $line = shift (@{$hwinfo})) { + if ($line =~ /\s+\*\-/) { + unshift (@{$hwinfo}, $line); + last; + } + foreach my $key (@{$keys}) { + if ($line =~ /$key:\s+(.+)/) { + $module{$key} = $1; + push (@{$module{'_keys'}}, $key); + } + } + } + + # No data found + my @data = keys (%module); + return unless ($#data >= 0); + + push (@{$modules->{$name}}, \%module); +} + +# Get a list of information file system in machine +sub get_file_system($$) { + my ($name, $modules) = @_; + + my @fileSystems = `df -h | tail -n +2`; #remove the titles of columns + + foreach my $row (@fileSystems) { + next unless ($row =~ /^(\S+)\s+\S+\s+(\S+)\s+(\S+)\s+\S+\s+(\S+)/); + + my %module; + $module{'filesystem'} = $1; + $module{'used'} = $2; + $module{'avail'} = $3; + $module{'mount'} = $4; + $module{'_keys'} = ['filesystem', 'used','avail', 'mount']; + push (@{$modules->{$name}}, \%module); + } +} + +# Get a list of services init in machine +sub get_servicies_init_machine($$) { + my ($name, $modules) = @_; + my $runlevel = `runlevel | cut -d' ' -f2`; + + #ini trim($runlevel) + $runlevel =~ s/^\s*//; #ltrim + $runlevel =~ s/\s*$//; #rtrim + #end trim($runlevel) + + my $script = "ls /etc/rc" . $runlevel .".d/ -l | grep \"^l.*\" | grep \" S.* \" | cut -d' ' -f11"; + + my @services = `$script`; + foreach my $row (@services) { + next unless ($row =~ /^\S+\/(\S+)$/); + + my %module; + $module{'service'} = $1; + $module{'_keys'} = ['service']; + push (@{$modules->{$name}}, \%module); + } +} + +# Get a list of running processes +sub get_processes ($$) { + my ($name, $modules) = @_; + + my $script = "ps aux"; + + my @services = `$script`; + foreach my $row (@services) { + my %module; + # Remove carriage returns + $row =~ s/[\n\l\f]//g; + $module{'service'} = $row; + $module{'_keys'} = ['service']; + push (@{$modules->{$name}}, \%module); + } +} + +# Get a list of valid users in the system +sub get_users ($$) { + my ($name, $modules) = @_; + + my $script = "cat /etc/passwd"; + my $user = ""; + my $estado = ""; + + my @services = `$script`; + foreach my $row (@services) { + my %module; + + next unless ($row =~ /^([A-Za-z0-9\-\_]*)/); + + $user = $1; + $script = `passwd -S $user`; + if ( $script =~ /^(\S+)\sP./){ + $module{'user'} = $user; + $module{'_keys'} = ['user']; + push (@{$modules->{$name}}, \%module); + } + } +} + +# Get a list of installed programs +sub get_software_module_data ($$) { + my ($name, $modules) = @_; + + # Guess the current distribution + open (RELEASE_FILE, '< /etc/lsb-release') or return; + my $distrib_id = ; + last unless ($distrib_id =~ m/DISTRIB_ID\s*=\s*(\S+)/); + $distrib_id = $1; + + # List installed programs + my @soft; + if ($distrib_id eq 'Ubuntu') { + @soft = `dpkg -l | grep ii`; + } else { + return; + } + + # Parse data + foreach my $row (@soft) { + next unless ($row =~ /^ii\s+(\S+)\s+(\S+)\s+([^\n]+)/); + + my %module; + $module{'program'} = $1; + $module{'version'} = $2; + $module{'description'} = $3; + $module{'_keys'} = ['program', 'version','description']; + + push (@{$modules->{$name}}, \%module); + } +} + +# Print module data +sub print_module ($$) { + my ($name, $module) = @_; + + print " \n"; + print " \n"; + print " \n"; + foreach my $item (@{$module}) { + # Compose module data + my $data = ''; + foreach my $key (@{$item->{'_keys'}}) { + next unless defined ($item->{$key}); + $data .= ($data eq '' ? '' : ';') . $item->{$key}; + } + + print " \n"; + } + print " \n"; + print " \n"; +} + +# Check command line parameters +if ($#ARGV < 0) { + print "Usage: $0 [cpu] [ram] [video] [nic] [hd] [cdrom] [software] [init_services] [filesystem] [users] [process] \n\n"; + exit 1; +} + +# Parse command line parameters +my %enabled; +my $enable_all = ($#ARGV > 0 ? 0 : 1); +my $interval = shift (@ARGV); +foreach my $module (@ARGV) { + $enabled{$module} = 1; +} + +# Check execution interval +if (-f TSTAMP_FILE) { + open (FILE, '<' . TSTAMP_FILE) || exit 1; + my $last_execution = ; + close (FILE); + exit 0 if ($last_execution + 86400 * $interval > time ()); +} +open (FILE, '>' . TSTAMP_FILE) || exit 1; +print FILE time (); +close (FILE); + +# Retrieve hardware information +my @hwinfo = `lshw 2>/dev/null`; + +# Parse hardware information +my %modules; +while (my $line = shift (@hwinfo)) { + chomp ($line); + + # CPU + if ($line =~ /\*\-cpu/ && ($enable_all == 1 || $enabled{'cpu'} == 1)) { + get_module_data ('CPU', \@hwinfo, ['product', 'vendor', 'capacity'], \%modules); + } + + # RAM + if ($line =~ /\*\-bank/ && ($enable_all == 1 || $enabled{'ram'} == 1)) { + get_module_data ('RAM', \@hwinfo, ['description', 'size'], \%modules); + } + + # VIDEO + if ($line =~ /\*\-display/ && ($enable_all == 1 || $enabled{'video'} == 1)) { + get_module_data ('VIDEO', \@hwinfo, ['product', 'description', 'vendor'], \%modules); + } + + # NIC + if ($line =~ /\*\-network/ && ($enable_all == 1 || $enabled{'nic'} == 1)) { + get_module_data ('NIC', \@hwinfo, ['product', 'description', 'vendor'], \%modules); + } + + # CDROM + if ($line =~ /\*\-cdrom/ && ($enable_all == 1 || $enabled{'cdrom'} == 1)) { + get_module_data ('CDROM', \@hwinfo, ['product', 'description', 'vendor'], \%modules); + } + + # HD + if ($line =~ /\*\-disk/ && ($enable_all == 1 || $enabled{'hd'} == 1)) { + get_module_data ('HD', \@hwinfo, ['product', 'description', 'size'], \%modules); + } +} + +# Software +if ($enable_all == 1 || $enabled{'software'} == 1) { + get_software_module_data ('Software', \%modules); +} + +#init_services +if ($enable_all == 1 || $enabled{'init_services'} == 1) { + get_servicies_init_machine ('Init services', \%modules); +} + +#filesystem +if ($enable_all == 1 || $enabled{'filesystem'} == 1) { + get_file_system('File system', \%modules); +} + +#processes +if ($enable_all == 1 || $enabled{'process'} == 1) { + get_processes('Process', \%modules); +} + +#users +if ($enable_all == 1 || $enabled{'users'} == 1){ + get_users ('Users', \%modules); +} + +# Print module data +print "\n"; +while (my ($name, $module) = each (%modules)) { + print_module ($name, $module); +} +print "\n"; + +exit 0; diff --git a/pandora_agents/unix/plugins/pandora_df b/pandora_agents/unix/plugins/pandora_df new file mode 100755 index 0000000000..e54069685d --- /dev/null +++ b/pandora_agents/unix/plugins/pandora_df @@ -0,0 +1,71 @@ +#!/usr/bin/perl +############################################################################### +# +# Copyright (c) 2009 Ramon Novoa +# Copyright (c) 2009 Artica Soluciones Tecnologicas S.L. +# +# pandora_df Retrieve filesystem disk usage. By default information for all +# filesystems is returned, but one or more filesystems may be +# specified as command line parameters. +# +# Sample usage: ./pandora_df tmpfs /dev/sda1 +# +# 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. +# +############################################################################### + +use strict; + +# Retrieve information from all filesystems +my $all_filesystems = 0; + +# Check command line parameters +if ($#ARGV < 0) { + $all_filesystems = 1; +} + +# Parse command line parameters +my %filesystems; +foreach my $fs (@ARGV) { + $filesystems{$fs} = '-1%'; +} + +# Retrieve filesystem information +# -P use the POSIX output format for portability +my @df = `df -P`; +shift (@df); + +# No filesystems? Something went wrong. +if ($#df < 0) { + exit 1; +} + +# Parse filesystem usage +foreach my $row (@df) { + my @columns = split (' ', $row); + exit 1 if ($#columns < 4); + $filesystems{$columns[0]} = $columns[4] if (defined ($filesystems{$columns[0]}) || $all_filesystems == 1); +} + +while (my ($filesystem, $use) = each (%filesystems)) { + + # Remove the trailing % + chop ($use); + + # Print module output + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print "% of usage in this volume\n"; + print "\n"; +} + +exit 0; diff --git a/pandora_agents/unix/tentacle_client b/pandora_agents/unix/tentacle_client index 2e3e27c7cf..3c38d19a85 100755 --- a/pandora_agents/unix/tentacle_client +++ b/pandora_agents/unix/tentacle_client @@ -1,7 +1,5 @@ #!/usr/bin/perl -eval 'exec /usr/bin/perl -S $0 ${1+"$@"}' - if 0; # not running under some shell ################################################################################ # # Copyright (c) 2007-2008 Ramon Novoa