Fixed snmp server selection

This commit is contained in:
Jose Gonzalez 2020-11-26 10:35:48 +01:00
parent 1ce0a8cba8
commit 9bf70add51
3 changed files with 146 additions and 115 deletions

View File

@ -1,16 +1,17 @@
<?php
// Pandora FMS- http://pandorafms.com
// ==================================================
// Copyright (c) 2005-2017 Artica Soluciones Tecnologicas
// 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 Lesser General Public License
// as published by the Free Software Foundation; 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.
/**
* Pandora FMS- http://pandorafms.com.
* ==================================================
* Copyright (c) 2005-2020 Artica Soluciones Tecnologicas
* 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 Lesser General Public License
* as published by the Free Software Foundation; 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.
*/
require_once $config['homedir'].'/include/functions_config.php';
require_once $config['homedir'].'/include/functions_snmp_browser.php';
require_once $config['homedir'].'/include/functions_snmp.php';
@ -37,6 +38,7 @@ if (is_ajax()) {
$targets_oids = get_parameter('oids', '');
$return_id = get_parameter('return_id', false);
$custom_action = get_parameter('custom_action', '');
$server_to_exec = get_parameter('server_to_exec');
if (!is_array($targets_oids)) {
$targets_oids = explode(',', $targets_oids);
@ -50,7 +52,6 @@ if (is_ajax()) {
if ($action == 'snmptree') {
$starting_oid = (string) get_parameter('starting_oid', '.');
$snmp_tree = snmp_browser_get_tree(
$target_ip,
$community,
@ -62,6 +63,7 @@ if (is_ajax()) {
$snmp3_auth_pass,
$snmp3_privacy_method,
$snmp3_privacy_pass,
'null',
$server_to_exec
);
if (! is_array($snmp_tree)) {
@ -166,7 +168,7 @@ if (is_ajax()) {
if ($method == 'snmp_browser_create_modules') {
// Get target ids from form.
$id_items = get_parameter('id_item2', null);
if (!is_null($id_items)) {
if (empty($id_items) === false) {
$id_target = explode(',', $id_items[0]);
}

View File

@ -263,10 +263,31 @@ function snmp_browser_get_tree(
$snmp3_auth_pass='',
$snmp3_privacy_method='',
$snmp3_privacy_pass='',
$snmp3_context_engine_id=null
$snmp3_context_engine_id=null,
$server_to_exec=0
) {
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 {
hd('entra por igual a 0', true);
switch ($version) {
case '1':
$snmp_version = SNMP::VERSION_1;
@ -331,8 +352,10 @@ function snmp_browser_get_tree(
}
$snmp_session->close();
}
// Build the tree.
// Build the tree if output comes filled.
if (empty($output) === false) {
$oid_tree = ['__LEAVES__' => []];
foreach ($output as $oid => $value) {
// Parse the OID.
@ -380,6 +403,10 @@ function snmp_browser_get_tree(
$ptr = &$ptr[$sub_oid];
$sub_oid = '';
}
} else {
$oid_tree = __('The server did not return any response.');
error_log($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_privacy_method = $("#snmp3_browser_privacy_method").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();
// Prepare the AJAX call
@ -41,6 +42,7 @@ function snmpBrowse() {
params["snmp3_browser_auth_pass"] = snmp3_auth_pass;
params["snmp3_browser_privacy_method"] = snmp3_privacy_method;
params["snmp3_browser_privacy_pass"] = snmp3_privacy_pass;
params["server_to_exec"] = server_to_exec;
params["action"] = "snmptree";
params["page"] = "include/ajax/snmp_browser.ajax";