diff --git a/library/Icingadb/Common/StateBadges.php b/library/Icingadb/Common/StateBadges.php index 1d6832ad2..2cb5cc8da 100644 --- a/library/Icingadb/Common/StateBadges.php +++ b/library/Icingadb/Common/StateBadges.php @@ -19,6 +19,9 @@ abstract class StateBadges extends BaseHtmlElement /** @var object $item */ protected $item; + /** @var string */ + protected $type; + /** @var string Prefix */ protected $prefix; @@ -37,6 +40,7 @@ abstract class StateBadges extends BaseHtmlElement public function __construct($item) { $this->item = $item; + $this->type = $this->getType(); $this->prefix = $this->getPrefix(); $this->url = $this->getBaseUrl(); } @@ -48,6 +52,13 @@ public function __construct($item) */ abstract protected function getBaseUrl(): Url; + /** + * Get the type of the items + * + * @return string + */ + abstract protected function getType(): string; + /** * Get the prefix for accessing state information * @@ -125,7 +136,7 @@ protected function createBadge(string $state) if (isset($this->item->$key) && $this->item->$key) { return Html::tag('li', $this->createLink( new StateBadge($this->item->$key, $state), - ['state.soft_state' => $this->getStateInt($state)] + [$this->type . '.state.soft_state' => $this->getStateInt($state)] )); } @@ -148,14 +159,20 @@ protected function createGroup(string $state) if (isset($this->item->$unhandledKey) && $this->item->$unhandledKey) { $content[] = Html::tag('li', $this->createLink( new StateBadge($this->item->$unhandledKey, $state), - ['state.soft_state' => $this->getStateInt($state), 'state.is_handled' => 'n'] + [ + $this->type . '.state.soft_state' => $this->getStateInt($state), + $this->type . '.state.is_handled' => 'n' + ] )); } if (isset($this->item->$handledKey) && $this->item->$handledKey) { $content[] = Html::tag('li', $this->createLink( new StateBadge($this->item->$handledKey, $state, true), - ['state.soft_state' => $this->getStateInt($state), 'state.is_handled' => 'y'] + [ + $this->type . '.state.soft_state' => $this->getStateInt($state), + $this->type . '.state.is_handled' => 'y' + ] )); } diff --git a/library/Icingadb/Widget/HostStateBadges.php b/library/Icingadb/Widget/HostStateBadges.php index 85b19486c..8141e82ec 100644 --- a/library/Icingadb/Widget/HostStateBadges.php +++ b/library/Icingadb/Widget/HostStateBadges.php @@ -16,6 +16,11 @@ protected function getBaseUrl(): Url return Links::hosts(); } + protected function getType(): string + { + return 'host'; + } + protected function getPrefix(): string { return 'hosts'; diff --git a/library/Icingadb/Widget/ServiceStateBadges.php b/library/Icingadb/Widget/ServiceStateBadges.php index 2f9530eb0..fee25864d 100644 --- a/library/Icingadb/Widget/ServiceStateBadges.php +++ b/library/Icingadb/Widget/ServiceStateBadges.php @@ -16,6 +16,11 @@ protected function getBaseUrl(): Url return Links::services(); } + protected function getType(): string + { + return 'service'; + } + protected function getPrefix(): string { return 'services';