Ad Widget

Collapse

Modifiying the view of Inventory \ Hosts page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mbuyukkarakas
    Member
    • Aug 2014
    • 49

    #1

    Modifiying the view of Inventory \ Hosts page

    Hello all,

    I would like to modify Inventory \ Hosts page's layout. I want to display different fields in this page, and after a little search found the hostinventories.php file.
    But PHP is far from me and dont know how to change the displayed fields.

    I found this piece of code and tried to change some fields (e.g. instead of 'type' field, put 'Location Latitude' but it didnt worked.

    PHP Code:
    if ($data['pageFilter']->groupsSelected) {
    // which inventory fields we will need for displaying
    $requiredInventoryFields = [
    'name',
    'type',
    'os',
    'serialno_a',
    'tag',
    'macaddress_a'
    ]; 
    Anybody can help me to change the view of this page, please ?

    Thank you.
    Mehmet
  • acevizci
    Junior Member
    • Feb 2023
    • 6

    #2
    Hi Mehmet,

    It's a bit late but the solution is as follows.


    PHP Code:
    // create table
    $url = (new CUrl('hostinventories.php'))->getUrl();

    $table = (new CTableInfo())
            ->
    setHeader([
                    
    make_sorting_header(_('Host'), 'name'$this->data['sort'], $this->data['sortorder'], $url),
                    
    _('Group'),
                    
    make_sorting_header(_('Name'), 'pr_name'$this->data['sort'], $this->data['sortorder'], $url),
                    
    make_sorting_header(_('custom Name'), 'pr_macaddress_a'$this->data['sort'], $this->data['sortorder'], $url),
                    
    make_sorting_header(_('custom name 2'), 'pr_type'$this->data['sort'], $this->data['sortorder'], $url),
                    
    make_sorting_header(_('Marka/Model'), 'pr_tag'$this->data['sort'], $this->data['sortorder'], $url),
                    
    make_sorting_header(_('Serial number A'), 'pr_serialno_a'$this->data['sort'], $this->data['sortorder'], $url),
                    
    make_sorting_header(_('OS'), 'pr_os'$this->data['sort'], $this->data['sortorder'], $url)

            ]);

    foreach (
    $this->data['hosts'] as $host) {
            
    $hostGroups = [];
            foreach (
    $host['groups'] as $group) {
                    
    $hostGroups[] = $group['name'];
            }
            
    natsort($hostGroups);
            
    $hostGroups implode(', '$hostGroups);

            
    $row = [
                    (new 
    CLink($host['name'], (new CUrl('hostinventories.php'))->setArgument('hostid'$host['hostid'])))
                            ->
    addClass($host['status'] == HOST_STATUS_NOT_MONITORED ZBX_STYLE_RED null),
                    
    $hostGroups,
                    
    zbx_str2links($host['inventory']['name']),
                    
    zbx_str2links($host['inventory']['macaddress_a']),
                    
    zbx_str2links($host['inventory']['type']),
                    
    zbx_str2links($host['inventory']['tag']),
                    
    zbx_str2links($host['inventory']['serialno_a']),
                    
    zbx_str2links($host['inventory']['os'])
    ​ 
    this form is located under /usr/share/zabbix/include/views/inventory.host.list.php

    Thanks,
    Aykut

    Comment

    Working...