Ad Widget

Collapse

PATCH: 1.4.1: Allow screens to be defined on templates

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cpicton
    Member
    • Nov 2006
    • 35

    #1

    PATCH: 1.4.1: Allow screens to be defined on templates

    Hi all

    This is a preliminary patch, which allows screens to be defined on templates. This allows one to define a screen, viewable for multiple hosts, without having to define a screen per host, with the same set of graphs in each screen.

    There are still some issues, but it works for me.

    Please give me any comments or suggestions.

    Chris

    Code:
    diff -uNr zabbix-1.4.1.orig/frontends/php/include/graphs.inc.php zabbix-1.4.1/frontends/php/include/graphs.inc.php
    --- zabbix-1.4.1.orig/frontends/php/include/graphs.inc.php      2007-06-29 22:50:28.000000000 +0200
    +++ zabbix-1.4.1/frontends/php/include/graphs.inc.php   2007-07-01 12:30:44.000000000 +0200
    @@ -605,7 +605,7 @@
    
            function        navigation_bar($url,$ext_saved_request=NULL)
            {
    -               $saved_request = array("screenid","itemid","action","from","fullscreen");
    +               $saved_request = array("screenid","itemid","action","from","fullscreen","hostid");
    
                    if(is_array($ext_saved_request))
                            $saved_request = array_merge($saved_request, $ext_saved_request);
    diff -uNr zabbix-1.4.1.orig/frontends/php/include/screens.inc.php zabbix-1.4.1/frontends/php/include/screens.inc.php
    --- zabbix-1.4.1.orig/frontends/php/include/screens.inc.php     2007-06-29 22:50:28.000000000 +0200
    +++ zabbix-1.4.1/frontends/php/include/screens.inc.php  2007-07-01 12:28:35.000000000 +0200
    @@ -219,7 +219,7 @@
            }
    
            // editmode: 0 - view with actions, 1 - edit mode, 2 - view without any actions
    -       function get_screen($screenid, $editmode, $effectiveperiod=NULL)
    +       function get_screen($screenid, $editmode, $effectiveperiod=NULL, $hostid=NULL)
            {
                    if(!screen_accessiable($screenid, $editmode ? PERM_READ_WRITE : PERM_READ_ONLY))
                            access_deny();
    @@ -325,6 +325,10 @@
                                    }
                                    elseif( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_GRAPH) )
                                    {
    +                                       if ($hostid != NULL)
    +                                       {
    +                                               $resourceid = graphid_for_hostid($resourceid, $hostid);
    +                                       }
                                            if($editmode == 0)
                                                    $action = "charts.php?graphid=$resourceid".url_param("period").
                                                             url_param("inc").url_param("dec");
    @@ -444,6 +448,21 @@
                    return $table;
            }
    
    +       function        graphid_for_hostid($graphid, $hostid)
    +       {
    +               $result = DBselect("SELECT distinct g.graphid, g.name, h.host ".
    +                                  "FROM graphs g LEFT JOIN graphs_items gi on g.graphid=gi.graphid ".
    +                                  "LEFT JOIN items i on gi.itemid=i.itemid ".
    +                                  "LEFT JOIN hosts h on h.hostid=i.hostid ".
    +                                  "WHERE g.templateid=$graphid and h.hostid=$hostid"
    +                                  );
    +               $newid = DBfetch($result);
    +               if (isset($newid["graphid"])) {
    +                       return $newid["graphid"];
    +               }
    +               return $graphid;
    +       }
    +
            function        slideshow_accessiable($slideshowid, $perm)
            {
                    global $USER_DETAILS;
    diff -uNr zabbix-1.4.1.orig/frontends/php/screens.php zabbix-1.4.1/frontends/php/screens.php
    --- zabbix-1.4.1.orig/frontends/php/screens.php 2007-06-29 22:50:30.000000000 +0200
    +++ zabbix-1.4.1/frontends/php/screens.php      2007-07-01 12:32:36.000000000 +0200
    @@ -49,6 +49,7 @@
                    "config"=>              array(T_ZBX_INT, O_OPT, P_SYS,  IN("0,1"),      null), // 0 - screens, 1 - slides
    
                    "elementid"=>           array(T_ZBX_INT, O_OPT, P_SYS|P_NZERO,  DB_ID,NULL),
    +                "hostid"=>              array(T_ZBX_INT, O_OPT,  P_SYS,         DB_ID,NULL),
                    "step"=>                array(T_ZBX_INT, O_OPT,  P_SYS,         BETWEEN(0,65535),NULL),
                    "dec"=>                 array(T_ZBX_INT, O_OPT,  P_SYS,         BETWEEN(0,65535*65535),NULL),
                    "inc"=>                 array(T_ZBX_INT, O_OPT,  P_SYS,         BETWEEN(0,65535*65535),NULL),
    @@ -104,6 +105,23 @@
            unset($screen_correct);
            unset($first_screen);
    
    +       $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT);
    +       $cmbHosts = new CComboBox("hostid",$_REQUEST["hostid"],"submit()");
    +
    +                $cmbHosts->AddItem(0,S_ALL_SMALL);
    +                $sql = "select distinct h.hostid,h.host from hosts h,items i, graphs_items gi where h.status=".HOST_STATUS_MONITORED.
    +                        " and i.status=".ITEM_STATUS_ACTIVE." and h.hostid=i.hostid".
    +                        " and h.hostid not in (".$denyed_hosts.") and i.itemid=gi.itemid".
    +                        " order by h.host";
    +
    +        $result=DBselect($sql);
    +        while($row=DBfetch($result))
    +        {
    +                $cmbHosts->AddItem($row["hostid"],$row["host"]);
    +        }
    +        $form->AddItem(array(SPACE.S_HOST.SPACE,$cmbHosts));
    +
    +
            if( 0 == $config )
            {
                    $result = DBselect("select screenid as elementid,name from screens where ".DBid2nodeid("screenid")."=".$ZBX_CURNODEID." order by name");
    @@ -175,7 +193,7 @@
                    $effectiveperiod = navigation_bar_calc();
                    if( 0 == $config )
                    {
    -                       $element = get_screen($elementid, 0, $effectiveperiod);
    +                       $element = get_screen($elementid, 0, $effectiveperiod, $_REQUEST['hostid']);
                    }
                    else
                    {
  • starstream
    Junior Member
    • Jun 2007
    • 13

    #2
    Hi!
    This is a feature i would like to se implemented!

    What are the issues thats left?

    /m

    Comment

    • cpicton
      Member
      • Nov 2006
      • 35

      #3
      Issues are cosmetic

      When first browsing to the page, I get PHP var not defined errors. It should be an easy fix, but it is not bugging me yet

      Comment

      • starstream
        Junior Member
        • Jun 2007
        • 13

        #4
        Nothing more serious that that...
        I thought that my zabbix server would go up in smoke ...

        I will try the patch during the week and let you know.

        Cheers!

        Comment

        • Saftnase
          Member
          • Jul 2006
          • 30

          #5
          YES PLEASE IMPLEMENT THIS !!!!!
          This would save me hours of work with the monitoring project i am setting up

          Comment

          • kloczek
            Senior Member
            • Jun 2006
            • 1771

            #6
            Originally posted by cpicton
            Issues are cosmetic

            When first browsing to the page, I get PHP var not defined errors. It should be an easy fix, but it is not bugging me yet
            BTW discuss about zabbix improvements.
            Any progress on merge templates for screens to official svn tree ?
            Alexei ?
            And/or what is missing in this patch before merge this in official tree ?
            http://uk.linkedin.com/pub/tomasz-k%...zko/6/940/430/
            https://kloczek.wordpress.com/
            zapish - Zabbix API SHell binding https://github.com/kloczek/zapish
            My zabbix templates https://github.com/kloczek/zabbix-templates

            Comment

            • freak
              Member
              • Oct 2007
              • 52

              #7
              Originally posted by Saftnase
              YES PLEASE IMPLEMENT THIS !!!!!
              I second that

              Comment

              • cpicton
                Member
                • Nov 2006
                • 35

                #8
                I have picked up on one error which I will be fixing soon - If the host inherits the screen from a 'grandparent' template - ie, host is a member of TemplateA, which itself is a member of TemplateB, then the graphs don't display, if the screen was defined on TemplateB

                Will let you know when fixed.

                Comment

                • jonnjonzzn
                  Junior Member
                  • Sep 2007
                  • 18

                  #9
                  Yes, this is probably the most important functionality missing for us.

                  Patch does not apply cleanly to 1.4.2 code base? Will look into when able but if someone is really bored, please, by all means take a look!

                  I think this would just be a terrific piece for Zabbix I hope this functionality can be implemented for 1.4.3 (1.6).
                  Last edited by jonnjonzzn; 07-11-2007, 23:04.

                  Comment

                  • noxis
                    Senior Member
                    • Aug 2007
                    • 145

                    #10
                    Any chance of a 1.4.2 patch for this?

                    Comment

                    • Alexei
                      Founder, CEO
                      Zabbix Certified Trainer
                      Zabbix Certified SpecialistZabbix Certified Professional
                      • Sep 2004
                      • 5654

                      #11
                      Screen based templates will be implemented in 1.6. The functionality will be ready within 2-3 weeks in the latest code.
                      Alexei Vladishev
                      Creator of Zabbix, Product manager
                      New York | Tokyo | Riga
                      My Twitter

                      Comment

                      • sebelk
                        Member
                        • Nov 2007
                        • 72

                        #12
                        Originally posted by cpicton
                        Hi all

                        This is a preliminary patch, which allows screens to be defined on templates. This allows one to define a screen, viewable for multiple hosts, without having to define a screen per host, with the same set of graphs in each screen.

                        There are still some issues, but it works for me.

                        Please give me any comments or suggestions.

                        Chris

                        Code:
                        diff -uNr zabbix-1.4.1.orig/frontends/php/include/graphs.inc.php zabbix-1.4.1/frontends/php/include/graphs.inc.php
                        --- zabbix-1.4.1.orig/frontends/php/include/graphs.inc.php      2007-06-29 22:50:28.000000000 +0200
                        +++ zabbix-1.4.1/frontends/php/include/graphs.inc.php   2007-07-01 12:30:44.000000000 +0200
                        @@ -605,7 +605,7 @@
                        
                                function        navigation_bar($url,$ext_saved_request=NULL)
                                {
                        -               $saved_request = array("screenid","itemid","action","from","fullscreen");
                        +               $saved_request = array("screenid","itemid","action","from","fullscreen","hostid");
                        
                                        if(is_array($ext_saved_request))
                                                $saved_request = array_merge($saved_request, $ext_saved_request);
                        diff -uNr zabbix-1.4.1.orig/frontends/php/include/screens.inc.php zabbix-1.4.1/frontends/php/include/screens.inc.php
                        --- zabbix-1.4.1.orig/frontends/php/include/screens.inc.php     2007-06-29 22:50:28.000000000 +0200
                        +++ zabbix-1.4.1/frontends/php/include/screens.inc.php  2007-07-01 12:28:35.000000000 +0200
                        @@ -219,7 +219,7 @@
                                }
                        
                                // editmode: 0 - view with actions, 1 - edit mode, 2 - view without any actions
                        -       function get_screen($screenid, $editmode, $effectiveperiod=NULL)
                        +       function get_screen($screenid, $editmode, $effectiveperiod=NULL, $hostid=NULL)
                                {
                                        if(!screen_accessiable($screenid, $editmode ? PERM_READ_WRITE : PERM_READ_ONLY))
                                                access_deny();
                        @@ -325,6 +325,10 @@
                                                        }
                                                        elseif( ($screenitemid!=0) && ($resourcetype==SCREEN_RESOURCE_GRAPH) )
                                                        {
                        +                                       if ($hostid != NULL)
                        +                                       {
                        +                                               $resourceid = graphid_for_hostid($resourceid, $hostid);
                        +                                       }
                                                                if($editmode == 0)
                                                                        $action = "charts.php?graphid=$resourceid".url_param("period").
                                                                                 url_param("inc").url_param("dec");
                        @@ -444,6 +448,21 @@
                                        return $table;
                                }
                        
                        +       function        graphid_for_hostid($graphid, $hostid)
                        +       {
                        +               $result = DBselect("SELECT distinct g.graphid, g.name, h.host ".
                        +                                  "FROM graphs g LEFT JOIN graphs_items gi on g.graphid=gi.graphid ".
                        +                                  "LEFT JOIN items i on gi.itemid=i.itemid ".
                        +                                  "LEFT JOIN hosts h on h.hostid=i.hostid ".
                        +                                  "WHERE g.templateid=$graphid and h.hostid=$hostid"
                        +                                  );
                        +               $newid = DBfetch($result);
                        +               if (isset($newid["graphid"])) {
                        +                       return $newid["graphid"];
                        +               }
                        +               return $graphid;
                        +       }
                        +
                                function        slideshow_accessiable($slideshowid, $perm)
                                {
                                        global $USER_DETAILS;
                        diff -uNr zabbix-1.4.1.orig/frontends/php/screens.php zabbix-1.4.1/frontends/php/screens.php
                        --- zabbix-1.4.1.orig/frontends/php/screens.php 2007-06-29 22:50:30.000000000 +0200
                        +++ zabbix-1.4.1/frontends/php/screens.php      2007-07-01 12:32:36.000000000 +0200
                        @@ -49,6 +49,7 @@
                                        "config"=>              array(T_ZBX_INT, O_OPT, P_SYS,  IN("0,1"),      null), // 0 - screens, 1 - slides
                        
                                        "elementid"=>           array(T_ZBX_INT, O_OPT, P_SYS|P_NZERO,  DB_ID,NULL),
                        +                "hostid"=>              array(T_ZBX_INT, O_OPT,  P_SYS,         DB_ID,NULL),
                                        "step"=>                array(T_ZBX_INT, O_OPT,  P_SYS,         BETWEEN(0,65535),NULL),
                                        "dec"=>                 array(T_ZBX_INT, O_OPT,  P_SYS,         BETWEEN(0,65535*65535),NULL),
                                        "inc"=>                 array(T_ZBX_INT, O_OPT,  P_SYS,         BETWEEN(0,65535*65535),NULL),
                        @@ -104,6 +105,23 @@
                                unset($screen_correct);
                                unset($first_screen);
                        
                        +       $denyed_hosts = get_accessible_hosts_by_user($USER_DETAILS,PERM_READ_ONLY, PERM_MODE_LT);
                        +       $cmbHosts = new CComboBox("hostid",$_REQUEST["hostid"],"submit()");
                        +
                        +                $cmbHosts->AddItem(0,S_ALL_SMALL);
                        +                $sql = "select distinct h.hostid,h.host from hosts h,items i, graphs_items gi where h.status=".HOST_STATUS_MONITORED.
                        +                        " and i.status=".ITEM_STATUS_ACTIVE." and h.hostid=i.hostid".
                        +                        " and h.hostid not in (".$denyed_hosts.") and i.itemid=gi.itemid".
                        +                        " order by h.host";
                        +
                        +        $result=DBselect($sql);
                        +        while($row=DBfetch($result))
                        +        {
                        +                $cmbHosts->AddItem($row["hostid"],$row["host"]);
                        +        }
                        +        $form->AddItem(array(SPACE.S_HOST.SPACE,$cmbHosts));
                        +
                        +
                                if( 0 == $config )
                                {
                                        $result = DBselect("select screenid as elementid,name from screens where ".DBid2nodeid("screenid")."=".$ZBX_CURNODEID." order by name");
                        @@ -175,7 +193,7 @@
                                        $effectiveperiod = navigation_bar_calc();
                                        if( 0 == $config )
                                        {
                        -                       $element = get_screen($elementid, 0, $effectiveperiod);
                        +                       $element = get_screen($elementid, 0, $effectiveperiod, $_REQUEST['hostid']);
                                        }
                                        else
                                        {
                        Does this patch work in zabbix 1.4.2?

                        Comment

                        • cpicton
                          Member
                          • Nov 2006
                          • 35

                          #13
                          I have been running on 1.4.1 for a while now - I am about to update to 1.4.4, as I have been experiencing zabbix server and agent hangs.

                          I will update the screen template patch for 1.4.4

                          Chris

                          Comment

                          Working...