forked from tsvcathed/CiscoChart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
290 lines (274 loc) · 10.8 KB
/
index.php
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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
<?php
// Fetch values from HTTP GET's and append to Variables
$snmp = $_GET['snmp'];
$ip = $_GET['ip'];
$community = $_GET['community'];
$interface = $_GET['interface'];
$oid0 = $_GET['oid0'];
$oid1 = $_GET['oid1'];
$refresh = $_GET['refresh'];
// Set defaults
if (empty($community)) { $community = "tceo"; }
if (empty($refresh)) { $refresh = "10"; }
// Change seconds to Milliseconds for setInterval loop
$chartloop = $refresh * 1000;
// Set Bandwidth OID's by Numerical Interface Choice
if (!empty($interface)) {
$oid0 = "1.3.6.1.2.1.2.2.1.10.$interface";
$oid1 = "1.3.6.1.2.1.2.2.1.16.$interface";
}
// Set PHP-SNMP Default Variables
snmp_set_oid_numeric_print(1);
snmp_set_quick_print(TRUE);
snmp_set_enum_print(TRUE);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
// Get OID Data if Requested
if (!empty($oid0)) {
$output0 = snmpget($ip, $community, $oid0);
}
if (!empty($oid1)) {
$output1 = snmpget($ip, $community, $oid1);
}
// Generate HTML Head Function
function head() {
echo "<!DOCTYPE html>
<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">
<title>Jordan's Live Bandwidth Grapher</title>
<style>
body {
background-color: #F5F5F5;
font-family: Monaco, Menlo, Consolas, \"Courier New\", monospace;
}
</style>
</head>";
}
// Generate Menu Function
function menu() {
echo "<div>
<form method=\"get\" action=\"\">";
if ( empty($GLOBALS[enumint])) {
echo "Router IP: <input type=\"text\" name=\"ip\" id=\"ip\" value=\"$GLOBALS[ip]\"/>
Community: <input type=\"text\" name=\"community\" id=\"community\" value=\"$GLOBALS[community]\"/>";
}
else { // Disable form entry for IP and Community once Interfaces have been enumerated
echo "Router IP: <input type=\"text\" name=\"ip\" id=\"ip\" value=\"$GLOBALS[ip]\" readonly=\"readonly\"/>
Community: <input type=\"text\" name=\"community\" id=\"community\" value=\"$GLOBALS[community]\" readonly=\"readonly\"/>";
}
if ( !empty($GLOBALS[enumint])) { // Generate Dropdown list of Interfaces if the Interface Enumeration has happened
echo " Interface: <select name=\"interface\">";
for ( $i=1; $i<$GLOBALS[enumint]+2; $i++) {
$valint = snmpget($GLOBALS[ip], $GLOBALS[community], "1.3.6.1.2.1.2.2.1.2.$i");
$valintnm = snmpget($GLOBALS[ip], $GLOBALS[community], "1.3.6.1.2.1.31.1.1.1.18.$i");
if ( !empty($valint) ) {
if ( "$GLOBALS[interface]" == $i ) {
echo "<option value=\"$i\" selected>$valint $valintnm</option>";
}
else {
echo "<option value=\"$i\">$valint $valintnm</option>";
}
}
}
echo "</select>
Refresh (Secs): <input type=\"text\" name=\"refresh\" id=\"refresh\" value=\"$GLOBALS[refresh]\"/>
<input type=\"submit\" id=\"submit\" value=\"Submit\"/>
<input type=\"reset\" id=\"reset\" onclick=\"window.location='?';\" value=\"Reset\"/>
</form>
</div>";
}
else {
echo "
<input type=\"submit\" id=\"submit\" value=\"List Interfaces\"/>
</form>
</div>";
}
}
// Append Footer Function to close page
function foot() {
echo "<br />To enable per-second polling on Cisco routers, please issue the following command: snmp-server hc poll 100
</body>
</html>";
}
// Check if all required values are available before generating Chart
if (empty($snmp) && !empty($ip) && !empty($oid0) && !empty($oid1) && !empty($community) && !empty($refresh)) {
$enumint = snmpget($ip, $community, "1.3.6.1.2.1.2.1.0");
$routernm = snmpget($ip, $community, "1.3.6.1.2.1.1.5.0");
head();
menu();
echo "<br /><script type=\"text/javascript\" src=\"http://code.jquery.com/jquery-1.9.1.js\"></script>
<script type=\"text/javascript\">
$(function () {
$(document).ready(function() {
Highcharts.setOptions({
global: {
useUTC: false
}
});
var chart;
$('#container').highcharts({
credits: {
enabled: false
},
chart: {
type: 'areaspline',
//animation: Highcharts.svg,
animation: false,
marginRight: 10,
events: {
load: function() {
var series0 = this.series[0],
series1 = this.series[1];
// Set initial variables
$.ajax({
type: \"GET\",
cache: false,
url: \"?snmp=true&ip=$ip&community=$community&oid0=$oid0\",
dataType: \"text\",
success: function(output0) {
previousval0 = parseInt(output0);
}
});
// Set initial variables
$.ajax({
type: \"GET\",
cache: false,
url: \"?snmp=true&ip=$ip&community=$community&oid1=$oid1\",
dataType: \"text\",
success: function(output1) {
previousval1 = parseInt(output1);
}
});
setInterval(function() {
var x = (new Date()).getTime();
$.ajax({
type: \"GET\",
cache: false,
url: \"?snmp=true&ip=$ip&community=$community&oid0=$oid0\",
dataType: \"text\",
success: function(output0) {
var y0 = ((parseInt(output0) - previousval0)/1024/1024*8)/$refresh;
previousval0 = parseInt(output0);
series0.addPoint([x, y0], true, true);
}
});
$.ajax({
type: \"GET\",
cache: false,
url: \"?snmp=true&ip=$ip&community=$community&oid1=$oid1\",
dataType: \"text\",
success: function(output1) {
var y1 = ((parseInt(output1) - previousval1)/1024/1024*8)/$refresh;
previousval1 = parseInt(output1);
series1.addPoint([x, y1], true, true);
}
});
}, $chartloop);
}
}
},
title: {
text: 'Live Ingress/Egress Bandwidth for $routernm'
},
xAxis: {
type: 'datetime',
minTickInterval: 1
},
yAxis: {
min: '0',
title: {
text: 'mbps'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
formatter: function() {
var s = '';
$.each(this.points, function(i, point) {
s += '<b>'+ this.series.name +'</b><br/>'+
Highcharts.dateFormat('%H:%M:%S %d-%m-%Y', this.x) +'<br/>'+
Highcharts.numberFormat(point.y, 2) +' mbps<br/>';
});
return s;
},
shared: true,
},
legend: {
enabled: false
},
exporting: {
enabled: false
},
plotOptions: {
areaspline: {
fillOpacity: 0.3
}
},
series: [{
name: 'Ingress Bandwidth',
data: (function() {
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i++) {
data.push({
x: time + i * $chartloop,
y: null,
});
}
return data;
})()
}, {
name: 'Egress Bandwidth',
data: (function() {
var data = [],
time = (new Date()).getTime(),
i;
for (i = -19; i <= 0; i++) {
data.push({
x: time + i * $chartloop,
y: null,
});
}
return data;
})()
}]
});
});
});
</script>
</head>
<body>
<script src=\"http://code.highcharts.com/highcharts.js\"></script>
<script src=\"http://code.highcharts.com/modules/exporting.js\"></script>
<div id=\"container\" style=\"min-width: 310px; min-height: 700px; margin: 0 auto\"></div>";
foot();
}
// Get Interface Enumeration number then generate expanded menu
elseif (empty($snmp) && !empty($ip) && !empty($community)) {
$enumint = snmpget($ip, $community, "1.3.6.1.2.1.2.1.0");
head();
menu();
foot();
}
// Return only Data values if snmp = true
elseif ( $snmp == "true" ) {
if (!empty($oid0)) {
echo $output0;
}
if (!empty($oid1)) {
echo $output1;
}
return;
}
// Generate splash page if no data received from GET
else {
head();
menu();
foot();
}
?>