Merge branch 'ent-4205-gigas-proyectos-funcionamiento-incorrecto-del-wizard-snmp-con-exec-server' into 'develop'
exec server error wizard See merge request artica/pandorafms!2606
This commit is contained in:
commit
8ce685a219
|
@ -382,13 +382,13 @@ $table_server = '<div class="label_select"><p class="input_label">'.__('Server')
|
|||
$table_server .= '<div class="label_select_parent">';
|
||||
if ($new_agent) {
|
||||
// Set first server by default.
|
||||
$servers_get_names = servers_get_names();
|
||||
$servers_get_names = $servers;
|
||||
$array_keys_servers_get_names = array_keys($servers_get_names);
|
||||
$server_name = reset($array_keys_servers_get_names);
|
||||
}
|
||||
|
||||
$table_server .= html_print_select(
|
||||
servers_get_names(),
|
||||
$servers,
|
||||
'server_name',
|
||||
$server_name,
|
||||
'',
|
||||
|
|
|
@ -1,16 +1,32 @@
|
|||
<?php
|
||||
/**
|
||||
* Extension to manage a list of gateways and the node address where they should
|
||||
* point to.
|
||||
*
|
||||
* @category SNMP interfaces.
|
||||
* @package Pandora FMS
|
||||
* @subpackage Community
|
||||
* @version 1.0.0
|
||||
* @license See below
|
||||
*
|
||||
* ______ ___ _______ _______ ________
|
||||
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
|
||||
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
|
||||
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
|
||||
*
|
||||
* ============================================================================
|
||||
* Copyright (c) 2005-2019 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 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.
|
||||
* ============================================================================
|
||||
*/
|
||||
|
||||
// Pandora FMS - http://pandorafms.com
|
||||
// ==================================================
|
||||
// Copyright (c) 2005-2011 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 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.
|
||||
global $config;
|
||||
require_once $config['homedir'].'/include/functions_agents.php';
|
||||
require_once 'include/functions_modules.php';
|
||||
|
@ -36,10 +52,10 @@ $snmp3_privacy_method = get_parameter('snmp3_privacy_method');
|
|||
$snmp3_privacy_pass = io_safe_output(get_parameter('snmp3_privacy_pass'));
|
||||
$tcp_port = (string) get_parameter('tcp_port');
|
||||
|
||||
// See if id_agente is set (either POST or GET, otherwise -1
|
||||
// See if id_agente is set (either POST or GET, otherwise -1.
|
||||
$id_agent = $idAgent;
|
||||
|
||||
// Get passed variables
|
||||
// Get passed variables.
|
||||
$snmpwalk = (int) get_parameter('snmpwalk', 0);
|
||||
$create_modules = (int) get_parameter('create_modules', 0);
|
||||
|
||||
|
@ -47,7 +63,7 @@ $interfaces = [];
|
|||
$interfaces_ip = [];
|
||||
|
||||
if ($snmpwalk) {
|
||||
// OID Used is for SNMP MIB-2 Interfaces
|
||||
// OID Used is for SNMP MIB-2 Interfaces.
|
||||
$snmpis = get_snmpwalk(
|
||||
$ip_target,
|
||||
$snmp_version,
|
||||
|
@ -63,7 +79,7 @@ if ($snmpwalk) {
|
|||
$tcp_port,
|
||||
$server_to_exec
|
||||
);
|
||||
// ifXTable is also used
|
||||
// IfXTable is also used.
|
||||
$ifxitems = get_snmpwalk(
|
||||
$ip_target,
|
||||
$snmp_version,
|
||||
|
@ -80,7 +96,7 @@ if ($snmpwalk) {
|
|||
$server_to_exec
|
||||
);
|
||||
|
||||
// Get the interfaces IPV4/IPV6
|
||||
// Get the interfaces IPV4/IPV6.
|
||||
$snmp_int_ip = get_snmpwalk(
|
||||
$ip_target,
|
||||
$snmp_version,
|
||||
|
@ -97,12 +113,12 @@ if ($snmpwalk) {
|
|||
$server_to_exec
|
||||
);
|
||||
|
||||
// Build a [<interface id>] => [<interface ip>] array
|
||||
// Build a [<interface id>] => [<interface ip>] array.
|
||||
if (!empty($snmp_int_ip)) {
|
||||
foreach ($snmp_int_ip as $key => $value) {
|
||||
// The key is something like IP-MIB::ipAddressIfIndex.ipv4."<ip>"
|
||||
// or IP-MIB::ipAddressIfIndex.ipv6."<ip>"
|
||||
// The value is something like INTEGER: <interface id>
|
||||
// The key is something like IP-MIB::ipAddressIfIndex.ipv4."<ip>".
|
||||
// or IP-MIB::ipAddressIfIndex.ipv6."<ip>".
|
||||
// The value is something like INTEGER: <interface id>.
|
||||
$data = explode(': ', $value);
|
||||
$interface_id = !empty($data) && isset($data[1]) ? $data[1] : false;
|
||||
|
||||
|
@ -110,7 +126,7 @@ if ($snmpwalk) {
|
|||
$interface_ip = $matches[1];
|
||||
}
|
||||
|
||||
// Get the first ip
|
||||
// Get the first ip.
|
||||
if ($interface_id !== false && !empty($interface_ip) && !isset($interfaces_ip[$interface_id])) {
|
||||
$interfaces_ip[$interface_id] = $interface_ip;
|
||||
}
|
||||
|
@ -119,17 +135,17 @@ if ($snmpwalk) {
|
|||
unset($snmp_int_ip);
|
||||
}
|
||||
|
||||
$snmpis = array_merge(($snmpis === false ? [] : $snmpis), ($ifxitems === false ? [] : $ifxitems));
|
||||
$snmpis = array_merge((($snmpis === false) ? [] : $snmpis), (($ifxitems === false) ? [] : $ifxitems));
|
||||
|
||||
$interfaces = [];
|
||||
|
||||
// We get here only the interface part of the MIB, not full mib
|
||||
// We get here only the interface part of the MIB, not full mib.
|
||||
foreach ($snmpis as $key => $snmp) {
|
||||
$data = explode(': ', $snmp, 2);
|
||||
$keydata = explode('::', $key);
|
||||
$keydata2 = explode('.', $keydata[1]);
|
||||
|
||||
// Avoid results without index and interfaces without name
|
||||
// Avoid results without index and interfaces without name.
|
||||
if (!isset($keydata2[1]) || !isset($data[1])) {
|
||||
continue;
|
||||
}
|
||||
|
@ -239,24 +255,22 @@ if ($create_modules) {
|
|||
$oid_array[(count($oid_array) - 1)] = $id;
|
||||
$oid = implode('.', $oid_array);
|
||||
|
||||
// Get the name
|
||||
// Get the name.
|
||||
$name_array = explode('::', $oid_array[0]);
|
||||
$name = $ifname.'_'.$name_array[1];
|
||||
|
||||
// Clean the name
|
||||
// Clean the name.
|
||||
$name = str_replace('"', '', $name);
|
||||
|
||||
// Proc moduletypes
|
||||
// Proc moduletypes.
|
||||
if (preg_match('/Status/', $name_array[1])) {
|
||||
$module_type = 18;
|
||||
} else if (preg_match('/Present/', $name_array[1])) {
|
||||
$module_type = 18;
|
||||
} else if (preg_match('/PromiscuousMode/', $name_array[1])) {
|
||||
$module_type = 18;
|
||||
}
|
||||
|
||||
// String moduletypes
|
||||
else if (preg_match('/Alias/', $name_array[1])) {
|
||||
} else if (preg_match('/Alias/', $name_array[1])) {
|
||||
// String moduletypes.
|
||||
$module_type = 17;
|
||||
} else if (preg_match('/Address/', $name_array[1])) {
|
||||
$module_type = 17;
|
||||
|
@ -266,15 +280,11 @@ if ($create_modules) {
|
|||
$module_type = 17;
|
||||
} else if (preg_match('/Descr/', $name_array[1])) {
|
||||
$module_type = 17;
|
||||
}
|
||||
|
||||
// Specific counters (ends in s)
|
||||
else if (preg_match('/s$/', $name_array[1])) {
|
||||
} else if (preg_match('/s$/', $name_array[1])) {
|
||||
// Specific counters (ends in s).
|
||||
$module_type = 16;
|
||||
}
|
||||
|
||||
// Otherwise, numeric
|
||||
else {
|
||||
} else {
|
||||
// Otherwise, numeric.
|
||||
$module_type = 15;
|
||||
}
|
||||
|
||||
|
@ -330,7 +340,7 @@ if ($create_modules) {
|
|||
|
||||
$output_oid = '';
|
||||
|
||||
exec('ssh pandora_exec_proxy@'.$row['ip_address'].' snmptranslate -On '.$oid, $output_oid, $rc);
|
||||
exec('snmptranslate -On '.$oid, $output_oid, $rc);
|
||||
|
||||
$conf_oid = $output_oid[0];
|
||||
$oid = $conf_oid;
|
||||
|
@ -397,7 +407,9 @@ if ($create_modules) {
|
|||
}
|
||||
|
||||
if ($done > 0) {
|
||||
ui_print_success_message(__('Successfully modules created')." ($done)");
|
||||
ui_print_success_message(
|
||||
__('Successfully modules created').' ('.$done.')'
|
||||
);
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
|
@ -407,17 +419,17 @@ if ($create_modules) {
|
|||
foreach ($errors as $code => $number) {
|
||||
switch ($code) {
|
||||
case ERR_EXIST:
|
||||
$msg .= '<br>'.__('Another module already exists with the same name')." ($number)";
|
||||
$msg .= '<br>'.__('Another module already exists with the same name').' ('.$number.')';
|
||||
break;
|
||||
|
||||
case ERR_INCOMPLETE:
|
||||
$msg .= '<br>'.__('Some required fields are missed').': ('.__('name').') '." ($number)";
|
||||
$msg .= '<br>'.__('Some required fields are missed').': ('.__('name').') ('.$number.')';
|
||||
break;
|
||||
|
||||
case ERR_DB:
|
||||
case ERR_GENERIC:
|
||||
default:
|
||||
$msg .= '<br>'.__('Processing error')." ($number)";
|
||||
$msg .= '<br>'.__('Processing error').' ('.$number.')';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -426,10 +438,10 @@ if ($create_modules) {
|
|||
}
|
||||
}
|
||||
|
||||
// Create the interface list for the interface
|
||||
// Create the interface list for the interface.
|
||||
$interfaces_list = [];
|
||||
foreach ($interfaces as $interface) {
|
||||
// Get the interface name, removing " " characters and avoid "blank" interfaces
|
||||
// Get the interface name, removing " " characters and avoid "blank" interfaces.
|
||||
if (isset($interface['ifDescr']) && $interface['ifDescr']['value'] != '') {
|
||||
$ifname = $interface['ifDescr']['value'];
|
||||
} else if (isset($interface['ifName']) && $interface['ifName']['value'] != '') {
|
||||
|
@ -442,7 +454,7 @@ foreach ($interfaces as $interface) {
|
|||
}
|
||||
|
||||
echo '<span id ="none_text" style="display: none;">'.__('None').'</span>';
|
||||
echo "<form method='post' id='walk_form' action='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=snmp_interfaces_explorer&id_agente=$id_agent'>";
|
||||
echo "<form method='post' id='walk_form' action='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=snmp_interfaces_explorer&id_agente=".$id_agent."'>";
|
||||
|
||||
$table->width = '100%';
|
||||
$table->cellpadding = 0;
|
||||
|
@ -464,12 +476,14 @@ if (enterprise_installed()) {
|
|||
enterprise_include_once('include/functions_satellite.php');
|
||||
|
||||
$rows = get_proxy_servers();
|
||||
|
||||
// Check if satellite server has remote configuration enabled.
|
||||
$satellite_remote = config_agents_has_remote_configuration($id_agent);
|
||||
|
||||
foreach ($rows as $row) {
|
||||
if ($row['server_type'] != 13) {
|
||||
$s_type = ' (Standard)';
|
||||
} else {
|
||||
// Check if satellite server has remote configuration enabled
|
||||
$satellite_remote = config_agents_has_remote_configuration($id_agent);
|
||||
$id_satellite = $row['id_server'];
|
||||
$s_type = ' (Satellite)';
|
||||
}
|
||||
|
@ -484,8 +498,7 @@ $table->data[1][4] = html_print_select(
|
|||
$servers_to_exec,
|
||||
'server_to_exec',
|
||||
$server_to_exec,
|
||||
'satellite_remote_warn('.$id_satellite.','.$satellite_remote.')
|
||||
',
|
||||
'satellite_remote_warn('.$id_satellite.','.$satellite_remote.')',
|
||||
'',
|
||||
'',
|
||||
true
|
||||
|
@ -509,7 +522,7 @@ html_print_table($table);
|
|||
|
||||
unset($table);
|
||||
|
||||
// SNMP3 OPTIONS
|
||||
// SNMP3 OPTIONS.
|
||||
$table->width = '100%';
|
||||
|
||||
$table->data[2][1] = '<b>'.__('Auth user').'</b>';
|
||||
|
@ -564,7 +577,7 @@ echo '</form>';
|
|||
|
||||
if (!empty($interfaces_list)) {
|
||||
echo '<span id ="none_text" style="display: none;">'.__('None').'</span>';
|
||||
echo "<form method='post' action='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=snmp_interfaces_explorer&id_agente=$id_agent'>";
|
||||
echo "<form method='post' action='index.php?sec=gagente&sec2=godmode/agentes/configurar_agente&tab=agent_wizard&wizard_section=snmp_interfaces_explorer&id_agente=".$id_agent."'>";
|
||||
echo '<span id="form_interfaces">';
|
||||
|
||||
$id_snmp_serialize = serialize_in_temp($interfaces, $config['id_user'].'_snmp');
|
||||
|
@ -589,7 +602,7 @@ if (!empty($interfaces_list)) {
|
|||
|
||||
$table->width = '100%';
|
||||
|
||||
// Agent selector
|
||||
// Agent selector.
|
||||
$table->data[0][0] = '<b>'.__('Interfaces').'</b>';
|
||||
$table->data[0][1] = '';
|
||||
$table->data[0][2] = '<b>'.__('Modules').'</b>';
|
||||
|
@ -636,12 +649,10 @@ ui_require_jquery_file('bgiframe');
|
|||
/* <![CDATA[ */
|
||||
|
||||
$(document).ready (function () {
|
||||
|
||||
|
||||
var inputActive = true;
|
||||
|
||||
$('#server_to_exec option').trigger('change');
|
||||
|
||||
|
||||
$(document).data('text_for_module', $("#none_text").html());
|
||||
|
||||
$("#id_snmp").change(snmp_changed_by_multiple_snmp);
|
||||
|
|
|
@ -566,11 +566,11 @@ function modules_update_agent_module(
|
|||
/**
|
||||
* Creates a module in an agent.
|
||||
*
|
||||
* @param int Agent id.
|
||||
* @param int Module name id.
|
||||
* @param array Extra values for the module.
|
||||
* @param bool Disable the ACL checking, for default false.
|
||||
* @param mixed Array with tag's ids or false.
|
||||
* @param integer $id_agent Agent id.
|
||||
* @param integer $name Module name id.
|
||||
* @param array $values Extra values for the module.
|
||||
* @param boolean $disableACL Disable the ACL checking, for default false.
|
||||
* @param mixed $tags Array with tag's ids or false.
|
||||
*
|
||||
* @return New module id if the module was created. False if not.
|
||||
*/
|
||||
|
@ -584,7 +584,9 @@ function modules_create_agent_module(
|
|||
global $config;
|
||||
|
||||
if (!$disableACL) {
|
||||
if (!users_is_admin() && (empty($id_agent) || ! users_access_to_agent($id_agent, 'AW'))) {
|
||||
if (!users_is_admin() && (empty($id_agent)
|
||||
|| !users_access_to_agent($id_agent, 'AW'))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -593,7 +595,7 @@ function modules_create_agent_module(
|
|||
return ERR_INCOMPLETE;
|
||||
}
|
||||
|
||||
// Check for non valid characters in module name
|
||||
// Check for non valid characters in module name.
|
||||
if (mb_ereg_match('[\xc2\xa1\xc2\xbf\xc3\xb7\xc2\xba\xc2\xaa]', io_safe_output($name)) !== false) {
|
||||
return ERR_GENERIC;
|
||||
}
|
||||
|
@ -605,23 +607,33 @@ function modules_create_agent_module(
|
|||
$values['nombre'] = $name;
|
||||
$values['id_agente'] = (int) $id_agent;
|
||||
|
||||
$exists = (bool) db_get_value_filter('id_agente_modulo', 'tagente_modulo', ['nombre' => $name, 'id_agente' => (int) $id_agent]);
|
||||
$exists = (bool) db_get_value_filter(
|
||||
'id_agente_modulo',
|
||||
'tagente_modulo',
|
||||
[
|
||||
'nombre' => $name,
|
||||
'id_agente' => (int) $id_agent,
|
||||
]
|
||||
);
|
||||
|
||||
if ($exists) {
|
||||
return ERR_EXIST;
|
||||
}
|
||||
|
||||
// Encrypt passwords
|
||||
// Encrypt passwords.
|
||||
if (isset($values['plugin_pass'])) {
|
||||
$values['plugin_pass'] = io_input_password($values['plugin_pass']);
|
||||
}
|
||||
|
||||
// Encrypt SNMPv3 passwords
|
||||
if (isset($values['id_tipo_modulo']) && ($values['id_tipo_modulo'] >= 15 && $values['id_tipo_modulo'] <= 18)
|
||||
// Encrypt SNMPv3 passwords.
|
||||
if (isset($values['id_tipo_modulo']) && ($values['id_tipo_modulo'] >= 15
|
||||
&& $values['id_tipo_modulo'] <= 18)
|
||||
&& isset($values['tcp_send']) && ($values['tcp_send'] == 3)
|
||||
&& isset($values['custom_string_2'])
|
||||
) {
|
||||
$values['custom_string_2'] = io_input_password($values['custom_string_2']);
|
||||
$values['custom_string_2'] = io_input_password(
|
||||
$values['custom_string_2']
|
||||
);
|
||||
}
|
||||
|
||||
$id_agent_module = db_process_sql_insert('tagente_modulo', $values);
|
||||
|
@ -645,25 +657,33 @@ function modules_create_agent_module(
|
|||
}
|
||||
|
||||
if (isset($values['id_tipo_modulo'])
|
||||
&& ($values['id_tipo_modulo'] == 21 || $values['id_tipo_modulo'] == 22 || $values['id_tipo_modulo'] == 23)
|
||||
&& ($values['id_tipo_modulo'] == 21
|
||||
|| $values['id_tipo_modulo'] == 22
|
||||
|| $values['id_tipo_modulo'] == 23)
|
||||
) {
|
||||
// Async modules start in normal status
|
||||
// Async modules start in normal status.
|
||||
$status = AGENT_MODULE_STATUS_NORMAL;
|
||||
} else {
|
||||
// Sync modules start in unknown status
|
||||
// Sync modules start in unknown status.
|
||||
$status = AGENT_MODULE_STATUS_NO_DATA;
|
||||
}
|
||||
|
||||
// Condition for cron modules. Don't touch.
|
||||
$time = 0;
|
||||
if (empty($values['interval']) === false) {
|
||||
$time = (time() - (int) $values['interval']);
|
||||
}
|
||||
|
||||
$result = db_process_sql_insert(
|
||||
'tagente_estado',
|
||||
[
|
||||
'id_agente_modulo' => $id_agent_module,
|
||||
'datos' => 0,
|
||||
'datos' => '',
|
||||
'timestamp' => '01-01-1970 00:00:00',
|
||||
'estado' => $status,
|
||||
'known_status' => $status,
|
||||
'id_agente' => (int) $id_agent,
|
||||
'utimestamp' => (time() - (int) $values['interval']),
|
||||
'utimestamp' => $time,
|
||||
'status_changes' => 0,
|
||||
'last_status' => $status,
|
||||
'last_known_status' => $status,
|
||||
|
@ -680,12 +700,20 @@ function modules_create_agent_module(
|
|||
return ERR_DB;
|
||||
}
|
||||
|
||||
// Update module status count if the module is not created disabled
|
||||
// Update module status count if the module is not created disabled.
|
||||
if (!isset($values['disabled']) || $values['disabled'] == 0) {
|
||||
if ($status == 0) {
|
||||
db_process_sql('UPDATE tagente SET total_count=total_count+1, normal_count=normal_count+1 WHERE id_agente='.(int) $id_agent);
|
||||
db_process_sql(
|
||||
'UPDATE tagente
|
||||
SET total_count=total_count+1, normal_count=normal_count+1
|
||||
WHERE id_agente='.(int) $id_agent
|
||||
);
|
||||
} else {
|
||||
db_process_sql('UPDATE tagente SET total_count=total_count+1, notinit_count=notinit_count+1 WHERE id_agente='.(int) $id_agent);
|
||||
db_process_sql(
|
||||
'UPDATE tagente
|
||||
SET total_count=total_count+1, notinit_count=notinit_count+1
|
||||
WHERE id_agente='.(int) $id_agent
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,11 +61,12 @@ function servers_get_server($id_server, $filter=false, $fields=false)
|
|||
*/
|
||||
function servers_get_names()
|
||||
{
|
||||
$all_servers = @db_get_all_rows_filter(
|
||||
'tserver',
|
||||
false,
|
||||
['DISTINCT(name) as name']
|
||||
$all_servers = db_get_all_rows_sql(
|
||||
'SELECT DISTINCT(`name`) as name
|
||||
FROM tserver
|
||||
WHERE server_type <> 13'
|
||||
);
|
||||
|
||||
if ($all_servers === false) {
|
||||
return [];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue