mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-20 14:50:11 -05:00
IDO: Add custom hoststatus and servicestatus queries
For autocompletion with custom variable support, it is required to be able to filter for custom variable values if no customvariable name is known. But since the template how custom variables are joined is on a private property, this many classes are required to circumvent/adjust that.
This commit is contained in:
parent
ff0cb21a2b
commit
0fdee96deb
5 changed files with 132 additions and 0 deletions
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Businessprocess\Monitoring\Backend\Ido\Query;
|
||||
|
||||
use Icinga\Module\Monitoring\Backend\Ido\Query\ServicecommenthistoryQuery;
|
||||
use Icinga\Module\Monitoring\Backend\Ido\Query\ServicecommentQuery;
|
||||
use Icinga\Module\Monitoring\Backend\Ido\Query\ServicedowntimeQuery;
|
||||
use Icinga\Module\Monitoring\Backend\Ido\Query\ServicedowntimestarthistoryQuery;
|
||||
use Icinga\Module\Monitoring\Backend\Ido\Query\ServiceflappingstarthistoryQuery;
|
||||
use Icinga\Module\Monitoring\Backend\Ido\Query\ServicegroupQuery;
|
||||
use Icinga\Module\Monitoring\Backend\Ido\Query\ServicenotificationQuery;
|
||||
use Icinga\Module\Monitoring\Backend\Ido\Query\ServicestatehistoryQuery;
|
||||
use Zend_Db_Select;
|
||||
|
||||
trait CustomVarJoinTemplateOverride
|
||||
{
|
||||
private $customVarsJoinTemplate = '%1$s = %2$s.object_id AND %2$s.varname LIKE %3$s';
|
||||
|
||||
/**
|
||||
* This is a 1:1 copy of {@see IdoQuery::joinCustomvar()} to be able to
|
||||
* adjust {@see IdoQuery::$customVarsJoinTemplate} as it's private
|
||||
*/
|
||||
protected function joinCustomvar($customvar)
|
||||
{
|
||||
// TODO: This is not generic enough yet
|
||||
list($type, $name) = $this->customvarNameToTypeName($customvar);
|
||||
$alias = ($type === 'host' ? 'hcv_' : 'scv_') . preg_replace('~[^a-zA-Z0-9_]~', '_', $name);
|
||||
|
||||
// We're replacing any problematic char with an underscore, which will lead to duplicates, this avoids them
|
||||
$from = $this->select->getPart(Zend_Db_Select::FROM);
|
||||
for ($i = 2; array_key_exists($alias, $from); $i++) {
|
||||
$alias = $alias . '_' . $i;
|
||||
}
|
||||
|
||||
$this->customVars[strtolower($customvar)] = $alias;
|
||||
|
||||
if ($type === 'host') {
|
||||
if ($this instanceof ServicecommentQuery
|
||||
|| $this instanceof ServicedowntimeQuery
|
||||
|| $this instanceof ServicecommenthistoryQuery
|
||||
|| $this instanceof ServicedowntimestarthistoryQuery
|
||||
|| $this instanceof ServiceflappingstarthistoryQuery
|
||||
|| $this instanceof ServicegroupQuery
|
||||
|| $this instanceof ServicenotificationQuery
|
||||
|| $this instanceof ServicestatehistoryQuery
|
||||
|| $this instanceof \Icinga\Module\Monitoring\Backend\Ido\Query\ServicestatusQuery
|
||||
) {
|
||||
$this->requireVirtualTable('services');
|
||||
$leftcol = 's.host_object_id';
|
||||
} else {
|
||||
$leftcol = 'ho.object_id';
|
||||
if (! $this->hasJoinedTable('ho')) {
|
||||
$this->requireVirtualTable('hosts');
|
||||
}
|
||||
}
|
||||
} else { // $type === 'service'
|
||||
$leftcol = 'so.object_id';
|
||||
if (! $this->hasJoinedTable('so')) {
|
||||
$this->requireVirtualTable('services');
|
||||
}
|
||||
}
|
||||
|
||||
$mapped = $this->getMappedField($leftcol);
|
||||
if ($mapped !== null) {
|
||||
$this->requireColumn($leftcol);
|
||||
$leftcol = $mapped;
|
||||
}
|
||||
|
||||
$joinOn = sprintf(
|
||||
$this->customVarsJoinTemplate,
|
||||
$leftcol,
|
||||
$alias,
|
||||
$this->db->quote($name)
|
||||
);
|
||||
|
||||
$this->select->joinLeft(
|
||||
array($alias => $this->prefix . 'customvariablestatus'),
|
||||
$joinOn,
|
||||
array()
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Businessprocess\Monitoring\Backend\Ido\Query;
|
||||
|
||||
class HostStatusQuery extends \Icinga\Module\Monitoring\Backend\Ido\Query\HoststatusQuery
|
||||
{
|
||||
use CustomVarJoinTemplateOverride;
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Businessprocess\Monitoring\Backend\Ido\Query;
|
||||
|
||||
class ServiceStatusQuery extends \Icinga\Module\Monitoring\Backend\Ido\Query\ServicestatusQuery
|
||||
{
|
||||
use CustomVarJoinTemplateOverride;
|
||||
}
|
||||
16
library/Businessprocess/Monitoring/DataView/HostStatus.php
Normal file
16
library/Businessprocess/Monitoring/DataView/HostStatus.php
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Businessprocess\Monitoring\DataView;
|
||||
|
||||
use Icinga\Data\ConnectionInterface;
|
||||
use Icinga\Module\Businessprocess\Monitoring\Backend\Ido\Query\HostStatusQuery;
|
||||
|
||||
class HostStatus extends \Icinga\Module\Monitoring\DataView\Hoststatus
|
||||
{
|
||||
public function __construct(ConnectionInterface $connection, array $columns = null)
|
||||
{
|
||||
parent::__construct($connection, $columns);
|
||||
|
||||
$this->query = new HostStatusQuery($connection->getResource(), $columns);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
namespace Icinga\Module\Businessprocess\Monitoring\DataView;
|
||||
|
||||
use Icinga\Data\ConnectionInterface;
|
||||
use Icinga\Module\Businessprocess\Monitoring\Backend\Ido\Query\ServiceStatusQuery;
|
||||
|
||||
class ServiceStatus extends \Icinga\Module\Monitoring\DataView\Servicestatus
|
||||
{
|
||||
public function __construct(ConnectionInterface $connection, array $columns = null)
|
||||
{
|
||||
parent::__construct($connection, $columns);
|
||||
|
||||
$this->query = new ServiceStatusQuery($connection->getResource(), $columns);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue