Ad Widget

Collapse

Adding Graphs/History/Latest data to Notifications

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • untergeek
    Senior Member
    Zabbix Certified Specialist
    • Jun 2009
    • 512

    #1

    Adding Graphs/History/Latest data to Notifications

    I have created a blog post on this subject here.

    For a brief synopsis, I have created a new php script I call rehistory.php which takes 1 or 2 variables passed and redirects to the actual Zabbix page for latest data, graph, or history.

    This has proven incredibly useful for us.
  • Jesster
    Junior Member
    • Mar 2007
    • 11

    #2
    This sounds pretty slick! - I'm trying to get mine working (v1.8.5) and get an error when I click on the URL via the Action.

    When I click on Graph or Latest Data URLs, I get a Zabbix error:


    Critical error. Field [hostid] is not integer


    Sample URL (after redirection):

    /history.php?action=showgraph&itemid=

    I'm assuming I've just done something, wrong.. any suggestions?

    Comment

    • untergeek
      Senior Member
      Zabbix Certified Specialist
      • Jun 2009
      • 512

      #3
      You've tested this with actual trigger IDs? What does the URL look like that you clicked on?

      Please include the triggerid as it appears, e.g.

      rehistory.php?triggerid=12345&displaytype=graph
      Last edited by untergeek; 20-05-2011, 18:51. Reason: URL too long, just put URI portion in

      Comment

      • untergeek
        Senior Member
        Zabbix Certified Specialist
        • Jun 2009
        • 512

        #4
        You can edit rehistory.php to not redirect and give some debugging information as follows.

        Comment out the line that has header( $urlpath . $uri); and add the following, like this:

        PHP Code:
        //  header( $urlpath . $uri);
        echo 'mydisplay = ' $mydisplay '<br />';
        echo 
        'triggerid = ' $triggerid '<br />';
        echo 
        'itemid = ' $itemresult['itemid'] . '<br />';
        echo 
        'valuetype = ' $value_type_result['value_type'] . '<br />';
        echo 
        'host = ' $hostresult['hostid'] . '<br />'

        Comment

        • Jesster
          Junior Member
          • Mar 2007
          • 11

          #5
          Code:
          Acknowledge: https://zabbix.example.net/acknow.php?eventid=127226
          DateTimeNOW: 2011.05.20 10:45:12
          EventDateTIME: 2011.05.20 10:45:05
          EventAge: 0m
          ItemName: ICMP Ping Performance
          ItemLastValue: 490.37 ms
          Comment: during last 2 minutes (120), the minimum value is greater than 300 (300ms latency)
          Graph: https://zabbix.example.net/rehistory.php?triggerid=32007&displaytype=graph
          Latest Data: https://zabbix.example.net/rehistory.php?triggerid=32007
          I modified rehistory.php to correct the URL being generated (removed the '/zabbix/' part)
          I will turn on the debugging as you suggested

          Update:
          Clicking "Latest Data" After debug edit:

          Code:
          mydisplay = latest
          triggerid = 32007
          itemid = 
          valuetype = 
          host =
          Last edited by Jesster; 20-05-2011, 21:19.

          Comment

          • untergeek
            Senior Member
            Zabbix Certified Specialist
            • Jun 2009
            • 512

            #6
            I think I know where the problem is. It appears that the SQL queries don't work for you in doing the reverse lookup from the triggerid. That is probably because you're not using Oracle (we are).

            Try removing the "where rownum=1" and replacing it with "LIMIT 1" and see if that helps.

            Comment

            • Jesster
              Junior Member
              • Mar 2007
              • 11

              #7
              I changed it to the following, however I still get the same problem:

              Code:
              $itemresult = DBfetch(DBselect('select itemid from (select itemid from functions where triggerid=' . $triggerid . ' order by itemid) LIMIT 1'));
              Code:
              mydisplay = latest
              triggerid = 32007
              itemid = 
              valuetype = 
              host =

              Comment

              • untergeek
                Senior Member
                Zabbix Certified Specialist
                • Jun 2009
                • 512

                #8
                What happens if you run the following queries against your db?


                Code:
                select itemid from functions where triggerid=32007 order by itemid;
                
                select itemid from (select itemid from functions where triggerid=32007 order by itemid) LIMIT 1;

                Comment

                • Jesster
                  Junior Member
                  • Mar 2007
                  • 11

                  #9
                  Code:
                  mysql> select itemid from functions where triggerid=32007 order by itemid;
                  +--------+
                  | itemid |
                  +--------+
                  |  76805 | 
                  +--------+
                  1 row in set (0.00 sec)
                  
                  mysql> 
                  mysql> select itemid from (select itemid from functions where triggerid=32007 order by itemid) LIMIT 1;
                  ERROR 1248 (42000): Every derived table must have its own alias
                  mysql>

                  Comment

                  • untergeek
                    Senior Member
                    Zabbix Certified Specialist
                    • Jun 2009
                    • 512

                    #10
                    Okay, it is the way the SQL is formatted.

                    Try this updated version of the whole script:

                    PHP Code:
                    <?php
                    // # $Rev:: 1062          $:  Revision of last commit
                    // # $Author:: aaronm     $:  Author of last commit
                    // # $Date:: 2011-05-20 1#$:  Date of last commit

                    require_once('include/config.inc.php');


                    $fqdn $_SERVER['SERVER_NAME'];
                    if(isset(
                    $_SERVER['HTTPS'])){
                      
                    $http 'https://';
                    }
                    else {
                      
                    $http 'http://';
                    }

                    $urlpath 'Location: ' $http $fqdn '/zabbix';

                    $mydisplay $_GET['displaytype'];
                    if(!isset(
                    $_GET['displaytype'])){
                      
                    $mydisplay 'latest';
                    }

                    if(isset(
                    $_GET['triggerid'])){
                      
                    $triggerid $_GET['triggerid'];
                      
                    $limiter 'LIMIT 1';
                      
                    $itemresultquery 'select itemid from functions where triggerid=' $triggerid ' order by itemid ' $limiter;

                      if(
                    $DB["TYPE"] == "ORACLE"){
                        
                    $limiter 'where rownum=1';
                        
                    $itemresultquery 'select itemid from (select itemid from functions where triggerid=' $triggerid ' order by itemid) ' $limiter;
                      }
                      
                    $itemresult DBfetch(DBselect($itemresultquery));
                      
                    $value_type_result DBfetch(DBselect('select value_type from items where itemid='.$itemresult['itemid']));
                      
                    $hostresult DBfetch(DBselect('select hostid from items where itemid='.$itemresult['itemid']));
                      if(
                    $mydisplay !== 'latest'){
                        if(
                    $value_type_result['value_type'] == || $value_type_result['value_type'] == 3){
                          
                    $mydisplay 'graph';
                        }
                        else {
                          
                    $mydisplay 'history';
                        }
                      }

                      if(
                    $mydisplay == 'graph'){
                        
                    $uri '/history.php?action=showgraph&itemid=' $itemresult['itemid'];
                      }
                      if(
                    $mydisplay == 'history'){
                        
                    $uri '/history.php?action=showvalues&period=3600&itemid=' $itemresult['itemid'];
                      }

                      if(
                    $mydisplay == 'latest'){
                        
                    $uri '/latest.php?hostid=' $hostresult['hostid'];
                      }
                      
                    header$urlpath $uri);
                    //  echo 'itemresultquery = ' . $itemresultquery . '<br />'; 
                    //  echo 'mydisplay = ' . $mydisplay . '<br />'; 
                    //  echo 'triggerid = ' . $triggerid . '<br />'; 
                    //  echo 'itemid = ' . $itemresult['itemid'] . '<br />'; 
                    //  echo 'valuetype = ' . $value_type_result['value_type'] . '<br />'; 
                    //  echo 'host = ' . $hostresult['hostid'] . '<br />'; 

                    }
                    ?>

                    Comment

                    • Jesster
                      Junior Member
                      • Mar 2007
                      • 11

                      #11
                      success! Thanks

                      Comment

                      • untergeek
                        Senior Member
                        Zabbix Certified Specialist
                        • Jun 2009
                        • 512

                        #12
                        No problem. Thanks for helping me make it more platform agnostic.

                        I will update it on my blog now.

                        Comment

                        • cucu
                          Junior Member
                          • Jun 2011
                          • 1

                          #13
                          oh,just in time!

                          i wanna to do the same thing also!thank you !

                          Comment

                          Working...