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