Get Graphs
Moderators: Developers, Moderators
-
- Posts: 5
- Joined: Wed Jan 07, 2015 8:38 am
Get Graphs
Hi,
Is there a method to get a graph from Cacti into a remote system?
Is there a method to get a graph from Cacti into a remote system?
-
- Posts: 5
- Joined: Wed Jan 07, 2015 8:38 am
Re: Get Graphs
Is this possible or should I look for a different method?
- phalek
- Developer
- Posts: 2838
- Joined: Thu Jan 31, 2008 6:39 am
- Location: Kressbronn, Germany
- Contact:
Re: Get Graphs
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
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
-
- Posts: 5
- Joined: Wed Jan 07, 2015 8:38 am
Re: Get Graphs
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.
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.
Re: Get Graphs
You can also use the graph export functionality to export the image, and then pull the image from the exported location.
-
- Posts: 5
- Joined: Wed Jan 07, 2015 8:38 am
Re: Get Graphs
Hi,
Yes I did see that feature.
To summarise for anyone else looking to do this:
Option 1:
Enable the Guest Account
Export the Graphs via FTP,SFTP or Locally
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.
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
- 4) Click Graphs
5) Locate the required graph and click
- 6) Right click the graph and select "Open Image in New Tab" (or whatever similar option is available)
-or-
Take note of the graph ID from the address bar
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.
Export the Graphs via FTP,SFTP or Locally
- 1) Click Settings
2) Click Graph Export
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';
}
}
- phalek
- Developer
- Posts: 2838
- Joined: Thu Jan 31, 2008 6:39 am
- Location: Kressbronn, Germany
- Contact:
Re: Get Graphs
Or use the nmidWebService plugin:
http://blog.network-outsourcing.de/prod ... ebservice/
Then look at this thread:
http://forums.cacti.net/viewtopic.php?t=32929
http://blog.network-outsourcing.de/prod ... ebservice/
Then look at this thread:
http://forums.cacti.net/viewtopic.php?t=32929
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
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
-
- Posts: 5
- Joined: Wed Jan 07, 2015 8:38 am
Re: Get Graphs
Thank you for highlighting that alternative.
Its a little excessive for my requirements but if they change good to know there is an option.
Its a little excessive for my requirements but if they change good to know there is an option.
Who is online
Users browsing this forum: No registered users and 2 guests