9555-Modules hitorical & styles

This commit is contained in:
Pablo Aragon 2023-04-18 17:05:08 +02:00
parent 49d82698b1
commit 2362fe8146
8 changed files with 458 additions and 29 deletions

View File

@ -56,10 +56,20 @@ body {
font-family: "Lato" !important;
}
a {
text-decoration: underline !important;
text-decoration-color: var(--muted-color) !important;
color: var(--primary-color);
}
.small {
font-size: 10px !important;
}
.font-10pt {
font-size: 10pt !important;
}
.center {
text-align: center;
}
@ -488,6 +498,7 @@ table.event_details td.cell_event_name {
@media screen and (max-width: 35em) {
/* Hide the title of event name */
#last_agent_events tbody tr.events td.cell_0 b.ui-table-cell-label,
#list_events tbody tr.events td.cell_0 b.ui-table-cell-label {
display: none;
}
@ -520,26 +531,36 @@ table.event_details td.cell_event_name {
font-weight: bold;
}
.agents_tiny_stats span {
background-color: transparent !important;
}
.agents_tiny_stats .red,
.color-red {
color: #c00 !important;
}
.agents_tiny_stats .green,
.color-green {
color: #5a8629 !important;
}
.agents_tiny_stats .orange,
.color-orange {
color: #fd7304 !important;
}
.agents_tiny_stats .yellow,
.color-yellow {
color: #f3c500 !important;
}
.agents_tiny_stats .grey,
.color-grey {
color: #808080 !important;
}
.agents_tiny_stats .blue,
.color-blue {
color: #4a83f3 !important;
}
@ -903,6 +924,7 @@ table.event_details td.cell_event_name {
font-size: 12px !important;
}
table#list_module_data tr,
table#list_servers tr,
table[id^="service-table-"] tr {
display: flex;
@ -911,6 +933,7 @@ table.event_details td.cell_event_name {
align-items: center;
}
table#list_module_data b.ui-table-cell-label,
table#list_servers b.ui-table-cell-label,
table[id^="service-table-"] b.ui-table-cell-label {
display: none;
@ -2114,33 +2137,65 @@ table#last-activity > tbody > tr > td > b {
}
/* Events table */
table#last_agent_events > tbody > tr.events > td.cell_0,
table#list_events > tbody > tr.events > td.cell_0 {
border-top-left-radius: 8px !important;
border-top-right-radius: 8px !important;
}
table#last_agent_events > tbody > tr.events > td.vertical_middle,
table#list_events > tbody > tr.events > td.vertical_middle {
border-bottom-left-radius: 8px !important;
border-bottom-right-radius: 8px !important;
color: #4a4a4a;
}
table#last_agent_events > tbody > tr.events,
table#list_events > tbody > tr.events {
background-color: var(--secondary-color) !important;
}
table#last_agent_events > tbody > tr.events.datos_green > td,
table#list_events > tbody > tr.events.datos_green > td {
background-color: #81b92e40;
}
table#last_agent_events > tbody > tr.events.datos_red > td,
table#list_events > tbody > tr.events.datos_red > td {
background-color: #ed474a40;
}
table#last_agent_events > tbody > tr.events.datos_yellow > td,
table#list_events > tbody > tr.events.datos_yellow > td {
background-color: #fcab1040;
}
table#last_agent_events > tbody > tr.events.datos_blue > td,
table#list_events > tbody > tr.events.datos_blue > td {
background-color: #25a8ff40;
}
table#last_agent_events > tbody > tr.events.datos_grey > td,
table#list_events > tbody > tr.events.datos_grey > td {
background-color: #adadad40;
}
table#list_module_data > thead > tr > th {
display: initial;
}
h4[id^="service-"].ui-collapsible-heading
> a
> span.ui-icon.ui-collapsible-icon-right {
margin-top: 2px !important;
}
h4[id^="service-"].ui-collapsible-heading
> a.ui-collapsible-heading-toggle.ui-button.ui-button-a {
padding-left: 10px !important;
}
table[id^="service-table-"] {
padding: 0px !important;
}
table[id^="service-table-"] > tbody > tr {
padding: 0px 5px !important;
height: 48px !important;
}

View File

