近期在部署zabbix时发现一个问题,在首页的仪表盘中显示的是hostname,不少若是没改默认主机名根本不知道是那台机器报警php
本人版本为zabbix4.0.5数据库
修改后的效果:segmentfault
需求加入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 ]));
问题:这样改只是仪表盘中改了,在问题的菜单中并无,但愿哪位能补充一下