summaryrefslogtreecommitdiffstats
path: root/apis
diff options
context:
space:
mode:
authorSimon Rettberg2015-12-22 19:57:51 +0100
committerSimon Rettberg2015-12-22 19:57:51 +0100
commit061f61a59c3ef7b9209f7318cd060484779b9b8c (patch)
treeb35d853a6d0682c7a807966736729b0bc51a6967 /apis
parent[statistics] Add table definition, bump db version (diff)
downloadslx-admin-061f61a59c3ef7b9209f7318cd060484779b9b8c.tar.gz
slx-admin-061f61a59c3ef7b9209f7318cd060484779b9b8c.tar.xz
slx-admin-061f61a59c3ef7b9209f7318cd060484779b9b8c.zip
[clientlog] Fix bootup db insert query
Diffstat (limited to 'apis')
-rw-r--r--apis/clientlog.inc.php12
1 files changed, 7 insertions, 5 deletions
diff --git a/apis/clientlog.inc.php b/apis/clientlog.inc.php
index 842e3469..61200875 100644
--- a/apis/clientlog.inc.php
+++ b/apis/clientlog.inc.php
@@ -32,6 +32,10 @@ if ($type{0} === '~') {
}
$NOW = time();
$old = Database::queryFirst('SELECT logintime, lastseen FROM machine WHERE machineuuid = :uuid', array('uuid' => $uuid));
+ if ($old !== false) {
+ settype($old['logintime'], 'integer');
+ settype($old['lastseen'], 'integer');
+ }
// Handle event type
if ($type === '~poweron') {
// Poweron & hw stats
@@ -58,7 +62,7 @@ if ($type{0} === '~') {
$data = Request::post('data', '', 'string');
if ($uptime < 120) {
// See if we have a lingering session, create statistic entry if so
- if ($old !== false && (int)$old['logintime'] !== 0) {
+ if ($old !== false && $old['logintime'] !== 0) {
$sessionLength = $old['lastseen'] - $old['logintime'];
if ($sessionLength > 0) {
$start = $old['logintime'];
@@ -90,7 +94,7 @@ if ($type{0} === '~') {
// Create/update machine entry
Database::exec('INSERT INTO machine '
. '(machineuuid, macaddr, clientip, firstseen, lastseen, logintime, position, lastboot, realcores, mbram,'
- . ' kvmstate, cpumodel, id44mb, badsectors, data, hostname) VALUES '
+ . ' kvmstate, cpumodel, systemmodel, id44mb, badsectors, data, hostname) VALUES '
. "(:uuid, :macaddr, :clientip, :firstseen, :lastseen, 0, '', :lastboot, :realcores, :mbram,"
. ' :kvmstate, :cpumodel, :systemmodel, :id44mb, :badsectors, :data, :hostname)'
. ' ON DUPLICATE KEY UPDATE'
@@ -130,9 +134,8 @@ if ($type{0} === '~') {
// Usage (occupied/free)
$sessionLength = 0;
$used = Request::post('used', 0, 'integer');
+ error_log("uuid=$uuid old=$old used=$used");
if ($old === false) die("Unknown machine.\n");
- settype($old['logintime'], 'integer');
- settype($old['lastseen'], 'integer');
// Figure out what's happening
if ($used === 0) {
// Is not in use
@@ -174,7 +177,6 @@ if ($type{0} === '~') {
));
}
} elseif ($type === '~poweroff') {
- $old = Database::queryFirst('SELECT logintime, lastseen FROM machine WHERE machineuuid = :uuid', array('uuid' => $uuid));
if ($old !== false && (int)$old['logintime'] !== 0) {
$sessionLength = $old['lastseen'] - $old['logintime'];
if ($sessionLength > 0) {