summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Klinger2016-08-22 15:08:10 +0200
committerChristian Klinger2016-08-22 15:08:10 +0200
commiteeed8c7993f8e10de001cc18d8754559d516eacb (patch)
tree9e97748c3c5a03da319624f3b3be41928d9344d9
parentremoved the tooltip plugin from jquery-ui. (diff)
parent[dozmod] Update translations (diff)
downloadslx-admin-eeed8c7993f8e10de001cc18d8754559d516eacb.tar.gz
slx-admin-eeed8c7993f8e10de001cc18d8754559d516eacb.tar.xz
slx-admin-eeed8c7993f8e10de001cc18d8754559d516eacb.zip
Merge branch 'modularization' of git.openslx.org:openslx-ng/slx-admin into modularization
-rw-r--r--apis/cron.inc.php42
-rw-r--r--modules-available/dozmod/lang/de/template-tags.json4
-rw-r--r--modules-available/dozmod/lang/en/template-tags.json4
-rw-r--r--modules-available/dozmod/page.inc.php3
-rw-r--r--modules-available/dozmod/templates/blockstats-details.html2
-rw-r--r--modules-available/dozmod/templates/blockstats.html6
-rw-r--r--modules-available/eventlog/hooks/cron.inc.php5
-rw-r--r--modules-available/statistics/hooks/cron.inc.php18
-rw-r--r--modules-available/statistics/inc/parser.inc.php4
-rw-r--r--modules-available/statistics/page.inc.php28
-rw-r--r--modules-available/syslog/hooks/cron.inc.php5
11 files changed, 82 insertions, 39 deletions
diff --git a/apis/cron.inc.php b/apis/cron.inc.php
index 7171fb4e..8068eb2e 100644
--- a/apis/cron.inc.php
+++ b/apis/cron.inc.php
@@ -10,41 +10,29 @@
if (!isLocalExecution())
exit(0);
+// Hooks by other modules
+function handleModule($file)
+{
+ include_once $file;
+}
+
+foreach (glob('modules/*/hooks/cron.inc.php') as $file) {
+ preg_match('#^modules/([^/]+)/#', $file, $out);
+ $mod = Module::get($out[1]);
+ if ($mod === false)
+ continue;
+ $mod->activate();
+ handleModule($file);
+}
+
switch (mt_rand(1, 10)) {
-case 1:
- Database::exec("DELETE FROM clientlog WHERE (UNIX_TIMESTAMP() - dateline) > 86400 * 90");
- break;
-case 2:
- Database::exec("DELETE FROM eventlog WHERE (UNIX_TIMESTAMP() - dateline) > 86400 * 90");
- break;
case 3:
Database::exec("DELETE FROM property WHERE dateline <> 0 AND dateline < UNIX_TIMESTAMP()");
break;
case 4:
Database::exec("DELETE FROM callback WHERE (UNIX_TIMESTAMP() - dateline) > 86400");
break;
-case 5:
- Database::exec("DELETE FROM statistic WHERE (UNIX_TIMESTAMP() - dateline) > 86400 * 90");
- break;
-case 6:
- Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - lastseen) > 86400 * 365");
- break;
-}
-
-// TODO: Move to some module
-function logstats() {
- $NOW = time();
- $cutoff = $NOW - 86400 * 30;
- $online = $NOW - 610;
- $known = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $cutoff");
- $on = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online");
- $used = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online AND logintime <> 0");
- Database::exec("INSERT INTO statistic (dateline, typeid, clientip, username, data) VALUES (:now, '~stats', '', '', :vals)", array(
- 'now' => $NOW,
- 'vals' => $known['val'] . '#' . $on['val'] . '#' . $used['val'],
- ));
}
-logstats();
Trigger::checkCallbacks();
Trigger::ldadp();
diff --git a/modules-available/dozmod/lang/de/template-tags.json b/modules-available/dozmod/lang/de/template-tags.json
index fe558ed5..92977639 100644
--- a/modules-available/dozmod/lang/de/template-tags.json
+++ b/modules-available/dozmod/lang/de/template-tags.json
@@ -1,6 +1,7 @@
{
"lang_actionTarget": "Aktionsziel",
"lang_asteriskRequired": "Felder mit (*) sind erforderlich",
+ "lang_blockCount": "Anzahl Bl\u00f6cke",
"lang_canLogin": "Nutzer dieser Einrichtung k\u00f6nnen sich am Satelliten anmelden",
"lang_createTime": "Erstellt",
"lang_currentFilter": "Aktueller Filter",
@@ -21,8 +22,10 @@
"lang_emailNotifications": "EMail-Benachrichtigungen aktiviert",
"lang_error": "Fehler",
"lang_event": "Ereignis",
+ "lang_fileSize": "Dateigr\u00f6\u00dfe",
"lang_followingPlaceholdersUnused": "Folgende Platzhalter m\u00fcssen im Template verwendet werden",
"lang_hasNewer": "Neuere Version existiert",
+ "lang_hash": "Hash",
"lang_heading": "Zu l\u00f6schende VM-Versionen",
"lang_host": "Host",
"lang_image": "VM",
@@ -56,6 +59,7 @@
"lang_senderAddress": "Absenderadresse",
"lang_senderName": "Absender Anzeigename",
"lang_size": "Gr\u00f6\u00dfe",
+ "lang_spaceWastedDuplication": "Potentiell durch mehrfach vorkommende Bl\u00f6cke belegter Speicherplatz",
"lang_ssl": "SSL-Modus",
"lang_sslExplicit": "Explizites SSL (\"STARTTLS\")",
"lang_sslImplicit": "Implizites SSL",
diff --git a/modules-available/dozmod/lang/en/template-tags.json b/modules-available/dozmod/lang/en/template-tags.json
index 6a0434a3..396cb839 100644
--- a/modules-available/dozmod/lang/en/template-tags.json
+++ b/modules-available/dozmod/lang/en/template-tags.json
@@ -1,6 +1,7 @@
{
"lang_actionTarget": "Action target",
"lang_asteriskRequired": "Fields marked with (*) are required",
+ "lang_blockCount": "Block count",
"lang_canLogin": "Members of this organization can login",
"lang_createTime": "Created",
"lang_currentFilter": "Current filter",
@@ -21,8 +22,10 @@
"lang_emailNotifications": "E-Mail notifications enabled",
"lang_error": "Error",
"lang_event": "Event",
+ "lang_fileSize": "File size",
"lang_followingPlaceholdersUnused": "The following placeholders are not being used",
"lang_hasNewer": "Newer version exists",
+ "lang_hash": "Hash",
"lang_heading": "Images marked for deletion",
"lang_host": "Host",
"lang_image": "VM",
@@ -56,6 +59,7 @@
"lang_senderAddress": "Sender address",
"lang_senderName": "Sender's display name",
"lang_size": "Size",
+ "lang_spaceWastedDuplication": "Potentially wasted space by duplicate blocks",
"lang_ssl": "SSL mode",
"lang_sslExplicit": "Explicit SSL (\"STARTTLS\")",
"lang_sslImplicit": "Implicit SSL",
diff --git a/modules-available/dozmod/page.inc.php b/modules-available/dozmod/page.inc.php
index dfb49e0b..6c0c8a6b 100644
--- a/modules-available/dozmod/page.inc.php
+++ b/modules-available/dozmod/page.inc.php
@@ -126,11 +126,14 @@ class Page_DozMod extends Page
$res = Database::simpleQuery("SELECT blocksha1, blocksize, Count(*) AS blockcount FROM sat.imageblock"
. " GROUP BY blocksha1, blocksize HAVING blockcount > 1 ORDER BY blockcount DESC, blocksha1 ASC");
$data = array('hashes' => array());
+ $spaceWasted = 0;
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
$row['hash_hex'] = bin2hex($row['blocksha1']);
$row['blocksize_s'] = Util::readableFileSize($row['blocksize']);
$data['hashes'][] = $row;
+ $spaceWasted += $row['blocksize'] * ($row['blockcount'] - 1);
}
+ $data['spacewasted'] = Util::readableFileSize($spaceWasted);
Render::addTemplate('blockstats', $data);
}
diff --git a/modules-available/dozmod/templates/blockstats-details.html b/modules-available/dozmod/templates/blockstats-details.html
index 68e03fbc..e9466d94 100644
--- a/modules-available/dozmod/templates/blockstats-details.html
+++ b/modules-available/dozmod/templates/blockstats-details.html
@@ -1,6 +1,6 @@
<table class="table table-bordered table-striped">
<tr>
- <th>{{lang_imageName}}</th>
+ <th>{{lang_image}}</th>
<th>{{lang_createTime}}</th>
<th>{{lang_fileSize}}</th>
<th>{{lang_blockCount}}</th>
diff --git a/modules-available/dozmod/templates/blockstats.html b/modules-available/dozmod/templates/blockstats.html
index 82a66146..cba3b476 100644
--- a/modules-available/dozmod/templates/blockstats.html
+++ b/modules-available/dozmod/templates/blockstats.html
@@ -1,8 +1,12 @@
+<div class="alert alert-info">
+ {{lang_spaceWastedDuplication}}: {{spacewasted}}
+</div>
+
<table class="table table-condensed table-striped" style="width: auto">
<tr>
<th>{{lang_hash}}</th>
<th>{{lang_size}}</th>
- <th>{{lang_count}}</th>
+ <th>{{lang_blockCount}}</th>
</tr>
{{#hashes}}
<tr>
diff --git a/modules-available/eventlog/hooks/cron.inc.php b/modules-available/eventlog/hooks/cron.inc.php
new file mode 100644
index 00000000..027acf87
--- /dev/null
+++ b/modules-available/eventlog/hooks/cron.inc.php
@@ -0,0 +1,5 @@
+<?php
+
+if (mt_rand(1, 10) === 1) {
+ Database::exec("DELETE FROM eventlog WHERE (UNIX_TIMESTAMP() - dateline) > 86400 * 190");
+} \ No newline at end of file
diff --git a/modules-available/statistics/hooks/cron.inc.php b/modules-available/statistics/hooks/cron.inc.php
new file mode 100644
index 00000000..94c65248
--- /dev/null
+++ b/modules-available/statistics/hooks/cron.inc.php
@@ -0,0 +1,18 @@
+<?php
+
+Database::exec("DELETE FROM statistic WHERE (UNIX_TIMESTAMP() - dateline) > 86400 * 190");
+Database::exec("DELETE FROM machine WHERE (UNIX_TIMESTAMP() - lastseen) > 86400 * 365");
+
+function logstats() {
+ $NOW = time();
+ $cutoff = $NOW - 86400 * 30;
+ $online = $NOW - 610;
+ $known = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $cutoff");
+ $on = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online");
+ $used = Database::queryFirst("SELECT Count(*) AS val FROM machine WHERE lastseen > $online AND logintime <> 0");
+ Database::exec("INSERT INTO statistic (dateline, typeid, clientip, username, data) VALUES (:now, '~stats', '', '', :vals)", array(
+ 'now' => $NOW,
+ 'vals' => $known['val'] . '#' . $on['val'] . '#' . $used['val'],
+ ));
+}
+logstats();
diff --git a/modules-available/statistics/inc/parser.inc.php b/modules-available/statistics/inc/parser.inc.php
index 1ecfbbf8..07bed8e5 100644
--- a/modules-available/statistics/inc/parser.inc.php
+++ b/modules-available/statistics/inc/parser.inc.php
@@ -103,6 +103,8 @@ class Parser {
$i = 0;
foreach ($lines as $line) {
if (preg_match('/^Disk (\S+):.* (\d+) bytes/i', $line, $out)) {
+ if ($out[2] < 10000) // sometimes vmware reports lots of 512byte disks
+ continue;
// disk total size and name
unset($hdd);
$unit = 0;
@@ -144,7 +146,7 @@ class Parser {
foreach ($hdds as &$hdd) {
$hdd['used'] = round($hdd['used'] / 1024);
$free = $hdd['size'] - $hdd['used'];
- if ($free > 5) {
+ if ($free > 5 || ($free / $hdd['size']) > 0.1) {
$hdd['partitions'][] = array(
'id' => 'free-id-' . $i,
'name' => Dictionary::translate('unused'),
diff --git a/modules-available/statistics/page.inc.php b/modules-available/statistics/page.inc.php
index ab0afcea..0639d784 100644
--- a/modules-available/statistics/page.inc.php
+++ b/modules-available/statistics/page.inc.php
@@ -136,6 +136,8 @@ class Page_Statistics extends Page
Message::addSuccess('notes-saved');
Util::redirect('?do=Statistics&uuid=' . $uuid);
}
+ // Fix online state of machines that crashed -- TODO: Make cronjob for this
+ Database::exec("UPDATE machine SET lastboot = 0 WHERE lastseen < UNIX_TIMESTAMP() - 610");
}
protected function doRender()
@@ -253,10 +255,9 @@ class Page_Statistics extends Page
{
$filterSet->makeFragments($where, $join, $sort, $args);
- $online = time() - 610;
$known = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE ($where)", $args);
- $on = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE lastseen > $online AND ($where)", $args);
- $used = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE lastseen > $online AND logintime <> 0 AND ($where)", $args);
+ $on = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE lastboot <> 0 AND ($where)", $args);
+ $used = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE lastboot <> 0 AND logintime <> 0 AND ($where)", $args);
$hdd = Database::queryFirst("SELECT Count(*) AS val FROM machine $join WHERE badsectors >= 10 AND ($where)", $args);
if ($on['val'] != 0) {
$usedpercent = round($used['val'] / $on['val'] * 100);
@@ -500,7 +501,7 @@ class Page_Statistics extends Page
$rows = array();
$NOW = time();
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
- if ($NOW - $row['lastseen'] > 610) {
+ if ($row['lastboot'] == 0) {
$row['state_off'] = true;
} elseif ($row['logintime'] == 0) {
$row['state_idle'] = true;
@@ -620,9 +621,14 @@ class Page_Statistics extends Page
$client = Database::queryFirst('SELECT machineuuid, locationid, macaddr, clientip, firstseen, lastseen, logintime, lastboot,'
. ' mbram, kvmstate, cpumodel, id44mb, data, hostname, notes FROM machine WHERE machineuuid = :uuid',
array('uuid' => $uuid));
+ // Hack: Get raw collected data
+ if (Request::get('raw', false)) {
+ Header('Content-Type: text/plain; charset=utf-8');
+ die($client['data']);
+ }
// Mangle fields
$NOW = time();
- if ($NOW - $client['lastseen'] > 610) {
+ if ($client['lastboot'] == 0) {
$client['state_off'] = true;
} elseif ($client['logintime'] == 0) {
$client['state_idle'] = true;
@@ -632,10 +638,14 @@ class Page_Statistics extends Page
}
$client['firstseen_s'] = date('d.m.Y H:i', $client['firstseen']);
$client['lastseen_s'] = date('d.m.Y H:i', $client['lastseen']);
- $uptime = $NOW - $client['lastboot'];
- $client['lastboot_s'] = date('d.m.Y H:i', $client['lastboot']);
- if (!isset($client['state_off']) || !$client['state_off']) {
- $client['lastboot_s'] .= ' (Up ' . floor($uptime / 86400) . 'd ' . gmdate('H:i', $uptime) . ')';
+ if ($client['lastboot'] == 0) {
+ $client['lastboot_s'] = '-';
+ } else {
+ $uptime = $NOW - $client['lastboot'];
+ $client['lastboot_s'] = date('d.m.Y H:i', $client['lastboot']);
+ if (!isset($client['state_off']) || !$client['state_off']) {
+ $client['lastboot_s'] .= ' (Up ' . floor($uptime / 86400) . 'd ' . gmdate('H:i', $uptime) . ')';
+ }
}
$client['logintime_s'] = date('d.m.Y H:i', $client['logintime']);
$client['gbram'] = round(round($client['mbram'] / 500) / 2, 1);
diff --git a/modules-available/syslog/hooks/cron.inc.php b/modules-available/syslog/hooks/cron.inc.php
new file mode 100644
index 00000000..c796675f
--- /dev/null
+++ b/modules-available/syslog/hooks/cron.inc.php
@@ -0,0 +1,5 @@
+<?php
+
+if (mt_rand(1, 10) === 1) {
+ Database::exec("DELETE FROM clientlog WHERE (UNIX_TIMESTAMP() - dateline) > 86400 * 190");
+} \ No newline at end of file