2014-09-23 18:05:44 +02:00
|
|
|
<?php
|
|
|
|
|
2021-11-04 16:28:15 +01:00
|
|
|
// Pandora FMS - http://pandorafms.com
|
2014-09-23 18:05:44 +02:00
|
|
|
// ==================================================
|
2020-11-27 13:52:35 +01:00
|
|
|
// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
|
2014-09-23 18:05:44 +02:00
|
|
|
// 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.
|
|
|
|
// Load global vars
|
|
|
|
global $config;
|
2019-01-30 16:18:44 +01:00
|
|
|
enterprise_include('operation/snmpconsole/snmp_view.php');
|
|
|
|
require_once $config['homedir'].'/include/functions_graph.php';
|
|
|
|
require_once $config['homedir'].'/include/functions_agents.php';
|
|
|
|
require_once $config['homedir'].'/include/functions_snmp.php';
|
2014-09-23 18:05:44 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
check_login();
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
// ACL
|
2019-01-30 16:18:44 +01:00
|
|
|
if (! check_acl($config['id_user'], 0, 'AR')) {
|
|
|
|
db_pandora_audit(
|
2022-01-20 10:55:23 +01:00
|
|
|
AUDIT_LOG_ACL_VIOLATION,
|
2019-01-30 16:18:44 +01:00
|
|
|
'Trying to access SNMP Console'
|
|
|
|
);
|
|
|
|
include 'general/noaccess.php';
|
|
|
|
exit;
|
2014-09-23 18:05:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read parameters
|
2019-01-30 16:18:44 +01:00
|
|
|
$refr = (int) get_parameter('refr', 0);
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Page header and tabs
|
|
|
|
// Fullscreen
|
2019-01-30 16:18:44 +01:00
|
|
|
$fullscreen = [];
|
|
|
|
if ($config['pure']) {
|
2021-03-11 15:40:23 +01:00
|
|
|
$fullscreen['text'] = '<a target="_top" href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_statistics&pure=0&refr='.$refr.'">'.html_print_image(
|
|
|
|
'images/normal_screen.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Normal screen'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
).'</a>';
|
2019-01-30 16:18:44 +01:00
|
|
|
} else {
|
2021-03-11 15:40:23 +01:00
|
|
|
$fullscreen['text'] = '<a target="_top" href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_statistics&pure=1&refr='.$refr.'">'.html_print_image(
|
|
|
|
'images/full_screen.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Full screen'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
).'</a>';
|
2014-09-23 18:05:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// List
|
2019-01-30 16:18:44 +01:00
|
|
|
$list = [];
|
2021-03-11 15:40:23 +01:00
|
|
|
$list['text'] = '<a href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_view&pure='.$config['pure'].'&refresh='.$refr.'">'.html_print_image(
|
|
|
|
'images/op_snmp.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('List'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
).'</a>';
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
// Statistics (This file)
|
2019-01-30 16:18:44 +01:00
|
|
|
$statistics = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
$statistics['active'] = true;
|
2021-03-11 15:40:23 +01:00
|
|
|
$statistics['text'] = '<a href="index.php?sec=estado&sec2=operation/snmpconsole/snmp_statistics&pure='.$config['pure'].'&refr='.$refr.'">'.html_print_image(
|
|
|
|
'images/op_reporting.png',
|
|
|
|
true,
|
|
|
|
[
|
|
|
|
'title' => __('Statistics'),
|
|
|
|
'class' => 'invert_filter',
|
|
|
|
]
|
|
|
|
).'</a>';
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
// Header
|
2021-04-29 15:35:33 +02:00
|
|
|
ui_print_standard_header(
|
|
|
|
__('SNMP Statistics'),
|
2019-01-30 16:18:44 +01:00
|
|
|
'images/op_snmp.png',
|
|
|
|
false,
|
|
|
|
'',
|
|
|
|
false,
|
|
|
|
[
|
|
|
|
$fullscreen,
|
|
|
|
$list,
|
|
|
|
$statistics,
|
2021-04-29 15:35:33 +02:00
|
|
|
],
|
|
|
|
[
|
|
|
|
[
|
|
|
|
'link' => '',
|
|
|
|
'label' => __('Monitoring'),
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'link' => '',
|
|
|
|
'label' => __('SNMP'),
|
|
|
|
],
|
2019-01-30 16:18:44 +01:00
|
|
|
]
|
|
|
|
);
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
// Retrieving the data
|
2019-01-30 16:18:44 +01:00
|
|
|
$user_groups = users_get_groups($config['id_user'], 'AR', false);
|
2014-09-23 18:05:44 +02:00
|
|
|
$user_groups_str = '0';
|
|
|
|
if (!empty($user_groups)) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$user_groups_str = implode(',', array_keys($user_groups));
|
2014-09-23 18:05:44 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$last_month_timestamp = date('Y-m-d H:i:s', (time() - SECONDS_1MONTH));
|
2014-09-23 18:05:44 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
switch ($config['dbtype']) {
|
|
|
|
case 'mysql':
|
|
|
|
case 'postgresql':
|
|
|
|
$sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num, MAX(timestamp) AS timestamp
|
2015-04-30 20:11:07 +02:00
|
|
|
FROM ttrap
|
|
|
|
WHERE timestamp >= '%s'
|
|
|
|
AND (source = ''
|
|
|
|
OR source NOT IN (SELECT direccion FROM tagente)
|
|
|
|
OR source IN (SELECT direccion
|
|
|
|
FROM tagente
|
|
|
|
WHERE id_grupo IN (%s)))
|
|
|
|
GROUP BY %s
|
|
|
|
ORDER BY num DESC, timestamp DESC
|
|
|
|
LIMIT 25";
|
2019-01-30 16:18:44 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'oracle':
|
|
|
|
// MAX(timestamp) AS timestamp is needed to do the magic with oracle
|
|
|
|
$sql_traps_generated = "SELECT %s, COUNT(id_trap) AS num, MAX(timestamp) AS timestamp
|
2015-04-30 20:11:07 +02:00
|
|
|
FROM ttrap
|
|
|
|
WHERE timestamp >= '%s'
|
|
|
|
AND (source = ''
|
|
|
|
OR source NOT IN (SELECT direccion FROM tagente)
|
|
|
|
OR source IN (SELECT direccion
|
|
|
|
FROM tagente
|
|
|
|
WHERE id_grupo IN (%s)))
|
|
|
|
GROUP BY %s
|
|
|
|
ORDER BY num DESC, timestamp DESC";
|
2019-01-30 16:18:44 +01:00
|
|
|
$sql_traps_generated = "SELECT * FROM ($sql_traps_generated) WHERE rownum <= 25";
|
|
|
|
break;
|
2015-04-30 20:11:07 +02:00
|
|
|
}
|
2014-09-23 18:05:44 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$sql_traps_generated_by_source = sprintf($sql_traps_generated, 'source', $last_month_timestamp, $user_groups_str, 'source');
|
|
|
|
$sql_traps_generated_by_oid = sprintf($sql_traps_generated, 'oid', $last_month_timestamp, $user_groups_str, 'oid');
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
$traps_generated_by_source = db_get_all_rows_sql($sql_traps_generated_by_source);
|
|
|
|
$traps_generated_by_oid = db_get_all_rows_sql($sql_traps_generated_by_oid);
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
// No traps
|
2014-09-23 18:05:44 +02:00
|
|
|
if (empty($traps_generated_by_source) || empty($traps_generated_by_oid)) {
|
2019-01-30 16:18:44 +01:00
|
|
|
ui_print_info_message(['no_close' => true, 'message' => __('There are no SNMP traps in database') ]);
|
|
|
|
return;
|
2014-09-23 18:05:44 +02:00
|
|
|
}
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$water_mark = [
|
|
|
|
'file' => $config['homedir'].'/images/logo_vertical_water.png',
|
|
|
|
'url' => ui_get_full_url('/images/logo_vertical_water.png'),
|
|
|
|
];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
// By SOURCE
|
|
|
|
$table_source = new StdClass();
|
|
|
|
$table_source->width = '100%';
|
2015-04-22 16:46:08 +02:00
|
|
|
$table_source->class = 'databox data';
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_source->head[] = __('Traps received by source').' - '.sprintf(__('Top %d'), 25);
|
2014-09-23 18:05:44 +02:00
|
|
|
$table_source->head_colspan[] = 2;
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_source->headstyle[] = 'background-color: #82b92e';
|
|
|
|
$table_source->size = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
$table_source->size['table'] = '50%';
|
|
|
|
$table_source->size['graph'] = '50%';
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_source->data = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_source_row = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
$table_source_data = new StdClass();
|
|
|
|
$table_source_data->width = '100%';
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_source_data->head = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
$table_source_data->head['source'] = __('Source IP');
|
|
|
|
$table_source_data->head['num'] = __('Number');
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_source_data->data = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_source_graph_data = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
foreach ($traps_generated_by_source as $trap) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$row = [];
|
|
|
|
|
|
|
|
$agent = agents_get_agent_with_ip($trap['source']);
|
|
|
|
if ($agent === false) {
|
|
|
|
$row['source'] = '<a href="index.php?sec=estado&sec2=godmode/agentes/configurar_agente&new_agent=1&direccion='.$trap['source'].'" title="'.__('Create agent').'">'.$trap['source'].'</a>';
|
|
|
|
} else {
|
|
|
|
$agent_id = $agent['id_agente'];
|
2019-09-03 11:14:33 +02:00
|
|
|
$agent_name = ui_print_truncate_text($agent['alias'], 'agent_medium', true, true, true, '[…]', '');
|
2019-01-30 16:18:44 +01:00
|
|
|
$row['source'] = "<a href=\"index.php?sec=estado&sec2=operation/agentes/ver_agente&id_agente=$agent_id\" title=\"".__('View agent details').'">';
|
|
|
|
$row['source'] .= "<strong>$agent_name</strong></a>";
|
|
|
|
}
|
|
|
|
|
|
|
|
$row['num'] = (int) $trap['num'];
|
|
|
|
|
|
|
|
$table_source_data->data[] = $row;
|
|
|
|
|
|
|
|
$table_source_graph_data[$trap['source']] = (int) $trap['num'];
|
2014-09-23 18:05:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$table_source_row['table'] = html_print_table($table_source_data, true);
|
|
|
|
unset($table_source_data);
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if (empty($table_source_graph_data)) {
|
|
|
|
$table_source_graph = graph_nodata_image();
|
|
|
|
} else {
|
|
|
|
$table_source_graph = pie_graph(
|
|
|
|
$table_source_graph_data,
|
|
|
|
400,
|
|
|
|
550,
|
|
|
|
__('Other'),
|
|
|
|
'',
|
|
|
|
$water_mark,
|
|
|
|
$config['fontpath'],
|
|
|
|
$config['font_size'],
|
|
|
|
1
|
|
|
|
);
|
|
|
|
}
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
$table_source_row['graph'] = $table_source_graph;
|
|
|
|
|
|
|
|
$table_source->data[] = $table_source_row;
|
|
|
|
|
|
|
|
html_print_table($table_source);
|
|
|
|
unset($table_source);
|
|
|
|
|
|
|
|
// By OID
|
|
|
|
$table_oid = new StdClass();
|
|
|
|
$table_oid->width = '100%';
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_oid->head[] = __('Traps received by Enterprise String').' - '.sprintf(__('Top %d'), 25);
|
2014-09-23 18:05:44 +02:00
|
|
|
$table_oid->head_colspan[] = 2;
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_oid->headstyle[] = 'background-color: #82b92e';
|
|
|
|
$table_oid->size = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
$table_oid->size['table'] = '50%';
|
|
|
|
$table_oid->size['graph'] = '50%';
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_oid->data = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_oid_row = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
$table_oid_data = new StdClass();
|
|
|
|
$table_oid_data->width = '100%';
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_oid_data->head = [];
|
2015-01-21 14:47:54 +01:00
|
|
|
$table_oid_data->head['oid'] = __('Trap Enterprise String');
|
2014-09-23 18:05:44 +02:00
|
|
|
$table_oid_data->head['num'] = __('Number');
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_oid_data->data = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_oid_graph_data = [];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
foreach ($traps_generated_by_oid as $trap) {
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_oid_data->data[] = [
|
|
|
|
'oid' => $trap['oid'],
|
|
|
|
'num' => (int) $trap['num'],
|
|
|
|
];
|
2014-09-23 18:05:44 +02:00
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
$table_oid_graph_data[$trap['oid']] = (int) $trap['num'];
|
2014-09-23 18:05:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$table_oid_row['table'] = html_print_table($table_oid_data, true);
|
|
|
|
unset($table_oid_data);
|
|
|
|
|
2019-01-30 16:18:44 +01:00
|
|
|
if (empty($table_oid_graph_data)) {
|
|
|
|
$table_oid_graph = graph_nodata_image();
|
|
|
|
} else {
|
|
|
|
$table_oid_graph = pie_graph(
|
|
|
|
$table_oid_graph_data,
|
|
|
|
400,
|
|
|
|
550,
|
|
|
|
__('Other'),
|
|
|
|
'',
|
|
|
|
$water_mark,
|
|
|
|
$config['fontpath'],
|
|
|
|
$config['font_size'],
|
|
|
|
1
|
|
|
|
);
|
|
|
|
}
|
2014-09-23 18:05:44 +02:00
|
|
|
|
|
|
|
$table_oid_row['graph'] = $table_oid_graph;
|
|
|
|
|
|
|
|
$table_oid->data[] = $table_oid_row;
|
|
|
|
|
|
|
|
html_print_table($table_oid);
|
|
|
|
unset($table_oid);
|