mirror of
https://github.com/Cacti/cacti.git
synced 2026-10-23 03:27:02 +09:00
Fixing Issue #4728 - Replacing Suggested Values
- Cacti Template and Package Installs need a way to deal with conflicting Suggested Name Values/Patterns - Note that this has not been fully tested yet.
This commit is contained in:
1 parent
13698a6ee2
commit
c99d9365a8
7 files changed
+96
-47
No files matched your search
@@ -19,6 +19,7 @@ Cacti CHANGELOG
|
||||
-issue#4719: Browsers to begin rejecting CactiTimeZone and CactiDateTime cookies due to SameSite Requirements
|
||||
-issue#4721: Some JavaScript and image files URL are broken under midwinter theme
|
||||
-issue#4722: Detect table user_auth_group and column user_auth.lastfail for Pre-1.0 upgradeing
|
||||
-issue#4729: Cacti Template and Package Installs need a way to deal with conflicting Suggested Name Values/Patterns
|
||||
-feature#4720: Add a CLI script to install/enable/disable/uninstall plugins
|
||||
|
||||
1.2.20
|
||||
|
||||
+20
-10
@@ -43,12 +43,13 @@ array_shift($parms);
|
||||
global $preview_only;
|
||||
|
||||
if (cacti_sizeof($parms)) {
|
||||
$filename = '';
|
||||
$use_profile = false;
|
||||
$remove_orphans = false;
|
||||
$preview_only = false;
|
||||
$info_only = false;
|
||||
$profile_id = '';
|
||||
$filename = '';
|
||||
$use_profile = false;
|
||||
$remove_orphans = false;
|
||||
$replace_svalues = false;
|
||||
$preview_only = false;
|
||||
$info_only = false;
|
||||
$profile_id = '';
|
||||
|
||||
foreach($parms as $parameter) {
|
||||
if (strpos($parameter, '=')) {
|
||||
@@ -70,6 +71,10 @@ if (cacti_sizeof($parms)) {
|
||||
case '--remove-orphans':
|
||||
$remove_orphans = true;
|
||||
|
||||
break;
|
||||
case '--replace-svalues':
|
||||
$replace_svalues = true;
|
||||
|
||||
break;
|
||||
case '--profile-id':
|
||||
$profile_id = trim($value);
|
||||
@@ -101,7 +106,7 @@ if (cacti_sizeof($parms)) {
|
||||
|
||||
if ($info_only) {
|
||||
if ($filename != '' && is_readable($filename) && file_exists($filename) && !is_dir($filename)) {
|
||||
$result = import_package($filename, $profile_id, $remove_orphans, $preview_only, $info_only);
|
||||
$result = import_package($filename, $profile_id, $remove_orphans, $replace_svalues, $preview_only, $info_only);
|
||||
|
||||
if ($result !== false && cacti_sizeof($result)) {
|
||||
print json_encode($result);
|
||||
@@ -139,7 +144,7 @@ if (cacti_sizeof($parms)) {
|
||||
|
||||
print 'Read ' . strlen($data) . ' bytes of Package data' . PHP_EOL;
|
||||
|
||||
$result = import_package($filename, $profile_id, $remove_orphans, $preview_only);
|
||||
$result = import_package($filename, $profile_id, $remove_orphans, $replace_svalues, $preview_only);
|
||||
|
||||
if ($result !== false) {
|
||||
$debug_data = $result[0];
|
||||
@@ -174,7 +179,7 @@ function display_version() {
|
||||
function display_help() {
|
||||
display_version();
|
||||
|
||||
print PHP_EOL . 'usage: import_package.php --filename=[filename] [--only-info] [--remove-orphans] [--with-profile] [--profile-id=N' . PHP_EOL . PHP_EOL;
|
||||
print PHP_EOL . 'usage: import_package.php --filename=[filename] [--only-info] [--remove-orphans] [--replace-svalues] [--with-profile] [--profile-id=N' . PHP_EOL . PHP_EOL;
|
||||
print 'A utility to allow signed Cacti Packages to be imported from the command line.' . PHP_EOL . PHP_EOL;
|
||||
print 'Required:' . PHP_EOL;
|
||||
print ' --filename The name of the gziped package file to import' . PHP_EOL . PHP_EOL;
|
||||
@@ -185,5 +190,10 @@ function display_help() {
|
||||
print ' --profile-id=N Use the specific profile id when importing' . PHP_EOL;
|
||||
print ' --remove-orphans If importing a new version of the template, old' . PHP_EOL;
|
||||
print ' elements will be removed, if they do not exist' . PHP_EOL;
|
||||
print ' in the new version of the template.' . PHP_EOL . PHP_EOL;
|
||||
print ' in the new version of the template.' . PHP_EOL;
|
||||
print ' --replace-svalues If replacing an old version of either a Device' . PHP_EOL;
|
||||
print ' Template with Data Queries or a Data Query, when' . PHP_EOL;
|
||||
print ' you select this option, all Data Query Suggested' . PHP_EOL;
|
||||
print ' Value Patterns will be replaced with that of the' . PHP_EOL;
|
||||
print ' Package Data Queries.' . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
+37
-26
@@ -40,11 +40,12 @@ array_shift($parms);
|
||||
global $preview_only;
|
||||
|
||||
if (cacti_sizeof($parms)) {
|
||||
$filename = '';
|
||||
$with_profile = false;
|
||||
$remove_orphans = false;
|
||||
$preview_only = 0;
|
||||
$profile_id = '';
|
||||
$filename = '';
|
||||
$with_profile = false;
|
||||
$remove_orphans = false;
|
||||
$replace_svalues = false;
|
||||
$preview_only = 0;
|
||||
$profile_id = '';
|
||||
|
||||
foreach($parms as $parameter) {
|
||||
if (strpos($parameter, '=')) {
|
||||
@@ -66,6 +67,10 @@ if (cacti_sizeof($parms)) {
|
||||
case '--remove-orphans':
|
||||
$remove_orphans = true;
|
||||
|
||||
break;
|
||||
case '--replace-svalues':
|
||||
$replace_svalues = true;
|
||||
|
||||
break;
|
||||
case '--preview':
|
||||
$preview_only = 1;
|
||||
@@ -86,19 +91,19 @@ if (cacti_sizeof($parms)) {
|
||||
display_version();
|
||||
exit(0);
|
||||
default:
|
||||
print "ERROR: Invalid Argument: ($arg)\n\n";
|
||||
print 'ERROR: Invalid Argument: ($arg)' . PHP_EOL . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
if($profile_id > 0) {
|
||||
if ($with_profile) {
|
||||
print "WARNING: '--with-profile' and '--profile-id=N' are exclusive. Ignoring '--with-profile'\n";
|
||||
print "WARNING: '--with-profile' and '--profile-id=N' are exclusive. Ignoring '--with-profile'" . PHP_EOL;
|
||||
} else {
|
||||
$id = db_fetch_cell_prepared('SELECT id FROM data_source_profiles WHERE id = ?', array($profile_id));
|
||||
|
||||
if (empty($id)) {
|
||||
print "WARNING: Data Source Profile ID $profile_id not found. Using System Default\n";
|
||||
print "WARNING: Data Source Profile ID $profile_id not found. Using System Default" . PHP_EOL;
|
||||
$id = db_fetch_cell_prepared('SELECT id FROM data_source_profiles ORDER BY `default` DESC LIMIT 1');
|
||||
}
|
||||
}
|
||||
@@ -107,7 +112,7 @@ if (cacti_sizeof($parms)) {
|
||||
}
|
||||
|
||||
if (empty($id)) {
|
||||
print "FATAL: No valid Data Source Profiles found on the system. Exiting!\n";
|
||||
print 'FATAL: No valid Data Source Profiles found on the system. Exiting!' . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -117,22 +122,22 @@ if (cacti_sizeof($parms)) {
|
||||
$xml_data = fread($fp,filesize($filename));
|
||||
fclose($fp);
|
||||
|
||||
print 'Read ' . strlen($xml_data) . " bytes of XML data\n";
|
||||
print 'Read ' . strlen($xml_data) . ' bytes of XML data' . PHP_EOL;
|
||||
|
||||
$debug_data = import_xml_data($xml_data, false, $id, $remove_orphans);
|
||||
$debug_data = import_xml_data($xml_data, false, $id, $remove_orphans, $replace_svalues);
|
||||
|
||||
import_display_results($debug_data, array(), $preview_only);
|
||||
} else {
|
||||
print "ERROR: file $filename is not readable, or does not exist\n\n";
|
||||
print "ERROR: file $filename is not readable, or does not exist" . PHP_EOL . PHP_EOL;
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
print "ERROR: no filename specified\n\n";
|
||||
print 'ERROR: no filename specified' . PHP_EOL . PHP_EOL;
|
||||
display_help();
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
print "ERROR: no parameters given\n\n";
|
||||
print 'ERROR: no parameters given' . PHP_EOL . PHP_EOL;
|
||||
display_help();
|
||||
exit(1);
|
||||
}
|
||||
@@ -140,21 +145,27 @@ if (cacti_sizeof($parms)) {
|
||||
/* display_version - displays version information */
|
||||
function display_version() {
|
||||
$version = get_cacti_cli_version();
|
||||
print "Cacti Import Template Utility, Version $version, " . COPYRIGHT_YEARS . "\n";
|
||||
print "Cacti Import Template Utility, Version $version, " . COPYRIGHT_YEARS . PHP_EOL;
|
||||
}
|
||||
|
||||
function display_help() {
|
||||
display_version();
|
||||
|
||||
print "\nusage: import_template.php --filename=[filename] [--with-profile | --profile-id=N]\n\n";
|
||||
print "A utility to allow Cacti Templates to be imported from the command line.\n\n";
|
||||
print "Required:\n";
|
||||
print " --filename The name of the XML file to import\n\n";
|
||||
print "Optional:\n";
|
||||
print " --preview Preview the Template Import, do not import\n";
|
||||
print " --with-profile Use the default system Data Source Profile\n";
|
||||
print " --profile-id=N Use the specific profile id when importing\n";
|
||||
print " --remove-orphans If importing a new version of the template, old\n";
|
||||
print " elements will be removed, if they do not exist\n";
|
||||
print " in the new version of the template.\n\n";
|
||||
print PHP_EOL;
|
||||
print 'usage: import_template.php --filename=[filename] [--with-profile | --profile-id=N]' . PHP_EOL . PHP_EOL;
|
||||
print 'A utility to allow Cacti Templates to be imported from the command line.' . PHP_EOL . PHP_EOL;
|
||||
print 'Required:' . PHP_EOL;
|
||||
print ' --filename The name of the XML file to import' . PHP_EOL . PHP_EOL;
|
||||
print 'Optional:' . PHP_EOL;
|
||||
print ' --preview Preview the Template Import, do not import' . PHP_EOL;
|
||||
print ' --with-profile Use the default system Data Source Profile' . PHP_EOL;
|
||||
print ' --profile-id=N Use the specific profile id when importing' . PHP_EOL;
|
||||
print ' --remove-orphans If importing a new version of the template, old' . PHP_EOL;
|
||||
print ' elements will be removed, if they do not exist' . PHP_EOL;
|
||||
print ' in the new version of the template.';
|
||||
print ' --replace-svalues If replacing an old version of either a Device' . PHP_EOL;
|
||||
print ' Template with Data Queries or a Data Query, when' . PHP_EOL;
|
||||
print ' you select this option, all Data Query Suggested' . PHP_EOL;
|
||||
print ' Value Patterns will be replaced with that of the' . PHP_EOL;
|
||||
print ' Package Data Queries.' . PHP_EOL . PHP_EOL;
|
||||
}
|
||||
+11
-4
@@ -1676,7 +1676,7 @@ $fields_template_import = array(
|
||||
'description' => __('If the XML file containing template data is located on your local machine, select it here.'),
|
||||
'accept' => '.xml',
|
||||
'method' => 'file'
|
||||
),
|
||||
),
|
||||
'import_text' => array(
|
||||
'method' => 'hidden',
|
||||
'friendly_name' => __('Import Template from Text'),
|
||||
@@ -1686,21 +1686,28 @@ $fields_template_import = array(
|
||||
'textarea_rows' => '10',
|
||||
'textarea_cols' => '50',
|
||||
'class' => 'textAreaNotes'
|
||||
),
|
||||
),
|
||||
'preview_only' => array(
|
||||
'friendly_name' => __('Preview Import Only'),
|
||||
'method' => 'checkbox',
|
||||
'description' => __('If checked, Cacti will not import the template, but rather compare the imported Template to the existing Template data. If you are acceptable of the change, you can them import.'),
|
||||
'value' => '',
|
||||
'default' => 'on'
|
||||
),
|
||||
),
|
||||
'remove_orphans' => array(
|
||||
'friendly_name' => __('Remove Orphaned Graph Items'),
|
||||
'method' => 'checkbox',
|
||||
'description' => __('If checked, Cacti will delete any Graph Items from both the Graph Template and associated Graphs that are not included in the imported Graph Template.'),
|
||||
'value' => '',
|
||||
'default' => ''
|
||||
),
|
||||
),
|
||||
'replace_svalues' => array(
|
||||
'friendly_name' => __('Replace Data Query Suggested Value Patterns'),
|
||||
'method' => 'checkbox',
|
||||
'description' => __('Replace Data Source and Graph Template Suggested Value Records for Data Queries. Graphs and Data Sources will take on new names after either a Data Query Reindex or by using the forced Replace Suggested Values process.'),
|
||||
'value' => '',
|
||||
'default' => ''
|
||||
),
|
||||
'import_data_source_profile' => array(
|
||||
'friendly_name' => __('Data Source Profile'),
|
||||
'method' => 'drop_sql',
|
||||
|
||||
+19
-5
@@ -22,7 +22,7 @@
|
||||
+-------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
function import_xml_data(&$xml_data, $import_as_new, $profile_id, $remove_orphans = false) {
|
||||
function import_xml_data(&$xml_data, $import_as_new, $profile_id, $remove_orphans = false, $replace_svalues = false) {
|
||||
global $config, $hash_type_codes, $cacti_version_codes, $preview_only, $import_debug_info, $legacy_template;
|
||||
|
||||
include_once($config['library_path'] . '/xml.php');
|
||||
@@ -191,7 +191,7 @@ function import_xml_data(&$xml_data, $import_as_new, $profile_id, $remove_orphan
|
||||
$repair++;
|
||||
break;
|
||||
case 'data_query':
|
||||
$hash_cache += xml_to_data_query($dep_hash_cache[$type][$i]['hash'], $hash_array, $hash_cache);
|
||||
$hash_cache += xml_to_data_query($dep_hash_cache[$type][$i]['hash'], $hash_array, $hash_cache, $replace_svalues);
|
||||
break;
|
||||
case 'gprint_preset':
|
||||
$hash_cache += xml_to_gprint_preset($dep_hash_cache[$type][$i]['hash'], $hash_array, $hash_cache);
|
||||
@@ -252,7 +252,7 @@ EOD;
|
||||
return $public_key;
|
||||
}
|
||||
|
||||
function import_package($xmlfile, $profile_id = 1, $remove_orphans = false, $preview = false, $info_only = false, $limitex = true) {
|
||||
function import_package($xmlfile, $profile_id = 1, $remove_orphans = false, $replace_svalues = false, $preview = false, $info_only = false, $limitex = true) {
|
||||
global $config, $preview_only;
|
||||
|
||||
$preview_only = $preview;
|
||||
@@ -380,7 +380,7 @@ function import_package($xmlfile, $profile_id = 1, $remove_orphans = false, $pre
|
||||
} else {
|
||||
cacti_log('Importing XML Data for ' . $name, false, 'IMPORT', POLLER_VERBOSITY_LOW);
|
||||
|
||||
$debug_data = import_xml_data($fdata, false, $profile_id, $remove_orphans, $preview_only);
|
||||
$debug_data = import_xml_data($fdata, false, $profile_id, $remove_orphans, $replace_svalues);
|
||||
|
||||
if ($debug_data === false) {
|
||||
return false;
|
||||
@@ -950,7 +950,7 @@ function xml_to_data_template($hash, &$xml_array, &$hash_cache, $import_as_new,
|
||||
return $hash_cache;
|
||||
}
|
||||
|
||||
function xml_to_data_query($hash, &$xml_array, &$hash_cache) {
|
||||
function xml_to_data_query($hash, &$xml_array, &$hash_cache, $replace_svalues = false) {
|
||||
global $config, $fields_data_query_edit, $fields_data_query_item_edit, $preview_only, $import_debug_info;
|
||||
|
||||
static $counter = 0;
|
||||
@@ -1085,6 +1085,13 @@ function xml_to_data_query($hash, &$xml_array, &$hash_cache) {
|
||||
|
||||
/* import into: snmp_query_graph_sv */
|
||||
if (is_array($item_array['sv_graph'])) {
|
||||
/* if the user choose to replace data query suggested values */
|
||||
if ($data_query_graph_id > 0 && $replace_svalues) {
|
||||
db_execute_prepared('DELETE FROM snmp_query_graph_sv
|
||||
WHERE snmp_query_graph_id = ?',
|
||||
array($data_query_graph_id));
|
||||
}
|
||||
|
||||
foreach ($item_array['sv_graph'] as $sub_item_hash => $sub_item_array) {
|
||||
/* parse information from the hash */
|
||||
$parsed_hash = parse_xml_hash($sub_item_hash);
|
||||
@@ -1130,6 +1137,13 @@ function xml_to_data_query($hash, &$xml_array, &$hash_cache) {
|
||||
|
||||
/* import into: snmp_query_graph_rrd_sv */
|
||||
if (is_array($item_array['sv_data_source'])) {
|
||||
/* if the user choose to replace data query suggested values */
|
||||
if ($data_query_graph_id > 0 && $replace_svalues) {
|
||||
db_execute_prepared('DELETE FROM snmp_query_graph_rrd_sv
|
||||
WHERE snmp_query_graph_id = ?',
|
||||
array($data_query_graph_id));
|
||||
}
|
||||
|
||||
foreach ($item_array['sv_data_source'] as $sub_item_hash => $sub_item_array) {
|
||||
/* parse information from the hash */
|
||||
$parsed_hash = parse_xml_hash($sub_item_hash);
|
||||
|
||||
+1
-1
@@ -2948,7 +2948,7 @@ class Installer implements JsonSerializable {
|
||||
|
||||
if (!empty($package)) {
|
||||
set_config_option('install_updated', microtime(true));
|
||||
$result = import_package($path . $package, $this->profile, false, false, false);
|
||||
$result = import_package($path . $package, $this->profile, false, false, false, false);
|
||||
|
||||
if ($result !== false) {
|
||||
log_install_always('', __('Import of Package #%s \'%s\' under Profile \'%s\' succeeded', $i, $package, $this->profile));
|
||||
|
||||
@@ -93,8 +93,14 @@ function form_save() {
|
||||
$remove_orphans = false;
|
||||
}
|
||||
|
||||
if (isset_request_var('replace_svalues') && get_nfilter_request_var('replace_svalues') == 'on') {
|
||||
$replace_svalues = true;
|
||||
} else {
|
||||
$replace_svalues = false;
|
||||
}
|
||||
|
||||
/* obtain debug information if it's set */
|
||||
$debug_data = import_xml_data($xml_data, $import_as_new, $profile_id, $remove_orphans);
|
||||
$debug_data = import_xml_data($xml_data, $import_as_new, $profile_id, $remove_orphans, $replace_svalues);
|
||||
if ($debug_data !== false && cacti_sizeof($debug_data)) {
|
||||
$_SESSION['import_debug_info'] = $debug_data;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user