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:
-rw-r--r--ChangeLog.d/feature/ZBXNEXT-63991
-rw-r--r--include/zbxserver.h1
-rw-r--r--src/libs/zbxserver/expression.c18
-rw-r--r--src/zabbix_server/poller/poller.c3
-rw-r--r--ui/app/controllers/CControllerPopupItemTest.php84
-rw-r--r--ui/app/controllers/CControllerPopupItemTestEdit.php12
-rw-r--r--ui/app/views/js/popup.itemtestedit.view.js.php2
-rw-r--r--ui/include/classes/macros/CMacrosResolver.php3
-rw-r--r--ui/include/classes/macros/CMacrosResolverHelper.php3
9 files changed, 101 insertions, 26 deletions
diff --git a/ChangeLog.d/feature/ZBXNEXT-6399 b/ChangeLog.d/feature/ZBXNEXT-6399
new file mode 100644
index 00000000000..2f83ff64c52
--- /dev/null
+++ b/ChangeLog.d/feature/ZBXNEXT-6399
@@ -0,0 +1 @@
+..F.....S. [ZBXNEXT-6399] added support of host and item macros for Script item parameters (viktors, vmaksimovs)
diff --git a/include/zbxserver.h b/include/zbxserver.h
index 7eebcb271fb..33e350977e9 100644
--- a/include/zbxserver.h
+++ b/include/zbxserver.h
@@ -50,6 +50,7 @@
#define MACRO_TYPE_ITEM_TAG 0x01000000
#define MACRO_TYPE_EVENT_NAME 0x02000000 /* event name in trigger configuration */
#define MACRO_TYPE_EXPRESSION 0x04000000 /* macros in expression macro */
+#define MACRO_TYPE_SCRIPT_PARAMS_FIELD 0x08000000
#define MACRO_EXPAND_NO 0
#define MACRO_EXPAND_YES 1
diff --git a/src/libs/zbxserver/expression.c b/src/libs/zbxserver/expression.c
index fafa74250ce..af9edc73434 100644
--- a/src/libs/zbxserver/expression.c
+++ b/src/libs/zbxserver/expression.c
@@ -4372,7 +4372,8 @@ static int substitute_simple_macros_impl(zbx_uint64_t *actionid, const DB_EVENT
}
else if (0 == indexed_macro &&
0 != (macro_type & (MACRO_TYPE_ITEM_KEY | MACRO_TYPE_PARAMS_FIELD |
- MACRO_TYPE_LLD_FILTER | MACRO_TYPE_ALLOWED_HOSTS)))
+ MACRO_TYPE_LLD_FILTER | MACRO_TYPE_ALLOWED_HOSTS |
+ MACRO_TYPE_SCRIPT_PARAMS_FIELD)))
{
if (ZBX_TOKEN_USER_MACRO == token.type)
{
@@ -4419,6 +4420,21 @@ static int substitute_simple_macros_impl(zbx_uint64_t *actionid, const DB_EVENT
ZBX_REQUEST_HOST_CONN);
}
}
+ else if (0 != (macro_type & MACRO_TYPE_SCRIPT_PARAMS_FIELD))
+ {
+ if (0 == strcmp(m, MVAR_ITEM_ID))
+ {
+ replace_to = zbx_dsprintf(replace_to, ZBX_FS_UI64, dc_item->itemid);
+ }
+ else if (0 == strcmp(m, MVAR_ITEM_KEY))
+ {
+ replace_to = zbx_strdup(replace_to, dc_item->key);
+ }
+ else if (0 == strcmp(m, MVAR_ITEM_KEY_ORIG))
+ {
+ replace_to = zbx_strdup(replace_to, dc_item->key_orig);
+ }
+ }
}
else if (0 == indexed_macro && 0 != (macro_type & MACRO_TYPE_INTERFACE_ADDR))
{
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c
index a41eebe6e41..1d35b7c7c0b 100644
--- a/src/zabbix_server/poller/poller.c
+++ b/src/zabbix_server/poller/poller.c
@@ -534,7 +534,8 @@ void zbx_prepare_items(DC_ITEM *items, int *errcodes, int num, AGENT_RESULT *res
substitute_simple_macros(NULL, NULL, NULL, NULL, &items[i].host.hostid, NULL, NULL,
NULL, NULL, NULL, &items[i].timeout, MACRO_TYPE_COMMON , NULL, 0);
substitute_simple_macros_unmasked(NULL, NULL, NULL, NULL, NULL, NULL, &items[i], NULL,
- NULL, NULL, &items[i].script_params, MACRO_TYPE_PARAMS_FIELD, NULL, 0);
+ NULL, NULL, &items[i].script_params, MACRO_TYPE_SCRIPT_PARAMS_FIELD,
+ NULL, 0);
substitute_simple_macros_unmasked(NULL, NULL, NULL, NULL, &items[i].host.hostid, NULL,
NULL, NULL, NULL, NULL, &items[i].params, MACRO_TYPE_COMMON, NULL, 0);
break;
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)])
]);
diff --git a/ui/app/views/js/popup.itemtestedit.view.js.php b/ui/app/views/js/popup.itemtestedit.view.js.php
index 47d1d37d239..b148a3dca9d 100644
--- a/ui/app/views/js/popup.itemtestedit.view.js.php
+++ b/ui/app/views/js/popup.itemtestedit.view.js.php
@@ -407,7 +407,7 @@ function saveItemTestInputs() {
interfaceid: <?= $data['interfaceid'] ?> || 0,
address: jQuery('#interface_address', $form).val(),
port: jQuery('#interface_port', $form).val(),
- interface_details: interface ? interface['details'] : null
+ interface_details: (interface && 'details' in interface) ? interface['details'] : null
});
<?php endif ?>
diff --git a/ui/include/classes/macros/CMacrosResolver.php b/ui/include/classes/macros/CMacrosResolver.php
index e21eae58a20..cdae81e8531 100644
--- a/ui/include/classes/macros/CMacrosResolver.php
+++ b/ui/include/classes/macros/CMacrosResolver.php
@@ -2775,7 +2775,8 @@ class CMacrosResolver extends CMacrosResolverGeneral {
* @param array $data['texts_support_macros'] List of texts potentially could contain macros.
* @param array $data['texts_support_user_macros'] List of texts potentially could contain user macros.
* @param array $data['texts_support_lld_macros'] List of texts potentially could contain LLD macros.
- * @param int $data['hostids'] Hostid for which tested item belongs to.
+ * @param int $data['hostid'] Hostid for which tested item belongs to.
+ * @param array $data['macros_values'] Values for supported macros.
*
* @return array
*/
diff --git a/ui/include/classes/macros/CMacrosResolverHelper.php b/ui/include/classes/macros/CMacrosResolverHelper.php
index 7370bb2f485..026e769f808 100644
--- a/ui/include/classes/macros/CMacrosResolverHelper.php
+++ b/ui/include/classes/macros/CMacrosResolverHelper.php
@@ -706,7 +706,8 @@ class CMacrosResolverHelper {
* @param array $data['texts_support_macros'] List of texts potentially could contain macros.
* @param array $data['texts_support_user_macros'] List of texts potentially could contain user macros.
* @param array $data['texts_support_lld_macros'] List of texts potentially could contain LLD macros.
- * @param int $data['hostids'] Hostid for which tested item belongs to.
+ * @param int $data['hostid'] Hostid for which tested item belongs to.
+ * @param array $data['macros_values'] Values for supported macros.
*
* @return array
*/