[HOWTO] Enable graph links with time and search info

If you figure out how to do something interesting/cool in Cacti and want to share it with the community, please post your experience here.

Moderators: Developers, Moderators

Post Reply
duderino
Posts: 2
Joined: Fri Apr 22, 2011 3:45 pm

[HOWTO] Enable graph links with time and search info

Post by duderino »

Maybe there was some way to do this already that I missed, but I couldn't find it.

It always bothered me that I couldn't send the view I was looking at to others via internal chat or email. If I wanted to send a link to a set of graphs from a search filter, I couldn't. Linking to multiple graphs via a host or data query view would work, but if I wanted a specific time period to be conveyed, I had to use a single graph view.

These changes will put a link on the time/search bar thingy that contains the time preset and search fields. You can then 'copy link location' or whatever your browser calls it. It doesn't do the exact time periods, you still have to use the graph.php magnifying glass thingy for that, but it will do last 2 hours, last month, etc.

It also adds some code that redirects the recipient back to a clean url after reading these variables into their session equivalents in the recipient browser.

In graph_view.php, at line 40ish, right after the input validation stuff:

Code: Select all

#redirect to a clean url after grabbing timespan and filter 
if (isset($_REQUEST["predefined_timespan"])) {
     $url = "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://". $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'];
        if (isset($_REQUEST["filter"])) {
         $_SESSION["sess_graph_view_filter"] = $_REQUEST["filter"];
        }
         if (preg_match("/predefined/i", "$url")) {
         $_SESSION["sess_current_timespan"] = $_REQUEST["predefined_timespan"];
             $url_arr = explode("&pre",$url);
             $url = $url_arr[0];
         header( "Location:$url" );
         }
 }
Then this next line goes in two places. Both times, I snuck it inside the same table cell as the second clear button (the line contains "button_clear.gif"). In graph_view.php, this is at line 512ish, In lib/html_tree.php, this is around 1081 or so.

Code: Select all

<a href=<?php print "http" . ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://". $_SERVER['HTTP_HOST']  . $_SERVER['REQUEST_URI'] . "&predefined_timespan=" . $_SESSION["sess_current_timespan"] . "&filter=" .   $_SESSION["sess_graph_view_filter"];?>>Link to this view</a>
You'll also need to enable 'Show the page that user pointed their browser to.' in user management if you haven't already.

I've probably done some scary things here. Forgive me. Not really a programmer. Use at your peril.
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: [HOWTO] Enable graph links with time and search info

Post by noname »

That's interesting modification.. Here is some sample.

Tree View
linkto_tree_view.png
linkto_tree_view.png (14.72 KiB) Viewed 7962 times
List View
linkto_list_view.png
linkto_list_view.png (10.99 KiB) Viewed 7962 times
For example,
if I select '1 Month' for timespan and specify 'Traffic' for search filter,
I got the link to this page (by right-click 'Link to this view') as:
http://server/cacti/graph_view.php?style=selective&action=preview&predefined_timespan=7&filter=Traffic
That's useful :)



BTW, (this is off-topic?) if you want to make link to several graphs by hand, do like this:
linkto_by_hand.png
linkto_by_hand.png (22.75 KiB) Viewed 7962 times
(In old version of Cacti, order of graph-ids can be specified voluntarily, but it is sorted automatically in recent Cacti...)

// Sorry my English
User avatar
dragossto
Cacti User
Posts: 86
Joined: Tue May 15, 2007 5:24 am
Location: Romania
Contact:

Re: [HOWTO] Enable graph links with time and search info

Post by dragossto »

Hy.
someone update the code ?
this future is interesting and useful (for someone ho update from 0.8.8 to 1.2.4 :D).

my interest is preview view
Unfortunately function redirect from above no longer work or i misplaced
so i add in html_graph.php after

Code: Select all

<input type='button' class='ui-button ui-corner-all ui-widget' id='save' value='<?php print __esc('Save');?>' title='<?php print __esc('Save the current Graphs, Columns, Thumbnail, Preset, and Timeshift preferences to your profile');?>'>
							<?php }?>

Code: Select all

<a href=<?php print $_SERVER['REQUEST_SCHEME'] . "://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI'] . "&predefined_timespan=" . $_SESSION['sess_current_timespan'] . "&predefined_timeshift=" . $_SESSION['sess_current_timeshift'] . "&filter=" .  $_SESSION['sess_graph_view_filter'] . "&date1=" . str_replace(' ', '%20', $_SESSION['sess_current_date1']) . "&date2=" .  str_replace(' ', '%20', $_SESSION['sess_current_date2']) . "&header=true";?>>Link to this view</a>
Regards,
Dragos Stoica.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests