Skip to content

Commit

Permalink
Fixing #5238 - SQL Issues due to non-visible chars (#5240)
Browse files Browse the repository at this point in the history
Fixing #5238 - SQL Issues due to non-visible chars
Fixing #5232 Poller Stacking
Fixing #5236 - Edit Graph Template
Fixing #5243 - Export columns missing
  • Loading branch information
TheWitness committed Feb 20, 2023
1 parent bf5f5d9 commit f9816fe
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 90 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG
Expand Up @@ -13,7 +13,6 @@ Cacti CHANGELOG
-issue#5147: Error 500 on apache when changing languages
-issue#5150: The Import Package cli script displays the wrong 'info' parameter
-issue#5151: Templates appear to lose their suggested name values
-issue#5155: Local Linux Machine Device Package Damaged
-issue#5159: Cannot turn on publishing when editing
-issue#5160: Translations on debian 'Bullseye' systems may cause server errors
-issue#5161: Switching language in the settings only becomes active after removal of session cookie
Expand Down Expand Up @@ -51,6 +50,10 @@ Cacti CHANGELOG
-issue#5223: Drop callback function sometimes puts name in the form input instead of the id
-issue#5224: When poller run is exceeded by only a short period of time, Cacti does not round the number in the error
-issue#5227: Data Source Debug throws and error when the Debug runs before the RRDfile is created
-issue#5232: On large systems statistics gathering at the beginning of a poller run lead to excessive polling times
-issue#5236: Edit Graph Template link missing base_url
-issue#5238: Searching for Poller Items Generates SQL Errors
-issue#5243: Template Export missing Graph Template columns multiple and test_source

1.2.23
-security#4920: Add .htaccess file to scripts folder
Expand Down
12 changes: 9 additions & 3 deletions include/global_settings.php
Expand Up @@ -1188,7 +1188,6 @@
'default' => 1,
'array' => $poller_options,
),

