# you will need perl 5.6 (probably) to be able to run this command
#
-sub cfgprint($$@$$$$$);
-
my ($self, $line) = @_;
# create the arg list
return (1, "MRTG not installed") unless $want{test} || -e '/usr/bin/mrtg' || -e '/usr/local/bin/mrtg';
-my $dir = "$main::root/mrtg";
-my $html = "$main::root/html/mrtg";
-my $cfg = "$dir/mrtg.cfg";
-
-my $mc = new IO::File ">$cfg" or return(1, "cannot open $cfg for mrtg writing");
-
-# print out the header
-print $mc <<"EOF";
-### Global Defaults
-
-# to get bits instead of bytes and graphs growing to the right
-# Options[_]: growright, bits
-
-Htmldir: $html
-Imagedir: $html
-Logdir: $dir
-Options[_]: growright
-
-##
-##
-
-EOF
-
-
-#dbg "$dir\n$html\n";
+my $mc = new Mrtg or return (1, "cannot initialise Mrtg $!");
# do the users and nodes
my $users = DXChannel::get_all_users();
my $nodes = DXChannel::get_all_nodes();
-my $uptime = main::uptime();
-#dbg "$users $nodes $uptime\n";
-if (my $m = new IO::File ">$dir/users") {
- print $m "$users\n$nodes\n$uptime\nUsers and Nodes\n";
- close $m;
-}
-cfgprint($mc, 'users', [qw(gauge)], 500,
+
+$mc->cfgprint('users', $users, $nodes, [qw(gauge)], 500,
"Users and Nodes on $main::mycall",
'Users / Nodes', 'Users', 'Nodes');
if ($want{totalusers} || $want{all}) {
$nodes = Route::Node::count();
$users = Route::User::count();
- #dbg "$users $nodes $uptime\n";
- if (my $m = new IO::File ">$dir/totalusers") {
- print $m "$users\n$nodes\n$uptime\nTotal Users and Nodes\n";
- close $m;
- }
- cfgprint($mc, 'totalusers', [qw(gauge)], 10000,
+ $mc->cfgprint('totalusers', $users, $nodes, [qw(gauge)], 10000,
'Total Users and Nodes in the Visible Cluster Network',
'Users / Nodes', 'Users', 'Nodes');
}
# do the total spots
if ($want{totalspots} || $want{all}) {
- if (my $m = new IO::File ">$dir/totalspots") {
- print $m "$Spot::totalspots\n$Spot::totalspots\n$uptime\nTotal Spots\n";
- close $m;
- }
- $Spot::totalspots = 0;
- cfgprint($mc, 'totalspots', [qw(unknaszero gauge noi)], 1000, 'Total Spots',
+ $mc->cfgprint('totalspots', $Spot::totalspots, $Spot::totalspots, [qw(unknaszero gauge noi)], 1000, 'Total Spots',
'Spots', 'Spots', 'Spots');
+ $Spot::totalspots = 0;
}
# do the HF and VHF spots
if ($want{hfvhf} || $want{all}) {
- if (my $m = new IO::File ">$dir/hfspots") {
- print $m "$Spot::hfspots\n$Spot::vhfspots\n$uptime\nHF and VHF+ Spots\n";
- close $m;
- }
- $Spot::hfspots = $Spot::vhfspots = 0;
- cfgprint($mc, 'hfspots', [qw(unknaszero gauge)], 1000, 'HF and VHF+ Spots',
+ $mc->cfgprint('hfspots', $Spot::hfspots, $Spot::vhfspots, [qw(unknaszero gauge)], 1000, 'HF and VHF+ Spots',
'Spots', 'HF', 'VHF');
+ $Spot::hfspots = $Spot::vhfspots = 0;
+}
+
+# wwv stuff
+if ($want{wwv} || $want{all}) {
+ $mc->cfgprint('wwvsfi', $Geomag::r || $WCY::r, $Geomag::sfi || $WCY::sfi, [qw(gauge)], 1000, 'WWV SFI and R',
+ 'SFI / R', 'SFI', 'R');
+ $mc->cfgprint('wwvka', $Geomag::a, $Geomag::k, [qw(gauge)], 1000, 'WWV A and K',
+ 'A / K', 'A', 'K');
+}
+
+# WCY stuff
+if ($want{wcy} || $want{all}) {
+ $mc->cfgprint('wcyka', $WCY::a, $WCY::k, [qw(gauge)], 1000, 'WCY A and K',
+ 'A / K', 'A', 'K');
}
#
# do the mrtg thing
#
-close $mc;
-my @out = `mrtg $cfg`;
+my @out = $mc->run unless $want{test};
return (1, @out);
-
-sub cfgprint
-{
- my ($mc, $name, $options, $max, $title, $legend, $iname, $oname) = @_;
- my $opt = join ', ', @$options, qw(withzeroes gauge growright nopercent integer);
-
- print $mc <<"EOF";
-
-#
-# $title
-#
-
-Target[$name]: `cat /spider/mrtg/$name`
-MaxBytes[$name]: $max
-Title[$name]: $title
-Options[$name]: $opt
-YLegend[$name]: $legend
-YTicsFactor[$name]: 1
-ShortLegend[$name]: \
-Legend1[$name]:Maximum No of $iname
-Legend2[$name]:Maximum No of $oname
-LegendI[$name]:$iname
-LegendO[$name]:$oname
-PageTop[$name]: <H1>$title</H1>
- <TABLE>
- <TR><TD>System:</TD> <TD>$main::mycall</TD></TR>
- <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
- <TR><TD>Description:</TD><TD>$title</TD></TR>
- </TABLE>
-EOF
-
-}
--- /dev/null
+#
+# the MRTG handler
+#
+# Copyright (c) - 2002 Dirk Koopman G1TLH
+#
+# $Id$
+#
+
+package Mrtg;
+
+use IO::File;
+use DXVars;
+use DXDebug;
+use DXUtil;
+use strict;
+
+use vars qw($VERSION $BRANCH);
+$VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
+$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0));
+$main::build += $VERSION;
+$main::branch += $BRANCH;
+
+sub new
+{
+ my $pkg = shift;
+ my $class = ref $pkg || $pkg;
+ my %args = @_;
+ my $self = bless { }, $class;
+
+ # argument processing
+ $self->{dir} = $args{dir} || "$main::root/mrtg";
+ $self->{html} = $args{html} || "$main::root/html/mrtg";
+ $self->{cfg} = $args{cfg} || "$self->{dir}/mrtg.cfg";
+
+ my $mc = new IO::File ">$self->{cfg}" or return undef;
+ $self->{mc} = $mc;
+
+ # print out the header
+ print $mc <<"EOF";
+### Global Defaults
+Htmldir: $self->{html}
+Imagedir: $self->{html}
+Logdir: $self->{dir}
+Options[_]: growright
+##
+##
+EOF
+
+ return $self;
+}
+
+sub run
+{
+ my $self = shift;
+ $self->{mc}->close;
+ return `mrtg $self->{cfg}`;
+}
+
+sub cfgprint
+{
+ my ($self, $name, $vali, $valo, $options, $max, $title, $legend, $iname, $oname) = @_;
+ my $opt = join ', ', @$options, qw(withzeroes gauge growright nopercent integer);
+ my $uptime = main::uptime();
+
+ if (my $m = new IO::File ">$self->{dir}/$name") {
+ $m->print("$vali\n$valo\n$uptime\n$title\n");
+ $m->close;
+ }
+
+ $self->{mc}->print(<<"EOF");
+
+#
+# $title
+#
+
+Target[$name]: `cat /spider/mrtg/$name`
+MaxBytes[$name]: $max
+Title[$name]: $title
+Options[$name]: $opt
+YLegend[$name]: $legend
+YTicsFactor[$name]: 1
+ShortLegend[$name]: \
+Legend1[$name]:Maximum No of $iname
+Legend2[$name]:Maximum No of $oname
+LegendI[$name]:$iname
+LegendO[$name]:$oname
+PageTop[$name]: <H1>$title</H1>
+ <TABLE>
+ <TR><TD>System:</TD> <TD>$main::mycall</TD></TR>
+ <TR><TD>Maintainer:</TD> <TD>$main::myemail</TD></TR>
+ <TR><TD>Description:</TD><TD>$title</TD></TR>
+ </TABLE>
+EOF
+
+}
+1;