@ -45,6 +45,7 @@ require_once 'operation/visualmaps.php';
require_once 'operation/visualmap.php';
require_once 'operation/server_status.php';
require_once 'operation/services.php';
require_once 'operation/module_data.php';
$enterpriseHook = enterprise_include('mobile/include/enterprise.class.php');
$enterpriseHook = enterprise_include('mobile/operation/home.php');
@ -189,6 +190,11 @@ switch ($action) {
$services->ajax($parameter2);
break;
case 'module_data':
$module_data = new ModuleData();
$module_data->ajax($parameter2);
break;
default:
if (class_exists('Enterprise')) {
$enterprise->enterpriseAjax($parameter1, $parameter2);
@ -429,6 +435,11 @@ switch ($action) {
$services = new Services();
$services->show();
break;
case 'module_data':
$module_data = new ModuleData();
$module_data->show();
break;
}
break;
}

View File

@ -27,6 +27,8 @@
* ============================================================================
*/
use PandoraFMS\Event;
// Begin.
require_once '../include/functions_users.php';
@ -130,9 +132,13 @@ class Agent
{
$ui = Ui::getInstance();
$system = System::getInstance();
$eventObj = new Events;
$ui->createPage();
$options = $eventObj->getEventDialogOptions();
$ui->addDialog($options);
if ($this->id != 0) {
$agent_alias = (string) $this->agent['alias'];

View File

@ -1201,7 +1201,7 @@ class Events
data: postvars,
success:
function (data) {
if (data.correct) {
if (data.correct) {
event = data.event;
//Fill the dialog
$("#detail_event_dialog .cell_event_name")

View File

@ -0,0 +1,354 @@
<?php
// phpcs:disable Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
/**
* Modules list view for mobile
*
* @category Mobile
* @package Pandora FMS
* @subpackage Community
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2022 Artica Soluciones Tecnologicas
* Please see http://pandorafms.org for full contribution list
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation for version 2.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* ============================================================================
*/
// Begin.
class ModuleData
{
private $correct_acl = false;
private $acl = 'AR';
private $default = true;
private $default_filters = [];
private $moduleId = null;
private $agentAlias = null;
private $moduleName = null;
private $columns = null;
function __construct()
{
$system = System::getInstance();
if ($system->checkACL($this->acl)) {
$this->correct_acl = true;
} else {
$this->correct_acl = false;
}
$this->moduleId = $system->getRequest('module_id');
}
public function ajax($parameter2=false)
{
$system = System::getInstance();
if (!$this->correct_acl) {
return;
} else {
switch ($parameter2) {
case 'get_module_data':
$this->getFilters();
$page = $system->getRequest('page', 0);
$module_id = $system->getRequest('module_id');
$servers = [];
$end = 1;
$listData = $this->getListData($page, true);
if (!empty($listData['data'])) {
$end = 0;
$servers = $listData['data'];
}
echo json_encode(['end' => $end, 'servers' => $servers]);
break;
}
}
}
public function show()
{
if (!$this->correct_acl) {
$this->show_fail_acl();
} else {
$this->show_module_data();
}
}
private function show_fail_acl()
{
$error['type'] = 'onStart';
$error['title_text'] = __('You don\'t have access to this page');
$error['content_text'] = System::getDefaultACLFailText();
if (class_exists('HomeEnterprise')) {
$home = new HomeEnterprise();
} else {
$home = new Home();
}
$home->show($error);
}
private function show_module_data()
{
$ui = Ui::getInstance();
$ui->createPage();
$ui->createDefaultHeader(
__('Module data'),
$ui->createHeaderButton(
[
'icon' => 'ui-icon-back',
'pos' => 'left',
'text' => __('Back'),
'href' => 'index.php?page=modules',
'class' => 'header-button-left',
]
)
);
$ui->showFooter(false);
$ui->beginContent();
$this->listDataHtml();
$ui->endContent();
$ui->showPage();
}
private function getListData($page=0, $ajax=false)
{
global $config;
$system = System::getInstance();
$total = 0;
$data = [];
$module_data = modules_get_agentmodule_data(
$this->moduleId,
604800,
0,
false,
false,
'DESC'
);
$total = (int) count($module_data);
foreach ($module_data as $module) {
$row[__('Data')] = '<span class="data">'.$module['data'].'</span>';
$row[__('Timestamp')] = '<span class="data">'.human_time_comparation($module['utimestamp'], 'tiny').'</span>';
array_push($data, $row);
}
return [
'data' => $data,
'total' => $total,
];
}
public function listDataHtml($page=0, $return=false)
{
$system = System::getInstance();
$ui = Ui::getInstance();
$listData = $this->getListData($page);
if ($listData['total'] == 0) {
$html = '<p class="empty_advice">'.__('No data').'</p>';
if (!$return) {
$ui->contentAddHtml($html);
} else {
return $html;
}
} else {
if (!$return) {
$table = new Table();
$table->id = 'list_module_data';
$table->importFromHash($listData['data']);
$ui->contentAddHtml('<div class="white-card">');
$agent_id = agents_get_agent_id_by_module_id($this->moduleId);
$agent_name = agents_get_name($agent_id);
$module_name = modules_get_agentmodule_name($this->moduleId);
$ui->contentAddHtml('<h1 class="center font-10pt">'.$module_name.'</h1>');
$ui->contentAddHtml('<p class="center"><span class="muted small">'.$agent_name.'</span></p>');
$ui->contentAddHtml($table->getHTML());
$ui->contentAddHtml('</div>');
} else {
$table = new Table();
$table->id = 'list_module_data';
$table->importFromHash($listData['data']);
$html = $table->getHTML();
return $html;
}
// if ($system->getPageSize() < $listData['total']) {
// $ui->contentAddHtml(
// '<div id="loading_rows">'.html_print_image('images/spinner.gif', true, false, false, false, false, true).' '.__('Loading...').'</div>'
// );
// $this->addJavascriptAddBottom();
// }
}
$ui->contentAddLinkListener('list_servers');
}
private function addJavascriptAddBottom()
{
$ui = Ui::getInstance();
$ui->contentAddHtml(
"<script type=\"text/javascript\">
var load_more_rows = 1;
var page = 1;
function custom_scroll() {
if (load_more_rows) {
if ($(this).scrollTop() + $(this).height()
>= ($(document).height() - 100)) {
load_more_rows = 0;
postvars = {};
postvars[\"action\"] = \"ajax\";
postvars[\"parameter1\"] = \"module_data\";
postvars[\"parameter2\"] = \"get_module_data\";
postvars[\"page\"] = page;
page++;
$.post(
\"index.php\",
postvars,
function (data) {
if (data.end) {
$(\"#loading_rows\").hide();
}
else {
$.each(data.servers, function(key, server) {;
$(\"table#list_servers tbody\").append(\"<tr>\" +
\"<td class='cell_0'><b class='ui-table-cell-label'>".__('Status')."</b>\" + server['Status'] + \"</td>\" +
\"<td class='cell_1'><b class='ui-table-cell-label'>".__('Image')."</b>\" + server['Image'] + \"</td>\" +
\"<td class='cell_2'><b class='ui-table-cell-label'>".__('Name')."</b>\" + server['Name'] + \"</td>\" +
\"</tr>\");
});
load_more_rows = 1;
refresh_link_listener_list_servers()
}
},
\"json\");
}
}
}
$(document).ready(function() {
$(window).bind(\"scroll\", function () {
custom_scroll();
});
$(window).on(\"touchmove\", function(event) {
custom_scroll();
});
});
</script>"
);
}
private function filterServersGetString()
{
if ($this->default) {
return __('(Default)');
} else {
$filters_to_serialize = [];
if (!$this->default_filters['group']) {
$filters_to_serialize[] = sprintf(
__('Group: %s'),
groups_get_name($this->group, true)
);
}
if (!$this->default_filters['module_group']) {
$module_group = db_get_value(
'name',
'tmodule_group',
'id_mg',
$this->module_group
);
$module_group = io_safe_output($module_group);
$filters_to_serialize[] = sprintf(
__('Module group: %s'),
$module_group
);
}
if (!$this->default_filters['status']) {
$filters_to_serialize[] = sprintf(
__('Status: %s'),
$this->list_status[$this->status]
);
}
if (!$this->default_filters['free_search']) {
$filters_to_serialize[] = sprintf(
__('Free Search: %s'),
$this->free_search
);
}
if (!$this->default_filters['tag']) {
$tag_name = tags_get_name($this->tag);
$filters_to_serialize[] = sprintf(
__('Tag: %s'),
$tag_name
);
}
$string = '('.implode(' - ', $filters_to_serialize).')';
return $string;
}
}
}

View File

@ -853,7 +853,7 @@ class Modules
'.__('Graph').'
</a>
<a id="historical-option" href="#" class="ui-btn ui-corner-all ui-btn-inline ui-btn-b" data-rel="back" data-transition="flow">
<a id="historical-option" href="#" class="ui-btn ui-corner-all ui-btn-inline ui-btn-b" data-transition="flow">
'.__('Historical data').'
</a>
</div>
@ -927,11 +927,14 @@ class Modules
var historical = '';
if (serverId === 'node') {
graph = 'index.php?page=module_graph&id='+moduleId+'&id_agent='+agentId;
historical = 'index.php?page=module_data&module_id='+moduleId;
} else {
graph = 'index.php?page=module_graph&id='+moduleId+'&id_agent='+agentId+'&server_id='+serverId;
historical = 'index.php?page=module_data&module_id='+moduleId;
}
$('#graph-option').attr('href', graph);
$('#historical-option').attr('href', historical);
$('#module-dialog-button').click();
}

View File

@ -354,12 +354,6 @@ class ServerStatus
}
}
echo "<script>
window.addEventListener('DOMContentLoaded', (event) => {
document.querySelector('table#list_servers span.data a').href = '#';
});
</script>";
return [
'servers' => $servers,
'total' => $total,
@ -386,7 +380,20 @@ class ServerStatus
$table->id = 'list_servers';
$table->importFromHash($listServers['servers']);
$ui->contentAddHtml('<div class="white-card">');
$ui->contentAddHtml($table->getHTML());
if ($this->all_servers === true) {
if ($system->getPageSize() < $listServers['total']) {
$ui->contentAddHtml(
'<br><div id="loading_rows">'.html_print_image('images/spinner.gif', true, false, false, false, false, true).' '.__('Loading...').'</div>'
);
$this->addJavascriptAddBottom();
}
}
$ui->contentAddHtml('</div>');
} else {
$table = new Table();
$table->id = 'list_servers_status';
@ -397,16 +404,6 @@ class ServerStatus
return $html;
}
if ($this->all_servers === true) {
if ($system->getPageSize() < $listServers['total']) {
$ui->contentAddHtml(
'<div id="loading_rows">'.html_print_image('images/spinner.gif', true, false, false, false, false, true).' '.__('Loading...').'</div>'
);
$this->addJavascriptAddBottom();
}
}
}
$ui->contentAddLinkListener('list_servers');
@ -454,12 +451,8 @@ class ServerStatus
load_more_rows = 1;
refresh_link_listener_list_servers()
}
},
\"json\");
}
}
}
@ -473,6 +466,10 @@ class ServerStatus
$(window).on(\"touchmove\", function(event) {
custom_scroll();
});
window.addEventListener('DOMContentLoaded', (event) => {
document.querySelector('table#list_servers span.data a').href = '#';
});
});
</script>"
);

