Skip to content

Instantly share code, notes, and snippets.

@BlueSkyDetector
Last active December 13, 2015 17:58
Show Gist options
  • Save BlueSkyDetector/4951571 to your computer and use it in GitHub Desktop.
Save BlueSkyDetector/4951571 to your computer and use it in GitHub Desktop.
zabbix host list view
<?php
/*
** Zabbix
** Copyright (C) 2001-2011 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
require_once dirname(__FILE__).'/include/config.inc.php';
require_once dirname(__FILE__).'/include/hosts.inc.php';
require_once dirname(__FILE__).'/include/html.inc.php';
$page['title'] = _('host_lists');
$page['file'] = 'search.php';
$page['hist_arg'] = array();
$page['type'] = detect_page_type(PAGE_TYPE_HTML);
require_once dirname(__FILE__).'/include/page_header.php';
// VAR TYPE OPTIONAL FLAGS VALIDATION EXCEPTION
$fields = array(
'type'=> array(T_ZBX_INT, O_OPT, P_SYS, IN('0,1'), null),
//ajax
'favobj'=> array(T_ZBX_STR, O_OPT, P_ACT, null, null),
'favref'=> array(T_ZBX_STR, O_OPT, P_ACT, NOT_EMPTY, 'isset({favobj})'),
'favstate'=> array(T_ZBX_INT, O_OPT, P_ACT, NOT_EMPTY, null),
);
check_fields($fields);
// ACTION /////////////////////////////////////////////////////////////////////////////
if ((PAGE_TYPE_JS == $page['type']) || (PAGE_TYPE_HTML_BLOCK == $page['type'])) {
require_once dirname(__FILE__).'/include/page_footer.php';
exit();
}
$admin = in_array($USER_DETAILS['type'], array(
USER_TYPE_ZABBIX_ADMIN,
USER_TYPE_SUPER_ADMIN
));
$rows_per_page = $USER_DETAILS['rows_per_page'];
$hostWidget = new CWidget('host_wdgt');
// Header
$hostWidget->setClass('header');
$hostWidget->addHeader(array(
), SPACE);
// FIND Hosts
$params = array(
'nodeids' => get_current_nodeid(true),
'limit' => $rows_per_page,
'selectGroups' => API_OUTPUT_EXTEND,
'selectInterfaces' => API_OUTPUT_EXTEND,
'selectItems' => API_OUTPUT_COUNT,
'selectTriggers' => API_OUTPUT_COUNT,
'selectGraphs' => API_OUTPUT_COUNT,
'selectApplications' => API_OUTPUT_COUNT,
'selectScreens' => API_OUTPUT_COUNT,
'output' => array('name', 'status'),
);
$hosts = API::Host()->get($params);
order_result($hosts, 'name');
$viewCount = count($hosts);
$table = new CTableInfo();
$table->setHeader(array(
ZBX_DISTRIBUTED ? new CCol(_('Node')) : null,
new CCol(_('Hosts')),
new CCol(_('IP')),
new CCol(_('DNS')),
new CCol(_('Latest data')),
new CCol(_('Triggers')),
new CCol(_('Events')),
new CCol(_('Screens')),
new CCol(_('Applications')),
new CCol(_('Items')),
new CCol(_('Triggers')),
new CCol(_('Graphs')),
));
foreach ($hosts as $hnum => $host) {
$hostid = $host['hostid'];
$interface = reset($host['interfaces']);
$host['ip'] = $interface['ip'];
$host['dns'] = $interface['dns'];
$host['port'] = $interface['port'];
$style = $host['status'] == HOST_STATUS_NOT_MONITORED ? 'on' : null;
$group = reset($host['groups']);
$link = 'groupid='.$group['groupid'].'&hostid='.$hostid.'&switch_node='.id2nodeid($hostid);
$caption = $host['name'];
$host_link = new CLink($caption, 'hosts.php?form=update&'.$link, $style);
$applications_link = array(
new CLink(_('Applications'), 'applications.php?'.$link),
' ('.$host['applications'].')'
);
$items_link = array(
new CLink(_('Items'), 'items.php?filter_set=1&'.$link),
' ('.$host['items'].')'
);
$triggers_link = array(
new CLink(_('Triggers'), 'triggers.php?'.$link),
' ('.$host['triggers'].')'
);
$graphs_link = array(
new CLink(_('Graphs'), 'graphs.php?'.$link),
' ('.$host['graphs'].')'
);
$hostip = $host['ip'];
$hostdns = $host['dns'];
$table->addRow(array(
get_node_name_by_elid($hostid, true),
$host_link,
$hostip,
$hostdns,
new CLink(_('Latest data'), 'latest.php?'.$link),
new CLink(_('Triggers'), 'tr_status.php?'.$link),
new CLink(_('Events'), 'events.php?'.$link),
new CLink(_('Screens'), 'host_screen.php?hostid='.$hostid),
$applications_link,
$items_link,
$triggers_link,
$graphs_link,
));
}
$sysmap_menu = get_icon('menu', array('menu' => 'sysmaps'));
$wdgt_hosts = new CUIWidget('search_hosts', $table);
$wdgt_hosts->setHeader(_('Hosts'), SPACE);
$wdgt_hosts->setFooter(_s('Displaying %1$s found', $viewCount));
$hostWidget->addItem(new CDiv($wdgt_hosts));
//----------------
$hostWidget->show();
require_once dirname(__FILE__).'/include/page_footer.php';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment