Commit 806a4ff6 authored by Eduardo L. Buratti's avatar Eduardo L. Buratti

Merge branch 'master' of git.c3sl.ufpr.br:proinfodata/unstable

parents fead4d06 126cb387
......@@ -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
File mode changed from 100644 to 100755
......@@ -50,7 +50,7 @@ BEGIN
i.disk2_used,
i.extra_hds,
i.mirror_timestamp,
i.version,
i.agent_version,
'0'::boolean as valid
FROM
proinfo_inventory i
......@@ -182,7 +182,7 @@ BEGIN
disk1_model is NULL OR
disk1_size is NULL OR
disk1_used is NULL OR
version is NULL OR
agent_version is NULL OR
NOT valid_macaddress(macaddr) OR
project < 0 OR project > 3 OR
inep is NULL);
......
......@@ -15,7 +15,7 @@ BEGIN
INTO result from sa_inventory;
--
INSERT INTO fact_contact (sch_id, cit_id, dat_id, macaddr, project, ts, version)
INSERT INTO fact_contact (sch_id, cit_id, dat_id, macaddr, project, mirror_timestamp, agent_version)
(SELECT sch_id, cit_id, contact_date, macaddr::macaddr, to_project_enum(project), mirror_timestamp, agent_version FROM sa_inventory WHERE valid = '1')
EXCEPT
(SELECT sch_id, cit_id, dat_id, macaddr, project, mirror_timestamp, agent_version FROM fact_contact WHERE dat_id >= result.min_date AND dat_id <= result.max_date);
......
......@@ -191,7 +191,7 @@ BEGIN
d.os_distro,
d.processor,
simplify_memory(d.memory),
simplify_hd(d.disk1_size)
simplify_hd(d.disk1_size + COALESCE(d.disk2_size,0))
FROM
(SELECT
macaddr,
......
CREATE OR REPLACE FUNCTION simplify_memory(integer) RETURNS text AS $$
SELECT CASE
WHEN $1 < 1024 THEN $1 || ' KiB'
WHEN $1 < 1048576 THEN ROUND($1 / 1024, 2) || ' MiB'
WHEN $1 < 1073741824 THEN ROUND($1 / 1048576, 2) || ' GiB'
ELSE ROUND($1 / 1073741824, 2) || ' TiB'
WHEN $1 < 1048576 THEN ROUND($1 / 1024.0, 2) || ' MiB'
WHEN $1 < 1073741824 THEN ROUND($1 / 1048576.0, 2) || ' GiB'
ELSE ROUND($1 / 1073741824.0, 2) || ' TiB'
END;
$$ LANGUAGE SQL;
CREATE OR REPLACE FUNCTION simplify_hd(integer) RETURNS text AS $$
SELECT CASE
WHEN $1 < 1000 THEN $1 || ' GB'
ELSE round($1 / 1000, 2) || ' TB'
ELSE round($1 / 1000.0, 2) || ' TB'
END;
$$ LANGUAGE SQL;
......@@ -170,19 +170,21 @@ private static String createIdVerificationQuery(String table, String inep) {
* @param kernel OS kernel
* @param timestamp Timestamp
* @param project Project number
* @param mirrorsTimestamp Mirror's timestamp
* @return String
*/
private static String createInventoryQuery(String table, String inep,
String mac, String hdd1Model, String hdd1Size, String hdd1Used,
String hdd2Model, String hdd2Size, String hdd2Used, String hddAd,
String memSize, String model, String type, String distro,
String kernel, String timestamp, String project, String version) {
String kernel, String timestamp, String project, String version, String mirrorsTimestamp) {
StringBuilder sb = new StringBuilder("INSERT INTO ");
sb.append(table);
sb.append(" (project, inep, macaddr, os_type, os_distro, os_kernel,");
sb.append(" (mirrors_timestamp, project, inep, macaddr, version, os_type, os_distro, os_kernel,");
sb.append(" processor, memory, disk1_model, disk1_size, disk1_used,");
sb.append(" disk2_model, disk2_size, disk2_used, extra_hds) VALUES (");
sb.append(" disk2_models, disk2_size, disk2_used, extra_hds) VALUES (");
sb.append(createValueString(mirrorsTimestamp, "str", 1));
/* Project */
sb.append(createValueString(project, "int", 1));
......@@ -193,7 +195,7 @@ private static String createInventoryQuery(String table, String inep,
sb.append(createValueString(mac, "str", 1));
/* Version */
//sb.append(createValueString(version, "str", 1));
sb.append(createValueString(version, "str", 1));
/* SO Type */
sb.append(createValueString(type, "str", 1));
......@@ -1467,6 +1469,7 @@ throws Exception {
int intSize = -1;
int intUsed = -1;
String project = null;
String mirrorsTimestamp = null;
String[] hddModel = new String[0];
String[] hddSize = new String[0];
String[] hddUsed = new String[0];
......@@ -1491,6 +1494,8 @@ throws Exception {
String strVersion = "version";
String strICode = "inep code";
String strMac = "mac";
String strTs = "timestamp"
String strMirrorTs = "mirrors-timestamp"
String strProjSrc = "project source";
String strSrc = "source";
String strMod = "model";
......@@ -1511,6 +1516,7 @@ throws Exception {
NodeList inepTagList = getTagList(invXML, strInep, 1);
NodeList useTagList = getTagList(invXML, strUse, 1);
NodeList invTagList = getTagList(invXML, strInv, 1);
NodeList mirrosTsTagList = getTagList(invXML, strTs, 1);
NodeList projTagList = getTagList(invXML, strProj, 1);
/* Inventory children */
NodeList osTagList = getTagList(invXML, strOS, 1);
......@@ -1643,6 +1649,23 @@ throws Exception {
throw new Exception(getErrorMessage(3, strProj));
}
}
/* MIRROR TIMESTAMP */
Node mirrosTsTag = getChildTag(mirrosTsTagList, strMirrorTs, strTs);
/* Check <mirrors-timestamp> */
if (validateTagName(mirrosTsTag, strTs) == true) {
/* MIRROR TIMESTAMP */
mirrorsTimestamp = getAttributeValue(mirrosTsTag, "value");
if(! mirrorsTimestamp.equals("")){
/* Check MIRROR TIMESTAMP format*/
try {
SimpleDateFormat dt = new SimpleDateFormat("EEE MMM dd hh:mm:ss zzz yyyy");
Date date = dt.parse(date_s);
} catch (Exception e) {
throw new Exception(getErrorMessage(7, strMirrorTs));
}
}
}
/* INVENTORY */
......@@ -1882,18 +1905,18 @@ throws Exception {
if (quantity == 0) {
query = createInventoryQuery(INVTABLE, inep, macAddr, null, null,
null, null, null, null, hddAd, memSize, model, type,
distro, kernel, dateTimestamp, project, version);
distro, kernel, dateTimestamp, project, version, mirrorsTimestamp);
} else if (quantity == 1) {
query = createInventoryQuery(INVTABLE, inep, macAddr, hddModel[0],
hddSize[0], hddUsed[0], null, null, null, hddAd, memSize,
model, type, distro, kernel, dateTimestamp, project, version);
model, type, distro, kernel, dateTimestamp, project, version, mirrorsTimestamp);
} else {
quantity = quantity - 2;
hddAd = quantity.toString();
query = createInventoryQuery(INVTABLE, inep, macAddr, hddModel[0],
hddSize[0], hddUsed[0], hddModel[1], hddSize[1],
hddUsed[1], hddAd, memSize, model, type, distro,
kernel, dateTimestamp, project, version);
kernel, dateTimestamp, project, version, mirrorsTimestamp);
}
/* Return inventory queries */
......
......@@ -189,6 +189,9 @@ def collect():
tagProject = SubElement( mainTag, 'project')
tagProjectSource = SubElement(tagProject, 'source', {'type':'int', 'value':"0"})
tagMirrorsTimestamp = SubElement( mainTag, 'mirrors-timestamp')
tagTimestamp = SubElement(tagMirrorsTimestamp, 'timestamp', {'type':'string', 'value':""})
tagUse = SubElement(mainTag, 'use')
tagUseBandUsage = SubElement(tagUse, 'bandwidth-usage', {'type':'tree'})
......
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