]>
Commit | Line | Data |
---|---|---|
cd1a2927 MT |
1 | #!/usr/bin/perl |
2 | ||
5468f102 CS |
3 | ############################################################################### |
4 | # # | |
5 | # IPFire.org - A linux based firewall # | |
6 | # Copyright (C) 2008 Michael Tremer & Christian Schmidt # | |
7 | # # | |
8 | # This program is free software: you can redistribute it and/or modify # | |
9 | # it under the terms of the GNU General Public License as published by # | |
10 | # the Free Software Foundation, either version 3 of the License, or # | |
11 | # (at your option) any later version. # | |
12 | # # | |
13 | # This program is distributed in the hope that it will be useful, # | |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
16 | # GNU General Public License for more details. # | |
17 | # # | |
18 | # You should have received a copy of the GNU General Public License # | |
19 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
20 | # # | |
21 | ############################################################################### | |
60cbd6e7 | 22 | |
cd1a2927 MT |
23 | use strict; |
24 | #use warnings; | |
25 | ||
26 | use RRDs; | |
986e08d9 | 27 | require "/var/ipfire/general-functions.pl"; |
cd1a2927 MT |
28 | require "${General::swroot}/lang.pl"; |
29 | ||
cd1a2927 | 30 | # Settings |
cd1a2927 | 31 | $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"; |
a68fedca | 32 | my $temp = ''; |
52345790 | 33 | my $ERROR; |
52345790 MT |
34 | my $path_smartctl = "/usr/sbin/smartctl"; |
35 | ||
4b4aec3a CS |
36 | my %color = (); |
37 | my %mainsettings = (); | |
38 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
39 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
52345790 | 40 | |
5468f102 CS |
41 | sub updatehdddata{ |
42 | my $disk = $_[0]; | |
43 | my $standby; | |
44 | my @array = split(/\//,$disk); | |
45 | ||
46 | if ( ! -e "$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd"){ | |
47 | # database did not exist -> create | |
48 | RRDs::create ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "--step=300", | |
49 | "DS:standby:GAUGE:600:0:1", | |
50 | "RRA:AVERAGE:0.5:1:576", | |
51 | "RRA:AVERAGE:0.5:6:672", | |
52 | "RRA:AVERAGE:0.5:24:732", | |
53 | "RRA:AVERAGE:0.5:144:1460"); | |
54 | $ERROR = RRDs::error; | |
55 | print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR; | |
56 | } | |
57 | ||
58 | if (-e "/tmp/hddshutdown-".$array[$#array]) {$standby = 1;} | |
59 | else {$standby = 0;} | |
60 | ||
61 | RRDs::update ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby"); | |
62 | $ERROR = RRDs::error; | |
63 | print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR; | |
64 | ||
65 | if ( ! -e "$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd"){ | |
66 | # database did not exist -> create | |
67 | RRDs::create ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "--step=300", | |
68 | "DS:temperature:GAUGE:600:0:100", | |
69 | "RRA:AVERAGE:0.5:1:576", | |
70 | "RRA:AVERAGE:0.5:6:672", | |
71 | "RRA:AVERAGE:0.5:24:732", | |
72 | "RRA:AVERAGE:0.5:144:1460"); | |
73 | $ERROR = RRDs::error; | |
74 | print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR; | |
75 | } | |
76 | ||
77 | # Temperaturlesen w�rde die Platte aufwecken!!! | |
78 | if (!$standby){ | |
79 | $temp = 0; | |
80 | my $smart_output = ''; | |
81 | system("$path_smartctl -iHA -d ata /dev/$disk > /tmp/smartctl_out_hddtemp-$disk"); | |
82 | if ( -e "/tmp/smartctl_out_hddtemp-".$array[$#array] ){ | |
83 | my $hdd_output = `cat /tmp/smartctl_out_hddtemp-$array[$#array] | grep Temperature_`; | |
84 | my @t = split(/\s+/,$hdd_output); | |
85 | $temp = $t[9]; | |
86 | }else{$temp = 0;} | |
87 | print "Temperature for ".$array[$#array]."->".$temp."<-\n"; | |
88 | # Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht) | |
89 | if ($temp){ | |
90 | RRDs::update ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp"); | |
91 | $ERROR = RRDs::error; | |
92 | print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR; | |
93 | } | |
94 | } | |
52345790 MT |
95 | } |
96 | ||
6c33dc5c AF |
97 | ## Update vnstat |
98 | system ('/usr/bin/vnstat -u'); | |
3bc32eab | 99 | |
350b52c5 | 100 | my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`; |
3bc32eab | 101 | system("unlink /tmp/hddstatus && touch /tmp/hddstatus"); |
350b52c5 | 102 | foreach (@disks){ |
5468f102 CS |
103 | my $disk = $_; |
104 | chomp $disk; | |
105 | print "Working on disk ".$disk.".\n"; | |
106 | ||
107 | my $status = ""; | |
108 | my $diskstats = ""; | |
109 | my $newdiskstats = ""; | |
110 | my @array = split(/\//,$disk); | |
111 | ||
112 | $diskstats = `cat /tmp/hddstats-$array[$#array]`; | |
113 | chomp $diskstats; | |
114 | my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -2 | head -1 | awk '{ print \$5","\$6}'`; | |
115 | chomp $newdiskstats; | |
116 | my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`; | |
117 | chomp $status; | |
118 | ||
119 | if ($status !~/standby/ || $diskstats ne $newdiskstats){ | |
120 | if (-e "/tmp/hddshutdown-".$array[$#array]){system("unlink /tmp/hddshutdown-".$array[$#array]);} | |
121 | } | |
122 | ||
123 | if (-e "/tmp/hddshutdown-".$array[$#array]){$status = " standby\n";} | |
124 | else{$status = " active\n";} | |
125 | ||
126 | open(DATEI, ">>/tmp/hddstatus") || die "Datei nicht gefunden"; | |
127 | print DATEI $disk."-".$status; | |
128 | close(DATEI); | |
129 | ||
130 | updatehdddata($disk); | |
6c666a3b | 131 | } |