Commit 21bce201 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

Merge remote branch 'collect/master'

Signed-off-by: default avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parents be01cf8c 5d1763b8
C3SL - Centro de Computacao Cientifica e Software Livre
Agtha Cristina de Nadai
Adriano da Luz
Aryane Ast dos Santos
Bruno Cesar Ribas
Carlos Carvalho
Cleide Luzia Bonfim Possamai
Daniel Weingaertner
Danilo Kiyoshi Simizu Yorinori
Diego Giovane Pasqualin
Eduardo Cunha de Almeida
Erik Alexandre Pucci
Fabiano Silva
Felipe Cys Laskoski
Guilherme Zasyeki Machado
Jorge Augusto Meira
Josiney de Souza
Juliana Bueno
Klismann Smoger Mottin
Luis Carlos Erpen de Bona
Marcos Castilho
Marcos Sunye
Pedro Eugenio Rocha
Renan Franca De Miranda
Ricardo Tavares De Oliveira
Rubens Massayuki Suguimoto
Thiago Henrique Dos Santos Picharski
Tiago Rodrigo Kepe
Victor Tarabola Cortiano
Vinicius Kwiecien Ruoso
This diff is collapsed.
TOPDIR = .
SRCDIR = $(TOPDIR)/src
LIBDIR = $(TOPDIR)/lib
BINDIR = bin
LIBXMLDIR = lib
NETDIR = $(TOPDIR)/net
all:
cd $(LIBDIR) && make all
cd $(SRCDIR) && make all
cd $(NETDIR) && make all
collect-parser:
cd $(SRCDIR) && make all
install: all
@cd $(LIBDIR) && make install
@cd $(SRCDIR) && make install
@cd $(NETDIR) && make install
@echo "Setting variables in collect.conf..."
@grep -v "XMLPARSER=" collect.conf > temp.conf\
&& cat temp.conf > collect.conf && rm -f temp.conf
@echo XMLPARSER=$$\{PREFIX\}/$(BINDIR)/collect-parser >> collect.conf
clean:
cd $(LIBDIR) && make clean
cd $(SRCDIR) && make clean
cd $(NETDIR) && make clean
distclean:
cd $(LIBDIR) && make distclean
cd $(SRCDIR) && make distclean
cd $(NETDIR) && make distclean
- Send inventory
- Check bugs
#!/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 - Success
# 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
# 6 - Error when loading configuration
#------------------------------------------------------------------------------
# Function: rotateLogFile
# If the log file is out-of-date (set by $2), execute savelog(1) to rotate it.
# 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
# Verify and download the new version of the agent.
function checkUpdate()
{
updateLink="$(${CLIENT} --update)"
returnValue=$?
if test ${returnValue} -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}
# If $FIST_EXECUTION is set, do not run the update. Otherwise, run the
# update and return 1 in case of error
test "${FIRST_EXECUTION}" || bash ${TMPDIR}/SEED2-update.run || return 1
rm -f ${TMPDIR}/SEED2-update.run
# Return 0 if this is the first execution of the agent
test "${FIRST_EXECUTION}" && return 0
fi
return ${returnValue}
}
#------------------------------------------------------------------------------
# Function: schedule
# Check scheduling in the user's crontab and write the new schedule in case
# there wasn't one or if it was different.
function schedule()
{
if test -f "${CLIENTCONFDIR}/inep"; then
MIN=$(( 10#$(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
# Verify if ${DELAY} seconds have elapsed since agent 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 $?
}
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 6
source ${PREFIX}/client/common.sh
exec >> ${LOGFILE} 2>&1
# Run extra scripts before anything
for script in ${PREFIX}/extra/scripts/* ; do
${script}
done
# Rotate the log file if it has already expired
if ! rotateLogFile '*.log' ${DAYSTOEXPIRELOG} 12; then
date +"%F %T - Error while rolling log file."
exit 1
fi
date +"%F %T - Agent started."
# Edit crontab if it isn't correct
if ! schedule; then
date +"%F %T - Error to edit crontab."
exit 2
fi
# If this is the agent's first execution, save the version and force the update
# process to happen by setting the version to "0.0.0"
if test "${FIRST_EXECUTION}"; then
REALVERSION=$(cat "${VERSIONFILE}")
echo "0.0.0" > "${VERSIONFILE}"
fi
checkUpdate
updateStatus=$?
# Restore the real version of the agent, if this is its first execution
test "${FIRST_EXECUTION}" && echo "${REALVERSION}" > "${VERSIONFILE}"
test ${updateStatus} -eq 4 && exit 0
if test ${updateStatus} -ne 0; then
date +"%F %T - Error while updating agent."
exit 3
fi
# Check if inep file exists and is configured
if ! test -f ${CLIENTCONFDIR}/inep -a -n "$(cat ${CLIENTCONFDIR}/inep \
2> /dev/null)"; then
date +"%F %T - INEP not found in ${CLIENTCONFDIR}/inep, waiting configuration."
exit 5
fi
# Collect and send system data if elapsed enough time or if it's the first
# execution
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 failure."
exit 4
fi
# Record the current execution time to be used by elapsedTime()
date +%s > ${TMPDIR}/lastExec.tmp
fi
date +"%F %T - Agent terminated sucessfully."
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 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 - Success
# 3 - Error when loading configuration
# 4 - XML filename not defined at configuration file
# 5 - Client not found or without execution permission
# 6 - Error while collecting system data
# 7 - Client returned an error
#------------------------------------------------------------------------------
# Function: clientExec
# Execute client sender with all necessary parameters.
# The parameters are obtained from the global variables.
function clientExec()
{
date +"%F %T - Sending data for the server."
${CLIENT} $*
error=$?
if test ${error} -ne 0; then
date +"%F %T - ERROR: while sending data for the server."
return ${error}
fi
}
declare PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 3
if test -z "${XMLFILENAME}"; then
printf "ERROR: XML filename not defined at configuration file.\n"
exit 4
else
# Create "data" directory if it does not exist
mkdir -p $(dirname $XMLFILENAME)
fi
if test ! -x "${CLIENT}"; then
printf "ERROR: Client not found or without execution permission.\n"
printf "${SCRIPTPATH} finished.\n"
exit 5
fi
# Collect system data
if ! ${XMLPARSER} "${SCRIPTSDIR}" "${XMLFILENAME}"; then
date +"%F %T - ERROR: while collecting system data."
exit 6
fi
date +"%F %T - New inventory collected."
if ! clientExec --inventory; then
exit 7
fi
exit 0
# Configuration file.
# $PREFIX contains the absolute path of the agent.
DATADIR=${PREFIX}/data
LOGDIR=${PREFIX}/log
XMLFILENAME=${DATADIR}/collect-data.xml
SCRIPTSDIR=${PREFIX}/scripts
CLIENT=${PREFIX}/client/run.sh
CLIENTCONFDIR=${PREFIX}/client/conf
VERSIONFILE=${CLIENTCONFDIR}/version
LOGFILE=${LOGDIR}/collect.log
TMPDIR=${PREFIX}/tmp
NETMONITOR=${PREFIX}/net/bandwidth.sh
SCHEDULE="* * * * ${PREFIX}/integrity-checker.sh && ${PREFIX}/agent.sh"
NETSCHEDULE="0-59/5 * * * * ${NETMONITOR}"
UPDATETRIES=3
UPDATETIMEOUT=100
DELAY=86400 # 24 hours
DAYSTOEXPIRELOG=31 # 1 month
#!/usr/bin/env python
import re,sys,socket,threading,os
from time import sleep,asctime,time
curdir = os.path.dirname(os.path.abspath(sys.argv[0]))
CONFFILE = curdir + "/remotelog.conf"
LOGFILE = curdir + "/remotelog.log"
LOGERROR=0
LOGWARNING=1
LOGCONTROL=2
LOGMESSAGE=3
LOGDEBUG=4
def readConf():
""" Le arquivo de configuracao mcast.conf e retorna dicionario
{opcao:valor} """
res = {}
for line in open(CONFFILE):
if not re.match("^(#|$)",line):
opt,value = [ i.strip() for i in line.split("=") ]
res[opt] = value
return res
class Log(object):
""" Salva mensagens no arquivo de log LOGFILE, respeitando o verboso
desejado escrito em CONFFILE """
def __init__(self,logFile=LOGFILE):
self.__conf = readConf()
self.__file = open(logFile,"a")
self.verbose = int(self.__conf["verbose"])
def log(self, msg, verbose=LOGERROR):
""" Escreve mensagem de log no arquivo se verbose for <= ao verbose
definido no arquivo de configuracao """
if int(verbose) <= self.verbose:
timestamp = asctime()[4:]
msg = "%s: %s" % (timestamp,msg)
self.__write(msg)
if self.verbose == 10:
print msg
def __flush(self):
self.__file.flush()
def __write(self,msg):
print "escrevendo", msg
self.__file.write(msg+"\n")
self.__file.flush()
# Arquivo de configuracao do remotelog_server e remotelog_client
remoteport = 5005
remotehost = colombard.c3sl.ufpr.br
# Onde os logs serao salvos no servidor
log = remotelog.log
# nivel de verboso das mensagens logadas (10 mostra tudo na tela)
verbose = 0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tcp import TCPClient
from misc import readConf
import sys
class RemoteLogClient(TCPClient):
def __init__(self, inep, logList):
self.__conf = readConf()
self.__logList = logList
self.__inep = inep
self.__remotePort = int(self.__conf["remoteport"])
self.__remoteHost = self.__conf["remotehost"]
TCPClient.__init__(self, self.__remoteHost, self.__remotePort)
self.__quit = False
def run(self):
inep = self.getInep()
for log in self.__logList:
for data in open(log):
msg = "%s: %s" % (inep,data)
self.send(msg)
def getInep(self):
return self.__inep
def usage():
print sys.argv[0],": <inep> <arq. de log 1> [arq. de log 2] ..."
if __name__ == "__main__":
if len(sys.argv) == 1:
usage()
sys.exit(0)
rls = RemoteLogClient(sys.argv[1], sys.argv[2:])
try:
rls.run()
except:
raise
rls.close()
sys.exit(0)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from tcp import TCPServer
from misc import Log, readConf
class RemoteLogServer(TCPServer):
def __init__(self, host="localhost"):
self.__conf = readConf()
self.__log = Log(self.__conf["log"])
self.__port = int(self.__conf["remoteport"])
TCPServer.__init__(self, "", self.__port)
self.__quit = False
def quit(self):
self.__quit = True
def log(self, msg):
self.__log.log(msg)
def init(self):
while not self.__quit:
connection, address = self.accept()
while True:
data = connection.recv(1024).strip()
if data:
for line in data.split("\n"):
self.log(data)
else:
break
connection.close()
if __name__ == "__main__":
import sys
rls = RemoteLogServer()
try:
rls.init()
except KeyboardInterrupt:
rls.quit()
sys.exit(1)
sys.exit(0)
#!/usr/bin/env python
from socket import *
TCP_CLIENT_TIMEOUT = None
BUFF_SIZE = 1024
class TCPParams(object):
def __init__(self,host,port):
self.__socket = socket(AF_INET, SOCK_STREAM)
self.__host = host
self.__port = int(port)
self.__addr = (self.getHost(),self.getPort())
self.__buffer = ""
def send(self, data):
self.getSocket().send(str(data))
def read(self):
return self.getSocket().recvfrom(1024)
def getSocket(self):
return self.__socket
def getPort(self):
return self.__port
def getHost(self):
return self.__host
def getAddr(self):
return self.__addr
def close(self):
self.getSocket().close()
class TCPServer(TCPParams):
def __init__(self,host,port,timeout=TCP_CLIENT_TIMEOUT):
TCPParams.__init__(self,host,port)
if timeout:
self.getSocket().settimeout(timeout)
self.__connect()
def __connect(self):
self.getSocket().bind(self.getAddr())
self.getSocket().listen(5)
def accept(self):
return self.getSocket().accept()
class TCPClient(TCPParams):
def __init__(self, host, port):
TCPParams.__init__(self, host, port)
self.__connect()
def __connect(self):
self.getSocket().connect(self.getAddr())
#!/usr/bin/expect -f
set cmd [lindex $argv 0 ]
spawn su -
# WARNING: Remeber to change 'XXX' by the real root password!
expect ": " { send "XXX\r" }
expect "# " { send "$cmd\r" }
expect "# " { send "exit\r" }
exit
#!/bin/bash
# Copyright (C) 2004-2010 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.
# This script will install/update tincuca-server on Metasys Servers
# of the RUCA project
LOGDIR=${HOME}/SEED2/log
LOGFILE=${LOGDIR}/tincucaclient-install.log
TINCUCALOG=/var/log/tincucaclient.log
TESTINEPSFILE=${HOME}/SEED2/extra/testineps.txt
REMOTELOGCLIENT=${HOME}/SEED2/extra/remotelog/remotelog_client.py
# Check if I am a Metasys Server
if ! grep -q "Metasys School Server" /etc/issue ; then
exit 0
fi
# Check if I am a test server
INEP=$(mysql -u root -D -s -N MetasysMonit -e "select INEP from INEP")
if test -z "${INEP}" || ! grep -q "${INEP}" ${TESTINEPSFILE} ; then
exit 0
fi
${REMOTELOGCLIENT} "${INEP}" "${LOGFILE}" "${TINCUCALOG}"
exit 0
#!/bin/bash
# Copyright (C) 2004-2010 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.
# This script will install/update tincuca-server on Metasys Servers
# of the RUCA project
LOGDIR=${HOME}/SEED2/log
LOGFILE=${LOGDIR}/tincucaclient-install.log
MYVERSION=/etc/tincuca-client/version
LASTVERSIONURL=http://colombard.c3sl.ufpr.br/update/tincuca-client-version
PACKAGEURL=http://colombard.c3sl.ufpr.br/update/tincuca-client.rpm
PACKPATH=/tmp/tincuca-client-new.rpm
RUNASROOT=${HOME}/SEED2/extra/runasroot.sh
TESTINEPSFILE=${HOME}/SEED2/extra/testineps.txt
PROINFOINEPFILE=/opt/seed_mec/SEED2/client/conf/inep
mkdir -p ${LOGDIR}
printLog () {
date +"%F %T - $1"
}
# Print all the output to the logfile
exec 1>> ${LOGFILE} 2>&1
# Check if I am a Metasys Server
if ! grep -q "Metasys School Server" /etc/issue ; then
printLog "This is not a Metasys School Server. Aborting."
exit 0
fi
# Check if I am a test server
INEP=$(mysql -u root -D -s -N MetasysMonit -e "select INEP from INEP")
if test $? -ne 0 || test -z "$INEP"; then
# MetasysMonitor not configured, trying to get INEP from PROINFODATA
if test -f ${PROINFOINEPFILE}; then
INEP=$(cat $PROINFOINEPFILE)
fi
fi
if test -z "${INEP}" || ! grep -q "${INEP}" ${TESTINEPSFILE} ; then
printLog "This is not a test server. Aborting."
exit 0
fi
# Make seed_mec a suduer
SUDOERS=/etc/sudoers
$RUNASROOT "chmod 644 ${SUDOERS}"
if ! grep -q seed_mec ${SUDOERS} ; then
$RUNASROOT "echo -e \"seed_mec\tALL=(ALL) NOPASSWD: ALL\" >> ${SUDOERS}"
fi
$RUNASROOT "chmod 440 ${SUDOERS}"
if test -f ${MYVERSION} ; then
# Get last version
LASTVERSION=$(mktemp)
if ! wget -q ${LASTVERSIONURL} -O ${LASTVERSION} ; then
printLog "Error while getting the last version!"
exit 1
fi
# Compare versions
if [[ "$(cat ${LASTVERSION})" == "$(cat ${MYVERSION})" ]]; then
printLog "Already up-to-date."
rm -f ${LASTVERSION}
exit 0
fi
else
# tincuca-client isn't installed yet. Try to get its dependences
DEPLISTURL=http://colombard.c3sl.ufpr.br/update/tincuca-deps/install_order
DEPLIST=$(mktemp)
if ! wget -q ${DEPLISTURL} -O ${DEPLIST} ; then
printLog "Error while getting the depencies list"
exit 2
fi
for package in $(cat ${DEPLIST}); do
printLog "Getting ${package}..."
DEPPACK=$(mktemp)
if ! wget -q -O ${DEPPACK} \
http://colombard.c3sl.ufpr.br/update/tincuca-deps/${package}
then
printLog "Error while getting ${package}!"