]>
Commit | Line | Data |
---|---|---|
cd1a2927 MT |
1 | #!/usr/bin/perl |
2 | ||
3 | ############################################################################ | |
4 | # # | |
5 | # This file is part of the IPCop Firewall. # | |
6 | # # | |
7 | # IPCop is free software; you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation; either version 2 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # IPCop is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with IPCop; if not, write to the Free Software # | |
19 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # | |
20 | # # | |
21 | # Copyright (C) 2004-01-19 Mark Wormgoor <mark@wormgoor.com>. # | |
22 | # # | |
23 | ############################################################################ | |
60cbd6e7 | 24 | |
cd1a2927 MT |
25 | use strict; |
26 | #use warnings; | |
27 | ||
28 | use RRDs; | |
986e08d9 | 29 | require "/var/ipfire/general-functions.pl"; |
cd1a2927 MT |
30 | require "${General::swroot}/lang.pl"; |
31 | ||
32 | my (%settings, @ipacsum, $iface, $ERROR); | |
33 | &General::readhash("${General::swroot}/ethernet/settings", \%settings); | |
52345790 MT |
34 | my %mbmon_settings = (); |
35 | &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings); | |
36 | ||
cd1a2927 MT |
37 | # Added for conversion of utf-8 characters |
38 | use Encode 'from_to'; | |
39 | my %tr=(); | |
40 | ||
de53a053 CS |
41 | system("chmod 777 /srv/web/ipfire/html/graphs"); |
42 | ||
cd1a2927 MT |
43 | # Force language back to English (ugly hack!) |
44 | # Modified to only force if we are unable to convert charset | |
45 | # from utf-8 | |
46 | if ((${Lang::language} eq 'el') || | |
47 | (${Lang::language} eq 'fa') || | |
48 | (${Lang::language} eq 'ru') || | |
49 | (${Lang::language} eq 'th') || | |
50 | (${Lang::language} eq 'vi') || | |
51 | (${Lang::language} eq 'zh') || | |
52 | (${Lang::language} eq 'zt')) { | |
350b52c5 | 53 | eval `/bin/cat "${General::swroot}/langs/en.pl"`; |
cd1a2927 | 54 | } else { |
350b52c5 | 55 | %tr=%Lang::tr; # use translated version for other languages |
cd1a2927 MT |
56 | } |
57 | ||
58 | # Settings | |
59 | my $rrdlog = "/var/log/rrd"; | |
fd0763dc | 60 | my $graphs = "/srv/web/ipfire/html/graphs"; |
cd1a2927 | 61 | $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"; |
60cbd6e7 | 62 | my $hdd_device = "/dev/harddisk"; |
a68fedca | 63 | my $temp = ''; |
52345790 MT |
64 | my %mbmon_values = (); |
65 | my $key; | |
66 | my $value; | |
67 | my @args = (); | |
68 | my $count = 0; | |
69 | my $ERROR; | |
70 | my $dbg = 0; | |
52345790 | 71 | my $path_smartctl = "/usr/sbin/smartctl"; |
e3a8510a | 72 | my $path_hddtemp = "/usr/sbin/hddtemp"; |
52345790 | 73 | |
4b4aec3a CS |
74 | my %color = (); |
75 | my %mainsettings = (); | |
76 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
77 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
52345790 MT |
78 | |
79 | open(MBMON_OUT, ">/var/log/mbmon-values"); | |
80 | open(FD, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ; | |
81 | ||
82 | while( $_ = <FD> ) | |
83 | { | |
84 | next unless( /^([A-Za-z][^:\s]+)\s*:\s*([+\-]{0,1}[\d\.]+)/ ) ; | |
85 | $key = $1 ; | |
86 | $value = $2 ; | |
87 | $key =~ y/A-Z/a-z/ ; | |
88 | $mbmon_values{$key} = $value; | |
89 | print(MBMON_OUT "$key=$value\n"); | |
90 | } | |
91 | close(FD); | |
92 | close(MBMON_OUT); | |
cd1a2927 MT |
93 | |
94 | sub gettraffic { | |
350b52c5 | 95 | my $interface = $_[0]; |
cd1a2927 | 96 | |
350b52c5 CS |
97 | my $bytesin=0; |
98 | my $bytesout=0; | |
cd1a2927 | 99 | |
350b52c5 CS |
100 | foreach (@ipacsum) |
101 | { | |
102 | # Incoming... | |
103 | $bytesin += $1 if (/^[\* ]\s+incoming\s+${interface}.+\:\s+(\d+)/); | |
cd1a2927 | 104 | |
350b52c5 CS |
105 | # Forwarded Incoming... |
106 | $bytesin += $1 if (/^[\* ]\s+forwarded\s+incoming\s+${interface}.+\:\s+(\d+)/); | |
cd1a2927 | 107 | |
350b52c5 CS |
108 | # Outgoing... |
109 | $bytesout += $1 if (/^[* ]\s+outgoing\s+${interface}.+\:\s+(\d+)/); | |
cd1a2927 | 110 | |
350b52c5 CS |
111 | # Forwarded Outgoing... |
112 | $bytesout += $1 if (/^[* ]\s+forwarded\s+outgoing\s+${interface}.+\:\s+(\d+)/); | |
113 | } | |
114 | return "$bytesin:$bytesout"; | |
cd1a2927 MT |
115 | } |
116 | ||
117 | sub updatecpudata { | |
350b52c5 CS |
118 | if ( ! -e "$rrdlog/cpu.rrd") { |
119 | RRDs::create ("$rrdlog/cpu.rrd", "--step=300", | |
60412147 CS |
120 | "DS:user:COUNTER:600:0:500000000", |
121 | "DS:system:COUNTER:600:0:500000000", | |
122 | "DS:idle:COUNTER:600:0:500000000", | |
123 | "DS:iowait:COUNTER:600:0:500000000", | |
124 | "DS:irq:COUNTER:600:0:500000000", | |
350b52c5 CS |
125 | "RRA:AVERAGE:0.5:1:576", |
126 | "RRA:AVERAGE:0.5:6:672", | |
127 | "RRA:AVERAGE:0.5:24:732", | |
128 | "RRA:AVERAGE:0.5:144:1460"); | |
129 | $ERROR = RRDs::error; | |
130 | print "Error in RRD::create for cpu: $ERROR\n" if $ERROR; | |
131 | } | |
132 | ||
60412147 | 133 | my ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq); |
350b52c5 | 134 | |
60412147 CS |
135 | open STAT, "/proc/stat"; |
136 | while(<STAT>) { | |
137 | chomp; | |
138 | /^cpu\s/ or next; | |
139 | ($cpu, $user, $nice, $system, $idle, $iowait, $irq, $softirq) = split /\s+/; | |
140 | last; | |
141 | } | |
142 | close STAT; | |
350b52c5 | 143 | $user += $nice; |
60412147 CS |
144 | $irq += $softirq; |
145 | ||
350b52c5 CS |
146 | |
147 | RRDs::update ("$rrdlog/cpu.rrd", | |
60412147 CS |
148 | "-t", "user:system:idle:iowait:irq", |
149 | "N:$user:$system:$idle:$iowait:$irq"); | |
350b52c5 CS |
150 | $ERROR = RRDs::error; |
151 | print "Error in RRD::update for cpu: $ERROR\n" if $ERROR; | |
cd1a2927 MT |
152 | |
153 | } | |
154 | ||
207cc1cf | 155 | sub updateloaddata { |
350b52c5 CS |
156 | if ( ! -e "$rrdlog/load.rrd") { |
157 | RRDs::create ("$rrdlog/load.rrd", "--step=60", | |
158 | "DS:load1:GAUGE:120:0:U", | |
159 | "DS:load5:GAUGE:120:0:U", | |
160 | "DS:load15:GAUGE:120:0:U", | |
161 | "RRA:AVERAGE:0.5:1:2160", | |
162 | "RRA:AVERAGE:0.5:5:2016", | |
163 | "RRA:AVERAGE:0.5:15:2880", | |
164 | "RRA:AVERAGE:0.5:60:8760"); | |
207cc1cf | 165 | |
350b52c5 CS |
166 | $ERROR = RRDs::error; |
167 | print "Error in RRD::create for cpu: $ERROR\n" if $ERROR; | |
168 | } | |
cd1a2927 MT |
169 | } |
170 | ||
171 | sub updatememdata { | |
350b52c5 CS |
172 | my ($memused, $memfree, $memshared, $membuffers, $memcache, $swapused, $swapfree, $swaptotal); |
173 | if ( ! -e "$rrdlog/mem.rrd") { | |
174 | RRDs::create ("$rrdlog/mem.rrd", "--step=300", | |
175 | "DS:memused:ABSOLUTE:600:0:5000000000", | |
176 | "DS:memfree:ABSOLUTE:600:0:5000000000", | |
177 | "DS:memshared:ABSOLUTE:600:0:5000000000", | |
178 | "DS:membuffers:ABSOLUTE:600:0:5000000000", | |
179 | "DS:memcache:ABSOLUTE:600:0:5000000000", | |
180 | "DS:swapused:ABSOLUTE:600:0:5000000000", | |
181 | "DS:swapfree:ABSOLUTE:600:0:5000000000", | |
182 | "RRA:AVERAGE:0.5:1:576", | |
183 | "RRA:AVERAGE:0.5:6:672", | |
184 | "RRA:AVERAGE:0.5:24:732", | |
185 | "RRA:AVERAGE:0.5:144:1460"); | |
186 | $ERROR = RRDs::error; | |
187 | print "Error in RRD::create for mem: $ERROR\n" if $ERROR; | |
188 | } | |
189 | ||
190 | open MEM, "/proc/meminfo"; | |
191 | while(<MEM>) { | |
192 | chomp; | |
193 | if ($_ =~ /^MemTotal:/) { | |
194 | my @temp = split (/\s+/, $_); | |
195 | $memused = $temp[1]; | |
196 | } elsif ($_ =~ /^MemFree:/) { | |
197 | my @temp = split (/\s+/, $_); | |
198 | $memfree = $temp[1]; | |
199 | } elsif ($_ =~ /^Cached:/) { | |
200 | my @temp = split (/\s+/, $_); | |
201 | $memcache = $temp[1]; | |
202 | } elsif ($_ =~ /^Buffers:/) { | |
203 | my @temp = split (/\s+/, $_); | |
204 | $membuffers = $temp[1]; | |
205 | } elsif ($_ =~ /^SwapTotal:/) { | |
206 | my @temp = split (/\s+/, $_); | |
207 | $swaptotal = $temp[1]; | |
208 | } elsif ($_ =~ /^SwapFree:/) { | |
209 | my @temp = split (/\s+/, $_); | |
210 | $swapfree = $temp[1]; | |
211 | } | |
212 | } | |
213 | close MEM; | |
214 | ||
215 | system("/bin/df > /tmp/diskfree"); | |
216 | open DF, "/tmp/diskfree"; | |
217 | while(<DF>) { | |
218 | chomp; | |
219 | if ($_ =~ /^shm/) { | |
220 | my @temp = split (/\s+/, $_); | |
221 | $memshared = $temp[2]; | |
222 | } | |
223 | } | |
224 | close DF; | |
225 | system("/bin/rm -f /tmp/diskfree"); | |
226 | ||
227 | $swapused = $swaptotal-$swapfree; | |
228 | RRDs::update ("$rrdlog/mem.rrd", | |
229 | "-t", "memused:memfree:memshared:membuffers:memcache:swapused:swapfree", | |
230 | "N:$memused:$memfree:$memshared:$membuffers:$memcache:$swapused:$swapfree"); | |
231 | $ERROR = RRDs::error; | |
232 | print "Error in RRD::update for mem: $ERROR\n" if $ERROR; | |
cd1a2927 MT |
233 | } |
234 | ||
235 | sub updatediskdata { | |
350b52c5 CS |
236 | my $disk = $_[0]; |
237 | my ($readsect, $writesect, $trash); | |
238 | if ( ! -e "$rrdlog/disk-$disk.rrd") { | |
239 | RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300", | |
240 | "DS:readsect:COUNTER:600:0:5000000000", | |
241 | "DS:writesect:COUNTER:600:0:5000000000", | |
242 | "RRA:AVERAGE:0.5:1:576", | |
243 | "RRA:AVERAGE:0.5:6:672", | |
244 | "RRA:AVERAGE:0.5:24:732", | |
245 | "RRA:AVERAGE:0.5:144:1460"); | |
246 | $ERROR = RRDs::error; | |
247 | print "Error in RRD::create for disk $disk: $ERROR\n" if $ERROR; | |
248 | } | |
249 | ||
250 | my $Zeilen = `/usr/bin/iostat $disk | tail -2 | head -1`; | |
251 | ($trash, $trash, $trash, $trash, $readsect, $writesect) = split(/\s+/,$Zeilen); | |
252 | ||
253 | print "\nread:".$readsect."write:".$writesect."\n"; | |
254 | ||
255 | if ($readsect && $writesect) { | |
256 | RRDs::update ("$rrdlog/disk-$disk.rrd", | |
257 | "-t", "readsect:writesect", | |
258 | "N:$readsect:$writesect"); | |
259 | $ERROR = RRDs::error; | |
260 | print "Error in RRD::update for disk $disk: $ERROR\n" if $ERROR; | |
261 | } else { | |
262 | print "Error in RRD::update for disk: $disk no data available\n"; | |
263 | } | |
cd1a2927 MT |
264 | } |
265 | ||
266 | sub updateifdata { | |
350b52c5 CS |
267 | my $interface = $_[0]; |
268 | ||
269 | if ( ! -e "$rrdlog/$interface.rrd") { | |
270 | RRDs::create ("$rrdlog/$interface.rrd", "--step=300", | |
271 | "DS:incoming:ABSOLUTE:600:0:12500000", | |
272 | "DS:outgoing:ABSOLUTE:600:0:12500000", | |
273 | "RRA:AVERAGE:0.5:1:576", | |
274 | "RRA:AVERAGE:0.5:6:672", | |
275 | "RRA:AVERAGE:0.5:24:732", | |
276 | "RRA:AVERAGE:0.5:144:1460"); | |
277 | $ERROR = RRDs::error; | |
278 | print "Error in RRD::create for $interface: $ERROR\n" if $ERROR; | |
279 | } | |
280 | ||
281 | my $traffic = gettraffic ($interface); | |
282 | RRDs::update ("$rrdlog/$interface.rrd", | |
283 | "-t", "incoming:outgoing", | |
284 | "N:$traffic"); | |
285 | $ERROR = RRDs::error; | |
286 | print "Error in RRD::update for $interface: $ERROR\n" if $ERROR; | |
df8c7810 MT |
287 | } |
288 | ||
289 | sub updatefwhitsdata { | |
350b52c5 CS |
290 | my $portamount=0; |
291 | my $alertaktuell=0; | |
292 | my $aktuell=0; | |
293 | my $portaktuell=0; | |
294 | my $skip=0; | |
295 | ||
296 | if (! -e "$rrdlog/firewallhits.rrd") | |
297 | { | |
298 | RRDs::create ("$rrdlog/firewallhits.rrd", "--step=300", | |
299 | "DS:amount:GAUGE:600:0:U", | |
300 | "DS:portamount:GAUGE:600:0:U", | |
301 | "RRA:AVERAGE:0.5:1:576", | |
302 | "RRA:AVERAGE:0.5:6:672", | |
303 | "RRA:AVERAGE:0.5:24:732", | |
304 | "RRA:AVERAGE:0.5:144:1460"); | |
305 | $ERROR = RRDs::error; | |
306 | print "Error in RRD::create for cpu: $ERROR\n" if $ERROR; | |
307 | } | |
308 | ||
309 | system("logtailfwhits /var/log/messages /var/log/fwhits.messages.offset >/tmp/messages.fwhits"); | |
310 | if (!(open (FILE,'/tmp/messages.fwhits'))) { | |
df8c7810 | 311 | $skip=1; |
350b52c5 CS |
312 | } |
313 | $aktuell = 0; | |
314 | if (!$skip) { | |
315 | while (<FILE>) { | |
316 | if (/kernel:.*(IN=.*)$/) { | |
317 | $aktuell++; | |
318 | } | |
319 | } | |
320 | close (FILE); | |
321 | } | |
322 | ||
323 | system("logtailfwhits /var/log/snort/alert /var/log/snort/fwhits.alert.offset >/tmp/snort.fwhits"); | |
324 | if (!(open (FILE,'/tmp/snort.fwhits'))) { | |
df8c7810 | 325 | $skip=1; |
350b52c5 CS |
326 | } |
327 | $alertaktuell = 0; | |
328 | if (!$skip) { | |
329 | while (<FILE>) { | |
330 | if (/scan.*$/) { | |
331 | $alertaktuell++; | |
332 | } | |
333 | } | |
334 | close (FILE); | |
335 | } | |
336 | ||
337 | if (!(open (FILE,'/tmp/messages.fwhits'))) { | |
df8c7810 | 338 | $skip=1; |
350b52c5 CS |
339 | } |
340 | $portaktuell = 0; | |
341 | if (!$skip) { | |
342 | while (<FILE>) { | |
343 | if (/kernel:.*(Scan.*)$/) { | |
344 | $portaktuell++; | |
345 | } | |
346 | } | |
347 | close (FILE); | |
348 | } | |
349 | ||
350 | system("rm /tmp/messages.fwhits"); | |
351 | system("rm /tmp/snort.fwhits"); | |
352 | ||
353 | $portamount = $portaktuell + $alertaktuell; | |
354 | chomp($portamount); | |
355 | RRDs::update ("$rrdlog/firewallhits.rrd", | |
356 | "N:$aktuell:$portamount"); | |
357 | $ERROR = RRDs::error; | |
358 | print "Error in RRD::update for Firewallhits: $ERROR\n" if $ERROR; | |
df8c7810 MT |
359 | } |
360 | ||
072cd997 MT |
361 | # Creates and updates a link quality database |
362 | # ------------------------------------------- | |
363 | sub updatelq { | |
350b52c5 CS |
364 | if ( ! -e "$rrdlog/lq.rrd") { |
365 | RRDs::create ("$rrdlog/lq.rrd", "--step=300", | |
366 | "DS:loss:GAUGE:600:0:100", | |
367 | "DS:roundtrip:GAUGE:600:0:10000", | |
368 | "RRA:AVERAGE:0.5:1:576", | |
369 | "RRA:AVERAGE:0.5:6:672", | |
370 | "RRA:AVERAGE:0.5:24:732", | |
371 | "RRA:AVERAGE:0.5:144:1460"); | |
372 | $ERROR = RRDs::error; | |
373 | print "Error in RRD::create for link: $ERROR\n" if $ERROR; | |
374 | } | |
375 | my $packetloss=0; | |
376 | my $roundtrip=0; | |
377 | my $test=0; | |
378 | # LQ_GATEWAY is the ip of your isp's public ip facing you | |
cce90b0b CS |
379 | my $LQ_GATEWAY=`cat /var/ipfire/red/remote-ipaddress`; |
380 | chomp($LQ_GATEWAY); | |
381 | my $NUMPINGS=5; | |
a28fdc01 | 382 | my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q $LQ_GATEWAY | tail -2`; |
350b52c5 | 383 | my @temp = split (/\/|\%|\s/, $pingoutput); |
a28fdc01 CS |
384 | $packetloss = $temp[5]; |
385 | $roundtrip = $temp[17]; | |
386 | ||
387 | print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n"; | |
388 | ||
389 | if ( $packetloss eq "100" ){ | |
390 | my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q ping.ipfire.org | tail -2`; | |
391 | my @temp = split (/\/|\%|\s/, $pingoutput); | |
392 | $packetloss = $temp[5]; | |
393 | $roundtrip = $temp[17]; | |
394 | ||
395 | print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n"; | |
396 | } | |
397 | ||
350b52c5 CS |
398 | RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip"); |
399 | $ERROR = RRDs::error; | |
400 | print "Error in RRD::update for line quality: $ERROR\n" if $ERROR; | |
072cd997 MT |
401 | } |
402 | ||
60cbd6e7 MT |
403 | sub updatehdddata |
404 | { | |
9217f236 MT |
405 | my $disk = $_[0]; |
406 | if ( ! -e "$rrdlog/hddtemp-$disk.rrd") | |
60cbd6e7 MT |
407 | { |
408 | # database did not exist -> create | |
9217f236 | 409 | RRDs::create ("$rrdlog/hddtemp-$disk.rrd", "--step=300", |
60cbd6e7 MT |
410 | "DS:temperature:GAUGE:600:0:100", |
411 | "RRA:AVERAGE:0.5:1:576", | |
412 | "RRA:AVERAGE:0.5:6:672", | |
413 | "RRA:AVERAGE:0.5:24:732", | |
414 | "RRA:AVERAGE:0.5:144:1460"); | |
415 | $ERROR = RRDs::error; | |
9217f236 | 416 | print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR; |
60cbd6e7 | 417 | } |
52345790 MT |
418 | $temp = 0; |
419 | my $hdd_output = ''; | |
420 | my $smart_output = ''; | |
249dda69 | 421 | |
52345790 | 422 | if ( -e "$path_smartctl" ) |
60cbd6e7 | 423 | { |
9217f236 | 424 | system("$path_smartctl -iHA /dev/$disk > /var/log/smartctl_out_hddtemp-$disk"); |
60cbd6e7 | 425 | } |
52345790 MT |
426 | |
427 | if ( -e "$path_hddtemp" ) | |
60cbd6e7 | 428 | { |
9217f236 | 429 | $hdd_output = `$path_hddtemp -qn /dev/$disk`; |
249dda69 | 430 | |
52345790 MT |
431 | # I know 4 response possible responses: |
432 | # | |
433 | # /dev/harddisk: harddisk type: S.M.A.R.T. not available | |
434 | # /dev/harddisk: harddisk type: no sensor | |
350b52c5 | 435 | # /dev/harddisk: harddisk type: 37?C or ?F |
52345790 MT |
436 | # 37 |
437 | ||
438 | if ( index($hdd_output, "S.M.A.R.T.") != -1 ) | |
439 | { | |
440 | $temp = 0; | |
441 | } | |
442 | elsif ( index($hdd_output, "no sensor") != -1 ) | |
443 | { | |
444 | $temp = 1; | |
445 | } | |
9217f236 | 446 | elsif ( index($hdd_output, "$disk") != -1 ) |
52345790 MT |
447 | { |
448 | $hdd_output =~ /.*:.*:\s*(\d+).*\s/; | |
449 | $temp = $1; | |
450 | } | |
451 | else | |
452 | { | |
453 | $hdd_output =~ /(\d+)\s/; | |
454 | $temp = $1; | |
455 | } | |
60cbd6e7 | 456 | } |
9217f236 | 457 | elsif ( -e "/var/log/smartctl_out_hddtemp-$disk" ) |
60cbd6e7 | 458 | { |
9217f236 | 459 | $hdd_output = `cat /var/log/smartctl_out_hddtemp-$disk | grep Temperature_`; |
52345790 MT |
460 | my @t = split(/\s+/,$hdd_output); |
461 | $temp = $t[9]; | |
60cbd6e7 MT |
462 | } |
463 | else | |
464 | { | |
52345790 | 465 | $temp = 0; |
60cbd6e7 | 466 | } |
249dda69 | 467 | |
60cbd6e7 | 468 | |
249dda69 | 469 | print "Temperature for ".$disk."->".$temp."<-\n"; |
52345790 | 470 | |
9217f236 | 471 | RRDs::update ("$rrdlog/hddtemp-$disk.rrd", "-t", "temperature", "N:$temp"); |
60cbd6e7 | 472 | $ERROR = RRDs::error; |
9217f236 | 473 | print "Error in RRD::update for hdd-$disk: $ERROR\n" if $ERROR; |
60cbd6e7 MT |
474 | } |
475 | ||
52345790 MT |
476 | sub updatembmondata |
477 | { | |
e3a8510a | 478 | if ( ! -e "$rrdlog/mbmon.rrd" ) |
52345790 MT |
479 | { |
480 | # database did not exist -> create | |
481 | ||
e3a8510a | 482 | @args = ("$rrdlog/mbmon.rrd"); |
52345790 MT |
483 | |
484 | push(@args, "--step=300"); | |
485 | foreach $key ( sort(keys %mbmon_values) ) | |
486 | { | |
487 | push(@args, "DS:$key:GAUGE:600:U:U"); | |
488 | } | |
489 | push(@args, "RRA:AVERAGE:0.5:1:576"); | |
490 | push(@args, "RRA:AVERAGE:0.5:6:672"); | |
491 | push(@args, "RRA:AVERAGE:0.5:24:732"); | |
492 | push(@args, "RRA:AVERAGE:0.5:144:1460"); | |
493 | ||
494 | print("create ". join( ", ", @args)) if ( $dbg ); | |
495 | ||
496 | RRDs::create (@args); | |
497 | $ERROR = RRDs::error; | |
498 | print("Error in RRD::create for mbmon: $ERROR\n") if $ERROR; | |
499 | } | |
500 | ||
501 | my @ds; | |
502 | my @val; | |
503 | my $template; | |
504 | ||
505 | foreach $key ( sort(keys %mbmon_values) ) | |
506 | { | |
507 | push(@ds, $key); | |
508 | push(@val, $mbmon_values{$key}); | |
509 | } | |
510 | ||
511 | $template = join(':', @ds); | |
512 | $value = "N:".join(':', @val); | |
513 | ||
514 | print("update template = '$template'\n") if ( $dbg ); | |
515 | print("update value = '$value'\n") if ( $dbg ); | |
516 | ||
e3a8510a | 517 | RRDs::update("$rrdlog/mbmon.rrd", "-t", $template, $value); |
52345790 MT |
518 | $ERROR = RRDs::error; |
519 | print("Error in RRD::update for mbmon: $ERROR\n") if $ERROR; | |
520 | } | |
521 | ||
cd1a2927 MT |
522 | ## Update ipac logs |
523 | system ('/usr/sbin/fetchipac'); | |
524 | sleep 8; | |
525 | ||
526 | ### | |
527 | ### Squid Graphs | |
528 | ### | |
529 | if ( -e "/var/log/squid/access.log") { | |
350b52c5 | 530 | system ("/usr/bin/squid-graph -o=/srv/web/ipfire/html/sgraph --tcp-only < /var/log/squid/access.log >/dev/null 2>&1"); |
cd1a2927 MT |
531 | } |
532 | ||
533 | ### | |
534 | ### utf8 conversion | |
535 | ### | |
536 | if ((${Lang::language} eq 'cs') || | |
537 | (${Lang::language} eq 'hu') || | |
538 | (${Lang::language} eq 'pl') || | |
539 | (${Lang::language} eq 'sk')) { | |
350b52c5 CS |
540 | # Czech, Hungarian, Polish and Slovak character set |
541 | foreach my $key(keys %Lang::tr) { | |
542 | from_to($tr{$key}, "utf-8", "iso-8859-2"); | |
543 | } | |
cd1a2927 | 544 | } elsif (${Lang::language} eq 'tr') { |
350b52c5 CS |
545 | # Turkish |
546 | foreach my $key(keys %Lang::tr) { | |
547 | from_to($tr{$key}, "utf-8", "iso-8859-9"); | |
548 | } | |
cd1a2927 | 549 | } else { |
350b52c5 CS |
550 | foreach my $key(keys %Lang::tr) { |
551 | from_to($tr{$key}, "utf-8", "iso-8859-1"); | |
552 | } | |
cd1a2927 MT |
553 | } |
554 | ||
555 | ### | |
556 | ### System graphs | |
557 | ### | |
558 | updatecpudata(); | |
207cc1cf | 559 | updateloaddata(); |
cd1a2927 | 560 | updatememdata(); |
6c666a3b | 561 | |
249dda69 CS |
562 | ### |
563 | ### HDD graphs | |
564 | ### | |
565 | ||
3bc32eab | 566 | |
350b52c5 | 567 | my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`; |
3bc32eab | 568 | system("unlink /tmp/hddstatus && touch /tmp/hddstatus"); |
350b52c5 CS |
569 | print "\nFound following amount of disks:".@disks."\n"; |
570 | foreach (@disks){ | |
571 | my $disk = $_; | |
572 | chomp $disk; | |
573 | print "Working on disk ".$disk.".\n"; | |
3bc32eab | 574 | |
350b52c5 | 575 | updatediskdata($disk); |
249dda69 | 576 | updatehdddata($disk); |
3bc32eab CS |
577 | |
578 | my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`; | |
579 | open(DATEI, ">>/tmp/hddstatus") || die "Datei nicht gefunden"; | |
580 | print DATEI $disk."-".$status; | |
581 | close(DATEI); | |
6c666a3b MT |
582 | } |
583 | ||
df8c7810 MT |
584 | ### |
585 | ### Firewallhits | |
586 | ### | |
587 | updatefwhitsdata(); | |
df8c7810 | 588 | |
072cd997 MT |
589 | ### |
590 | ### Link Quality | |
591 | ### | |
592 | updatelq(); | |
072cd997 | 593 | |
60cbd6e7 | 594 | ### |
249dda69 | 595 | ### Mbmon Data |
60cbd6e7 | 596 | ### |
249dda69 | 597 | updatembmondata(); |
52345790 | 598 | |
cd1a2927 MT |
599 | ### |
600 | ### Network Graphs | |
601 | ### | |
602 | @ipacsum = `/usr/sbin/ipacsum --exact -s 5m 2>/dev/null`; | |
603 | if (@ipacsum) { | |
350b52c5 CS |
604 | updateifdata ("GREEN"); |
605 | updateifdata ("RED"); | |
606 | if ($settings{'CONFIG_TYPE'} =~ /^(2|4)$/ ) { | |
607 | updateifdata ("ORANGE"); | |
608 | } | |
609 | if ($settings{'CONFIG_TYPE'} =~ /^(3|4)$/ ) { | |
610 | updateifdata ("BLUE"); | |
611 | } | |
cd1a2927 | 612 | } |