diff --git a/CHANGELOG b/CHANGELOG index a161359b6..202c3f136 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -127,6 +127,7 @@ Cacti CHANGELOG -feature#5692: Add a "device enabled/disabled" indicator next to the graphs -feature#5710: Notify the admin periodically when a remote data collector goes into heartbeat status -feature#5716: Add Aruba Clearpass template +-feature#5730: Enable a way to view which Device Templates are using which Graph Templates 1.2.26 -issue#5464: PHP warning when view Data Source Info mode with new Data Source diff --git a/host_templates.php b/host_templates.php index 86f85b561..927c186ba 100644 --- a/host_templates.php +++ b/host_templates.php @@ -265,7 +265,10 @@ function template_item_remove_gt_confirm() { html_start_box('', '100%', '', '3', 'center', ''); - $template = db_fetch_row_prepared('SELECT * FROM graph_templates WHERE id = ?', array(get_request_var('id'))); + $template = db_fetch_row_prepared('SELECT * + FROM graph_templates + WHERE id = ?', + array(get_request_var('id'))); ?> @@ -634,6 +637,11 @@ function template() { 'pageset' => true, 'default' => '' ), + 'graph_template' => array( + 'filter' => FILTER_DEFAULT, + 'pageset' => true, + 'default' => '-1' + ), 'class' => array( 'filter' => FILTER_CALLBACK, 'default' => '-1', @@ -673,103 +681,139 @@ function template() { ?> -
- - - - - - - - - - - -
- - - '> - - - - - - - - - - - > - - - - - ' title=''> - ' title=''> - -
-
+
+ + + + + + + + + + + + + +
+ + + '> + + + + + + + + + + + + + + + > + + + + + ' title=''> + ' title=''> + +
+
@@ -779,13 +823,35 @@ function clearFilter() { /* form the 'where' clause for our main sql query */ $sql_where = ''; + $sql_join = ''; if (get_request_var('filter') != '') { - $sql_where .= 'WHERE (host_template.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')'; + $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . '(ht.name LIKE ' . db_qstr('%' . get_request_var('filter') . '%') . ')'; } if (get_request_var('class') != '-1') { - $sql_where .= 'WHERE (host_template.class = ' . db_qstr(get_request_var('class')) . ')'; + $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . '(ht.class = ' . db_qstr(get_request_var('class')) . ')'; + } + + if (get_request_var('graph_template') != '-1') { + $sql_where .= ($sql_where != '' ? ' AND ':'WHERE ') . '(gt_id = ' . get_request_var('graph_template') . ')'; + $sql_join = "INNER JOIN ( + SELECT DISTINCT host_template_id, id AS gt_id + FROM ( + SELECT htg.host_template_id, gt.id + FROM graph_templates AS gt + INNER JOIN host_template_graph AS htg + ON htg.graph_template_id = gt.id + UNION + SELECT htsq.host_template_id, gt.id + FROM graph_templates AS gt + INNER JOIN snmp_query_graph AS sqg + ON gt.id = sqg.graph_template_id + INNER JOIN host_template_snmp_query AS htsq + ON sqg.snmp_query_id = htsq.snmp_query_id + ) AS rs + ) AS htdata + ON htdata.host_template_id = ht.id"; } if (get_request_var('has_hosts') == 'true') { @@ -794,18 +860,30 @@ function clearFilter() { $sql_having = ''; } - $total_rows = db_fetch_cell("SELECT COUNT(*) - FROM host_template - $sql_where - $sql_having"); + $total_rows = db_fetch_cell("SELECT COUNT(`rows`) + FROM ( + SELECT + COUNT(ht.id) AS `rows`, COUNT(DISTINCT host.id) AS hosts + FROM host_template AS ht + $sql_join + LEFT JOIN host + ON host.host_template_id = ht.id + $sql_where + GROUP BY ht.id + $sql_having + ) AS rs"); $sql_order = get_order_string(); $sql_limit = ' LIMIT ' . ($rows * (get_request_var('page') - 1)) . ',' . $rows; $template_list = db_fetch_assoc("SELECT - host_template.id, host_template.name, host_template.class, devices AS hosts - FROM host_template + ht.id, ht.name, ht.class, COUNT(DISTINCT host.id) AS hosts + FROM host_template AS ht + $sql_join + LEFT JOIN host + ON host.host_template_id=ht.id $sql_where + GROUP BY ht.id $sql_having $sql_order $sql_limit"); @@ -817,13 +895,13 @@ function clearFilter() { 'sort' => 'ASC', 'tip' => __('The name of this Device Template.') ), - 'host_template.class' => array( + 'ht.class' => array( 'display' => __('Device Class'), 'align' => 'left', 'sort' => 'ASC', 'tip' => __('The Class of this Device Template. The Class Name should be representative of it\'s function.') ), - 'host_template.id' => array( + 'ht.id' => array( 'display' => __('ID'), 'align' => 'right', 'sort' => 'ASC',