From 63e654ab4bcfe28676f120e8f3edb5429cbea3f3 Mon Sep 17 00:00:00 2001 From: TheWitness Date: Tue, 20 Jun 2023 20:34:59 -0400 Subject: [PATCH] Fixing #5384 - Untemplated Data Source Issue * Untemplated Data Sources can fail to update due to lack of an assigned Graph * Related to #5336. We missed the case of the untemplated data source when we fixed this, and another issue in release 1.2.24. This will allow objects such as RTM's ELIM Templates to properly create RRDfiles and operate as it does today. --- CHANGELOG | 1 + lib/boost.php | 214 +++++++++++++++++++++++++++++++---------------- lib/poller.php | 136 +++++++++++++++++++----------- lib/rrd.php | 87 ++++++++++++------- poller_boost.php | 125 +++++++++++++++++---------- 5 files changed, 370 insertions(+), 193 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 298195abcd..b6c74a8063 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -43,6 +43,7 @@ Cacti CHANGELOG -issue#5377: When attempting to edit a tree, the search filter for Graphs remains disabled -issue#5381: Once a Data Source is orphaned there are cases where it will not become un-orphaned upon reindex -issue#5382: Splice rrd could in some cases incorrectly detect the date and cause php errors +-issue#5384: Untemplated Data Sources can fail to update due to lack of an assigned Graph -feature#5375: Add template for Fortinet firewall and Aruba Instant cluster -feature: Upgrade billboard.js to version 3.7.4 -feature: Upgrade d3.js to version 7.8.2 diff --git a/lib/boost.php b/lib/boost.php index a920abc28f..c1fd6f5295 100644 --- a/lib/boost.php +++ b/lib/boost.php @@ -738,12 +738,14 @@ function boost_process_poller_output($local_data_id, $rrdtool_pipe = '') { $arch_results = cacti_sizeof($results); - $tresults = db_fetch_assoc_prepared("SELECT local_data_id, - UNIX_TIMESTAMP(time) AS timestamp, rrd_name, output - FROM poller_output_boost - WHERE local_data_id = ? - AND time < FROM_UNIXTIME(?) - ORDER BY time, rrd_name", + $tresults = db_fetch_assoc_prepared("SELECT po.local_data_id, dl.data_template_id, + UNIX_TIMESTAMP(po.time) AS timestamp, po.rrd_name, po.output + FROM poller_output_boost AS po + INNER JOIN data_local AS dl + ON po.local_data_id = dl.id + WHERE po.local_data_id = ? + AND po.time < FROM_UNIXTIME(?) + ORDER BY po.time, po.rrd_name", array($local_data_id, $timestamp)); $boost_results = cacti_sizeof($tresults); @@ -906,27 +908,47 @@ function boost_process_poller_output($local_data_id, $rrdtool_pipe = '') { $values = preg_split('/\s+/', $value); if (!$multi_vals_set) { - $rrd_field_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name - FROM graph_templates_item AS gti - INNER JOIN data_template_rrd AS dtr - ON gti.task_item_id = dtr.id - INNER JOIN data_input_fields AS dif - ON dtr.data_input_field_id = dif.id - WHERE dtr.local_data_id = ?', - array($item['local_data_id'])), - 'data_name', 'data_source_name' - ); - - $unused_data_source_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name - FROM data_template_rrd AS dtr - LEFT JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', - array($item['local_data_id'])), - 'data_source_name', 'data_source_name' - ); + if ($item['data_template_id'] > 0) { + $rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM graph_templates_item AS gti + INNER JOIN data_template_rrd AS dtr + ON gti.task_item_id = dtr.id + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id = dif.id + WHERE dtr.local_data_id = ?', + array($item['local_data_id'])), + 'data_name', 'data_source_name' + ); + + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + LEFT JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', + array($item['local_data_id'])), + 'data_source_name', 'data_source_name' + ); + } else { + $rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM data_template_rrd AS dtr + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id = dif.id + WHERE dtr.local_data_id = ?', + array($item['local_data_id'])), + 'data_name', 'data_source_name' + ); + + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', + array($item['local_data_id'])), + 'data_source_name', 'data_source_name' + ); + } $rrd_tmpl = ''; } @@ -982,29 +1004,48 @@ function boost_process_poller_output($local_data_id, $rrdtool_pipe = '') { $vals_in_buffer++; } } else { - if (!$multi_vals_set) { - $rrd_field_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name - FROM graph_templates_item AS gti - INNER JOIN data_template_rrd AS dtr - ON gti.task_item_id = dtr.id - INNER JOIN data_input_fields AS dif - ON dtr.data_input_field_id = dif.id - WHERE dtr.local_data_id = ?', - array($item['local_data_id'])), - 'data_name', 'data_source_name' - ); - - $unused_data_source_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name - FROM data_template_rrd AS dtr - LEFT JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', - array($item['local_data_id'])), - 'data_source_name', 'data_source_name' - ); + if ($item['data_template_id'] > 0) { + $rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM graph_templates_item AS gti + INNER JOIN data_template_rrd AS dtr + ON gti.task_item_id = dtr.id + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id = dif.id + WHERE dtr.local_data_id = ?', + array($item['local_data_id'])), + 'data_name', 'data_source_name' + ); + + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + LEFT JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', + array($item['local_data_id'])), + 'data_source_name', 'data_source_name' + ); + } else { + $rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM data_template_rrd AS dtr + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id = dif.id + WHERE dtr.local_data_id = ?', + array($item['local_data_id'])), + 'data_name', 'data_source_name' + ); + + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', + array($item['local_data_id'])), + 'data_source_name', 'data_source_name' + ); + } $rrd_tmpl = ''; } @@ -1130,17 +1171,33 @@ function boost_get_rrd_filename_and_template($local_data_id) { $ds_null = array(); $ds_nnull = array(); - $ds_names = db_fetch_assoc_prepared("SELECT DISTINCT data_source_name, rrd_name, rrd_path - FROM data_template_rrd AS dtr - INNER JOIN graph_templates_item AS gti - ON gti.task_item_id = dtr.id - INNER JOIN poller_item AS pi - ON pi.local_data_id = dtr.local_data_id - AND (pi.rrd_name = dtr.data_source_name OR pi.rrd_name = '') - WHERE dtr.local_data_id = ? - ORDER BY data_source_name ASC", + $data_template_id = db_fetch_cell_prepared('SELECT data_template_id + FROM data_local + WHERE id = ?', array($local_data_id)); + if ($data_template_id > 0) { + $ds_names = db_fetch_assoc_prepared("SELECT DISTINCT data_source_name, rrd_name, rrd_path + FROM data_template_rrd AS dtr + INNER JOIN graph_templates_item AS gti + ON gti.task_item_id = dtr.id + INNER JOIN poller_item AS pi + ON pi.local_data_id = dtr.local_data_id + AND (pi.rrd_name = dtr.data_source_name OR pi.rrd_name = '') + WHERE dtr.local_data_id = ? + ORDER BY data_source_name ASC", + array($local_data_id)); + } else { + $ds_names = db_fetch_assoc_prepared("SELECT DISTINCT data_source_name, rrd_name, rrd_path + FROM data_template_rrd AS dtr + INNER JOIN poller_item AS pi + ON pi.local_data_id = dtr.local_data_id + AND (pi.rrd_name = dtr.data_source_name OR pi.rrd_name = '') + WHERE dtr.local_data_id = ? + ORDER BY data_source_name ASC", + array($local_data_id)); + } + if (cacti_sizeof($ds_names)) { foreach($ds_names as $ds_name) { if ($rrd_path == '') { @@ -1225,19 +1282,32 @@ function boost_rrdtool_function_create($local_data_id, $show_source, &$rrdtool_p $create_ds = RRD_NL . '--start 0 --step '. $rras[0]['rrd_step'] . ' ' . RRD_NL; /** - * Only use the Data Sources that are included in the Graph in the case that there - * is a Data Template that includes more Data Sources than there Graph Template - * uses. - */ - $data_sources = db_fetch_assoc_prepared('SELECT DISTINCT dtr.id, dtr.data_source_name, dtr.rrd_heartbeat, - dtr.rrd_minimum, dtr.rrd_maximum, dtr.data_source_type_id - FROM data_template_rrd AS dtr - INNER JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE dtr.local_data_id = ? - ORDER BY local_data_template_rrd_id', + * We have to check for Non-Templated Data Source first as they may not include + * a graph. So, for that case, we need the RRDfile to include all data sources + */ + $data_template_id = db_fetch_cell_prepared('SELECT data_template_id + FROM data_local + WHERE id = ?', array($local_data_id)); + if ($data_template_id > 0) { + $data_sources = db_fetch_assoc_prepared('SELECT DISTINCT dtr.id, dtr.data_source_name, dtr.rrd_heartbeat, + dtr.rrd_minimum, dtr.rrd_maximum, dtr.data_source_type_id + FROM data_template_rrd AS dtr + INNER JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE dtr.local_data_id = ? + ORDER BY local_data_template_rrd_id', + array($local_data_id)); + } else { + $data_sources = db_fetch_assoc_prepared('SELECT DISTINCT dtr.id, dtr.data_source_name, dtr.rrd_heartbeat, + dtr.rrd_minimum, dtr.rrd_maximum, dtr.data_source_type_id + FROM data_template_rrd AS dtr + WHERE dtr.local_data_id = ? + ORDER BY local_data_template_rrd_id', + array($local_data_id)); + } + /** * ONLY make a new DS entry if: * @@ -1359,6 +1429,8 @@ function boost_rrdtool_function_create($local_data_id, $show_source, &$rrdtool_p @arg $rrd_update_template - the order in which values need to be added @arg $rrd_update_values - values to include in the database */ function boost_rrdtool_function_update($local_data_id, $rrd_path, $rrd_update_template, &$rrd_update_values, &$rrdtool_pipe) { + global $debug; + /* lets count the number of rrd files processed */ $rrds_processed = 0; @@ -1399,11 +1471,11 @@ function boost_rrdtool_function_update($local_data_id, $rrd_path, $rrd_update_te if ($valid_entry) { if ($rrd_update_template != '') { - cacti_log("update $rrd_path $update_options --template $rrd_update_template $rrd_update_values", true, 'DEBUG'); + cacti_log("update $rrd_path $update_options --template $rrd_update_template $rrd_update_values", true, 'BOOST', ($debug ? POLLER_VERBOSITY_NONE:POLLER_VERBOSITY_HIGH)); rrdtool_execute("update $rrd_path $update_options --template $rrd_update_template $rrd_update_values", false, RRDTOOL_OUTPUT_STDOUT, $rrdtool_pipe, 'BOOST'); } else { - cacti_log("update $rrd_path $update_options $rrd_update_values", true, 'DEBUG'); + cacti_log("update $rrd_path $update_options $rrd_update_values", true, 'BOOST', ($debug ? POLLER_VERBOSITY_NONE:POLLER_VERBOSITY_HIGH)); rrdtool_execute("update $rrd_path $update_options $rrd_update_values", false, RRDTOOL_OUTPUT_STDOUT, $rrdtool_pipe, 'BOOST'); } diff --git a/lib/poller.php b/lib/poller.php index ec46f7f37f..425ccba3ba 100644 --- a/lib/poller.php +++ b/lib/poller.php @@ -568,12 +568,13 @@ function process_poller_output(&$rrdtool_pipe, $remainder = 0) { /* create an array keyed off of each .rrd file */ foreach ($results as $item) { /* trim the default characters, but add single and double quotes */ - $value = $item['output']; - $unix_time = $item['unix_time']; - $rrd_path = $item['rrd_path']; - $rrd_name = $item['rrd_name']; - $local_data_id = $item['local_data_id']; - $rrd_tmpl = ''; + $value = $item['output']; + $unix_time = $item['unix_time']; + $rrd_path = $item['rrd_path']; + $rrd_name = $item['rrd_name']; + $local_data_id = $item['local_data_id']; + $data_template_id = $item['data_template_id']; + $rrd_tmpl = ''; $rrd_update_array[$rrd_path]['local_data_id'] = $local_data_id; @@ -605,16 +606,20 @@ function process_poller_output(&$rrdtool_pipe, $remainder = 0) { /* multiple value output */ $values = preg_split('/\s+/', $value); - $unused_data_source_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name - FROM data_template_rrd AS dtr - LEFT JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE dtr.local_data_id = ? - AND gti.task_item_id IS NULL', - array($local_data_id)), - 'data_source_name', 'data_source_name' - ); + if ($data_template_id > 0) { + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + LEFT JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE dtr.local_data_id = ? + AND gti.task_item_id IS NULL', + array($local_data_id)), + 'data_source_name', 'data_source_name' + ); + } else { + $unused_data_source_names = array(); + } foreach($values as $value) { $matches = explode(':', $value); @@ -644,17 +649,29 @@ function process_poller_output(&$rrdtool_pipe, $remainder = 0) { $rrd_update_array[$rrd_path]['template'] = $rrd_tmpl; } else { // Handle data source without a data template - $nt_rrd_field_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name - FROM graph_templates_item AS gti - INNER JOIN data_template_rrd AS dtr - ON gti.task_item_id = dtr.id - INNER JOIN data_input_fields AS dif - ON dtr.data_input_field_id = dif.id - WHERE dtr.local_data_id = ?', - array($local_data_id)), - 'data_name', 'data_source_name' - ); + if ($data_template_id > 0) { + $nt_rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM graph_templates_item AS gti + INNER JOIN data_template_rrd AS dtr + ON gti.task_item_id = dtr.id + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id = dif.id + WHERE dtr.local_data_id = ?', + array($local_data_id)), + 'data_name', 'data_source_name' + ); + } else { + $nt_rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM data_template_rrd AS dtr + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id = dif.id + WHERE dtr.local_data_id = ?', + array($local_data_id)), + 'data_name', 'data_source_name' + ); + } if (cacti_sizeof($nt_rrd_field_names)) { if (isset($nt_rrd_field_names[$matches[0]])) { @@ -683,28 +700,49 @@ function process_poller_output(&$rrdtool_pipe, $remainder = 0) { } } } else { - $unused_data_source_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name - FROM data_template_rrd AS dtr - LEFT JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE dtr.local_data_id = ? - AND gti.task_item_id IS NULL', - array($local_data_id)), - 'data_source_name', 'data_source_name' - ); - - $nt_rrd_field_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name - FROM graph_templates_item AS gti - INNER JOIN data_template_rrd AS dtr - ON gti.task_item_id = dtr.id - INNER JOIN data_input_fields AS dif - ON dtr.data_input_field_id = dif.id - WHERE dtr.local_data_id = ?', - array($local_data_id)), - 'data_name', 'data_source_name' - ); + if ($data_template_id > 0) { + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + LEFT JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE dtr.local_data_id = ? + AND gti.task_item_id IS NULL', + array($local_data_id)), + 'data_source_name', 'data_source_name' + ); + + $nt_rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM graph_templates_item AS gti + INNER JOIN data_template_rrd AS dtr + ON gti.task_item_id = dtr.id + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id = dif.id + WHERE dtr.local_data_id = ?', + array($local_data_id)), + 'data_name', 'data_source_name' + ); + } else { + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + WHERE dtr.local_data_id = ? + AND gti.task_item_id IS NULL', + array($local_data_id)), + 'data_source_name', 'data_source_name' + ); + + $nt_rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM data_template_rrd AS dtr + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id = dif.id + WHERE dtr.local_data_id = ?', + array($local_data_id)), + 'data_name', 'data_source_name' + ); + } $expected = ''; diff --git a/lib/rrd.php b/lib/rrd.php index 90f13fa467..85b084dcf5 100644 --- a/lib/rrd.php +++ b/lib/rrd.php @@ -633,19 +633,33 @@ function rrdtool_function_create($local_data_id, $show_source, $rrdtool_pipe = f $create_ds = RRD_NL . '--start 0 --step '. $rras[0]['rrd_step'] . ' ' . RRD_NL; /** - * Only use the Data Sources that are included in the Graph in the case that there - * is a Data Template that includes more Data Sources than there Graph Template - * uses. + * We have to check for Non-Templated Data Source first as they may not include + * a graph. So, for that case, we need the RRDfile to include all data sources */ - $data_sources = db_fetch_assoc_prepared('SELECT DISTINCT dtr.id, dtr.data_source_name, dtr.rrd_heartbeat, - dtr.rrd_minimum, dtr.rrd_maximum, dtr.data_source_type_id - FROM data_template_rrd AS dtr - INNER JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE local_data_id = ? - ORDER BY local_data_template_rrd_id', - array($local_data_id) - ); + $data_template_id = db_fetch_cell_prepared('SELECT data_template_id + FROM data_local + WHERE id = ?', + array($local_data_id)); + + if ($data_template_id > 0) { + $data_sources = db_fetch_assoc_prepared('SELECT DISTINCT dtr.id, dtr.data_source_name, dtr.rrd_heartbeat, + dtr.rrd_minimum, dtr.rrd_maximum, dtr.data_source_type_id + FROM data_template_rrd AS dtr + INNER JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE local_data_id = ? + ORDER BY local_data_template_rrd_id', + array($local_data_id) + ); + } else { + $data_sources = db_fetch_assoc_prepared('SELECT DISTINCT dtr.id, dtr.data_source_name, dtr.rrd_heartbeat, + dtr.rrd_minimum, dtr.rrd_maximum, dtr.data_source_type_id + FROM data_template_rrd AS dtr + WHERE local_data_id = ? + ORDER BY local_data_template_rrd_id', + array($local_data_id) + ); + } /** * ONLY make a new DS entry if: @@ -797,15 +811,19 @@ function rrdtool_function_update($update_cache_array, $rrdtool_pipe = false) { $create_rrd_file = true; } - $unused_data_source_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name - FROM data_template_rrd AS dtr - LEFT JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', - array($rrd_fields['local_data_id'])), - 'data_source_name', 'data_source_name' - ); + if ($rrd_fields['data_template_id'] > 0) { + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + LEFT JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', + array($rrd_fields['local_data_id'])), + 'data_source_name', 'data_source_name' + ); + } else { + $unused_data_source_names = array(); + } foreach ($rrd_fields['times'] as $update_time => $field_array) { if (empty($update_time)) { @@ -2739,15 +2757,28 @@ function rrdtool_function_info_from_ds($data_source_id) { WHERE local_data_id = ?', array($data_source_id)); - /* get cacti DS information */ - $cacti_ds_array = db_fetch_assoc_prepared('SELECT DISTINCT dtr.id, dtr.data_source_name, dtr.data_source_type_id, - dtr.rrd_heartbeat, dtr.rrd_maximum, dtr.rrd_minimum - FROM data_template_rrd AS dtr - INNER JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE local_data_id = ?', + $data_template_id = db_fetch_cell_prepared('SELECT data_template_id + FROM data_local + WHERE id = ?', array($data_source_id)); + /* get cacti DS information */ + if ($data_template_id > 0) { + $cacti_ds_array = db_fetch_assoc_prepared('SELECT DISTINCT dtr.id, dtr.data_source_name, dtr.data_source_type_id, + dtr.rrd_heartbeat, dtr.rrd_maximum, dtr.rrd_minimum + FROM data_template_rrd AS dtr + INNER JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE local_data_id = ?', + array($data_source_id)); + } else { + $cacti_ds_array = db_fetch_assoc_prepared('SELECT DISTINCT dtr.id, dtr.data_source_name, dtr.data_source_type_id, + dtr.rrd_heartbeat, dtr.rrd_maximum, dtr.rrd_minimum + FROM data_template_rrd AS dtr + WHERE local_data_id = ?', + array($data_source_id)); + } + if (cacti_sizeof($cacti_header_array) && cacti_sizeof($cacti_ds_array)) { $info_array['step'] = $cacti_header_array['rrd_step']; diff --git a/poller_boost.php b/poller_boost.php index 877aa5d5d8..790a22b082 100755 --- a/poller_boost.php +++ b/poller_boost.php @@ -911,15 +911,19 @@ function boost_process_local_data_ids($last_id, $child, $rrdtool_pipe) { if (!$reset_template) { $rrd_tmpl = ''; } else { - $unused_data_source_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name - FROM data_template_rrd AS dtr - LEFT JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', - array($item['local_data_id'])), - 'data_source_name', 'data_source_name' - ); + if ($item['data_template_id'] > 0) { + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + LEFT JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', + array($item['local_data_id'])), + 'data_source_name', 'data_source_name' + ); + } else { + $unused_data_source_names = array(); + } } foreach($values as $value) { @@ -958,21 +962,32 @@ function boost_process_local_data_ids($last_id, $child, $rrdtool_pipe) { $vals_in_buffer++; } else { /** - * Handle data source without a data template - * This section of the code should not be reached - * if there is no issue in the database. + * We have to check for Non-Templated Data Source first as they may not include + * a graph. So, for that case, we need the RRDfile to include all data sources */ - $nt_rrd_field_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name - FROM graph_templates_item AS gti - INNER JOIN data_template_rrd AS dtr - ON gti.task_item_id = dtr.id - INNER JOIN data_input_fields AS dif - ON dtr.data_input_field_id=dif.id - WHERE dtr.local_data_id = ?', - array($item['local_data_id'])), - 'data_name', 'data_source_name' - ); + if ($item['data_template_id'] > 0) { + $nt_rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM graph_templates_item AS gti + INNER JOIN data_template_rrd AS dtr + ON gti.task_item_id = dtr.id + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id=dif.id + WHERE dtr.local_data_id = ?', + array($item['local_data_id'])), + 'data_name', 'data_source_name' + ); + } else { + $nt_rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM data_template_rrd AS dtr + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id=dif.id + WHERE dtr.local_data_id = ?', + array($item['local_data_id'])), + 'data_name', 'data_source_name' + ); + } if (cacti_sizeof($nt_rrd_field_names)) { if (isset($nt_rrd_field_names[$matches[0]])) { @@ -983,7 +998,7 @@ function boost_process_local_data_ids($last_id, $child, $rrdtool_pipe) { } if ($reset_template) { - cacti_log("Parsed MULTI output field in path 2 '" . $matches[0] . ':' . $matches[1] . "' [map " . $matches[0] . '->' . $field . ']', false, 'BOOOST', ($debug ? POLLER_VERBOSITY_NONE:POLLER_VERBOSITY_HIGH)); + cacti_log("Parsed MULTI output field in path 2 '" . $matches[0] . ':' . $matches[1] . "' [map " . $matches[0] . '->' . $field . ']', false, 'BOOST', ($debug ? POLLER_VERBOSITY_NONE:POLLER_VERBOSITY_HIGH)); if (trim(read_config_option('path_boost_log')) != '') { print "DEBUG: Parsed MULTI output field '" . $matches[0] . "' [map " . $matches[1] . '->' . $field . ']' . PHP_EOL; @@ -1016,27 +1031,47 @@ function boost_process_local_data_ids($last_id, $child, $rrdtool_pipe) { } } else { if ($reset_template) { - $unused_data_source_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name - FROM data_template_rrd AS dtr - LEFT JOIN graph_templates_item AS gti - ON dtr.id = gti.task_item_id - WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', - array($item['local_data_id'])), - 'data_source_name', 'data_source_name' - ); - - $nt_rrd_field_names = array_rekey( - db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name - FROM graph_templates_item AS gti - INNER JOIN data_template_rrd AS dtr - ON gti.task_item_id = dtr.id - INNER JOIN data_input_fields AS dif - ON dtr.data_input_field_id=dif.id - WHERE dtr.local_data_id = ?', - array($item['local_data_id'])), - 'data_name', 'data_source_name' - ); + if ($item['data_template_id'] > 0) { + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + LEFT JOIN graph_templates_item AS gti + ON dtr.id = gti.task_item_id + WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', + array($item['local_data_id'])), + 'data_source_name', 'data_source_name' + ); + + $nt_rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM graph_templates_item AS gti + INNER JOIN data_template_rrd AS dtr + ON gti.task_item_id = dtr.id + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id=dif.id + WHERE dtr.local_data_id = ?', + array($item['local_data_id'])), + 'data_name', 'data_source_name' + ); + } else { + $unused_data_source_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dtr.data_source_name + FROM data_template_rrd AS dtr + WHERE dtr.local_data_id = ? AND gti.task_item_id IS NULL', + array($item['local_data_id'])), + 'data_source_name', 'data_source_name' + ); + + $nt_rrd_field_names = array_rekey( + db_fetch_assoc_prepared('SELECT DISTINCT dtr.data_source_name, dif.data_name + FROM data_template_rrd AS dtr + INNER JOIN data_input_fields AS dif + ON dtr.data_input_field_id=dif.id + WHERE dtr.local_data_id = ?', + array($item['local_data_id'])), + 'data_name', 'data_source_name' + ); + } } $expected = '';