SNMP Information at graph_view.php page

Addons for Cacti and discussion about those addons

Moderators: Developers, Moderators

dan707
Posts: 1
Joined: Tue Dec 16, 2003 4:03 am

SNMP Information at graph_view.php page

Post by dan707 »

This short modification of the graph_view.php allows you to see a short SNMP Information about every system at the graph view page.
You have to paste the following code in your graph_view.php between line 256 to 276.
I have cacti 0.8.4.

Code: Select all

print "<table width='98%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center' cellspacing='2' cellpadding='3' border='0'>
		<tr bgcolor='#" . $colors["header_panel"] . "'>
			<td colspan='" . read_graph_config_option("num_columns") . "' class='textHeaderDark'>
				<strong>SNMP Information</strong><br>
				<span style='font-size: 10px; font-weight: normal; font-family: monospace;'>";
					$host = db_fetch_row("select * from host where id=" . $_REQUEST["host_id"]);
					$header_label = "[edit: " . $host["description"] . "]";

					if (($host["snmp_community"] == "") && ($host["snmp_username"] == "")) {
						print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n";
					}else{
						$snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);

						if ($snmp_system == "") {
							print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n";
						}else{
							$snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);
							$snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);
							$snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);

							print "System: '$snmp_system'<br>\n";
							print "Uptime: '$snmp_uptime'<br>\n";
							print "Hostname: '$snmp_hostname'<br>\n";
							print "Location: '$snmp_location'<br>\n";
						}
					}
print "</span></td></tr></table>";

print "<table width='98%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center'><tr>";
	$i = 0; $k = 0;
	if (sizeof($graphs) > 0) {
	foreach ($graphs as $graph) {
		print "<td align='center' width='" . (98 / read_graph_config_option("num_columns")) . "%'><br><a href='graph.php?rra_id=all&local_graph_id=" . $graph["local_graph_id"] . "'><img src='graph_image.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=" . (empty($set_rra_id) ? read_graph_config_option("default_rra_id") : $set_rra_id) . "&graph_start=-" . (empty($set_rra_id) ? read_graph_config_option("timespan") : "0") . "&graph_height=" . read_graph_config_option("default_height") . "&graph_width=" . read_graph_config_option("default_width") . "&graph_nolegend=true' border='0' alt='" . $graph["title_cache"] . "'></a></td>\n";

		$i++;
		$k++;

		if (($i == read_graph_config_option("num_columns")) && ($k < count($graphs))) {
			$i = 0;
			print "</tr><tr>";
		}
	}
	}else{
		print "<td><em>No Graphs Found.</em></td>";
	}

	print "</tr></table>";
	print "<br><br>";
print "<table width='98%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center' cellspacing='2' cellpadding='3' border='0'>
		<tr bgcolor='#" . $colors["header_panel"] . "'>
			<td colspan='" . read_graph_config_option("num_columns") . "' class='textHeaderDark'>
				<strong>SNMP Information</strong><br>
				<span style='font-size: 10px; font-weight: normal; font-family: monospace;'>";
					$host = db_fetch_row("select * from host where id=" . $_REQUEST["host_id"]);
					$header_label = "[edit: " . $host["description"] . "]";

					if (($host["snmp_community"] == "") && ($host["snmp_username"] == "")) {
						print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n";
					}else{
						$snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);

						if ($snmp_system == "") {
							print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n";
						}else{
							$snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);
							$snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);
							$snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);

							print "System: '$snmp_system'<br>\n";
							print "Uptime: '$snmp_uptime'<br>\n";
							print "Hostname: '$snmp_hostname'<br>\n";
							print "Location: '$snmp_location'<br>\n";
						}
					}
print "</span></td></tr></table>";

print "<table width='98%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center'><tr>";
	$i = 0; $k = 0;
	if (sizeof($graphs) > 0) {
	foreach ($graphs as $graph) {
		print "<td align='center' width='" . (98 / read_graph_config_option("num_columns")) . "%'><br><a href='graph.php?rra_id=all&local_graph_id=" . $graph["local_graph_id"] . "'><img src='graph_image.php?local_graph_id=" . $graph["local_graph_id"] . "&rra_id=" . (empty($set_rra_id) ? read_graph_config_option("default_rra_id") : $set_rra_id) . "&graph_start=-" . (empty($set_rra_id) ? read_graph_config_option("timespan") : "0") . "&graph_height=" . read_graph_config_option("default_height") . "&graph_width=" . read_graph_config_option("default_width") . "&graph_nolegend=true' border='0' alt='" . $graph["title_cache"] . "'></a></td>\n";

		$i++;
		$k++;

		if (($i == read_graph_config_option("num_columns")) && ($k < count($graphs))) {
			$i = 0;
			print "</tr><tr>";
		}
	}
	}else{
		print "<td><em>No Graphs Found.</em></td>";
	}

	print "</tr></table>";
	print "<br><br>";
Also you have to add:

Code: Select all

include_once("./lib/snmp.php")
At line 255 you have substitute:

Code: Select all

<tr>
with

Code: Select all

</table>
kurowsky
Cacti User
Posts: 52
Joined: Wed Feb 04, 2004 4:43 pm
Location: Richmond, VA.

Post by kurowsky »

I added/changed the following to graph_view.php tobreakdown the uptime response into something useful to the viewers:
(I don't know php, so it's ugly but it works.)


$y = 217728000;
$m = 18144000;
$w = 604800;
$d = 86400;
$h = 3600;
$mn = 60;
$s = round($snmp_uptime/100);
$year = (floor($s/$y));
$month = (floor(($s%$y)/$m));
$week = (floor((($s%$y)%$m)/$w));
$day = (floor(((($s%$y)%$m)%$w)/$d));
$hour = (floor((((($s%$y)%$m)%$w)%$d)/$h));
$min = (floor(((((($s%$y)%$m)%$w)%$d)%$h)/$mn));
$sec = (((((($s%$y)%$m)%$w)%$d)%$h)%$mn);
print "System: '$snmp_system'<br>\n";
print "Uptime: $year yr(s) $month mo(s) $week wk(s) $day day(s) $hour hour(s) $min min(s) $sec sec(s)<br>\n";
print "Hostname: '$snmp_hostname'<br>\n";
print "Location: '$snmp_location'<br>\n";
User avatar
Pumpi
Cacti User
Posts: 259
Joined: Wed Jan 14, 2004 3:23 am
Location: Germany

Post by Pumpi »

has somebody tested dan707's mod on 0.8.5 ?


@ kurowsky

where should I insert these lines ?
kurowsky
Cacti User
Posts: 52
Joined: Wed Feb 04, 2004 4:43 pm
Location: Richmond, VA.

Post by kurowsky »

I'm running 8.5 and it works.

one correction, I used the wrong values for year and month. russhing a little.

They should be:

$y = 31536000;
$m = 2592000;

I'll go ahead and attach the whole altered graph_view.php in a zip file.
Attachments
graph_view.zip
(5.25 KiB) Downloaded 3704 times
kurowsky
Cacti User
Posts: 52
Joined: Wed Feb 04, 2004 4:43 pm
Location: Richmond, VA.

Post by kurowsky »

Oh, also ... I'd like to apply this same feature to the treeview but I don't know where to start.

If someone could point me in the right direction.

Is it in the same file?
User avatar
Pumpi
Cacti User
Posts: 259
Joined: Wed Jan 14, 2004 3:23 am
Location: Germany

Works now

Post by Pumpi »

:D Good work - works for me also kurowsky
User avatar
Morgan
Cacti User
Posts: 187
Joined: Wed Feb 25, 2004 3:38 am

Post by Morgan »

could someone post a screenshot of what information this actually adds?
thanks!
M
User avatar
Pumpi
Cacti User
Posts: 259
Joined: Wed Jan 14, 2004 3:23 am
Location: Germany

Post by Pumpi »

Not yet possible, still having this problem:

http://www.raxnet.net/board/viewtopic.php?t=3578

You can see in the Preview View hostname, description, uptime, location etc.

Perhaps you have an idea for my problem above ?
kurowsky
Cacti User
Posts: 52
Joined: Wed Feb 04, 2004 4:43 pm
Location: Richmond, VA.

Post by kurowsky »

Better late than never....
Attachments
Screenshot.png
Screenshot.png (82.42 KiB) Viewed 45751 times
noskill
Posts: 32
Joined: Mon Feb 21, 2005 12:32 am

Post by noskill »

can you post a newer version of that for 0.8.6f ? It seems alot of the code changes make it unusuable.
kurowsky
Cacti User
Posts: 52
Joined: Wed Feb 04, 2004 4:43 pm
Location: Richmond, VA.

SNMP Info in Graph tree

Post by kurowsky »

**** Edited - Code is correct now also took Month Variables out for correctness ****

Took me a while, but after bastardizing some of the code finally got the results I wanted. And I don't think I broke anything yet..... :o
Using Cacti 8.6h

You can give this a shot if you like ....

in ../lib/html_tree.php add the following:

line 457:

Code: Select all

include_once($config["library_path"] . "/snmp.php");
line 519: .......
BETWEEN

Code: Select all

/* include time span selector */
        if (read_graph_config_option("timespan_sel") == "on") {
                html_graph_start_box(3, false);
                include("./include/html/inc_timespan_selector.php");
                html_graph_end_box();
                print "<br>";
        }
and

Code: Select all

/* start graph display */ 
Paste the following:

Code: Select all

/* start SNMP information*/
          if (empty($leaf_id)) { return; }
          if (!empty($leaf_id)) {
          $host = db_fetch_row ("select * from (graph_tree_items,host) where graph_tree_items.host_id=host.id and graph_tree_items.id=$leaf_id");}

                html_graph_start_box(3, false);
                print "<table width='98%' style='background-color: #f5f5f5; border: 1px solid #bbbbbb;' align='center' cellspacing='2' cellpadding='3' border='0'>
      <tr bgcolor='#" . $colors["header_panel"] . "'>
         <td colspan='" . read_graph_config_option("num_columns") . "' class='textHeaderDark'>
            <strong>SNMP Information</strong><br>
            <span style='font-size: 10px; font-weight: normal; font-family: monospace;'>";
               if (($host["snmp_community"] == "") && ($host["snmp_username"] == "")) {
                  print "<span style='color: #ab3f1e; font-weight: bold;'>SNMP not in use</span>\n";
               }else{
                  $snmp_system = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.1.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);
 if ($snmp_system == "") {
                     print "<span style='color: #ff0000; font-weight: bold;'>SNMP error</span>\n";
                  }else{
                     $snmp_uptime = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.3.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);
                     $snmp_hostname = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.5.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);
                     $snmp_location = cacti_snmp_get($host["hostname"], $host["snmp_community"], ".1.3.6.1.2.1.1.6.0", $host["snmp_version"], $host["snmp_username"], $host["snmp_password"], $host["snmp_port"], $host["snmp_timeout"]);
                   $y = 31536000;
                   $w = 604800;
                   $d = 86400;
                   $h = 3600;
                   $mn = 60;
                   $s = round($snmp_uptime/100);
                   $year = (floor($s/$y));
                   $month = (floor($s%$y));
                   $week = (floor(($s%$y)/$w));
                   $day = (floor((($s%$y)%$w)/$d));
                   $hour = (floor(((($s%$y)%$w)%$d)/$h));
                   $min = (floor((((($s%$y)%$w)%$d)%$h)/$mn));
                   $sec = ((((($s%$y)%$w)%$d)%$h)%$mn);
                   print "System: '$snmp_system'<br>\n";
                   print "<span style='color: #00FF00; font-size: 12px; font-weight: bold;'>Uptime: $year yr(s) $week wk(s) $day day(s) $hour hr(s) $min min(s) $sec sec(s)</span><br>\n";
                   print "Hostname: '$snmp_hostname'<br>\n";
                   print "Location: '$snmp_location'<br>\n";

                  }
               }
print "</span></td>";
html_graph_end_box();
                print "<br>";
Don't forget to back up the original...

-Brian
Attachments
Screenshot.png
Screenshot.png (112.15 KiB) Viewed 44935 times
Last edited by kurowsky on Tue Oct 31, 2006 3:29 pm, edited 2 times in total.
Kurowsky
kurowsky
Cacti User
Posts: 52
Joined: Wed Feb 04, 2004 4:43 pm
Location: Richmond, VA.

Post by kurowsky »

Spoke too soon. Found one error.
If you click on the root of the tree you get an undefined variable error.

I'll see if I can get that fixed.

Other than that, I believe it's okay.
Kurowsky
knobdy
Cacti User
Posts: 495
Joined: Wed Sep 28, 2005 1:39 pm

Post by knobdy »

Sweet! I looked at the differences in the code posted here (in the zip for graph view) and what is currently in h - wouldn't know where to start!

Be sure to let us know if you work out an h version for the list view! :)
kurowsky
Cacti User
Posts: 52
Joined: Wed Feb 04, 2004 4:43 pm
Location: Richmond, VA.

Post by kurowsky »

Okay, think I fixed the error.

Forgot one line.

Need to append this to the very beginning:

Code: Select all

if (empty($leaf_id)) { return; }
As for the the list view... Don't mind giving it a shot.
Not a coder though..

Better at reverse egineering ...

:wink:

Just always thought this was nice info to have showing.

-Brian
Kurowsky
knobdy
Cacti User
Posts: 495
Joined: Wed Sep 28, 2005 1:39 pm

Post by knobdy »

kurowsky wrote:Need to append this to the very beginning:
Does this mean where we first inserted code in the original?
As for the the list view... Don't mind giving it a shot.
Not a coder though..
Me either - I've been reversing perl scripts for the last month...it's frustrating at times, but fun.
Just always thought this was nice info to have showing.
I agree and it makes me want to develop a seperate plugin for Cacti...it would grab this information but then correlate it with info from Cisco in regards to updates, EOL, etc.. that'd be nice. A lot like the tool Cisco is selling/giving to their partners but not their customers. Hmm...is this grabbing model? Not in the office to check right now, but if not, is it hard to add?
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests