]> dxcluster.org Git - spider.git/blob - perl/Mrtg.pm
add ak1a compat changes to chat
[spider.git] / perl / Mrtg.pm
1 #
2 # the MRTG handler
3 #
4 # Copyright (c) - 2002 Dirk Koopman G1TLH
5 #
6 # $Id$
7 #
8
9 package Mrtg;
10
11 use IO::File;
12 use DXVars;
13 use DXDebug;
14 use DXUtil;
15 use strict;
16
17 use vars qw($VERSION $BRANCH);
18 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
19 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
20 $main::build += $VERSION;
21 $main::branch += $BRANCH;
22
23 sub new
24 {
25         my $pkg = shift;
26         my $class = ref $pkg || $pkg;
27         my %args = @_;
28         my $self = bless { }, $class;
29
30         # argument processing
31         $self->{dir} = $args{dir} || "$main::root/mrtg";
32         $self->{html} = $args{html} || "$main::root/html/mrtg";
33         $self->{cfg} = $args{cfg} || "$self->{dir}/mrtg.cfg";
34
35         my $mc = new IO::File ">$self->{cfg}" or return undef;
36         $self->{mc} = $mc;
37         
38         # print out the header
39         print $mc <<"EOF";
40 ### Global Defaults
41 Htmldir: $self->{html}
42 Imagedir: $self->{html}
43 Logdir: $self->{dir}
44 Options[_]: growright
45 ##
46 ##
47 EOF
48
49         return $self;
50 }
51
52 sub run
53 {
54         my $self = shift;
55         $self->{mc}->close;
56         return `mrtg $self->{cfg}`;
57 }
58
59 sub data
60 {
61         my ($self, $name, $vali, $valo, $title) = @_;
62         my $uptime = main::uptime();
63
64         if (my $m = new IO::File ">$self->{dir}/$name" ) {
65                 $m->print("$vali\n$valo\n$uptime\n$title\n");
66                 $m->close;
67         } else {
68                 dbg("MRTG: cannot open $self->{dir}/$name $!");
69         }
70 }
71
72 sub cfgprint
73 {
74         my ($self, $name, $options, $max, $title, $legend, $iname, $oname) = @_;
75         my $opt = join ', ', @$options, qw(withzeroes growright nopercent integer);
76
77         $self->{mc}->print(<<"EOF");
78
79 #
80 # $title
81 #
82
83 Target[$name]: `cat /spider/mrtg/$name`
84 MaxBytes[$name]: $max
85 Title[$name]: $title
86 Options[$name]: $opt
87 YLegend[$name]: $legend
88 YTicsFactor[$name]: 1
89 ShortLegend[$name]: \&nbsp;
90 Legend1[$name]:Maximum No of $iname
91 Legend2[$name]:Maximum No of $oname
92 LegendI[$name]:$iname
93 LegendO[$name]:$oname
94 PageTop[$name]: <H1>$title</H1>
95  <TABLE>
96    <TR><TD>System:</TD>     <TD>$main::mycall</TD></TR>
97    <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
98    <TR><TD>Description:</TD><TD>$title</TD></TR>
99  </TABLE>
100 EOF
101
102 }
103 1;