data/vars: add a new table
Also cleaned up some obsolete code fixes #1016
This commit is contained in:
parent
acddf07849
commit
e200221529
|
@ -6,6 +6,7 @@ use Icinga\Module\Director\Forms\DirectorDatalistEntryForm;
|
||||||
use Icinga\Module\Director\Forms\DirectorDatalistForm;
|
use Icinga\Module\Director\Forms\DirectorDatalistForm;
|
||||||
use Icinga\Module\Director\Objects\DirectorDatalist;
|
use Icinga\Module\Director\Objects\DirectorDatalist;
|
||||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||||
|
use Icinga\Module\Director\Web\Table\CustomvarTable;
|
||||||
use Icinga\Module\Director\Web\Table\DatafieldTable;
|
use Icinga\Module\Director\Web\Table\DatafieldTable;
|
||||||
use Icinga\Module\Director\Web\Table\DatalistEntryTable;
|
use Icinga\Module\Director\Web\Table\DatalistEntryTable;
|
||||||
use Icinga\Module\Director\Web\Table\DatalistTable;
|
use Icinga\Module\Director\Web\Table\DatalistTable;
|
||||||
|
@ -28,8 +29,7 @@ class DataController extends ActionController
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->tabs(new DataTabs())->activate('datalist');
|
$this->tabs(new DataTabs())->activate('datalist');
|
||||||
$table = new DatalistTable($this->db());
|
(new DatalistTable($this->db()))->renderTo($this);
|
||||||
$table->renderTo($this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listAction()
|
public function listAction()
|
||||||
|
@ -72,43 +72,6 @@ class DataController extends ActionController
|
||||||
$form->handleRequest();
|
$form->handleRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function indexAction()
|
|
||||||
{
|
|
||||||
$edit = false;
|
|
||||||
|
|
||||||
if ($id = $this->params->get('id')) {
|
|
||||||
$edit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($edit) {
|
|
||||||
$this->addTitle($title = $this->translate('Edit list'));
|
|
||||||
|
|
||||||
$this->getTabs()->add('editlist', array(
|
|
||||||
'url' => 'director/datalist/edit' . '?id=' . $id,
|
|
||||||
'label' => $title,
|
|
||||||
))->add('entries', array(
|
|
||||||
'url' => 'director/data/listentry' . '?list_id=' . $id,
|
|
||||||
'label' => $this->translate('List entries'),
|
|
||||||
))->activate('editlist');
|
|
||||||
} else {
|
|
||||||
$this->addTitle($title = $this->translate('Add list'));
|
|
||||||
$this->getTabs()->add('addlist', array(
|
|
||||||
'url' => 'director/datalist/add',
|
|
||||||
'label' => $title,
|
|
||||||
))->activate('addlist');
|
|
||||||
}
|
|
||||||
|
|
||||||
$form = DirectorDatalistForm::load()
|
|
||||||
->setSuccessUrl('director/data/lists')
|
|
||||||
->setDb($this->db());
|
|
||||||
|
|
||||||
if ($edit) {
|
|
||||||
$form->loadObject($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
$form->handleRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function fieldsAction()
|
public function fieldsAction()
|
||||||
{
|
{
|
||||||
$this->tabs(new DataTabs())->activate('datafield');
|
$this->tabs(new DataTabs())->activate('datafield');
|
||||||
|
@ -120,7 +83,14 @@ class DataController extends ActionController
|
||||||
['class' => 'icon-plus']
|
['class' => 'icon-plus']
|
||||||
));
|
));
|
||||||
|
|
||||||
$this->content()->add(new DatafieldTable($this->db()));
|
(new DatafieldTable($this->db()))->renderTo($this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function varsAction()
|
||||||
|
{
|
||||||
|
$this->tabs(new DataTabs())->activate('customvars');
|
||||||
|
$this->addTitle($this->translate('Custom Vars - Overview'));
|
||||||
|
(new CustomvarTable($this->db()))->renderTo($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listentryAction()
|
public function listentryAction()
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Dashboard\Dashlet;
|
||||||
|
|
||||||
|
class CustomvarDashlet extends Dashlet
|
||||||
|
{
|
||||||
|
protected $icon = 'keyboard';
|
||||||
|
|
||||||
|
public function getTitle()
|
||||||
|
{
|
||||||
|
return $this->translate('CustomVar Overview');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSummary()
|
||||||
|
{
|
||||||
|
return $this->translate(
|
||||||
|
'Get an overview of used CustomVars and their variants'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrl()
|
||||||
|
{
|
||||||
|
return 'director/data/vars';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function listRequiredPermissions()
|
||||||
|
{
|
||||||
|
return array('director/admin');
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,103 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Icinga\Module\Director\Web\Table;
|
||||||
|
|
||||||
|
use ipl\Web\Table\ZfQueryBasedTable;
|
||||||
|
use Zend_Db_Adapter_Abstract as ZfDbAdapter;
|
||||||
|
use Zend_Db_Select as ZfDbSelect;
|
||||||
|
|
||||||
|
class CustomvarTable extends ZfQueryBasedTable
|
||||||
|
{
|
||||||
|
protected $searchColumns = array(
|
||||||
|
'varname',
|
||||||
|
);
|
||||||
|
|
||||||
|
public function renderRow($row)
|
||||||
|
{
|
||||||
|
$tr = $this::tr(
|
||||||
|
/* TODO: not yet
|
||||||
|
$this::td(Link::create(
|
||||||
|
$row->varname,
|
||||||
|
'director/customvar',
|
||||||
|
['name' => $row->varname]
|
||||||
|
))
|
||||||
|
*/
|
||||||
|
$this::td($row->varname)
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($this->getObjectTypes() as $type) {
|
||||||
|
$tr->add($this::td(sprintf(
|
||||||
|
$this->translate('%d (variants: %d)'),
|
||||||
|
$row->{"cnt_$type"},
|
||||||
|
$row->{"distinct_$type"}
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $tr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColumnsToBeRendered()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
$this->translate('Variable name'),
|
||||||
|
$this->translate('Distinct Commands'),
|
||||||
|
$this->translate('Hosts'),
|
||||||
|
$this->translate('Services'),
|
||||||
|
$this->translate('Service Sets'),
|
||||||
|
$this->translate('Notifications'),
|
||||||
|
$this->translate('Users'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function getObjectTypes()
|
||||||
|
{
|
||||||
|
return ['command', 'host', 'service', 'service_set', 'notification', 'user'];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function prepareQuery()
|
||||||
|
{
|
||||||
|
$db = $this->db();
|
||||||
|
$varsColumns = ['varname' => 'v.varname'];
|
||||||
|
$varsTypes = $this->getObjectTypes();
|
||||||
|
foreach ($varsTypes as $type) {
|
||||||
|
$varsColumns["cnt_$type"] = '(0)';
|
||||||
|
$varsColumns["distinct_$type"] = '(0)';
|
||||||
|
}
|
||||||
|
$varsQueries = [];
|
||||||
|
foreach ($varsTypes as $type) {
|
||||||
|
$varsQueries[] = $this->makeVarSub($type, $varsColumns, $db);
|
||||||
|
}
|
||||||
|
|
||||||
|
$union = $db->select()->union($varsQueries, ZfDbSelect::SQL_UNION_ALL);
|
||||||
|
|
||||||
|
$columns = ['varname' => 'u.varname'];
|
||||||
|
foreach ($varsTypes as $column) {
|
||||||
|
$columns["cnt_$column"] = "SUM(u.cnt_$column)";
|
||||||
|
$columns["distinct_$column"] = "SUM(u.distinct_$column)";
|
||||||
|
}
|
||||||
|
return $db->select()->from(
|
||||||
|
array('u' => $union),
|
||||||
|
$columns
|
||||||
|
)->group('u.varname')->order('u.varname ASC');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $type
|
||||||
|
* @param array $columns
|
||||||
|
* @param ZfDbAdapter $db
|
||||||
|
* @return ZfDbSelect
|
||||||
|
*/
|
||||||
|
protected function makeVarSub($type, array $columns, ZfDbAdapter $db)
|
||||||
|
{
|
||||||
|
$columns["cnt_$type"] = 'COUNT(*)';
|
||||||
|
$columns["distinct_$type"] = 'COUNT(DISTINCT varvalue)';
|
||||||
|
return $db->select()->from(
|
||||||
|
['v' => "icinga_${type}_var"],
|
||||||
|
$columns
|
||||||
|
)->join(
|
||||||
|
['o' => "icinga_${type}"],
|
||||||
|
"o.id = v.${type}_id",
|
||||||
|
[]
|
||||||
|
)->where('o.object_type != ?', 'external_object')->group('varname');
|
||||||
|
}
|
||||||
|
}
|
|
@ -23,6 +23,9 @@ class DataTabs extends Tabs
|
||||||
])->add('datalist', [
|
])->add('datalist', [
|
||||||
'label' => $this->translate('Data lists'),
|
'label' => $this->translate('Data lists'),
|
||||||
'url' => 'director/data/lists'
|
'url' => 'director/data/lists'
|
||||||
|
])->add('customvars', [
|
||||||
|
'label' => $this->translate('Custom Variables'),
|
||||||
|
'url' => 'director/data/vars'
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue