Skip to content

Commit

Permalink
Fixing #5828 - Add Location and Site to Graph List View
Browse files Browse the repository at this point in the history
* Add Location and Site to Graph List View
  • Loading branch information
TheWitness committed Sep 18, 2024
1 parent 41116e2 commit b6fa403
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Cacti CHANGELOG
-feature#5796: Due to Conflicting Interpretations of TCP Ping, Introduce new Ping Method
-feature#5819: Be more precise on the Graph End time when an end time is not provided
-feature#5825: Allow remove_device.php to use a list of device id's
-feature#5828: Add Location and Site to Graph List View
-feature: Update jQuery to 3.7.1
-feature: Update jQueryUI to 1.14.0
-feature: Update billboard.js to 3.13.0
Expand Down
52 changes: 44 additions & 8 deletions graph_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -525,38 +525,49 @@ function get_matching_nodes() {
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
),
'page' => array(
'filter' => FILTER_VALIDATE_INT,
'default' => '1'
),
),
'rfilter' => array(
'filter' => FILTER_VALIDATE_IS_REGEX,
'pageset' => true,
'default' => '',
),
),
'graph_template_id' => array(
'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST,
'pageset' => true,
'default' => '-1'
),
),
'site_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
'host_id' => array(
'filter' => FILTER_VALIDATE_INT,
'pageset' => true,
'default' => '-1'
),
),
'location' => array(
'filter' => FILTER_CALLBACK,
'pageset' => true,
'default' => '-1',
'options' => array('options' => 'sanitize_search_string')
),
'graph_add' => array(
'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST,
'default' => ''
),
),
'graph_list' => array(
'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST,
'default' => ''
),
),
'graph_remove' => array(
'filter' => FILTER_VALIDATE_IS_NUMERIC_LIST,
'default' => ''
)
)
);

validate_store_request_vars($filters, 'sess_gl');
Expand Down Expand Up @@ -638,6 +649,17 @@ function get_matching_nodes() {
</table>
<table class='filterTable'>
<tr>
<?php html_site_filter(get_request_var('site_id'));?>
<?php

if (get_request_var('site_id') >= 0) {
$loc_where = 'WHERE site_id = ' . db_qstr(get_request_var('site_id'));
} else {
$loc_where = '';
}

html_location_filter(get_request_var('location'), 'applyFilter', $loc_where);
?>
<td>
<?php print __('Template');?>
</td>
Expand Down Expand Up @@ -709,12 +731,24 @@ function get_matching_nodes() {
$sql_where .= " gtg.title_cache RLIKE '" . get_request_var('rfilter') . "'";
}

if (!isempty_request_var('site_id') && get_request_var('site_id') > 0) {
$sql_where .= ($sql_where == '' ? '' : ' AND') . ' h.site_id=' . get_request_var('site_id');
} elseif (isempty_request_var('site_id')) {
$sql_where .= ($sql_where == '' ? '' : ' AND') . ' h.site_id=0';
}

if (!isempty_request_var('host_id') && get_request_var('host_id') > 0) {
$sql_where .= ($sql_where == '' ? '' : ' AND') . ' gl.host_id=' . get_request_var('host_id');
} elseif (isempty_request_var('host_id')) {
$sql_where .= ($sql_where == '' ? '' : ' AND') . ' gl.host_id=0';
}

if (get_request_var('location') != '' && get_request_var('location') != '-1' && get_request_var('location') != '0') {
$sql_where .= ($sql_where == '' ? '' : ' AND') . ' h.location = ' . db_qstr(get_request_var('location'));
} elseif (get_request_var('location') == '0') {
$sql_where .= ($sql_where == '' ? '' : ' AND') . ' h.location = ""';
}

if (!isempty_request_var('graph_template_id') && get_request_var('graph_template_id') != '-1' && get_request_var('graph_template_id') != '0') {
$sql_where .= ($sql_where != '' ? ' AND ':'') . ' (gl.graph_template_id IN (' . get_request_var('graph_template_id') . '))';
} elseif (get_request_var('graph_template_id') == '0') {
Expand Down Expand Up @@ -866,7 +900,9 @@ function clearFilter() {

function applyFilter() {
strURL = 'graph_view.php?action=list&header=false&page=1';
strURL += '&site_id=' + $('#site_id').val();
strURL += '&host_id=' + $('#host_id').val();
strURL += '&location=' + $('#location').val();
strURL += '&rows=' + $('#rows').val();
strURL += '&graph_template_id=' + $('#graph_template_id').val();
strURL += '&rfilter=' + base64_encode($('#rfilter').val());
Expand Down
40 changes: 40 additions & 0 deletions lib/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,46 @@ function html_site_filter($site_id = '-1', $call_back = 'applyFilter', $sql_wher
<?php
}

function html_location_filter($location = '', $call_back = 'applyFilter', $sql_where = '', $noany = false, $nonone = false) {
$theme = get_selected_theme();

if (strpos($call_back, '()') === false) {
$call_back .= '()';
}

?>
<td>
<?php print __('Location');?>
</td>
<td>
<select id='location' onChange='<?php print $call_back;?>'>
<?php if (!$noany) {?><option value='-1'<?php if ($location == '-1') {?> selected<?php }?>><?php print __('Any');?></option><?php }?>
<?php if (!$nonone) {?><option value='0'<?php if ($location == '0') {?> selected<?php }?>><?php print __('None');?></option><?php }?>
<?php

$locations = array_rekey(
db_fetch_assoc("SELECT DISTINCT location
FROM host
$sql_where
ORDER BY location ASC"),
'location', 'location'
);

if (cacti_sizeof($locations)) {
foreach ($locations as $l) {
if ($l == '') {
continue;
}

print "<option value='" . html_escape($l) . "'"; if ($location == $l) { print ' selected'; } print '>' . html_escape($l) . '</option>';
}
}
?>
</select>
</td>
<?php
}

function html_spikekill_actions() {
switch(get_nfilter_request_var('action')) {
case 'spikemenu':
Expand Down

0 comments on commit b6fa403

Please sign in to comment.