From 64bab3f8dac9ec0ee7e7cb5c9632e3333a7bb934 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 5 Oct 2015 12:34:47 +0200 Subject: [PATCH] Node: remove implementation-specific logic --- library/Businessprocess/BpNode.php | 2 ++ library/Businessprocess/HostNode.php | 2 ++ library/Businessprocess/ImportedNode.php | 2 ++ library/Businessprocess/Node.php | 23 +++++++++-------------- library/Businessprocess/ServiceNode.php | 2 ++ 5 files changed, 17 insertions(+), 14 deletions(-) diff --git a/library/Businessprocess/BpNode.php b/library/Businessprocess/BpNode.php index c0424a8..ad38936 100644 --- a/library/Businessprocess/BpNode.php +++ b/library/Businessprocess/BpNode.php @@ -21,6 +21,8 @@ class BpNode extends Node ); + protected $className = 'process'; + public function __construct( BusinessProcess $bp, $object diff --git a/library/Businessprocess/HostNode.php b/library/Businessprocess/HostNode.php index e04212a..cc4387e 100644 --- a/library/Businessprocess/HostNode.php +++ b/library/Businessprocess/HostNode.php @@ -8,6 +8,8 @@ class HostNode extends Node { protected $hostname; + protected $className = 'host'; + public function __construct(BusinessProcess $bp, $object) { $this->name = $object->hostname . ';Hoststatus'; diff --git a/library/Businessprocess/ImportedNode.php b/library/Businessprocess/ImportedNode.php index fd636d5..aedcf86 100644 --- a/library/Businessprocess/ImportedNode.php +++ b/library/Businessprocess/ImportedNode.php @@ -14,6 +14,8 @@ class ImportedNode extends Node protected $importedNode; + protected $className = 'subtree'; + public function __construct(BusinessProcess $bp, $object) { $this->name = $object->name; diff --git a/library/Businessprocess/Node.php b/library/Businessprocess/Node.php index 44ca343..2a039e3 100644 --- a/library/Businessprocess/Node.php +++ b/library/Businessprocess/Node.php @@ -93,6 +93,8 @@ abstract class Node protected $missing = false; + protected $className = 'unknown'; + protected static $state_names = array( 'OK', 'WARNING', @@ -327,32 +329,25 @@ abstract class Node { return md5($prefix . (string) $this); } - + + protected function getObjectClassName() + { + return $this->className; + } + public function renderHtml($view, $prefix = '') { $id = $this->getId($prefix); $state = strtolower($this->getStateName()); if ($this->isMissing()) $state = 'missing'; $handled = $this->isAcknowledged() || $this->isInDowntime(); - if ($this instanceof BpNode) { - $typeClass = 'process'; - } elseif ($this instanceof HostNode) { - $typeClass = 'host'; - } elseif ($this instanceof ServiceNode) { - $typeClass = 'service'; - } elseif ($this instanceof ImportedNode) { - $typeClass = 'subtree'; - } else { - // WTF? - var_dump($this); exit; - } $html = sprintf( '', $state === 'ok' ? 'ok' : 'problem ' . $state, $handled ? ' handled' : '', ($this->hasChildren() ? ' operator ' : ' node '), - $typeClass, + $this->getObjectClassName(), $id ); diff --git a/library/Businessprocess/ServiceNode.php b/library/Businessprocess/ServiceNode.php index 69c859e..31e2a82 100644 --- a/library/Businessprocess/ServiceNode.php +++ b/library/Businessprocess/ServiceNode.php @@ -10,6 +10,8 @@ class ServiceNode extends Node protected $service; + protected $className = 'service'; + public function __construct(BusinessProcess $bp, $object) { $this->name = $object->hostname . ';' . $object->service;