From 6299258c679f3dbe416e89414b16b2ef9f9c8a39 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Volker=20Fr=C3=B6hlich?= <volker.froehlich@meduniwien.ac.at>
Date: Fri, 27 Sep 2013 14:01:48 +0200
Subject: [PATCH] Improving search result display (technical names, interfaces) See ZBXNEXT-1371

- Show all interfaces in search results, as they are all considered
  while searching but there is no visible feedback
- Search technical names too
- Add technical name column to host and template search results
---
 search.php |   51 +++++++++++++++++++++++++++++++++++----------------
 1 files changed, 35 insertions(+), 16 deletions(-)

diff --git a/search.php b/search.php
index b13ef44..79d2f55 100644
--- a/search.php
+++ b/search.php
@@ -80,6 +80,7 @@ $params = array(
 	'nodeids' => get_current_nodeid(true),
 	'search' => array(
 		'name' => $search,
+		'host' => $search,
 		'dns' => $search,
 		'ip' => $search
 	),
@@ -93,7 +94,7 @@ $params = array(
 	'selectScreens' => API_OUTPUT_COUNT,
 	'selectHttpTests' => API_OUTPUT_COUNT,
 	'selectDiscoveries' => API_OUTPUT_COUNT,
-	'output' => array('name', 'status'),
+	'output' => array('name', 'host', 'status', 'proxy_hostid'),
 	'searchByAny' => true
 );
 $db_hosts = API::Host()->get($params);
@@ -129,8 +130,9 @@ $table = new CTableInfo(_('No hosts found.'));
 $table->setHeader(array(
 	ZBX_DISTRIBUTED ? new CCol(_('Node')) : null,
 	new CCol(_('Hosts')),
-	new CCol(_('IP')),
-	new CCol(_('DNS')),
+	new CCol(_('Names')),
+	new CCol(_('IP addresses')),
+	new CCol(_('DNS names')),
 	new CCol(_('Latest data')),
 	new CCol(_('Triggers')),
 	new CCol(_('Events')),
@@ -148,10 +150,12 @@ $table->setHeader(array(
 foreach ($hosts as $hnum => $host) {
 	$hostid = $host['hostid'];
 
-	$interface = reset($host['interfaces']);
-	$host['ip'] = $interface['ip'];
-	$host['dns'] = $interface['dns'];
-	$host['port'] = $interface['port'];
+    foreach ($host['interfaces'] as $interface) {
+        foreach (array('ip', 'dns', 'port') as $key) {
+            $host[$key][] = make_decoration($interface[$key], $search);
+            $host[$key][] = BR();
+        }
+    }
 
 	$style = $host['status'] == HOST_STATUS_NOT_MONITORED ? 'on' : null;
 
@@ -197,14 +201,25 @@ foreach ($hosts as $hnum => $host) {
 		$httpTestsLink = _('Web').' ('.$host['httpTests'].')';
 	}
 
-	$hostip = make_decoration($host['ip'], $search);
-	$hostdns = make_decoration($host['dns'], $search);
+	$description = array();
+	if ($host['proxy_hostid']) {
+		$proxy = API::Proxy()->get(array(
+			'proxyids' => $host['proxy_hostid'],
+			'output' => API_OUTPUT_EXTEND
+			));
+		$proxy = reset($proxy);
+		$description[] = $proxy['host'].NAME_DELIMITER;
+	}
+	$description[] = $host_link;
+
+	$host_name = make_decoration($host['host'], $search);
 
 	$table->addRow(array(
 		get_node_name_by_elid($hostid, true),
-		$host_link,
-		$hostip,
-		$hostdns,
+		$description,
+        $host_name,
+        $host['ip'],
+		$host['dns'],
 		new CLink(_('Latest data'), 'latest.php?'.$link),
 		new CLink(_('Triggers'), 'tr_status.php?'.$link),
 		new CLink(_('Events'), 'events.php?'.$link),
@@ -263,7 +278,7 @@ $viewCount = count($hostGroups);
 
 $header = array(
 	ZBX_DISTRIBUTED ? new CCol(_('Node')) : null,
-	new CCol(_('Host group')),
+	new CCol(_('Host groups')),
 	new CCol(_('Latest data')),
 	new CCol(_('Triggers')),
 	new CCol(_('Events')),
@@ -339,18 +354,20 @@ $searchWidget->addItem(new CDiv($wdgt_hgroups));
 if ($admin) {
 	$params = array(
 		'nodeids' => get_current_nodeid(true),
-		'search' => array('name' => $search),
-		'output' => array('name'),
+		'search' => array('name' => $search, 'host' => $search),
+		'output' => array('name', 'host'),
 		'selectGroups' => API_OUTPUT_REFER,
 		'sortfield' => 'name',
 		'selectItems' => API_OUTPUT_COUNT,
+        'selectDiscoveries' => API_OUTPUT_COUNT,
 		'selectTriggers' => API_OUTPUT_COUNT,
 		'selectGraphs' => API_OUTPUT_COUNT,
 		'selectApplications' => API_OUTPUT_COUNT,
 		'selectScreens' => API_OUTPUT_COUNT,
 		'selectHttpTests' => API_OUTPUT_COUNT,
 		'selectDiscoveries' => API_OUTPUT_COUNT,
-		'limit' => $rows_per_page
+		'limit' => $rows_per_page,
+        'searchByAny' => true
 	);
 	$db_templates = API::Template()->get($params);
 	order_result($db_templates, 'name');
@@ -379,6 +396,7 @@ if ($admin) {
 	$header = array(
 		ZBX_DISTRIBUTED ? new CCol(_('Node')) : null,
 		new CCol(_('Templates')),
+		new CCol(_('Names')),
 		new CCol(_('Applications')),
 		new CCol(_('Items')),
 		new CCol(_('Triggers')),
@@ -444,6 +462,7 @@ if ($admin) {
 		$table->addRow(array(
 			get_node_name_by_elid($templateid, true),
 			$template_link,
+            $template['host'],
 			$applications_link,
 			$items_link,
 			$triggers_link,
-- 
1.7.1

