store collected device information in database

This commit is contained in:
Andreas Steffen
2012-11-28 10:51:11 +01:00
parent 07f826af67
commit 7b6cc33eb2
6 changed files with 107 additions and 8 deletions
+23 -6
View File
@@ -795,19 +795,36 @@ METHOD(attest_db_t, list_devices, void,
{
enumerator_t *e;
chunk_t value;
int id, count = 0;
char *product;
time_t timestamp;
int id, last_id = 0, device_count = 0;
int count, count_update, count_blacklist;
e = this->db->query(this->db,
"SELECT id, value FROM devices", DB_INT, DB_BLOB);
"SELECT d.id, d.value, i.time, i.count, i.count_update, "
"i.count_blacklist, p.name FROM devices AS d "
"JOIN device_infos AS i ON d.id = i.device "
"JOIN products AS p ON p.id = i.product "
"ORDER BY d.value, i.time DESC",
DB_INT, DB_BLOB, DB_UINT, DB_INT, DB_INT, DB_INT, DB_TEXT);
if (e)
{
while (e->enumerate(e, &id, &value))
while (e->enumerate(e, &id, &value, &timestamp, &count, &count_update,
&count_blacklist, &product))
{
printf("%4d: %.*s\n", id, value.len, value.ptr);
count++;
if (id != last_id)
{
printf("%4d: %.*s\n", id, value.len, value.ptr);
device_count++;
last_id = id;
}
printf(" %T, %4d, %3d, %3d, '%s'\n", &timestamp, TRUE,
count, count_update, count_blacklist, product);
}
e->destroy(e);
printf("%d device%s found\n", count, (count == 1) ? "" : "s");
printf("%d device%s found\n", device_count,
(device_count == 1) ? "" : "s");
}
}
@@ -64,6 +64,9 @@ Usage:\n\
Show a list of software packages for a given product or\n\
its primary key as an optional selector.\n\
\n\
ipsec attest --devices\n\
Show a list of registered devices and associated collected information\n\
\n\
ipsec attest --add --file <path>|--dir <path>|--product <name>|--component <cfn>\n\
Add a file, directory, product or component entry\n\
Component <cfn> entries must be of the form <vendor_id>/<name>-<qualifier>\n\
@@ -131,7 +131,7 @@ CREATE TABLE device_infos (
product INTEGER DEFAULT 0,
count INTEGER DEFAULT 0,
count_update INTEGER DEFAULT 0,
count_remove INTEGER DEFAULT 0,
count_blacklist INTEGER DEFAULT 0,
flags INTEGER DEFAULT 0,
PRIMARY KEY (device, time)
);