2023-09-27 13:30:56 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Alerts 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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Alerts, this class contain all logic for this section.
|
|
|
|
*/
|
|
|
|
class Alerts extends Element
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->title = __('Alerts');
|
|
|
|
$this->ajaxMethods = ['getUsers'];
|
2023-10-02 16:44:53 +02:00
|
|
|
$this->ajaxMethods = [
|
|
|
|
'getUsers',
|
|
|
|
'getCurrentlyTriggered',
|
|
|
|
'getActiveCorrelation',
|
|
|
|
];
|
|
|
|
$this->interval = 300000;
|
|
|
|
$this->refreshConfig = [
|
|
|
|
'triggered' => [
|
|
|
|
'id' => 'currently-triggered',
|
|
|
|
'method' => 'getCurrentlyTriggered',
|
|
|
|
],
|
|
|
|
'active-correlation' => [
|
|
|
|
'id' => 'active-correlation',
|
|
|
|
'method' => 'getActiveCorrelation',
|
|
|
|
],
|
|
|
|
];
|
2023-09-27 13:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the html of currently triggered.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getCurrentlyTriggered():string
|
|
|
|
{
|
2023-10-02 16:44:53 +02:00
|
|
|
$value = $this->valueMonitoring('triggered_alerts');
|
|
|
|
$total = round($value[0]['datos']);
|
2023-09-27 13:30:56 +02:00
|
|
|
return html_print_div(
|
|
|
|
[
|
2023-10-02 16:44:53 +02:00
|
|
|
'content' => $total,
|
2023-09-27 13:30:56 +02:00
|
|
|
'class' => 'text-l',
|
2023-10-02 16:44:53 +02:00
|
|
|
'id' => 'currently-triggered',
|
2023-09-27 13:30:56 +02:00
|
|
|
'style' => 'margin: 0px 10px 10px 10px;',
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the html of active correlation.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getActiveCorrelation():string
|
|
|
|
{
|
2023-10-02 16:44:53 +02:00
|
|
|
$value = $this->valueMonitoring('triggered_correlative_alerts');
|
|
|
|
$total = round($value[0]['datos']);
|
2023-09-27 13:30:56 +02:00
|
|
|
return html_print_div(
|
|
|
|
[
|
2023-10-02 16:44:53 +02:00
|
|
|
'content' => $total,
|
2023-09-27 13:30:56 +02:00
|
|
|
'class' => 'text-l',
|
2023-10-02 16:44:53 +02:00
|
|
|
'id' => 'active-correlation',
|
2023-09-27 13:30:56 +02:00
|
|
|
'style' => 'margin: 0px 10px 10px 10px;',
|
|
|
|
],
|
|
|
|
true
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a datatable with de users lists.
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDataTableUsers():string
|
|
|
|
{
|
|
|
|
$columns = [
|
|
|
|
'id_user',
|
|
|
|
'is_admin',
|
|
|
|
'last_connect',
|
|
|
|
];
|
|
|
|
|
|
|
|
$columnNames = [
|
|
|
|
__('User'),
|
|
|
|
__('Role'),
|
|
|
|
__('Last seen'),
|
|
|
|
];
|
|
|
|
|
|
|
|
return ui_print_datatable(
|
|
|
|
[
|
|
|
|
'id' => 'list_users',
|
|
|
|
'class' => 'info_table',
|
|
|
|
'style' => 'width: 90%',
|
|
|
|
'dom_elements' => 'tfp',
|
|
|
|
'filter_main_class' => 'box-flat white_table_graph fixed_filter_bar',
|
|
|
|
'columns' => $columns,
|
|
|
|
'column_names' => $columnNames,
|
|
|
|
'ajax_url' => $this->ajaxController,
|
|
|
|
'ajax_data' => [
|
|
|
|
'method' => 'getUsers',
|
|
|
|
'class' => static::class,
|
|
|
|
],
|
|
|
|
'order' => [
|
|
|
|
'field' => 'title',
|
|
|
|
'direction' => 'asc',
|
|
|
|
],
|
2023-10-03 15:32:53 +02:00
|
|
|
'default_pagination' => 10,
|
2023-09-27 13:30:56 +02:00
|
|
|
'search_button_class' => 'sub filter float-right',
|
|
|
|
'return' => true,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return all users for ajax.
|
|
|
|
*
|
2023-10-02 16:44:53 +02:00
|
|
|
* @return string
|
2023-09-27 13:30:56 +02:00
|
|
|
*/
|
2023-10-02 16:44:53 +02:00
|
|
|
public function getUsers():string
|
2023-09-27 13:30:56 +02:00
|
|
|
{
|
|
|
|
global $config;
|
|
|
|
|
|
|
|
$start = get_parameter('start', 0);
|
|
|
|
$length = get_parameter('length', $config['block_size']);
|
|
|
|
$orderDatatable = get_datatable_order(true);
|
|
|
|
$pagination = '';
|
|
|
|
$order = '';
|
|
|
|
|
|
|
|
try {
|
|
|
|
ob_start();
|
|
|
|
if (isset($orderDatatable)) {
|
|
|
|
$order = sprintf(
|
|
|
|
' ORDER BY %s %s',
|
|
|
|
$orderDatatable['field'],
|
|
|
|
$orderDatatable['direction']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($length) && $length > 0
|
|
|
|
&& isset($start) && $start >= 0
|
|
|
|
) {
|
|
|
|
$pagination = sprintf(
|
|
|
|
' LIMIT %d OFFSET %d ',
|
|
|
|
$length,
|
|
|
|
$start
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql = sprintf(
|
|
|
|
'SELECT id_user, is_admin ,last_connect
|
|
|
|
FROM tusuario u %s %s',
|
|
|
|
$order,
|
|
|
|
$pagination
|
|
|
|
);
|
|
|
|
|
|
|
|
$rows = db_process_sql($sql);
|
|
|
|
|
|
|
|
foreach ($rows as $key => $row) {
|
|
|
|
if ((bool) $row['is_admin'] === true) {
|
|
|
|
$rows[$key]['is_admin'] = '<span class="admin">'.__('Admin').'</span>';
|
|
|
|
} else {
|
|
|
|
$rows[$key]['is_admin'] = '<span class="user">'.__('User').'</span>';
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($row['last_connect'] > 0) {
|
|
|
|
$rows[$key]['last_connect'] = ui_print_timestamp($row['last_connect'], true, ['prominent' => 'compact']);
|
|
|
|
} else {
|
|
|
|
$rows[$key]['last_connect'] = __('Unknown');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql_count = sprintf(
|
|
|
|
'SELECT count(*) as total FROM tusuario %s',
|
|
|
|
$order,
|
|
|
|
);
|
|
|
|
|
|
|
|
$total = db_process_sql($sql_count);
|
|
|
|
|
2023-10-02 16:44:53 +02:00
|
|
|
// Capture output.
|
|
|
|
$response = ob_get_clean();
|
|
|
|
|
|
|
|
return json_encode(
|
2023-09-27 13:30:56 +02:00
|
|
|
[
|
|
|
|
'data' => $rows,
|
|
|
|
'recordsTotal' => $total[0]['total'],
|
|
|
|
'recordsFiltered' => $total[0]['total'],
|
|
|
|
]
|
|
|
|
);
|
|
|
|
} catch (Exception $e) {
|
2023-10-02 16:44:53 +02:00
|
|
|
return json_encode(['error' => $e->getMessage()]);
|
2023-09-27 13:30:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
json_decode($response);
|
|
|
|
if (json_last_error() === JSON_ERROR_NONE) {
|
2023-10-02 16:44:53 +02:00
|
|
|
return $response;
|
2023-09-27 13:30:56 +02:00
|
|
|
} else {
|
2023-10-02 16:44:53 +02:00
|
|
|
return json_encode(
|
2023-09-27 13:30:56 +02:00
|
|
|
[
|
|
|
|
'success' => false,
|
|
|
|
'error' => $response,
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|