show/activitylog: first simple visualization

This commit is contained in:
Thomas Gelf 2015-06-01 14:33:07 +02:00
parent 75fb3c2226
commit 8037f19e13
7 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,14 @@
<?php
use Icinga\Module\Director\ActionController;
class Director_ShowController extends ActionController
{
public function activitylogAction()
{
if ($id = $this->params->get('id')) {
$this->view->entry = $this->db()->fetchActivityLogEntry($id);
$this->view->title = $this->translate('Activity');
}
}
}

View File

@ -0,0 +1,24 @@
<h2><?= sprintf(
'%s "%s" has been created',
ucfirst(preg_replace('/^icinga_/', '', $entry->object_type)),
$entry->object_name
) ?></h2>
<h3><?= $this->translate('Properties') ?></h3>
<table class="log-properties">
<?php
$new = json_decode($entry->new_properties);
foreach ($new as $key => $value) {
if ($key === 'id') continue;
if ($value === null) continue;
echo ' <tr><th>' . $this->escape($key) . '</th><td>';
echo $this->escape($value);
echo "</td></tr>\n";
}
?>
</table>

View File

@ -0,0 +1,8 @@
<h3><?= sprintf(
'%s "%s" has been modified',
ucfirst(preg_replace('/^icinga_/', '', $entry->object_type)),
$entry->object_name
) ?></h3>
<pre>
<?= $this->escape(print_r($entry, 1)) ?>
</pre>

View File

@ -0,0 +1,34 @@
<h2><?= sprintf(
'%s "%s" has been modified',
ucfirst(preg_replace('/^icinga_/', '', $entry->object_type)),
$entry->object_name
) ?></h2>
<h3><?= $this->translate('Properties') ?></h3>
<table class="log-properties">
<?php
$old = json_decode($entry->old_properties);
$new = json_decode($entry->new_properties);
foreach ($old as $key => $value) {
if ($key === 'id') continue;
$modified = array_key_exists($key, $new);
if ($value === null && ! $modified) continue;
echo ' <tr><th>' . $this->escape($key) . '</th><td>';
if ($modified) {
printf(
'<span class="old">%s</span> <span class="new">%s</span>',
$this->escape($value),
$this->escape($new->$key)
);
} else {
echo $this->escape($value);
}
echo "</td></tr>\n";
}
?>
</table>

View File

@ -0,0 +1,23 @@
<div class="controls">
<?= $this->tabs ?>
</div>
<div class="content">
<?php
switch ($entry->action_name) {
case 'create':
echo $this->render('show/activitylog-create.phtml');
break;
case 'modify':
echo $this->render('show/activitylog-modify.phtml');
break;
case 'delete':
echo $this->render('show/activitylog-delete.phtml');
break;
default:
echo 'Invalid action';
}
?>
</div>

View File

@ -13,6 +13,13 @@ class Db extends DbConnection
return $this->getDbAdapter();
}
public function fetchActivityLogEntry($id)
{
$sql = 'SELECT * FROM director_activity_log WHERE id = ' . (int) $id;
return $this->db()->fetchRow($sql);
}
public function getLastActivityChecksum()
{
$select = "SELECT checksum FROM (SELECT * FROM (SELECT 1 AS pos, LOWER(HEX(checksum)) AS checksum FROM director_activity_log ORDER BY change_time DESC LIMIT 1) a UNION SELECT 2 AS pos, '' AS checksum) u ORDER BY pos LIMIT 1";

View File

@ -28,3 +28,31 @@ table.simple {
text-align: right;
}
}
table.log-properties {
width: 100%;
th {
width: 12em;
text-align: left;
}
td {
font-family: monospace;
}
span {
padding: 0.3em 1em;
}
.old {
background-color: @colorCriticalHandled;
color: white;
text-decoration: stroken;
}
.new {
background-color: @colorOk;
color: white;
}
}