From 6519e1579c6a9deb260a1885c562f07924d7cff0 Mon Sep 17 00:00:00 2001 From: Steve Schnepp Date: Mon, 16 Jan 2012 16:07:54 +0100 Subject: [PATCH] Pushing pmmn over here, in an attempt to merge all the various munin tools scattered around the internet --- tools/pmmn/bin/pmmn | 129 ++++++++++++++++++++++++++++++++++++++ tools/pmmn/plugins/README | 2 + 2 files changed, 131 insertions(+) create mode 100755 tools/pmmn/bin/pmmn create mode 100644 tools/pmmn/plugins/README diff --git a/tools/pmmn/bin/pmmn b/tools/pmmn/bin/pmmn new file mode 100755 index 00000000..ce149228 --- /dev/null +++ b/tools/pmmn/bin/pmmn @@ -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 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 diff --git a/tools/pmmn/plugins/README b/tools/pmmn/plugins/README new file mode 100644 index 00000000..27630a2f --- /dev/null +++ b/tools/pmmn/plugins/README @@ -0,0 +1,2 @@ +This is where you should put symlinks to plugins. +It behaves like /etc/munin/plugins for munin-node