]>
git.zerfleddert.de Git - upsgraph/blob - upsgraph.pl
aa777210125b94c4fafe92b5e554da58e52288d8
4 print STDERR
"Syntax: ${0} host /path/to/file.rrd /output/directory/\n";
11 my $community="public";
14 my @fields = ( 'inputV', 'outputV', 'inputHZ', 'outputHZ', 'battT', 'battC', 'load', 'ambT', 'ambH', 'timeR', 'timeO' );
18 'name' => 'Input Voltage',
19 'oidtext' => 'PowerNet-MIB::upsAdvInputLineVoltage.0',
20 'oid' => '1.3.6.1.4.1.318.1.1.1.3.2.1.0',
25 'name' => 'Output Voltage',
26 'oidtext' => 'PowerNet-MIB::upsAdvOutputVoltage.0',
27 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.1.0',
32 'name' => 'Input Frequency',
33 'oidtext' => 'PowerNet-MIB::upsAdvInputFrequency.0',
34 'oid' => '1.3.6.1.4.1.318.1.1.1.3.2.4.0',
39 'name' => 'Output Frequency',
40 'oidtext' => 'PowerNet-MIB::upsAdvOutputFrequency.0',
41 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.2.0',
46 'name' => 'Battery Temperature',
47 'oidtext' => 'PowerNet-MIB::upsAdvBatteryTemperature.0',
48 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.2.0',
53 'name' => 'Battery Capacity',
54 'oidtext' => 'PowerNet-MIB::upsAdvBatteryCapacity.0',
55 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.1.0',
61 'oidtext' => 'PowerNet-MIB::upsAdvOutputLoad.0',
62 'oid' => '1.3.6.1.4.1.318.1.1.1.4.2.3.0',
67 'name' => 'Ambient Temperature',
68 'oidtext' => 'PowerNet-MIB::mUpsEnvironAmbientTemperature.0',
69 'oid' => '1.3.6.1.4.1.318.1.1.2.1.1.0',
74 'name' => 'Ambient Humidity',
75 'oidtext' => 'PowerNet-MIB::mUpsEnvironRelativeHumidity.0',
76 'oid' => '1.3.6.1.4.1.318.1.1.2.1.2.0',
81 'name' => 'Time Remaining',
82 'oidtext' => 'PowerNet-MIB::upsAdvBatteryRunTimeRemaining.0',
83 'oid' => '1.3.6.1.4.1.318.1.1.1.2.2.3.0',
89 'name' => 'Time On Battery',
90 'oidtext' => 'PowerNet-MIB::upsBasicBatteryTimeOnBattery.0',
91 'oid' => '1.3.6.1.4.1.318.1.1.1.2.1.2.0',
100 if (! -e
"${rrdfile}") {
101 my $cmd = "rrdtool create \"${rrdfile}\" ";
102 foreach my $var (@fields) {
103 $cmd .= "DS:${var}:GAUGE:600:" .
104 $vars->{$var}->{'min'} . ":" .
105 $vars->{$var}->{'max'} . " ";
107 $cmd .= "RRA:AVERAGE:0.5:1:10080 --step ${step}";
109 print "Creating ${rrdfile}...\n";
115 die "fork failed!" if (!defined($child));
117 exit 0 if ($child != 0);
120 ($session,$error) = Net
::SNMP
->session(Hostname
=> $host,
121 Community
=> $community);
123 die "session error: $error" unless ($session);
125 $session->translate(0);
127 foreach my $var (@fields) {
128 delete $vars->{$var}->{'value'};
130 my $result = $session->get_request($vars->{$var}->{'oid'});
131 next unless (defined $result);
133 $vars->{$var}->{'value'} = $result->{$vars->{$var}->{'oid'}};
134 if (defined($vars->{$var}->{'factor'})) {
135 $vars->{$var}->{'value'} *= $vars->{$var}->{'factor'};
141 my $cmd = "rrdtool update \"${rrdfile}\" \"N";
142 foreach my $var (@fields) {
143 if (!(defined($vars->{$var}->{'value'}))) {
144 $vars->{$var}->{'value'} = 'U';
146 $cmd .= ":" . $vars->{$var}->{'value'};
151 open(HTML
, ">${outdir}/index.html.new");
153 print HTML
'<html><head><meta http-equiv="refresh" content="60"/><meta http-equiv="cache-control" content="no-cache"/><meta http-equiv="pragma" content="no-cache"/><meta http_equiv="expires" content="Sat, 26 Jul 1997 05:00:00 GMT"/><title>USV status</title></head>';
154 print HTML
'<body bgcolor="#ffffff">';
156 foreach my $var (@fields) {
157 my $graphdef = "-t \"" . $vars->{$var}->{'name'} . "\" \"DEF:${var}=${rrdfile}:${var}:AVERAGE\" \"LINE1:${var}#FF0000\"";
158 my $cmd = "rrdtool graph \"${outdir}/${var}.png.new\" -w 720 ${graphdef}";
160 rename("${outdir}/${var}.png.new", "${outdir}/${var}.png");
161 (my $width, my $height) = split(/x/,$size);
163 my $cmd2 = "rrdtool graph \"${outdir}/${var}.long.png.new\" -w 1008 -e now -s end-1w ${graphdef}";
165 rename("${outdir}/${var}.long.png.new", "${outdir}/${var}.long.png");
167 print HTML
"<a href=\"${var}.long.png\"><img src=\"${var}.png\" width=\"${width}\" height=\"${height}\" border=\"0\"></a>";
170 print HTML
"</body></html>\n";
171 print HTML
"<br>Generated on: " . localtime(time());
172 print HTML
' by <a href="http://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph">upsgraph</a>.';
176 rename("${outdir}/index.html.new", "${outdir}/index.html");