From 014688468c2f3d066c244290d24a57005102bd0d Mon Sep 17 00:00:00 2001
From: alejandro-campos <alejandro.campos@artica.es>
Date: Thu, 19 Mar 2020 15:18:20 +0100
Subject: [PATCH] changes to show last status change of modules

---
 .../pandoradb_migrate_6.0_to_7.0.mysql.sql     |  1 +
 pandora_console/include/ajax/module.php        |  2 +-
 pandora_console/include/functions_ui.php       | 18 +++++++++++++-----
 pandora_console/pandoradb.sql                  |  1 +
 4 files changed, 16 insertions(+), 6 deletions(-)

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 d9fe58ee64..bc08477b28 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
@@ -1284,6 +1284,7 @@ ALTER TABLE `tagente_estado` MODIFY COLUMN `datos` mediumtext NOT NULL,
 	MODIFY COLUMN `last_known_status` tinyint(4) NULL DEFAULT '0',
 	MODIFY COLUMN `last_dynamic_update` bigint(20) NOT NULL DEFAULT '0',
 	MODIFY COLUMN `last_unknown_update` bigint(20) NOT NULL DEFAULT '0';
+ALTER TABLE `tagente_estado` ADD COLUMN `last_status_change` bigint(20) NOT NULL DEFAULT '0';
 
 -- ---------------------------------------------------------------------
 -- Table `talert_actions`
diff --git a/pandora_console/include/ajax/module.php b/pandora_console/include/ajax/module.php
index 952ee9ee54..3da3b46728 100755
--- a/pandora_console/include/ajax/module.php
+++ b/pandora_console/include/ajax/module.php
@@ -1028,7 +1028,7 @@ if (check_login()) {
                 $title
             );
 
-            $data[5] = ui_print_status_image($status, htmlspecialchars($title), true);
+            $data[5] = ui_print_status_image($status, htmlspecialchars($title), true, false, false, false, $module['last_status_change']);
             if (!$show_context_help_first_time) {
                 $show_context_help_first_time = true;
 
diff --git a/pandora_console/include/functions_ui.php b/pandora_console/include/functions_ui.php
index b503abca63..12d94d3cef 100755
--- a/pandora_console/include/functions_ui.php
+++ b/pandora_console/include/functions_ui.php
@@ -2663,7 +2663,8 @@ function ui_print_status_image(
     $return=false,
     $options=false,
     $path=false,
-    $image_with_css=false
+    $image_with_css=false,
+    $module_last_status_change=''
 ) {
     if ($path === false) {
         $imagepath_array = ui_get_status_images_path();
@@ -2678,9 +2679,15 @@ function ui_print_status_image(
 
     $imagepath .= '/'.$type;
 
+    $title_extra_line = '';
+
+    if (!empty($module_last_status_change)) {
+        $title_extra_line = 'Time elapsed since last status change: '.date('h', $module_last_status_change).' '.__('hour').' '.date('i', $module_last_status_change).' '.__('min').' '.date('s', $module_last_status_change).' '.__('sec');
+    }
+
     if ($image_with_css === true) {
         $shape_status = get_shape_status_set($type);
-        return ui_print_status_sets($type, $title, $return, $shape_status);
+        return ui_print_status_sets($type, $title, $return, $shape_status, $title_extra_line);
     } else {
         if ($options === false) {
             $options = [];
@@ -2779,7 +2786,8 @@ function ui_print_status_sets(
     $status,
     $title='',
     $return=false,
-    $options=false
+    $options=false,
+    $extra_line_title=''
 ) {
     global $config;
 
@@ -2798,8 +2806,8 @@ function ui_print_status_sets(
     }
 
     if ($title != '') {
-        $options['title'] = $title;
-        $options['data-title'] = $title;
+        $options['title'] = empty($extra_line_title) ? $title : $title.'&#10'.$extra_line_title;
+        $options['data-title'] = empty($extra_line_title) ? $title : $title.'<br>'.$extra_line_title;
         $options['data-use_title_for_force_title'] = 1;
         if (isset($options['class'])) {
             $options['class'] .= ' forced_title';
diff --git a/pandora_console/pandoradb.sql b/pandora_console/pandoradb.sql
index e07fc5f6ad..635047e413 100644
--- a/pandora_console/pandoradb.sql
+++ b/pandora_console/pandoradb.sql
@@ -169,6 +169,7 @@ CREATE TABLE IF NOT EXISTS `tagente_estado` (
 	`ff_critical` int(4) unsigned default '0',
 	`last_dynamic_update` bigint(20) NOT NULL default '0',
 	`last_unknown_update` bigint(20) NOT NULL default '0',
+	`last_status_change` bigint(20) NOT NULL default '0',
 	PRIMARY KEY  (`id_agente_estado`),
 	KEY `status_index_1` (`id_agente_modulo`),
 	KEY `idx_agente` (`id_agente`),