From f14654f005b7a04e0948860e6e4b9fc7466a79b9 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 and discovery column to host and template search results
---
 search.php |   62 ++++++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 46 insertions(+), 16 deletions(-)

diff --git a/search.php b/search.php
index ca1cd5d..328c5b7 100644
--- a/search.php
+++ b/search.php
@@ -80,18 +80,20 @@ $params = array(
 	'nodeids' => get_current_nodeid(true),
 	'search' => array(
 		'name' => $search,
+		'host' => $search,
 		'dns' => $search,
 		'ip' => $search
 	),
 	'limit' => $rows_per_page,
 	'selectGroups' => API_OUTPUT_EXTEND,
+	'selectDiscoveries' => API_OUTPUT_COUNT,
 	'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'),
+	'output' => array('name', 'host', 'status'),
 	'searchByAny' => true
 );
 $db_hosts = API::Host()->get($params);
@@ -127,8 +129,9 @@ $table = new CTableInfo();
 $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')),
@@ -137,15 +140,18 @@ $table->setHeader(array(
 	new CCol(_('Items')),
 	new CCol(_('Triggers')),
 	new CCol(_('Graphs')),
+	new CCol(_('Discoveries')),
 ));
 
 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;
 
@@ -172,6 +178,10 @@ foreach ($hosts as $hnum => $host) {
 			new CLink(_('Graphs'), 'graphs.php?'.$link),
 			' ('.$host['graphs'].')'
 		);
+		$discoveries_link = array(
+			new CLink(_('Discoveries'), 'host_discovery.php?'.$link),
+			' ('.$host['discoveries'].')'
+		);
 	}
 	else {
 		$host_link = new CSpan($caption, $style);
@@ -191,16 +201,20 @@ foreach ($hosts as $hnum => $host) {
 			new CSpan(_('Graphs'), 'unknown'),
 			' ('.$host['graphs'].')'
 		);
+		$discoveries_link = array(
+			new CSpan(_('Discoveries'), 'unknown'),
+			' ('.$host['discoveries'].')'
+		);
 	}
 
-	$hostip = make_decoration($host['ip'], $search);
-	$hostdns = make_decoration($host['dns'], $search);
+	$host_name = make_decoration($host['host'], $search);
 
 	$table->addRow(array(
 		get_node_name_by_elid($hostid, true),
 		$host_link,
-		$hostip,
-		$hostdns,
+        $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),
@@ -209,6 +223,7 @@ foreach ($hosts as $hnum => $host) {
 		$items_link,
 		$triggers_link,
 		$graphs_link,
+		$discoveries_link,
 	));
 }
 
@@ -255,7 +270,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')),
@@ -324,19 +339,22 @@ $searchWidget->addItem(new CDiv($wdgt_hgroups));
 //----------------
 
 // FIND Templates
+#TODO: Das suchen funktioniert mit host nicht richtig.
 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,
-		'limit' => $rows_per_page
+		'limit' => $rows_per_page,
+        'searchByAny' => true
 	);
 	$db_templates = API::Template()->get($params);
 	order_result($db_templates, 'name');
@@ -365,11 +383,13 @@ 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')),
 		new CCol(_('Graphs')),
 		new CCol(_('Screens')),
+	    new CCol(_('Discoveries'))
 	);
 
 	$table = new CTableInfo();
@@ -405,6 +425,10 @@ if ($admin) {
 				new CLink(_('Screens'), 'screenconf.php?templateid='.$templateid),
 				' ('.$template['screens'].')'
 			);
+                $discoveriesLink = array(
+                    new CLink(_('Discoveries'), 'host_discovery.php?'.$link),
+                    ' ('.$template['discoveries'].')'
+                      );
 		}
 		else {
 			$template_link = new CSpan($caption);
@@ -428,16 +452,22 @@ if ($admin) {
 				new CSpan(_('Screens'), 'unknown'),
 				' ('.$template['screens'].')'
 			);
+			$discoveriesLink = array(
+				new CSpan(_('Discoveries'), 'unknown'),
+				' ('.$template['discovery'].')'
+			);
 		}
 
 		$table->addRow(array(
 			get_node_name_by_elid($templateid, true),
 			$template_link,
+            $template['host'],
 			$applications_link,
 			$items_link,
 			$triggers_link,
 			$graphs_link,
-			$screensLink
+			$screensLink,
+            $discoveriesLink
 		));
 	}
 
-- 
1.7.1

