Get Graphs

Post general support questions here that do not specifically fall into the Linux or Windows categories.

Moderators: Developers, Moderators

Post Reply
insertcoin
Posts: 5
Joined: Wed Jan 07, 2015 8:38 am

Get Graphs

Post by insertcoin »

Hi,

Is there a method to get a graph from Cacti into a remote system?
insertcoin
Posts: 5
Joined: Wed Jan 07, 2015 8:38 am

Re: Get Graphs

Post by insertcoin »

Is this possible or should I look for a different method?
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: Get Graphs

Post by phalek »

You can enable the guest account and then simply use the URL from the graph/image.
Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
insertcoin
Posts: 5
Joined: Wed Jan 07, 2015 8:38 am

Re: Get Graphs

Post by insertcoin »

oh dear....

I didn't know if there was a simple way so ive just been writing a php function to get the image data and load it via cURL, and literally just this minute got it working!

Guest account I will look to see if thats possible to enable, may be a security issue.
cigamit
Developer
Posts: 3369
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Re: Get Graphs

Post by cigamit »

You can also use the graph export functionality to export the image, and then pull the image from the exported location.
insertcoin
Posts: 5
Joined: Wed Jan 07, 2015 8:38 am

Re: Get Graphs

Post by insertcoin »

Hi,

Yes I did see that feature.

To summarise for anyone else looking to do this:

Option 1:

Enable the Guest Account
  • 1) Click Setttings
    2) Click Authentication
    3) Enable The Guest User
Image
  • 4) Click Graphs
    5) Locate the required graph and click
Image
  • 6) Right click the graph and select "Open Image in New Tab" (or whatever similar option is available)

    Image

    -or-
    Take note of the graph ID from the address bar

    Image

    Go directly to: https://xxx.xxx.xxx.xxx/cacti/graph_image.php?action=view&local_graph_id=1344&rra_id=1
    Where "1344" would be your own "graph_id" and "rra_id=1" (Round Robin Archive) would equal the graph you want to see for the period or omit it to view the first graph

    You can use these URLs however you require, you could grab them and save them locally via a script or directly include the URL as a image src.

    WARNING: With the guest account activated it does mean that anyone can view the graphs, so be wary of this and take any necessary precautions to keep sensitive data safe.
Option 2:

Export the Graphs via FTP,SFTP or Locally
  • 1) Click Settings
    2) Click Graph Export
Alter the settings to those you require.

Image

Option 3:

Use a PHP Function to obtain the graphs via a authenticated cURL call.

My method I utilised the function written here http://forums.cacti.net/post-82996.html and altered it to meet my own needs. The function accepts the graph_id as a variable, it will then create an authenticated session. Once this is open it will then grab the graph and save it locally as "{grapid_id}.jpg" whenever the function is called. You could easily expand this to include the rra_id if required.

Code: Select all

function cactiGraph($graphid){

$url = "https://xxx.xxx.xxx.xxx/cacti/graph_image.php?action=view&local_graph_id=$graphid";

$username = 'admin';
$password = 'xxxxxxxxxxxx';

$cookiefile = tempnam ("/temp", "CURLCOOKIE");

   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_POST, TRUE);
   curl_setopt($ch, CURLOPT_POSTFIELDS,
      array(
         'login_username' => $username,
         'login_password' => $password,
         'realm' => 'local',
         'action' => 'login'
      )
   );
   curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE); 
   curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiefile);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
   curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
   if (preg_match('`^https://`i', $url))
      {
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      } 
   $ret = curl_exec($ch);
   if ($ret === FALSE) {
      print (curl_error($ch));
      die(curl_error());
   }
   curl_close($ch);

   $ch = curl_init($url);
   $fp = fopen("temp/$graphid.jpg","w");
   curl_setopt($ch, CURLOPT_POST, FALSE);
   if (preg_match('`^https://`i', $url))
      {
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      }
   curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE); 
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
   curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
   curl_setopt($ch, CURLOPT_HEADER, 0);;
   curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiefile);
   $ret = curl_exec($ch);
   if ($ret === FALSE) {
      $errorMsg = curl_error($ch);
      print $errorMsg;
   }
   curl_close($ch);

//ERROR HANDLING
  if(!(fwrite($fp, $ret))){
    error_log("Error in dashboard/functions.php - cactiGraph() unable to handle file", 0);
    return "Error In File Handler";
  } else {
//RETURN THE GRAPH ID
  fclose($fp);
    return $graphid.'.jpg';
  }
}
User avatar
phalek
Developer
Posts: 2838
Joined: Thu Jan 31, 2008 6:39 am
Location: Kressbronn, Germany
Contact:

Re: Get Graphs

Post by phalek »

Greetings,
Phalek
---
Need more help ? Read the Cacti documentation or my new Cacti 1.x Book
Need on-site support ? Look here Cacti Workshop
Need professional Cacti support ? Look here CereusService
---
Plugins : CereusReporting
insertcoin
Posts: 5
Joined: Wed Jan 07, 2015 8:38 am

Re: Get Graphs

Post by insertcoin »

Thank you for highlighting that alternative.

Its a little excessive for my requirements but if they change good to know there is an option.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests