zabbix4.0修改儀表盤中的問題列表(加入IP、羣組顯示)


主機名顯示 IP+主機名的問題已經有更好的解決辦法,參見《zabbix4.0蛇皮走位之主機名稱(hostname)加入ip地址》



近期在部署zabbix時發現一個問題,在首頁的儀表盤中顯示的是hostname,不少若是沒改默認主機名根本不知道是那臺機器報警php

本人版本爲zabbix4.0.5數據庫

修改後的效果:segmentfault

clipboard.png

需求加入IP信息:
實現方式:
一、修改主機詳情中的可見名稱app

手工修改(不推薦,主機多時不方便,並且IP變了以後麻煩);
在數據庫中建觸發器或者定時任務(修改hosts表的name字段,ip信息在interface表中)

二、直接修改php文件url

本人不會php,參考https://blog.csdn.net/xsm5223508/article/details/78696993這篇文章中的內容實現

修改文件
/usr/share/zabbix/app/views/monitoring.widget.problems.view.php
注意備份原文件.

原代碼spa

$table = (new CTableInfo())
    ->setHeader(array_merge($header, [
        $show_recovery_data ? _('Recovery time') : null,
        $show_recovery_data ? _('Status') : null,
        _('Info'),
        ($data['sortfield'] === 'host') ? [_('Host'), $sort_div] : _('Host'),
        [
            ($data['sortfield'] === 'name') ? [_('Problem'), $sort_div] : _('Problem'),
            ' • ',
            ($data['sortfield'] === 'severity') ? [_('Severity'), $sort_div] : _('Severity')
        ],
        $data['fields']['show_latest_values'] ? _('Latest values') : null,
        _('Duration'),
        _('Ack'),
        _('Actions'),
        $data['fields']['show_tags'] ? _('Tags') : null
    ]));

修改後代碼:.net

$table = (new CTableInfo())
    ->setHeader(array_merge($header, [
        $show_recovery_data ? _('Recovery time') : null,
        $show_recovery_data ? _('Status') : null,
        _('Info'),
        _('Group'), //加一個羣組
        ($data['sortfield'] === 'host') ? [_('Host'), $sort_div] : _('Host'),
        _('Interface'), //加一個ip
        [
            ($data['sortfield'] === 'name') ? [_('Problem'), $sort_div] : _('Problem'),
            ' • ',
            ($data['sortfield'] === 'severity') ? [_('Severity'), $sort_div] : _('Severity')
        ],
        $data['fields']['show_latest_values'] ? _('Latest values') : null,
        _('Duration'),
        _('Ack'),
        _('Actions'),
        $data['fields']['show_tags'] ? _('Tags') : null
    ]));

3d

$table->addRow(array_merge($row, [

以上加入代碼code

$hostid = $trigger['hosts'][0]['hostid'];
    $groups = API::HostGroup()->get([
        'output' => ['groupid', 'name'],
        'groupids' => null,
        'hostids' => $hostid,
        'monitored_hosts' => true,
        'preservekeys' => true
    ]);
    $group = array_shift($groups);
    $group = new CCol($group['name']);


    $hostinterfaces = API::HostInterface()->get([
        'output' => ['interfaceid', 'ip'],
        'interfaceids' => null,
        'hostids' => $hostid
    ]);
    $hostinterfaces = array_shift($hostinterfaces);
    $hostinterfaces = new CCol($hostinterfaces['ip']);

在table的數據中加入代碼orm

$table->addRow(array_merge($row, [
        $show_recovery_data ? $cell_r_clock : null,
        $show_recovery_data ? $cell_status : null,
        makeInformationList($info_icons),
        $group,
        $triggers_hosts[$trigger['triggerid']],
        $hostinterfaces,
        $description,
        $data['fields']['show_latest_values'] ? CScreenProblem::getLatestValues($trigger['items']) : null,
        (new CCol(zbx_date2age($problem['clock'], ($problem['r_eventid'] != 0) ? $problem['r_clock'] : 0)))
            ->addClass(ZBX_STYLE_NOWRAP),
        (new CLink($problem['acknowledged'] == EVENT_ACKNOWLEDGED ? _('Yes') : _('No'), $problem_update_url))
            ->addClass($problem['acknowledged'] == EVENT_ACKNOWLEDGED ? ZBX_STYLE_GREEN : ZBX_STYLE_RED)
            ->addClass(ZBX_STYLE_LINK_ALT),
        makeEventActionsIcons($problem['eventid'], $data['data']['actions'], $data['data']['mediatypes'],
            $data['data']['users'], $data['config']
        ),
        $data['fields']['show_tags'] ? $data['data']['tags'][$problem['eventid']] : null
    ]));

問題:這樣改只是儀表盤中改了,在問題的菜單中並無,但願哪位能補充一下

相關文章
相關標籤/搜索