-- Insert new Google APP
SET @current_app_type = 13;
SET @short_name = 'pandorafms.gcp.ce';
SET @name = 'Google&#x20;Cloud&#x20;Compute&#x20;Engine';
SET @section = 'cloud';
SET @description = 'Monitor&#x20;Google&#x20;Cloud&#x20;Platform&#x20;Compute&#x20;Engine&#x20;VMs';
SET @version = '1.0';
INSERT IGNORE INTO `tdiscovery_apps` (`id_app`, `short_name`, `name`, `section`, `description`, `version`) VALUES ('', @short_name, @name, @section, @description, @version);
SELECT @id_app := `id_app` FROM `tdiscovery_apps` WHERE `short_name` = @short_name;

-- Insert into tdiscovery_apps_scripts
INSERT IGNORE INTO `tdiscovery_apps_scripts` (`id_app`, `macro`, `value`) VALUES (@id_app, '_exec1_', 'bin/pandora_gcp_ce');
INSERT IGNORE INTO `tdiscovery_apps_scripts` (`id_app`, `macro`, `value`) VALUES (@id_app, '_exec2_', 'bin/google_instances');

-- Insert into tdiscovery_apps_executions
INSERT IGNORE INTO `tdiscovery_apps_executions` (`id`, `id_app`, `execution`) VALUES (1, @id_app, '&#039;_exec1_&#039;&#x20;--conf&#x20;&#039;_tempfileGoogleCE_&#039;');

-- Migrate current Google tasks configurations
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_tentacleIP_', 'custom', '127.0.0.1', 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_tentaclePort_', 'custom', '41121', 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_tentacleExtraOpt_', 'custom', '', 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_credentials_', 'credentials.gcp', `auth_strings`, 0
    FROM `trecon_task`
    WHERE `trecon_task`.`type` = @current_app_type
;

SET @position = 4;
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`,
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        '_googleCEInstanceSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        '_googleCECpuPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        '_googleCEIopsPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        '_googleCEDiskPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        '_googleCENetworkPerfSummary_',
        NULL
    )
    )
    )
    )
    ),
    'custom',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
        "0"
    )
    )
    )
    )
    ),
    0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

SET @position = 5;
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`,
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        '_googleCEInstanceSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        '_googleCECpuPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        '_googleCEIopsPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        '_googleCEDiskPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        '_googleCENetworkPerfSummary_',
        NULL
    )
    )
    )
    )
    ),
    'custom',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
        "0"
    )
    )
    )
    )
    ),
    0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

SET @position = 6;
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`,
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        '_googleCEInstanceSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        '_googleCECpuPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        '_googleCEIopsPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        '_googleCEDiskPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        '_googleCENetworkPerfSummary_',
        NULL
    )
    )
    )
    )
    ),
    'custom',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
        "0"
    )
    )
    )
    )
    ),
    0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

SET @position = 7;
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`,
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        '_googleCEInstanceSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        '_googleCECpuPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        '_googleCEIopsPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        '_googleCEDiskPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        '_googleCENetworkPerfSummary_',
        NULL
    )
    )
    )
    )
    ),
    'custom',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
        "0"
    )
    )
    )
    )
    ),
    0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

SET @position = 8;
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`,
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        '_googleCEInstanceSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        '_googleCECpuPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        '_googleCEIopsPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        '_googleCEDiskPerfSummary_',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        '_googleCENetworkPerfSummary_',
        NULL
    )
    )
    )
    )
    ),
    'custom',
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_instance_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_cpu_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_iops_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_disk_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
    IF(
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", 1) = 'ec2_network_perf_summary',
        SUBSTRING_INDEX(SUBSTRING_INDEX(SUBSTRING_INDEX(
            CONCAT(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",1),REPLACE(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONCAT(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",1),REPLACE(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),CONCAT(SUBSTRING_INDEX(SUBSTRING_INDEX(CONVERT(FROM_BASE64(field1) USING UTF8MB4),"ec2_zones ",-1),"\n",1),"\n"),"")),"ec2_instance ",-1),"\n",1),"\n"),""))
        , "\n", @position), "\n", -1), " ", -1),
        "0"
    )
    )
    )
    )
    ),
    0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_statsAgent_', 'custom', 0, 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_statsAgentName_', 'custom', '', 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_googleCEInstanceSummary_', 'custom', 0, 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_googleCECpuPerfSummary_', 'custom', 0, 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_googleCEIopsPerfSummary_', 'custom', 0, 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_googleCEDiskPerfSummary_', 'custom', 0, 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_googleCENetworkPerfSummary_', 'custom', 0, 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

SET @param = 'ec2_instance';
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`,
    '_googleCEInstance_',
    'custom', 
    REPLACE(
        REPLACE(
            CONCAT(
                '["',
                REPLACE(
                    REPLACE(
                        REPLACE(
                            REPLACE(
                                CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                SUBSTRING_INDEX(
                                    CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                    CONCAT(@param, " "), 1
                                ),
                                ""
                            ),
                            REPLACE(
                                SUBSTRING_INDEX(
                                    REPLACE(
                                        CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                        SUBSTRING_INDEX(
                                            CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                            CONCAT(@param, " "), 1
                                        ),
                                        ""
                                    ),
                                    CONCAT(@param, " "), -1
                                ),
                                SUBSTRING_INDEX(SUBSTRING_INDEX(
                                    REPLACE(
                                        CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                        SUBSTRING_INDEX(
                                            CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                            CONCAT(@param, " "), 1
                                        ),
                                        ""
                                    ),
                                    CONCAT(@param, " "), -1
                                ), "\n", 1),
                                ""
                            ),
                            "\n"
                        ),
                        CONCAT(@param, " "),
                        ""
                    ),
                    "\n",
                    '","'
                ),
                '"]'
            ),
            ',""]',
            ']'
        ),
        '[""]',
        '[]'
    ),
    0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

