konto usunięte
Temat: OCS + munin
Witam,Dopiero zaczynam zabawę z OCS'em - serwer postawiony na debianie, wszystko ładnie się komunikuje. Mam jednak pytanie: jak połączyć/skonfigurować ocs'a/munina aby plugin OCS wyświetlał na muninie, czy komputery łączą się z serwerem?
Mam taki oto kod:
#!/usr/bin/perl -w
# -*- perl -*-
=head1 NAME
ocsinventory - Plugin to monitor the ocsinventory
=head1 CONFIGURATION
Configuration parameters for /etc/munin/ocsinventory,
if you need to override the defaults below:
[ocsinventory]
env.logdir - Which logfile to use
env.logfile - What file to read in logdir
=head2 DEFAULT CONFIGURATION
[ocs-inventory]
env.logdir /var/log/ocsinventory-server
env.logfile activity.log
=head1 AUTHOR
W
=head1 LICENSE
Unknown license
=head1 MAGIC MARKERS
=begin comment
These magic markers are used by munin-node-configure when installing
munin-node.
=end comment
#%# family=manual
#%# capabilities=autoconf
=head1 RANDOM COMMENTS
Would be cool if someone ported this to Munin::Plugin for both state
file and log tailing.
=cut
my $statefile = $ENV{'MUNIN_PLUGSTATE'} . "/munin-ocsinventory.state";
#my $statefile = "/var/lib/munin-node/plugin-state/munin-ocsinventory.state";
my $pos;
my @hosts = exists $ENV{hosts} ? split(/,/,$ENV{hosts}) : ( );
my @names = exists $ENV{names} ? split(/,/,$ENV{names}) : ( );
my $delivered = 0;
my $ile = 0;
my $rejects = {};
my $agents = {};
my $LOGDIR = $ENV{'logdir'} || '/var/log/ocsinventory-server';
my $LOGFILE = $ENV{'logfile'} || 'activity.log';
my $logfile = "$LOGDIR/$LOGFILE";
if ( $ARGV[0] and $ARGV[0] eq "autoconf" )
{
my $logfile;
if (-d $LOGDIR)
{
if (-f $logfile)
{
if (-r $logfile)
{
print "yes\n";
exit 0;
}
else
{
print "no (logfile '$logfile' not readable)\n";
}
}
else
{
print "no (logfile '$logfile' not found)\n";
}
}
else
{
print "no (could not find logdir '$LOGDIR')\n";
}
exit 0;
}
if ( -f $statefile)
{
open (IN, '<' , $statefile) or die "Unable to open state-file: $!\n";
if (<IN> =~ /^(\d+):(\d+)/)
{
($pos, $delivered) = ($1, $2);
}
while (<IN>)
{
print "\n";
if (/^(;0-9a-z.\-]+):(\d+)$/)
{
$rejects->{$1} = $2;
}
}
close IN;
}
if (! -f $logfile)
{
print "delivered.value U\n";
foreach my $i (@hosts)
{
print "$i.value U\n";
}
exit 0;
}
$startsize = (stat $logfile)[7];
if (!defined $pos)
{
# Initial run.
$pos = $startsize;
}
parseLogfile($logfile, $pos, $startsize);
$pos = $startsize;
# print "@hosts \n";
if ( $ARGV[0] and $ARGV[0] eq "config" )
{
print "graph_title OCSInventory message throughput\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel hosts / \${graph_period}\n";
print "graph_scale no\n";
# print "graph_total Total\n";
print "graph_category OCSInventory\n";
print "delivered.label delivered\n";
print "delivered.type DERIVE\n";
print "delivered.draw AREA\n";
print "delivered.min 0\n";
$ile = 0;
foreach my $i (@hosts)
{
$in = $i;
$i =~ s/\.//g;
print "$i.label $names[$ile]\n";
print "$i.type DERIVE\n";
print "$i.draw STACK\n";
## print "$i.info $names[$ile]\n";
# print "$i.info $in \n";
print "$i.min 0\n";
$ile++;
}
exit 0;
}
print "delivered.value $delivered\n";
#foreach my $i (@hosts)
foreach my $i ( keys %{$rejects})
{
$in = $i;
$i =~ s/\.//g;
print "$i.value ", $rejects->{$i}, "\n";
}
if(-l $statefile) {
die("$statefile is a symbolic link, refusing to touch it.");
}
open (OUT, '>', $statefile) or die "Unable to open statefile: $!\n";
print OUT "$pos:$delivered\n";
foreach my $i (@hosts)
{
# print OUT "$i:", $rejects->{$i}, "\n";
$in = $i;
$i =~ s/\.//g;
# print "-- $in $i $rejects->{$i}\n";
print OUT "$i:", $rejects->{$i}, "\n";
}
close OUT;
sub parseLogfile
{
my ($fname, $start, $stop) = @_;
open (LOGFILE, $fname)
or die "Unable to open logfile $fname for reading: $!\n";
seek (LOGFILE, $start, 0)
or die "Unable to seek to $start in $fname: $!\n";
while (tell (LOGFILE) < $stop)
{
my $line = <LOGFILE>;
chomp ($line);
if ($line =~ /\;(\d+\.\d+\.\d+\.\d+):\S+/)
{
print "$line atu\n";
$delivered++;
$name = $1;
$name =~ s/\.//g;
$rejects->{$name}++;
}
elsif ($line =~ /postfix\/smtpd.*reject: \S+ \S+ \S+ (\S+)/ ||
$line =~ /postfix\/cleanup.* reject: (\S+)/)
{
$name = $1;
$name =~ s/\.//g;
$rejects->{$name}++;
}
}
close(LOGFILE) or warn "Error closing $fname: $!\n";
}
# vim:syntax=perl