ZABBIX Forums  
  #1  
Old 08-01-2015, 13:22
incama incama is offline
Junior Member
 
Join Date: Jan 2015
Location: Maastricht
Posts: 13
Default Zabbix Trigger Dashboard

First of all, I really like Zabbix. As a HPOMW trained fellow I really like the simplicity and ease of the global interface. But (as there is always a "but"), I couldn't find a descend way to project relevant data to people who aren't skilled in bits and pieces of our environment. I have tested the screens and maps features a lot but they where not suitable enough.

Gladly, there is the Zabbix Api, and with the massive help of a PHP programmer, I (we) were able to generate a Dashboard screen that fit our needs and I would like to share this with you.

Some features and requirements:

- Itís build with php using the php api ( http://zabbixapi.confirm.ch )
- It queries a Host Group (via a read only user access) and checks itís active triggers
- If none of itís trigger are fired, the host is probably Ďokí and will be shown in bright green on the dashboard
- If a trigger gets fired, the color and/or size are adjusted
- Using jquery and masonry javascripts hosts are aligned on the dashboard.

This will display a screen like:



Code is available on Github:
https://github.com/incama/Zabbix-Dashboard
Reply With Quote
  #2  
Old 13-01-2015, 10:36
noeand noeand is offline
Junior Member
 
Join Date: Apr 2014
Posts: 24
Default

Good work on this one!

If you could provide more details in the documentation about the installation and any configuration of this Dashboard it would be great!

Thanks!
Reply With Quote
  #3  
Old 13-01-2015, 14:27
rocksteady rocksteady is offline
Junior Member
 
Join Date: Apr 2010
Location: Tessin Switzerland
Posts: 25
Default

Quote:
Originally Posted by noeand View Post
Good work on this one!

If you could provide more details in the documentation about the installation and any configuration of this Dashboard it would be great!

Thanks!

Yes some docs Pls

Cheers
Marco
Reply With Quote
  #4  
Old 22-01-2015, 16:32
AlexYoung AlexYoung is offline
Member
 
Join Date: Jul 2013
Posts: 37
Default

Tried it on 2.4 and it maxes out my cpu on mysqld i have updated the api from the version that comes with it from 2.2 to 2.4 and yeah cpu is a problem with mine so bit unsure but screenshot looks nice.
Reply With Quote
  #5  
Old 25-01-2015, 13:24
BDiE8VNy BDiE8VNy is offline
Senior Member
 
Join Date: Apr 2010
Location: Germany
Posts: 665
Default

Very nice work!

One can significantly improve performance when querying all trigger information at once by a single API call.
The diff below shall just show the idea and not how it should be made - It's even not apply able since special characters like tabulators got lost.

In fact a colleague of mine started to hack this dashboard to suit his needs but was suffering by a page reload time of >45 seconds.
I just made some improvements to point him in the right direction. After the modification the page reloads in <2 seconds. Since I just modified the file he provided me, I've no idea whether this file was current or unmodified.

Additionally hosts are ordered by name and a session logout was added.

Note that I replaced 'div' by 'ddiv'
This was necessary due to this stupid 'live link' restrictions of the forum :\

Code:
--- hostgroup01.php.orig     2015-01-10 09:22:21.000000000 +0100
+++ hostgroup01.php     2015-01-25 11:44:37.000000000 +0100
@@ -36,19 +36,51 @@
 <ddiv id="sheetname">Your Group</ddiv>

 <?php
-// get hostgroupid with hosts
-    $groupids = $api->hostgroupGet(array(
-       'output' => 'extend',
-       'selectHosts' => 'extend',
-       'select_acknowledges' => 'extend',
-       'only_true' => '1'
+    $groups = $api->hostgroupGet(array(
+       'output' => array('name'),
+       'selectHosts' => array(
+               'flags',
+               'hostid',
+               'name',
+               'maintenance_status'),
+       'real_hosts ' => 1,
+       'with_monitored_triggers' => 1,
+       'sortfield' => 'name'
     ));

+       foreach($groups as $group) {
+               $groupIds[] = $group->groupid;
+       }
+
+       $triggers = $api->triggerGet(array(
+               'output' => array(
+                       'priority',
+                       'description'),
+               'selectHosts' => array('hostid'),
+               'groupids' => $groupIds,
+               'expandDescription' => 1,
+               'only_true' => 1,
+               'monitored' => 1,
+               'withLastEventUnacknowledged' => 1,
+               'sortfield' => 'priority',
+               'sortorder' => 'DESC'
+       ));
+
+       foreach($triggers as $trigger) {
+               foreach($trigger->hosts as $host) {
+                       $hostTriggers[$host->hostid][] = $trigger;
+               }
+       }

 // get all hosts from each groupid
-    foreach($groupids as $groupid) {
-       $groupname = $groupid->name;
-       $hosts = $groupid->hosts;
+    foreach($groups as $group) {
+       $groupname = $group->name;
+       $hosts = $group->hosts;
+
+       usort($hosts, function ($a, $b) {
+               if ($a->name == $b) return 0;
+               return ($a->name < $b->name ? -1 : 1);
+       });

        if ($hosts) {
        $count = "0";
@@ -71,21 +103,11 @@
                                $hostid = $host->hostid;
                                $hostname = $host->name;
                                $maintenance = $host->maintenance_status;
-
-                               $trigger = $api->triggerGet(array(
-                                       'output' => 'extend',
-                                       'hostids' => $hostid,
-                                       'sortfield' => 'priority',
-                                       'sortorder' => 'DESC',
-                                       'only_true' => '1',
-                                       'active' => '1', // include trigger state active not active
-                                       'withUnacknowledgedEvents' => '1' // show only unacknowledgeevents
-                               ));
-
-                               if ($trigger) {
+
+                               if (array_key_exists($hostid, $hostTriggers)) {

                                        // Highest Priority error
-                                       $hostboxprio = $trigger[0]->priority;
+                                       $hostboxprio = $hostTriggers[$hostid][0]->priority;
                                        //First filter the hosts that are in maintenance and assign the maintenance class if is true
                                        if ($maintenance != "0") {
                                                echo "<ddiv class=\"hostbox maintenance\">";
@@ -96,7 +118,7 @@
                                        }
                                        echo "<ddiv class=\"title\">" . $hostname . "</ddiv><ddiv class=\"hostid\">" . $hostid . "</ddiv>";
                                        $count = "0";
-                                       foreach ($trigger as $event) {
+                                       foreach ($hostTriggers[$hostid] as $event) {
                                                if ($count++ <= 2 ) {
                                                                $priority = $event->priority;
                                                                $description = $event->description;
@@ -123,6 +145,7 @@
         if ($count != "0") {echo "</ddiv>";}
        }
     }
+    $api->userLogout();
 ?>
 <!-- Second piece of js to gracefully reload the page (value in ms) -->
 <script>
Reply With Quote
  #6  
Old 26-01-2015, 15:28
AlexYoung AlexYoung is offline
Member
 
Join Date: Jul 2013
Posts: 37
Default

Tried doing that to mine on 2.4 but still just hangs it does eventually load but i only see the clock after about 45 seconds.
Reply With Quote
  #7  
Old 26-01-2015, 17:43
BDiE8VNy BDiE8VNy is offline
Senior Member
 
Join Date: Apr 2010
Location: Germany
Posts: 665
Default

Quote:
Originally Posted by AlexYoung View Post
Tried doing that to mine on 2.4 but still just hangs it does eventually load but i only see the clock after about 45 seconds.
Can you share your code?
Reply With Quote
  #8  
Old 26-01-2015, 18:02
AlexYoung AlexYoung is offline
Member
 
Join Date: Jul 2013
Posts: 37
Default

It's probably wrong lol i'm only a level numpty at PHP lol

PHP Code:
<?php
<!-- We could use the Zabbix HostGroup name herebut would not work in a nice way when using a dozen of hostgroupsyetSo we hardcoded it here. --> 
<
div id="sheetname">Monitoring</div>

 <?
php
// get hostgroupid with hosts
    
$groupids $api>hostgroupGet(array(
       
'output' => 'extend',
       
'selectHosts' => 'extend',
       
'select_acknowledges' => 'extend',
       
'only_true' => '1'
    
$groups $api>hostgroupGet(array(
       
'output' => array('name'),
       
'selectHosts' => array(
               
'flags',
               
'hostid',
               
'name',
               
'maintenance_status'),
       
'real_hosts ' => 1,
       
'with_monitored_triggers' => 1,
       
'sortfield' => 'name'
     
));

       foreach(
$groups as $group) {
               
$groupIds[] = $group>groupid;
       }

       
$triggers $api>triggerGet(array(
               
'output' => array(
                       
'priority',
                       
'description'),
               
'selectHosts' => array('hostid'),
               
'groupids' => $groupIds,
               
'expandDescription' => 1,
               
'only_true' => 1,
               
'monitored' => 1,
               
'withLastEventUnacknowledged' => 1,
               
'sortfield' => 'priority',
               
'sortorder' => 'DESC'
       
));

       foreach(
$triggers as $trigger) {
               foreach(
$trigger>hosts as $host) {
                       
$hostTriggers[$host>hostid][] = $trigger;
               }
       }

 
// get all hosts from each groupid
    
foreach($groupids as $groupid) {
       
$groupname $groupid>name;
       
$hosts $groupid>hosts;
    foreach(
$groups as $group) {
       
$groupname $group>name;
       
$hosts $group>hosts;

       
usort($hosts, function ($a$b) {
               if (
$a>name == $b) return 0;
               return (
$a>name $b>name 1);
       });

        if (
$hosts) {
        
$count "0";

                                
$hostid $host>hostid;
                                
$hostname $host>name;
                                
$maintenance $host>maintenance_status;

                               
$trigger $api>triggerGet(array(
                                       
'output' => 'extend',
                                       
'hostids' => $hostid,
                                       
'sortfield' => 'priority',
                                       
'sortorder' => 'DESC',
                                       
'only_true' => '1',
                                       
'active' => '1'// include trigger state active not active
                                       
'withUnacknowledgedEvents' => '1' // show only unacknowledgeevents
                               
));

                               if (
$trigger) {

                               if (
array_key_exists($hostid$hostTriggers)) {

                                        
// Highest Priority error
                                       
$hostboxprio $trigger[0]>priority;
                                       
$hostboxprio $hostTriggers[$hostid][0]>priority;
                                        
//First filter the hosts that are in maintenance and assign the maintenance class if is true
                                        
if ($maintenance != "0") {
                                                echo 
"<ddiv class=\"hostbox maintenance\">";

                                        }
                                        echo 
"<ddiv class=\"title\">" $hostname "</ddiv><ddiv class=\"hostid\">" $hostid "</ddiv>";
                                        
$count "0";
                                      foreach (
$trigger as $event) {
                                     foreach (
$hostTriggers[$hostid] as $event) {
                                                if (
$count <= ) {
                                                                
$priority $event>priority;
                                                                
$description $event>description;

         if (
$count != "0") {echo "</ddiv>";}
        }
     }
   
$api>userLogout();
 
?>


<!-- Second piece of js to gracefully reload the page (value in ms) -->
<script>
    function ReloadPage() {
       location.reload();
    };
    $(document).ready(function() {
      setTimeout("ReloadPage()", 60000);
    });
</script> 
</body>
</html>
Reply With Quote
  #9  
Old 26-01-2015, 18:37
BDiE8VNy BDiE8VNy is offline
Senior Member
 
Join Date: Apr 2010
Location: Germany
Posts: 665
Default

The lines in my diff having '-' as first character indicate removed lines!
Reply With Quote
  #10  
Old 27-01-2015, 13:45
AlexYoung AlexYoung is offline
Member
 
Join Date: Jul 2013
Posts: 37
Default

Well i think i've done it right but still not working, now just a blank page

PHP Code:
<?php

<!-- We could use the Zabbix HostGroup name herebut would not work in a nice way when using a dozen of hostgroupsyetSo we hardcoded it here. --> 
<
div id="sheetname">Monitoring</div>

 <?
php

    $groups 
$api->hostgroupGet(array(
       
'output' => array('name'),
       
'selectHosts' => array(
               
'flags',
               
'hostid',
               
'name',
               
'maintenance_status'),
       
'real_hosts ' => 1,
       
'with_monitored_triggers' => 1,
       
'sortfield' => 'name'
     
));

       foreach(
$groups as $group) {
               
$groupIds[] = $group->groupid;
       }

       
$triggers $api->triggerGet(array(
               
'output' => array(
                       
'priority',
                       
'description'),
               
'selectHosts' => array('hostid'),
               
'groupids' => $groupIds,
               
'expandDescription' => 1,
               
'only_true' => 1,
               
'monitored' => 1,
               
'withLastEventUnacknowledged' => 1,
               
'sortfield' => 'priority',
               
'sortorder' => 'DESC'
       
));

       foreach(
$triggers as $trigger) {
               foreach(
$trigger->hosts as $host) {
                       
$hostTriggers[$host->hostid][] = $trigger;
               }
       }

 
// get all hosts from each groupid
    
foreach($groups as $group) {
       
$groupname $group->name;
       
$hosts $group->hosts;

       
usort($hosts, function ($a$b) {
               if (
$a->name == $b) return 0;
               return (
$a->name $b->name ? -1);
       });

        if (
$hosts) {
        
$count "0";

                                
$hostid $host->hostid;
                                
$hostname $host->name;
                                
$maintenance $host->maintenance_status;


                               if (
array_key_exists($hostid$hostTriggers)) {

                                        
// Highest Priority error

                                       
$hostboxprio $hostTriggers[$hostid][0]->priority;
                                        
//First filter the hosts that are in maintenance and assign the maintenance class if is true
                                        
if ($maintenance != "0") {
                                                echo 
"<ddiv class=\"hostbox maintenance\">";

                                        }
                                        echo 
"<ddiv class=\"title\">" $hostname "</ddiv><ddiv class=\"hostid\">" $hostid "</ddiv>";
                                        
$count "0";

                                       foreach (
$hostTriggers[$hostid] as $event) {
                                                if (
$count <= ) {
                                                                
$priority $event->priority;
                                                                
$description $event->description;

         if (
$count != "0") {echo "</ddiv>";}
        }
     }
    
$api->userLogout();
 
?>
 <!-- Second piece of js to gracefully reload the page (value in ms) -->
 <script>


<!-- Second piece of js to gracefully reload the page (value in ms) -->
<script>
    function ReloadPage() {
       location.reload();
    };
    $(document).ready(function() {
      setTimeout("ReloadPage()", 60000);
    });
</script>  
</body>
</html>
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 14:50.