Hi Folks,
Wanted to hear your advice,
We are doing a Test deploy of Cacti at work to monitor our switches and routers. We are looking into the possibility of adding graphs into a different system we use.
As far as I could see I can pull those graphs out with the local_graph_id. But I was hoping that there is some way I issue a search for the local_graph_id by supplying the switch name and port.
will it be possible without writing a special PHP page for that?
if not, would it be even possible? (getting the local_graph_id out of the DB).
I'm not a PHP/ASP guy, so I don't even know how to start looking at it.
Any Ideas would be greatly appreciated,
Cheers,
Uri
Searching a Graph from an external webpage
Moderators: Developers, Moderators
OK,
I've written a php page that takes host (the device description) and port as argument, uses them to pull out the local_graph_id from the DB and redirects the user to the graph itself.
To "override" the authentication I've set up a guest user that can read all the graphs in the system, and limited the ability to use it to our office network by using this solution, http://forums.cacti.net/viewtopic.php?p=159566#159566
I will post the script tomorrow (the system is closed to our office network only).
cheers,
Uri
I've written a php page that takes host (the device description) and port as argument, uses them to pull out the local_graph_id from the DB and redirects the user to the graph itself.
To "override" the authentication I've set up a guest user that can read all the graphs in the system, and limited the ability to use it to our office network by using this solution, http://forums.cacti.net/viewtopic.php?p=159566#159566
I will post the script tomorrow (the system is closed to our office network only).
cheers,
Uri
OK,
as promised here is the PHP code
it takes few arguments from the user:
host: specifies which equipment you want (Device description)
port: port number
and two optional arguments:
type: what time of graph would be shown. ( [normal] | thumb | zoom | full )
time: what would be the graph timeframe ( [day] | week | hour | year | hour )
URL for an hourly thumb would proably look like this
http://cactiserver/cacti/pull_graph.php ... &time=hour
things to pay attention to:
1. when searching the graph_id notice that i'm looking for graph_template_id of 2 which is traffic graph on MY deployment - YMMV look it up on the DB.
2. PHP is talking directly to the DB - just to save the trouble. so make sure you put in your DB user, password and cacti's DB name.
3. while type and time are optional args. host and port are REQUIRED.
as promised here is the PHP code
it takes few arguments from the user:
host: specifies which equipment you want (Device description)
port: port number
and two optional arguments:
type: what time of graph would be shown. ( [normal] | thumb | zoom | full )
time: what would be the graph timeframe ( [day] | week | hour | year | hour )
URL for an hourly thumb would proably look like this
http://cactiserver/cacti/pull_graph.php ... &time=hour
Code: Select all
<?php
mysql_connect("localhost", "DBuserHere", "DBpassHere") or die(mysql_error());
mysql_select_db("cacti") or die(mysql_error());
$host = $_GET['host'];
$port = $_GET['port'];
/** Find Host ID **/
$result = mysql_query("SELECT id FROM `host` WHERE `description` LIKE '$host' LIMIT 0 , 30")
or die(mysql_error());
$row = mysql_fetch_row($result);
$host_id = $row[0];
/** translate user input port number to fit snmp_index as found in the DB
* Here are two types of switches Cisco 2960G and Cisco 4948
* Each cwitch model will probably have it's own unique snmp_index structure, just check the DB
* on this sample host_id 1 to 10 are 2960G and 11 to 20 are 4849
**/
if ( $host_id < 10 ) {
/** cisco 2960G **/
if ( $port < 10 ) {
$snmpport = "1010".$port;
} else {
$snmpport = "101".$port;
}
} else {
/** Cisco 4948 **/
$snmpport = $port+1;
}
/** Get local_graph_id **/
$result = mysql_query("SELECT id FROM `graph_local` WHERE `graph_template_id` =2 AND `host_id` LIKE $host_id AND `snmp_index` =$snmpport LIMIT 0 , 30")
or die(mysql_error());
$row = mysql_fetch_row($result);
$local_graph_id = $row[0];
/** Choose graph Timeframe **/
$rra_id = 1;
if ( $_GET['time'] == day ) {
$rra_id = 1;
}
if ( $_GET['time'] == week ) {
$rra_id = 2;
}
if ( $_GET['time'] == month ) {
$rra_id = 3;
}
if ( $_GET['time'] == year ) {
$rra_id = 4;
}
if ( $_GET['time'] == hour ) {
$rra_id = 5;
}
/** choose graph type **/
$type = normal;
if ( $_GET['type'] == thumb ) {
$type = thumb;
}
if ( $_GET['type'] == zoom ) {
$type = zoom;
}
if ( $_GET['type'] == full ) {
$type = full;
}
/** normal size graph **/
if ( $type == noraml ) {
header('Location: '."http://cactiserver/cacti/graph_image.php?local_graph_id=".$local_graph_id."&rra_id=".$rra_id);
}
/** Small size (300*100) thumb **/
if ( $type == thumb ) {
header('Location: '."http://cactiserver/cacti/graph_image.php?local_graph_id=".$local_graph_id."&rra_id=".$rra_id."&graph_height=100&graph_width=300&graph_nolegend=true");
}
/** opens up cacti to the Graph timeframe of choice - straight to zoom mode (magnifying glass) **/
if ( $type == zoom ) {
header('Location: '."http://cactiserver/cacti/graph.php?action=zoom&local_graph_id=".$local_graph_id."&&rra_id=".$rra_id);
}
/** Opens up cacti to the selected graph. shows the entire-set of graphs (day, week, month, year) **/
if ( $type == full ) {
header('Location: '."http://cactiserver/cacti/graph.php?action=view&rra_id=all&local_graph_id=".$local_graph_id);
}
?>
1. when searching the graph_id notice that i'm looking for graph_template_id of 2 which is traffic graph on MY deployment - YMMV look it up on the DB.
2. PHP is talking directly to the DB - just to save the trouble. so make sure you put in your DB user, password and cacti's DB name.
3. while type and time are optional args. host and port are REQUIRED.
Who is online
Users browsing this forum: No registered users and 4 guests