]>
Commit | Line | Data |
---|---|---|
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 | ############################################################################ | |
24 | ||
25 | use strict; | |
26 | #use warnings; | |
27 | ||
28 | use RRDs; | |
29 | require "/var/ipfire/general-functions.pl"; | |
30 | require "${General::swroot}/lang.pl"; | |
31 | ||
32 | # Settings | |
33 | $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"; | |
34 | my $temp = ''; | |
35 | my $ERROR; | |
36 | my $path_smartctl = "/usr/sbin/smartctl"; | |
37 | ||
38 | my %color = (); | |
39 | my %mainsettings = (); | |
40 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
41 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
42 | ||
43 | sub updatehdddata | |
44 | { | |
45 | my $disk = $_[0]; | |
46 | my $standby; | |
47 | my @array = split(/\//,$disk); | |
48 | ||
49 | if ( ! -e "$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd"){ | |
50 | # database did not exist -> create | |
51 | RRDs::create ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "--step=300", | |
52 | "DS:standby:GAUGE:600:0:1", | |
53 | "RRA:AVERAGE:0.5:1:576", | |
54 | "RRA:AVERAGE:0.5:6:672", | |
55 | "RRA:AVERAGE:0.5:24:732", | |
56 | "RRA:AVERAGE:0.5:144:1460"); | |
57 | $ERROR = RRDs::error; | |
58 | print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR; | |
59 | } | |
60 | ||
61 | if (-e "/tmp/hddshutdown-".$array[$#array]) {$standby = 1;} | |
62 | else {$standby = 0;} | |
63 | ||
64 | RRDs::update ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby"); | |
65 | $ERROR = RRDs::error; | |
66 | print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR; | |
67 | ||
68 | if ( ! -e "$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd"){ | |
69 | # database did not exist -> create | |
70 | RRDs::create ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "--step=300", | |
71 | "DS:temperature:GAUGE:600:0:100", | |
72 | "RRA:AVERAGE:0.5:1:576", | |
73 | "RRA:AVERAGE:0.5:6:672", | |
74 | "RRA:AVERAGE:0.5:24:732", | |
75 | "RRA:AVERAGE:0.5:144:1460"); | |
76 | $ERROR = RRDs::error; | |
77 | print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR; | |
78 | } | |
79 | ||
80 | # Temperaturlesen w�rde die Platte aufwecken!!! | |
81 | if (!$standby){ | |
82 | $temp = 0; | |
83 | my $smart_output = ''; | |
84 | system("$path_smartctl -iHA -d ata /dev/$disk > /var/log/smartctl_out_hddtemp-$disk"); | |
85 | if ( -e "/var/log/smartctl_out_hddtemp-".$array[$#array] ){ | |
86 | my $hdd_output = `cat /var/log/smartctl_out_hddtemp-$array[$#array] | grep Temperature_`; | |
87 | my @t = split(/\s+/,$hdd_output); | |
88 | $temp = $t[9]; | |
89 | }else{$temp = 0;} | |
90 | print "Temperature for ".$array[$#array]."->".$temp."<-\n"; | |
91 | # Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht) | |
92 | if ($temp){ | |
93 | RRDs::update ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp"); | |
94 | $ERROR = RRDs::error; | |
95 | print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR; | |
96 | } | |
97 | } | |
98 | } | |
99 | ||
100 | ## Update ipac logs | |
101 | #system ('/usr/sbin/fetchipac'); | |
102 | ## Update vnstat | |
103 | system ('/usr/bin/vnstat -u'); | |
104 | ||
105 | my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`; | |
106 | system("unlink /tmp/hddstatus && touch /tmp/hddstatus"); | |
107 | foreach (@disks){ | |
108 | my $disk = $_; | |
109 | chomp $disk; | |
110 | print "Working on disk ".$disk.".\n"; | |
111 | ||
112 | my $status = ""; | |
113 | my $diskstats = ""; | |
114 | my $newdiskstats = ""; | |
115 | my @array = split(/\//,$disk); | |
116 | ||
117 | $diskstats = `cat /tmp/hddstats-$array[$#array]`; | |
118 | chomp $diskstats; | |
119 | my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -2 | head -1 | awk '{ print \$5","\$6}'`; | |
120 | chomp $newdiskstats; | |
121 | my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`; | |
122 | chomp $status; | |
123 | ||
124 | if ($status !~/standby/ || $diskstats ne $newdiskstats){ | |
125 | if (-e "/tmp/hddshutdown-".$array[$#array]){system("unlink /tmp/hddshutdown-".$array[$#array]);} | |
126 | } | |
127 | ||
128 | if (-e "/tmp/hddshutdown-".$array[$#array]){$status = " standby\n";} | |
129 | else{$status = " active\n";} | |
130 | ||
131 | open(DATEI, ">>/tmp/hddstatus") || die "Datei nicht gefunden"; | |
132 | print DATEI $disk."-".$status; | |
133 | close(DATEI); | |
134 | ||
135 | updatehdddata($disk); | |
136 | } |