add new report custom render pandora_enterprise#8540

This commit is contained in:
Daniel Barbero Martin 2022-04-01 13:55:18 +02:00
parent bfa137aa67
commit 597e527f38
4 changed files with 126 additions and 35 deletions

View File

@ -6814,36 +6814,46 @@ function chooseType() {
}
function addCustomFieldRow() {
var array_tr = $("tr.tr-macros-definition");
var last_tr = array_tr[array_tr.length - 1];
var array_id = /(\d)+$/.exec($(last_tr).attr('id'));
var max = (parseInt(array_id[0]) + 1);
var clone = $("#table-macros-definition #table-macros-definition-0")
.clone()
.prop("id", "table-macros-definition-" + $("tr.tr-macros-definition").length);
.prop("id", "table-macros-definition-" + max);
clone
.find("#macro_custom_name")
.prop("id", "macro_custom_name_" + $("tr.tr-macros-definition").length)
.prop("id", "macro_custom_name_" + max)
.val("");
clone
.find("#macro_custom_key")
.prop("id", "macro_custom_key_" + max)
.val(max);
clone
.find("#macro_custom_type")
.prop("id", "macro_custom_type" + $("tr.tr-macros-definition").length)
.attr("onchange", "change_custom_fields_macros_report(" + $("tr.tr-macros-definition").length + ")");
.prop("id", "macro_custom_type" + max)
.attr("onchange", "change_custom_fields_macros_report(" + max + ")");
clone
.find("#table-macros-definition-0-value")
.prop("id", "table-macros-definition-"+$("tr.tr-macros-definition").length+"-value");
.prop("id", "table-macros-definition-"+max+"-value");
clone
.find("#macro_custom_value")
.prop("id", "macro_custom_value_" + $("tr.tr-macros-definition").length)
.prop("id", "macro_custom_value_" + max)
.val('');
clone
.find(".icon-clean-custom-macro")
.attr("onclick", "cleanCustomFieldRow(" + $("tr.tr-macros-definition").length + ")");
.attr("onclick", "cleanCustomFieldRow(" + max + ")");
clone
.find(".icon-delete-custom-macro")
.attr("onclick", "removeCustomFieldRow(" + $("tr.tr-macros-definition").length + ")")
.attr("onclick", "removeCustomFieldRow(" + max + ")")
.css("display", "inline-block");
clone

View File

@ -1856,25 +1856,24 @@ switch ($action) {
$macro_custom_name = get_parameter('macro_custom_name', []);
$macro_custom_type = get_parameter('macro_custom_type', []);
$macro_custom_value = get_parameter('macro_custom_value', []);
$macro_custom_width = get_parameter('macro_custom_width', []);
$macro_custom_height = get_parameter('macro_custom_height', []);
$macro_custom_key = get_parameter('macro_custom_key', []);
$macros_definition = [];
hd($_POST);
foreach ($macro_custom_name as $key_macro => $value_macro) {
$kl = (empty($macro_custom_key[$key_macro]) === true) ? 0 : $macro_custom_key[$key_macro];
$macros_definition[$key_macro]['name'] = $value_macro;
$macros_definition[$key_macro]['type'] = $macro_custom_type[$key_macro];
if (isset($macro_custom_value[$key_macro]) === true) {
if (is_array($macro_custom_value[$kl]) === true) {
foreach ($macro_custom_value[$kl] as $k => $v) {
$macros_definition[$key_macro][$k] = $v;
}
} else {
$macros_definition[$key_macro]['value'] = $macro_custom_value[$key_macro];
}
if (isset($macro_custom_width[$key_macro]) === true) {
$macros_definition[$key_macro]['width'] = $macro_custom_width[$key_macro];
}
if (isset($macro_custom_height[$key_macro]) === true) {
$macros_definition[$key_macro]['height'] = $macro_custom_height[$key_macro];
}
}
$values['macros_definition'] = json_encode($macros_definition);
@ -2636,25 +2635,22 @@ switch ($action) {
$macro_custom_name = get_parameter('macro_custom_name', []);
$macro_custom_type = get_parameter('macro_custom_type', []);
$macro_custom_value = get_parameter('macro_custom_value', []);
$macro_custom_width = get_parameter('macro_custom_width', []);
$macro_custom_height = get_parameter('macro_custom_height', []);
$macro_custom_key = get_parameter('macro_custom_key', []);
$macros_definition = [];
foreach ($macro_custom_name as $key_macro => $value_macro) {
$kl = (empty($macro_custom_key[$key_macro]) === true) ? 0 : $macro_custom_key[$key_macro];
$macros_definition[$key_macro]['name'] = $value_macro;
$macros_definition[$key_macro]['type'] = $macro_custom_type[$key_macro];
if (isset($macro_custom_value[$key_macro]) === true) {
if (is_array($macro_custom_value[$kl]) === true) {
foreach ($macro_custom_value[$kl] as $k => $v) {
$macros_definition[$key_macro][$k] = $v;
}
} else {
$macros_definition[$key_macro]['value'] = $macro_custom_value[$key_macro];
}
if (isset($macro_custom_width[$key_macro]) === true) {
$macros_definition[$key_macro]['width'] = $macro_custom_width[$key_macro];
}
if (isset($macro_custom_height[$key_macro]) === true) {
$macros_definition[$key_macro]['height'] = $macro_custom_height[$key_macro];
}
}
$values['macros_definition'] = json_encode($macros_definition);

View File

@ -4884,6 +4884,35 @@ function reporting_custom_render($report, $content, $type='dinamic', $pdf=0)
$substitutions[] = $value_query;
break;
case 3:
// Type: SQL graph.
$patterns[] = addslashes(
'/_'.$data_macro['name'].'_/'
);
$params = [
'agent_module_id' => $data_macro['id_agent_module'],
'period' => 86400,
'title' => '',
'label' => '',
'pure' => false,
'only_image' => true,
'homeurl' => ui_get_full_url(
false,
false,
false,
false
),
'ttl' => 2,
'show_unknown' => true,
'height' => $config['graph_image_height'],
'backgroundColor' => 'transparent',
'return_img_base_64' => true,
];
$substitutions[] = '<img style="max-width:100%;" src="data:image/png;base64,'.grafico_modulo_sparse($params).'" />';
break;
default:
// Not possible.
break;

View File

@ -1099,6 +1099,15 @@ function get_table_custom_macros_report($data)
true
);
$table->data[$key_macro]['name'] .= html_print_input_hidden(
'macro_custom_key[]',
$key_macro,
true,
false,
false,
($key_macro === 0) ? 'macro_custom_key' : 'macro_custom_key_'.$key_macro
);
$table->data[$key_macro]['type'] = html_print_select(
$list_macro_custom_type,
'macro_custom_type[]',
@ -1180,10 +1189,10 @@ function custom_fields_macros_report($macro, $key_macro)
case 1:
$result['value'] = '<div class="custom-field-macro-report">';
$result['value'] .= '<label>';
$result['value'] .= ($macro['type'] === 0) ? __('String') : __('Sql');
$result['value'] .= ($macro['type'] == 0) ? __('String') : __('Sql');
$result['value'] .= '</label>';
$result['value'] .= html_print_input_text_extended(
'macro_custom_value['.$key_macro.']',
'macro_custom_value[]',
$macro['value'],
($key_macro === 0) ? 'macro_custom_value' : 'macro_custom_value_'.$key_macro,
'',
@ -1203,7 +1212,7 @@ function custom_fields_macros_report($macro, $key_macro)
$result['value'] .= __('Sql');
$result['value'] .= '</label>';
$result['value'] .= html_print_input_text_extended(
'macro_custom_value['.$key_macro.']',
'macro_custom_value['.$key_macro.'][value]',
$macro['value'],
($key_macro === 0) ? 'macro_custom_value' : 'macro_custom_value_'.$key_macro,
'',
@ -1221,7 +1230,7 @@ function custom_fields_macros_report($macro, $key_macro)
$result['size'] .= __('Width');
$result['size'] .= '</label>';
$result['size'] .= html_print_input_text_extended(
'macro_custom_width['.$key_macro.']',
'macro_custom_value['.$key_macro.'][width]',
$macro['width'],
($key_macro === 0) ? 'macro_custom_width' : 'macro_custom_width_'.$key_macro,
'',
@ -1237,7 +1246,7 @@ function custom_fields_macros_report($macro, $key_macro)
$result['size'] .= __('Height');
$result['size'] .= '</label>';
$result['size'] .= html_print_input_text_extended(
'macro_custom_height['.$key_macro.']',
'macro_custom_value['.$key_macro.'][height]',
$macro['height'],
($key_macro === 0) ? 'macro_custom_height' : 'macro_custom_height_'.$key_macro,
'',
@ -1251,6 +1260,53 @@ function custom_fields_macros_report($macro, $key_macro)
$result['size'] .= '</div>';
break;
case 3:
$params = [];
$params['show_helptip'] = true;
$params['input_name'] = 'macro_custom_value_agent_name_'.$key_macro;
$params['value'] = agents_get_alias($macro['agent_id']);
$params['print_hidden_input_idagent'] = true;
$params['hidden_input_idagent_id'] = 'macro_custom_value_agent_id_'.$key_macro;
$params['hidden_input_idagent_name'] = 'macro_custom_value['.$key_macro.'][agent_id]';
$params['hidden_input_idagent_value'] = $macro['agent_id'];
$params['javascript_is_function_select'] = true;
$params['selectbox_id'] = 'macro_custom_value'.$key_macro.'id_agent_module';
$params['add_none_module'] = false;
$params['return'] = true;
$params['disabled_javascript_on_blur_function'] = true;
// TODO: Metaconsole.
// if (is_metaconsole() === true) {
// $params['use_input_id_server'] = true;
// $params['input_id_server_id'] = 'hidden-id_server';
// }
$result['size'] .= ui_print_agent_autocomplete_input($params);
$modules = [];
if ($macro['agent_id']) {
$modules = agents_get_modules(
$macro['agent_id'],
false,
['delete_pending' => 0]
);
}
$result['size'] .= html_print_select(
$modules,
'macro_custom_value['.$key_macro.'][id_agent_module]',
$macro['id_agent_module'],
true,
__('Select'),
0,
true,
false,
true,
'',
(empty($macro['agent_id']) === true),
'min-width: 250px;margin-right: 0.5em;'
);
break;
default:
// code...
break;