)}" to expression macros "{?func(/host/key<, param>)}". * * @static * * @param string $text * * @return string */ private static function convertFunctionMacros(string $text): string { return (new C54SimpleMacroConverter())->convert($text); } /** * Convert hosts. * * @static * * @param array $hosts * * @return array */ private static function convertHosts(array $hosts): array { foreach ($hosts as &$host) { if (array_key_exists('items', $host)) { $host['items'] = self::convertItems($host['items']); } if (array_key_exists('discovery_rules', $host)) { $host['discovery_rules'] = self::convertDiscoveryRules($host['discovery_rules']); } } unset($host); return $hosts; } /** * Convert templates. * * @static * * @param array $templates * * @return array */ private static function convertTemplates(array $templates): array { foreach ($templates as &$template) { if (array_key_exists('items', $template)) { $template['items'] = self::convertItems($template['items']); } if (array_key_exists('discovery_rules', $template)) { $template['discovery_rules'] = self::convertDiscoveryRules($template['discovery_rules']); } } unset($template); return $templates; } /** * Convert items. * * @static * * @param array $items * * @return array */ private static function convertItems(array $items): array { foreach ($items as &$item) { if (array_key_exists('preprocessing', $item)) { $item['preprocessing'] = self::convertPreprocessingSteps($item['preprocessing']); } } unset($item); return $items; } /** * Convert preprocessing steps. * * @static * * @param array $preprocessing_steps * * @return array */ private static function convertPreprocessingSteps(array $preprocessing_steps): array { foreach ($preprocessing_steps as &$preprocessing_step) { if ($preprocessing_step['type'] === CXmlConstantName::PROMETHEUS_PATTERN && count($preprocessing_step['parameters']) === 2) { $preprocessing_step['parameters'][2] = $preprocessing_step['parameters'][1]; $preprocessing_step['parameters'][1] = ($preprocessing_step['parameters'][2] === '') ? ZBX_PREPROC_PROMETHEUS_VALUE : ZBX_PREPROC_PROMETHEUS_LABEL; } } unset($preprocessing_step); return $preprocessing_steps; } /** * Convert discover rules. * * @param array $discovery_rules * * @return array */ private static function convertDiscoveryRules(array $discovery_rules): array { foreach ($discovery_rules as &$discovery_rule) { if (array_key_exists('graph_prototypes', $discovery_rule)) { $discovery_rule['graph_prototypes'] = self::convertGraphs($discovery_rule['graph_prototypes']); } if (array_key_exists('item_prototypes', $discovery_rule)) { $discovery_rule['item_prototypes'] = self::convertItems($discovery_rule['item_prototypes']); } } unset($discovery_rule); return $discovery_rules; } /** * Convert graphs. * * @static * * @param array $graphs * * @return array */ private static function convertGraphs(array $graphs): array { foreach ($graphs as &$graph) { $graph['name'] = self::convertFunctionMacros($graph['name']); } unset($graph); return $graphs; } /** * Convert maps. * * @static * * @param array $maps * * @return array */ private static function convertMaps(array $maps): array { foreach ($maps as &$map) { $map['label_string_host'] = self::convertFunctionMacros($map['label_string_host']); $map['label_string_map'] = self::convertFunctionMacros($map['label_string_map']); $map['label_string_trigger'] = self::convertFunctionMacros($map['label_string_trigger']); $map['label_string_hostgroup'] = self::convertFunctionMacros($map['label_string_hostgroup']); $map['label_string_image'] = self::convertFunctionMacros($map['label_string_image']); foreach ($map['selements'] as &$selement) { $selement['label'] = self::convertFunctionMacros($selement['label']); } unset($selement); foreach ($map['shapes'] as &$shape) { $shape['text'] = self::convertFunctionMacros($shape['text']); } unset($shape); foreach ($map['links'] as &$link) { $link['label'] = self::convertFunctionMacros($link['label']); } unset($link); } unset($map); return $maps; } /** * Convert media types. * * @static * * @param array $media_types * * @return array */ private static function convertMediaTypes(array $media_types): array { foreach ($media_types as &$media_type) { if (array_key_exists('message_templates', $media_type)) { foreach ($media_type['message_templates'] as &$message_template) { if (array_key_exists('subject', $message_template)) { $message_template['subject'] = self::convertFunctionMacros($message_template['subject']); } if (array_key_exists('message', $message_template)) { $message_template['message'] = self::convertFunctionMacros($message_template['message']); } } unset($message_template); } } unset($media_type); return $media_types; } }