pandorafms/pandora_console/extras/mr/67.sql

1041 lines
63 KiB
MySQL
Raw Normal View History

2023-10-26 12:49:30 +02:00
START TRANSACTION;
ALTER TABLE `tncm_queue`
2023-10-30 10:52:13 +01:00
ADD COLUMN `id_agent_data` bigint unsigned AFTER `id_script`;
2023-10-26 12:49:30 +02:00
2023-10-31 16:55:35 +01:00
CREATE TABLE IF NOT EXISTS `tncm_agent_data_template` (
2023-10-31 13:45:26 +01:00
`id` SERIAL,
`name` TEXT,
`vendors` TEXT,
`models` TEXT,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
ALTER TABLE `tncm_agent`
2023-10-31 16:55:35 +01:00
ADD COLUMN `id_agent_data_template` BIGINT UNSIGNED NULL DEFAULT NULL AFTER `id_template`;
2023-10-31 13:45:26 +01:00
2023-10-31 16:55:35 +01:00
CREATE TABLE IF NOT EXISTS `tncm_agent_data_template_scripts` (
2023-10-31 13:45:26 +01:00
`id` SERIAL,
2023-10-31 16:55:35 +01:00
`id_agent_data_template` BIGINT UNSIGNED NOT NULL,
2023-10-31 13:45:26 +01:00
`id_script` BIGINT UNSIGNED NOT NULL,
PRIMARY KEY (`id`),
2023-10-31 16:55:35 +01:00
FOREIGN KEY (`id_agent_data_template`) REFERENCES `tncm_agent_data_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE,
2023-10-31 13:45:26 +01:00
FOREIGN KEY (`id_script`) REFERENCES `tncm_script`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=UTF8MB4;
ALTER TABLE `tncm_agent`
2023-10-31 16:55:35 +01:00
ADD COLUMN `agent_data_cron_interval` VARCHAR(100) NULL DEFAULT '' AFTER `cron_interval`;
2023-10-31 13:45:26 +01:00
ALTER TABLE `tncm_agent`
2023-10-31 16:55:35 +01:00
ADD COLUMN `agent_data_event_on_change` INT UNSIGNED NULL DEFAULT NULL AFTER `event_on_change`;
2023-10-31 13:45:26 +01:00
2023-11-06 15:06:16 +01:00
-- Add new vendor and model
SET @vendor_name = 'Cisco';
SET @model_name = 'Cisco-Generic';
SET @template_name = 'Cisco-Generic';
SET @agent_data_template_name = 'Cisco-Generic';
SET @script_test = 'enable\n
expect:Password:\s*
_enablepass_\n
exit\n';
SET @script_get_config = 'enable\n
expect:Password:\s*
_enablepass_\n
term length 0\n
capture:show running-config\n
exit\n';
SET @script_set_config = 'enable\n
expect:Password:\s*
_enablepass_\n
term length 0\n
config terminal\n
_applyconfigbackup_\n
exit\n';
SET @script_get_firmware = 'enable\n
expect:Password:\s*
_enablepass_\n
term length 0\n
capture:show version | i IOS Software\n
exit\n';
SET @script_set_firmware = 'copy tftp flash\n
expect:\]\?
_TFTP_SERVER_IP_\n
expect:\]\?
_SOURCE_FILE_NAME_\n
expect:\]\?
_DESTINATION_FILE_NAME_\n
show flash\n
reload\n
expect:confirm
y\n
config terminal\n
boot system _DESTINATION_FILE_NAME_\n';
SET @script_custom = '';
SET @script_os_version = @script_get_firmware;
-- Try to insert vendor
INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, '');
-- Get vendor ID
SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name;
-- Try to insert model
INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name);
-- Get model ID
SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name;
-- Get template ID if exists
SET @id_template = NULL;
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Try to insert template
INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get template ID again if inserted
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Get agent data template ID if exists
SET @id_agent_data_template = NULL;
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Try to insert agent data template
INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get agent data template ID again if inserted
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Get test script ID if exists
SET @id_script_test = NULL;
SET @script_type = 0;
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Try to insert test script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test);
-- Get test script ID again if inserted
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Get get_config script ID if exists
SET @id_script_get_config = NULL;
SET @script_type = 1;
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Try to insert get_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config);
-- Get get_config script ID again if inserted
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Get set_config script ID if exists
SET @id_script_set_config = NULL;
SET @script_type = 2;
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Try to insert set_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config);
-- Get set_config script ID again if inserted
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Get get_firmware script ID if exists
SET @id_script_get_firmware = NULL;
SET @script_type = 3;
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Try to insert get_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware);
-- Get get_firmware script ID again if inserted
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Get set_firmware script ID if exists
SET @id_script_set_firmware = NULL;
SET @script_type = 4;
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Try to insert set_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware);
-- Get set_firmware script ID again if inserted
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Get custom script ID if exists
SET @id_script_custom = NULL;
SET @script_type = 5;
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Try to insert custom script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom);
-- Get custom script ID again if inserted
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Get os_version script ID if exists
SET @id_script_os_version = NULL;
SET @script_type = 7;
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Try to insert os_version script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version);
-- Get os_version script ID again if inserted
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Get template scripts ID if exists
SET @id_ts_test = NULL;
SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test);
-- Get template scripts ID if exists
SET @id_ts_get_config = NULL;
SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config);
-- Get template scripts ID if exists
SET @id_ts_set_config = NULL;
SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config);
-- Get template scripts ID if exists
SET @id_ts_get_firmware = NULL;
SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware);
-- Get template scripts ID if exists
SET @id_ts_set_firmware = NULL;
SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware);
-- Get template scripts ID if exists
SET @id_ts_custom = NULL;
SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom);
-- Get template scripts ID if exists
SET @id_ts_os_version = NULL;
SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version;
-- Try to insert
INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version);
-- Add new vendor and model
SET @vendor_name = 'Juniper';
SET @model_name = 'Juniper-Generic';
SET @template_name = 'Juniper-Generic';
SET @agent_data_template_name = 'Juniper-Generic';
SET @script_test = 'expect:root@%
cli\n
exit\n';
SET @script_get_config = 'expect:root@%
cli\n
expect:root>
capture:show configuration\n
capture:\n
quit\n
expect:root@%
exit\n';
SET @script_set_config = 'expect:root@%
cli\n
expect:root>
configure\n
load override terminal\n
_applyconfigbackup_\n
commit\n
exit\n';
SET @script_get_firmware = 'expect:root@%
cli\n
expect:root>
capture:show version|match Junos:\n
capture: \n
quit\n
expect:root@%
exit\n';
SET @script_set_firmware = 'expect:root@%
cli\n
expect:root>
save software from tftp _TFTP_SERVER_IP_ _FIRMWARE_NAME_ to flash\n
reset\n
exit\n';
SET @script_custom = '';
SET @script_os_version = @script_get_firmware;
-- Try to insert vendor
INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, '');
-- Get vendor ID
SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name;
-- Try to insert model
INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name);
-- Get model ID
SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name;
-- Get template ID if exists
SET @id_template = NULL;
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Try to insert template
INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get template ID again if inserted
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Get agent data template ID if exists
SET @id_agent_data_template = NULL;
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Try to insert agent data template
INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get agent data template ID again if inserted
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Get test script ID if exists
SET @id_script_test = NULL;
SET @script_type = 0;
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Try to insert test script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test);
-- Get test script ID again if inserted
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Get get_config script ID if exists
SET @id_script_get_config = NULL;
SET @script_type = 1;
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Try to insert get_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config);
-- Get get_config script ID again if inserted
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Get set_config script ID if exists
SET @id_script_set_config = NULL;
SET @script_type = 2;
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Try to insert set_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config);
-- Get set_config script ID again if inserted
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Get get_firmware script ID if exists
SET @id_script_get_firmware = NULL;
SET @script_type = 3;
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Try to insert get_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware);
-- Get get_firmware script ID again if inserted
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Get set_firmware script ID if exists
SET @id_script_set_firmware = NULL;
SET @script_type = 4;
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Try to insert set_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware);
-- Get set_firmware script ID again if inserted
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Get custom script ID if exists
SET @id_script_custom = NULL;
SET @script_type = 5;
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Try to insert custom script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom);
-- Get custom script ID again if inserted
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Get os_version script ID if exists
SET @id_script_os_version = NULL;
SET @script_type = 7;
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Try to insert os_version script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version);
-- Get os_version script ID again if inserted
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Get template scripts ID if exists
SET @id_ts_test = NULL;
SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test);
-- Get template scripts ID if exists
SET @id_ts_get_config = NULL;
SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config);
-- Get template scripts ID if exists
SET @id_ts_set_config = NULL;
SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config);
-- Get template scripts ID if exists
SET @id_ts_get_firmware = NULL;
SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware);
-- Get template scripts ID if exists
SET @id_ts_set_firmware = NULL;
SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware);
-- Get template scripts ID if exists
SET @id_ts_custom = NULL;
SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom);
-- Get template scripts ID if exists
SET @id_ts_os_version = NULL;
SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version;
-- Try to insert
INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version);
-- Add new vendor and model
SET @vendor_name = 'Palo Alto';
SET @model_name = 'Palo Alto-Generic';
SET @template_name = 'Palo Alto-Generic';
SET @agent_data_template_name = 'Palo Alto-Generic';
SET @script_test = 'sleep:1
exit\n';
SET @script_get_config = 'set cli pager off \n
capture:show config running\n
exit\n';
SET @script_set_config = 'set cli terminal width 500\n
set cli scripting-mode on\n
configure\n
_applyconfigbackup_\n
commit\n';
SET @script_get_firmware = 'set cli pager off \n
capture:show system info | match app-version:\n
sleep:1 
expect:app-version:\s*
exit \n';
SET @script_set_firmware = 'tftp import software from _TFTP_SERVER_IP_ file _FIRMWARE_NAME_\n
request system software install version\n
reboot\n
exit\n';
SET @script_custom = '';
SET @script_os_version = @script_get_firmware;
-- Try to insert vendor
INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, '');
-- Get vendor ID
SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name;
-- Try to insert model
INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name);
-- Get model ID
SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name;
-- Get template ID if exists
SET @id_template = NULL;
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Try to insert template
INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get template ID again if inserted
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Get agent data template ID if exists
SET @id_agent_data_template = NULL;
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Try to insert agent data template
INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get agent data template ID again if inserted
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Get test script ID if exists
SET @id_script_test = NULL;
SET @script_type = 0;
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Try to insert test script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test);
-- Get test script ID again if inserted
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Get get_config script ID if exists
SET @id_script_get_config = NULL;
SET @script_type = 1;
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Try to insert get_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config);
-- Get get_config script ID again if inserted
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Get set_config script ID if exists
SET @id_script_set_config = NULL;
SET @script_type = 2;
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Try to insert set_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config);
-- Get set_config script ID again if inserted
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Get get_firmware script ID if exists
SET @id_script_get_firmware = NULL;
SET @script_type = 3;
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Try to insert get_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware);
-- Get get_firmware script ID again if inserted
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Get set_firmware script ID if exists
SET @id_script_set_firmware = NULL;
SET @script_type = 4;
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Try to insert set_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware);
-- Get set_firmware script ID again if inserted
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Get custom script ID if exists
SET @id_script_custom = NULL;
SET @script_type = 5;
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Try to insert custom script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom);
-- Get custom script ID again if inserted
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Get os_version script ID if exists
SET @id_script_os_version = NULL;
SET @script_type = 7;
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Try to insert os_version script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version);
-- Get os_version script ID again if inserted
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Get template scripts ID if exists
SET @id_ts_test = NULL;
SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test);
-- Get template scripts ID if exists
SET @id_ts_get_config = NULL;
SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config);
-- Get template scripts ID if exists
SET @id_ts_set_config = NULL;
SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config);
-- Get template scripts ID if exists
SET @id_ts_get_firmware = NULL;
SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware);
-- Get template scripts ID if exists
SET @id_ts_set_firmware = NULL;
SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware);
-- Get template scripts ID if exists
SET @id_ts_custom = NULL;
SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom);
-- Get template scripts ID if exists
SET @id_ts_os_version = NULL;
SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version;
-- Try to insert
INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version);
-- Add new vendor and model
SET @vendor_name = 'A10';
SET @model_name = 'A10-Generic';
SET @template_name = 'A10-Generic';
SET @agent_data_template_name = 'A10-Generic';
SET @script_test = 'sleep:1
enable\n
expect:Password:\s*
_enablepass_\n';
SET @script_get_config = 'sleep:1
enable\n
expect:Password:\s*
_enablepass_\n
capture:show running-config\n
exit\n';
SET @script_set_config = 'sleep:1
enable\n
expect:Password:\s*
_enablepass_\n
configure\n
_applyconfigbackup_\n
exit\n';
SET @script_get_firmware = 'sleep:1
enable\n
expect:Password:\s*
_enablepass_\n
capture:show version\n
exit\n';
SET @script_set_firmware = 'sleep:1
enable\n
expect:Password:\s*
_enablepass_\n
configure\n
expect:(config)
restore _TFTP_SERVER_IP_/_FIRMWARE_NAME_\n
expect:Password:\s*
_enablepass_\n
expect:skip port map
yes\n
expect: see the diff
yes\n
sleep:1
expect:Proceed with reboot
yes\n
expect:eof';
SET @script_custom = '';
SET @script_os_version = @script_get_firmware;
-- Try to insert vendor
INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, '');
-- Get vendor ID
SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name;
-- Try to insert model
INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name);
-- Get model ID
SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name;
-- Get template ID if exists
SET @id_template = NULL;
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Try to insert template
INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get template ID again if inserted
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Get agent data template ID if exists
SET @id_agent_data_template = NULL;
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Try to insert agent data template
INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get agent data template ID again if inserted
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Get test script ID if exists
SET @id_script_test = NULL;
SET @script_type = 0;
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Try to insert test script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test);
-- Get test script ID again if inserted
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Get get_config script ID if exists
SET @id_script_get_config = NULL;
SET @script_type = 1;
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Try to insert get_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config);
-- Get get_config script ID again if inserted
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Get set_config script ID if exists
SET @id_script_set_config = NULL;
SET @script_type = 2;
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Try to insert set_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config);
-- Get set_config script ID again if inserted
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Get get_firmware script ID if exists
SET @id_script_get_firmware = NULL;
SET @script_type = 3;
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Try to insert get_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware);
-- Get get_firmware script ID again if inserted
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Get set_firmware script ID if exists
SET @id_script_set_firmware = NULL;
SET @script_type = 4;
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Try to insert set_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware);
-- Get set_firmware script ID again if inserted
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Get custom script ID if exists
SET @id_script_custom = NULL;
SET @script_type = 5;
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Try to insert custom script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom);
-- Get custom script ID again if inserted
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Get os_version script ID if exists
SET @id_script_os_version = NULL;
SET @script_type = 7;
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Try to insert os_version script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version);
-- Get os_version script ID again if inserted
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Get template scripts ID if exists
SET @id_ts_test = NULL;
SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test);
-- Get template scripts ID if exists
SET @id_ts_get_config = NULL;
SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config);
-- Get template scripts ID if exists
SET @id_ts_set_config = NULL;
SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config);
-- Get template scripts ID if exists
SET @id_ts_get_firmware = NULL;
SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware);
-- Get template scripts ID if exists
SET @id_ts_set_firmware = NULL;
SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware);
-- Get template scripts ID if exists
SET @id_ts_custom = NULL;
SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom);
-- Get template scripts ID if exists
SET @id_ts_os_version = NULL;
SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version;
-- Try to insert
INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version);
-- Add new vendor and model
SET @vendor_name = 'Alcatel-Lucent Enterprise';
SET @model_name = 'Alcatel-Generic';
SET @template_name = 'Alcatel-Generic';
SET @agent_data_template_name = 'Alcatel-Generic';
SET @script_test = 'enable\n
expect:Password:\s*
_enablepass_\n
exit\n';
SET @script_get_config = 'enable\n
expect:Password:\s*
_enablepass_\n
capture:admin display-config\n
logout\n';
SET @script_set_config = '';
SET @script_get_firmware = 'enable\n
expect:Password:\s*
_enablepass_\n
capture:show version\n
logout\n';
SET @script_set_firmware = '';
SET @script_custom = '';
SET @script_os_version = @script_get_firmware;
-- Try to insert vendor
INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, '');
-- Get vendor ID
SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name;
-- Try to insert model
INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name);
-- Get model ID
SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name;
-- Get template ID if exists
SET @id_template = NULL;
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Try to insert template
INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get template ID again if inserted
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Get agent data template ID if exists
SET @id_agent_data_template = NULL;
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Try to insert agent data template
INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get agent data template ID again if inserted
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Get test script ID if exists
SET @id_script_test = NULL;
SET @script_type = 0;
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Try to insert test script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test);
-- Get test script ID again if inserted
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Get get_config script ID if exists
SET @id_script_get_config = NULL;
SET @script_type = 1;
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Try to insert get_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config);
-- Get get_config script ID again if inserted
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Get set_config script ID if exists
SET @id_script_set_config = NULL;
SET @script_type = 2;
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Try to insert set_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config);
-- Get set_config script ID again if inserted
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Get get_firmware script ID if exists
SET @id_script_get_firmware = NULL;
SET @script_type = 3;
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Try to insert get_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware);
-- Get get_firmware script ID again if inserted
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Get set_firmware script ID if exists
SET @id_script_set_firmware = NULL;
SET @script_type = 4;
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Try to insert set_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware);
-- Get set_firmware script ID again if inserted
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Get custom script ID if exists
SET @id_script_custom = NULL;
SET @script_type = 5;
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Try to insert custom script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom);
-- Get custom script ID again if inserted
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Get os_version script ID if exists
SET @id_script_os_version = NULL;
SET @script_type = 7;
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Try to insert os_version script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version);
-- Get os_version script ID again if inserted
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Get template scripts ID if exists
SET @id_ts_test = NULL;
SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test);
-- Get template scripts ID if exists
SET @id_ts_get_config = NULL;
SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config);
-- Get template scripts ID if exists
SET @id_ts_set_config = NULL;
SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config);
-- Get template scripts ID if exists
SET @id_ts_get_firmware = NULL;
SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware);
-- Get template scripts ID if exists
SET @id_ts_set_firmware = NULL;
SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware);
-- Get template scripts ID if exists
SET @id_ts_custom = NULL;
SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom);
-- Get template scripts ID if exists
SET @id_ts_os_version = NULL;
SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version;
-- Try to insert
INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version);
-- Add new vendor and model
SET @vendor_name = 'Aruba';
SET @model_name = 'Aruba-Generic';
SET @template_name = 'Aruba-Generic';
SET @agent_data_template_name = 'Aruba-Generic';
SET @script_test = 'enable\n
expect:Password:\s*
_enablepass_\n
exit\n';
SET @script_get_config = 'enable\n
expect:Password:\s*
_enablepass_\n
capture:show running-config\n
exit\n';
SET @script_set_config = 'configure terminal\n
load replace /var/tmp/file.conf\n
end\n
write memory\n
exit\n';
SET @script_get_firmware = 'enable\n
expect:Password:\s*
_enablepass_\n
capture:show version\n
exit\n';
SET @script_set_firmware = 'copy tftp flash _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_.swi secondary\n
boot system flash secondary\n
copy tftp flash  _TFTP_SERVER_IP_ _DESTINATION_FILE_NAME_ primary\n
boot system flash primary\n';
SET @script_custom = '';
SET @script_os_version = @script_get_firmware;
-- Try to insert vendor
INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, '');
-- Get vendor ID
SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name;
-- Try to insert model
INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name);
-- Get model ID
SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name;
-- Get template ID if exists
SET @id_template = NULL;
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Try to insert template
INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get template ID again if inserted
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Get agent data template ID if exists
SET @id_agent_data_template = NULL;
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Try to insert agent data template
INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get agent data template ID again if inserted
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Get test script ID if exists
SET @id_script_test = NULL;
SET @script_type = 0;
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Try to insert test script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test);
-- Get test script ID again if inserted
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Get get_config script ID if exists
SET @id_script_get_config = NULL;
SET @script_type = 1;
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Try to insert get_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config);
-- Get get_config script ID again if inserted
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Get set_config script ID if exists
SET @id_script_set_config = NULL;
SET @script_type = 2;
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Try to insert set_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config);
-- Get set_config script ID again if inserted
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Get get_firmware script ID if exists
SET @id_script_get_firmware = NULL;
SET @script_type = 3;
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Try to insert get_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware);
-- Get get_firmware script ID again if inserted
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Get set_firmware script ID if exists
SET @id_script_set_firmware = NULL;
SET @script_type = 4;
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Try to insert set_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware);
-- Get set_firmware script ID again if inserted
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Get custom script ID if exists
SET @id_script_custom = NULL;
SET @script_type = 5;
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Try to insert custom script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom);
-- Get custom script ID again if inserted
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Get os_version script ID if exists
SET @id_script_os_version = NULL;
SET @script_type = 7;
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Try to insert os_version script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version);
-- Get os_version script ID again if inserted
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Get template scripts ID if exists
SET @id_ts_test = NULL;
SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test);
-- Get template scripts ID if exists
SET @id_ts_get_config = NULL;
SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config);
-- Get template scripts ID if exists
SET @id_ts_set_config = NULL;
SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config);
-- Get template scripts ID if exists
SET @id_ts_get_firmware = NULL;
SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware);
-- Get template scripts ID if exists
SET @id_ts_set_firmware = NULL;
SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware);
-- Get template scripts ID if exists
SET @id_ts_custom = NULL;
SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom);
-- Get template scripts ID if exists
SET @id_ts_os_version = NULL;
SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version;
-- Try to insert
INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version);
-- Add new vendor and model
SET @vendor_name = 'Mikrotik';
SET @model_name = 'Mikrotik-Generic';
SET @template_name = 'Mikrotik-Generic';
SET @agent_data_template_name = 'Mikrotik-Generic';
SET @script_test = 'sleep:1
exit\n\r';
SET @script_get_config = 'sleep:1
capture:system resource print\n\r 
exit\n\r';
SET @script_set_config = 'sleep:1
system backup load name=_nameBackup_ password=_passwordBackup_\n\r
expect:Restore
yes\n\r
exit\n\r';
SET @script_get_firmware = 'sleep:1
capture:/system package print\n\r 
exit\n\r';
SET @script_set_firmware = 'sleep:1
/system routerboard upgrade\n\r
expect:Do
yes\n\r
exit\n\r';
SET @script_custom = '';
SET @script_os_version = @script_get_firmware;
-- Try to insert vendor
INSERT IGNORE INTO `tncm_vendor` (`id`, `name`, `icon`) VALUES ('', @vendor_name, '');
-- Get vendor ID
SELECT @id_vendor := `id` FROM `tncm_vendor` WHERE `name` = @vendor_name;
-- Try to insert model
INSERT IGNORE INTO `tncm_model` (`id`, `id_vendor`, `name`) VALUES ('', @id_vendor, @model_name);
-- Get model ID
SELECT @id_model := `id` FROM `tncm_model` WHERE `id_vendor` = @id_vendor AND `name` = @model_name;
-- Get template ID if exists
SET @id_template = NULL;
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Try to insert template
INSERT IGNORE INTO `tncm_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_template, @template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get template ID again if inserted
SELECT @id_template := `id` FROM `tncm_template` WHERE `name` = @template_name;
-- Get agent data template ID if exists
SET @id_agent_data_template = NULL;
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Try to insert agent data template
INSERT IGNORE INTO `tncm_agent_data_template` (`id`, `name`, `vendors`, `models`) VALUES (@id_agent_data_template, @agent_data_template_name, CONCAT('[',@id_vendor,']'), CONCAT('[',@id_model,']'));
-- Get agent data template ID again if inserted
SELECT @id_agent_data_template := `id` FROM `tncm_agent_data_template` WHERE `name` = @agent_data_template_name;
-- Get test script ID if exists
SET @id_script_test = NULL;
SET @script_type = 0;
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Try to insert test script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_test, @script_type, @script_test);
-- Get test script ID again if inserted
SELECT @id_script_test := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_test;
-- Get get_config script ID if exists
SET @id_script_get_config = NULL;
SET @script_type = 1;
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Try to insert get_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_config, @script_type, @script_get_config);
-- Get get_config script ID again if inserted
SELECT @id_script_get_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_config;
-- Get set_config script ID if exists
SET @id_script_set_config = NULL;
SET @script_type = 2;
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Try to insert set_config script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_config, @script_type, @script_set_config);
-- Get set_config script ID again if inserted
SELECT @id_script_set_config := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_config;
-- Get get_firmware script ID if exists
SET @id_script_get_firmware = NULL;
SET @script_type = 3;
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Try to insert get_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_get_firmware, @script_type, @script_get_firmware);
-- Get get_firmware script ID again if inserted
SELECT @id_script_get_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_get_firmware;
-- Get set_firmware script ID if exists
SET @id_script_set_firmware = NULL;
SET @script_type = 4;
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Try to insert set_firmware script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_set_firmware, @script_type, @script_set_firmware);
-- Get set_firmware script ID again if inserted
SELECT @id_script_set_firmware := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_set_firmware;
-- Get custom script ID if exists
SET @id_script_custom = NULL;
SET @script_type = 5;
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Try to insert custom script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_custom, @script_type, @script_custom);
-- Get custom script ID again if inserted
SELECT @id_script_custom := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_custom;
-- Get os_version script ID if exists
SET @id_script_os_version = NULL;
SET @script_type = 7;
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Try to insert os_version script
INSERT IGNORE INTO `tncm_script` (`id`, `type`, `content`) VALUES (@id_script_os_version, @script_type, @script_os_version);
-- Get os_version script ID again if inserted
SELECT @id_script_os_version := `id` FROM `tncm_script` WHERE `type` = @script_type AND `content` = @script_os_version;
-- Get template scripts ID if exists
SET @id_ts_test = NULL;
SELECT @id_ts_test := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_test;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_test, @id_template, @id_script_test);
-- Get template scripts ID if exists
SET @id_ts_get_config = NULL;
SELECT @id_ts_get_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_config, @id_template, @id_script_get_config);
-- Get template scripts ID if exists
SET @id_ts_set_config = NULL;
SELECT @id_ts_set_config := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_config;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_config, @id_template, @id_script_set_config);
-- Get template scripts ID if exists
SET @id_ts_get_firmware = NULL;
SELECT @id_ts_get_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_get_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_get_firmware, @id_template, @id_script_get_firmware);
-- Get template scripts ID if exists
SET @id_ts_set_firmware = NULL;
SELECT @id_ts_set_firmware := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_set_firmware;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_set_firmware, @id_template, @id_script_set_firmware);
-- Get template scripts ID if exists
SET @id_ts_custom = NULL;
SELECT @id_ts_custom := `id` FROM `tncm_template_scripts` WHERE `id_template` = @id_template AND `id_script` = @id_script_custom;
-- Try to insert
INSERT IGNORE INTO `tncm_template_scripts` (`id`, `id_template`, `id_script`) VALUES (@id_ts_custom, @id_template, @id_script_custom);
-- Get template scripts ID if exists
SET @id_ts_os_version = NULL;
SELECT @id_ts_os_version := `id` FROM `tncm_agent_data_template_scripts` WHERE `id_agent_data_template` = @id_template AND `id_script` = @id_script_os_version;
-- Try to insert
INSERT IGNORE INTO `tncm_agent_data_template_scripts` (`id`, `id_agent_data_template`, `id_script`) VALUES (@id_ts_os_version, @id_agent_data_template, @id_script_os_version);
2023-10-31 13:45:26 +01:00
COMMIT;