]>
Commit | Line | Data |
---|---|---|
cd1a2927 | 1 | #!/usr/bin/perl |
5468f102 CS |
2 | ############################################################################### |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
66c36198 | 5 | # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> # |
5468f102 CS |
6 | # # |
7 | # This program 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 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program 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 this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
60cbd6e7 | 21 | |
cd1a2927 MT |
22 | use strict; |
23 | #use warnings; | |
24 | ||
25 | use RRDs; | |
986e08d9 | 26 | require "/var/ipfire/general-functions.pl"; |
cd1a2927 MT |
27 | require "${General::swroot}/lang.pl"; |
28 | ||
cd1a2927 | 29 | # Settings |
cd1a2927 | 30 | $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"; |
a68fedca | 31 | my $temp = ''; |
52345790 | 32 | my $ERROR; |
52345790 MT |
33 | my $path_smartctl = "/usr/sbin/smartctl"; |
34 | ||
4b4aec3a CS |
35 | my %color = (); |
36 | my %mainsettings = (); | |
37 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
8186b372 | 38 | &General::readhash("/srv/web/ipfire/html/themes/ipfire/include/colors.txt", \%color); |
52345790 | 39 | |
dd7d74eb AF |
40 | if ( $mainsettings{'RRDLOG'} eq "" ){ |
41 | $mainsettings{'RRDLOG'}="/var/log/rrd"; | |
42 | &General::writehash("${General::swroot}/main/settings", \%mainsettings); | |
43 | } | |
44 | ||
5468f102 CS |
45 | sub updatehdddata{ |
46 | my $disk = $_[0]; | |
47 | my $standby; | |
48 | my @array = split(/\//,$disk); | |
49 | ||
50 | if ( ! -e "$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd"){ | |
51 | # database did not exist -> create | |
52 | RRDs::create ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "--step=300", | |
53 | "DS:standby:GAUGE:600:0:1", | |
54 | "RRA:AVERAGE:0.5:1:576", | |
55 | "RRA:AVERAGE:0.5:6:672", | |
56 | "RRA:AVERAGE:0.5:24:732", | |
57 | "RRA:AVERAGE:0.5:144:1460"); | |
58 | $ERROR = RRDs::error; | |
59 | print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR; | |
60 | } | |
61 | ||
965f4547 | 62 | if (-e "/var/run/hddshutdown-".$array[$#array]) {$standby = 1;} |
5468f102 CS |
63 | else {$standby = 0;} |
64 | ||
65 | RRDs::update ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby"); | |
66 | $ERROR = RRDs::error; | |
67 | print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR; | |
68 | ||
69 | if ( ! -e "$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd"){ | |
70 | # database did not exist -> create | |
71 | RRDs::create ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "--step=300", | |
72 | "DS:temperature:GAUGE:600:0:100", | |
73 | "RRA:AVERAGE:0.5:1:576", | |
74 | "RRA:AVERAGE:0.5:6:672", | |
75 | "RRA:AVERAGE:0.5:24:732", | |
76 | "RRA:AVERAGE:0.5:144:1460"); | |
77 | $ERROR = RRDs::error; | |
78 | print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR; | |
79 | } | |
80 | ||
81 | # Temperaturlesen w�rde die Platte aufwecken!!! | |
82 | if (!$standby){ | |
83 | $temp = 0; | |
84 | my $smart_output = ''; | |
bf97c674 | 85 | system("$path_smartctl -iHA /dev/$disk > /var/run/smartctl_out_hddtemp-$disk"); |
965f4547 | 86 | if ( -e "/var/run/smartctl_out_hddtemp-".$array[$#array] ){ |
ca9c45b3 AF |
87 | my $hdd_nvme = `grep "NVMe Log" /var/run/smartctl_out_hddtemp-$array[$#array]`; |
88 | if ( $hdd_nvme !~/NVMe Log/ ) { | |
89 | my $hdd_output = `cat /var/run/smartctl_out_hddtemp-$array[$#array] | grep Temperature_`; | |
90 | my @t = split(/\s+/,$hdd_output); | |
91 | $temp = $t[9]; | |
92 | } else { | |
93 | my $hdd_output = `cat /var/run/smartctl_out_hddtemp-$array[$#array] | grep Temperature:`; | |
94 | my @t = split(/\s+/,$hdd_output); | |
95 | $temp = $t[1]; | |
96 | } | |
97 | } else { $temp = 0; } | |
5468f102 CS |
98 | print "Temperature for ".$array[$#array]."->".$temp."<-\n"; |
99 | # Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht) | |
100 | if ($temp){ | |
101 | RRDs::update ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp"); | |
102 | $ERROR = RRDs::error; | |
103 | print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR; | |
104 | } | |
105 | } | |
52345790 MT |
106 | } |
107 | ||
ca9c45b3 | 108 | my @disks = `ls -1 /sys/block | grep -E '^sd|^nvme|^mmcblk|^xvd|^vd|^md' | sort | uniq`; |
8845173b | 109 | system("unlink /var/run/hddstatus 2>/dev/null && touch /var/run/hddstatus"); |
350b52c5 | 110 | foreach (@disks){ |
5468f102 CS |
111 | my $disk = $_; |
112 | chomp $disk; | |
113 | print "Working on disk ".$disk.".\n"; | |
114 | ||
115 | my $status = ""; | |
116 | my $diskstats = ""; | |
117 | my $newdiskstats = ""; | |
118 | my @array = split(/\//,$disk); | |
119 | ||
8845173b | 120 | $diskstats = `cat /var/run/hddstats-$array[$#array] 2>/dev/null`; |
5468f102 | 121 | chomp $diskstats; |
cbf3a350 | 122 | my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -3 | head -1 | awk '{ print \$6","\$7}'`; |
5468f102 CS |
123 | chomp $newdiskstats; |
124 | my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`; | |
125 | chomp $status; | |
126 | ||
127 | if ($status !~/standby/ || $diskstats ne $newdiskstats){ | |
8845173b | 128 | if (-e "/var/run/hddshutdown-".$array[$#array]){system("unlink /var/run/hddshutdown-".$array[$#array]." 2>/dev/null");} |
5468f102 CS |
129 | } |
130 | ||
965f4547 | 131 | if (-e "/var/run/hddshutdown-".$array[$#array]){$status = " standby\n";} |
5468f102 CS |
132 | else{$status = " active\n";} |
133 | ||
965f4547 | 134 | open(DATEI, ">>/var/run/hddstatus") || die "Datei nicht gefunden"; |
5468f102 CS |
135 | print DATEI $disk."-".$status; |
136 | close(DATEI); | |
137 | ||
138 | updatehdddata($disk); | |
023f43ff AF |
139 | |
140 | if ( $diskstats eq $newdiskstats ) { | |
141 | # update diskstat because read temp change the status | |
cbf3a350 | 142 | my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -3 | head -1 | awk '{ print \$6","\$7}'`; |
023f43ff AF |
143 | chomp $newdiskstats; |
144 | open(DATEI, ">/var/run/hddstats-$array[$#array]") || die "Datei nicht gefunden"; | |
145 | print DATEI $newdiskstats; | |
146 | close(DATEI); | |
147 | } | |
6c666a3b | 148 | } |