Commit 40cb13a6 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

Removed unnecessary old installed agent files in /opt

Removed because the package now uses the PROINFODATA installer to install
the agent on the machine.
Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
Acked-by: default avatarAryane Ast dos Santos <aras10@c3sl.ufpr.br>
parent 663cf17b
#!/bin/bash
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of collect-agent
#
# collect-agent 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Exit status:
#
# 0 - Successfully
# 1 - Error to rotate log file
# 2 - Error to edit crontab
# 3 - Error when updating
# 4 - Error to collect or send data
# 5 - INEP not found
#------------------------------------------------------------------------------
# function: rotateLogFile
# If the log file is out-of-date (set by $2), the savelog(1) will execute
# to rotate log file.
# Parameters:
# $1: log file name
# $2: time in days to expire
# $3: save $3 versions of the log file
function rotateLogFile()
{
find "${LOGDIR}" -type f -name "$1" -atime +$2 -exec savelog -c $3 {} \; ||
return 1
return 0
}
#------------------------------------------------------------------------------
# function: checkUpdate
# check for available updates and do downloads of the updates.
function checkUpdate()
{
updateLink="$(${CLIENT} --update)"
if test $? -eq 4; then
test -f "${TMPDIR}/SEED2-update.run" || rm -f ${TMPDIR}/SEED2-update.run
tryWget ${updateLink} \
-O ${TMPDIR}/SEED2-update.run || return 1
cd ${TMPDIR}
bash ${TMPDIR}/SEED2-update.run || return 1
rm -f ${TMPDIR}/SEED2-update.run
return 4
fi
return 0
}
#------------------------------------------------------------------------------
# function: schedule
# check scheduling in the crontab of current user, and insert schedule
# this agent in the crontab if not inserted.
function schedule()
{
if test -f "${CLIENTCONFDIR}/inep"; then
MIN=$(( $(sed "s/[^0-9]//g" ${CLIENTCONFDIR}/inep) % 60 ))
else
MIN=$(( $RANDOM % 60 ))
fi
userCron="$(printf\
"${MIN} ${SCHEDULE}\n${NETSCHEDULE}\n@reboot ${PREFIX}/agent.sh\n")"
if test "$(crontab -l)" != "${userCron}"; then
printf "${userCron}\n\n" | crontab - || return 1
fi
return 0
}
#------------------------------------------------------------------------------
# function: elapsedTime
# Check if elapsed ${DELAY} seconds since the last execution.
# return true or false.
function elapsedTime()
{
test -f "${TMPDIR}/lastExec.tmp" || return 0
atSeconds=$(date +%s)
oldSeconds=$(cat ${TMPDIR}/lastExec.tmp)
(( (${atSeconds}-${oldSeconds}) >= ${DELAY} ))
return $?
}
declare PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 3
source ${PREFIX}/client/common.sh
exec 1>> ${LOGFILE} 2>&1
if ! rotateLogFile '*.log' ${DAYSTOEXPIRELOG} 12; then
date +"%F %T - Error while rolling log file."
exit 1
fi
date +"%F %T - Agent started."
if ! schedule; then
date +"%F %T - Error to edit crontab."
exit 2
fi
checkUpdate
updateStatus=$?
test ${updateStatus} -eq 4 && exit 0
if test ${updateStatus} -eq 1; then
date +"%F %T - Error while updating agent."
exit 3
fi
if ! test -f ${CLIENTCONFDIR}/inep -a -n "$(cat ${CLIENTCONFDIR}/inep)"; then
date +"%F %T - INEP not found in ${CLIENTCONFDIR}/inep, waiting configuration."
exit 5
fi
if elapsedTime; then
if ! bash ${PREFIX}/collect-data.sh; then
date +"%F %T - Error at collect system data or send data."
date +"%F %T - Agent terminated with fails."
exit 4
fi
# Records the time of execution current to the use of function elapsedTime.
date +%s > ${TMPDIR}/lastExec.tmp
fi
date +"%F %T - Agent terminated sucessfull."
exit 0
#!/bin/bash
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of client, it is used to store common functions
#
# common.sh 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#------------------------------------------------------------------------------
# function: getProxyConf
# Load the proxy configuration.
function getProxyConf()
{
if ! test -z "${PREFIX}"; then
PROXYCONF="${PREFIX}/client/conf/proxy"
else
PROXYCONF="${dirname}/conf/proxy"
fi
phost=$(grep "^phost=" ${PROXYCONF} | cut -f2 -d=)
pport=$(grep "^pport=" ${PROXYCONF} | cut -f2 -d=)
puid=$(grep "^puid=" ${PROXYCONF} | cut -f2 -d=)
ppasswd=$(grep "^ppasswd=" ${PROXYCONF} | cut -f2 -d=)
if test -n "${phost}"; then
phost="--phost=${phost}"
fi
if test -n "${pport}"; then
pport="--pport=${pport}"
fi
if test -n "${puid}"; then
puid="--puid=${puid}"
fi
if test -n "${ppasswd}"; then
ppasswd="--ppasswd=${ppasswd}"
fi
}
function tryWget(){
getProxyConf
if test -z "$phost"; then
PROXY=""
else
PROXY="http://${phost}:${pport}"
fi
if which wget &>/dev/null; then
WGETBIN="$(which wget)"
else
WGETBIN="${PREFIX}/bin/wget"
fi
http_proxy="${PROXY}" ${WGETBIN} --tries=${UPDATETRIES} \
--timeout=${UPDATETIMEOUT} \
--proxy-user="${puid}" \
--proxy-password="${ppasswd}" \
$* || return 1
}
#!/bin/bash
# Run.sh
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of client
#
# client 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
dirname=$(dirname $0)
basename=$(basename ${dirname})
bindir=${dirname}/bin
inepRE="^[A-Z]{2}?[[:digit:]]{8}$"
# Redirects all error output to log file
exec 2>> ${dirname}/run.log
# Timestamp
date +"%F %T" >> ${dirname}/run.log
# Get common functions
source ${dirname}/common.sh
# Get MAC address from collect-parser mac-address script
mac=$(bash ${dirname}/../scripts/collect/mac-address/number.string)
url="--url=http://seed.c3sl.ufpr.br/tomcat/axis/Seed2.jws"
inep=$(cat ${dirname}/conf/inep)
# Check INEP integrity: the egrep test verifies if INEP is valid, returning
# an empty string if it isn't. The first test checks if INEP is empty before
# doing the second test. If it isn't empty, the regular expression occurs.
# Otherwise, the INEP is accepted and the program continues with the
# execution. In short, the test allows empty and valid INEPs.
if test -n "${inep}" -a -z "$(egrep ${inepRE} <<< ${inep})"; then
echo "INEP format error." >> ${dirname}/run.log
exit 100
fi
getProxyConf
proxy="${phost} ${pport} ${puid} ${ppasswd}"
inep="--inep=${inep}"
mac="--mac=${mac}"
# Execution
if test $# -gt 1; then
echo "Run.sh call: wrong number of parameters ($#)." \
>> ${dirname}/run.log
exit 101
elif test $# -eq 0; then
${bindir}/client ${url} ${inep} ${mac} ${proxy} >> ${dirname}/run.log
elif [[ $1 == "--update" ]]; then
retstr=$(${bindir}/client $1 ${url} ${proxy})
retval=$?
if test ${retval} -eq 4; then
echo "$retstr" | tee -a ${dirname}/run.log
fi
exit $retval
elif [[ $1 == "--inventory" ]]; then
${bindir}/client $1 ${url} ${inep} ${proxy} >> ${dirname}/run.log
else
echo "Run.sh call: wrong parameter (\"$1\")." >> ${dirname}/run.log
exit 102
fi
#general
#the var $PREFIX content the absolute path of agent.
DATADIR=${PREFIX}/data
LOGDIR=${PREFIX}/log
XMLFILENAME=${DATADIR}/collect-data.xml
SCRIPTSDIR=${PREFIX}/scripts
CLIENT=${PREFIX}/client/run.sh
CLIENTCONFDIR=${PREFIX}/client/conf
LOGFILE=${LOGDIR}/collect.log
TMPDIR=${PREFIX}/tmp
NETMONITOR=${PREFIX}/net/network-monitor.sh
SCHEDULE="* * * * ${PREFIX}/integrity-checker.sh && ${PREFIX}/agent.sh"
NETSCHEDULE="0-59 * * * * ${NETMONITOR}"
UPDATETRIES=3
UPDATETIMEOUT=100
DELAY=86400 #24 hours
DAYSTOEXPIRELOG=31 #1 month
LD_LIBRARY_PATH=${PREFIX}/lib/lib:${LD_LIBRARY_PATH}
XMLPARSER=${PREFIX}/bin/collect-parser
#!/bin/bash
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of collect-agent
#
# collect-agent 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#------------------------------------------------------------------------------
# function: message
# Treat out stream of the error.
# argument $1: Id of the error.
# argument $2: Out Stream (default stderr)
function message()
{
stream="/proc/self/fd/1"
test -n "$2" && stream="$2"
case $1 in
1)
printf "Usage: ${SCRIPTPATH} {start|stop}\n" > ${stream}
;;
2)
printf "This Daemon already running.\n" > ${stream}
;;
3)
printf "Config file not found.\n" > ${stream}
;;
*)
printf "Unknow.\n" > ${stream}
;;
esac
return $1
}
declare SCRIPTPATH="$0" DEFAULTCONFIG="collect.conf"
if test $# -gt 1 -a -f "$1"; then
conf=$(readlink -f $1)
elif test -f "${PREFIX}/${DEFAULTCONFIG}"; then
conf="${PREFIX}/${DEFAULTCONFIG}"
else
message 3 /proc/self/fd/2; exit 3
fi
#read config file and declares only valid vars.
while read var; do
test -n "$(echo $var | egrep -i "^[a-z_]+=")" && eval "declare ${var}"
done < ${conf}
mkdir -p ${TMPDIR} ${DATADIR} ${LOGDIR}
d41d8cd98f00b204e9800998ecf8427e
# SEED2 COLLECT AGENT
C3SL - Centro de Computacao Cientifica e Software Livre
Agtha Cristina de Nadai
Bruno Cesar Ribas
Carlos Carvalho
Daniel Weingaertner
Danilo Kiyoshi Simizu Yorinori
Diego Giovane Pasqualin
Edson Ramiro Lucas Filho
Eduardo Cunha de Almeida
Erik Alexandre Pucci
Fabiano Silva
Jorge Augusto Meira
Josiney de Souza
Juliana Bueno
Lucio Foltran da Silva
Luis Carlos Erpen de Bona
Marcos Castilho
Renan Franca De Miranda
Ricardo Tavares De Oliveira
Rubens Massayuki Suguimoto
Thiago Henrique Dos Santos Picharski
Tiago Rodrigo Kepe
Vinicius Kwiecien Ruoso
This diff is collapsed.
#!/bin/bash
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of collect-agent
#
# collect-agent 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; either version 2
# of the License, or (at your option) any later version.
#
# 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.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
#
# Exit status:
#
# 0 - Successfully
# 1 - Error to rotate log file
# 2 - Error to edit crontab
# 3 - Error when updating
# 4 - Error to collect or send data
# 5 - INEP not found
#------------------------------------------------------------------------------
# function: rotateLogFile
# If the log file is out-of-date (set by $2), the savelog(1) will execute
# to rotate log file.
# Parameters:
# $1: log file name
# $2: time in days to expire
# $3: save $3 versions of the log file
function rotateLogFile()
{
find "${LOGDIR}" -type f -name "$1" -atime +$2 -exec savelog -c $3 {} \; ||
return 1
return 0
}
#------------------------------------------------------------------------------
# function: checkUpdate
# check for available updates and do downloads of the updates.
function checkUpdate()
{
updateLink="$(${CLIENT} --update)"
if test $? -eq 4; then
test -f "${TMPDIR}/SEED2-update.run" || rm -f ${TMPDIR}/SEED2-update.run
tryWget ${updateLink} \
-O ${TMPDIR}/SEED2-update.run || return 1
cd ${TMPDIR}
bash ${TMPDIR}/SEED2-update.run || return 1
rm -f ${TMPDIR}/SEED2-update.run
return 4
fi
return 0
}
#------------------------------------------------------------------------------
# function: schedule
# check scheduling in the crontab of current user, and insert schedule
# this agent in the crontab if not inserted.
function schedule()
{
if test -f "${CLIENTCONFDIR}/inep"; then
MIN=$(( $(sed "s/[^0-9]//g" ${CLIENTCONFDIR}/inep) % 60 ))
else
MIN=$(( $RANDOM % 60 ))
fi
userCron="$(printf\
"${MIN} ${SCHEDULE}\n${NETSCHEDULE}\n@reboot ${PREFIX}/agent.sh\n")"
if test "$(crontab -l)" != "${userCron}"; then
printf "${userCron}\n\n" | crontab - || return 1
fi
return 0
}
#------------------------------------------------------------------------------
# function: elapsedTime
# Check if elapsed ${DELAY} seconds since the last execution.
# return true or false.
function elapsedTime()
{
test -f "${TMPDIR}/lastExec.tmp" || return 0
atSeconds=$(date +%s)
oldSeconds=$(cat ${TMPDIR}/lastExec.tmp)
(( (${atSeconds}-${oldSeconds}) >= ${DELAY} ))
return $?
}
declare PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 3
source ${PREFIX}/client/common.sh
exec 1>> ${LOGFILE} 2>&1
if ! rotateLogFile '*.log' ${DAYSTOEXPIRELOG} 12; then
date +"%F %T - Error while rolling log file."
exit 1
fi
date +"%F %T - Agent started."
if ! schedule; then
date +"%F %T - Error to edit crontab."
exit 2
fi
checkUpdate
updateStatus=$?
test ${updateStatus} -eq 4 && exit 0
if test ${updateStatus} -eq 1; then
date +"%F %T - Error while updating agent."
exit 3
fi
if ! test -f ${CLIENTCONFDIR}/inep -a -n "$(cat ${CLIENTCONFDIR}/inep)"; then
date +"%F %T - INEP not found in ${CLIENTCONFDIR}/inep, waiting configuration."
exit 5
fi
if elapsedTime; then
if ! bash ${PREFIX}/collect-data.sh; then
date +"%F %T - Error at collect system data or send data."
date +"%F %T - Agent terminated with fails."
exit 4
fi
# Records the time of execution current to the use of function elapsedTime.
date +%s > ${TMPDIR}/lastExec.tmp
fi
date +"%F %T - Agent terminated sucessfull."
exit 0
#!/bin/bash
# Copyright (C) 2004-2009 Centro de Computacao Cientifica e Software Livre
# Departamento de Informatica - Universidade Federal do Parana - C3SL/UFPR
#
# This file is part of client, it is used to store common functions
#
# common.sh 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; either version 2
# of the License, or (at your option) any later version.
#