mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 02:51:03 +00:00
Pushing pmmn over here, in an attempt to merge all the various munin tools scattered around the internet
This commit is contained in:
parent
8a95538509
commit
6519e1579c
2 changed files with 131 additions and 0 deletions
129
tools/pmmn/bin/pmmn
Executable file
129
tools/pmmn/bin/pmmn
Executable file
|
@ -0,0 +1,129 @@
|
|||
#! /usr/bin/perl
|
||||
# Poor man's Munin Node
|
||||
# Usable with only Perl 5
|
||||
|
||||
use warnings;
|
||||
use strict;
|
||||
use Carp;
|
||||
use Data::Dumper;
|
||||
|
||||
use Getopt::Long;
|
||||
use Pod::Usage;
|
||||
|
||||
$| = 1;
|
||||
|
||||
my $VERSION = "0.0.1";
|
||||
|
||||
my $port; # Default is stdin/stdout
|
||||
my $verbose;
|
||||
my $host;
|
||||
my $plugin_dir = "plugins";
|
||||
{
|
||||
my $man = 0;
|
||||
my $help = 0;
|
||||
|
||||
GetOptions(
|
||||
'port|p=i' => \$port,
|
||||
'verbose|v' => \$verbose,
|
||||
'plugin-dir|d=s' => \$plugin_dir,
|
||||
'host|h=s' => \$host,
|
||||
|
||||
'help|?' => \$help,
|
||||
man => \$man,
|
||||
) or pod2usage(2);
|
||||
pod2usage(1) if $help;
|
||||
pod2usage(-exitstatus => 0, -verbose => 2) if $man;
|
||||
}
|
||||
|
||||
# Handle $port
|
||||
if ($port) {
|
||||
die ("--port is not yet supported");
|
||||
}
|
||||
|
||||
$host ||= `hostname`;
|
||||
chomp($host);
|
||||
print "# munin node at $host\n";
|
||||
while(my $line = <>) {
|
||||
chomp($line);
|
||||
my ($cmd, $arg) = split(/ /, $line, 2);
|
||||
$arg ||= "";
|
||||
my $plugin_filename = $plugin_dir . "/" . $arg;
|
||||
if (! $cmd) { next; }
|
||||
if ($cmd eq "version") {
|
||||
print "munins node on $host version: $VERSION";
|
||||
next;
|
||||
} elsif ($cmd eq "nodes") {
|
||||
print "$host\n";
|
||||
next;
|
||||
} elsif ($cmd eq "quit") {
|
||||
exit(0);
|
||||
} elsif ($cmd eq "list") {
|
||||
opendir(PLUGIN_DIR, $plugin_dir) or die("cannot open: $@");
|
||||
while(my $plugin = readdir(PLUGIN_DIR)) {
|
||||
chomp($plugin);
|
||||
if ($plugin =~ m/^\./) { next; }
|
||||
next unless (-x "$plugin_dir/$plugin");
|
||||
print "$plugin ";
|
||||
}
|
||||
closedir(PLUGIN_DIR);
|
||||
next;
|
||||
} elsif (-e $plugin_filename) {
|
||||
my $arg_plugin;
|
||||
if ($cmd eq "config") {
|
||||
$arg_plugin = "config";
|
||||
} elsif ($cmd eq "fetch") {
|
||||
$arg_plugin = "";
|
||||
} else {
|
||||
# Ignore
|
||||
next;
|
||||
}
|
||||
system($plugin_filename, $arg_plugin);
|
||||
print ".";
|
||||
}
|
||||
} continue {
|
||||
#print " " x 4096;
|
||||
print "\n";
|
||||
};
|
||||
|
||||
|
||||
__END__
|
||||
|
||||
=head1 NAME
|
||||
|
||||
pmmn - Poor man's Munin Node
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
pmmn [options]
|
||||
|
||||
Options:
|
||||
|
||||
--port Port to listen to (default is stdin/stdout)
|
||||
--verbose Verbose mode
|
||||
--plugin-dir Plugin directory (default is current dir)
|
||||
--host Host name (default is /bin/hostname)
|
||||
|
||||
--help brief help message
|
||||
--man full documentation
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
=over 8
|
||||
|
||||
=item B<-help>
|
||||
|
||||
Print a brief help message and exits.
|
||||
|
||||
=item B<-man>
|
||||
|
||||
Prints the manual page and exits.
|
||||
|
||||
=back
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<This program> emulates a poor man's munin-node. It can listen on a port or,
|
||||
most frequently read its commands from stdin, sending output on stdout. This is
|
||||
in order to be managed by inetd or a custom SSH vehicule.
|
||||
|
||||
=cut
|
2
tools/pmmn/plugins/README
Normal file
2
tools/pmmn/plugins/README
Normal file
|
@ -0,0 +1,2 @@
|
|||
This is where you should put symlinks to plugins.
|
||||
It behaves like /etc/munin/plugins for munin-node
|
Loading…
Add table
Add a link
Reference in a new issue