From 0746d3c815fa5dffe8ed766043cb996e5e2ce581 Mon Sep 17 00:00:00 2001
From: Jannik Schönartz
Date: Mon, 20 Nov 2017 14:30:31 +0100
Subject: [statistics&syslog] Changed ip to machine-uuid for filtering. Fixed
a bug where the client-log was losing the specific client when a filter was
added.
---
modules-available/statistics/page.inc.php | 2 +-
modules-available/statistics/templates/syslog.html | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
(limited to 'modules-available/statistics')
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index 479f3089..f8b40405 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -920,7 +920,7 @@ class Page_Statistics extends Page
}
}
Render::addTemplate('syslog', array(
- 'clientip' => $client['clientip'],
+ 'machineuuid' => $client['machineuuid'],
'list' => $log,
));
}
diff --git a/modules-available/statistics/templates/syslog.html b/modules-available/statistics/templates/syslog.html
index c82cb8ac..968d32ab 100644
--- a/modules-available/statistics/templates/syslog.html
+++ b/modules-available/statistics/templates/syslog.html
@@ -20,7 +20,7 @@
{{/list}}
-
+
--
cgit v1.2.3-55-g7522
From ec10851584b4be86add55b571e56c79afe97975f Mon Sep 17 00:00:00 2001
From: Jannik Schönartz
Date: Thu, 23 Nov 2017 13:00:55 +0100
Subject: [statistics] Filter 'state' was missing in the client statistics
filter
---
modules-available/statistics/page.inc.php | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
(limited to 'modules-available/statistics')
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index f8b40405..575c5c19 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -106,6 +106,12 @@ class Page_Statistics extends Page
'op' => Page_Statistics::$op_nominal,
'type' => 'string',
'column' => true
+ ],
+ 'state' => [
+ 'op' => Page_Statistics::$op_nominal,
+ 'type' => 'enum',
+ 'column' => true,
+ 'values' => ['occupied', 'on']
]
];
if (Module::isAvailable('locations')) {
@@ -211,7 +217,6 @@ class Page_Statistics extends Page
$sortColumn = Request::any('sortColumn');
$sortDirection = Request::any('sortDirection');
$filters = Filter::parseQuery($this->query);
-
$filterSet = new FilterSet($filters);
$filterSet->setSort($sortColumn, $sortDirection);
--
cgit v1.2.3-55-g7522
From 116a65eaeda0b3f20d3dd5c7b7aa80607b855525 Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Fri, 24 Nov 2017 12:58:35 +0100
Subject: [statistics] Warn about suspicious hardware changes (RAM, CPU)
If the CPU model changes or the amount of RAM decreases we issue
a warning message to the server log, since at least in the
RAM case it might not have been an authorized access.... :/
---
modules-available/statistics/api.inc.php | 60 ++++++++++++++++++++++----------
1 file changed, 42 insertions(+), 18 deletions(-)
(limited to 'modules-available/statistics')
diff --git a/modules-available/statistics/api.inc.php b/modules-available/statistics/api.inc.php
index c395220a..022277fe 100644
--- a/modules-available/statistics/api.inc.php
+++ b/modules-available/statistics/api.inc.php
@@ -34,7 +34,7 @@ if ($type{0} === '~') {
// External mode of operation?
$mode = Request::post('mode', false, 'string');
$NOW = time();
- $old = Database::queryFirst('SELECT clientip, logintime, lastseen, lastboot FROM machine WHERE machineuuid = :uuid', array('uuid' => $uuid));
+ $old = Database::queryFirst('SELECT clientip, logintime, lastseen, lastboot, mbram, cpumodel FROM machine WHERE machineuuid = :uuid', array('uuid' => $uuid));
if ($old !== false) {
settype($old['logintime'], 'integer');
settype($old['lastseen'], 'integer');
@@ -93,6 +93,23 @@ if ($type{0} === '~') {
}
}
}
+ $new = array(
+ 'uuid' => $uuid,
+ 'macaddr' => $macaddr,
+ 'clientip' => $ip,
+ 'firstseen' => $NOW,
+ 'lastseen' => $NOW,
+ 'lastboot' => $NOW - $uptime,
+ 'realcores' => $realcores,
+ 'mbram' => $mbram,
+ 'kvmstate' => $kvmstate,
+ 'cpumodel' => $cpumodel,
+ 'systemmodel'=> $systemmodel,
+ 'id44mb' => $id44mb,
+ 'badsectors' => $badsectors,
+ 'data' => $data,
+ 'hostname' => $hostname,
+ );
// Create/update machine entry
Database::exec('INSERT INTO machine '
. '(machineuuid, macaddr, clientip, firstseen, lastseen, logintime, position, lastboot, realcores, mbram,'
@@ -113,29 +130,18 @@ if ($type{0} === '~') {
. ' id44mb = VALUES(id44mb),'
. ' badsectors = VALUES(badsectors),'
. ' data = VALUES(data),'
- . " hostname = If(VALUES(hostname) = '', hostname, VALUES(hostname))", array(
- 'uuid' => $uuid,
- 'macaddr' => $macaddr,
- 'clientip' => $ip,
- 'firstseen' => $NOW,
- 'lastseen' => $NOW,
- 'lastboot' => $NOW - $uptime,
- 'realcores' => $realcores,
- 'mbram' => $mbram,
- 'kvmstate' => $kvmstate,
- 'cpumodel' => $cpumodel,
- 'systemmodel'=> $systemmodel,
- 'id44mb' => $id44mb,
- 'badsectors' => $badsectors,
- 'data' => $data,
- 'hostname' => $hostname,
- ));
+ . " hostname = If(VALUES(hostname) = '', hostname, VALUES(hostname))", $new);
if (($old === false || $old['clientip'] !== $ip) && Module::isAvailable('locations')) {
// New, or ip changed (dynamic pool?), update subnetlicationid
Location::updateMapIpToLocation($uuid, $ip);
}
+ // Check for suspicious hardware changes
+ if ($old !== false) {
+ checkHardwareChange($old, $new);
+ }
+
// Write statistics data
} else if ($type === '~runstate') {
@@ -336,4 +342,22 @@ if ($type{0} === '.') {
}
}
+/**
+ * @param array $old row from DB with client's old data
+ * @param array $new new data to be written
+ */
+function checkHardwareChange($old, $new)
+{
+ if ($new['mbram'] !== 0) {
+ if ($new['mbram'] + 1000 < $old['mbram']) {
+ $ram1 = round($old['mbram'] / 512) / 2;
+ $ram2 = round($new['mbram'] / 512) / 2;
+ EventLog::warning('Client ' . $new['uuid'] . ' (' . $new['clientip'] . "): RAM decreased from {$ram1}GB to {$ram2}GB");
+ }
+ if (!empty($old['cpumodel']) && !empty($new['cpumodel']) && $new['cpumodel'] !== $old['cpumodel']) {
+ EventLog::warning('Client ' . $new['uuid'] . ' (' . $new['clientip'] . "): CPU changed from '{$old['cpumodel']}' to '{$new['cpumodel']}'");
+ }
+ }
+}
+
echo "OK.\n";
--
cgit v1.2.3-55-g7522
From 23d8c6fc0c3b031aa081ee1a245f9b0792514fd3 Mon Sep 17 00:00:00 2001
From: Simon Rettberg
Date: Tue, 28 Nov 2017 16:41:33 +0100
Subject: [statistics] Introduce state column to get rid of complicated state
determination
This also adds support for the STANDBY state
---
.../locationinfo/inc/infopanel.inc.php | 4 +-
.../locationinfo/inc/locationinfo.inc.php | 12 +-
.../locationinfo/templates/frontend-default.html | 4 +-
.../rebootcontrol/inc/rebootqueries.inc.php | 10 +-
.../runmode/templates/machine-selector.html | 15 +-
modules-available/statistics/api.inc.php | 190 +++++++++++++++------
modules-available/statistics/hooks/cron.inc.php | 18 +-
modules-available/statistics/inc/filter.inc.php | 20 +--
modules-available/statistics/install.inc.php | 20 ++-
modules-available/statistics/page.inc.php | 30 +---
.../statistics/templates/clientlist.html | 17 +-
.../statistics/templates/machine-main.html | 15 +-
12 files changed, 226 insertions(+), 129 deletions(-)
(limited to 'modules-available/statistics')
diff --git a/modules-available/locationinfo/inc/infopanel.inc.php b/modules-available/locationinfo/inc/infopanel.inc.php
index 66ee0ae7..c612e518 100644
--- a/modules-available/locationinfo/inc/infopanel.inc.php
+++ b/modules-available/locationinfo/inc/infopanel.inc.php
@@ -81,7 +81,7 @@ class InfoPanel
}
$positionCol = $withPosition ? 'm.position,' : '';
- $query = "SELECT m.locationid, m.machineuuid, $positionCol m.logintime, m.lastseen, m.lastboot FROM machine m
+ $query = "SELECT m.locationid, m.machineuuid, $positionCol m.logintime, m.lastseen, m.lastboot, m.state FROM machine m
WHERE m.locationid IN (:idlist)";
$dbquery = Database::simpleQuery($query, array('idlist' => $idList));
@@ -107,7 +107,7 @@ class InfoPanel
}
}
$pc['pcState'] = LocationInfo::getPcState($row);
- //$pc['pcState'] = ['BROKEN', 'OFF', 'IDLE', 'OCCUPIED'][mt_rand(0,3)]; // XXX
+ //$pc['pcState'] = ['BROKEN', 'OFFLINE', 'IDLE', 'OCCUPIED', 'STANDBY'][mt_rand(0,4)]; // XXX
// Add the array to the machines list.
$array[$row['locationid']]['machines'][] = $pc;
diff --git a/modules-available/locationinfo/inc/locationinfo.inc.php b/modules-available/locationinfo/inc/locationinfo.inc.php
index 830fb050..933eaf4d 100644
--- a/modules-available/locationinfo/inc/locationinfo.inc.php
+++ b/modules-available/locationinfo/inc/locationinfo.inc.php
@@ -6,7 +6,7 @@ class LocationInfo
/**
* Gets the pc data and returns it's state.
*
- * @param array $pc The pc data from the db. Array('logintime' =>, 'lastseen' =>, 'lastboot' =>)
+ * @param array $pc The pc data from the db. Array('state' => xx, 'lastseen' => xxx)
* @return int pc state
*/
public static function getPcState($pc)
@@ -16,16 +16,10 @@ class LocationInfo
$lastboot = (int)$pc['lastboot'];
$NOW = time();
- if ($NOW - $lastseen > 14 * 86400) {
+ if ($pc['state'] === 'OFFLINE' && $NOW - $lastseen > 21 * 86400) {
return "BROKEN";
- } elseif (($NOW - $lastseen > 610) || $lastboot === 0) {
- return "OFF";
- } elseif ($logintime === 0) {
- return "IDLE";
- } elseif ($logintime > 0) {
- return "OCCUPIED";
}
- return -1;
+ return $pc['state'];
}
/**
diff --git a/modules-available/locationinfo/templates/frontend-default.html b/modules-available/locationinfo/templates/frontend-default.html
index fc9c3eac..e199fc36 100755
--- a/modules-available/locationinfo/templates/frontend-default.html
+++ b/modules-available/locationinfo/templates/frontend-default.html
@@ -29,7 +29,7 @@ optional:
-