From 1cb2f779453e3201d416b5b48c8c72101ae42150 Mon Sep 17 00:00:00 2001
From: fbsanchez <fborja.sanchez@artica.es>
Date: Fri, 8 Oct 2021 15:12:23 +0200
Subject: [PATCH] WIP NCM

---
 pandora_console/extras/mr/50.sql              | 31 ++++------
 .../pandoradb_migrate_6.0_to_7.0.mysql.sql    | 36 +++++-------
 .../general/first_task/cluster_builder.php    |  6 +-
 pandora_console/include/styles/first_task.css | 56 +++++++------------
 pandora_console/pandoradb.sql                 | 36 +++++-------
 5 files changed, 60 insertions(+), 105 deletions(-)

diff --git a/pandora_console/extras/mr/50.sql b/pandora_console/extras/mr/50.sql
index 69f951efd5..b012cc8b00 100644
--- a/pandora_console/extras/mr/50.sql
+++ b/pandora_console/extras/mr/50.sql
@@ -21,9 +21,11 @@ DELETE FROM `treport_content` WHERE type = 'histogram_data';
 
 CREATE TABLE IF NOT EXISTS `tncm_template` (
     `id` serial,
-    `vendor` text,
-    `model` text,
-    PRIMARY KEY (`id`)
+    `name` text,
+    `vendor` varchar(500),
+    `model` varchar(500),
+    PRIMARY KEY (`id`),
+	UNIQUE(`vendor`, `model`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 CREATE TABLE IF NOT EXISTS `tncm_script` (
@@ -51,31 +53,22 @@ CREATE TABLE IF NOT EXISTS `tncm_agent` (
     `status` int(4) NOT NULL default 5,
     `updated_at` bigint(20) NOT NULL default 0,
     `config_backup_id` bigint(20) UNSIGNED DEFAULT NULL,
+	`id_template` bigint(20) unsigned,
+	`execute` int(2) UNSIGNED NOT NULL default 0,
     PRIMARY KEY (`id_agent`),
     FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
-    FOREIGN KEY (`cred_key`) REFERENCES `tcredential_store`(`identifier`) ON UPDATE CASCADE ON DELETE SET NULL
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE IF NOT EXISTS `tncm_agent_templates` (
-    `id_agent` int(10) unsigned NOT NULL,
-    `id_template` bigint(20) unsigned NOT NULL,
-    `status` int(4) NOT NULL default 5,
-    `updated_at` bigint(20) NOT NULL default 0,
-    `execute` int(2) UNSIGNED NOT NULL default 0,
-    PRIMARY KEY (`id_agent`, `id_template`),
-    FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
-    FOREIGN KEY (`id_template`) REFERENCES `tncm_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
+    FOREIGN KEY (`cred_key`) REFERENCES `tcredential_store`(`identifier`) ON UPDATE CASCADE ON DELETE SET NULL,
+	FOREIGN KEY (`id_template`) REFERENCES `tncm_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 CREATE TABLE IF NOT EXISTS `tncm_agent_data` (
     `id_agent` int(10) unsigned NOT NULL,
-    `id_template` bigint(20) unsigned NOT NULL,
+    `script_type` int unsigned not null,
     `data` LONGBLOB,
     `status` int(4) NOT NULL default 5,
     `updated_at` bigint(20) NOT NULL default 0,
-    PRIMARY KEY (`id_agent`, `id_template`),
-    FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
-    FOREIGN KEY (`id_template`) REFERENCES `tncm_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
+    PRIMARY KEY (`id_agent`, `id_script`),
+    FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE
 ) 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 1b0d17c604..379ae946e1 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
@@ -4098,9 +4098,11 @@ UPDATE `tlanguage` SET `name` = 'Deutsch' WHERE `id_language` = 'de';
 -- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tncm_template` (
     `id` serial,
-    `vendor` text,
-    `model` text,
-    PRIMARY KEY (`id`)
+	`name` text,
+    `vendor` varchar(500),
+    `model` varchar(500),
+    PRIMARY KEY (`id`),
+	UNIQUE(`vendor`, `model`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 -- ----------------------------------------------------------------------
@@ -4126,7 +4128,7 @@ CREATE TABLE IF NOT EXISTS `tncm_template_scripts` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 -- ----------------------------------------------------------------------
--- Table `tncm_agents`
+-- Table `tncm_agent`
 -- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tncm_agent` (
     `id_agent` int(10) unsigned NOT NULL,
@@ -4137,23 +4139,12 @@ CREATE TABLE IF NOT EXISTS `tncm_agent` (
     `status` int(4) NOT NULL default 5,
     `updated_at` bigint(20) NOT NULL default 0,
     `config_backup_id` bigint(20) UNSIGNED DEFAULT NULL,
+	`id_template` bigint(20) unsigned,
+	`execute` int(2) UNSIGNED NOT NULL default 0,
     PRIMARY KEY (`id_agent`),
     FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
-    FOREIGN KEY (`cred_key`) REFERENCES `tcredential_store`(`identifier`) ON UPDATE CASCADE ON DELETE SET NULL
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
--- ----------------------------------------------------------------------
--- Table `tncm_agent_templates`
--- ----------------------------------------------------------------------
-CREATE TABLE IF NOT EXISTS `tncm_agent_templates` (
-    `id_agent` int(10) unsigned NOT NULL,
-    `id_template` bigint(20) unsigned NOT NULL,
-    `status` int(4) NOT NULL default 5,
-    `updated_at` bigint(20) NOT NULL default 0,
-    `execute` int(2) UNSIGNED NOT NULL default 0,
-    PRIMARY KEY (`id_agent`, `id_template`),
-    FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
-    FOREIGN KEY (`id_template`) REFERENCES `tncm_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
+    FOREIGN KEY (`cred_key`) REFERENCES `tcredential_store`(`identifier`) ON UPDATE CASCADE ON DELETE SET NULL,
+	FOREIGN KEY (`id_template`) REFERENCES `tncm_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 -- ----------------------------------------------------------------------
@@ -4161,11 +4152,10 @@ CREATE TABLE IF NOT EXISTS `tncm_agent_templates` (
 -- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tncm_agent_data` (
     `id_agent` int(10) unsigned NOT NULL,
-    `id_template` bigint(20) unsigned NOT NULL,
+    `script_type` int unsigned not null,
     `data` LONGBLOB,
     `status` int(4) NOT NULL default 5,
     `updated_at` bigint(20) NOT NULL default 0,
-    PRIMARY KEY (`id_agent`, `id_template`),
-    FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
-    FOREIGN KEY (`id_template`) REFERENCES `tncm_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
+    PRIMARY KEY (`id_agent`, `id_script`),
+    FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
diff --git a/pandora_console/general/first_task/cluster_builder.php b/pandora_console/general/first_task/cluster_builder.php
index 157bdce0d7..22c624c9a6 100644
--- a/pandora_console/general/first_task/cluster_builder.php
+++ b/pandora_console/general/first_task/cluster_builder.php
@@ -46,11 +46,11 @@ ui_require_css_file('first_task');
 ui_print_info_message(['no_close' => true, 'message' => __('There are no clusters defined yet.') ]);
 ?>
 
-<div class="new_task_cluster">
-    <div class="image_task_cluster">
+<div class="new_task">
+    <div class="image_task">
         <?php echo html_print_image('images/first_task/icono-cluster-activo.png', true, ['title' => __('Clusters')]); ?>
     </div>
-    <div class="text_task_cluster">
+    <div class="text_task">
         <h3> <?php echo __('Create Cluster'); ?></h3>
         <p id="description_task"> 
     <?php
diff --git a/pandora_console/include/styles/first_task.css b/pandora_console/include/styles/first_task.css
index 54a05d4855..b9d1e41ffa 100755
--- a/pandora_console/include/styles/first_task.css
+++ b/pandora_console/include/styles/first_task.css
@@ -1,25 +1,28 @@
 .new_task p,
+.new_task b,
+.new_task div {
+  font-size: 1.05em;
+}
+.new_task p,
 .new_task div {
   font-weight: inherit;
 }
+
 .new_task {
   margin-top: 30px;
   min-width: 600px;
+  width: 100%;
   left: 20px;
-  height: 300px;
+  height: auto;
   background-color: #ececec;
   border-radius: 3px 3px 3px 3px;
-}
-div.new_task_cluster {
-  margin-top: 30px;
-  left: 20px;
-  width: 60%;
-  border-radius: 3px 3px 3px 3px;
-}
-
-div.new_task_cluster,
-div.new_task_cluster > div {
-  background-color: #ececec;
+  clear: both;
+  display: flex;
+  flex-direction: row;
+  padding-top: 1em;
+  padding-bottom: 5em;
+  align-items: center;
+  align-content: center;
 }
 
 .title_task {
@@ -33,39 +36,20 @@ div.new_task_cluster > div {
 }
 
 .image_task {
-  width: 20%;
-  min-width: 175px;
-  height: 100%;
-  float: left;
-}
-.image_task_cluster {
-  width: 20%;
-  height: 100%;
-  float: left;
-  margin-left: 50px;
-  margin-top: 50px;
+  margin: auto 35px;
 }
+
 .image_task > img {
-  margin-top: 35%;
-  margin-left: 15%;
+  position: relative;
 }
 
 .text_task {
+  flex: 1 1 auto;
   width: 70%;
   float: left;
   height: 100%;
   padding-right: 25px;
 }
-.text_task_cluster {
-  width: 70%;
-  height: 100%;
-  padding-right: 25px;
-  margin-left: 270px;
-  padding-top: 10px;
-}
-.text_task > p {
-  margin-top: 4%;
-}
 
 .button_task {
   margin-top: 10px;
@@ -76,12 +60,10 @@ div.new_task_cluster > div {
   border: none;
 }
 #description_task {
-  font-size: 12px;
   line-height: 1.8em;
 }
 
 #fuerte {
-  font-size: 12px;
 }
 
 .flex-row-baseline * {
diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql
index a8e53bd245..d19119dbb8 100644
--- a/pandora_console/pandoradb.sql
+++ b/pandora_console/pandoradb.sql
@@ -4034,9 +4034,11 @@ CREATE TABLE IF NOT EXISTS `tsync_queue` (
 -- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tncm_template` (
     `id` serial,
-    `vendor` text,
-    `model` text,
-    PRIMARY KEY (`id`)
+	`name` text,
+	`vendor` varchar(500),
+    `model` varchar(500),
+    PRIMARY KEY (`id`),
+	UNIQUE(`vendor`, `model`)
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 -- ----------------------------------------------------------------------
@@ -4062,7 +4064,7 @@ CREATE TABLE IF NOT EXISTS `tncm_template_scripts` (
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 -- ----------------------------------------------------------------------
--- Table `tncm_agents`
+-- Table `tncm_agent`
 -- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tncm_agent` (
     `id_agent` int(10) unsigned NOT NULL,
@@ -4073,23 +4075,12 @@ CREATE TABLE IF NOT EXISTS `tncm_agent` (
     `status` int(4) NOT NULL default 5,
     `updated_at` bigint(20) NOT NULL default 0,
     `config_backup_id` bigint(20) UNSIGNED DEFAULT NULL,
+	`id_template` bigint(20) unsigned,
+	`execute` int(2) UNSIGNED NOT NULL default 0,
     PRIMARY KEY (`id_agent`),
     FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
-    FOREIGN KEY (`cred_key`) REFERENCES `tcredential_store`(`identifier`) ON UPDATE CASCADE ON DELETE SET NULL
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
--- ----------------------------------------------------------------------
--- Table `tncm_agent_templates`
--- ----------------------------------------------------------------------
-CREATE TABLE IF NOT EXISTS `tncm_agent_templates` (
-    `id_agent` int(10) unsigned NOT NULL,
-    `id_template` bigint(20) unsigned NOT NULL,
-    `status` int(4) NOT NULL default 5,
-    `updated_at` bigint(20) NOT NULL default 0,
-    `execute` int(2) UNSIGNED NOT NULL default 0,
-    PRIMARY KEY (`id_agent`, `id_template`),
-    FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
-    FOREIGN KEY (`id_template`) REFERENCES `tncm_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
+    FOREIGN KEY (`cred_key`) REFERENCES `tcredential_store`(`identifier`) ON UPDATE CASCADE ON DELETE SET NULL,
+	FOREIGN KEY (`id_template`) REFERENCES `tncm_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
 
 -- ----------------------------------------------------------------------
@@ -4097,11 +4088,10 @@ CREATE TABLE IF NOT EXISTS `tncm_agent_templates` (
 -- ----------------------------------------------------------------------
 CREATE TABLE IF NOT EXISTS `tncm_agent_data` (
     `id_agent` int(10) unsigned NOT NULL,
-    `id_template` bigint(20) unsigned NOT NULL,
+    `script_type` int unsigned not null,
     `data` LONGBLOB,
     `status` int(4) NOT NULL default 5,
     `updated_at` bigint(20) NOT NULL default 0,
-    PRIMARY KEY (`id_agent`, `id_template`),
-    FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE,
-    FOREIGN KEY (`id_template`) REFERENCES `tncm_template`(`id`) ON UPDATE CASCADE ON DELETE CASCADE
+    PRIMARY KEY (`id_agent`, `id_script`),
+    FOREIGN KEY (`id_agent`) REFERENCES `tagente`(`id_agente`) ON UPDATE CASCADE ON DELETE CASCADE
 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;