zabbix4.0修改仪表盘中的问题列表(加入IP、群组显示)

10次阅读

共计 2815 个字符,预计需要花费 8 分钟才能阅读完成。

近期在部署 zabbix 时发现一个问题,在首页的仪表盘中显示的是 hostname,很多如果没改默认主机名根本不知道是那台机器报警
本人版本为 zabbix4.0.5
修改后的效果:

需求加入 IP 信息:实现方式:1、修改主机详情中的可见名称
手工修改(不推荐,主机多时不方便,而且 IP 变了之后麻烦);
在数据库中建触发器或者定时任务(修改 hosts 表的 name 字段,ip 信息在 interface 表中)
2、直接修改 php 文件
本人不会 php,参考 https://blog.csdn.net/xsm5223508/article/details/78696993 这篇文章中的内容实现

修改文件
/usr/share/zabbix/app/views/monitoring.widget.problems.view.php
注意备份原文件.
原代码
$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
]));

修改后代码:
$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
]));


$table->addRow(array_merge($row, [
以上加入代码

$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 的数据中加入代码
$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
]));
问题:这样改只是仪表盘中改了,在问题的菜单中并没有,希望哪位能补充一下

正文完
 0