SET @param = 'ec2_zones';
INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`,
    '_googleCEZones_',
    'custom',
    REPLACE(
        REPLACE(
            CONCAT(
                '["',
                REPLACE(
                    REPLACE(
                        REPLACE(
                            REPLACE(
                                CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                SUBSTRING_INDEX(
                                    CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                    CONCAT(@param, " "), 1
                                ),
                                ""
                            ),
                            REPLACE(
                                SUBSTRING_INDEX(
                                    REPLACE(
                                        CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                        SUBSTRING_INDEX(
                                            CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                            CONCAT(@param, " "), 1
                                        ),
                                        ""
                                    ),
                                    CONCAT(@param, " "), -1
                                ),
                                SUBSTRING_INDEX(SUBSTRING_INDEX(
                                    REPLACE(
                                        CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                        SUBSTRING_INDEX(
                                            CONVERT(FROM_BASE64(`field1`) USING UTF8MB4),
                                            CONCAT(@param, " "), 1
                                        ),
                                        ""
                                    ),
                                    CONCAT(@param, " "), -1
                                ), "\n", 1),
                                ""
                            ),
                            "\n"
                        ),
                        CONCAT(@param, " "),
                        ""
                    ),
                    "\n",
                    '","'
                ),
                '"]'
            ),
            ',""]',
            ']'
        ),
        '[""]',
        '[]'
    ),
    0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_googleCEZonesInstance_', 'custom', '[]', 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_threads_', 'custom', 1, 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_useProxy_', 'custom', 0, 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_proxyUrl_', 'custom', '', 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_sslCheck_', 'custom', 0, 0
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

INSERT IGNORE INTO `tdiscovery_apps_tasks_macros`
    (`id_task`, `macro`, `type`, `value`, `temp_conf`)
    SELECT
    `id_rt`, '_tempfileGoogleCE_', 'custom', 'agents_group_name=__taskGroup__&#x0d;&#x0a;interval=__taskInterval__&#x0d;&#x0a;threads=_threads_&#x0d;&#x0a;temporal=__temp__&#x0d;&#x0a;transfer_mode=tentacle&#x0d;&#x0a;tentacle_ip=_tentacleIP_&#x0d;&#x0a;tentacle_port=_tentaclePort_&#x0d;&#x0a;tentacle_opts=_tentacleExtraOpt_&#x0d;&#x0a;advance_monitoring=_googleCEInstanceSummary_&#x0d;&#x0a;cpu_summary=_googleCECpuPerfSummary_&#x0d;&#x0a;iops_summary=_googleCEIopsPerfSummary_&#x0d;&#x0a;disk_summary=_googleCEDiskPerfSummary_&#x0d;&#x0a;network_summary=_googleCENetworkPerfSummary_&#x0d;&#x0a;creds_b64=_credentials_&#x0d;&#x0a;gcp_zones=_googleCEZones_&#x0d;&#x0a;gcp_instances=_googleCEInstances_&#x0d;&#x0a;stats_agent=_statsAgent_&#x0d;&#x0a;stats_agent_name=_statsAgentName_', 1
    FROM `trecon_task`
    WHERE `type` = @current_app_type
;

-- Delete NULL macros
DELETE FROM `tdiscovery_apps_tasks_macros` WHERE `macro` = '';

-- Migrate current Google tasks
UPDATE `trecon_task`
    SET
        `id_app` = @id_app,
        `setup_complete` = 1,
        `type` = 15
    WHERE `type` = @current_app_type
;