Use display_name as alias for host and service nodes

This commit is contained in:
Eric Lippmann 2019-12-02 15:24:24 +01:00
parent 8ef1dfcbdc
commit a2854e8cf4
8 changed files with 67 additions and 32 deletions

View file

@ -21,7 +21,6 @@ class BpNode extends Node
/** @var array */
protected $childNames = array();
protected $alias;
protected $counters;
protected $missing = null;
protected $missingChildren;
@ -307,22 +306,11 @@ class BpNode extends Node
return $this->info_command;
}
public function hasAlias()
{
return $this->getAlias() !== null;
}
public function getAlias()
{
return $this->alias ? preg_replace('~_~', ' ', $this->alias) : $this->name;
}
public function setAlias($name)
{
$this->alias = $name;
return $this;
}
/**
* @return int
*/

View file

@ -45,11 +45,6 @@ class HostNode extends MonitoredNode
}
}
public function getAlias()
{
return $this->getHostname();
}
public function getHostname()
{
return $this->hostname;
@ -67,9 +62,4 @@ class HostNode extends MonitoredNode
return Url::fromPath('businessprocess/host/show', $params);
}
public function getLink()
{
return Html::tag('a', ['href' => $this->getUrl()], $this->hostname);
}
}

View file

@ -44,6 +44,9 @@ abstract class Node
self::ICINGA_OK => 0,
);
/** @var string Alias of the node */
protected $alias;
/**
* Main business process object
*
@ -331,12 +334,31 @@ abstract class Node
public function hasAlias()
{
return false;
return $this->alias !== null;
}
/**
* Get the alias of the node
*
* @return string
*/
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()

View file

@ -162,10 +162,8 @@ class NodeTile extends BaseHtmlElement
{
$node = $this->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());
} elseif ($node instanceof HostNode) {
$link = Html::tag('a', ['href' => $url, 'data-base-target' => '_next'], $node->getHostname());
} else {
$link = Html::tag('a', ['href' => $url], $node->getAlias());
$link->getAttributes()->add('data-base-target', '_self');

View file

@ -8,6 +8,9 @@ class ServiceNode extends MonitoredNode
{
protected $hostname;
/** @var string Alias of the host */
protected $hostAlias;
protected $service;
protected $className = 'service';
@ -31,6 +34,30 @@ class ServiceNode extends MonitoredNode
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()
{
return $this->service;
@ -38,7 +65,7 @@ class ServiceNode extends MonitoredNode
public function getAlias()
{
return $this->hostname . ': ' . $this->service;
return $this->getHostAlias() . ': ' . $this->alias;
}
public function getUrl()

View file

@ -6,6 +6,7 @@ use Exception;
use Icinga\Application\Benchmark;
use Icinga\Data\Filter\Filter;
use Icinga\Module\Businessprocess\BpConfig;
use Icinga\Module\Businessprocess\ServiceNode;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
class MonitoringState
@ -74,7 +75,8 @@ class MonitoringState
'last_state_change' => $hostStateChangeColumn,
'in_downtime' => 'host_in_downtime',
'ack' => 'host_acknowledged',
'state' => $hostStateColumn
'state' => $hostStateColumn,
'display_name' => 'host_display_name'
))->applyFilter($hostFilter)->getQuery()->fetchAll();
Benchmark::measure('Retrieved states for ' . count($hostStatus) . ' hosts in ' . $config->getName());
@ -88,7 +90,9 @@ class MonitoringState
'last_state_change' => $serviceStateChangeColumn,
'in_downtime' => 'service_in_downtime',
'ack' => 'service_acknowledged',
'state' => $serviceStateColumn
'state' => $serviceStateColumn,
'display_name' => 'service_display_name',
'host_display_name' => 'host_display_name'
))->applyFilter($hostFilter)->getQuery()->fetchAll();
Benchmark::measure('Retrieved states for ' . count($serviceStatus) . ' services in ' . $config->getName());
@ -137,5 +141,11 @@ class MonitoringState
if ((int) $row->ack === 1) {
$node->setAck(true);
}
$node->setAlias($row->display_name);
if ($node instanceof ServiceNode) {
$node->setHostAlias($row->host_display_name);
}
}
}

View file

@ -60,6 +60,6 @@ class HostNodeTest extends BaseTestCase
return (new HostNode((object) array(
'hostname' => 'localhost',
'state' => 0,
)))->setBpConfig($bp);
)))->setBpConfig($bp)->setAlias('localhost');
}
}

View file

@ -51,6 +51,6 @@ class ServiceNodeTest extends BaseTestCase
'hostname' => 'localhost',
'service' => 'ping <> pong',
'state' => 0,
)))->setBpConfig($bp);
)))->setBpConfig($bp)->setHostAlias('localhost')->setAlias('ping <> pong');
}
}