Skip to content

Commit

Permalink
Initial import of QT 0.2 from zip
Browse files Browse the repository at this point in the history
  • Loading branch information
howardjones committed May 22, 2017
1 parent 8ee0a17 commit a12343f
Show file tree
Hide file tree
Showing 14 changed files with 697 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
# cacti-quicktree
Make playlists of graphs in Cacti

***NOTE*** Version 0.2 of QuickTree only works on Cacti 0.8.x!

Quite often while looking at an issue, you find yourself switching between a small set of graphs that relate to the problem, but not necessarily to the same device - the server load, it's mail queue, and the switch port, for example. QuickTree is a 'shopping basket' for graphs - click the '+' icon next to a graph and it's added to the QuickTree page. You can collect graphs from across your Cacti install very quickly. If it turns out that the set of graphs will be useful in the future too, you can save them as a normal Cacti graph tree, provided that you have permissions to do so.

Each user (with QuickTree permssions) gets their own QuickTree.

Install using the Plugin Management screen. Then enter the User Management page and give the required users access to it. A green '+' icon should appear next to graphs on the 'single graph' viewing page (not in preview or list view - the hook doesn't exist to add one there).

Known Issue: the way Cacti caches Graph Trees means that you might need to switch to another graph tree before the newly-created one appears in your list. This is true for Cacti-created trees too, so it seems to just be how it is.
Binary file added images/add.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/delete.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tab_quicktree.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tab_quicktree_active.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tab_quicktree_hover.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tab_quicktree_red.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tab_shelf.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php

header("Location:../index.php");

// vim:ts=4:sw=4:
?>
154 changes: 154 additions & 0 deletions jquery-latest.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions quicktree.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

#qt_treeselector { display: none; position: absolute; z-index: 1000; background: white; border: solid gray 3px; padding: 20px;}
27 changes: 27 additions & 0 deletions quicktree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

jQuery(document).ready( function() {

// bind for the popup tree-selection box
jQuery('#qt_existing').bind('click', function (e) {
jQuery('#qt_treeselector').show();
e.preventDefault();

});

jQuery(document).bind('click', function(e) {
var target = jQuery( e.target );

// so we don't just undo the click on the link
if( !target.is('#qt_existing')) {
// if the target isn't contained by the popup, hide the popup
if ( target.closest('#qt_treeselector').length < 1 ) {
jQuery('#qt_treeselector').hide();
return;
}
}

});



});
185 changes: 185 additions & 0 deletions quicktree.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
<?php
$guest_account = true;

chdir('../../');

include_once("./include/auth.php");
include_once("./include/global.php");
include_once($config["library_path"] . "/tree.php");
include_once($config["library_path"] . "/api_tree.php");


$action = "";

if (isset($_REQUEST['action']))
{
$action = $_REQUEST['action'];
}
$user = $_SESSION["sess_user_id"];

switch ($action)
{
case 'add':
$graph = 0;

if (isset($_GET['graph_id']))
{
$graph = intval($_GET['graph_id']);
$rra = intval($_GET['rra_id']);

$title = mysql_escape_string(
db_fetch_cell("select title_cache from graph_templates_graph where local_graph_id=$graph"));

$SQL =
"insert into quicktree_graphs (userid,local_graph_id,rra_id,title) values ($user,$graph,$rra,'$title');";
$result = db_execute($SQL);
}
header("Location: quicktree.php");
break;

case 'clear':
$SQL = "delete from quicktree_graphs where userid=$user;";
$result = db_execute($SQL);
header("Location: quicktree.php");
break;

case 'save':

$new_tree_id = -1;
$parent_id = 0;
$username = db_fetch_cell("select username from user_auth where id=$user");

if(isset($_REQUEST['tree_id']))
{
$new_tree_id = intval($_REQUEST['tree_id']);
}

if($new_tree_id > 0)
{
$tree_name = "saved quicktree for user '" . $username . "' on ".date("r");
}
else
{
$tree_name = "saved quicktree for user '" . $username . "'";
}

$SQL = sprintf("select * from quicktree_graphs where userid=%d", $user);
$graphs = db_fetch_assoc($SQL);

if (sizeof($graphs) > 0)
{
// if no existing tree was picked, create one
if($new_tree_id < 1)
{
$save = array ();
$save["id"] = "";
$save["name"] = $tree_name;
$save["sort_type"] = TREE_ORDERING_NONE;

$new_tree_id = sql_save($save, "graph_tree");
sort_tree(SORT_TYPE_TREE, $new_tree_id, TREE_ORDERING_NONE);
}
else
{
// if an existing tree was picked, create a new heading to
// be the parent for all our graphs

$parent_id = api_tree_item_save(0, $new_tree_id, TREE_ITEM_TYPE_HEADER,
0, // all items are children of the root item
$tree_name, 0, 0, 0, 1, 1, false);
}

foreach ($graphs as $gr)
{
$tree_item_id = api_tree_item_save(0, $new_tree_id, TREE_ITEM_TYPE_GRAPH,
$parent_id, // all items are children of the root item
"", $gr['local_graph_id'], $gr['rra_id'], 0, 1, 1, false);
}
}

header("Location: ../../tree.php?action=edit&id=" . $new_tree_id);
break;

case 'remove':
$graph = 0;

if (isset($_GET['id']))
{
$graph = intval($_GET['id']);

$SQL = "delete from quicktree_graphs where userid=$user and id=$graph;";
$result = db_execute($SQL);
}
header("Location: quicktree.php");
break;

case 'add_ajax':
header('Content-type: text/plain');

print "{ status: 'OK' }";
break;

default:
include_once($config["base_path"] . "/include/top_header.php");

print
"<p>These are the graphs that you have added to your QuickTree. You can keep them here for as long as you like, or you can <a href='quicktree.php?action=save'>save them to a new Graph Tree</a> so you can keep them for later and work on something new. (you can also <a id='qt_existing'>save them as a branch to an existing tree</a>) The idea is to collect together the graphs for a situation you are monitoring, as easily as possible.</p>";

$SQL = "select g.id, g.name from graph_tree g order by g.name";
$queryrows = db_fetch_assoc($SQL);
if (sizeof($queryrows) > 0)
{
print "<div id='qt_treeselector'><h3>Add to which graph tree?</h3><form method='post' action='quicktree.php'><input name='action' type='hidden' value='save' /><select name='tree_id'>";
# <option value=1>1<option value=2>2
foreach ($queryrows as $tr)
{
printf("<option value='%d'>%s</option>", $tr['id'], htmlspecialchars($tr['name']));
}
print "</select><input type='submit' value='Add to this tree' /></form></div>";
}

print
"<p>You can add more graphs here by clicking the <img src='images/add.png'> icon next to a graph. You can remove them from this list by clicking the <img src='images/delete.png'> next to the graph on this page. You can see the full history for any graph by clicking on it. Finally, you can <a href='quicktree.php?action=clear'>clear all the graphs from this QuickTree</a>.</p>";
print
"<p>Don't Worry! Deleting a graph on this page does not affect the rest of Cacti. Each user gets their own QuickTree, if they have permission.</p>";
print "<hr>";

$SQL =
"select qt.*, gtg.title_cache from quicktree_graphs qt,graph_templates_graph gtg where qt.local_graph_id = gtg.local_graph_id and userid="
. $user;
$queryrows = db_fetch_assoc($SQL);

if (sizeof($queryrows) > 0)
{
foreach ($queryrows as $gr)
{
# print $gr['local_graph_id']."/".$gr['rra_id'];
$graph_title = $gr['title_cache'];
print "<table><thead><tr><th>";
print htmlspecialchars($graph_title);
print "&nbsp;&nbsp;<a href='quicktree.php?action=remove&id=" . $gr['id']
. "'><img border=0 src='images/delete.png' title='Remove This Graph From QuickTree'></a>";
print "</th></tr></thead>\n";
print "<tbody><tr><td>";
?>

<a href = "../../graph.php?action=view&rra_id=all&local_graph_id=<?php print $gr['local_graph_id']; ?>"><img class = 'graphimage'
id = 'graph_<?php print $gr["local_graph_id"] ?>'
src = '../../graph_image.php?action=view&local_graph_id=<?php print $gr["local_graph_id"];?>&rra_id=<?php print $gr["rra_id"];?>'
border = '0' alt = '<?php print $graph_title;?>'></a>

<?php
print "</td></tr></tbody></table>\n";
}

print "<hr>";
}
else
{
print "<p><em>No graphs yet</em></p>";
}

include_once($config["base_path"] . "/include/bottom_footer.php");
break;
}
?>
Loading

0 comments on commit a12343f

Please sign in to comment.