report for ncm simple

This commit is contained in:
fbsanchez 2021-11-29 15:26:19 +01:00
parent 68c2400b9c
commit 19643cd685
6 changed files with 192 additions and 2 deletions

View File

@ -829,6 +829,10 @@ switch ($action) {
$select_by_group = $es['select_by_group']; $select_by_group = $es['select_by_group'];
break; break;
case 'ncm':
$idAgent = $item['id_agent'];
break;
default: default:
// It's not possible. // It's not possible.
break; break;
@ -6319,6 +6323,11 @@ function chooseType() {
} else { } else {
$("#row_profiles_group").hide(); $("#row_profiles_group").hide();
} }
break;
case 'ncm':
$("#row_agent").show();
break;
} }

View File

@ -774,8 +774,59 @@ function mysql_db_format_array_where_clause_sql($values, $join='AND', $prefix=fa
$not = (($negative === true) ? ' !' : ''); $not = (($negative === true) ? ' !' : '');
$query .= sprintf('%s %s= %f', $field, $not, $value); $query .= sprintf('%s %s= %f', $field, $not, $value);
} else if (is_array($value)) { } else if (is_array($value)) {
$not = (($negative === true) ? 'NOT' : ''); $values_check = array_keys($value);
$query .= sprintf('%s %s IN ("%s")', $field, $not, implode('", "', $value)); $ranges = false;
$initialized = false;
foreach ($values_check as $operation) {
if ($ranges === true && $initialized === true) {
$query .= ' '.$join.' ';
} else {
$initialized = true;
}
if ($operation === '>') {
$query .= sprintf("%s > '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($operation === '>=') {
$query .= sprintf("%s >= '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($operation === '<') {
$query .= sprintf("%s < '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($operation === '<=') {
$query .= sprintf("%s <= '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($operation === '!=') {
$query .= sprintf("%s != '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($operation === '=') {
$query .= sprintf("%s = '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($negative === true && $operation === '>') {
$query .= sprintf("%s <= '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($negative === true && $operation === '>=') {
$query .= sprintf("%s < '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($negative === true && $operation === '<') {
$query .= sprintf("%s >= '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($negative === true && $operation === '<=') {
$query .= sprintf("%s > '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($negative === true && $operation === '!=') {
$query .= sprintf("%s = '%s'", $field, $value[$operation]);
$ranges = true;
} else if ($negative === true && $operation === '=') {
$query .= sprintf("%s != '%s'", $field, $value[$operation]);
$ranges = true;
}
}
if ($ranges !== true) {
$not = (($negative === true) ? 'NOT' : '');
$query .= sprintf('%s %s IN ("%s")', $field, $not, implode('", "', $value));
}
} else { } else {
if ($value === '') { if ($value === '') {
// Search empty string. // Search empty string.

View File

@ -873,6 +873,14 @@ function reporting_make_reporting_data(
); );
break; break;
case 'ncm':
$report['contents'][] = reporting_ncm_config(
$report,
$content,
$pdf
);
break;
default: default:
// Default. // Default.
break; break;

View File

@ -437,6 +437,10 @@ function reporting_html_print_report($report, $mini=false, $report_info=1)
$mini $mini
); );
break; break;
case 'ncm':
reporting_html_ncm_config($table, $item);
break;
} }
if ($item['type'] == 'agent_module') { if ($item['type'] == 'agent_module') {
@ -5977,3 +5981,43 @@ function reporting_html_permissions($table, $item, $pdf=0)
); );
} }
} }
/**
* HTML content for ncm configuration diff report.
*
* @param array $item Content generated by reporting_ncm_config.
*
* @return string HTML code.
*/
function reporting_html_ncm_config($table, $item, $pdf=0)
{
$key = uniqid();
if ($pdf === 0) {
ui_require_javascript_file('diff2html-ui.min');
ui_require_css_file('diff2html.min');
$script = "$(document).ready(function() {
const configuration = {
drawFileList: false,
collapsed: true,
matching: 'lines',
outputFormat: 'side-by-side',
};
const diff2htmlUi = new Diff2HtmlUI(
document.getElementById('".$key."'),
atob('".base64_encode($item['data'])."'),
configuration
);
diff2htmlUi.draw();
});";
$content = '<div class="w100p" id="'.$key.'"></div class="w100p">';
$content .= '<script>'.$script.'</script>';
$table->data[1] = $content;
$table->colspan[1][0] = 2;
} else {
$content = '<div style="text-align:left;margin-left: 14px;">';
$content .= str_replace("\n", '<br>', $item['data']);
$content .= '</div>';
return $content;
}
}

View File

@ -911,6 +911,11 @@ function reports_get_report_types($template=false, $not_editor=false)
]; ];
} }
$types['ncm'] = [
'optgroup' => __('NCM'),
'name' => __('Network configuration changes'),
];
return $types; return $types;
} }

View File

@ -0,0 +1,73 @@
<?php
/**
* Class to manage some advanced operations over strings.
*
* @category Class
* @package Pandora FMS
* @subpackage Tools
* @version 1.0.0
* @license See below
*
* ______ ___ _______ _______ ________
* | __ \.-----.--.--.--| |.-----.----.-----. | ___| | | __|
* | __/| _ | | _ || _ | _| _ | | ___| |__ |
* |___| |___._|__|__|_____||_____|__| |___._| |___| |__|_|__|_______|
*
* ============================================================================
* Copyright (c) 2005-2021 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.
* ============================================================================
*/
// Begin.
namespace PandoraFMS\Tools;
global $config;
/**
* Files class definition.
*/
class Strings
{
/**
* Retrieves a diff output for given strings.
*
* @param string $a A.
* @param string $b B.
*
* @return string Diff or error.
*/
public static function diff(string $a, string $b)
{
$A = sys_get_temp_dir().'/A-'.uniqid();
$B = sys_get_temp_dir().'/B-'.uniqid();
file_put_contents($A, \io_safe_output($a));
file_put_contents($B, \io_safe_output($b));
$cmd = 'diff -u '.$A.' '.$B.' 2>&1';
exec($cmd, $output, $rc);
unlink($A);
unlink($B);
$output = join("\n", $output);
if ($rc <= 1) {
return $output;
}
return 'Error ['.$rc.']: '.$output;
}
}