Commit fead4d06 authored by Eduardo L. Buratti's avatar Eduardo L. Buratti
Browse files

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

parents a47838a4 ca7cc1ac
......@@ -156,17 +156,22 @@ else
SEED_MEC_HOME="/opt/seed_mec"
fi
AGENT_DIR="${SEED_MEC_HOME}/SEED2"
LASTEXEC="${AGENT_DIR}/tmp/lastExec.tmp"
LASTEXEC="${AGENT_DIR}/tmp/last-exec.tmp"
NETLASTEXEC="${AGENT_DIR}/tmp/net-last-exec.tmp"
LOGFILE=/tmp/collected-information.log
# Save stdout to file descriptor 3 and redirect all output to $LOGFILE
exec 3>&1 &> ${LOGFILE}
# Check if lastExec.tmp exist then save its content to prevent that
# Check if last-exec.tmp exist then save its content to prevent that
# agent send a inventory more than once per day
if test -f ${LASTEXEC}; then
LASTEXECBACKUP=$(cat ${LASTEXEC})
fi
if test -f ${NETLASTEXEC}; then
NETLASTEXECBACKUP=$(cat ${NETLASTEXEC})
fi
# Remove any previous installation of the agent
rm -rf "${AGENT_DIR}"
/usr/sbin/userdel -r seed_mec
......@@ -253,10 +258,14 @@ fi
# Export a variable to inform the agent that this is its first execution
export FIRST_EXECUTION=1
# Restore lastExec.tmp
# Restore last-exec.tmp
if ! test -z ${LASTEXECBACKUP};then
echo ${LASTEXECBACKUP} > ${LASTEXEC}
fi
# Restore net-last-exec.tmp
if ! test -z ${NETLASTEXECBACKUP};then
echo ${NETLASTEXECBACKUP} > ${NETLASTEXEC}
fi
# Run the agent and check if its execution went alright, exiting in case of
# error
......
/* OLTP operational database tables */
CREATE TABLE proinfo_inventory (
contact_date DATE DEFAULT CURRENT_DATE NOT NULL,
project INTEGER DEFAULT 0 NOT NULL,
inep CHARACTER VARYING(18) NOT NULL,
macaddr CHARACTER VARYING(18) NOT NULL,
os_type TEXT,
os_distro TEXT,
os_kernel TEXT,
processor TEXT,
memory INTEGER,
disk1_model TEXT,
disk1_size INTEGER,
disk1_used INTEGER,
disk2_model TEXT,
disk2_size INTEGER,
disk2_used INTEGER,
extra_hds SMALLINT DEFAULT 0 NOT NULL
contact_date DATE DEFAULT CURRENT_DATE NOT NULL,
project INTEGER DEFAULT 0 NOT NULL,
inep CHARACTER VARYING(18) NOT NULL,
macaddr CHARACTER VARYING(18) NOT NULL,
os_type TEXT,
os_distro TEXT,
os_kernel TEXT,
processor TEXT,
memory INTEGER,
disk1_model TEXT,
disk1_size INTEGER,
disk1_used INTEGER,
disk2_model TEXT,
disk2_size INTEGER,
disk2_used INTEGER,
extra_hds SMALLINT DEFAULT 0 NOT NULL,
mirror_timestamp TIMESTAMP,
agent_version CHARACTER VARYING(20) NOT NULL
);
CREATE TABLE proinfo_net_usage (
......@@ -30,25 +32,27 @@ CREATE TABLE proinfo_net_usage (
);
CREATE TABLE rejected_inventory (
id INTEGER,
sch_id INTEGER,
cit_id INTEGER,
contact_date DATE NOT NULL,
project INTEGER,
inep CHARACTER VARYING(18) NOT NULL,
macaddr TEXT NOT NULL,
os_type TEXT,
os_distro TEXT,
os_kernel TEXT,
processor TEXT,
memory INTEGER,
disk1_model TEXT,
disk1_size INTEGER,
disk1_used INTEGER,
disk2_model TEXT,
disk2_size INTEGER,
disk2_used INTEGER,
extra_hds SMALLINT
id INTEGER,
sch_id INTEGER,
cit_id INTEGER,
contact_date DATE NOT NULL,
project INTEGER,
inep CHARACTER VARYING(18) NOT NULL,
macaddr TEXT NOT NULL,
os_type TEXT,
os_distro TEXT,
os_kernel TEXT,
processor TEXT,
memory INTEGER,
disk1_model TEXT,
disk1_size INTEGER,
disk1_used INTEGER,
disk2_model TEXT,
disk2_size INTEGER,
disk2_used INTEGER,
extra_hds SMALLINT,
mirror_timestamp TIMESTAMP,
agent_version CHARACTER VARYING(20)
);
CREATE TABLE rejected_net_usage (
......
......@@ -16,7 +16,7 @@ CREATE TABLE dim_school (
inep CHARACTER VARYING(12) NOT NULL,
name CHARACTER VARYING(150) NOT NULL,
address CHARACTER VARYING(100),
cep CHARACTER VARYING(10)
cep CHARACTER VARYING(10),
CHECK (inep <> ''),
CHECK (name <> '')
);
......
-- fact tables
CREATE TABLE fact_contact (
id SERIAL PRIMARY KEY,
sch_id INTEGER NOT NULL REFERENCES dim_school,
cit_id INTEGER NOT NULL REFERENCES dim_city,
dat_id DATE NOT NULL REFERENCES dim_date,
macaddr MACADDR NOT NULL,
project project_enum DEFAULT 'proinfo' NOT NULL,
id SERIAL PRIMARY KEY,
sch_id INTEGER NOT NULL REFERENCES dim_school,
cit_id INTEGER NOT NULL REFERENCES dim_city,
dat_id DATE NOT NULL REFERENCES dim_date,
macaddr MACADDR NOT NULL,
project project_enum DEFAULT 'proinfo' NOT NULL,
mirror_timestamp TIMESTAMP,
agent_version CHARACTER VARYING(20) NOT NULL,
UNIQUE (sch_id, cit_id, dat_id, macaddr)
);
......
......@@ -49,6 +49,8 @@ BEGIN
i.disk2_size,
i.disk2_used,
i.extra_hds,
i.mirror_timestamp,
i.version,
'0'::boolean as valid
FROM
proinfo_inventory i
......@@ -180,6 +182,7 @@ BEGIN
disk1_model is NULL OR
disk1_size is NULL OR
disk1_used is NULL OR
version is NULL OR
NOT valid_macaddress(macaddr) OR
project < 0 OR project > 3 OR
inep is NULL);
......@@ -189,11 +192,11 @@ BEGIN
INSERT INTO rejected_inventory
(sch_id, cit_id, contact_date, project, inep, macaddr,
os_type, os_distro, os_kernel, processor, memory, disk1_model,
disk1_size, disk1_used, disk2_model, disk2_size, disk2_used)
disk1_size, disk1_used, disk2_model, disk2_size, disk2_used, mirror_timestamp, agent_version)
(SELECT
sch_id, cit_id, contact_date, project, inep, macaddr,
os_type, os_distro, os_kernel, processor, memory, disk1_model,
disk1_size, disk1_used, disk2_model, disk2_size, disk2_used
disk1_size, disk1_used, disk2_model, disk2_size, disk2_used, mirror_timestamp, agent_version
FROM
sa_inventory
WHERE
......
......@@ -15,10 +15,10 @@ BEGIN
INTO result from sa_inventory;
--
INSERT INTO fact_contact (sch_id, cit_id, dat_id, macaddr, project)
(SELECT sch_id, cit_id, contact_date, macaddr::macaddr, to_project_enum(project) FROM sa_inventory WHERE valid = '1')
INSERT INTO fact_contact (sch_id, cit_id, dat_id, macaddr, project, ts, 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 FROM fact_contact WHERE dat_id >= result.min_date AND dat_id <= result.max_date);
(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);
-- how many rows were inserted?
GET DIAGNOSTICS total_rows = ROW_COUNT;
......
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