diff --git a/CHANGELOG b/CHANGELOG index 845145a488..555b7b8dbe 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -6,6 +6,7 @@ Cacti CHANGELOG -issue#4455: When updating poller name, matches may be too wide in scope -issue#4458: MIB Cache column check causes poller crash under PHP 8.x -issue#4461: When viewing graph data, non-numeric values may appear +-issue#4457: Titles may show "Missing Datasource" incorectly 1.2.19 -security#4356: Further fixes for grave character security protection diff --git a/lib/functions.php b/lib/functions.php index d9ba0c8a0f..7c1bad3d05 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -2433,23 +2433,33 @@ function clean_up_path($path) { * @return - the data source title */ function get_data_source_title($local_data_id) { - $data = db_fetch_row_prepared('SELECT dl.host_id, dl.snmp_query_id, dl.snmp_index, dtd.name + $data = db_fetch_row_prepared('SELECT + dl.host_id, dl.snmp_query_id, dl.snmp_index, dl.data_template_id, + dtd.name, dtd.id as template_id FROM data_local AS dl - INNER JOIN data_template_data AS dtd + LEFT JOIN data_template_data AS dtd ON dtd.local_data_id = dl.id WHERE dl.id = ?', array($local_data_id)); + $title = 'Missing Datasource ' . $local_data_id; if (cacti_sizeof($data)) { if (strstr($data['name'], '|') !== false && $data['host_id'] > 0) { $data['name'] = substitute_data_input_data($data['name'], '', $local_data_id); - return expand_title($data['host_id'], $data['snmp_query_id'], $data['snmp_index'], $data['name']); + $title = expand_title($data['host_id'], $data['snmp_query_id'], $data['snmp_index'], $data['name']); } else { - return $data['name']; + $title = $data['name']; + } + + // Is the data source linked to a template? If so, make sure we have a template on the + // LEFT JOIN since it may not find one. Also, we can't check that they are the same ID + // ID yet because there are two, one with a 0 local_data_id (base template) and one with + // this source's id (instance of template). + if ($data['data_template_id'] && !$data['template_id']) { + $title .= ' (Bad template "' . $data['data_template_id'] . '")'; } - } else { - return 'Missing Datasource ' . $local_data_id; } + return $title; } /**