From dc9dcaa4ae79a74d4c3597bbda66db2d68655f62 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Volker=20Fr=C3=B6hlich?= <volker27@gmx.at>
Date: Wed, 27 Nov 2013 16:11:57 +0100
Subject: [PATCH] ZBXNEXT-669 -- denote maintenance in "latest data"

Forward-ported but not well tested

Host status in the host list does not change due to maintenance too,
for the sake of consistency
---
 hosts.php  |   39 ++++++++++++++++++++++++++--------
 latest.php |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 97 insertions(+), 10 deletions(-)

diff --git a/hosts.php b/hosts.php
index ccf73ba..756e86b 100644
--- a/hosts.php
+++ b/hosts.php
@@ -906,6 +906,34 @@ else {
 
 		$description[] = new CLink(CHtml::encode($host['name']), 'hosts.php?form=update&hostid='.$host['hostid'].url_param('groupid'));
 
+        #TODO: Disabled hosts show the maintenance symbol but there's no mouse-over text. Is that what we want?
+		// add maintenance icon with hint if host is in maintenance
+		if($host['maintenance_status']){
+		$mntIco = new CDiv(null, 'icon-maintenance-inline');
+
+		$maintenances = API::Maintenance()->get(array(
+				'maintenanceids' => $host['maintenanceid'],
+				'output' => API_OUTPUT_EXTEND,
+				'limit' => 1
+				));
+
+		if ($maintenance = reset($maintenances)) {
+			$hint = $maintenance['name'].' ['.($host['maintenance_type']
+					? _('Maintenance without data collection')
+					: _('Maintenance with data collection')).']';
+
+			if (isset($maintenance['description'])) {
+				// double quotes mandatory
+				$hint .= "\n".$maintenance['description'];
+			}
+
+			$mntIco->setHint($hint);
+			$mntIco->addClass('pointer');
+		}
+
+		$description[] = $mntIco;
+		}
+
 		$hostInterface = ($interface['useip'] == INTERFACE_USE_IP) ? $interface['ip'] : $interface['dns'];
 		$hostInterface .= empty($interface['port']) ? '' : NAME_DELIMITER.$interface['port'];
 
@@ -913,15 +941,8 @@ else {
 
 		switch ($host['status']) {
 			case HOST_STATUS_MONITORED:
-				if ($host['maintenance_status'] == HOST_MAINTENANCE_STATUS_ON) {
-					$statusCaption = _('In maintenance');
-					$statusClass = 'orange';
-				}
-				else {
-					$statusCaption = _('Monitored');
-					$statusClass = 'enabled';
-				}
-
+                $statusCaption = _('Monitored');
+                $statusClass = 'enabled';
 				$statusScript = 'return Confirm('.zbx_jsvalue(_('Disable host?')).');';
 				$statusUrl = 'hosts.php?hosts'.SQUAREBRACKETS.'='.$host['hostid'].'&go=disable'.url_param('groupid');
 				break;
diff --git a/latest.php b/latest.php
index 911eaf0..27f8ecd 100644
--- a/latest.php
+++ b/latest.php
@@ -166,7 +166,7 @@ else {
 }
 
 $hosts = API::Host()->get(array(
-	'output' => array('name', 'hostid', 'status'),
+	'output' => array('name', 'hostid', 'status', 'maintenance_status', 'maintenance_type', 'maintenanceid'),
 	'hostids' => $availableHostIds,
 	'with_monitored_items' => true,
 	'preservekeys' => true
@@ -508,6 +508,32 @@ foreach ($applications as $appid => $dbApp) {
 		$hostName->setMenuPopup(getMenuPopupHost($host, $hostScripts[$host['hostid']]));
 	}
 
+	if ($host['maintenance_status']) {
+		$mntIco = new CDiv(null, 'icon-maintenance-inline');
+
+		// get maintenance
+		$maintenances = API::Maintenance()->get(array(
+			'maintenanceids' => $host['maintenanceid'],
+			'output' => API_OUTPUT_EXTEND,
+			'limit' => 1
+		));
+		if ($maintenance = reset($maintenances)) {
+			$hint = $maintenance['name'].' ['.($host['maintenance_type']
+				? _('Maintenance without data collection')
+				: _('Maintenance with data collection')).']';
+
+			if (isset($maintenance['description'])) {
+				// double quotes mandatory
+				$hint .= "\n".$maintenance['description'];
+			}
+
+			$mntIco->setHint($hint);
+			$mntIco->addClass('pointer');
+		}
+
+		$hostName->addItem($mntIco);
+	}
+
 	// add toggle row
 	$table->addRow(array(
 		$toggle,
@@ -679,6 +705,46 @@ foreach ($hosts as $hostId => $dbHost) {
 			'link_menu menu-host'.(($host['status'] == HOST_STATUS_NOT_MONITORED) ? ' not-monitored' : '')
 		);
 		$hostName->setMenuPopup(getMenuPopupHost($host, $hostScripts[$host['hostid']]));
+
+	if ($host['maintenance_status']) {
+		$mntIco = new CDiv(null, 'icon-maintenance-inline');
+
+		// get maintenance
+		$maintenances = API::Maintenance()->get(array(
+			'maintenanceids' => $host['maintenanceid'],
+			'output' => API_OUTPUT_EXTEND,
+			'limit' => 1
+		));
+		if ($maintenance = reset($maintenances)) {
+			$hint = $maintenance['name'].' ['.($host['maintenance_type']
+				? _('Maintenance without data collection')
+				: _('Maintenance with data collection')).']';
+
+			if (isset($maintenance['description'])) {
+				// double quotes mandatory
+				$hint .= "\n".$maintenance['description'];
+			}
+
+			$mntIco->setHint($hint);
+			$mntIco->addClass('pointer');
+		}
+
+		$hostName->addItem($mntIco);
+	}
+
+		// add toggle row
+		$table->addRow(array(
+			$toggle,
+			get_node_name_by_elid($dbHost['hostid']),
+			$hostName,
+			new CCol(
+				array(
+					bold('- '.('other').' -'),
+					SPACE.'('._n('%1$s Item', '%1$s Items', $dbHost['item_cnt']).')'
+				),
+				null, $filterShowDetails ? 10 : 5
+			)
+		), 'odd_row');
 	}
 
 	// add toggle row
-- 
1.7.1

