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

* linux/pandora_agent.spec: Fixed some permissions.

	* pandora_agent.conf, pandora_agent: Support for description and group
	passed to the server. Also implemented AUTOTIME, where timestamp used
	is the server localtime instead agent datetime. Also placed new token for
	module_postprocess data to be passed to server.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1863 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2009-08-19 02:28:44 +00:00
parent e131606862
commit 5971f0ac67
4 changed files with 123 additions and 37 deletions

View File

@ -1,3 +1,12 @@
2009-08-18 Sancho Lerena <slerena@artica.es>
* linux/pandora_agent.spec: Fixed some permissions.
* pandora_agent.conf, pandora_agent: Support for description and group
passed to the server. Also implemented AUTOTIME, where timestamp used
is the server localtime instead agent datetime. Also placed new token for
module_postprocess data to be passed to server.
2009-08-14 Sancho Lerena <slerena@artica.es> 2009-08-14 Sancho Lerena <slerena@artica.es>
* linux/pandora_agent_installer: Fixed problems with .conf backup * linux/pandora_agent_installer: Fixed problems with .conf backup

View File

@ -1,13 +1,13 @@
#!/bin/bash #!/bin/bash
# ********************************************************************** # **********************************************************************
# Pandora FMS Generic Linux Agent # Pandora FMS Generic Linux Agent
# (c) 2009 Artica Soluciones Tecnológicas SL # (c) 2009 Artica Soluciones Tecnológicas
# with the help of many people. Please see http://pandorafms.org # with the help of many people. Please see http://pandorafms.org
# This code is licensed under GPL 2.0 license. # This code is licensed under GPL 2.0 license.
# ********************************************************************** # **********************************************************************
AGENT_VERSION=3.0 AGENT_VERSION=3.0
AGENT_BUILD=090608 AGENT_BUILD=090818
# ********************************************************************** # **********************************************************************
# function configure_agent() # function configure_agent()
@ -153,14 +153,27 @@ function configure_agent {
SECONDARY_TENTACLE_OPTS="$SECONDARY_SERVER_OPTS $SECONDARY_TENTACLE_OPTS" SECONDARY_TENTACLE_OPTS="$SECONDARY_SERVER_OPTS $SECONDARY_TENTACLE_OPTS"
echo "$TIMESTAMP - [SETUP] - Extra options for the secondary Tentacle client $SECONDARY_SERVER_OPTS" >> $PANDORA_LOGFILE echo "$TIMESTAMP - [SETUP] - Extra options for the secondary Tentacle client $SECONDARY_SERVER_OPTS" >> $PANDORA_LOGFILE
fi 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 fi
done done
if [ "$CRON_MODE" == "0" ] if [ "$CRON_MODE" == "0" ]
then then
# Script banner at start # Script banner at start
echo "Pandora FMS Agent $AGENT_VERSION (c) Sancho Lerena 2003-2008" echo "Pandora FMS Agent $AGENT_VERSION (c) Artica ST 2003-2009"
echo "This program is licensed under GPL2 Terms. http://pandora.sf.net" echo "This program is licensed under GPL2 Terms. http://pandorafms.org"
echo "Running in $NOMBRE_HOST at $TIMESTAMP" echo "Running in $NOMBRE_HOST at $TIMESTAMP"
echo " " echo " "
else else
@ -498,6 +511,11 @@ do
# Date and time, SERIAL is number of seconds since 1/1/1970, for every packet. # Date and time, SERIAL is number of seconds since 1/1/1970, for every packet.
TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"` TIMESTAMP=`date +"%Y/%m/%d %H:%M:%S"`
SERIAL=`date +"%s"` SERIAL=`date +"%s"`
if [ "$AGENT_AUTOTIME" == "1" ]
then
TIMESTAMP="AUTO"
fi
# File names # File names
DATA=$TEMP/$NOMBRE_HOST.$SERIAL.data DATA=$TEMP/$NOMBRE_HOST.$SERIAL.data
@ -505,7 +523,7 @@ do
# Makes data packet # Makes data packet
echo "<?xml version=\"1.0\" encoding=\"$ENCODING\"?> " > $DATA echo "<?xml version=\"1.0\" encoding=\"$ENCODING\"?> " > $DATA
echo "<agent_data os_name='$OS_NAME' os_version='$OS_VERSION' interval='$INTERVAL' version='$AGENT_VERSION' timestamp='$TIMESTAMP' agent_name='$NOMBRE_HOST'>" >> $DATA echo "<agent_data description='$AGENT_DESCRIPTION' group='$AGENT_GROUP' os_name='$OS_NAME' os_version='$OS_VERSION' interval='$INTERVAL' version='$AGENT_VERSION' timestamp='$TIMESTAMP' agent_name='$NOMBRE_HOST'>" >> $DATA
for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v -e "^#" | grep -e "^module" ` for a in `cat $PANDORA_HOME/pandora_agent.conf | grep -v -e "^#" | grep -e "^module" `
do do
@ -596,6 +614,13 @@ do
fi fi
fi fi
# Module postprocess info
if [ ! -z "`echo $a | grep -e '^module_postprocess'`" ]
then
pprocess=`echo $a | cut -d" " -f2-`
echo "<postprocess><![CDATA[$pprocess]]></postprocess>" >> $DATA2
fi
# If module ends, and execute for this module is enabled # If module ends, and execute for this module is enabled
# then write # then write

View File

@ -22,6 +22,17 @@ debug 0
# By default, agent takes machine name # By default, agent takes machine name
#agent_name adama #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. # By default agent try to take default encoding defined in host.
# encoding iso-8859-15 # encoding iso-8859-15
@ -112,10 +123,12 @@ module_type generic_data
module_exec cat /proc/meminfo | grep MemFree | awk '{ print $2 }' module_exec cat /proc/meminfo | grep MemFree | awk '{ print $2 }'
module_end module_end
# This module uses postprocess feature to pass postprocess value to module
module_begin module_begin
module_name memused module_name memused
module_type generic_data module_type generic_data
module_exec cat /proc/meminfo | grep "Active" | awk '{ print $2 }' module_exec cat /proc/meminfo | grep "Active" | awk '{ print $2 }'
module_postprocess 0,976
module_end module_end
module_begin module_begin

View File

@ -1,26 +1,27 @@
#Pandora Linux Agent
# #
%define name PandoraFMS_Agent #Pandora FMS Linux Agent
#
%define name pandorafms_agent
%define version 3.0.0 %define version 3.0.0
Summary: Pandora Agents Summary: Pandora FMS Linux agent
Name: %{name} Name: %{name}
Version: %{version} Version: %{version}
Release: 1 Release: 1
License: GPL License: GPL
Vendor: Sancho Lerena <sancho.lerena@artica.es> Vendor: ArticaST <http://www.artica.es>
Source0: %{name}-%{version}.tar.gz Source0: %{name}-%{version}.tar.gz
URL: http://pandora.sf.net URL: http://pandorafms.org
Group: System/Monitoring Group: System/Monitoring
Packager: Manuel Arostegui <marostegui@artica.es> Packager: Manuel Arostegui <manuel.arostegui@gmail.com>
Prefix: /usr/share Prefix: /usr/share
BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot BuildRoot: %{_tmppath}/%{name}-%{version}-buildroot
BuildArchitectures: noarch BuildArchitectures: noarch
Requires: coreutils Requires: coreutils
AutoReq: 0 AutoReq: 0
Provides: %{name}-%{version} Provides: %{name}-%{version}
%description %description
Pandora agents are based on native languages in every platform: scripts that can be written in any language. Its possible to reproduce any agent in any programming language and can be extended without difficulty the existing ones in order to cover aspects not taken into account up to the moment. Pandora FMS agents are based on native languages in every platform: scripts that can be written in any language. Its possible to reproduce any agent in any programming language and can be extended without difficulty the existing ones in order to cover aspects not taken into account up to the moment.
These scripts are formed by modules that each one gathers a "chunk" of information. Thus, every agent gathers several "chunks" of information; this one is organized in a data set and stored in a single file, called data file. These scripts are formed by modules that each one gathers a "chunk" of information. Thus, every agent gathers several "chunks" of information; this one is organized in a data set and stored in a single file, called data file.
%prep %prep
@ -47,62 +48,100 @@ cp -aRf $RPM_BUILD_ROOT%{prefix}/pandora_agent/tentacle_client $RPM_BUILD_ROOT/
mv $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent $RPM_BUILD_ROOT/usr/bin/ mv $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent $RPM_BUILD_ROOT/usr/bin/
%endif %endif
mv $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent_daemon $RPM_BUILD_ROOT/etc/init.d/pandora_agent_daemon mv $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent_daemon $RPM_BUILD_ROOT/etc/init.d/pandora_agent_daemon
mv $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.conf $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.conf.rpmnew
# Checking old config file (if exists)
if [ -f /etc/pandora/pandora_agent.conf ] ; then
cp /etc/pandora/pandora_agent.conf /etc/pandora/pandora_agent.conf.backup
fi
cp $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.conf $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.conf.rpmnew
if [ -f $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.spec ] ; then if [ -f $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.spec ] ; then
rm $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.spec rm $RPM_BUILD_ROOT%{prefix}/pandora_agent/pandora_agent.spec
fi fi
%clean %clean
rm -rf $RPM_BUILD_ROOT rm -Rf $RPM_BUILD_ROOT
%pre %pre
%if "%{_vendor}" == "redhat" /usr/sbin/useradd -d %{prefix}/pandora -s /bin/false -M -g 0 pandora
/usr/sbin/useradd -d %{prefix}/pandora -s /sbin/nologin -M -r pandora 2>/dev/null
%endif
exit 0 exit 0
%post %post
mkdir -p /etc/pandora if [ ! -d /etc/pandora ] ; then
if [ ! -f /usr/share/pandora_agent/pandora_agent.conf ] ; then mkdir -p /etc/pandora
mv /usr/share/pandora_agent/pandora_agent.conf.rpmnew /usr/share/pandora_agent/pandora_agent.conf
ln -s /usr/share/pandora_agent/pandora_agent.conf /etc/pandora/pandora_agent.conf
else
echo "Pandora Agent configuration file installed as /usr/share/pandora_agent/pandora_agent.conf.rpmnew"
fi fi
%if "%{_vendor}" == "suse"
if [ ! -f /usr/share/pandora_agent/pandora_agent.conf ] ; then
cp /usr/share/pandora_agent/pandora_agent.conf.rpmnew /usr/share/pandora_agent/pandora_agent.conf
else
cp /usr/share/pandora_agent/pandora_agent.conf /etc/pandora/pandora_agent.conf.backup
cp /usr/share/pandora_agent/pandora_agent.conf.rpmnew /usr/share/pandora_agent/pandora_agent.conf
fi
if [ -f /etc/pandora/pandora_agent.conf ] ; then
rm -Rf /etc/pandora/pandora_agent.conf
fi
if [ ! -e /etc/pandora/plugins ]; then
ln -s /usr/share/pandora_agent/plugins /etc/pandora
fi
if [ ! -e /etc/pandora/pandora_agent.conf ]; then
ln -s /usr/share/pandora_agent/pandora_agent.conf /etc/pandora/pandora_agent.conf
fi
%if "%{_vendor}" == "redhat"
ln -s /etc/init.d/pandora_agent_daemon /etc/rc0.d/K99pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc3.d/S99pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc5.d/S99pandora_agent_daemon
%else
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc5.d/S99pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc3.d/S99pandora_agent_daemon ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc3.d/S99pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc2.d/S99pandora_agent_daemon ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc2.d/S99pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc6.d/K99pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc0.d/K99pandora_agent_daemon ln -s /etc/init.d/pandora_agent_daemon /etc/rc.d/rc0.d/K99pandora_agent_daemon
%else
ln -s /etc/init.d/pandora_agent_daemon /etc/rc0.d/K99pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc6.d/K99pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc3.d/S99pandora_agent_daemon
ln -s /etc/init.d/pandora_agent_daemon /etc/rc5.d/S99pandora_agent_daemon
%endif %endif
%preun %preun
if [ "$1" = 0 ]; then if [ "$1" = 0 ]; then
# stop pandora_agent silently, but only if it's running /etc/init.d/pandora_agent_daemon stop
/usr/sbin/userdel pandora
rm /usr/bin/pandora_agent
rm /usr/bin/tentacle_client
rm /etc/init.d/pandora_agent_daemon
rm -Rf /usr/share/pandora_agent/
rm -Rf /etc/pandora/pandora_agent.conf
rm -Rf /etc/pandora/plugins
rm -Rf /var/spool/pandora/data_out
rm -Rf /var/log/pandora/pandora_agent* 2> /dev/null
%if "%{_vendor}" == "redhat" %if "%{_vendor}" == "redhat"
/usr/sbin/service pandora_agent_daemon stop &>/dev/null
/sbin/chkconfig --del pandora_agent_daemon /sbin/chkconfig --del pandora_agent_daemon
/usr/sbin/userdel pandora rm /etc/rc0.d/K99pandora_agent_daemon
rm /etc/rc3.d/S99pandora_agent_daemon
rm /etc/rc5.d/S99pandora_agent_daemon
%else
rm /etc/rc.d/rc5.d/S99pandora_agent_daemon
rm /etc/rc.d/rc3.d/S99pandora_agent_daemon
rm /etc/rc.d/rc2.d/S99pandora_agent_daemon
rm /etc/rc.d/rc0.d/K99pandora_agent_daemon
%endif %endif
fi fi
exit 0 exit 0
%files %files
%defattr(700,pandora,pandora) %defattr(750,pandora,root)
%if "%{_vendor}" == "redhat" %if "%{_vendor}" == "redhat"
/usr/bin/pandora_agent /usr/bin/pandora_agent
%else %else
/usr/bin/pandora_agent /usr/bin/pandora_agent
%endif %endif
%defattr(700,pandora,pandora) %defattr(770,pandora,root)
/var/log/pandora/ /var/log/pandora/
/var/spool/pandora/ /var/spool/pandora/
%defattr(755,pandora,pandora) /var/spool/pandora/data_out
%defattr(755,pandora,root)
/usr/bin/tentacle_client /usr/bin/tentacle_client
/etc/init.d/pandora_agent_daemon /etc/init.d/pandora_agent_daemon
%docdir %{prefix}/pandora_agents/docs %docdir %{prefix}/pandora_agents/docs