Merge branch 'ent-6407-server-to-execute-snmp-browser' into 'develop'

Fixed snmp server selection

See merge request artica/pandorafms!3658
This commit is contained in:
Daniel Rodriguez 2021-01-11 14:57:12 +01:00
commit 14985c35ec
3 changed files with 145 additions and 116 deletions

View File

@ -1,22 +1,22 @@
<?php <?php
/**
// Pandora FMS- http://pandorafms.com * Pandora FMS- http://pandorafms.com.
// ================================================== * ==================================================
// Copyright (c) 2005-2021 Artica Soluciones Tecnologicas * Copyright (c) 2005-2021 Artica Soluciones Tecnologicas
// Please see http://pandorafms.org for full contribution list * Please see http://pandorafms.org for full contribution list
// This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License * modify it under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation; version 2 * as published by the Free Software Foundation; version 2
// This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details. * GNU General Public License for more details.
*/
require_once $config['homedir'].'/include/functions_config.php'; require_once $config['homedir'].'/include/functions_config.php';
require_once $config['homedir'].'/include/functions_snmp_browser.php'; require_once $config['homedir'].'/include/functions_snmp_browser.php';
require_once $config['homedir'].'/include/functions_snmp.php'; require_once $config['homedir'].'/include/functions_snmp.php';
require_once $config['homedir'].'/include/functions_network_components.php'; require_once $config['homedir'].'/include/functions_network_components.php';
global $config; global $config;
if (is_ajax()) { if (is_ajax()) {
@ -37,6 +37,7 @@ if (is_ajax()) {
$targets_oids = get_parameter('oids', ''); $targets_oids = get_parameter('oids', '');
$return_id = get_parameter('return_id', false); $return_id = get_parameter('return_id', false);
$custom_action = get_parameter('custom_action', ''); $custom_action = get_parameter('custom_action', '');
$server_to_exec = get_parameter('server_to_exec');
if (!is_array($targets_oids)) { if (!is_array($targets_oids)) {
$targets_oids = explode(',', $targets_oids); $targets_oids = explode(',', $targets_oids);
@ -50,7 +51,6 @@ if (is_ajax()) {
if ($action == 'snmptree') { if ($action == 'snmptree') {
$starting_oid = (string) get_parameter('starting_oid', '.'); $starting_oid = (string) get_parameter('starting_oid', '.');
$snmp_tree = snmp_browser_get_tree( $snmp_tree = snmp_browser_get_tree(
$target_ip, $target_ip,
$community, $community,
@ -62,6 +62,7 @@ if (is_ajax()) {
$snmp3_auth_pass, $snmp3_auth_pass,
$snmp3_privacy_method, $snmp3_privacy_method,
$snmp3_privacy_pass, $snmp3_privacy_pass,
'null',
$server_to_exec $server_to_exec
); );
if (! is_array($snmp_tree)) { if (! is_array($snmp_tree)) {
@ -166,7 +167,7 @@ if (is_ajax()) {
if ($method == 'snmp_browser_create_modules') { if ($method == 'snmp_browser_create_modules') {
// Get target ids from form. // Get target ids from form.
$id_items = get_parameter('id_item2', null); $id_items = get_parameter('id_item2', null);
if (!is_null($id_items)) { if (empty($id_items) === false) {
$id_target = explode(',', $id_items[0]); $id_target = explode(',', $id_items[0]);
} }

View File

@ -264,10 +264,30 @@ function snmp_browser_get_tree(
$snmp3_auth_pass='', $snmp3_auth_pass='',
$snmp3_privacy_method='', $snmp3_privacy_method='',
$snmp3_privacy_pass='', $snmp3_privacy_pass='',
$snmp3_context_engine_id=null $snmp3_context_engine_id=null,
$server_to_exec=0
) { ) {
global $config; global $config;
if ($server_to_exec != 0) {
$output = get_snmpwalk(
$target_ip,
$version,
$community,
$snmp3_auth_user,
$snmp3_security_level,
$snmp3_auth_method,
$snmp3_auth_pass,
$snmp3_privacy_method,
$snmp3_privacy_pass,
0,
$starting_oid,
'',
$server_to_exec,
'',
''
);
} else {
switch ($version) { switch ($version) {
case '1': case '1':
$snmp_version = SNMP::VERSION_1; $snmp_version = SNMP::VERSION_1;
@ -332,8 +352,10 @@ function snmp_browser_get_tree(
} }
$snmp_session->close(); $snmp_session->close();
}
// Build the tree. // Build the tree if output comes filled.
if (empty($output) === false) {
$oid_tree = ['__LEAVES__' => []]; $oid_tree = ['__LEAVES__' => []];
foreach ($output as $oid => $value) { foreach ($output as $oid => $value) {
// Parse the OID. // Parse the OID.
@ -381,6 +403,10 @@ function snmp_browser_get_tree(
$ptr = &$ptr[$sub_oid]; $ptr = &$ptr[$sub_oid];
$sub_oid = ''; $sub_oid = '';
} }
} else {
$oid_tree = __('The server did not return any response.');
error_log($oid_tree);
}
return $oid_tree; return $oid_tree;
} }

View File

@ -25,6 +25,7 @@ function snmpBrowse() {
var snmp3_auth_pass = $("#password-snmp3_browser_auth_pass").val(); var snmp3_auth_pass = $("#password-snmp3_browser_auth_pass").val();
var snmp3_privacy_method = $("#snmp3_browser_privacy_method").val(); var snmp3_privacy_method = $("#snmp3_browser_privacy_method").val();
var snmp3_privacy_pass = $("#password-snmp3_browser_privacy_pass").val(); var snmp3_privacy_pass = $("#password-snmp3_browser_privacy_pass").val();
var server_to_exec = $("#server_to_exec").val();
var ajax_url = $("#hidden-ajax_url").val(); var ajax_url = $("#hidden-ajax_url").val();
// Prepare the AJAX call // Prepare the AJAX call
@ -41,6 +42,7 @@ function snmpBrowse() {
params["snmp3_browser_auth_pass"] = snmp3_auth_pass; params["snmp3_browser_auth_pass"] = snmp3_auth_pass;
params["snmp3_browser_privacy_method"] = snmp3_privacy_method; params["snmp3_browser_privacy_method"] = snmp3_privacy_method;
params["snmp3_browser_privacy_pass"] = snmp3_privacy_pass; params["snmp3_browser_privacy_pass"] = snmp3_privacy_pass;
params["server_to_exec"] = server_to_exec;
params["action"] = "snmptree"; params["action"] = "snmptree";
params["page"] = "include/ajax/snmp_browser.ajax"; params["page"] = "include/ajax/snmp_browser.ajax";