Ad Widget

Collapse

Zabbix Trigger Dashboard

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • incama
    Member
    • Jan 2015
    • 65

    #1

    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:
    Zabbix Dashboard. Contribute to incama/Zabbix-Dashboard development by creating an account on GitHub.
  • noeand
    Junior Member
    • Apr 2014
    • 24

    #2
    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!

    Comment

    • rocksteady
      Junior Member
      • Apr 2010
      • 26

      #3
      Originally posted by noeand
      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

      Comment

      • AlexYoung
        Member
        • Jul 2013
        • 37

        #4
        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.

        Comment

        • BDiE8VNy
          Senior Member
          • Apr 2010
          • 680

          #5
          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>

          Comment

          • AlexYoung
            Member
            • Jul 2013
            • 37

            #6
            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.

            Comment

            • BDiE8VNy
              Senior Member
              • Apr 2010
              • 680

              #7
              Originally posted by AlexYoung
              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?

              Comment

              • AlexYoung
                Member
                • Jul 2013
                • 37

                #8
                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>

                Comment

                • BDiE8VNy
                  Senior Member
                  • Apr 2010
                  • 680

                  #9
                  The lines in my diff having '-' as first character indicate removed lines!

                  Comment

                  • AlexYoung
                    Member
                    • Jul 2013
                    • 37

                    #10
                    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>

                    Comment

                    • Lurnux
                      Junior Member
                      • May 2014
                      • 22

                      #11
                      Thanks BDiE8VNy, works great, at least for me.

                      AlexYoung, try with this already patched file attached to this post.
                      Attached Files

                      Comment

                      • incama
                        Member
                        • Jan 2015
                        • 65

                        #12
                        Hi BDiE8VNy,

                        Can you share the complete file with me? I'm very interested in speeding up the load times.

                        Originally posted by BDiE8VNy
                        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 :\

                        Comment

                        • Diwahar
                          Junior Member
                          • Sep 2014
                          • 15

                          #13
                          Zabbix Trigger Dashboard

                          Hi,

                          is it possible to create a dropdown menu. so that if a particular group is selected only that group details will be shown below.

                          can someone share ur thoughts how to do that?





                          Originally posted by incama
                          Hi BDiE8VNy,

                          Can you share the complete file with me? I'm very interested in speeding up the load times.

                          Comment

                          • waardd
                            Member
                            • Aug 2014
                            • 82

                            #14
                            The idea is great but i only get the clock and "Your hostgroup" on a grey backdrop.
                            No further blocks or info....

                            What am i missing?

                            Comment

                            • Diwahar
                              Junior Member
                              • Sep 2014
                              • 15

                              #15
                              Zabbix Trigger Dashboard

                              @waardd: if you select a hostgroup, host related that group that should display with the trigger value of that host.

                              Got my question?

                              Originally posted by waardd
                              The idea is great but i only get the clock and "Your hostgroup" on a grey backdrop.
                              No further blocks or info....

                              What am i missing?

                              Comment

                              Working...