View File

@ -171,7 +171,8 @@ class Services
'
);
$ui->contentAddHtml('<div class="border-collapsible" data-collapsed-icon="group_'.$count.'" data-expanded-icon="group_'.$count.'" data-iconpos="right" data-role="collapsible" data-collapsed="true" data-content-theme="d">');
$ui->contentAddHtml('<h4 id="service-'.$service['id'].'" onclick="loadTable(\''.$service['id'].'\')">'.$group_icon.'&nbsp;'.$service['description'].'</h4>');
$arrow = '<span class="ui-icon ui-icon-arrow-d"></span>';
$ui->contentAddHtml('<h4 id="service-'.$service['id'].'" onclick="loadTable(\''.$service['id'].'\')">'.$arrow.$group_icon.'&nbsp;'.$service['description'].'</h4>');
$spinner = '
<div class="spinner mt15px" id="spinner-'.$service['id'].'">
@ -236,7 +237,6 @@ class Services
}
}
$name .= '<strong>';
if (is_metaconsole()
&& ((int) $item->id_server_meta()) !== 0
) {
@ -244,7 +244,6 @@ class Services
}
$name .= $item->agent()->alias();
$name .= '</strong>';
$name .= '</a>';
if (((bool) $item->agent()->disabled()) === true) {
@ -303,7 +302,6 @@ class Services
}
}
$name .= '<strong>';
if (is_metaconsole()
&& ((int) $item->id_server_meta()) !== 0
) {
@ -311,7 +309,6 @@ class Services
}
$name .= $item->service()->name();
$name .= '</strong>';
$name .= '</a>';
if (((bool) $item->service()->disabled()) === true) {
@ -340,7 +337,6 @@ class Services
'index.php?sec=eventos&sec2=operation/events/events&event_view_hr=8&severity=4&id_agent='.$item->module()->id_agente().'&id_agent_module='.$item->id_agente_modulo()
);
$name = '<a target="_blank" href="'.$url.'">';
$name .= '<strong>';
if (((bool) $item->module()->disabled()) === true) {
$disabled_element = true;
@ -367,7 +363,6 @@ class Services
).'</em>';
}
$name .= '</strong>';
$name .= '</a>';
}
break;
@ -527,6 +522,14 @@ class Services
$('h4#service-'+id+' + div.ui-collapsible-content').html(data);
},
\"html\");
var arrow = document.querySelector('h4#service-'+id+' > a > span.ui-icon.ui-icon-arrow-d');
if (arrow.style.transform == 'rotate(180deg)') {
arrow.style.transform = '';
} else {
arrow.style.transform = 'rotate(180deg)';
}
}
</script>"
);