]>
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 | my (%settings, @ipacsum, $iface, $ERROR); | |
33 | &General::readhash("${General::swroot}/ethernet/settings", \%settings); | |
34 | my %mbmon_settings = (); | |
35 | &General::readhash("${General::swroot}/mbmon/settings", \%mbmon_settings); | |
36 | ||
37 | # Added for conversion of utf-8 characters | |
38 | use Encode 'from_to'; | |
39 | my %tr=(); | |
40 | ||
41 | system("chmod 777 /srv/web/ipfire/html/graphs"); | |
42 | ||
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')) { | |
53 | eval `/bin/cat "${General::swroot}/langs/en.pl"`; | |
54 | } else { | |
55 | #use translated version for other languages | |
56 | %tr=%Lang::tr; | |
57 | } | |
58 | ||
59 | # Settings | |
60 | my $rrdlog = "/var/log/rrd"; | |
61 | my $graphs = "/srv/web/ipfire/html/graphs"; | |
62 | $ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"; | |
63 | my $hdd_device = "/dev/harddisk"; | |
64 | my $temp = ''; | |
65 | my %mbmon_values = (); | |
66 | my $key; | |
67 | my $value; | |
68 | my @args = (); | |
69 | my $count = 0; | |
70 | my $ERROR; | |
71 | my $dbg = 0; | |
72 | my $path_smartctl = "/usr/sbin/smartctl"; | |
73 | my $path_hddtemp = "/usr/sbin/hddtemp"; | |
74 | ||
75 | my %color = (); | |
76 | my %mainsettings = (); | |
77 | &General::readhash("${General::swroot}/main/settings", \%mainsettings); | |
78 | &General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); | |
79 | ||
80 | open(MBMON_OUT, ">/var/log/mbmon-values"); | |
81 | open(FD, "/usr/bin/mbmon -rc1|" ) || die "ERROR: Cannot run mbmon\n" ; | |
82 | ||
83 | while( $_ = <FD> ) | |
84 | { | |
85 | next unless( /^([A-Za-z][^:\s]+)\s*:\s*([+\-]{0,1}[\d\.]+)/ ) ; | |
86 | $key = $1 ; | |
87 | $value = $2 ; | |
88 | $key =~ y/A-Z/a-z/ ; | |
89 | $mbmon_values{$key} = $value; | |
90 | print(MBMON_OUT "$key=$value\n"); | |
91 | } | |
92 | close(FD); | |
93 | close(MBMON_OUT); | |
94 | ||
95 | sub updatehdddata | |
96 | { | |
97 | my $disk = $_[0]; | |
98 | my $standby; | |
99 | my @array = split(/\//,$disk); | |
100 | ||
101 | if ( ! -e "$rrdlog/hddshutdown-".$array[$#array].".rrd"){ | |
102 | # database did not exist -> create | |
103 | RRDs::create ("$rrdlog/hddshutdown-".$array[$#array].".rrd", "--step=300", | |
104 | "DS:standby:GAUGE:600:0:1", | |
105 | "RRA:AVERAGE:0.5:1:576", | |
106 | "RRA:AVERAGE:0.5:6:672", | |
107 | "RRA:AVERAGE:0.5:24:732", | |
108 | "RRA:AVERAGE:0.5:144:1460"); | |
109 | $ERROR = RRDs::error; | |
110 | print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR; | |
111 | } | |
112 | ||
113 | if (-e "/tmp/hddshutdown-".$array[$#array]) {$standby = 1;} | |
114 | else {$standby = 0;} | |
115 | ||
116 | RRDs::update ("$rrdlog/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby"); | |
117 | $ERROR = RRDs::error; | |
118 | print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR; | |
119 | ||
120 | if ( ! -e "$rrdlog/hddtemp-".$array[$#array].".rrd"){ | |
121 | # database did not exist -> create | |
122 | RRDs::create ("$rrdlog/hddtemp-".$array[$#array].".rrd", "--step=300", | |
123 | "DS:temperature:GAUGE:600:0:100", | |
124 | "RRA:AVERAGE:0.5:1:576", | |
125 | "RRA:AVERAGE:0.5:6:672", | |
126 | "RRA:AVERAGE:0.5:24:732", | |
127 | "RRA:AVERAGE:0.5:144:1460"); | |
128 | $ERROR = RRDs::error; | |
129 | print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR; | |
130 | } | |
131 | ||
132 |