[icinga-checkins] icinga.org: dashing-icinga2/master: Add state based colors to problem listing

git at icinga.org git at icinga.org
Sun Nov 27 19:17:00 CET 2016


Module: dashing-icinga2
Branch: master
Commit: 4b7710c2e478ae641b887480bbd45c5d66c283b7
URL:    https://git.icinga.org/?p=dashing-icinga2.git;a=commit;h=4b7710c2e478ae641b887480bbd45c5d66c283b7

Author: Michael Friedrich <michael.friedrich at icinga.com>
Date:   Sun Nov 27 19:15:27 2016 +0100

Add state based colors to problem listing

---

 jobs/icinga2.rb        |    4 ++--
 lib/icinga2.rb         |   21 +++++++++++++++++++--
 widgets/list/list.html |    8 ++++----
 widgets/list/list.scss |   16 ++++++++++++++++
 4 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/jobs/icinga2.rb b/jobs/icinga2.rb
index af14bf6..35d9b1c 100644
--- a/jobs/icinga2.rb
+++ b/jobs/icinga2.rb
@@ -54,8 +54,8 @@ SCHEDULER.every '5s', :first_in => 0 do |job|
   # severity list
   severity_stats = []
   icinga.service_problems_severity.each do |name, state|
-    #severity_stats.push({ "label" => icinga.formatService(name), "value" => state})
-    severity_stats.push({ "label" => icinga.formatService(name)})
+    color = icinga.stateToColor(state.to_int, false)
+    severity_stats.push({ "label" => icinga.formatService(name), "color" => color})
   end
 
   puts "Severity: " + severity_stats.to_s
diff --git a/lib/icinga2.rb b/lib/icinga2.rb
index 6a4f341..dfe2ea6 100644
--- a/lib/icinga2.rb
+++ b/lib/icinga2.rb
@@ -232,6 +232,24 @@ class Icinga2
     return "Undefined state. Programming error."
   end
 
+  def stateToColor(state, is_host = false)
+    if (is_host && state >= 1)
+      return "red"
+    elsif (is_host && state == 0)
+      return "green"
+    elsif (state == 0)
+      return "green"
+    elsif (state == 1)
+      return "yellow"
+    elsif (state == 2)
+      return "red"
+    elsif (state == 3)
+      return "purple"
+    end
+
+    return "Undefined state. Programming error."
+  end
+
   def countProblems(objects)
     problems = 0
 
@@ -357,8 +375,7 @@ class Icinga2
       end
 
       name = obj["name"]
-      state = stateToString(obj["attrs"]["state"].to_int, false)
-      @service_problems_severity[name] = state
+      @service_problems_severity[name] = obj["attrs"]["state"]
 
       count += 1
     end
diff --git a/widgets/list/list.html b/widgets/list/list.html
index 07e0471..039c41a 100644
--- a/widgets/list/list.html
+++ b/widgets/list/list.html
@@ -2,15 +2,15 @@
 
 <ol>
   <li data-foreach-item="items">
-    <span class="label" data-bind="item.label"></span>
-    <span class="value" data-bind="item.value"></span>
+    <span class="label" data-bind-class="item.color" data-bind="item.label"></span>
+    <span class="value" data-bind-class="item.color" data-bind="item.value"></span>
   </li>
 </ol>
 
 <ul class="list-nostyle">
   <li data-foreach-item="items">
-    <span class="label" data-bind="item.label"></span>
-    <span class="value" data-bind="item.value"></span>
+    <span class="label" data-bind-class="item.color" data-bind="item.label"></span>
+    <span class="value" data-bind-class="item.color" data-bind="item.value"></span>
   </li>
 </ul>
 
diff --git a/widgets/list/list.scss b/widgets/list/list.scss
index 483fd13..2647bc2 100644
--- a/widgets/list/list.scss
+++ b/widgets/list/list.scss
@@ -59,4 +59,20 @@ $moreinfo-color:    rgba(255, 255, 255, 0.7);
     color: $moreinfo-color;
   }
 
+  .green {
+    color: #44bb77;
+    font-size: 15px;
+  }
+  .yellow {
+    color: #ffaa44;
+    font-size: 15px;
+  }
+  .red {
+    color: #ff5566;
+    font-size: 15px;
+  }
+  .purple {
+    color: #aa44ff;
+    font-size: 15px;
+  }
 }



More information about the icinga-checkins mailing list