'poller_sync_interval' => array(
'friendly_name' => __('Poller Sync Interval'),
'description' => __('The default polling sync interval to use when creating a poller. This setting will affect how often remote pollers are checked and updated.'),
Expand Down Expand Up @@ -1238,7 +1237,7 @@
10 => __('%d Seconds', 10),
15 => __('%d Seconds', 15),
20 => __('%d Seconds', 20)
)
)
),
'snmp_bulk_walk_size' => array(
'friendly_name' => __('SNMP Bulkwalk Fetch Size'),
Expand All @@ -1257,7 +1256,8 @@
'90' => '90',
'100' => '100',
'150' => '150',
'200' => '200')
'200' => '200'
)
),
'max_get_size' => array(
'friendly_name' => __('SNMP Get OID Limit'),
Expand All @@ -1267,6 +1267,12 @@
'max_length' => '10',
'size' => '5'
),
'poller_refresh_output_table' => array(
'friendly_name' => __('Refresh Poller Table Per Cycle'),
'description' => __('This setting is for a single poller systems only to rebuild the poller output table on each polling cycle to prevent the memory table from swapping on very large systems with large databases that could use swap.'),
'method' => 'checkbox',
'default' => '',
),
'disable_cache_replication' => array(
'friendly_name' => __('Disable Resource Cache Replication'),
'description' => __('By default, the main Cacti Data Collector will cache the entire web site and plugins into a Resource Cache. Then, periodically the Remote Data Collectors will update themselves with any updates from the main Cacti Data Collector. This Resource Cache essentially allows Remote Data Collectors to self upgrade. If you do not wish to use this option, you can disable it using this setting.'),
Expand Down
9 changes: 7 additions & 2 deletions lib/export.php
Expand Up @@ -31,7 +31,7 @@ function graph_template_to_xml($graph_template_id) {
$hash['graph_template'] = get_hash_version('graph_template') . get_hash_graph_template($graph_template_id);
$xml_text = '';

$graph_template = db_fetch_row_prepared('SELECT id, name
$graph_template = db_fetch_row_prepared('SELECT *
FROM graph_templates
WHERE id = ?',
array($graph_template_id));
Expand Down Expand Up @@ -64,7 +64,12 @@ function graph_template_to_xml($graph_template_id) {
return;
}

$xml_text .= '<hash_' . $hash['graph_template'] . ">\n\t<name>" . xml_character_encode($graph_template['name']) . "</name>\n\t<graph>\n";
$xml_text .= '<hash_' . $hash['graph_template'] . ">\n";
$xml_text .= "\t<name>" . xml_character_encode($graph_template['name']) . "</name>\n";
$xml_text .= "\t<multiple>" . xml_character_encode($graph_template['multiple']) . "</multiple>\n";
$xml_text .= "\t<test_source>" . xml_character_encode($graph_template['test_source']) . "</test_source>\n";

$xml_text .= "\t<graph>\n";

/* XML Branch: <graph> */
foreach ($struct_graph as $field_name => $field_array) {
Expand Down
26 changes: 25 additions & 1 deletion lib/functions.php
Expand Up @@ -1953,17 +1953,20 @@ function prepare_validate_result(&$result) {
/* looking for name value pairs */
if (substr_count($result, ' ') == 0) {
dsv_log('prepare_validate_result', 'data has no spaces');

return true;
} else {
$delim_cnt = 0;

if (substr_count($result, ':')) {
$delim_cnt = substr_count($result, ':');
} elseif (strstr($result, '!')) {
$delim_cnt = substr_count($result, '!');
}

$space_cnt = substr_count(trim($result), ' ');
dsv_log('prepare_validate_result', "data has $space_cnt spaces and $delim_cnt fields which is " . (($space_cnt+1 == $delim_cnt) ? 'NOT ' : '') . ' okay');

dsv_log('prepare_validate_result', "data has $space_cnt spaces and $delim_cnt fields which is " . (($space_cnt + 1 == $delim_cnt) ? '' : 'NOT') . ' okay');

return ($space_cnt+1 == $delim_cnt);
}
Expand All @@ -1972,6 +1975,7 @@ function prepare_validate_result(&$result) {

if ($result === false) {
$result = 'U';

return false;
} else {
return true;
Expand Down Expand Up @@ -2060,6 +2064,7 @@ function test_data_sources($graph_template_id, $host_id, $snmp_query_id = 0, $sn
if (cacti_sizeof($data_template_ids) && $test_source == 'on') {
foreach($data_template_ids as $dt) {
dsv_log("test_data_source", [ 'dt' => $dt, 'host_id' => $host_id, 'snmp_query_id' => $snmp_query_id, 'snmp_index' => $snmp_index, 'values' => $values]);

if (!test_data_source($dt, $host_id, $snmp_query_id, $snmp_index, $values)) {
return false;
}
Expand Down Expand Up @@ -2087,6 +2092,7 @@ function test_data_source($data_template_id, $host_id, $snmp_query_id = 0, $snmp
$called_by_script_server = true;

dsv_log('test_data_source', [ 'data_template_id' => $data_template_id, 'host_id' => $host_id, 'snmp_query_id' => $snmp_query_id, 'snmp_index' => $snmp_index, 'suggested_vals' => $suggested_vals]);

$data_input = db_fetch_row_prepared('SELECT ' . SQL_NO_CACHE . '
di.id, di.type_id, dtd.id AS data_template_data_id,
dtd.data_template_id, dtd.active, dtd.rrd_step, di.name
Expand Down Expand Up @@ -2155,16 +2161,19 @@ function test_data_source($data_template_id, $host_id, $snmp_query_id = 0, $snmp
}

$script_path = get_full_test_script_path($data_template_id, $host_id);

dsv_log('script_path', $script_path);

$num_output_fields_sql = 'SELECT ' . SQL_NO_CACHE . ' id
FROM data_input_fields
WHERE data_input_id = ?
AND input_output = "out"
AND update_rra="on"';

dsv_log('num_output_fields_sql',$num_output_fields_sql);

$num_output_fields = cacti_sizeof(db_fetch_assoc_prepared($num_output_fields_sql, array($data_input['id'])));

dsv_log('num_output_fields', $num_output_fields);

if ($num_output_fields == 1) {
Expand All @@ -2181,22 +2190,27 @@ function test_data_source($data_template_id, $host_id, $snmp_query_id = 0, $snmp
}

dsv_log('data_source_item_name', $data_source_item_name);

if ($action == POLLER_ACTION_SCRIPT) {
dsv_log('script_path', $script_path);

$output = shell_exec($script_path);
} else {
// Script server is a bit more complicated
$php = read_config_option('path_php_binary');
$parts = explode(' ', $script_path);

dsv_log('parts', $parts);

if (file_exists($parts[0])) {
unset($parts[1]);

$script = implode(' ', $parts);

dsv_log('script', $script);

$output = shell_exec("$php -q $script");

if ($output == '' || $output == false) {
$output = 'U';
}
Expand All @@ -2206,9 +2220,12 @@ function test_data_source($data_template_id, $host_id, $snmp_query_id = 0, $snmp
}

dsv_log('output', $output);

if (!is_numeric($output)) {
if ($output == 'U') {
return false;
} elseif (strpos($output, ':U') !== false) {
return false;
} elseif (prepare_validate_result($output) === false) {
return false;
}
Expand All @@ -2224,6 +2241,7 @@ function test_data_source($data_template_id, $host_id, $snmp_query_id = 0, $snmp
WHERE (type_code LIKE "snmp_%" OR type_code IN("hostname","host_id"))
AND did.data_template_data_id = ?
AND did.value != ""';

dsv_log('host_fields_sql',$host_fields_sql);
dsv_log('host_fields_sql_params', ['data_template_data_id' => $data_template_data_id]);

Expand All @@ -2244,25 +2262,31 @@ function test_data_source($data_template_id, $host_id, $snmp_query_id = 0, $snmp
array($data_template_data_id));

dsv_log('SNMP data_template_data', $data_template_data);

if (cacti_sizeof($data_template_data)) {
foreach ($data_template_data as $field) {
$key = $field['type_code'];
$value = $field['value'];

dsv_log('SNMP field', $field);
//dsv_log('SNMP suggested_val', $suggested_vals['custom_data'][$data_template_id]);

if (!empty($suggested_vals['custom_data'][$data_template_id][$field['id']])) {
$value = $suggested_vals['custom_data'][$data_template_id][$field['id']];

dsv_log("SNMP value replace suggested $key", $value);
}

if (!empty($value) && !isset($host_fields[$key])) {
$host_fields[$key] = $value;

dsv_log("SNMP value replace template $key", $value);
}
}
}

dsv_log('SNMP [updated] host_fields', $host_fields);

$host = array_merge($host, $host_fields);

dsv_log('SNMP [updated] host', $host);
Expand Down
2 changes: 1 addition & 1 deletion lib/html.php
Expand Up @@ -502,7 +502,7 @@ function graph_drilldown_icons($local_graph_id, $type = 'graph_buttons', $tree_i
}

if (is_realm_allowed(10) && $graph_template_id > 0) {
print "<a class='iconLink' role='link' title='" . __esc('Edit Graph Template') . "' href='" . html_escape($config['url_path'] . '/graph_templates.php?action=template_edit&id=' . $graph_template_id) . "'><img src='" . html_escape($config['url_path'] . 'images/template_edit.png') . "'></img></a>";
print "<a class='iconLink' role='link' title='" . __esc('Edit Graph Template') . "' href='" . html_escape($config['url_path'] . 'graph_templates.php?action=template_edit&id=' . $graph_template_id) . "'><img src='" . html_escape($config['url_path'] . 'images/template_edit.png') . "'></img></a>";
print '<br/>';
}

Expand Down

0 comments on commit f9816fe

Please sign in to comment.