]>
cvs.zerfleddert.de Git - upsgraph/blob - upsgraph.pl
3 if ((@ARGV != 1) && (@ARGV != 2)) {
4 print STDERR
"Syntax: ${0} configfile [uid]\n";
11 $UPSGRAPH::rrdfile
= "";
12 $UPSGRAPH::outdir
= "";
13 $UPSGRAPH::community
= "public";
15 @UPSGRAPH::fields
= ();
18 do $ARGV[0] or die "can't read config: $!";
20 my $host = $UPSGRAPH::host
;
21 my $rrdfile = $UPSGRAPH::rrdfile
;
22 my $outdir = $UPSGRAPH::outdir
;
23 my $community = $UPSGRAPH::community
;
24 my $step = $UPSGRAPH::step
;
25 my @fields = @UPSGRAPH::fields
;
26 my $vars = $UPSGRAPH::vars
;
30 print STDERR
"Running as root, please provide UID as 4th argument!\n";
34 print "Running as root, switching to ".$ARGV[3]."\n";
38 if (! -e
"${rrdfile}") {
39 my $cmd = "rrdtool create \"${rrdfile}\" ";
40 foreach my $var (@fields) {
41 $cmd .= "DS:${var}:GAUGE:600:" .
42 $vars->{$var}->{'min'} . ":" .
43 $vars->{$var}->{'max'} . " ";
45 $cmd .= "RRA:AVERAGE:0.5:1:10080 --step ${step}";
47 print "Creating ${rrdfile}...\n";
53 die "fork failed!" if (!defined($child));
55 exit 0 if ($child != 0);
58 ($session,$error) = Net
::SNMP
->session(Hostname
=> $host,
59 Community
=> $community);
61 die "session error: $error" unless ($session);
63 $session->translate(0);
65 foreach my $var (@fields) {
66 delete $vars->{$var}->{'value'};
68 my $result = $session->get_request($vars->{$var}->{'oid'});
69 next unless (defined $result);
71 $vars->{$var}->{'value'} = $result->{$vars->{$var}->{'oid'}};
72 if (defined($vars->{$var}->{'factor'})) {
73 $vars->{$var}->{'value'} *= $vars->{$var}->{'factor'};
79 my $cmd = "rrdtool update \"${rrdfile}\" \"N";
80 foreach my $var (@fields) {
81 if (!(defined($vars->{$var}->{'value'}))) {
82 $vars->{$var}->{'value'} = 'U';
84 $cmd .= ":" . $vars->{$var}->{'value'};
89 open(HTML
, ">${outdir}/index.html.new");
91 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>';
92 print HTML
'<body bgcolor="#ffffff">';
94 foreach my $var (@fields) {
95 my $graphdef = "-t \"" . $vars->{$var}->{'name'} . "\" \"DEF:${var}=${rrdfile}:${var}:AVERAGE\" \"LINE1:${var}#FF0000\"";
96 my $cmd = "rrdtool graph \"${outdir}/${var}.png.new\" -w 720 ${graphdef}";
98 rename("${outdir}/${var}.png.new", "${outdir}/${var}.png");
99 (my $width, my $height) = split(/x/,$size);
101 my $cmd2 = "rrdtool graph \"${outdir}/${var}.long.png.new\" -w 1008 -e now -s end-1w ${graphdef}";
103 rename("${outdir}/${var}.long.png.new", "${outdir}/${var}.long.png");
105 print HTML
"<a href=\"${var}.long.png\"><img src=\"${var}.png\" width=\"${width}\" height=\"${height}\" border=\"0\"></a>";
108 print HTML
"</body></html>\n";
109 print HTML
"<br>Generated on: " . localtime(time());
110 print HTML
' by <a href="http://git.zerfleddert.de/cgi-bin/gitweb.cgi/upsgraph">upsgraph</a>.';
114 rename("${outdir}/index.html.new", "${outdir}/index.html");