diff --git a/frontends/php/include/defines.inc.php b/frontends/php/include/defines.inc.php index 1d29a2c..5320ec9 100644 --- a/frontends/php/include/defines.inc.php +++ b/frontends/php/include/defines.inc.php @@ -786,6 +786,7 @@ define('AVAILABLE_NOCACHE', 0); // take available objects not from cache define('SBR', "
\n"); define('SPACE', ' '); define('RARR', '⇒'); +define('LARR', '⇐'); define('SQUAREBRACKETS', '%5B%5D'); define('NAME_DELIMITER', ': '); define('UNKNOWN_VALUE', '-'); diff --git a/frontends/php/include/func.inc.php b/frontends/php/include/func.inc.php index 6e3373c..3b2be54 100644 --- a/frontends/php/include/func.inc.php +++ b/frontends/php/include/func.inc.php @@ -2846,3 +2846,31 @@ function splitPath($path, $stripSlashes = true) { return $items; } + +function get_macros_recursively($hostids) { + $macros = API::UserMacro()->get(array( + 'hostids' => $hostids, + 'output' => API_OUTPUT_EXTEND + )); + $macros = order_macros($macros, 'hostid', ZBX_SORT_DOWN); + + $templates = API::Template()->get(array( + 'templateids' => $hostids, + 'selectParentTemplates' => array('templateid'), + 'output' => array('hostid') + )); + $templates = zbx_toHash($templates, 'templateid'); + + foreach ($templates as $template) { + $parents = isset($template['parentTemplates'])?$template['parentTemplates']:array(); + foreach($parents as $parent) $parentids[] = $parent['templateid']; + } + + if (!isset($parentids) || is_null($parentids)) { + return $macros; + } + else { + $parent_macros = get_macros_recursively($parentids); + return array_merge($parent_macros, $macros); + } +} diff --git a/frontends/php/include/views/common.macros.php b/frontends/php/include/views/common.macros.php index 853b0eb..c171db2 100644 --- a/frontends/php/include/views/common.macros.php +++ b/frontends/php/include/views/common.macros.php @@ -34,7 +34,7 @@ if (!$readonly) { $macrosTable = new CTable(SPACE, 'formElementTable'); $macrosTable->setAttribute('id', 'tbl_macros'); -$macrosTable->addRow(array(_('Macro'), SPACE, _('Value'), SPACE)); +$macrosTable->addRow(array(_('Macro'), SPACE, _('Host value'), SPACE)); // fields foreach ($macros as $i => $macro) { @@ -59,6 +59,47 @@ foreach ($macros as $i => $macro) { $row = array($text1, $span, $text2, $deleteButtonCell); $macrosTable->addRow($row, 'form_row'); + $host_macro_values[$macro['macro']] = $macro['value']; +} + +if (!empty($this->data['macros_overview'])) { + $macrosOverviewTable = new CTable(SPACE, 'formElementTable'); + $macrosOverviewTable->addRow(array(_('Macro'), SPACE, _('Global value'), SPACE, _('Template value'))); + + foreach ($this->data['macros_overview'] as $macro => $value) { + $text1 = new CTextBox(null, $macro, 30, 'yes', 255); + $text2 = new CTextBox(null, $value['global_value'], 40, 'yes', 255); + $text2->setAttribute('placeholder', '-'); + $text3 = new CTextBox(null, $value['template_value'], 40, 'yes', 255); + $text3->setAttribute('placeholder', '-'); + if (array_key_exists($macro, $host_macro_values)) { + $text1->setAttribute('title', _('Host macro').SPACE.RARR.SPACE.$host_macro_values[$macro]); + $text1->setAttribute('style','background-color:#FFCCCC'); + $text2->setAttribute('placeholder', SPACE); + $text2->setAttribute('style','background-color:#FFCCCC'); + $text2->setAttribute('title', _('Host macro').SPACE.RARR.SPACE.$host_macro_values[$macro]); + $text3->setAttribute('placeholder', SPACE); + $text3->setAttribute('style','background-color:#FFCCCC'); + $text3->setAttribute('title', _('Host macro').SPACE.RARR.SPACE.$host_macro_values[$macro]); + } + + $span1 = new CSpan(RARR); + $span1->addStyle('vertical-align:top;'); + + if (!is_null($value['template_name'])) { + $templateLink = new CLink($value['template_name'], 'templates.php?form=update&templateid='.$value['template_id']); + $text4 = $templateLink; + $span2 = new CSpan(LARR); + $span2->addStyle('vertical-align:top;'); + + $row = array($text1, $span1, $text2, $span1, $text3, $span2, $text4); + } + else { + $row = array($text1, $span1, $text2, $span1, $text3); + } + + $macrosOverviewTable->addRow($row, 'form_row'); + } } // buttons @@ -76,6 +117,7 @@ if (!$readonly) { // form list $macrosFormList = new CFormList('macrosFormList'); +if (isset($macrosOverviewTable)) $macrosFormList->addRow($macrosOverviewTable); $macrosFormList->addRow($macrosTable); return $macrosFormList; diff --git a/frontends/php/include/views/configuration.host.edit.php b/frontends/php/include/views/configuration.host.edit.php index f39a8d3..0a8d0ea 100644 --- a/frontends/php/include/views/configuration.host.edit.php +++ b/frontends/php/include/views/configuration.host.edit.php @@ -57,6 +57,44 @@ if ($_REQUEST['hostid'] > 0) { $original_templates = $dbHost['parentTemplates']; $original_templates = zbx_toHash($original_templates, 'templateid'); + $macros_overview = $templateids = array(); + + /*$global_macros = API::UserMacro()->get(array( + 'globalmacro' => true, + 'output' => API_OUTPUT_EXTEND + )); + foreach ($global_macros as $macro) { + $macros_overview[$macro['macro']]['global_value'] = $macro['value']; + }*/ + foreach ($original_templates as $tnum => $tpl) { + $templateids[] = $tpl['templateid']; + } + + $template_macros = get_macros_recursively($templateids); + $hostids = array(); + foreach ($template_macros as $macro) $hostids[] = $macro['hostid']; + + $macro_hosts = API::Host()->get(array( + 'hostids' => array_unique($hostids), + 'templated_hosts' => true, + 'output' => array('name') + )); + $macro_hosts = zbx_toHash($macro_hosts, 'hostid'); + + foreach ($template_macros as $macro) { + $macros_overview[$macro['macro']]['template_id'] = $macro['hostid']; + $macros_overview[$macro['macro']]['template_value'] = $macro['value']; + $macros_overview[$macro['macro']]['template_name'] = $macro_hosts[$macro['hostid']]['name']; + } + + foreach ($macros_overview as $macro => $values) { + if (!array_key_exists('global_value', $values)) $values['global_value'] = null; + if (!array_key_exists('template_value', $values)) $values['template_value'] = null; + if (!array_key_exists('template_name', $values)) $values['template_name'] = null; + $macros_overview[$macro] = $values; + } + ksort($macros_overview); + if (isset($_REQUEST['mainInterfaces'][INTERFACE_TYPE_AGENT])) { $mainAgentId = $_REQUEST['mainInterfaces'][INTERFACE_TYPE_AGENT]; $interfaces[$mainAgentId]['main'] = '1'; @@ -731,6 +769,7 @@ if (empty($macros)) { $macrosView = new CView('common.macros', array( 'macros' => $macros, + 'macros_overview' => isset($macros_overview) ? $macros_overview : array(), 'readonly' => $isDiscovered )); $divTabs->addTab('macroTab', _('Macros'), $macrosView->render()); diff --git a/frontends/php/include/views/configuration.template.edit.php b/frontends/php/include/views/configuration.template.edit.php index 7c9056a..0132ce9 100644 --- a/frontends/php/include/views/configuration.template.edit.php +++ b/frontends/php/include/views/configuration.template.edit.php @@ -36,6 +36,46 @@ $frm_title = _('Template'); if ($templateid > 0) { $frm_title .= SPACE.' ['.$this->data['dbTemplate']['name'].']'; + + $templateids = $macros_overview = array(); + foreach($this->data['original_templates'] as $tid => $tpl){ + $templateids[] = $tpl; + } + + /*$global_macros = API::UserMacro()->get(array( + 'globalmacro' => true, + 'output' => API_OUTPUT_EXTEND + )); + foreach ($global_macros as $macro) { + $macros_overview[$macro['macro']]['global_value'] = $macro['value']; + }*/ + $template_macros = get_macros_recursively($templateids); + $hostids = array(); + foreach ($template_macros as $macro) $hostids[] = $macro['hostid']; + + $macro_hosts = API::Host()->get(array( + 'hostids' => array_unique($hostids), + 'templated_hosts' => true, + 'output' => array('name') + )); + $macro_hosts = zbx_toHash($macro_hosts, 'hostid'); + + foreach ($template_macros as $macro) { + $macros_overview[$macro['macro']]['template_id'] = $macro['hostid']; + $macros_overview[$macro['macro']]['template_value'] = $macro['value']; + $macros_overview[$macro['macro']]['template_name'] = $macro_hosts[$macro['hostid']]['name']; + } + + foreach ($macros_overview as $macro => $values) { + if (!array_key_exists('global_value', $values)) $values['global_value'] = null; + if (!array_key_exists('template_value', $values)) $values['template_value'] = null; + if (!array_key_exists('template_name', $values)) $values['template_name'] = null; + $macros_overview[$macro] = $values; + } + ksort($macros_overview); +} +else { + $macros = array(array('macro' => '', 'value' => '')); } $frmHost = new CForm(); $frmHost->setName('tpl_for'); @@ -428,7 +468,8 @@ if (empty($macros)) { $macros = array(array('macro' => '', 'value' => '')); } $macrosView = new CView('common.macros', array( - 'macros' => $macros + 'macros' => $macros, + 'macros_overview' => isset($macros_overview) ? $macros_overview : array(), )); $divTabs->addTab('macroTab', _('Macros'), $macrosView->render());