]> scm.dxcluster.org Git - spider.git/blob - perl/Mrtg.pm
fix K crash
[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 $self->{cfg}`;
51 }
52
53 sub data
54 {
55         my ($self, $name, $vali, $valo, $title) = @_;
56         my $uptime = main::uptime();
57
58         if (my $m = new IO::File ">$self->{dir}/$name" ) {
59                 $m->print("$vali\n$valo\n$uptime\n$title\n");
60                 $m->close;
61         } else {
62                 dbg("MRTG: cannot open $self->{dir}/$name $!");
63         }
64 }
65
66 sub cfgprint
67 {
68         my ($self, $name, $options, $max, $title, $legend, $iname, $oname) = @_;
69         my $opt = join ', ', @$options, qw(withzeroes growright nopercent integer);
70
71         $self->{mc}->print(<<"EOF");
72
73 #
74 # $title
75 #
76
77 Target[$name]: `cat /spider/mrtg/$name`
78 MaxBytes[$name]: $max
79 Title[$name]: $title
80 Options[$name]: $opt
81 YLegend[$name]: $legend
82 YTicsFactor[$name]: 1
83 ShortLegend[$name]: \&nbsp;
84 Legend1[$name]:Maximum No of $iname
85 Legend2[$name]:Maximum No of $oname
86 LegendI[$name]:$iname
87 LegendO[$name]:$oname
88 PageTop[$name]: <H1>$title</H1>
89  <TABLE>
90    <TR><TD>System:</TD>     <TD>$main::mycall</TD></TR>
91    <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
92    <TR><TD>Description:</TD><TD>$title</TD></TR>
93  </TABLE>
94 EOF
95
96 }
97 1;