From 62d8c04ab3bf4798a241655a1d58918be0cb6993 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Tue, 23 Jul 2019 13:01:50 +0200 Subject: [PATCH] Agent deployment v1 --- pandora_console/extras/mr/30.sql | 42 ++++++++-------- .../pandoradb_migrate_6.0_to_7.0.mysql.sql | 48 ++++++++++--------- pandora_console/pandoradb.sql | 48 ++++++++++--------- .../lib/PandoraFMS/DiscoveryServer.pm | 6 +++ 4 files changed, 78 insertions(+), 66 deletions(-) diff --git a/pandora_console/extras/mr/30.sql b/pandora_console/extras/mr/30.sql index e8a9703835..dd8439745a 100644 --- a/pandora_console/extras/mr/30.sql +++ b/pandora_console/extras/mr/30.sql @@ -23,24 +23,6 @@ CREATE TABLE `ttask_credentials` ( ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -CREATE TABLE `tdeployment_hosts` ( - `id` SERIAL, - `id_cs` VARCHAR(100), - `ip` VARCHAR(100) NOT NULL UNIQUE, - `id_os` INT(10) UNSIGNED DEFAULT 0, - `os_version` VARCHAR(100) DEFAULT '' COMMENT "OS version in STR format", - `arch` ENUM('x64', 'x86') DEFAULT 'x64', - `current_agent_version` VARCHAR(100) DEFAULT '', - `desired_agent_version` VARCHAR(100) DEFAULT '', - `deployed` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", - `last_err` text, - PRIMARY KEY (`id`), - FOREIGN KEY (`id_cs`) REFERENCES `tcredential_store` (`identifier`) - ON UPDATE CASCADE ON DELETE SET NULL, - FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) - ON UPDATE CASCADE ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - CREATE TABLE `tagent_repository` ( `id` SERIAL, `id_os` INT(10) UNSIGNED DEFAULT 0, @@ -48,12 +30,32 @@ CREATE TABLE `tagent_repository` ( `version` VARCHAR(10) DEFAULT '', `path` text, `uploaded_by` VARCHAR(100) DEFAULT '', - `uploaded` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", + `uploaded` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was uploaded", `last_err` text, PRIMARY KEY (`id`), - FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) + FOREIGN KEY (`id_os`) REFERENCES `tconfig_os`(`id_os`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +CREATE TABLE `tdeployment_hosts` ( + `id` SERIAL, + `id_cs` VARCHAR(100), + `ip` VARCHAR(100) NOT NULL UNIQUE, + `id_os` INT(10) UNSIGNED DEFAULT 0, + `os_version` VARCHAR(100) DEFAULT '' COMMENT "OS version in STR format", + `arch` ENUM('x64', 'x86') DEFAULT 'x64', + `current_agent_version` VARCHAR(100) DEFAULT '' COMMENT "String latest installed agent", + `target_agent_version_id` BIGINT UNSIGNED, + `deployed` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", + `last_err` text, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_cs`) REFERENCES `tcredential_store`(`identifier`) + ON UPDATE CASCADE ON DELETE SET NULL, + FOREIGN KEY (`id_os`) REFERENCES `tconfig_os`(`id_os`) + ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`target_agent_version_id`) REFERENCES `tagent_repository`(`id`) + ON UPDATE CASCADE ON DELETE SET NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + COMMIT; diff --git a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql index 60c74f4a60..40f192b32e 100644 --- a/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql +++ b/pandora_console/extras/pandoradb_migrate_6.0_to_7.0.mysql.sql @@ -2235,27 +2235,6 @@ CREATE TABLE `ttask_credentials` ( ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- ---------------------------------------------------------------------- --- Table `tdeployment_hosts` --- ---------------------------------------------------------------------- -CREATE TABLE `tdeployment_hosts` ( - `id` SERIAL, - `id_cs` VARCHAR(100), - `ip` VARCHAR(100) NOT NULL UNIQUE, - `id_os` INT(10) UNSIGNED DEFAULT 0, - `os_version` VARCHAR(100) DEFAULT '' COMMENT "OS version in STR format", - `arch` ENUM('x64', 'x86') DEFAULT 'x64', - `current_agent_version` VARCHAR(100) DEFAULT '', - `desired_agent_version` VARCHAR(100) DEFAULT '', - `deployed` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", - `last_err` text, - PRIMARY KEY (`id`), - FOREIGN KEY (`id_cs`) REFERENCES `tcredential_store` (`identifier`) - ON UPDATE CASCADE ON DELETE SET NULL, - FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) - ON UPDATE CASCADE ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -- --------------------------------------------------------------------- -- Table `tagent_repository` -- --------------------------------------------------------------------- @@ -2266,9 +2245,32 @@ CREATE TABLE `tagent_repository` ( `version` VARCHAR(10) DEFAULT '', `path` text, `uploaded_by` VARCHAR(100) DEFAULT '', - `uploaded` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", + `uploaded` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was uploaded", `last_err` text, PRIMARY KEY (`id`), - FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) + FOREIGN KEY (`id_os`) REFERENCES `tconfig_os`(`id_os`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ---------------------------------------------------------------------- +-- Table `tdeployment_hosts` +-- ---------------------------------------------------------------------- +CREATE TABLE `tdeployment_hosts` ( + `id` SERIAL, + `id_cs` VARCHAR(100), + `ip` VARCHAR(100) NOT NULL UNIQUE, + `id_os` INT(10) UNSIGNED DEFAULT 0, + `os_version` VARCHAR(100) DEFAULT '' COMMENT "OS version in STR format", + `arch` ENUM('x64', 'x86') DEFAULT 'x64', + `current_agent_version` VARCHAR(100) DEFAULT '' COMMENT "String latest installed agent", + `target_agent_version_id` BIGINT UNSIGNED, + `deployed` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", + `last_err` text, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_cs`) REFERENCES `tcredential_store`(`identifier`) + ON UPDATE CASCADE ON DELETE SET NULL, + FOREIGN KEY (`id_os`) REFERENCES `tconfig_os`(`id_os`) + ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`target_agent_version_id`) REFERENCES `tagent_repository`(`id`) + ON UPDATE CASCADE ON DELETE SET NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql index 57c3f5c59b..b9a35fbb99 100644 --- a/pandora_console/pandoradb.sql +++ b/pandora_console/pandoradb.sql @@ -824,27 +824,6 @@ CREATE TABLE `ttask_credentials` ( ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; --- ---------------------------------------------------------------------- --- Table `tdeployment_hosts` --- ---------------------------------------------------------------------- -CREATE TABLE `tdeployment_hosts` ( - `id` SERIAL, - `id_cs` VARCHAR(100), - `ip` VARCHAR(100) NOT NULL UNIQUE, - `id_os` INT(10) UNSIGNED DEFAULT 0, - `os_version` VARCHAR(100) DEFAULT '' COMMENT "OS version in STR format", - `arch` ENUM('x64', 'x86') DEFAULT 'x64', - `current_agent_version` VARCHAR(100) DEFAULT '', - `desired_agent_version` VARCHAR(100) DEFAULT '', - `deployed` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", - `last_err` text, - PRIMARY KEY (`id`), - FOREIGN KEY (`id_cs`) REFERENCES `tcredential_store` (`identifier`) - ON UPDATE CASCADE ON DELETE SET NULL, - FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) - ON UPDATE CASCADE ON DELETE CASCADE -) ENGINE=InnoDB DEFAULT CHARSET=utf8; - -- ---------------------------------------------------------------------- -- Table `tmodule_relationship` -- ---------------------------------------------------------------------- @@ -3657,9 +3636,32 @@ CREATE TABLE `tagent_repository` ( `version` VARCHAR(10) DEFAULT '', `path` text, `uploaded_by` VARCHAR(100) DEFAULT '', - `uploaded` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", + `uploaded` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was uploaded", `last_err` text, PRIMARY KEY (`id`), - FOREIGN KEY (`id_os`) REFERENCES tconfig_os(`id_os`) + FOREIGN KEY (`id_os`) REFERENCES `tconfig_os`(`id_os`) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- ---------------------------------------------------------------------- +-- Table `tdeployment_hosts` +-- ---------------------------------------------------------------------- +CREATE TABLE `tdeployment_hosts` ( + `id` SERIAL, + `id_cs` VARCHAR(100), + `ip` VARCHAR(100) NOT NULL UNIQUE, + `id_os` INT(10) UNSIGNED DEFAULT 0, + `os_version` VARCHAR(100) DEFAULT '' COMMENT "OS version in STR format", + `arch` ENUM('x64', 'x86') DEFAULT 'x64', + `current_agent_version` VARCHAR(100) DEFAULT '' COMMENT "String latest installed agent", + `target_agent_version_id` BIGINT UNSIGNED, + `deployed` bigint(20) NOT NULL DEFAULT 0 COMMENT "When it was deployed", + `last_err` text, + PRIMARY KEY (`id`), + FOREIGN KEY (`id_cs`) REFERENCES `tcredential_store`(`identifier`) + ON UPDATE CASCADE ON DELETE SET NULL, + FOREIGN KEY (`id_os`) REFERENCES `tconfig_os`(`id_os`) + ON UPDATE CASCADE ON DELETE CASCADE, + FOREIGN KEY (`target_agent_version_id`) REFERENCES `tagent_repository`(`id`) + ON UPDATE CASCADE ON DELETE SET NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8; diff --git a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm index e91b580498..de3fa45f39 100644 --- a/pandora_server/lib/PandoraFMS/DiscoveryServer.pm +++ b/pandora_server/lib/PandoraFMS/DiscoveryServer.pm @@ -237,6 +237,12 @@ sub data_consumer ($$) { && -f $cnf_extra{'creds_file'}) { unlink($cnf_extra{'creds_file'}); } + + + # Clean one shot tasks + if ($task->{'type'} eq DISCOVERY_DEPLOY_AGENTS) { + db_delete_limit($dbh, ' trecon_task ', ' id_rt = ? ', 1, $task->{'id_rt'}); + } }; if ($@) { logger(