mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-20 23:00:16 -05:00
Use display_name as alias for host and service nodes
This commit is contained in:
parent
8ef1dfcbdc
commit
a2854e8cf4
8 changed files with 67 additions and 32 deletions
|
|
@ -21,7 +21,6 @@ class BpNode extends Node
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $childNames = array();
|
protected $childNames = array();
|
||||||
protected $alias;
|
|
||||||
protected $counters;
|
protected $counters;
|
||||||
protected $missing = null;
|
protected $missing = null;
|
||||||
protected $missingChildren;
|
protected $missingChildren;
|
||||||
|
|
@ -307,22 +306,11 @@ class BpNode extends Node
|
||||||
return $this->info_command;
|
return $this->info_command;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasAlias()
|
|
||||||
{
|
|
||||||
return $this->getAlias() !== null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getAlias()
|
public function getAlias()
|
||||||
{
|
{
|
||||||
return $this->alias ? preg_replace('~_~', ' ', $this->alias) : $this->name;
|
return $this->alias ? preg_replace('~_~', ' ', $this->alias) : $this->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAlias($name)
|
|
||||||
{
|
|
||||||
$this->alias = $name;
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -45,11 +45,6 @@ class HostNode extends MonitoredNode
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getAlias()
|
|
||||||
{
|
|
||||||
return $this->getHostname();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getHostname()
|
public function getHostname()
|
||||||
{
|
{
|
||||||
return $this->hostname;
|
return $this->hostname;
|
||||||
|
|
@ -67,9 +62,4 @@ class HostNode extends MonitoredNode
|
||||||
|
|
||||||
return Url::fromPath('businessprocess/host/show', $params);
|
return Url::fromPath('businessprocess/host/show', $params);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getLink()
|
|
||||||
{
|
|
||||||
return Html::tag('a', ['href' => $this->getUrl()], $this->hostname);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@ abstract class Node
|
||||||
self::ICINGA_OK => 0,
|
self::ICINGA_OK => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/** @var string Alias of the node */
|
||||||
|
protected $alias;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main business process object
|
* Main business process object
|
||||||
*
|
*
|
||||||
|
|
@ -331,12 +334,31 @@ abstract class Node
|
||||||
|
|
||||||
public function hasAlias()
|
public function hasAlias()
|
||||||
{
|
{
|
||||||
return false;
|
return $this->alias !== null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the alias of the node
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function getAlias()
|
public function getAlias()
|
||||||
{
|
{
|
||||||
return $this->name;
|
return $this->alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the alias of the node
|
||||||
|
*
|
||||||
|
* @param string $alias
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setAlias($alias)
|
||||||
|
{
|
||||||
|
$this->alias = $alias;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasParents()
|
public function hasParents()
|
||||||
|
|
|
||||||
|
|
@ -162,10 +162,8 @@ class NodeTile extends BaseHtmlElement
|
||||||
{
|
{
|
||||||
$node = $this->node;
|
$node = $this->node;
|
||||||
$url = $this->getMainNodeUrl($node);
|
$url = $this->getMainNodeUrl($node);
|
||||||
if ($node instanceof ServiceNode) {
|
if ($node instanceof MonitoredNode) {
|
||||||
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getAlias());
|
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getAlias());
|
||||||
} elseif ($node instanceof HostNode) {
|
|
||||||
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getHostname());
|
|
||||||
} else {
|
} else {
|
||||||
$link = Html::tag('a', ['href' => $url], $node->getAlias());
|
$link = Html::tag('a', ['href' => $url], $node->getAlias());
|
||||||
$link->getAttributes()->add('data-base-target', '_self');
|
$link->getAttributes()->add('data-base-target', '_self');
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,9 @@ class ServiceNode extends MonitoredNode
|
||||||
{
|
{
|
||||||
protected $hostname;
|
protected $hostname;
|
||||||
|
|
||||||
|
/** @var string Alias of the host */
|
||||||
|
protected $hostAlias;
|
||||||
|
|
||||||
protected $service;
|
protected $service;
|
||||||
|
|
||||||
protected $className = 'service';
|
protected $className = 'service';
|
||||||
|
|
@ -31,6 +34,30 @@ class ServiceNode extends MonitoredNode
|
||||||
return $this->hostname;
|
return $this->hostname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the host alias
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function getHostAlias()
|
||||||
|
{
|
||||||
|
return $this->hostAlias;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the host alias
|
||||||
|
*
|
||||||
|
* @param string $hostAlias
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setHostAlias($hostAlias)
|
||||||
|
{
|
||||||
|
$this->hostAlias = $hostAlias;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function getServiceDescription()
|
public function getServiceDescription()
|
||||||
{
|
{
|
||||||
return $this->service;
|
return $this->service;
|
||||||
|
|
@ -38,7 +65,7 @@ class ServiceNode extends MonitoredNode
|
||||||
|
|
||||||
public function getAlias()
|
public function getAlias()
|
||||||
{
|
{
|
||||||
return $this->hostname . ': ' . $this->service;
|
return $this->getHostAlias() . ': ' . $this->alias;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrl()
|
public function getUrl()
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ use Exception;
|
||||||
use Icinga\Application\Benchmark;
|
use Icinga\Application\Benchmark;
|
||||||
use Icinga\Data\Filter\Filter;
|
use Icinga\Data\Filter\Filter;
|
||||||
use Icinga\Module\Businessprocess\BpConfig;
|
use Icinga\Module\Businessprocess\BpConfig;
|
||||||
|
use Icinga\Module\Businessprocess\ServiceNode;
|
||||||
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
|
||||||
|
|
||||||
class MonitoringState
|
class MonitoringState
|
||||||
|
|
@ -74,7 +75,8 @@ class MonitoringState
|
||||||
'last_state_change' => $hostStateChangeColumn,
|
'last_state_change' => $hostStateChangeColumn,
|
||||||
'in_downtime' => 'host_in_downtime',
|
'in_downtime' => 'host_in_downtime',
|
||||||
'ack' => 'host_acknowledged',
|
'ack' => 'host_acknowledged',
|
||||||
'state' => $hostStateColumn
|
'state' => $hostStateColumn,
|
||||||
|
'display_name' => 'host_display_name'
|
||||||
))->applyFilter($hostFilter)->getQuery()->fetchAll();
|
))->applyFilter($hostFilter)->getQuery()->fetchAll();
|
||||||
|
|
||||||
Benchmark::measure('Retrieved states for ' . count($hostStatus) . ' hosts in ' . $config->getName());
|
Benchmark::measure('Retrieved states for ' . count($hostStatus) . ' hosts in ' . $config->getName());
|
||||||
|
|
@ -88,7 +90,9 @@ class MonitoringState
|
||||||
'last_state_change' => $serviceStateChangeColumn,
|
'last_state_change' => $serviceStateChangeColumn,
|
||||||
'in_downtime' => 'service_in_downtime',
|
'in_downtime' => 'service_in_downtime',
|
||||||
'ack' => 'service_acknowledged',
|
'ack' => 'service_acknowledged',
|
||||||
'state' => $serviceStateColumn
|
'state' => $serviceStateColumn,
|
||||||
|
'display_name' => 'service_display_name',
|
||||||
|
'host_display_name' => 'host_display_name'
|
||||||
))->applyFilter($hostFilter)->getQuery()->fetchAll();
|
))->applyFilter($hostFilter)->getQuery()->fetchAll();
|
||||||
|
|
||||||
Benchmark::measure('Retrieved states for ' . count($serviceStatus) . ' services in ' . $config->getName());
|
Benchmark::measure('Retrieved states for ' . count($serviceStatus) . ' services in ' . $config->getName());
|
||||||
|
|
@ -137,5 +141,11 @@ class MonitoringState
|
||||||
if ((int) $row->ack === 1) {
|
if ((int) $row->ack === 1) {
|
||||||
$node->setAck(true);
|
$node->setAck(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$node->setAlias($row->display_name);
|
||||||
|
|
||||||
|
if ($node instanceof ServiceNode) {
|
||||||
|
$node->setHostAlias($row->host_display_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -60,6 +60,6 @@ class HostNodeTest extends BaseTestCase
|
||||||
return (new HostNode((object) array(
|
return (new HostNode((object) array(
|
||||||
'hostname' => 'localhost',
|
'hostname' => 'localhost',
|
||||||
'state' => 0,
|
'state' => 0,
|
||||||
)))->setBpConfig($bp);
|
)))->setBpConfig($bp)->setAlias('localhost');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,6 @@ class ServiceNodeTest extends BaseTestCase
|
||||||
'hostname' => 'localhost',
|
'hostname' => 'localhost',
|
||||||
'service' => 'ping <> pong',
|
'service' => 'ping <> pong',
|
||||||
'state' => 0,
|
'state' => 0,
|
||||||
)))->setBpConfig($bp);
|
)))->setBpConfig($bp)->setHostAlias('localhost')->setAlias('ping <> pong');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue