2023-09-21 17:58:18 +02:00
|
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Overview element for tactical view.
|
|
|
|
|
*
|
|
|
|
|
* @category General
|
|
|
|
|
* @package Pandora FMS
|
|
|
|
|
* @subpackage TacticalView
|
|
|
|
|
* @version 1.0.0
|
|
|
|
|
* @license See below
|
|
|
|
|
*
|
|
|
|
|
* ______ ___ _______ _______ ________
|
|
|
|
|
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
|
|
|
|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
|
|
|
|
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
|
|
|
|
*
|
|
|
|
|
* ============================================================================
|
|
|
|
|
* Copyright (c) 2007-2023 Artica Soluciones Tecnologicas, http://www.artica.es
|
|
|
|
|
* This code is NOT free software. This code is NOT licenced under GPL2 licence
|
|
|
|
|
* You cannnot redistribute it without written permission of copyright holder.
|
|
|
|
|
* ============================================================================
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
use PandoraFMS\TacticalView\Element;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Overview, this class contain all logic for this section.
|
|
|
|
|
*/
|
|
|
|
|
class Overview extends Element
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Constructor
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2023-10-09 16:42:39 +02:00
|
|
|
|
global $config;
|
2023-09-27 13:30:56 +02:00
|
|
|
|
parent::__construct();
|
2023-10-09 16:42:39 +02:00
|
|
|
|
if (is_ajax() === true) {
|
|
|
|
|
include_once $config['homedir'].'/include/functions_servers.php';
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-21 17:58:18 +02:00
|
|
|
|
$this->title = __('General overview');
|
2023-10-02 16:44:53 +02:00
|
|
|
|
$this->ajaxMethods = [
|
|
|
|
|
'getLogSizeStatus',
|
2023-10-09 16:42:39 +02:00
|
|
|
|
'getServerStatus',
|
2023-10-02 16:44:53 +02:00
|
|
|
|
];
|
|
|
|
|
$this->interval = 300000;
|
|
|
|
|
$this->refreshConfig = [
|
2023-10-09 16:42:39 +02:00
|
|
|
|
'logSizeStatus' => [
|
2023-10-02 16:44:53 +02:00
|
|
|
|
'id' => 'status-log-size',
|
|
|
|
|
'method' => 'getLogSizeStatus',
|
|
|
|
|
],
|
2023-10-09 16:42:39 +02:00
|
|
|
|
'ServerStatus' => [
|
|
|
|
|
'id' => 'status-servers',
|
|
|
|
|
'method' => 'getServerStatus',
|
2023-10-02 16:44:53 +02:00
|
|
|
|
],
|
|
|
|
|
];
|
2023-09-21 17:58:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return the html log size status.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getLogSizeStatus():string
|
|
|
|
|
{
|
2023-10-02 16:44:53 +02:00
|
|
|
|
$size = $this->valueMonitoring('console_log_size');
|
|
|
|
|
$status = ($size[0]['datos'] < 1000) ? true : false;
|
2023-09-21 17:58:18 +02:00
|
|
|
|
|
|
|
|
|
if ($status === true) {
|
|
|
|
|
$image_status = html_print_image('images/status_check@svg.svg', true);
|
|
|
|
|
$text = html_print_div(
|
|
|
|
|
[
|
|
|
|
|
'content' => __('Everything’s OK!'),
|
|
|
|
|
'class' => 'status-text',
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$image_status = html_print_image('images/status_error@svg.svg', true);
|
|
|
|
|
$text = html_print_div(
|
|
|
|
|
[
|
2023-10-02 16:44:53 +02:00
|
|
|
|
'content' => __('Too size log size'),
|
2023-09-21 17:58:18 +02:00
|
|
|
|
'class' => 'status-text',
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$output = $image_status.$text;
|
|
|
|
|
|
|
|
|
|
return html_print_div(
|
|
|
|
|
[
|
|
|
|
|
'content' => $output,
|
2023-10-09 16:42:39 +02:00
|
|
|
|
'class' => 'margin-top-5 flex_center',
|
2023-10-02 16:44:53 +02:00
|
|
|
|
'id' => 'status-log-size',
|
2023-09-21 17:58:18 +02:00
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-09 16:42:39 +02:00
|
|
|
|
* Return the html Servers status.
|
2023-09-21 17:58:18 +02:00
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2023-10-09 16:42:39 +02:00
|
|
|
|
public function getServerStatus():string
|
2023-09-21 17:58:18 +02:00
|
|
|
|
{
|
2023-10-09 16:42:39 +02:00
|
|
|
|
$status = check_all_servers_up();
|
2023-09-21 17:58:18 +02:00
|
|
|
|
|
|
|
|
|
if ($status === true) {
|
|
|
|
|
$image_status = html_print_image('images/status_check@svg.svg', true);
|
|
|
|
|
$text = html_print_div(
|
|
|
|
|
[
|
|
|
|
|
'content' => __('Everything’s OK!'),
|
|
|
|
|
'class' => 'status-text',
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
$image_status = html_print_image('images/status_error@svg.svg', true);
|
|
|
|
|
$text = html_print_div(
|
|
|
|
|
[
|
|
|
|
|
'content' => __('Something’s wrong'),
|
|
|
|
|
'class' => 'status-text',
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$output = $image_status.$text;
|
|
|
|
|
|
|
|
|
|
return html_print_div(
|
|
|
|
|
[
|
|
|
|
|
'content' => $output,
|
|
|
|
|
'class' => 'flex_center margin-top-5',
|
2023-10-09 16:42:39 +02:00
|
|
|
|
'id' => 'status-servers',
|
2023-09-21 17:58:18 +02:00
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the html of the used licenses.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2023-09-25 13:52:28 +02:00
|
|
|
|
public function getLicenseUsageGraph():string
|
2023-09-21 17:58:18 +02:00
|
|
|
|
{
|
2023-10-09 19:04:01 +02:00
|
|
|
|
// TODO: show real data.
|
|
|
|
|
$data = [
|
|
|
|
|
'free_agents' => [
|
|
|
|
|
'label' => __('Free agents'),
|
|
|
|
|
'perc' => 40,
|
|
|
|
|
'color' => '#5C63A2',
|
2023-09-21 17:58:18 +02:00
|
|
|
|
],
|
2023-10-09 19:04:01 +02:00
|
|
|
|
'agents_used' => [
|
|
|
|
|
'label' => __('Agents used'),
|
|
|
|
|
'perc' => 60,
|
|
|
|
|
'color' => '#1C4E6B',
|
2023-09-21 17:58:18 +02:00
|
|
|
|
],
|
|
|
|
|
];
|
2023-10-09 19:04:01 +02:00
|
|
|
|
|
|
|
|
|
$bar = $this->printHorizontalBar($data);
|
2023-09-21 17:58:18 +02:00
|
|
|
|
$output = html_print_div(
|
|
|
|
|
[
|
2023-10-09 19:04:01 +02:00
|
|
|
|
'content' => $bar,
|
|
|
|
|
'style' => 'margin: 0 auto;',
|
2023-09-21 17:58:18 +02:00
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2023-10-09 19:04:01 +02:00
|
|
|
|
* Print horizontal bar divided by percentage.
|
|
|
|
|
*
|
|
|
|
|
* @param array $data Required [perc, color, label].
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
private function printHorizontalBar(array $data):string
|
|
|
|
|
{
|
|
|
|
|
$output = '<div id="horizontalBar">';
|
|
|
|
|
$output .= '<div class="labels">';
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
$output .= html_print_div(
|
|
|
|
|
[
|
|
|
|
|
'content' => '<div style="background: '.$value['color'].'"></div>'.$value['label'],
|
|
|
|
|
'class' => 'label',
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$output .= '</div>';
|
|
|
|
|
$output .= '<div class="bar">';
|
|
|
|
|
foreach ($data as $key => $value) {
|
|
|
|
|
$output .= html_print_div(
|
|
|
|
|
[
|
|
|
|
|
'content' => $value['perc'].' %',
|
|
|
|
|
'style' => 'width: '.$value['perc'].'%; background-color: '.$value['color'].';',
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$output .= '</div>';
|
|
|
|
|
$output .= '
|
|
|
|
|
<div class="marks">
|
|
|
|
|
<div class="mark"><div class="line"></div><span class="number">0 %</span></div>
|
|
|
|
|
<div class="mark"><div class="line"></div><span class="number">20 %</span></div>
|
|
|
|
|
<div class="mark"><div class="line"></div><span class="number">40 %</span></div>
|
|
|
|
|
<div class="mark"><div class="line"></div><span class="number">60 %</span></div>
|
|
|
|
|
<div class="mark"><div class="line"></div><span class="number">80 %</span></div>
|
|
|
|
|
<div class="mark"><div class="line"></div><span class="number">100 %</span></div>
|
|
|
|
|
</div>';
|
|
|
|
|
$output .= '</div>';
|
|
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the html of a graph with the cpu load.
|
2023-09-21 17:58:18 +02:00
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
2023-10-09 19:04:01 +02:00
|
|
|
|
public function getCPULoadGraph():string
|
2023-09-21 17:58:18 +02:00
|
|
|
|
{
|
|
|
|
|
$sql = 'SELECT
|
|
|
|
|
utimestamp,
|
|
|
|
|
DATE_FORMAT(FROM_UNIXTIME(utimestamp), "%Y-%m-%d %H:00:00") AS hour,
|
|
|
|
|
COUNT(*) AS xml_proccessed
|
|
|
|
|
FROM tagent_access
|
|
|
|
|
WHERE FROM_UNIXTIME(utimestamp) >= NOW() - INTERVAL 24 HOUR
|
|
|
|
|
GROUP BY hour
|
|
|
|
|
ORDER BY hour;';
|
|
|
|
|
|
|
|
|
|
$rows = db_process_sql($sql);
|
2023-10-09 19:04:01 +02:00
|
|
|
|
$data_last24h = $this->valueMonitoring('CPU Load', (time() - 86400), time());
|
2023-09-21 17:58:18 +02:00
|
|
|
|
$dates = [];
|
2023-10-09 19:04:01 +02:00
|
|
|
|
$cpu_load = [];
|
2023-09-21 17:58:18 +02:00
|
|
|
|
$total = 0;
|
2023-10-09 19:04:01 +02:00
|
|
|
|
foreach ($data_last24h as $key => $raw_data) {
|
|
|
|
|
$dates[] = date('H:m:s', $raw_data['utimestamp']);
|
|
|
|
|
$cpu_load[] = $raw_data['datos'];
|
2023-09-21 17:58:18 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$options = [
|
|
|
|
|
'labels' => $dates,
|
|
|
|
|
'legend' => [ 'display' => false ],
|
|
|
|
|
'tooltips' => [ 'display' => false ],
|
|
|
|
|
'scales' => [
|
|
|
|
|
'y' => [
|
2023-10-09 19:04:01 +02:00
|
|
|
|
'grid' => ['display' => false],
|
|
|
|
|
'ticks' => ['display' => false],
|
|
|
|
|
'display' => false,
|
2023-09-21 17:58:18 +02:00
|
|
|
|
],
|
|
|
|
|
'x' => [
|
|
|
|
|
'grid' => ['display' => false],
|
|
|
|
|
'display' => false,
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
|
2023-09-25 13:52:28 +02:00
|
|
|
|
$data = [
|
|
|
|
|
[
|
|
|
|
|
'backgroundColor' => '#009D9E',
|
|
|
|
|
'borderColor' => '#009D9E',
|
|
|
|
|
'pointBackgroundColor' => '#009D9E',
|
|
|
|
|
'pointHoverBorderColor' => '#009D9E',
|
2023-10-09 19:04:01 +02:00
|
|
|
|
'data' => $cpu_load,
|
2023-09-25 13:52:28 +02:00
|
|
|
|
],
|
|
|
|
|
];
|
2023-09-21 17:58:18 +02:00
|
|
|
|
|
|
|
|
|
$graph_area = html_print_div(
|
|
|
|
|
[
|
|
|
|
|
'content' => line_graph($data, $options),
|
|
|
|
|
'class' => 'margin-top-5 w100p h100p',
|
2023-10-09 19:04:01 +02:00
|
|
|
|
'style' => 'max-height: 50px;',
|
2023-09-21 17:58:18 +02:00
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$total = html_print_div(
|
|
|
|
|
[
|
|
|
|
|
'content' => $total,
|
|
|
|
|
'class' => 'text-xl',
|
|
|
|
|
],
|
|
|
|
|
true
|
|
|
|
|
);
|
|
|
|
|
|
2023-10-09 19:04:01 +02:00
|
|
|
|
$output = $graph_area;
|
2023-09-21 17:58:18 +02:00
|
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|