Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimirs Maksimovs <vladimirs.maksimovs@zabbix.com>2021-01-20 13:23:41 +0300
committerVladimirs Maksimovs <vladimirs.maksimovs@zabbix.com>2021-01-20 13:23:41 +0300
commitdcfc3b8064c1ed7894c02816d3542a8fa5212484 (patch)
tree2c5c770cf065411cbdf3b3cf500eb2cc384ebef9 /ui/app/controllers
parenteb672f5f6c5d9941ae00726d58d322a0d0162015 (diff)
..F.....S. [ZBXNEXT-6399] added support of host and item macros for Script item parameters
Diffstat (limited to 'ui/app/controllers')
-rw-r--r--ui/app/controllers/CControllerPopupItemTest.php84
-rw-r--r--ui/app/controllers/CControllerPopupItemTestEdit.php12
2 files changed, 75 insertions, 21 deletions
diff --git a/ui/app/controllers/CControllerPopupItemTest.php b/ui/app/controllers/CControllerPopupItemTest.php
index f16ac62cfcd..29b59609690 100644
--- a/ui/app/controllers/CControllerPopupItemTest.php
+++ b/ui/app/controllers/CControllerPopupItemTest.php
@@ -137,55 +137,56 @@ abstract class CControllerPopupItemTest extends CController {
'url' => [
'host' => ['{HOSTNAME}', '{HOST.HOST}', '{HOST.NAME}'],
'interface' => ['{HOST.IP}', '{IPADDRESS}', '{HOST.DNS}', '{HOST.CONN}', '{HOST.PORT}'],
- 'item' => ['{ITEM.ID}', '{ITEM.KEY}'],
+ 'item' => ['{ITEM.ID}', '{ITEM.KEY.ORIG}', '{ITEM.KEY}'],
'support_user_macros' => true,
'support_lld_macros' => true
],
'posts' => [
'host' => ['{HOSTNAME}', '{HOST.HOST}', '{HOST.NAME}'],
'interface' => ['{HOST.IP}', '{IPADDRESS}', '{HOST.DNS}', '{HOST.CONN}', '{HOST.PORT}'],
- 'item' => ['{ITEM.ID}', '{ITEM.KEY}'],
+ 'item' => ['{ITEM.ID}', '{ITEM.KEY.ORIG}', '{ITEM.KEY}'],
'support_user_macros' => true,
'support_lld_macros' => true
],
'http_proxy' => [
'host' => ['{HOSTNAME}', '{HOST.HOST}', '{HOST.NAME}'],
'interface' => ['{HOST.IP}', '{IPADDRESS}', '{HOST.DNS}', '{HOST.CONN}', '{HOST.PORT}'],
- 'item' => ['{ITEM.ID}', '{ITEM.KEY}'],
+ 'item' => ['{ITEM.ID}', '{ITEM.KEY.ORIG}', '{ITEM.KEY}'],
'support_user_macros' => true,
'support_lld_macros' => true
],
'ssl_cert_file' => [
'host' => ['{HOSTNAME}', '{HOST.HOST}', '{HOST.NAME}'],
'interface' => ['{HOST.IP}', '{IPADDRESS}', '{HOST.DNS}', '{HOST.CONN}', '{HOST.PORT}'],
- 'item' => ['{ITEM.ID}', '{ITEM.KEY}'],
+ 'item' => ['{ITEM.ID}', '{ITEM.KEY.ORIG}', '{ITEM.KEY}'],
'support_user_macros' => true,
'support_lld_macros' => true
],
'ssl_key_file' => [
'host' => ['{HOSTNAME}', '{HOST.HOST}', '{HOST.NAME}'],
'interface' => ['{HOST.IP}', '{IPADDRESS}', '{HOST.DNS}', '{HOST.CONN}', '{HOST.PORT}'],
- 'item' => ['{ITEM.ID}', '{ITEM.KEY}'],
+ 'item' => ['{ITEM.ID}', '{ITEM.KEY.ORIG}', '{ITEM.KEY}'],
'support_user_macros' => true,
'support_lld_macros' => true
],
'query_fields' => [
'host' => ['{HOSTNAME}', '{HOST.HOST}', '{HOST.NAME}'],
'interface' => ['{HOST.IP}', '{IPADDRESS}', '{HOST.DNS}', '{HOST.CONN}', '{HOST.PORT}'],
- 'item' => ['{ITEM.ID}', '{ITEM.KEY}'],
+ 'item' => ['{ITEM.ID}', '{ITEM.KEY.ORIG}', '{ITEM.KEY}'],
'support_user_macros' => true,
'support_lld_macros' => true
],
'headers' => [
'host' => ['{HOSTNAME}', '{HOST.HOST}', '{HOST.NAME}'],
'interface' => ['{HOST.IP}', '{IPADDRESS}', '{HOST.DNS}', '{HOST.CONN}', '{HOST.PORT}'],
- 'item' => ['{ITEM.ID}', '{ITEM.KEY}'],
+ 'item' => ['{ITEM.ID}', '{ITEM.KEY.ORIG}', '{ITEM.KEY}'],
'support_user_macros' => true,
'support_lld_macros' => true
],
'parameters' => [
'host' => ['{HOSTNAME}', '{HOST.HOST}', '{HOST.NAME}'],
'interface' => ['{HOST.IP}', '{IPADDRESS}', '{HOST.DNS}', '{HOST.CONN}'],
+ 'item' => ['{ITEM.ID}', '{ITEM.KEY.ORIG}', '{ITEM.KEY}'],
'support_user_macros' => true,
'support_lld_macros' => true
],
@@ -426,7 +427,8 @@ abstract class CControllerPopupItemTest extends CController {
$interface_input['address'] = $input['address'];
}
- if (array_key_exists('data', $input) && array_key_exists('interface_details', $input['data'])) {
+ if (array_key_exists('data', $input) && array_key_exists('interface_details', $input['data'])
+ && is_array($input['data']['interface_details'])) {
$interface_input['details'] = $input['data']['interface_details'];
}
elseif (array_key_exists('interface', $input) && array_key_exists('details', $input['interface'])) {
@@ -734,12 +736,39 @@ abstract class CControllerPopupItemTest extends CController {
// Get values from database; resolve macros.
if (($this->host['status'] == HOST_STATUS_MONITORED || $this->host['status'] == HOST_STATUS_NOT_MONITORED)
&& array_key_exists('interfaceid', $inputs)) {
- $output_details = ($this->item_type == ITEM_TYPE_SNMP) ? ['details'] : [];
- $interfaces = API::HostInterface()->get([
- 'output' => array_merge(['hostid', 'type', 'dns', 'ip', 'port', 'main', 'useip'], $output_details),
- 'interfaceids' => $inputs['interfaceid'],
- 'hostids' => $this->host['hostid']
- ]);
+ $output = ['hostid', 'type', 'dns', 'ip', 'port', 'main', 'useip'];
+ $interfaces = [];
+
+ if ($this->item_type == ITEM_TYPE_SNMP) {
+ $output[] = 'details';
+ }
+
+ if (itemTypeInterface($this->item_type) === false) {
+ $host_interfaces = API::HostInterface()->get([
+ 'output' => $output,
+ 'hostids' => $this->host['hostid'],
+ 'filter' => ['main' => INTERFACE_PRIMARY]
+ ]);
+ $host_interfaces = zbx_toHash($host_interfaces, 'type');
+
+ $ordered_interface_types = [INTERFACE_TYPE_AGENT, INTERFACE_TYPE_SNMP, INTERFACE_TYPE_JMX,
+ INTERFACE_TYPE_IPMI
+ ];
+
+ foreach ($ordered_interface_types as $interface_type) {
+ if (array_key_exists($interface_type, $host_interfaces)) {
+ $interfaces[] = $host_interfaces[$interface_type];
+ break;
+ }
+ }
+ }
+ else {
+ $interfaces = API::HostInterface()->get([
+ 'output' => $output,
+ 'interfaceids' => $inputs['interfaceid'],
+ 'hostids' => $this->host['hostid']
+ ]);
+ }
if (count($interfaces) != 0) {
$interfaces = CMacrosResolverHelper::resolveHostInterfaces($interfaces);
@@ -761,6 +790,10 @@ abstract class CControllerPopupItemTest extends CController {
}
}
+ if ($this->item_type == ITEM_TYPE_SCRIPT) {
+ return $interface_data;
+ }
+
// Apply client side cache.
foreach ($inputs as $key => $value) {
if (is_array($value)) {
@@ -888,10 +921,31 @@ abstract class CControllerPopupItemTest extends CController {
'{ITEM.ID}' => (array_key_exists('itemid', $inputs) && $inputs['itemid'])
? $inputs['itemid']
: UNRESOLVED_MACRO_STRING,
- '{ITEM.KEY}' => array_key_exists('key', $inputs) ? $inputs['key'] : UNRESOLVED_MACRO_STRING
+ '{ITEM.KEY}' => array_key_exists('key', $inputs) ? $inputs['key'] : UNRESOLVED_MACRO_STRING,
+ '{ITEM.KEY.ORIG}' => array_key_exists('key', $inputs) ? $inputs['key'] : UNRESOLVED_MACRO_STRING
]
];
+ if (array_key_exists('key', $inputs) && strstr($inputs['key'], '{') !== false) {
+ $usermacros = CMacrosResolverHelper::extractItemTestMacros([
+ 'steps' => [],
+ 'delay' => '',
+ 'supported_macros' => array_diff_key($this->macros_by_item_props['key'],
+ ['support_user_macros' => true, 'support_lld_macros' => true]
+ ),
+ 'support_lldmacros' => ($this->preproc_item instanceof CItemPrototype),
+ 'texts_support_macros' => [$inputs['key']],
+ 'texts_support_lld_macros' => [$inputs['key']],
+ 'texts_support_user_macros' => [$inputs['key']],
+ 'hostid' => $this->host ? $this->host['hostid'] : 0,
+ 'macros_values' => array_intersect_key($macros, $this->macros_by_item_props['key'])
+ ]);
+
+ foreach ($usermacros['macros'] as $macro => $value) {
+ $macros['item']['{ITEM.KEY}'] = str_replace($macro, $value, $macros['item']['{ITEM.KEY}']);
+ }
+ }
+
return $macros;
}
diff --git a/ui/app/controllers/CControllerPopupItemTestEdit.php b/ui/app/controllers/CControllerPopupItemTestEdit.php
index 808c77fe8fb..abddd97d4ac 100644
--- a/ui/app/controllers/CControllerPopupItemTestEdit.php
+++ b/ui/app/controllers/CControllerPopupItemTestEdit.php
@@ -149,9 +149,9 @@ class CControllerPopupItemTestEdit extends CControllerPopupItemTest {
$inputs = $this->getItemTestProperties($this->getInputAll());
// Work with preprocessing steps.
- $preprocessing_steps_inpupt = $this->getInput('steps', []);
+ $preprocessing_steps_input = $this->getInput('steps', []);
$preprocessing_steps = [];
- foreach ($preprocessing_steps_inpupt as $preproc) {
+ foreach ($preprocessing_steps_input as $preproc) {
if ($preproc['type'] == ZBX_PREPROC_VALIDATE_NOT_SUPPORTED) {
array_unshift($preprocessing_steps, $preproc);
}
@@ -248,13 +248,13 @@ class CControllerPopupItemTestEdit extends CControllerPopupItemTest {
// Extract macros and apply effective values for each of them.
$usermacros = CMacrosResolverHelper::extractItemTestMacros([
'steps' => $preprocessing_steps,
- 'hostid' => $this->host ? $this->host['hostid'] : 0,
'delay' => $show_prev ? $this->getInput('delay', ZBX_ITEM_DELAY_DEFAULT) : '',
- 'texts_support_macros' => $texts_support_macros,
- 'texts_support_lld_macros' => $texts_support_lld_macros,
- 'texts_support_user_macros' => $texts_support_user_macros,
'supported_macros' => $supported_macros,
'support_lldmacros' => $support_lldmacros,
+ 'texts_support_macros' => $texts_support_macros,
+ 'texts_support_user_macros' => $texts_support_user_macros,
+ 'texts_support_lld_macros' => $texts_support_lld_macros,
+ 'hostid' => $this->host ? $this->host['hostid'] : 0,
'macros_values' => $this->getSupportedMacros($inputs + ['interfaceid' => $this->getInput('interfaceid', 0)])
]);