Allow dinamic ip

This commit is contained in:
daniel 2017-01-17 09:21:46 +01:00
parent 2aba5dde02
commit 9e391e0210
6 changed files with 76 additions and 19 deletions

View File

@ -31,6 +31,7 @@ $ipAgent = db_get_value('direccion', 'tagente', 'id_agente', $idAgent);
check_login (); check_login ();
$ip_target = (string) get_parameter ('ip_target', $ipAgent); $ip_target = (string) get_parameter ('ip_target', $ipAgent);
$use_agent = get_parameter ('use_agent');
$snmp_community = (string) get_parameter ('snmp_community', 'public'); $snmp_community = (string) get_parameter ('snmp_community', 'public');
$snmp_version = get_parameter('snmp_version', '1'); $snmp_version = get_parameter('snmp_version', '1');
$snmp3_auth_user = get_parameter('snmp3_auth_user'); $snmp3_auth_user = get_parameter('snmp3_auth_user');
@ -305,7 +306,13 @@ if ($create_modules) {
$common_values['tcp_port'] = $tcp_port; $common_values['tcp_port'] = $tcp_port;
} }
$common_values['snmp_community'] = $snmp_community; $common_values['snmp_community'] = $snmp_community;
if($use_agent){
$common_values['ip_target'] = 'auto';
}
else{
$common_values['ip_target'] = $ip_target; $common_values['ip_target'] = $ip_target;
}
$common_values['tcp_send'] = $snmp_version; $common_values['tcp_send'] = $snmp_version;
if ($snmp_version == '3') { if ($snmp_version == '3') {
@ -696,18 +703,22 @@ $table->data[0][1] = html_print_input_text ('ip_target', $ip_target, '', 15, 60,
$table->data[0][2] = '<b>' . __('Port') . '</b>'; $table->data[0][2] = '<b>' . __('Port') . '</b>';
$table->data[0][3] = html_print_input_text ('tcp_port', $tcp_port, '', 5, 20, true); $table->data[0][3] = html_print_input_text ('tcp_port', $tcp_port, '', 5, 20, true);
$table->data[1][0] = '<b>' . __('Use agent ip') . '</b>';
$table->data[1][1] = html_print_checkbox ('use_agent', 1, $use_agent, true);
$snmp_versions['1'] = 'v. 1'; $snmp_versions['1'] = 'v. 1';
$snmp_versions['2'] = 'v. 2'; $snmp_versions['2'] = 'v. 2';
$snmp_versions['2c'] = 'v. 2c'; $snmp_versions['2c'] = 'v. 2c';
$snmp_versions['3'] = 'v. 3'; $snmp_versions['3'] = 'v. 3';
$table->data[1][0] = '<b>' . __('SNMP community') . '</b>'; $table->data[2][0] = '<b>' . __('SNMP community') . '</b>';
$table->data[1][1] = html_print_input_text ('snmp_community', $snmp_community, '', 15, 60, true); $table->data[2][1] = html_print_input_text ('snmp_community', $snmp_community, '', 15, 60, true);
$table->data[1][2] = '<b>' . __('SNMP version') . '</b>'; $table->data[2][2] = '<b>' . __('SNMP version') . '</b>';
$table->data[1][3] = html_print_select ($snmp_versions, 'snmp_version', $snmp_version, '', '', '', true, false, false, ''); $table->data[2][3] = html_print_select ($snmp_versions, 'snmp_version', $snmp_version, '', '', '', true, false, false, '');
$table->data[2][3] .= '<div id="spinner_modules" style="float: left; display: none;">' . html_print_image("images/spinner.gif", true) . '</div>';
$table->data[1][3] .= '<div id="spinner_modules" style="float: left; display: none;">' . html_print_image("images/spinner.gif", true) . '</div>';
html_print_input_hidden('snmpwalk', 1); html_print_input_hidden('snmpwalk', 1);
html_print_table($table); html_print_table($table);
@ -763,6 +774,7 @@ if (!$fail) {
html_print_input_hidden('create_modules', 1); html_print_input_hidden('create_modules', 1);
html_print_input_hidden('ip_target', $ip_target); html_print_input_hidden('ip_target', $ip_target);
html_print_input_hidden('use_agent', $use_agent);
html_print_input_hidden('tcp_port', $tcp_port); html_print_input_hidden('tcp_port', $tcp_port);
html_print_input_hidden('snmp_community', $snmp_community); html_print_input_hidden('snmp_community', $snmp_community);
html_print_input_hidden('snmp_version', $snmp_version); html_print_input_hidden('snmp_version', $snmp_version);

View File

@ -28,6 +28,7 @@ $ipAgent = db_get_value('direccion', 'tagente', 'id_agente', $idAgent);
check_login (); check_login ();
$ip_target = (string) get_parameter ('ip_target', $ipAgent); $ip_target = (string) get_parameter ('ip_target', $ipAgent);
$use_agent = get_parameter ('use_agent');
$snmp_community = (string) get_parameter ('snmp_community', 'public'); $snmp_community = (string) get_parameter ('snmp_community', 'public');
$snmp_version = get_parameter('snmp_version', '1'); $snmp_version = get_parameter('snmp_version', '1');
$snmp3_auth_user = get_parameter('snmp3_auth_user'); $snmp3_auth_user = get_parameter('snmp3_auth_user');
@ -136,7 +137,12 @@ if ($create_modules) {
$values['tcp_port'] = $tcp_port; $values['tcp_port'] = $tcp_port;
} }
$values['snmp_community'] = $snmp_community; $values['snmp_community'] = $snmp_community;
if($use_agent){
$values['ip_target'] = 'auto';
}
else{
$values['ip_target'] = $ip_target; $values['ip_target'] = $ip_target;
}
$values['tcp_send'] = $snmp_version; $values['tcp_send'] = $snmp_version;
if ($snmp_version == '3') { if ($snmp_version == '3') {
@ -336,18 +342,21 @@ $table->data[0][1] = html_print_input_text ('ip_target', $ip_target, '', 15, 60,
$table->data[0][2] = '<b>' . __('Port') . '</b>'; $table->data[0][2] = '<b>' . __('Port') . '</b>';
$table->data[0][3] = html_print_input_text ('tcp_port', $tcp_port, '', 5, 20, true); $table->data[0][3] = html_print_input_text ('tcp_port', $tcp_port, '', 5, 20, true);
$table->data[1][0] = '<b>' . __('Use agent ip') . '</b>';
$table->data[1][1] = html_print_checkbox ('use_agent', 1, $use_agent, true);
$snmp_versions['1'] = 'v. 1'; $snmp_versions['1'] = 'v. 1';
$snmp_versions['2'] = 'v. 2'; $snmp_versions['2'] = 'v. 2';
$snmp_versions['2c'] = 'v. 2c'; $snmp_versions['2c'] = 'v. 2c';
$snmp_versions['3'] = 'v. 3'; $snmp_versions['3'] = 'v. 3';
$table->data[1][0] = '<b>' . __('SNMP community') . '</b>'; $table->data[2][0] = '<b>' . __('SNMP community') . '</b>';
$table->data[1][1] = html_print_input_text ('snmp_community', $snmp_community, '', 15, 60, true); $table->data[2][1] = html_print_input_text ('snmp_community', $snmp_community, '', 15, 60, true);
$table->data[1][2] = '<b>' . __('SNMP version') . '</b>'; $table->data[2][2] = '<b>' . __('SNMP version') . '</b>';
$table->data[1][3] = html_print_select ($snmp_versions, 'snmp_version', $snmp_version, '', '', '', true, false, false, ''); $table->data[2][3] = html_print_select ($snmp_versions, 'snmp_version', $snmp_version, '', '', '', true, false, false, '');
$table->data[1][3] .= '<div id="spinner_modules" style="float: left; display: none;">' . html_print_image("images/spinner.gif", true) . '</div>'; $table->data[2][3] .= '<div id="spinner_modules" style="float: left; display: none;">' . html_print_image("images/spinner.gif", true) . '</div>';
html_print_input_hidden('snmpwalk', 1); html_print_input_hidden('snmpwalk', 1);
html_print_table($table); html_print_table($table);
@ -409,6 +418,7 @@ if (!empty($interfaces_list)) {
html_print_input_hidden('create_modules', 1); html_print_input_hidden('create_modules', 1);
html_print_input_hidden('ip_target', $ip_target); html_print_input_hidden('ip_target', $ip_target);
html_print_input_hidden('use_agent', $use_agent);
html_print_input_hidden('tcp_port', $tcp_port); html_print_input_hidden('tcp_port', $tcp_port);
html_print_input_hidden('snmp_community', $snmp_community); html_print_input_hidden('snmp_community', $snmp_community);
html_print_input_hidden('snmp_version', $snmp_version); html_print_input_hidden('snmp_version', $snmp_version);

View File

@ -974,6 +974,9 @@ if ($update_module || $create_module) {
$parent_module_id = (int) get_parameter('parent_module_id'); $parent_module_id = (int) get_parameter('parent_module_id');
$ip_target = (string) get_parameter ('ip_target'); $ip_target = (string) get_parameter ('ip_target');
if($ip_target == ''){
$ip_target = 'auto';
}
$custom_id = (string) get_parameter ('custom_id'); $custom_id = (string) get_parameter ('custom_id');
$history_data = (int) get_parameter('history_data'); $history_data = (int) get_parameter('history_data');
$dynamic_interval = (int) get_parameter('dynamic_interval'); $dynamic_interval = (int) get_parameter('dynamic_interval');

View File

@ -65,6 +65,10 @@ $extra_title = __('Network server module');
$data = array (); $data = array ();
$data[0] = __('Target IP'); $data[0] = __('Target IP');
//show agent_for defect;
if($ip_target == 'auto'){
$ip_target = agents_get_address ($id_agente);
}
$data[1] = html_print_input_text ('ip_target', $ip_target, '', 15, 60, true); $data[1] = html_print_input_text ('ip_target', $ip_target, '', 15, 60, true);
// In ICMP modules, port is not configurable // In ICMP modules, port is not configurable

View File

@ -480,9 +480,17 @@ $table->data['edit3'][2] = __('SMNP community');
$table->data['edit3'][3] = html_print_input_text ('snmp_community', '', $table->data['edit3'][3] = html_print_input_text ('snmp_community', '',
'', 10, 15, true); '', 10, 15, true);
$target_ip_values = array();
$target_ip_values['auto'] = __('Auto');
$target_ip_values['force_pri'] = __('Force primary key');
$target_ip_values['custom'] = __('Custom');
$table->data['edit35'][0] = __('Target IP'); $table->data['edit35'][0] = __('Target IP');
$table->data['edit35'][1] = html_print_input_text ('ip_target', '', '', $table->data['edit35'][1] = html_print_select ($target_ip_values,
15, 60, true); 'ip_target', '', '', __('No change'), '', true, false, false, '', false, 'width:200px;');
$table->data['edit35'][1] .= html_print_input_text ('custom_ip_target', '', '', 15, 60, true);
$table->data['edit35'][2] = __('SNMP version'); $table->data['edit35'][2] = __('SNMP version');
$table->data['edit35'][3] = html_print_select ($snmp_versions, $table->data['edit35'][3] = html_print_select ($snmp_versions,
'tcp_send', '', '', __('No change'), '', true, false, false, ''); 'tcp_send', '', '', __('No change'), '', true, false, false, '');
@ -647,6 +655,7 @@ $(document).ready (function () {
} }
}); });
$("#text-custom_ip_target").hide();
$("#id_agents").change(agent_changed_by_multiple_agents); $("#id_agents").change(agent_changed_by_multiple_agents);
$("#module_name").change(module_changed_by_multiple_modules); $("#module_name").change(module_changed_by_multiple_modules);
@ -929,6 +938,15 @@ $(document).ready (function () {
} }
}); });
$('#ip_target').change(function() {
if($(this).val() == 'custom') {
$("#text-custom_ip_target").show();
}
else{
$("#text-custom_ip_target").hide();
}
});
var recursion; var recursion;
$("#checkbox-recursion").click(function () { $("#checkbox-recursion").click(function () {
@ -1062,7 +1080,7 @@ function process_manage_edit ($module_name, $agents_select = null) {
'id_export', 'history_data', 'critical_inverse', 'id_export', 'history_data', 'critical_inverse',
'warning_inverse', 'critical_instructions', 'warning_inverse', 'critical_instructions',
'warning_instructions', 'unknown_instructions', 'policy_linked', 'warning_instructions', 'unknown_instructions', 'policy_linked',
'id_category', 'disabled_types_event', 'ip_target', 'id_category', 'disabled_types_event', 'ip_target', "custom_ip_target",
'descripcion', 'min_ff_event_normal', 'min_ff_event_warning', 'descripcion', 'min_ff_event_normal', 'min_ff_event_warning',
'min_ff_event_critical', 'each_ff', 'module_ff_interval', 'min_ff_event_critical', 'each_ff', 'module_ff_interval',
'ff_timeout', 'max_timeout'); 'ff_timeout', 'max_timeout');

View File

@ -412,7 +412,17 @@ function modules_update_agent_module ($id, $values,
} }
} }
if(isset ($values['ip_target'])){
if($values['ip_target'] == 'force_pri'){
$sql_agent = "SELECT id_agente FROM tagente_modulo WHERE id_agente_modulo=" . $id;
$id_agente = mysql_db_process_sql($sql_agent);
$values['ip_target'] = agents_get_address ($id_agente);
}
elseif($values['ip_target'] == 'custom'){
$values['ip_target'] = $values['custom_ip_target'];
}
}
unset($values['custom_ip_target']);
$where = array(); $where = array();
$where['id_agente_modulo'] = $id; $where['id_agente_modulo'] = $id;