File: snmp_interfaces.php

package info (click to toggle)
cacti 0.6.7-2.2
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,000 kB
  • ctags: 1,120
  • sloc: php: 5,059; sql: 922; sh: 302; perl: 81; makefile: 56
file content (177 lines) | stat: -rw-r--r-- 8,176 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?/* 
+-------------------------------------------------------------------------+
| Copyright (C) 2002 Ian Berry                                            |
|                                                                         |
| This program is free software; you can redistribute it and/or           |
| modify it under the terms of the GNU General Public License             |
| as published by the Free Software Foundation; either version 2          |
| of the License, or (at your option) any later version.                  |
|                                                                         |
| This program is distributed in the hope that it will be useful,         |
| but WITHOUT ANY WARRANTY; without even the implied warranty of          |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           |
| GNU General Public License for more details.                            |
+-------------------------------------------------------------------------+
| cacti: the rrdtool frontend [php-auth, php-tree, php-form]              |
+-------------------------------------------------------------------------+
| This code is currently maintained and debugged by Ian Berry, any        |
| questions or comments regarding this code should be directed to:        |
| - iberry@raxnet.net                                                     |
+-------------------------------------------------------------------------+
| - raXnet - http://www.raxnet.net/                                       |
+-------------------------------------------------------------------------+
*/?>
<? 	$section = "Add/Edit Data Sources"; include ('auth/include/auth.php');
	header("Cache-control: no-cache");
	include_once ('include/functions.php');
	include_once ('include/utility_functions.php');
	include ('include/database.php');
	include ('include/config.php');
	include_once ('include/form.php');

switch ($action) {
	case 'save':
		$graph_parameters["snmp_interface_id"] = $id;
		$graph_parameters["data_source_name"] = $dsname;
		$graph_parameters["unparsed_graph_title"] = $title;
		
		CreateGraphDataFromSNMPData($graph_parameters);
		
		header ("Location: snmp_interfaces.php?id=$gid");
		break;
	case 'saveall':
		$sql_id = mysql_query("select * from snmp_hosts_interfaces where hostid=$gid", $cnn_id);
		$rows = mysql_num_rows($sql_id); $i = 0;
		
		while ($i < $rows) {
			if (${mysql_result($sql_id, $i, "id")} != "") {
				$graph_parameters["snmp_interface_id"] = mysql_result($sql_id, $i, "id");
				$graph_parameters["data_source_name"] = ${mysql_result($sql_id, $i, "id")};
				$graph_parameters["unparsed_graph_title"] = $title;
				
				CreateGraphDataFromSNMPData($graph_parameters);
			}
			
			$i++;
		}
		
		header ("Location: snmp_interfaces.php?id=$gid");
		break;
	case 'makegraph':
		include_once ('include/top_header.php');
		
		/* get a nice default name */
		$sql_id = mysql_query("select * from snmp_hosts_interfaces where id=$id", $cnn_id);
		
		if (mysql_result($sql_id, 0, "ipaddress") == "") {
			$snmp_description = substr(mysql_result($sql_id, 0, "description"),0,10) . "_" . mysql_result($sql_id, 0, "interfacenumber");
		}else{
			$snmp_description = mysql_result($sql_id, 0, "ipaddress") . "_" . mysql_result($sql_id, 0, "interfacenumber");
		}
		
		/* this "name cleanup" is only for the default name in the textbox; the user
		can enter something different if they so choose */
		$snmp_description = CleanUpName($snmp_description);
		$snmp_description = strtolower($snmp_description);
		$snmp_description = "traf_$snmp_description";
		
		DrawFormHeader("Create Graph from SNMP Data Interface","You must specify some additional
			information to create a graph, please supply it here.",false);
		
		DrawFormItem("Graph Title","The title format used for the name of this graph. Valid
			variable names are: &lt;data_source_name&gt;, &lt;snmp_description&gt;, &lt;snmp_interface_number&gt;,
			&lt;snmp_interface_speed&gt;, &lt;snmp_hardware_address&gt;, and &lt;snmp_ip_address&gt;");
		DrawFormItemTextBox("title","Traffic Analysis for <data_source_name>","","");
		
		DrawFormItem("Data Source Name","Please enter a name for the data source, this name 
			cannot contain spaces or other strange charcters.");
		DrawFormItemTextBox("dsname",$snmp_description,"","");
		
		DrawFormSaveButton();
		DrawFormItemHiddenIDField("id",$id);
		DrawFormItemHiddenIDField("gid",$gid);
		DrawFormFooter();
		
		include_once ("include/bottom_footer.php");
		
		break;
	case 'makeall':
		include_once ('include/top_header.php');
		
		/* get a nice default name */
		$sql_id = mysql_query("select * from snmp_hosts_interfaces where hostid=$gid", $cnn_id);
		$rows = mysql_num_rows($sql_id); $i = 0;
		
		DrawFormHeader("Create Graph from SNMP Data Interface","You must specify some additional
			information to create a graph, please supply it here.",false);
		
		DrawFormItem("Graph Title","The title format used for the name of this graph. Valid
			variable names are: &lt;data_source_name&gt;, &lt;snmp_description&gt;, &lt;snmp_interface_number&gt;,
			&lt;snmp_interface_speed&gt;, &lt;snmp_hardware_address&gt;, and &lt;snmp_ip_address&gt;");
		DrawFormItemTextBox("title","Traffic Analysis for <data_source_name>","","");
		
		DrawFormItem("Data Source Name(s)","Please enter a name for the data source, this name 
			cannot contain spaces or other strange charcters.");
		
		while ($i < $rows) {
			if (mysql_result($sql_id, $i, "ipaddress") == "") {
				$snmp_description = substr(mysql_result($sql_id, $i, "description"),0,10) . "_" . mysql_result($sql_id, $i, "interfacenumber");
			}else{
				$snmp_description = mysql_result($sql_id, $i, "ipaddress") . "_" . mysql_result($sql_id, $i, "interfacenumber");
			}
			
			$snmp_description = CleanUpName($snmp_description);
			$snmp_description = strtolower($snmp_description);
			$snmp_description = "traf_$snmp_description";
			
			DrawFormItem("",mysql_result($sql_id, $i, "description") . "/" . mysql_result($sql_id, $i, "ipaddress"));
			DrawFormItemTextBox(mysql_result($sql_id, $i, "id"),$snmp_description,"","");
			
			$i++;
		}
		
		DrawFormSaveButton();
		DrawFormItemHiddenIDField("gid",$gid);
		print "<input type=\"hidden\" name=\"action\" value=\"saveall\"></form>";
		
		include_once ("include/bottom_footer.php");
		
		break;
	default:
		include_once ('include/top_header.php');
		
		DrawMatrixTableBegin("97%");
		DrawMatrixRowBegin();
			DrawMatrixHeaderTop("Current SNMP Interfaces",$color_dark_bar,"","5");
			DrawMatrixLoopItemAction("Make All Graphs",$color_dark_bar,"",true,"snmp_interfaces.php?action=makeall&gid=$id");
		DrawMatrixRowEnd();
		
		DrawMatrixRowBegin();
			DrawMatrixHeaderItem("Interface Number",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("Description",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("Speed",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("Hardware Address",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("IP Address",$color_panel,$color_panel_text);
			DrawMatrixHeaderItem("",$color_panel,$color_panel_text);
		DrawMatrixRowEnd();
		
		$sql_id = mysql_query("select * from snmp_hosts_interfaces where hostid=$id order by interfacenumber", $cnn_id);
		$rows = mysql_num_rows($sql_id); $i = 0;
		
		while ($i < $rows) {
			DrawMatrixRowAlternateColorBegin($color_alternate,$color_light,$i);
				DrawMatrixLoopItem($sql_id,"interfacenumber",$i,false,"");
				DrawMatrixLoopItem($sql_id,"description",$i,false,"");
				DrawMatrixLoopItem((mysql_result($sql_id, $i, "speed")/1000000) . " mbit","","",false,"");
				DrawMatrixLoopItem($sql_id,"hardwareaddress",$i,false,"");
				DrawMatrixLoopItem($sql_id,"ipaddress",$i,false,"");
				DrawMatrixLoopItemAction("Make Graph",$color_panel,"",false,"snmp_interfaces.php?action=makegraph&gid=$id&id=" . mysql_result($sql_id, $i, "id"));
			DrawMatrixRowEnd();
			$i++;
		}
		
		DrawMatrixTableEnd();
		include_once ("include/bottom_footer.php");
		
		break;
} ?>