Dashboards widgets

This commit is contained in:
Pablo Aragon 2023-03-14 14:56:33 +01:00
parent ca39fa8560
commit 658f2853f7
12 changed files with 311 additions and 43 deletions

View File

@ -406,9 +406,9 @@ $filterTable->data[1][0] = html_print_submit_button(
);
// Print filter table.
echo '<form method=\'post\' action=\'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente\'>';
$form = '<form method=\'post\' action=\'index.php?sec=gagente&sec2=godmode/agentes/modificar_agente\'>';
ui_toggle(
html_print_table($filterTable, true),
$form.html_print_table($filterTable, true).'</form>',
'<span class="subsection_header_title">'.__('Filter').'</span>',
__('Filter'),
'filter',
@ -418,7 +418,6 @@ ui_toggle(
'white-box-content no_border',
'filter-datatable-main box-flat white_table_graph fixed_filter_bar'
);
echo '</form>';
// Data table.
$selected = true;

View File

@ -61,13 +61,19 @@ if ($default_action != 0) {
}
// Header.
ui_print_page_header(
ui_print_standard_header(
__('Alert details'),
'images/op_alerts.png',
false,
'',
false,
''
[],
[
[
'link' => '',
'label' => __('Alerts'),
],
]
);
// TABLE DETAILS.

View File

@ -4356,7 +4356,7 @@ function events_page_details($event, $server_id=0)
$graph_params_str = http_build_query($graph_params);
$link = "winopeng_var('".$url.'?'.$graph_params_str."','".$win_handle."', 800, 480)";
$link = 'winopeng_var("'.$url.'?'.$graph_params_str.'","'.$win_handle.'", 800, 480)';
$data[1] = html_print_button(__('View graph'), 'view_graph_button', false, $link, ['mode' => 'link'], true);
$table_details->data[] = $data;
}

View File

@ -1153,6 +1153,27 @@ function modules_get_raw_data($id_agent_module, $date_init, $date_end)
}
function module_get_min_max_tagente_datos($id_agent_module, $date_init, $date_end)
{
$table = modules_get_table_data($id_agent_module, null);
$datelimit = ($date_init - $date_end);
$search_in_history_db = db_search_in_history_db($datelimit);
$data = db_get_all_rows_sql(
'
SELECT max(datos) as max, min(datos) as min
FROM '.$table.'
WHERE id_agente_modulo = '.$id_agent_module.'
AND utimestamp >= '.$date_init.'
AND utimestamp <= '.$date_end,
$search_in_history_db
);
return $data;
}
function modules_get_agent_groups($id_agent_module)
{
$return = false;

View File

@ -3885,6 +3885,7 @@ function ui_print_datatable(array $parameters)
$("div.dataTables_paginate").hide();
$("div.dataTables_info").hide();
$("div.dataTables_length").hide();
$("div.dt-buttons").hide();
if (dt_'.$table_id.'.page.info().pages > 1) {
$(".dataTables_paginate.paging_simple_numbers").show()
@ -3895,6 +3896,7 @@ function ui_print_datatable(array $parameters)
$("div.dataTables_paginate").show();
$("div.dataTables_info").show();
$("div.dataTables_length").show();
$("div.dt-buttons").show();
if (dt_'.$table_id.'.page.info().pages == 1) {
$(".dataTables_paginate.paging_simple_numbers").hide()

View File

@ -316,6 +316,10 @@ class AvgSumMaxMinModule extends Widget
$values['unit'] = $decoder['unit'];
}
if (isset($decoder['layout']) === true) {
$values['layout'] = $decoder['layout'];
}
return $values;
}
@ -501,6 +505,18 @@ class AvgSumMaxMinModule extends Widget
],
];
// Layout.
$inputs[] = [
'label' => __('Layout').ui_print_help_tip(__('Off: vertical. On: horizontal'), true),
'arguments' => [
'wrapper' => 'div',
'name' => 'layout',
'type' => 'switch',
'value' => $values['layout'],
'return' => true,
],
];
return $inputs;
}
@ -525,6 +541,7 @@ class AvgSumMaxMinModule extends Widget
$values['sizeLabel'] = \get_parameter_switch('sizeLabel');
$values['text_color'] = \get_parameter('text_color', 0);
$values['unit'] = \get_parameter_switch('unit');
$values['layout'] = \get_parameter_switch('layout');
return $values;
}
@ -601,13 +618,13 @@ class AvgSumMaxMinModule extends Widget
break;
case 2:
$rows = modules_get_min_max_data($id_module, $to);
$rows = module_get_min_max_tagente_datos($id_module, $to, $now);
$data = $rows[0]['max'];
break;
case 3:
$rows = modules_get_min_max_data($id_module, $to);
$rows = module_get_min_max_tagente_datos($id_module, $to, $now);
$data = $rows[0]['min'];
break;
@ -621,11 +638,22 @@ class AvgSumMaxMinModule extends Widget
$sizeLabel = (isset($this->values['sizeLabel']) === true) ? $this->values['sizeLabel'] : 40;
$sizeValue = (isset($this->values['sizeValue']) === true) ? $this->values['sizeValue'] : 40;
$output .= '<div class="container-center">';
$uuid = uniqid();
$output .= '<div class="container-center" id="container-'.$uuid.'">';
$orientation = '';
if ((int) $this->values['layout'] === 1) {
$orientation = 'flex';
} else {
$orientation = 'grid';
}
// General div.
$output .= '<div class="container-icon">';
$output .= '<div class="'.$orientation.'" id="general-'.$uuid.'">';
// Div value.
$output .= '<div style="flex: 0 1 '.$sizeValue.'px; font-size:'.$sizeValue.'px;'.$text_color.'">';
$output .= '<div class="pdd_l_15px pdd_r_15px mrgn_btn_20px" style="font-size:'.$sizeValue.'px;'.$text_color.'">';
if (is_numeric($data) === true) {
$dataDatos = remove_right_zeros(
@ -651,11 +679,22 @@ class AvgSumMaxMinModule extends Widget
if (empty($label) === false) {
// Div Label.
$output .= '<div style="flex: 1 1 '.$sizeLabel.'px; font-size:'.$sizeLabel.'px;'.$text_color.'">'.$label.'</div>';
$output .= '<div class="pdd_l_15px pdd_r_15px" style="font-size:'.$sizeLabel.'px;'.$text_color.'">'.$label.'</div>';
}
$output .= '</div>';
$output .= '</div>';
$output .= '<script>
var containerWidth = document.querySelector("#container-'.$uuid.'").offsetWidth;
var generalWidth = document.querySelector("#general-'.$uuid.'").offsetWidth;
if (generalWidth >= containerWidth) {
$("#container-'.$uuid.'").css("align-items", "flex-start");
} else {
$("#container-'.$uuid.'").css("align-items", "center");
}
</script>';
return $output;
}

View File

@ -305,6 +305,10 @@ class ModuleIconWidget extends Widget
$values['imageSrc'] = $decoder['imageSrc'];
}
if (isset($decoder['layout']) === true) {
$values['layout'] = $decoder['layout'];
}
return $values;
}
@ -482,6 +486,18 @@ class ModuleIconWidget extends Widget
],
];
// Layout.
$inputs[] = [
'label' => __('Layout').ui_print_help_tip(__('Off: vertical. On: horizontal'), true),
'arguments' => [
'wrapper' => 'div',
'name' => 'layout',
'type' => 'switch',
'value' => $values['layout'],
'return' => true,
],
];
return $inputs;
}
@ -504,6 +520,7 @@ class ModuleIconWidget extends Widget
$values['sizeValue'] = \get_parameter('sizeValue', 0);
$values['sizeLabel'] = \get_parameter_switch('sizeLabel');
$values['sizeIcon'] = \get_parameter_switch('sizeIcon');
$values['layout'] = \get_parameter_switch('layout');
return $values;
}
@ -533,39 +550,84 @@ class ModuleIconWidget extends Widget
$this->values['moduleId']
);
$unit = \modules_get_unit($this->values['moduleId']);
$icon = $this->values['imageSrc'];
$label = $this->values['label'];
$sizeLabel = (($this->values['sizeLabel'] !== 0) ? $this->values['sizeLabel'] : 20);
$sizeValue = (($this->values['sizeValue'] !== 0) ? $this->values['sizeValue'] : 20);
$sizeIcon = (($this->values['sizeIcon'] !== 0) ? $this->values['sizeIcon'] : 100);
$output .= '<div class="container-center">';
$uuid = uniqid();
$output .= '<div class="container-center" id="container-'.$uuid.'">';
$orientation = '';
if ((int) $this->values['layout'] === 1) {
$orientation = 'flex aligni_center';
} else {
$orientation = 'grid';
}
// General div.
$output .= '<div class="container-icon">';
$output .= '<div class="'.$orientation.'" id="general-'.$uuid.'">';
$sql = 'SELECT min_warning,
max_warning,
min_critical,
max_critical,
str_warning,
str_critical
FROM tagente_modulo
WHERE id_agente_modulo = '.(int) $this->values['moduleId'];
$sql_data = db_get_row_sql($sql);
$last = modules_get_last_value($this->values['moduleId']);
$color_icon = '_ok';
if (($last >= $sql_data['min_warning']) && ($last < $sql_data['max_warning'])) {
$color_icon = '_warning';
}
if ($last >= $sql_data['max_warning']) {
$color_icon = '_bad';
}
// Div image.
$output .= '<div style="flex: 0 1 '.$sizeIcon.'px;">';
$style_icon = 'flex: 0 1 '.$sizeIcon.'px;';
$output .= '<div class="pdd_l_15px pdd_r_15px" style="flex: 0 1 '.$sizeIcon.'px;">';
$output .= html_print_image(
'images/console/icons/'.$icon.'.png',
'images/console/icons/'.$icon.$color_icon.'.png',
true,
['width' => $sizeIcon]
);
$output .= '</div>';
// Div value.
$output .= '<div style="flex: 0 1 10px; font-size:'.$sizeValue.'px;">';
$output .= '<div class="mrgn_btn_15px" style="flex: 0 1 10px; font-size:'.$sizeValue.'px;">';
$output .= remove_right_zeros(
number_format($data_module, $config['graph_precision'], $config['decimal_separator'], $config['thousand_separator'])
);
).$unit;
$output .= '</div>';
if (empty($label) === false) {
// Div Label.
$output .= '<div style="flex: 1; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
$output .= '<div class="pdd_l_15px pdd_r_15px" style="flex: 1; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
}
$output .= '</div>';
$output .= '</div>';
$output .= '<script>
var containerWidth = document.querySelector("#container-'.$uuid.'").offsetWidth;
var generalWidth = document.querySelector("#general-'.$uuid.'").offsetWidth;
if (generalWidth >= containerWidth) {
$("#container-'.$uuid.'").css("align-items", "flex-start");
} else {
$("#container-'.$uuid.'").css("align-items", "center");
}
</script>';
return $output;
}

View File

@ -300,6 +300,10 @@ class ModuleStatusWidget extends Widget
$values['imageSrc'] = $decoder['imageSrc'];
}
if (isset($decoder['layout']) === true) {
$values['layout'] = $decoder['layout'];
}
return $values;
}
@ -461,6 +465,18 @@ class ModuleStatusWidget extends Widget
],
];
// Layout.
$inputs[] = [
'label' => __('Layout').ui_print_help_tip(__('Off: vertical. On: horizontal'), true),
'arguments' => [
'wrapper' => 'div',
'name' => 'layout',
'type' => 'switch',
'value' => $values['layout'],
'return' => true,
],
];
return $inputs;
}
@ -483,6 +499,7 @@ class ModuleStatusWidget extends Widget
$values['sizeValue'] = \get_parameter('sizeValue', 0);
$values['sizeLabel'] = \get_parameter_switch('sizeLabel');
$values['sizeIcon'] = \get_parameter_switch('sizeIcon');
$values['layout'] = \get_parameter_switch('layout');
return $values;
}
@ -538,12 +555,22 @@ class ModuleStatusWidget extends Widget
break;
}
$output .= '<div class="container-center">';
$uuid = uniqid();
$output .= '<div class="container-center" id="container-'.$uuid.'">';
$orientation = '';
if ((int) $this->values['layout'] === 1) {
$orientation = 'flex aligni_center';
} else {
$orientation = 'grid';
}
// General div.
$output .= '<div class="container-icon">';
$output .= '<div class="'.$orientation.'" id="general-'.$uuid.'">';
// Div image.
$output .= '<div style="flex: 0 1 '.$sizeIcon.'px;">';
$output .= '<div class="pdd_l_15px pdd_r_15px" style="flex: 0 1 '.$sizeIcon.'px;">';
$output .= html_print_image(
'images/console/icons/'.$icon,
true,
@ -553,11 +580,22 @@ class ModuleStatusWidget extends Widget
if (empty($label) === false) {
// Div Label.
$output .= '<div style="flex: 1 1 '.$sizeLabel.'px; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
$output .= '<div class="pdd_l_15px pdd_r_15px" style="flex: 1 1 '.$sizeLabel.'px; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
}
$output .= '</div>';
$output .= '</div>';
$output .= '<script>
var containerWidth = document.querySelector("#container-'.$uuid.'").offsetWidth;
var generalWidth = document.querySelector("#general-'.$uuid.'").offsetWidth;
if (generalWidth >= containerWidth) {
$("#container-'.$uuid.'").css("align-items", "flex-start");
} else {
$("#container-'.$uuid.'").css("align-items", "center");
}
</script>';
return $output;
}

View File

@ -284,6 +284,10 @@ class ModuleValueWidget extends Widget
$values['sizeLabel'] = $decoder['sizeLabel'];
}
if (isset($decoder['layout']) === true) {
$values['layout'] = $decoder['layout'];
}
return $values;
}
@ -385,6 +389,18 @@ class ModuleValueWidget extends Widget
],
];
// Layout.
$inputs[] = [
'label' => __('Layout').ui_print_help_tip(__('Off: vertical. On: horizontal'), true),
'arguments' => [
'wrapper' => 'div',
'name' => 'layout',
'type' => 'switch',
'value' => $values['layout'],
'return' => true,
],
];
return $inputs;
}
@ -405,6 +421,7 @@ class ModuleValueWidget extends Widget
$values['moduleId'] = \get_parameter('moduleId', 0);
$values['sizeValue'] = \get_parameter('sizeValue', 0);
$values['sizeLabel'] = \get_parameter_switch('sizeLabel');
$values['layout'] = \get_parameter_switch('layout');
return $values;
}
@ -422,6 +439,7 @@ class ModuleValueWidget extends Widget
$output = '';
$id_module = $this->values['moduleId'];
$unit = modules_get_unit($this->values['moduleId']);
$data_module = \modules_get_last_value($id_module);
@ -429,11 +447,41 @@ class ModuleValueWidget extends Widget
$sizeLabel = (isset($this->values['sizeLabel']) === true) ? $this->values['sizeLabel'] : 40;
$sizeValue = (isset($this->values['sizeValue']) === true) ? $this->values['sizeValue'] : 40;
$output .= '<div class="container-center">';
$sql = 'SELECT min_warning,
max_warning,
min_critical,
max_critical,
str_warning,
str_critical
FROM tagente_modulo
WHERE id_agente_modulo = '.(int) $this->values['moduleId'];
$sql_data = db_get_row_sql($sql);
$last = modules_get_last_value($this->values['moduleId']);
if (($last >= $sql_data['min_warning']) && ($last < $sql_data['max_warning'])) {
$color = COL_WARNING;
}
if ($last >= $sql_data['max_warning']) {
$color = COL_CRITICAL;
}
$uuid = uniqid();
$output .= '<div class="container-center" id="container-'.$uuid.'">';
$orientation = '';
if ((int) $this->values['layout'] === 1) {
$orientation = 'flex';
} else {
$orientation = 'grid';
}
// General div.
$output .= '<div class="container-icon">';
$output .= '<div class="'.$orientation.'" id="general-'.$uuid.'">';
// Div value.
$output .= '<div style="flex: 0 1 '.$sizeValue.'px; font-size:'.$sizeValue.'px;">';
$output .= '<div class="pdd_l_15px pdd_r_15px mrgn_btn_20px" style="flex: 0 1 '.$sizeValue.'px; font-size:'.$sizeValue.'px; color: '.$color.'">';
if (is_numeric($data_module) === true) {
$dataDatos = remove_right_zeros(
@ -443,7 +491,7 @@ class ModuleValueWidget extends Widget
$config['decimal_separator'],
$config['thousand_separator']
)
);
).$unit;
} else {
$dataDatos = trim($data_module);
}
@ -454,11 +502,22 @@ class ModuleValueWidget extends Widget
if (empty($label) === false) {
// Div Label.
$output .= '<div style="flex: 1 1 '.$sizeLabel.'px; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
$output .= '<div class="pdd_l_15px pdd_r_15px" style="flex: 1 1 '.$sizeLabel.'px; font-size:'.$sizeLabel.'px;">'.$label.'</div>';
}
$output .= '</div>';
$output .= '</div>';
$output .= '<script>
var containerWidth = document.querySelector("#container-'.$uuid.'").offsetWidth;
var generalWidth = document.querySelector("#general-'.$uuid.'").offsetWidth;
if (generalWidth >= containerWidth) {
$("#container-'.$uuid.'").css("align-items", "flex-start");
} else {
$("#container-'.$uuid.'").css("align-items", "center");
}
</script>';
return $output;
}

View File

@ -282,10 +282,10 @@ class OsQuickReportWidget extends Widget
$table->head = [];
$table->head[0] = __('OS');
$table->head[1] = __('OS name');
$table->head[2] = ucfirst(__('total agents'));
$table->head[3] = ucfirst(__('normal agents'));
$table->head[4] = ucfirst(__('critical agents'));
$table->head[5] = ucfirst(__('unknown agents'));
$table->head[2] = ucfirst(__('total'));
$table->head[3] = ucfirst(__('normal'));
$table->head[4] = ucfirst(__('critical'));
$table->head[5] = ucfirst(__('unknown'));
$table->headstyle = [];
$table->headstyle[0] = 'text-align:center;background-color: '.$values['background'];
@ -296,12 +296,12 @@ class OsQuickReportWidget extends Widget
$table->headstyle[5] = 'text-align:center;background-color: '.$values['background'];
$table->style = [];
$table->style[0] = 'background-color: '.$values['background'];
$table->style[1] = 'background-color: '.$values['background'];
$table->style[2] = 'font-size: 22px;background-color: '.$values['background'];
$table->style[3] = 'font-size: 22px;background-color: '.$values['background'];
$table->style[4] = 'font-size: 22px;background-color: '.$values['background'];
$table->style[5] = 'font-size: 22px;background-color: '.$values['background'];
$table->style[0] = 'background-color: '.$values['background'].';';
$table->style[1] = 'background-color: '.$values['background'].';';
$table->style[2] = 'background-color: '.$values['background'].'; font-size: 1.5em; font-weight: bolder;';
$table->style[3] = 'background-color: '.$values['background'].'; font-size: 1.5em; font-weight: bolder;';
$table->style[4] = 'background-color: '.$values['background'].'; font-size: 1.5em; font-weight: bolder;';
$table->style[5] = 'background-color: '.$values['background'].'; font-size: 1.5em; font-weight: bolder;';
foreach ($result as $id => $os) {
$data = [];

View File

@ -289,6 +289,10 @@ class SLAPercentWidget extends Widget
$values['period'] = $decoder['period'];
}
if (isset($decoder['layout']) === true) {
$values['layout'] = $decoder['layout'];
}
return $values;
}
@ -404,6 +408,18 @@ class SLAPercentWidget extends Widget
],
];
// Layout.
$inputs[] = [
'label' => __('Layout').ui_print_help_tip(__('Off: vertical. On: horizontal'), true),
'arguments' => [
'wrapper' => 'div',
'name' => 'layout',
'type' => 'switch',
'value' => $values['layout'],
'return' => true,
],
];
return $inputs;
}
@ -425,6 +441,7 @@ class SLAPercentWidget extends Widget
$values['period'] = \get_parameter('period', 0);
$values['sizeValue'] = \get_parameter('sizeValue', '');
$values['sizeLabel'] = \get_parameter('sizeLabel', '');
$values['layout'] = \get_parameter_switch('layout');
return $values;
}
@ -494,21 +511,42 @@ class SLAPercentWidget extends Widget
$sizeLabel = (isset($this->values['sizeLabel']) === true) ? $this->values['sizeLabel'] : 30;
$sizeValue = (isset($this->values['sizeValue']) === true) ? $this->values['sizeValue'] : 30;
$output .= '<div class="container-center">';
$uuid = uniqid();
$output .= '<div class="container-center" id="container-'.$uuid.'">';
$orientation = '';
if ((int) $this->values['layout'] === 1) {
$orientation = 'flex';
} else {
$orientation = 'grid';
}
// General div.
$output .= '<div class="container-icon">';
$output .= '<div class="'.$orientation.'" id="general-'.$uuid.'">';
// Div value.
$output .= '<div style="flex: 0 1 '.$sizeValue.'px; font-size:'.$sizeValue.'px;">';
$output .= '<div class="pdd_l_15px pdd_r_15px mrgn_btn_20px" style="flex: 0 1 '.$sizeValue.'px; font-size:'.$sizeValue.'px;">';
$output .= $sla_array['sla_fixed'].'%';
$output .= '</div>';
if (empty($label) === false) {
// Div Label.
$output .= '<div style="flex: 1 1; font-size:'.$sizeLabel.'px; text-align: left;">'.$label.'</div>';
$output .= '<div class="pdd_l_15px pdd_r_15px" style="flex: 1 1; font-size:'.$sizeLabel.'px; text-align: left;">'.$label.'</div>';
}
$output .= '</div>';
$output .= '</div>';
$output .= '<script>
var containerWidth = document.querySelector("#container-'.$uuid.'").offsetWidth;
var generalWidth = document.querySelector("#general-'.$uuid.'").offsetWidth;
if (generalWidth >= containerWidth) {
$("#container-'.$uuid.'").css("align-items", "flex-start");
} else {
$("#container-'.$uuid.'").css("align-items", "center");
}
</script>';
return $output;
}

View File

@ -11664,3 +11664,7 @@ div.ui-dialog-buttonset > button.ui-button.ui-corner-all.ui-widget:active {
background-color: #0d312f;
border-color: #0d312f;
}
div#menu_full > div#menu_tabs > ul.tabs_ul {
margin-bottom: 0px;
}