availability failover

This commit is contained in:
Daniel Maya 2020-01-15 17:16:46 +01:00
parent c1a124c970
commit c68f83f013
6 changed files with 229 additions and 16 deletions

View File

@ -2,5 +2,6 @@ START TRANSACTION;
ALTER TABLE `tmap` ADD COLUMN `id_group_map` INT(10) UNSIGNED NOT NULL default 0;
ALTER TABLE `tevent_filter` MODIFY `severity` TEXT NOT NULL;
ALTER TABLE `treport_content_item` ADD `id_agent_module_failover` int(10) unsigned NOT NULL DEFAULT 0;
COMMIT;

View File

@ -628,6 +628,8 @@ switch ($action) {
$unknown_checks = $item['unknown_checks'];
$agent_max_value = $item['agent_max_value'];
$agent_min_value = $item['agent_min_value'];
$failover_mode = $item['failover_mode'];
$failover_type = $item['failover_type'];
break;
case 'group_report':
@ -3263,6 +3265,13 @@ function print_General_list($width, $action, $idItem=null, $type='general')
$meta = false;
}
$failover_mode = db_get_value(
'failover_mode',
'treport_content',
'id_rc',
$idItem
);
$operation = [
'avg' => __('rate'),
'max' => __('max'),
@ -3284,6 +3293,18 @@ function print_General_list($width, $action, $idItem=null, $type='general')
<th class="header" scope="col">
<?php echo __('Module'); ?>
</th>
<?php
if ($failover_mode) {
?>
<th class="header" scope="col">
<?php echo __('Agent Failover'); ?>
</th>
<th class="header" scope="col">
<?php echo __('Module Failover'); ?>
</th>
<?php
}
?>
<th class="header" scope="col">
<?php echo __('Action'); ?>
</th>
@ -3365,19 +3386,50 @@ function print_General_list($width, $action, $idItem=null, $type='general')
['id_agente_modulo' => $item['id_agent_module']]
);
if (isset($item['id_agent_module_failover']) === true
&& $item['id_agent_module_failover'] !== 0
) {
$idAgentFailover = db_get_value_filter(
'id_agente',
'tagente_modulo',
['id_agente_modulo' => $item['id_agent_module_failover']]
);
$nameAgentFailover = agents_get_alias(
$idAgentFailover
);
$nameModuleFailover = db_get_value_filter(
'nombre',
'tagente_modulo',
['id_agente_modulo' => $item['id_agent_module_failover']]
);
}
$server_name_element = '';
if ($meta && $server_name != '') {
$server_name_element .= ' ('.$server_name.')';
}
if ($type == 'availability') {
echo '<tr id="general_'.$item['id'].'" style="" class="datos">
<td>'.printSmallFont($nameAgent).$server_name_element.'</td>
<td>'.printSmallFont($nameModule).'</td>
<td style="text-align: center;">
<a href="javascript: deleteGeneralRow('.$item['id'].');">'.html_print_image('images/cross.png', true).'</a>
</td>
</tr>';
if ($failover_mode) {
echo '<tr id="general_'.$item['id'].'" style="" class="datos">
<td>'.printSmallFont($nameAgent).$server_name_element.'</td>
<td>'.printSmallFont($nameModule).'</td>
<td>'.printSmallFont($nameAgentFailover).$server_name_element.'</td>
<td>'.printSmallFont($nameModuleFailover).'</td>
<td style="text-align: center;">
<a href="javascript: deleteGeneralRow('.$item['id'].');">'.html_print_image('images/cross.png', true).'</a>
</td>
</tr>';
} else {
echo '<tr id="general_'.$item['id'].'" style="" class="datos">
<td>'.printSmallFont($nameAgent).$server_name_element.'</td>
<td>'.printSmallFont($nameModule).'</td>
<td style="text-align: center;">
<a href="javascript: deleteGeneralRow('.$item['id'].');">'.html_print_image('images/cross.png', true).'</a>
</td>
</tr>';
}
} else {
echo '<tr id="general_'.$item['id'].'" style="" class="datos">
<td>'.printSmallFont($nameAgent).$server_name_element.'</td>
@ -3403,6 +3455,15 @@ function print_General_list($width, $action, $idItem=null, $type='general')
<td class="agent_name"></td>
<td class="module_name"></td>
<?php
if ($type == 'availability'
&& $failover_mode
) {
?>
<td class="agent_name_failover"></td>
<td class="module_name_failover"></td>
<?php
}
if ($type != 'availability') {
?>
<td class="operation_name"></td>
@ -3456,6 +3517,43 @@ function print_General_list($width, $action, $idItem=null, $type='general')
</select>
</td>
<?php
if ($type == 'availability' && $failover_mode) {
?>
<td class="sla_list_agent_failover_col">
<input id="hidden-id_agent_failover" name="id_agent_failover" value="" type="hidden">
<input id="hidden-server_name_failover" name="server_name_failover" value="" type="hidden">
<?php
$params = [];
$params['show_helptip'] = true;
$params['input_name'] = 'agent_failover';
$params['value'] = '';
$params['use_hidden_input_idagent'] = true;
$params['hidden_input_idagent_id'] = 'hidden-id_agent_failover';
$params['javascript_is_function_select'] = true;
$params['selectbox_id'] = 'id_agent_module_failover';
$params['add_none_module'] = false;
if ($meta) {
$params['use_input_id_server'] = true;
$params['input_id_server_id'] = 'hidden-id_server';
$params['disabled_javascript_on_blur_function'] = true;
}
ui_print_agent_autocomplete_input($params);
?>
</td>
<td class="sla_list_module_failover_col">
<select id="id_agent_module_failover" name="id_agent_module_failover" disabled="disabled" style="max-width: 180px">
<option value="0">
<?php
echo __('Select an Agent first');
?>
</option>
</select>
</td>
<?php
}
?>
<?php
if ($type !== 'availability') {
?>
<td>
@ -4495,6 +4593,10 @@ function addGeneralRow() {
var idAgent = $("input[name=id_agent_general]").val();
var serverId = $("input[name=id_server]").val();
var idModule = $("#id_agent_module_general").val();
var nameAgentFailover = $("input[name=agent_failover]").val();
var idModuleFailover = $("#id_agent_module_failover").val();
var nameModuleFailover = $("#id_agent_module_failover :selected").text();
var operation;
if ($("#id_operation_module_general").length) {
operation = $("#id_operation_module_general").val();
@ -4580,10 +4682,63 @@ function addGeneralRow() {
}
});
if (nameAgentFailover != '') {
//Truncate nameAgentFailover
var params = [];
params.push("truncate_text=1");
params.push("text=" + nameAgentFailover);
params.push("page=include/ajax/reporting.ajax");
jQuery.ajax ({
data: params.join ("&"),
type: 'POST',
url: action=
<?php
echo '"'.ui_get_full_url(
false,
false,
false,
false
).'"';
?>
+ "/ajax.php",
async: false,
timeout: 10000,
success: function (data) {
nameAgentFailover = data;
}
});
//Truncate nameModuleFailover
var params = [];
params.push("truncate_text=1");
params.push("text=" + nameModuleFailover);
params.push("page=include/ajax/reporting.ajax");
jQuery.ajax ({
data: params.join ("&"),
type: 'POST',
url: action=
<?php
echo '"'.ui_get_full_url(
false,
false,
false,
false
).'"';
?>
+ "/ajax.php",
async: false,
timeout: 10000,
success: function (data) {
nameModuleFailover = data;
}
});
}
var params = [];
params.push("add_general=1");
params.push("id=" + $("input[name=id_item]").val());
params.push("id_module=" + idModule);
params.push("id_module_failover=" + idModuleFailover);
params.push("id_server=" + serverId);
params.push("operation=" + operation);
params.push("id_agent=" + idAgent);
@ -4610,6 +4765,8 @@ function addGeneralRow() {
$("#row", row).attr('id', 'general_' + data['id']);
$(".agent_name", row).html(nameAgent);
$(".module_name", row).html(nameModule);
$(".agent_name_failover", row).html(nameAgentFailover);
$(".module_name_failover", row).html(nameModuleFailover);
$(".operation_name", row).html(nameOperation);
$(".delete_button", row).attr(
'href',
@ -4624,6 +4781,15 @@ function addGeneralRow() {
$("#id_operation_module_general").val('avg');
$("#id_agent_module_general").empty();
$("#id_agent_module_general").attr('disabled', 'true');
$("input[name=id_agent_failover]").val('');
$("input[name=agent_failover]").val('');
$("#id_agent_module_failover").empty();
$("#id_agent_module_failover").attr('disabled', 'true');
$("#id_agent_module_failover").append(
$("<option></option>")
.attr ("value", 0)
.html ($("#module_sla_text").html()));
}
}
});
@ -5111,6 +5277,12 @@ function chooseType() {
$("#row_select_fields3").hide();
}
$("#row_historical_db_check").hide();
$("#row_failover_mode").show();
var failover_checked = $("input[name='failover_mode']").prop("checked");
if(failover_checked){
$("#row_failover_type").show();
}
break;
case 'group_report':

View File

@ -1609,6 +1609,14 @@ switch ($action) {
$values['agent_min_value'] = get_parameter(
'agent_min_value'
);
$values['failover_mode'] = get_parameter(
'failover_mode',
0
);
$values['failover_type'] = get_parameter(
'failover_type',
REPORT_FAILOVER_TYPE_NORMAL
);
$good_format = true;
break;

View File

@ -111,6 +111,7 @@ if ($add_general) {
$id_module = get_parameter('id_module', 0);
$id_server = (int) get_parameter('id_server', 0);
$operation = get_parameter('operation', '');
$id_module_failover = (int) get_parameter('id_module_failover', 0);
$include_enterprise = enterprise_include('include/functions_metaconsole.php');
@ -126,10 +127,11 @@ if ($add_general) {
$result = db_process_sql_insert(
'treport_content_item',
[
'id_report_content' => $id,
'id_agent_module' => $id_module,
'server_name' => $connection['server_name'],
'operation' => $operation,
'id_report_content' => $id,
'id_agent_module' => $id_module,
'server_name' => $connection['server_name'],
'operation' => $operation,
'id_agent_module_failover' => $id_module_failover,
]
);

View File

@ -6252,7 +6252,7 @@ function reporting_availability($report, $content, $date=false, $time=false)
$sql = sprintf(
'
SELECT id_agent_module,
SELECT id_agent_module, id_agent_module_failover,
server_name, operation
FROM treport_content_item
WHERE id_report_content = %d',
@ -6337,6 +6337,30 @@ function reporting_availability($report, $content, $date=false, $time=false)
$content['time_to']
);
// $row['data']= reporting_advanced_sla(
// $item['id_agent_module_failover'],
// ($report['datetime'] - $content['period']),
// $report['datetime'],
// null,
// min_value -> dynamic
// null,
// max_value -> dynamic
// null,
// inverse_interval -> dynamic
// [
// '1' => $content['sunday'],
// '2' => $content['monday'],
// '3' => $content['tuesday'],
// '4' => $content['wednesday'],
// '5' => $content['thursday'],
// '6' => $content['friday'],
// '7' => $content['saturday'],
// ],
// $content['time_from'],
// $content['time_to']
// );
hd($row['data']);
// HACK it is saved in show_graph field.
// Show interfaces instead the modules
if ($content['show_graph']) {
@ -6450,6 +6474,8 @@ function reporting_availability($report, $content, $date=false, $time=false)
}
}
hd($data);
$return['data'] = $data;
$return['resume'] = [];
$return['resume']['resume'] = $content['show_resume'];
@ -6472,6 +6498,8 @@ function reporting_availability($report, $content, $date=false, $time=false)
$return['fields']['agent_max_value'] = $content['agent_max_value'];
$return['fields']['agent_min_value'] = $content['agent_min_value'];
hd(reporting_check_structure_content($return));
return reporting_check_structure_content($return);
}
@ -6595,6 +6623,7 @@ function reporting_availability_graph($report, $content, $pdf=false)
$slice = ($content['period'] / $module_interval);
$data_combined = [];
// hd($sla_failover);
foreach ($sla_failover as $k_sla => $v_sla) {
$sla_array = data_db_uncompress_module(
$v_sla,

View File

@ -1485,14 +1485,15 @@ CREATE TABLE IF NOT EXISTS `treport_content_sla_combined` (
-- Table `treport_content_item`
-- ----------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS `treport_content_item` (
`id` INTEGER UNSIGNED NOT NULL auto_increment,
`id_report_content` INTEGER UNSIGNED NOT NULL,
`id_agent_module` int(10) unsigned NOT NULL,
`id` INTEGER UNSIGNED NOT NULL auto_increment,
`id_report_content` INTEGER UNSIGNED NOT NULL,
`id_agent_module` int(10) unsigned NOT NULL,
`id_agent_module_failover` int(10) unsigned NOT NULL DEFAULT 0,
`server_name` text,
`operation` text,
PRIMARY KEY(`id`),
FOREIGN KEY (`id_report_content`) REFERENCES treport_content(`id_rc`)
ON UPDATE CASCADE ON DELETE CASCADE
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE = InnoDB DEFAULT CHARSET=utf8;
-- ---------------------------------------------------------------------