Ad Widget

Collapse

Version Pre 1.7.0 Build 6836 -- Template Linkage

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Palmertree
    Senior Member
    • Sep 2005
    • 746

    #1

    Version Pre 1.7.0 Build 6836 -- Template Linkage

    Hosts and Templates are showing up under the column "Templates" in "Template Linkage" on the first screen where an admin should pick a template to link to. This could cause a mess if someone linked a host to another host.

    So if a admin goes to
    Configuration -> Hosts
    Drop Down: Template Linkage

    Host will show up under the Templates column in "Template Linkage". It does not happen all the time. I see it mostly of the time if I go to "Host" in the drop down while in host configuration and select "all" for the group and then go back to "Template Linkage"

    The following user definitions are being used in the defines.inc.php file:
    Code:
    /* USER DEFINES */
    
            define('ZBX_LOGIN_ATTEMPTS',    5);
            define('ZBX_LOGIN_BLOCK',               30); // sec
    
            define('TRIGGERS_OPTION_DISABLED',              0);             // reserved
            define('TRIGGERS_OPTION_ONLYTRUE',              1);             // use 0 to disable
            define('TRIGGERS_OPTION_ALL',                   2);             // use 0 to disable
            define('TRIGGERS_OPTION_NOFALSEFORB',   0);             // use 0 to disable
    
            define('TRIGGER_FALSE_PERIOD',                  1800);  // 30min,  0 - disable
            define('TRIGGER_BLINK_PERIOD',                  1800);  // 30min,  0 - disable
    
            define('EVENTS_OPTION_DISABLED',                0);             //      reserved
            define('EVENTS_OPTION_NOEVENT',                 1);             //      use 0 to disable
            define('EVENTS_OPTION_ALL',                             2);             //      use 0 to disable
            define('EVENTS_OPTION_NOT_ACK',                 3);             //      use 0 to disable
            define('EVENTS_OPTION_ONLYTRUE_NOTACK', 4);             //      use 0 to disable
            define('EVENTS_OPTION_NOFALSEFORB',             5);             //  reserved for TRIGGERS_OPTION_NOFALSEFORB, to disable set TRIGGERS_OPTION_NOFALSEFORB to 0
    
            define('ZBX_MIN_PERIOD', 3600);                                 // ~1 hour
            define('ZBX_MAX_PERIOD', 12*31*24*3600);                // ~1 year
            define('ZBX_PERIOD_DEFAULT', ZBX_MIN_PERIOD);
    
            define('ZBX_DROPDOWN_FIRST_ENTRY',              0);             // 0 - NONE, 1 - ALL
            define('ZBX_DROPDOWN_FIRST_REMEMBER',   1);             // 0 - do NOT remember, 1 - do remember
    
            define('ZBX_DISABLE_MENU_CACHE',                0);             // set 1 to disable
    Last edited by Palmertree; 27-02-2009, 03:43.
  • Palmertree
    Senior Member
    • Sep 2005
    • 746

    #2
    Here is the fix for the Template Linkage page and Template Linkage form:

    Code:
    diff -ruN zabbix-original/frontends/php/hosts.php zabbix/frontends/php/hosts.php
    --- zabbix-original/frontends/php/hosts.php    2009-02-28 10:03:40.000000000 -0500
    +++ zabbix/frontends/php/hosts.php    2009-03-01 09:49:17.000000000 -0500
    @@ -1238,15 +1238,18 @@
                 validate_group($PAGE_GROUPS, $PAGE_HOSTS, $PAGE_HOSTS, false);
                 break;
             case 2:
    -            $options = array('only_current_node','templated_hosts');
    +            if(isset($_REQUEST['form']))
    +                $options = array('only_current_node','not_proxy_hosts','allow_all');
    +            else
    +                $options = array('only_current_node','templated_hosts','allow_all');
                 if(isset($_REQUEST['form']) || isset($_REQUEST['massupdate'])) array_push($options,'do_not_select_if_empty');
    -            
    +
                 foreach($options as $option) $params[$option] = 1;
                 $PAGE_GROUPS = get_viewed_groups(PERM_READ_WRITE, $params);
     
    -            $params = array();    
    -            $options = array('only_current_node','not_proxy_hosts');
    -            foreach($options as $option) $params[$option] = 1;
    +//            $params = array();    
    +//            $options = array('only_current_node','not_proxy_hosts');
    +//            foreach($options as $option) $params[$option] = 1;
                 $PAGE_HOSTS = get_viewed_hosts(PERM_READ_WRITE, $available_groups, $params);    // more hosts
     
                 validate_group($PAGE_GROUPS, $PAGE_HOSTS, false);
    @@ -1650,55 +1653,75 @@
                                 new CSpan(SPACE.SPACE.'|'.SPACE.SPACE, 'divider'),
                                 S_FOUND.': ',$numrows,)
                                 );                            
    -            show_table_header($header);
    -        
    -            $table = new CTableInfo(S_NO_LINKAGES);
    -            $table->setHeader(array(S_TEMPLATES,S_HOSTS));
    -        
    -            $sql = 'SELECT h.* '.
    -                    ' FROM hosts h, hosts_groups hg '.
    -                    ' WHERE hg.groupid='.$_REQUEST['groupid'].
    -                        ' AND h.hostid=hg.hostid '.
    -                        ' AND '.DBcondition('h.hostid',$available_hosts).
    -                    ' ORDER BY h.host';
    -            $templates = DBSelect($sql);
    -            while($template = DBfetch($templates)){
    -            
    -                $hosts = DBSelect('SELECT DISTINCT h.host, h.hostid, h.status '.
    -                    ' FROM hosts h, hosts_templates ht '.
    -                    ' WHERE ht.templateid='.$template['hostid'].
    -                        ' AND ht.hostid=h.hostid '.
    -                        ' AND '.DBcondition('h.hostid',$available_hosts).
    -                    ' ORDER BY h.host');
    -                $host_list = array();
    -                while($host = DBfetch($hosts)){
    -                    $link = 'hosts.php?form=update&config=0&hostid='.$host['hostid'];
    -                    switch($host['status']){
    -                        case HOST_STATUS_MONITORED:
    -                            $style = null;
    -                            break;
    -                        case HOST_STATUS_TEMPLATE:
    -                            $style = 'unknown';
    -                            break;
    -                        default:
    -                            $style = 'on';
    -                    }
    +            show_table_header($header, $frmForm);
    +         
    +             $table = new CTableInfo(S_NO_LINKAGES);
    +             $table->setHeader(array(S_TEMPLATES,S_HOSTS));
    +                    
    +            $sql_from = '';
    +            $sql_where = '';
    +            if($_REQUEST['groupid'] > 0){
    +                $sql_from.= ',hosts_groups hg ';
    +                $sql_where.= ' AND hg.groupid='.$_REQUEST['groupid'].' AND hg.hostid=h.hostid ';
    +            } 
     
    -                    array_push($host_list, empty($host_list)?'':', ', new CLink(new CSpan($host['host'], $style), $link));
    -                }
    -                
    -                $table->addRow(array(        
    -                    new CCol(array(
    -                        new CLink($template['host'],'hosts.php?form=update&hostid='.
    -                            $template['hostid'].url_param('groupid').url_param('config'), 'action')
    -                        ),'unknown'),
    -                    empty($host_list)?'-':new CCol($host_list,'wraptext')
    -                ));
    -                $row_count++;
    +            $templates = array();
    +            $templateids = array();
    +            $sql = 'SELECT h.hostid, h.host '.
    +                    ' FROM hosts h '.$sql_from.
    +                    ' WHERE '.DBcondition('h.hostid',$available_hosts).
    +                        $sql_where.
    +                     ' ORDER BY h.host';
    +            $result = DBSelect($sql);
    +            while($template = DBfetch($result)) {
    +                $templateids[$template['hostid']] = $template['hostid'];
    +                $templates[$template['hostid']] = $template; 
    +            }
    +            
    +            $allowed_hosts = get_accessible_hosts_by_user($USER_DETAILS, PERM_READ_ONLY);
    +            
    +            $sql = 'SELECT h.host, h.hostid, h.status, ht.templateid '.
    +                     ' FROM hosts h, hosts_templates ht '.
    +                    ' WHERE ht.hostid=h.hostid '.
    +                        ' AND '.DBcondition('h.hostid', $allowed_hosts).
    +                        ' AND '.DBcondition('ht.templateid', $templateids).
    +                     ' ORDER BY host';
    +            $result = DBSelect($sql);
    +            while($host = DBfetch($result)){
    +                if(!isset($templates[$host['templateid']]['hosts'])) $templates[$host['templateid']]['hosts'] = array(); 
    +                $templates[$host['templateid']]['hosts'][] = $host;
                 }
                 
    -            $table->Show();
    -        }
    +            foreach($templates as $templateid => $template) {
    +                $host_list = array();
    +                
    +                if(isset($template['hosts'])) {
    +                    foreach($template['hosts'] as $host) {
    +                        switch($host['status']) {
    +                            case HOST_STATUS_NOT_MONITORED:
    +                                $style = 'on';
    +                                break;
    +                            case HOST_STATUS_TEMPLATE:
    +                                $style = 'unknown';
    +                                break;
    +                            default:
    +                                $style = null;
    +                        }                                        
    +                        array_push($host_list, empty($host_list)?'':', ', new CSpan($host['host'], $style));
    +                    }
    +                 }
    +                 
    +                 $table->addRow(array(        
    +                     new CCol(array(
    +                         new CLink($template['host'],'hosts.php?form=update&hostid='.
    +                             $template['hostid'].url_param('groupid').url_param('config'), 'action')
    +                        ), 'unknown'),
    +                     empty($host_list)?'-':new CCol($host_list,'wraptext')
    +                 ));
    +            }    
    +            $table->show();
    +            $row_count = $table->getNumRows();
    +        }        
     //----- END MODE -----
         }
         else if($_REQUEST['config']==4){

    Comment

    Working...