Commit c6e36e53 authored by Erik Alexandre Pucci's avatar Erik Alexandre Pucci

collect: Add network scripts structure and make some corrections

Update exit values and status of the main agent scripts.
Signed-off-by: 's avatarErik Alexandre Pucci <eap08@c3sl.ufpr.br>
parent 02076257
......@@ -20,7 +20,7 @@
# USA.
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 6
source ${PREFIX}/load-config.sh || exit 1
exec >> ${LOGFILE} 2>&1
......
......@@ -22,12 +22,12 @@
# 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
# 1 - Error when loading configuration
# 2 - INEP not configured
# 3 - XML filename not defined
# 4 - Client not found or without execution permission
# 5 - Error while collecting inventory
# 6 - Error while executing the client
# ------------------------------------------------------------------------------
# Function: elapsedTime
......@@ -64,7 +64,7 @@ function clientExec()
# ------------------------------------------------------------------------------
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 6
source ${PREFIX}/load-config.sh || exit 1
exec >> ${LOGFILE} 2>&1
......@@ -72,7 +72,7 @@ exec >> ${LOGFILE} 2>&1
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
exit 2
fi
# Collect and send system data if elapsed enough time or if it's the first
......@@ -80,7 +80,7 @@ fi
if elapsedTime; then
if test -z "${XMLFILENAME}"; then
printf "ERROR: XML filename not defined at configuration file.\n"
exit 4
exit 3
else
# Create "data" directory if it does not exist
mkdir -p $(dirname $XMLFILENAME)
......@@ -88,18 +88,18 @@ if elapsedTime; then
if test ! -x "${CLIENT}"; then
printf "ERROR: Client not found or without execution permission.\n"
printf "${SCRIPTPATH} finished.\n"
exit 5
exit 4
fi
# Collect system data
if ! ${XMLPARSER} "${SCRIPTSDIR}" "${XMLFILENAME}"; then
date +"%F %T - ERROR: while collecting system data."
exit 6
exit 5
fi
date +"%F %T - New inventory collected."
if ! clientExec --inventory; then
exit 7
exit 6
fi
# Record the current execution time to be used by elapsedTime()
......
#!/bin/bash
# Copyright (C) 2009-2012 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.
PREFIX="$(dirname $(readlink -f $0))"
cat ${PREFIX}/../../../client/conf/version
exit $?
#!/bin/bash
# Copyright (C) 2009-2012 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.
PREFIX="$(dirname $(readlink -f $0))"
cat ${PREFIX}/../../../client/conf/inep
exit $?
#!/bin/bash
# Copyright (C) 2009-2012 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.
while read mac; do
newTag="<mac value=\"$mac\" type=\"string\"/>"
tags="$tags$newTag"
done < <(/sbin/ifconfig 2>&1 | awk '/HW/ {print $NF}' | sort -u)
printf "${tags}\n"
#!/bin/bash
# Copyright (C) 2009-2012 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.
PROJECTOR=$(grep "Projetor ProInfo" /etc/issue 2> /dev/null)
UCA_SERVER=$(grep "Metasys School Server" /etc/issue 2> /dev/null)
UCA_CLASSMATE=$(grep "Metasys ClassmatePC" /etc/issue 2> /dev/null)
if test -n "${PROJECTOR}" -o -f "/usr/sbin/projetor"; then
printf "3\n"
elif test -n "${UCA_SERVER}"; then
printf "2\n"
elif test -f "/etc/cmpc-release" -o -n "${UCA_CLASSMATE}"; then
printf "1\n"
else
printf "0\n"
fi
exit $?
......@@ -22,12 +22,12 @@
# 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
# 1 - Error when loading configuration
# 2 - INEP not configured
# 3 - XML filename not defined
# 4 - Client not found or without execution permission
# 5 - Error while collecting network usage
# 6 - Error while executing the client
# ------------------------------------------------------------------------------
# Function: elapsedTime
......@@ -64,7 +64,8 @@ function clientExec()
# ------------------------------------------------------------------------------
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 6
source ${PREFIX}/load-config.sh || exit 1
PREVIOUS_TRAFFIC="${PREFIX}/../../../net/previous-traffic.txt"
exec >> ${LOGFILE} 2>&1
......@@ -73,15 +74,15 @@ 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
exit 2
fi
# Collect and send system data if elapsed enough time or if it's the first
# execution of the agent
if elapsedTime; then
if elapsedTime && test -s "${PREVIOUS_TRAFFIC}"; then
if test -z "${NETXMLFILENAME}"; then
printf "ERROR: Net XML filename not defined at configuration file.\n"
exit 4
exit 3
else
# Create "data" directory if it does not exist
mkdir -p $(dirname $NETXMLFILENAME)
......@@ -89,18 +90,18 @@ if elapsedTime; then
if test ! -x "${CLIENT}"; then
printf "ERROR: Client not found or without execution permission.\n"
printf "${SCRIPTPATH} finished.\n"
exit 5
exit 4
fi
# Collect system data
if ! ${XMLPARSER} "${NETSCRIPTSDIR}" "${NETXMLFILENAME}"; then
date +"%F %T - ERROR: while collecting network usage data."
exit 6
exit 5
fi
date +"%F %T - New network usage data collected."
if ! clientExec --network; then
exit 7
exit 6
fi
# Record the current execution time to be used by elapsedTime()
......
......@@ -22,12 +22,10 @@
# 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
# 1 - Error when loading configuration
# 2 - Error to rotate log file
# 3 - Error to edit crontab
# 4 - Error while trying to update the agent
# ------------------------------------------------------------------------------
# Function: rotateLogFile
......@@ -97,7 +95,7 @@ function schedule()
# ------------------------------------------------------------------------------
export PREFIX="$(dirname $(readlink -f $0))"
source ${PREFIX}/load-config.sh || exit 6
source ${PREFIX}/load-config.sh || exit 1
source ${PREFIX}/client/common.sh
exec >> ${LOGFILE} 2>&1
......@@ -105,7 +103,7 @@ exec >> ${LOGFILE} 2>&1
# 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
exit 2
fi
date +"%F %T - Agent started."
......@@ -113,7 +111,7 @@ date +"%F %T - Agent started."
# Edit crontab if it isn't correct
if ! schedule; then
date +"%F %T - Error to edit crontab."
exit 2
exit 3
fi
# If this is the agent's first execution, save the version and force the update
......@@ -131,9 +129,9 @@ 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
date +"%F %T - Error while trying to update the agent."
exit 4
fi
date +"%F %T - Agent terminated sucessfully."
date +"%F %T - Update process terminated sucessfully."
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment