-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_webstats.pl
260 lines (215 loc) · 7.92 KB
/
sample_webstats.pl
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
#-------------------------------------------------------------
# Sample script for the ReadyNAS Perl library
#-------------------------------------------------------------
use POSIX qw( strftime getcwd );
use Time::Local;
#-------------------------------------------------------------
# Load the library
#-------------------------------------------------------------
require 'readynas.pl'; # Loader
loadReadyNASLibrary("MULTICAST"); # Select Library to Use
# SNMP = SNMP
# MULTICAST = UPNP
# UNICAST = UPNP
# HYBRID = UNICAST/SNMP
#--------------------------------------------------#
# You can alternately use the libraries directly. #
# #
# e.g. require 'readynas-unicast.pl'; #
#--------------------------------------------------#
#-------------------------------------------------------------
# Set Options
#-------------------------------------------------------------
setOptionRequireUniqueHosts(1); # Filter duplicate hostnames (0=off, 1=on)
setOptionVerbose(0); # Verbose Messages (0=off, 1=on)
setOptionDebug(0); # Debug Messages (0=off, 1=on)
setOptionDebugFile("console"); # Output to CONSOLE
setOptionDumpPackets(0); # Write packets to disk
setOptionDumpBadPacketsOnly(0); # Write ONLY bad packets to disk
setSocketTimeout(1); # Set Socket Timeout (Seconds)
# setSocketErrorTimeout(30); # Set Socket Error Timeout (Seconds) (MULTICAST ONLY)
# setCommunity("public"); # Set SNMP Community (SNMP Only)
#-------------------------------------------------------------
# ReadyNAS Units to Scan
#-------------------------------------------------------------
setBroadcastAddress("192.168.0.255");
#------------------------------------------------------------#
# Look for units in the subnet (UPNP only) #
# #
# * If not set, defaults to 255.255.255.255 which will only #
# work with UPNP MULTICAST. #
# #
# * If using UPNP to detect units, do NOT specify any units #
# below. #
# #
# * If using SNMP you MUST specify each unit below. #
# (No discovery is available) #
#------------------------------------------------------------#
# addUnit("192.168.0.1");
# addUnit("192.168.0.2");
# addUnit("192.168.0.3");
#------------------------------------------------------------#
# Add NETGEAR ReadyNAS unit at IP address to the list to #
# gather information from. #
#------------------------------------------------------------#
#-------------------------------------------------------------
# Full pathname to the stats file
#-------------------------------------------------------------
$fname = "nas.html";
my $_VERSION = "201003141246";
#-------------------------------------------------------------
# Gather ReadyNAS Data
#-------------------------------------------------------------
loadReadyNASData();
if (getBytesRead() < 1) {
exit(1);
}
#-------------------------------------------------------------
# Get a list of IP addresses of Units we now have data on
#-------------------------------------------------------------
$units = getUnitAddresses();
$unitcount = getUnitCount();
if ($unitcount > 0) {
}else{
exit(1);
}
$now = strftime( "%Y-%m-%d", localtime ) . " " . strftime( "%H:%M:%S", localtime );
#-------------------------------------------------------------
# Build Web Page
#-------------------------------------------------------------
open(HOUTPUT,">$fname");
print HOUTPUT "<html><head>\n";
print HOUTPUT "<meta http-equiv=\"Pragma\" content=\"no-cache\">\n";
print HOUTPUT "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";
print HOUTPUT "<meta http-equiv=\"refresh\" content=\"60\">\n";
print HOUTPUT "<TITLE>NETGEAR ReadyNAS Status Page</TITLE>\n";
print HOUTPUT "<head>\n";
print HOUTPUT "<BODY bgcolor=\#FFFFFF text=\#000000 vlink=\#0000A0 alink=\#0000FF link=\#0000D0>\n";
print HOUTPUT "<H1><font face=\"Tahoma\">NETGEAR ReadyNAS Server Status</h1><p></font>\n";
print HOUTPUT "Generated at $now<p>";
print HOUTPUT "<table border=1>\n";
print HOUTPUT "<tr><td>Server Information<td>Temperatures</tr>\n";
my $i = 0;
for ( split /\|/, $units ) {
/\|/;
if ($_ ne "") {
$i++;
$macindex = parseReadyNASData(getUnitData($_));
$nasindex{$_} = $macindex;
print HOUTPUT "<tr>";
print HOUTPUT "<td><font face=\"Tahoma\">";
print HOUTPUT "<a href=http://" . lc getAdminAddress($unit{$macindex}{ipaddr}{0}) . "/admin>";
print HOUTPUT "$unit{$macindex}{hostname}{0}";
print HOUTPUT "</a>";
print HOUTPUT "<br>$unit{$macindex}{models}{0}";
print HOUTPUT "<hr>";
print HOUTPUT "<small>";
print HOUTPUT "O/S: $unit{$macindex}{os}{0}";
print HOUTPUT "<br>MAC: $unit{$macindex}{mac}{0}";
print HOUTPUT "<br>TCP: $unit{$macindex}{ipaddr}{0}";
print HOUTPUT "<br>FAN: $unit{$macindex}{fan}{0}";
print HOUTPUT "<br>BOOT: $unit{$macindex}{boot}{0}";
print HOUTPUT "<br>MEM: $unit{$macindex}{system}{memory}{0}\n";
print HOUTPUT "<br>SYS: $unit{$macindex}{system}{processes}{0}\n";
print HOUTPUT "<br>UPT: $unit{$macindex}{system}{uptime}{0}\n";
print HOUTPUT "<p>$unit{$macindex}{volumes}{0}";
print HOUTPUT "</small>";
if ($unit{$macindex}{tmps}{0} ne "N/A")
{
print HOUTPUT "<td><font face=\"Tahoma\">";
my $temp_c = substr($unit{$macindex}{tmps}{1}{desc},0,2);
my $font_color = "";
if ($temp_c < 61) {
$font_color = "\#FF0000";
}
if ($temp_c < 56) {
$font_color = "\#900000";
}
if ($temp_c < 51) {
$font_color = "\#400000";
}
if ($temp_c < 41) {
$font_color = "\#004000";
}
if ($temp_c < 31) {
$font_color = "\#000040";
}
if ($temp_c < 21) {
$font_color = "\#000090";
}
if ($temp_c < 11) {
$font_color = "\#0000FF";
}
print HOUTPUT "<font color=$font_color>";
print HOUTPUT "<br>0: $unit{$macindex}{tmps}{1}{desc} System Core";
print HOUTPUT "</font>";
}else{
print HOUTPUT "<td><font face=\"Tahoma\">";
print HOUTPUT "<br>N/A";
print HOUTPUT "</font>";
}
if ($unit{$macindex}{disks}{0} ne "N/A") {
for ( $instance = 1; $instance < ($unit{$macindex}{disks}{0}{records} + 1); $instance++) {
print HOUTPUT "<br>";
my $temp_c = substr($unit{$macindex}{disks}{$instance}{tmps},0,2);
my $font_color = "";
if ($temp_c < 61) {
$font_color = "\#FF0000";
}
if ($temp_c < 56) {
$font_color = "\#900000";
}
if ($temp_c < 51) {
$font_color = "\#400000";
}
if ($temp_c < 41) {
$font_color = "\#004000";
}
if ($temp_c < 31) {
$font_color = "\#000040";
}
if ($temp_c < 21) {
$font_color = "\#000090";
}
if ($temp_c < 11) {
$font_color = "\#0000FF";
}
print HOUTPUT "<font color=$font_color>";
print HOUTPUT "$unit{$macindex}{disks}{$instance}{channel}: ";
print HOUTPUT "$unit{$macindex}{disks}{$instance}{tmps} ";
print HOUTPUT "$unit{$macindex}{disks}{$instance}{model} ";
if (uc $unit{$macindex}{disks}{$instance}{errors} eq "NONE") {
print HOUTPUT "(" . uc $unit{$macindex}{disks}{$instance}{status} . ")";
}else{
print HOUTPUT "(" . uc $unit{$macindex}{disks}{$instance}{status} . ";" . $unit{$macindex}{disks}{$instance}{errors} . ")";
}
print HOUTPUT "</font>";
}
}
print HOUTPUT "</tr>\n";
}
}
print HOUTPUT "</table>\n";
print HOUTPUT "<p><small>sample_webstats.pl v$_VERSION (" . getLibraryTitle() . " v" . getLibraryVersion() . ")\n";
print HOUTPUT "</body><html>\n";
close HOUTPUT;
exit(0);
#-------------------------------------------------------------
sub getAdminAddress{
my $ipaddr = shift;
my $dnsname= "";
if ($dnsname eq "") {
((my $host, my $aliases, my $addrtype, my $len, my @addrlist) = gethostbyaddr(inet_aton($ipaddr), AF_INET));
$dnsname = $host;
}
if ($dnsname eq "") {
$dnsname = gethostbyaddr(inet_aton($ipaddr),AF_INET);
}
if ($dnsname eq "") {
$dnsname = $unit{$macindex}{hostname}{0};
}
if ($dnsname eq "") {
$dnsname = $ipaddr;
}
return $dnsname;
}