[icinga-checkins] icinga.org: icingaweb2-module-director/feature/icinga-legacy-config-13049: ServiceObjectDashlet: Add service_set details

git at icinga.org git at icinga.org
Mon Nov 28 18:11:04 CET 2016


Module: icingaweb2-module-director
Branch: feature/icinga-legacy-config-13049
Commit: 03493ad32894451dc9895edbd6a6f4de554a5112
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=03493ad32894451dc9895edbd6a6f4de554a5112

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Mon Nov 28 17:10:35 2016 +0100

ServiceObjectDashlet: Add service_set details

---

 library/Director/Dashboard/Dashlet/Dashlet.php     |   12 +++++++++
 .../Dashboard/Dashlet/ServiceObjectDashlet.php     |   27 +++++++++++++++++++-
 2 files changed, 38 insertions(+), 1 deletion(-)

diff --git a/library/Director/Dashboard/Dashlet/Dashlet.php b/library/Director/Dashboard/Dashlet/Dashlet.php
index a69e012..81f79c8 100644
--- a/library/Director/Dashboard/Dashlet/Dashlet.php
+++ b/library/Director/Dashboard/Dashlet/Dashlet.php
@@ -16,6 +16,7 @@ abstract class Dashlet
 
     protected $supportsLegacyConfig;
 
+    /** @var View */
     protected $view;
 
     protected $db;
@@ -173,6 +174,14 @@ abstract class Dashlet
         return $this->view->translate($msg);
     }
 
+    /**
+     * Hook to add more details by a lower class
+     *
+     * @param $type
+     * @param $extra
+     */
+    protected function onStatSummary($type, &$extra) {}
+
     protected function statSummary($type)
     {
         $view = $this->view;
@@ -233,6 +242,9 @@ abstract class Dashlet
             }
         }
 
+        // call hook for more details
+        $this->onStatSummary($type, $extra);
+
         if (empty($extra)) {
             return $msg;
         }
diff --git a/library/Director/Dashboard/Dashlet/ServiceObjectDashlet.php b/library/Director/Dashboard/Dashlet/ServiceObjectDashlet.php
index aa7d41a..0421d89 100644
--- a/library/Director/Dashboard/Dashlet/ServiceObjectDashlet.php
+++ b/library/Director/Dashboard/Dashlet/ServiceObjectDashlet.php
@@ -6,7 +6,7 @@ class ServiceObjectDashlet extends Dashlet
 {
     protected $icon = 'services';
 
-    protected $requiredStats = array('service', 'servicegroup');
+    protected $requiredStats = array('service', 'servicegroup', 'service_set');
 
     public function getTitle()
     {
@@ -22,4 +22,29 @@ class ServiceObjectDashlet extends Dashlet
     {
         return array('director/admin');
     }
+
+    protected function onStatSummary($type, &$extra)
+    {
+        $view = $this->view;
+
+        if (array_key_exists($type . '_set', $this->stats)) {
+            $setstat = $this->stats[$type . '_set'];
+            if ((int) $setstat->cnt_total === 0) {
+                $extra[] = $view->translate('no related set exists');
+            } else {
+                if ((int) $setstat->cnt_template > 0) {
+                    $extra[] = sprintf(
+                        $view->translate('%s sets exist'),
+                        $setstat->cnt_template
+                    );
+                }
+                if ((int) $setstat->cnt_object > 0) {
+                    $extra[] = sprintf(
+                        $view->translate('%s sets are added to a host'),
+                        $setstat->cnt_object
+                    );
+                }
+            }
+        }
+    }
 }



More information about the icinga-checkins mailing list