Skip to content

Commit

Permalink
Resolving issues #155 from Cacti
Browse files Browse the repository at this point in the history
  • Loading branch information
cigamit committed Jan 6, 2017
1 parent bdcc214 commit 7e7214d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
8 changes: 7 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,13 @@ function thold_rrd_graph_graph_options ($g) {
$start--;

if ($id) {
$rows = db_fetch_assoc_prepared('SELECT time, status FROM plugin_thold_log WHERE local_graph_id = ? AND type = 0 and time > ? and time < ?', array($id, $start, $end));
$rows = db_fetch_assoc_prepared('SELECT time, status
FROM plugin_thold_log
WHERE local_graph_id = ?
AND type = 0
AND time > ?
AND time < ?', array($id, $start, $end));

if (!empty($rows)) {
foreach ($rows as $row) {
$g['graph_defs'] .= 'VRULE:' . $row['time'] . ($row['status'] == 0 ? '#00FF21' : '#FF0000') . ' \\' . "\n";
Expand Down
1 change: 0 additions & 1 deletion thold.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
if (isset($_SERVER['HTTP_REFERER'])) {
if (preg_match('/(data_sources.php|graph_view.php|graph.php)/', $_SERVER['HTTP_REFERER'])) {
$_SESSION['data_return'] = $_SERVER['HTTP_REFERER'];
cacti_log('Data Return 1');
}
}

Expand Down
43 changes: 32 additions & 11 deletions thold_webapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,30 @@ function thold_add_graphs_action_execute() {
include_once($config['base_path'] . '/plugins/thold/thold_functions.php');

$host_id = get_filter_request_var('host_id');
$local_graph_id = get_filter_request_var('local_data_id');
$local_graph_id = get_filter_request_var('local_graph_id');
$thold_template_id = get_filter_request_var('thold_template_id');

$message = '';

$template = db_fetch_row_prepared('SELECT * FROM thold_template WHERE id = ?', array($thold_template_id));

$temp = db_fetch_row_prepared('SELECT dtr.*
FROM data_template_rrd AS dtr
LEFT JOIN graph_templates_item AS gti
ON gti.task_item_id=dtr.id
LEFT JOIN graph_local AS gl
ON gl.id=gti.local_graph_id
WHERE gl.id = ?' , array($local_graph_id));
FROM data_template_rrd AS dtr
LEFT JOIN graph_templates_item AS gti
ON gti.task_item_id=dtr.id
LEFT JOIN graph_local AS gl
ON gl.id=gti.local_graph_id
WHERE gl.id = ?
LIMIT 1' ,
array($local_graph_id));

$data_template_id = $temp['data_template_id'];
$local_data_id = $temp['local_data_id'];

$data_source = db_fetch_row_prepared('SELECT * FROM data_local WHERE id = ?', array($local_data_id));
$data_source = db_fetch_row_prepared('SELECT *
FROM data_local
WHERE id = ?',
array($local_data_id));

$data_template_id = $data_source['data_template_id'];

Expand Down Expand Up @@ -115,7 +120,7 @@ function thold_add_graphs_action_execute() {
$insert['id'] = 0;
$id = sql_save($insert, 'thold_data');
if ($id) {
thold_template_update_threshold($id, $insert['template']);
thold_template_update_threshold($id, $insert['thold_template_id']);

$l = db_fetch_assoc("SELECT name FROM data_template where id=$data_template_id");
$tname = $l[0]['name'];
Expand Down Expand Up @@ -209,7 +214,7 @@ function thold_add_graphs_action_prepare() {
print '<ul>' . $not_found . '</ul>';
}

print '<p>' . __('Are you sure you wish to create Thresholds for this Graph?') . '
print '<p>' . __('Press \'Continue\' after you have selected the Threshold Template to utilize.') . '
<ul>' . $found_list . "</ul>
</td>
</tr>\n";
Expand Down Expand Up @@ -316,11 +321,27 @@ function thold_add_graphs_action_prepare() {

form_end(false);

if (isset($_SERVER['HTTP_REFERER'])) {
$backto = $_SERVER['HTTP_REFERER'];
}else{
$backto = $config['url_path'] . 'plugins/thold/thold.php';
}

?>
<script type='text/javascript'>
$(function() {
$('#cancel').click(function() {
document.location = '<?php print $_SERVER['HTTP_REFERER'];?>';
document.location = '<?php print $backto;?>';
});

$('#tholdform').submit(function(event) {
event.preventDefault();
strURL = $(this).attr('action');
strURL += (strURL.indexOf('?') >- 0 ? '&':'?') + 'header=false';
json = $('#listthold').serializeObject();
$.post(strURL, { usetemplate: 1, local_graph_id: $('#local_graph_id').val(), thold_template_id: $('#thold_template_id').val(), __csrf_magic: csrfMagicToken } ).done(function(data) {
document.location = '<?php print $backto;?>';
});
});
});
</script>
Expand Down

0 comments on commit 7e7214d

Please sign in to comment.