collect: Fix empty net usage inventory

Signed-off-by: 's avatarEdileuton Henrique de Oliveira <eho09@c3sl.ufpr.br>
parent f79cc0b7
......@@ -53,26 +53,6 @@ function xml_print()
printf "</netuse>"
}
# Function: xml_print_zero
# Function that prints the contents of XML when there was no collected
# data. Print the statistics with zeroed content.
function xml_print_zero()
{
local TRAFFIC_TIME=$(printf "%02d:%02d:30" $TRAFFIC_HOUR $TRAFFIC_MINUTE)
printf "<netuse id=\"$((COUNT+1))\">"
printf "<date value=\"$TRAFFIC_DATE\" type=\"string\"/>"
printf "<time value=\"$TRAFFIC_TIME\" type=\"string\"/>"
printf "<rx>"
printf "<packets value=\"0\" type=\"int\"/>"
printf "<bytes value=\"0\" type=\"int\"/>"
printf "</rx>"
printf "<tx>"
printf "<packets value=\"0\" type=\"int\"/>"
printf "<bytes value=\"0\" type=\"int\"/>"
printf "</tx>"
printf "</netuse>"
}
# Function: xml_data_generator
# This function compares the file date of the last day of collection
......@@ -105,25 +85,16 @@ function xml_data_generator()
else
INTERVALID=$(cut -d" " -f1 <<< $line)
while test $COUNT -lt $INTERVALID -a $COUNT -lt 288; do
xml_print_zero
COUNT=$((${COUNT} + 1))
increment_time
done
if test $COUNT -eq $INTERVALID -a $COUNT -lt 288; then
if test $COUNT -lt 288; then
xml_print
COUNT=$((${COUNT} + 1))
increment_time
fi
fi
done < $TRAFFIC
while test $COUNT -lt 288; do
xml_print_zero
COUNT=$((${COUNT} + 1))
increment_time
done
else
# If date in TRAFFIC file is older than 15 days then remove the file.
rm -f $TRAFFIC
fi
printf "\n"
......@@ -142,10 +113,15 @@ if test "$(bash $PROJECT)" != "0" -o "${FIRST_EXECUTION}"; then
exit 0
fi
TRAFFIC="${PREFIX}/../../../net/previous-traffic.txt"
TRAFFICS="${PREFIX}/../../../net/previous"
test -f "${TRAFFIC}" || exit 0
test -s $TRAFFIC || exit 0
test -d ${TRAFFICS} || exit 0
# Call the function xml_data_generator to generate the data to XML
xml_data_generator
for TRAFFIC in $(ls -r ${TRAFFICS})
do
TRAFFIC="${TRAFFICS}/${TRAFFIC}"
if test -s ${TRAFFIC}; then
xml_data_generator
fi
done
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