1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-24 18:07:20 +00:00

More housecleaning.

Collapse some categories; remove duplicates; move plugins in where
they belong, remove files that are not really plugins at all.
This commit is contained in:
Diego Elio Pettenò 2012-08-06 21:55:44 -07:00
parent 4e3ef5b93e
commit 0a1524f27f
45 changed files with 0 additions and 1337 deletions

View file

@ -1,134 +0,0 @@
#!/usr/bin/env python
# -*- encoding: iso-8859-1 -*-
#
# apt_ubuntu
#
# Plugin to monitor packages that should be installed on Ubuntu systems.
#
# Author: Stefan Daniel Schwarz <munin@wolfram.ravenwolf.de>
#
# v1.0 2008-11-07 - First draft
# v1.1 2008-11-08 - critical = #: First # critical, rest warning
# v1.2 2008-11-09 - Code cleanup for MuninExchange submission
#
# Usage: place in /etc/munin/plugins/ (or link it there using ln -s)
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-config)
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# capabilities=autoconf
#%# family=contrib
###########################################################
category = 'system' # 'upgrades'
title = 'Upgradable packages' # 'Upgradeable packages'
vlabel = 'Total packages'
other = 'other'
total = 'total'
archives = ['security', 'updates', 'proposed', 'backports']
colour = ['ff0000', '22ff22', '0022ff', '00aaaa', 'ff00ff']
origins = ['Ubuntu']
critical = 1
###########################################################
import os
import sys
import warnings
warnings.filterwarnings('ignore', 'apt API not stable yet', FutureWarning)
def autoconf():
if os.path.exists('/etc/lsb-release'):
for line in open('/etc/lsb-release'):
if line.strip() == 'DISTRIB_ID=Ubuntu':
try:
import apt
except ImportError:
print 'no (python-apt not installed)'
sys.exit(1)
cache = apt.Cache()
if not cache.has_key('update-notifier-common'):
print 'no (update-notifier-common not found)'
sys.exit(1)
if not cache['update-notifier-common'].isInstalled:
print 'no (update-notifier-common not installed)'
sys.exit(1)
if not os.path.exists('/etc/apt/apt.conf.d/10periodic'):
print 'no (/etc/apt/apt.conf.d/10periodic not found)'
sys.exit(1)
for line in open('/etc/apt/apt.conf.d/10periodic'):
if line.strip() == 'APT::Periodic::Update-Package-Lists "1";':
print 'yes'
sys.exit(0)
print 'no (APT::Periodic::Update-Package-Lists not "1")'
sys.exit(1)
print 'no'
sys.exit(1)
def config():
print 'graph_category %s' % (category)
print 'graph_title %s' % (title)
#print 'graph_total %s' % (total)
print 'graph_vlabel %s' % (vlabel)
for i, archive in enumerate(archives + [other]):
if len(colour) > i:
print '%s.colour %s' % (archive, colour[i])
if i < critical:
print '%s.critical 0:0' % (archive)
if i == 0:
print '%s.draw AREA' % (archive)
else:
print '%s.draw STACK' % (archive)
print '%s.label %s' % (archive, archive)
if i + 1 > critical:
print '%s.warning 0:0' % (archive)
print 'total.colour 000000'
print 'total.draw LINE1'
print 'total.label %s' % (total)
sys.exit(0)
def check_origin(pkg):
#print 'Checking: %s (%s)' % (pkg.name, map(str, pkg.candidateOrigin))
if pkg.candidateOrigin:
for archive in archives:
for origin in pkg.candidateOrigin:
#a = origin.archive.rpartition('-')[2]
a = origin.archive.split('-')[origin.archive.count('-')]
if a == archive and origin.origin in origins:
return a
return other
if len(sys.argv) > 1:
if sys.argv[1] == 'autoconf':
autoconf()
elif sys.argv[1] == 'config':
config()
elif sys.argv[1]:
print('unknown argument "' + sys.argv[1] + '"')
sys.exit(1)
try:
import apt
except ImportError:
print "The module 'apt' is currently not installed. You can install it by typing:\nsudo apt-get install python-apt\nImportError: No module named apt"
sys.exit(1)
pkgs = {}
total = 0
for pkg in apt.Cache():
if pkg.isUpgradable:
a = check_origin(pkg)
pkgs[a] = pkgs.get(a, 0) + 1
total += 1
for archive in archives + [other]:
print '%s.value %s' % (archive, pkgs.pop(archive, 0))
print 'total.value %s' % (total)

View file

@ -1,176 +0,0 @@
#!/usr/bin/perl -w
#
# Plugin for monitoring boinc processes
#
# Parameters:
#
# password -- The password for RPC authentication
# (default: boinc_cmd will look for a file
# 'gui_rpc_auth.cfg' and use the password in it)
# host -- the host to connect to (default: localhost)
# port -- optional (default: 31416)
#
# This plugin can monitor boinc processes running on local/remote machines.
# You can see the progress on various projects.
#
# Author: Petr Ruzicka <petr.ruzicka@gmail.com>
# GPL v3
#
#%# family=auto
#%# capabilities=autoconf
use IO::Socket;
use Digest::MD5 qw(md5_hex);
if ($ENV{'password_path'}) {
$password = $ENV{'password_path'};
} else {
$password = $ENV{'password'} || `cat /var/lib/boinc/gui_rpc_auth.cfg 2>/dev/null`;
}
my $host = $ENV{'host'} || '127.0.0.1';
my $port = $ENV{'port'} || '31416';
sub autoconf {
my $client = new IO::Socket::INET (
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp' );
if ($client) {
print $client "<boinc_gui_rpc_request><auth1/></boinc_gui_rpc_request>\003";
{
local $/ = "\003";
$reply = <$client>;
}
$reply =~ /<nonce>(.*)<\/nonce>/;
$hash = md5_hex($1, $password);
print $client "<boinc_gui_rpc_request><auth2><nonce_hash>$hash</nonce_hash></auth2></boinc_gui_rpc_request>\003";
{
local $/ = "\003";
$reply = <$client>;
}
if ($reply =~ /<authorized\/>/) {
print "yes\n";
exit 0;
}
}
print "no\n";
exit 1;
}
sub config {
my $client = IO::Socket::INET->new ( PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp' )
or die "Can't bind : $@\n";
print $client "<boinc_gui_rpc_request><auth1/></boinc_gui_rpc_request>\003";
{
local $/ = "\003";
$reply = <$client>;
}
$reply =~ /<nonce>(.*)<\/nonce>/;
my $hash = md5_hex($1, $password);
print $client "<boinc_gui_rpc_request><auth2><nonce_hash>$hash</nonce_hash></auth2></boinc_gui_rpc_request>\003";
{
local $/ = "\003";
$reply = <$client>;
}
if ($reply !~ /<authorized\/>/) {
die "Wrong password: $_";
}
print $client "<boinc_gui_rpc_request><get_state></boinc_gui_rpc_request>";
while (chomp($reply = <$client>) && ($reply ne "</boinc_gui_rpc_reply>")) {
if ($reply =~ /<domain_name>(.*)<\/domain_name>/) {
print "graph_title BOINC task progress [$1]\n";
print "graph_args -l 0\n";
print "graph_vlabel %\n";
}
if ($reply =~ /<project_name>(.*)<\/project_name>/) {
my $boinc_munin_name=$1;
$boinc_munin_name =~ /(\w+).*/;
print "$1.label $boinc_munin_name\n";
}
}
close ($client);
}
sub report {
my $client = IO::Socket::INET->new ( PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp' )
or die "Can't bind : $@\n";
print $client "<boinc_gui_rpc_request><auth1/></boinc_gui_rpc_request>\003";
{
local $/ = "\003";
$reply = <$client>;
}
$reply =~ /<nonce>(.*)<\/nonce>/;
my $hash = md5_hex($1, $password);
print $client "<boinc_gui_rpc_request><auth2><nonce_hash>$hash</nonce_hash></auth2></boinc_gui_rpc_request>\003";
{
local $/ = "\003";
$reply = <$client>;
}
if ($reply !~ /<authorized\/>/) {
die "Wrong password: $_";
}
print $client "<boinc_gui_rpc_request><get_state></boinc_gui_rpc_request>";
while (chomp($reply = <$client>) && ($reply ne "</boinc_gui_rpc_reply>")) {
if ($reply =~ /<project_name>(\w+).*<\/project_name>/) {
$project = $1;
$fraction_done=0;
while (chomp($reply = <$client>) && ($reply ne "<project>") && ($reply ne "</client_state>")) {
if ($reply =~ /\s*<active_task_state>1<\/active_task_state>/) {
while (chomp($reply = <$client>) && ($reply ne "</active_task>")) {
if ($reply =~ /<fraction_done>(.*)<\/fraction_done>/) {
$fraction_done+=int($1*100 + .5 * ($1*100 <=> 0));
}
}
}
}
print "$project.value $fraction_done\n";
}
}
close ($client);
}
if (defined $ARGV[0]) {
my $arg = $ARGV[0];
my %funcs = ( config => \&config,
autoconf => \&autoconf,
report => \&report
);
if (exists $funcs{$arg}) {
$funcs{$arg}->();
}
else {
$funcs{"report"}->();
}
} else {
report();
}

View file

@ -1,2 +0,0 @@
Check http://aouyar.github.com/PyMunin/ to get the most recent versionof the
PyMunin Multi graph Munin Plugins and documentation.

View file

@ -1,2 +0,0 @@
Check http://aouyar.github.com/PyMunin/ to get the most recent versionof the
PyMunin Multi graph Munin Plugins and documentation.

View file

@ -1,185 +0,0 @@
#!/usr/bin/perl -w
=head1 NAME
dnsresponse - Plugin to monitor DNS resolution times.
"Poor man's smokeping" :)
=head1 APPLICABLE SYSTEMS
Any unix system.
=head1 CONFIGURATION
The following shows the default configuration.
[dnsresponse_*]
env.site www.google.com
env.times 20
=head1 INTERPRETATION
The plugin shows the average and median times taken to resolve a site.
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf,suggest
=head1 BUGS
None known.
=head1 VERSION
$Id: dnsresponse_ 61 2009-04-14 09:11:00Z stsimb $
=head1 AUTHOR
Copyright (c) 2009 by Sotiris Tsimbonis.
=head1 LICENSE
GPLv2
=cut
#%# family=auto
#%# capabilities=autoconf suggest
use strict;
use warnings;
my $DEBUG=0;
my $site = exists $ENV{'site'} ? $ENV{'site'} : "www.google.com";
my $times = exists $ENV{'times'} ? $ENV{'times'} : "20";
my $resconf="/etc/resolv.conf";
use File::Basename;
my $basename=basename($0);
my $scriptname;
my $dnsip;
($scriptname, $dnsip) = split("_", $basename);
print "DBG: target dns ip $dnsip\n" if ($DEBUG>0);
if ( defined $ARGV[0] and $ARGV[0] eq "config" ) {
print "graph_title $dnsip DNS response time\n";
print "graph_vlabel milliseconds\n";
print "graph_scale no\n";
print "graph_category Other\n";
print "graph_info Time taken by $dnsip to resolve $site $times times.\n";
#my @val = ("min", "avg", "median", "max");
my @val = ("avg", "median", "stddev");
my $value;
foreach $value ( @val ) {
if ($value eq "stddev") {
print "$value.info Standard deviation (variance).\n";
} else {
print "$value.info $value time taken by $dnsip to resolve $site $times times.\n";
}
print "$value.label $value\n";
# print "$value.type DERIVE\n";
# print "$value.min 0\n";
# print "$value.warning 100\n";
# print "$value.critical 600\n";
}
exit 0;
}
if ( defined $ARGV[0] and $ARGV[0] eq "autoconf" ) {
my $ret;
if (! eval "require Net::DNS;") { $ret .= "Net::DNS not found. "; }
if (! eval "require Time::HiRes;") { $ret .= "Time::HiRes not found. "; }
if (! -s $resconf) { $ret .= "$resconf not found. "; }
if ($ret) {
print "no ($ret)\n";
exit 1;
} else {
print "yes\n";
exit 0;
}
}
if ( defined $ARGV[0] and $ARGV[0] eq "suggest" ) {
if (-s $resconf) {
open (FILE, "< $resconf") || die "Could not open $resconf: $!\n";
my $line;
while ($line = <FILE>) {
if ($line =~ /^nameserver/) {
my $ns; my $ip;
($ns, $ip) = split(" ", $line);
print "$ip\n";
}
}
exit 0;
} else {
print "ERROR reading $resconf\n";
exit 1;
}
}
use Time::HiRes qw ( gettimeofday tv_interval );
use Net::DNS;
my $res = Net::DNS::Resolver->new(
nameservers => [$dnsip],
recurse => 1,
debug => $DEBUG,
);
my $i;
my @restimes;
for ($i=1; $i<=$times; $i++) {
my $t0 = [gettimeofday];
my $answer = $res->send($site);
my $elapsed = tv_interval ($t0);
push(@restimes, $elapsed);
print "DBG: count $i elapsed $elapsed\n" if ($DEBUG>0);
}
@restimes=sort(@restimes);
#my $min=$restimes[0]*1000;
my $average=mean(@restimes)*1000;
my $median=median(@restimes)*1000;
my $stddev=std_dev_ref_sum(@restimes)*1000;
#my $max=$restimes[$times-1]*1000;
#print "min.value $min\n";
print "avg.value $average\n";
print "median.value $median\n";
print "stddev.value $stddev\n";
#print "max.value $max\n";
sub mean {
my $result;
foreach (@_) { $result += $_ }
return $result / @_;
}
sub median {
my @ar = @_;
my $elements = scalar(@ar);
return $ar[(int($elements-1)/2)];
# if ($elements % 2) {
# return $ar[($elements-1)/2];
# } else {
# return ($ar[($elements-1)/2-0.5]+$ar[($elements-1)/2+0.5])/2;
# }
}
# Standard Deviance function from http://www.linuxjournal.com/article/6540
sub std_dev_ref_sum {
my @ar = @_;
my $elements = scalar @ar;
my $sum = 0;
my $sumsq = 0;
foreach (@ar) {
$sum += $_;
$sumsq += ($_ **2);
}
return sqrt( $sumsq/$elements - (($sum/$elements) ** 2));
}

View file

@ -1,159 +0,0 @@
#!/bin/bash
# Simple munin plugin to find the google rank for a URL/WORD combination
#
# THIS SCRIPT BREAKS THE TOS OF GOOGLE SO USE WITH CARE AND DON'T BLAME ME IF THINGS GO WRONG
#
# (c) 2009 i.dobson@planet-ian.com
#
# For each url/words that you want to watch you need to create a variable/word pair in your
# munin-node configuration file for example
#
#[google_rank]
#user root
#timeout 60
#env.URL1 http://www.plant-ian.com
#env.WORD1 avr webcam
#env.URL2 http://www.plant-ian.com
#env.WORD2 bascom
#
# Version 0.5 24.1.2009
# Added loop to check the first 500 pages. Note the script sleeps 5 seconds beween each page grab so
# If the word/url your looking for is in the higher positions then you need to increase the timeout
#
# Version 0.5 21.1.2009
# Dump each page grabbed from google into seperate files (helps with debugging)
#
# Version 0.4 19.1.2009
# Fixed corrupt then empty cache file bug
#
# Version 0.3 19.1.2009
# The script now grabs the google page based on the LASTHIT counter.
# The script grabs the google page for URL1, then the next time it's called URL2 etc. If the url/word pair doesn't exist for LASTHIT then the script just dumps the cached data
#
# Version 0.2 18.01.2009
# Cache added, the script only grabs the pages from google every 10 calls
# The script still only checks to first 100 pages returned by google
#
# Version 0.1 17.01.2009 Initial release
# The script only checks to first 100 pages returned by google
#
# Auto Configure, Check it word 1 is defined
if [ "$1" = "autoconf" ]; then
if [ "$URL1" != "" ]; then
if [ "$WORD1" != "" ]; then
echo yes
exit 0
fi
fi
echo no
exit 1
fi
#Configure, loop through each variable defined WORDx URLx dumping it to munin
if [ "$1" = "config" ]; then
iLoop=1
echo 'graph_title Google page rank'
echo 'graph_args --upper-limit 100 -l 0'
echo 'graph_category other'
echo 'graph_scale no'
echo 'graph_info Google page rank for URLs & Words'
URL="xxx"
until [ "$URL" = "" ]; do
TMPURL=URL$iLoop
URL="${!TMPURL}"
TMPWORD=WORD$iLoop
WORD="${!TMPWORD}"
if [ "$URL" = "" ]; then
exit 0
fi
if [ "$WORD" = "" ]; then
exit 0
fi
VAR=`echo $URL.$WORD | sed -e "s/http:\/\///g"| sed -e "s/ /_/g"| sed -e "s/\./_/g"| sed -e "s/\-/_/g"`
URL=`echo $URL| sed -e "s/http:\/\///g"`
echo $VAR.label Pagerank $URL - $WORD
let iLoop="$iLoop +1"
done
exit 0
fi
#Meat of the program, grabs data from google for one word/url pair using LASTHIT as the pointer to which url/word pair to read
#Read update & save counter
LASTHIT=0
if [ -f /tmp/google_rank.status ]; then
LASTHIT=`cat /tmp/google_rank.status | awk '{print $1}'`
fi
let LASTHIT="$LASTHIT + 1"
echo $LASTHIT > /tmp/google_rank.status
#Find URL/WORD PAIR for loop counter
TMPURL=URL$LASTHIT
URL="${!TMPURL}"
TMPWORD=WORD$LASTHIT
WORD="${!TMPWORD}"
if [ "$URL" != "" ]; then
#Setup defaults
base=0
num=1
start=0
FOUND=0
#Clean up URL/WORD pair, removing http:// replacing " " with "_", "." with "_", "-" with "-"
VAR=`echo $URL.$WORD | sed -e "s/http:\/\///g"| sed -e "s/ /_/g"| sed -e "s/\./_/g"| sed -e "s/\-/_/g"`
SEARCHWORD=`echo $WORD| sed -e "s/ /%20/g"`
until [ "$FOUND" -ne "0" ]; do
#Grab page from google for the WORD/PAGE combination.Pipe it into awk to pull out the url's only, one per line. Then dump only the lines containing the URL defined
wget -q --user-agent=Firefox -O - http://www.google.com/search?q=$SEARCHWORD\&num=100\&hl=en\&safe=off\&pwst=1\&start=$start\&sa=N > /tmp/google_rank.$LASTHIT.data
VALUE=`cat /tmp/google_rank.$LASTHIT.data|sed 's/<a href=\"\([^\"]*\)\" class=l>/\n\1\n/g'|awk -v num=$num -v base=$base '{ if ( $1 ~ /^http/ ) print base,num++,$NF }'|awk '{ print $2 " " $3}'|grep -i $URL| awk '{ print $1}'`
VALUE=`echo $VALUE| awk '{ print $1}'`
if [ "$VALUE" = "" ]; then
VALUE=-1
let start="start + 100"
sleep 5
else
FOUND=1
let VALUE="$VALUE + $start"
fi
### echo Start=$start Value=$VALUE Found=$FOUND
if [ "$start" -gt 500 ];then
FOUND=-1
VALUE=-1
fi
done
#Read through cache file saving to array
iLoop=1
while read line ;do
Data[$iLoop]=$line
let iLoop="$iLoop +1"
done < /tmp/google_rank.cache
#replace one line with the new value grabbed from google
Data[$LASTHIT]="$VAR.value $VALUE"
#write data back
rm /tmp/google_rank.cache
for iLoop in `seq 1 10`; do
echo ${Data[$iLoop]} >> /tmp/google_rank.cache
done
fi
#Reset counter to start
if [ "$LASTHIT" -gt 30 ]; then
echo 0 > /tmp/google_rank.status
fi
#Dump data to munin
while read line ;do
if [ "$line" != "" ]; then
echo $line
fi
done < /tmp/google_rank.cache
exit 0

View file

@ -1,241 +0,0 @@
#!/usr/bin/perl -w
=head1 NAME
multi_snmp_querier - Munin plugin to query several SNMP hosts
=head1 SYNOPSIS
This plugin is meant to be called from Munin. You should at least set the
'hosts' environment variable from Munin's configuration (i.e.
/etc/munin/munin.conf) to specify which hosts and how to query.
=head1 DESCRIPTION
This plugin expects to receive the following environment variables:
=over 4
=item snmp_oid
Which SNMP OID should we query on; it defaults to
1.3.6.1.2.1.43.10.2.1.4.1.1 (total printed pages - of course, it only
makes sense to query a printer on this ;-) ).
Other known and useful OIDs for printers are
1.3.6.1.2.1.43.11.1.1.9.1.1 (total number of pages printed with this
toner cartridge), 1.3.6.1.2.1.43.11.1.1.9.1.1 (total projected
capacity of this toner cartridge - Note that for many makers, the
literal '-2' is returning, meaning more or less "I don't know"), You
might also be interested in 1.3.6.1.2.1.43.11.1.1.6.1.1 (toner type
this printer uses), although as it is a constant string and not
indicative of any kind of value, there's no use in putting it into
Munin (at least, not via this plugin).
Appropriate labels will be given when Munin requests for configuration
on the above mentioned OIDs - Of course, other OIDs will get far more
generic labels.
=item hosts (REQUIRED!)
Comma-separated list of hosts to send SNMP queries to. You can specify
SNMP port and community to each of the hosts by listing them as
community@host:port - Community defaults to public, port defaults to
161. The following is a valid hosts declaration:
hosts='192.168.0.15, 192.168.0.18:162, private@192.168.0.20'
It will query host 192.168.0.15 on port 161 with the 'private'
community, host 192.168.0.18 on port 162 with the 'private' community
and host 192.168.0.20 on port 161 with the 'public' community.
=back
=head1 DEPENDS ON
L<Net::Ping>, L<Net::SNMP>
=head1 SEE ALSO
L<munin>, L<munin-node>
=head1 TO DO
Add a mechanism to specify the labels for unknown OIDs
=head1 AUTHOR
Gunnar Wolf <gwolf@gwolf.org>
=head1 COPYRIGHT
Copyright 2008 Gunnar Wolf, Instituto de Investigaciones
Economicas, UNAM. This plugin is Free Software; you can
redistribute it and/or modify it under the terms of the GNU General
Public License as published by the Free Software Foundation; version 2
dated June, 1991, or any later version (at your choice).
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
=cut
use strict;
use Net::SNMP;
use Net::Ping;
my (%defaults, @hosts, $oid, %known_oids, $VERSION, $cmd_arg);
$VERSION = '1.0'; # No, not a module, not used in any way - but where else? :)
%defaults = (community => 'public',
timeout => 1,
port => 161,
oid => '1.3.6.1.2.1.43.10.2.1.4.1.1');
@hosts = get_hosts($ENV{hosts});
$oid = $ENV{snmp_oid} || $defaults{oid};
%known_oids = ('1.3.6.1.2.1.43.10.2.1.4.1.1' =>
{ title => 'Pages',
vlabel => 'Printed pages',
category => 'Printer',
info => 'Returns the total number of printed pages per defined printer',
total => 'Total',
units => 'pages'
},
'1.3.6.1.2.1.43.11.1.1.8.1.1' =>
{ title => 'Total projected capacity of this cartridge',
vlabel => 'Total capacity',
category => 'Printer',
info => 'Returns the total projected capacity (in pages) of '.
'the currently installed cartridge',
total => 'Total',
units => 'pages'
},
'1.3.6.1.2.1.43.11.1.1.9.1.1' =>
{ title => 'Pages printed with this cartridge',
vlabel => 'Printed pages',
category => 'Printer',
info => 'Returns the total number of printed pages per ' .
'defined printer with the current cartridge',
total => 'Total',
units => 'pages'
},
'default' =>
{ title => "Results for SNMP OID $oid",
vlabel => 'units',
category => 'Other',
info => "Results for SNMP OID $oid",
total => 'Total',
units => 'units'
}
);
die "Hosts not set - cannot continue" unless @hosts;
$cmd_arg = $ARGV[0] || '';
if($cmd_arg eq "config") {
my $labels = $known_oids{$oid} || $known_oids{default};
# See http://munin.projects.linpro.no/wiki/HowToWritePlugins for
# explanation on the following fields
print "graph_title $labels->{title}\n";
print "graph_args --base 1000 -l 0\n";
print "graph_vlabel $labels->{vlabel}\n";
print "graph_scale no\n";
print "graph_category $labels->{category}\n";
print "graph_info $labels->{info}\n";
print "graph_total $labels->{total}\n";
for my $host (@hosts) {
my $addr = host_label_for($host->{addr});
print "${addr}_pages.label $addr\n";
print "${addr}_pages.draw AREA\n";
print "${addr}_pages.type DERIVE\n";
print "${addr}_pages.info $labels->{units} per minute\n";
}
exit 0;
} elsif ($cmd_arg eq 'autoconf') {
print "yes\n";
exit 0;
}
for my $host (@hosts) {
my ($data, $addr);
$data = get_value_for($host);
$addr = host_label_for($host->{addr});
# We only use N/A as an internal marker - It would just confuse RRD.
next if $data eq 'N/A';
print "${addr}_pages.value $data\n";
}
exit 0;
sub ck_alive{
my ($host, $ping);
$host = shift;
$ping = Net::Ping->new("tcp", 1);
$ping->ping($host);
}
sub get_hosts {
# Hosts are defined in the 'hosts' environment variable. It's a list of
# hosts (and optionally ports) - We parse the list and arrange it neatly
# to be easily consumed.
my ($hostsdef, @hosts);
$hostsdef = shift;
for my $host (split(/,/, $hostsdef)) {
$host =~ s/\s//g;
$host =~ /^(?:(.*)@)?
([^:]+)
(?::(\d+))?$/x;
push @hosts, {community => $1 || $defaults{community},
addr => $2,
port => $3 || $defaults{port} };
}
return @hosts;
}
sub get_value_for {
my ($host, $snmp, $data);
$host = shift;
ck_alive($host->{addr}) or return 'N/A';
$snmp = setup_snmp($host);
$data = $snmp->get_request($oid);
return 'N/A' unless $data->{$oid};
return $data->{$oid};
}
sub setup_snmp {
my ($host, $session, $error);
$host = shift;
($session, $error) = Net::SNMP->session( -hostname => $host->{addr},
-port => $host->{port},
-community => $host->{community},
-timeout => $defaults{timeout} );
$session or die "Error before query $host->{addr}:$host->{port}: $error";
return $session;
}
sub host_label_for {
my ($addr);
$addr = 'src_' . shift;
$addr =~ s/\./_/g; # Periods not allowed in variable names
return $addr;
}

View file

@ -1,701 +0,0 @@
#!/usr/bin/perl
#
=head1 NAGIOS MULTIGRAPH
A Plugin to monitor Nagios Servers and their Performance (Multigraph)
=head1 MUNIN CONFIGURATION
[nagios_multi_*]
user root
env.binary /usr/local/nagios/bin/nagiostats *default*
env.passive off *default*
=head2 MUNIN ENVIRONMENT CONFIGURATION EXPLANATION
binary = location of your nagiostats binary including binary
passive = tell the plugin to graph passive results
=head1 NODE CONFIGURATION
Make sure the nagiostats binary exists and is executable by root
or by the user specified that the plugin will run as.
Available root graphs and subgraphs contained in this Plugin.
services => I<MULTIGRAPH> This graphs the current service problems.
svcchkdetail => This graph shows current services warning,critical,unknown,checked,scheduled,flapping,down
svcchkext => This graph shows the service check execution times
svcchklat => This graph shows the service check latency times
svcchksc => This graph shows the serivce check state change %
hosts => I<MULTIGRAPH> This graphs the current host problems.
hostchkdetail => This graph shows current hosts down,unreachable,checked,scheduled,flapping,down
hostchkext => This graph shows the host check execution times
hostchklat => This graph shows the host check latency times
hostchksc => This graph shows the host check state change %
checks => I<MULTIGRAPH> This graphs the current host problems.
extcmdcount => This graph shows external command buffer availability / usage
hostchkactcount => This graph shows the active host checks for the last 1,5,15,60M
hostchkpsvcount => This graph shows the passive host checks for the last 1,5,15,60M
* depends on passive flag, which defaults to off, and forces these graphs to not be drawn
svcchkactcount => This graph shows the active service checks for the last 1,5,15,60M
svcchkpsvcount => This graph shows the passive service checks for the last 1,5,15,60M
* depends on passive flag, which defaults to off, and forces these graphs to not be drawn
=head1 MUNIN PLUGIN DOCUMENTATION
This is just some helpful links for plugin troubleshooting.
http://munin-monitoring.org/wiki/Documentation#Plugins
http://munin-monitoring.org/wiki/protocol-config
=head1 AUTHOR
Matt West < https://github.com/mhwest13/Nagios-Munin-Plugin >
=head1 LICENSE
GPLv2
=head1 MAGIC MARKERS
#%# family=auto
#%# capabilities=autoconf suggest
=cut
use strict;
use warnings;
use Munin::Plugin;
use File::Basename;
if (basename($0) !~ /^nagios_multi_/) {
print "This script needs to be named nagios_multi_ and have symlinks which start the same.\n";
exit 1;
}
# tell munin about our multigraph capabilties
need_multigraph();
# import binary information or use default setting
my $binary = $ENV{binary} || '/usr/local/nagios/bin/nagiostats';
unless ((-e $binary) && (-x $binary)) {
# err, I'm unable to run the binary specified
print "no: Unable to execute $binary\n";
exit 1;
}
# import passive flag or use default setting
my $passive = $ENV{passive} || 'off';
=head1 Graph Declarations
This block of code builds up all of the graph info for all root / sub graphs.
%graphs: is a container for all of the graph definition information. In here is where you'll
find the configuration information for munin's graphing procedure.
Format:
$graph{graph_name} => {
config => {
You'll find the main graph config stored here
{ key => value },
{ ... },
},
keys => [ 'Name', 'Name', 'Name', ... ],
datasrc => [
Name: name given to data value
Attr: Attribute and value, attribute must be valid plugin argument
{ name => 'Name', info => 'info about graph' },
{ ... },
],
results => {
You'll find the results info from a stats call stored here
{ key => value },
{ ... },
},
}
=cut
my %graphs;
# main graph for service checks
$graphs{services} = {
config => {
args => '--lower-limit 0',
vlabel => 'Service Problems',
category => 'nagios',
title => 'Service Problems',
info => 'Current Service Problems by Alert Status',
},
keys => [ 'NUMSVCOK', 'NUMSVCWARN', 'NUMSVCUNKN', 'NUMSVCCRIT' ],
datasrc => [
{ name => 'NUMSVCOK', label => 'Up', min => '0', type => 'GAUGE', info => 'number of services which are Ok.', graph => 'no', draw => 'LINE2' },
{ name => 'NUMSVCWARN', label => 'Warning', min => '0', type => 'GAUGE', info => 'number of services which are Warning.', draw => 'LINE2' },
{ name => 'NUMSVCUNKN', label => 'Unknown', min => '0', type => 'GAUGE', info => 'number of services which are Unknown.', draw => 'LINE2' },
{ name => 'NUMSVCCRIT', label => 'Critical', min => '0', type => 'GAUGE', info => 'number of services which are Critical.', draw => 'LINE2' },
],
};
# multi-graph for service check detail information ( sub graph of service problems graph )
$graphs{svcchkdetail} = {
config => {
args => '--lower-limit 0',
vlabel => 'Total number of Service Checks',
category => 'details',
title => 'Detailed Service Info',
info => 'Detailed Service Check Information',
},
keys => [ 'NUMSVCWARN', 'NUMSVCUNKN', 'NUMSVCCRIT', 'NUMSVCCHECKED', 'NUMSVCSCHEDULED', 'NUMSVCFLAPPING', 'NUMSVCDOWNTIME' ],
datasrc => [
{ name => 'NUMSVCWARN', label => 'Warning', min => '0', type => 'GAUGE', info => 'number of services which are Warning.', draw => 'LINE2' },
{ name => 'NUMSVCUNKN', label => 'Unknown', min => '0', type => 'GAUGE', info => 'number of services which are Unknown.', draw => 'LINE2' },
{ name => 'NUMSVCCRIT', label => 'Critical', min => '0', type => 'GAUGE', info => 'number of services which are Critical.', draw => 'LINE2' },
{ name => 'NUMSVCCHECKED', label => 'Checked', min => '0', type => 'GAUGE', info => 'total number of services that have been checked since start.', draw => 'LINE2' },
{ name => 'NUMSVCSCHEDULED', label => 'Scheduled', min => '0', type => 'GAUGE', info => 'total number of services that are currently scheduled to be checked.', draw => 'LINE2' },
{ name => 'NUMSVCFLAPPING', label => 'Flapping', min => '0', type => 'GAUGE', info => 'total number of services that are currently flapping.', draw => 'LINE2' },
{ name => 'NUMSVCDOWNTIME', label => 'Scheduled Downtime', min => '0', type => 'GAUGE', info => 'total number of services that are currently in scheduled downtime.', draw => 'LINE2' },
],
};
# multi-graph for service check % state change ( sub graph of service problems graph )
$graphs{svcchksc} = {
config => {
args => '--lower-limit 0 --upper-limit 100',
vlabel => '%',
category => 'statechange',
title => 'Service State Change',
info => 'Total Percent of State Change between checks',
},
keys => [ 'MINSVCPSC', 'MAXSVCPSC', 'AVGSVCPSC' ],
datasrc => [
{ name => 'MINSVCPSC', label => 'Min', min => '0', type => 'GAUGE', info => 'min service check % state change.', draw => 'AREA' },
{ name => 'MAXSVCPSC', label => 'Max', min => '0', type => 'GAUGE', info => 'max service check % state change.', draw => 'AREA' },
{ name => 'AVGSVCPSC', label => 'Average', min => '0', type => 'GAUGE', info => 'avg service check % state change.', draw => 'LINE2' },
],
};
# multi-graph for service check latency and execution times ( sub graph of service problems graph )
$graphs{svcchklat} = {
config => {
args => '--lower-limit 0',
vlabel => 'time (ms)',
category => 'latency',
title => 'Service Check Latency Times',
info => 'Service Check Latency Times',
},
keys => [ 'MINACTSVCLAT', 'MAXACTSVCLAT', 'AVGACTSVCLAT' ],
datasrc => [
{ name => 'MINACTSVCLAT', label => 'Min Latency', min => '0', type => 'GAUGE', info => 'min active service check latency (ms).', draw => 'LINE2' },
{ name => 'MAXACTSVCLAT', label => 'Max Latency', min => '0', type => 'GAUGE', info => 'max active service check latency (ms).', draw => 'LINE2' },
{ name => 'AVGACTSVCLAT', label => 'Average Latency', min => '0', type => 'GAUGE', info => 'avg active service check latency (ms).', draw => 'LINE2' },
],
};
# multi-graph for service check execution time ( sub graph of service problems graph )
$graphs{svcchkext} = {
config => {
args => '--lower-limit 0',
vlabel => 'time (ms)',
category => 'execution',
title => 'Service Check Execution Times',
info => 'Service Check Execution Times',
},
keys => [ 'MINACTSVCEXT', 'MAXACTSVCEXT', 'AVGACTSVCEXT' ],
datasrc => [
{ name => 'MINACTSVCEXT', label => 'Min Execution', min => '0', type => 'GAUGE', info => 'min active service check execution time (ms).', draw => 'LINE2' },
{ name => 'MAXACTSVCEXT', label => 'Max Execution', min => '0', type => 'GAUGE', info => 'max active service check execution time (ms).', draw => 'LINE2' },
{ name => 'AVGACTSVCEXT', label => 'Average Execution', min => '0', type => 'GAUGE', info => 'avg active service check execution time (ms).', draw => 'LINE2' },
],
};
# main graph for host problems
$graphs{hosts} = {
config => {
args => '--lower-limit 0',
vlabel => 'Host Problems',
category => 'nagios',
title => 'Host Problems',
info => 'Current Host Problems by Alert Status',
},
keys => [ 'NUMHSTUP', 'NUMHSTDOWN', 'NUMHSTUNR' ],
datasrc => [
{ name => 'NUMHSTUP', label => 'Up', min => '0', type => 'GAUGE', info => 'number of hosts up.', graph => 'no', draw => 'LINE2' },
{ name => 'NUMHSTDOWN', label => 'Down', min => '0', type => 'GAUGE', info => 'number of hosts which are down.', draw => 'LINE2' },
{ name => 'NUMHSTUNR', label => 'Unknown', min => '0', type => 'GAUGE', info => 'number of hosts which are Unreachable.', draw => 'LINE2' },
],
};
# multi-graph for host check detail information ( sub graph of host problems graph )
$graphs{hostchkdetail} = {
config => {
args => '--lower-limit 0',
vlabel => 'Total number of Host Checks',
category => 'details',
title => 'Detailed Host Info',
info => 'Detailed Host Check Information',
},
keys => [ 'NUMHSTDOWN', 'NUMHSTUNR', 'NUMHSTCHECKED', 'NUMHSTSCHEDULED', 'NUMHSTFLAPPING', 'NUMHSTDOWNTIME' ],
datasrc => [
{ name => 'NUMHSTDOWN', label => 'Down', min => '0', type => 'GAUGE', info => 'number of hosts which are down.', draw => 'LINE2' },
{ name => 'NUMHSTUNR', label => 'Unknown', min => '0', type => 'GAUGE', info => 'number of hosts which are Unreachable.', draw => 'LINE2' },
{ name => 'NUMHSTCHECKED', label => 'Checked', min => '0', type => 'GAUGE', info => 'total number of hosts that have been checked since start.', draw => 'LINE2' },
{ name => 'NUMHSTSCHEDULED', label => 'Scheduled', min => '0', type => 'GAUGE', info => 'total number of hosts that are currently scheduled to be checked.', draw => 'LINE2' },
{ name => 'NUMHSTFLAPPING', label => 'Flapping', min => '0', type => 'GAUGE', info => 'total number of hosts that are currently flapping.', draw => 'LINE2' },
{ name => 'NUMHSTDOWNTIME', label => 'Downtime', min => '0', type => 'GAUGE', info => 'total number of hosts that are currently in scheduled downtime.', draw => 'LINE2' },
],
};
# multi-graph for host check % state change ( sub graph of host problems graph )
$graphs{hostchksc} = {
config => {
args => '--lower-limit 0 --upper-limit 100',
vlabel => '%',
category => 'statechange',
title => 'Host State Change',
info => 'Total Percent of State Change between checks',
},
keys => [ 'MINHSTPSC', 'MAXHSTPSC', 'AVGHSTPSC' ],
datasrc => [
{ name => 'MINHSTPSC', label => 'Min', min => '0', type => 'GAUGE', info => 'min host check % state change.', draw => 'AREA' },
{ name => 'MAXHSTPSC', label => 'Max', min => '0', type => 'GAUGE', info => 'max host check % state change.', draw => 'AREA' },
{ name => 'AVGHSTPSC', label => 'Average', min => '0', type => 'GAUGE', info => 'avg host check % state change.', draw => 'LINE2' },
],
};
# multi-graph for host check latency times ( sub graph of host problems graph )
$graphs{hostchklat} = {
config => {
args => '--lower-limit 0',
vlabel => 'time (ms)',
category => 'latency',
title => 'Host Check Latency Times',
info => 'Host Check Latency Times',
},
keys => [ 'MINACTHSTLAT', 'MAXACTHSTLAT', 'AVGACTHSTLAT' ],
datasrc => [
{ name => 'MINACTHSTLAT', label => 'Min Latency', min => '0', type => 'GAUGE', info => 'min active host check latency (ms).', draw => 'LINE2' },
{ name => 'MAXACTHSTLAT', label => 'Max Latency', min => '0', type => 'GAUGE', info => 'max active host check latency (ms).', draw => 'LINE2' },
{ name => 'AVGACTHSTLAT', label => 'Average Latency', min => '0', type => 'GAUGE', info => 'avg active host check latency (ms).', draw => 'LINE2' },
],
};
# multi-graph for host check execution times ( sub graph of host problems graph )
$graphs{hostchkext} = {
config => {
args => '--lower-limit 0',
vlabel => 'time (ms)',
category => 'execution',
title => 'Host Check Execution Times',
info => 'Host Check Execution Times',
},
keys => [ 'MINACTHSTEXT', 'MAXACTHSTEXT', 'AVGACTHSTEXT' ],
datasrc => [
{ name => 'MINACTHSTEXT', label => 'Min Execution', min => '0', type => 'GAUGE', info => 'min active host check execution time (ms).', draw => 'LINE2' },
{ name => 'MAXACTHSTEXT', label => 'Max Execution', min => '0', type => 'GAUGE', info => 'max active host check execution time (ms).', draw => 'LINE2' },
{ name => 'AVGACTHSTEXT', label => 'Average Execution', min => '0', type => 'GAUGE', info => 'avg active host check execution time (ms).', draw => 'LINE2' },
],
};
# main graph for host / service check counts
$graphs{checks} = {
config => {
args => '--lower-limit 0',
vlabel => 'Total number of Checks',
category => 'nagios',
title => 'Totals',
info => 'Total Number of Service and Host Checks',
},
keys => [ 'NUMSERVICES', 'NUMHOSTS' ],
datasrc => [
{ name => 'NUMSERVICES', label => 'Number of Services', min => '0', type => 'GAUGE', info => 'total number of services.', draw => 'LINE2' },
{ name => 'NUMHOSTS', label => 'Number of Hosts', min => '0', type => 'GAUGE', info => 'total number of hosts.', draw => 'LINE2' },
],
};
# multi-graph for number of host checks in x mins ( sub graph of checks graph )
$graphs{hostchkactcount} = {
config => {
args => '--lower-limit 0',
vlabel => 'Host Checks',
category => 'active',
title => 'Host Checks',
info => 'Total Number of Active Host Checks',
order => 'NUMHSTACTCHK60M NUMHSTACTCHK15M NUMHSTACTCHK5M NUMHSTACTCHK1M',
},
keys => [ 'NUMHSTACTCHK1M', 'NUMHSTACTCHK5M', 'NUMHSTACTCHK15M', 'NUMHSTACTCHK60M' ],
datasrc => [
{ name => 'NUMHSTACTCHK1M', label => 'Active Checks 1m', min => '0', type => 'GAUGE', info => 'number of hosts actively checked in last 1 minutes.', draw => 'AREA' },
{ name => 'NUMHSTACTCHK5M', label => 'Active Checks 5m', min => '0', type => 'GAUGE', info => 'number of hosts actively checked in last 5 minutes.', draw => 'AREA' },
{ name => 'NUMHSTACTCHK15M', label => 'Active Checks 15m', min => '0', type => 'GAUGE', info => 'number of hosts actively checked in last 15 minutes.', draw => 'AREA' },
{ name => 'NUMHSTACTCHK60M', label => 'Active Checks 60m', min => '0', type => 'GAUGE', info => 'number of hosts actively checked in last 60 minutes.', draw => 'AREA' },
],
};
# multi-graph for number of host checks in x mins ( sub graph of checks graph )
$graphs{hostchkpsvcount} = {
config => {
args => '--lower-limit 0',
vlabel => 'Host Checks',
category => 'passive',
title => 'Host Checks',
info => 'Total Number of Passive Host Checks',
order => 'NUMHSTPSVCHK60M NUMHSTPSVCHK15M NUMHSTPSVCHK5M NUMHSTPSVCHK1M',
},
keys => [ 'NUMHSTPSVCHK1M', 'NUMHSTPSVCHK5M', 'NUMHSTPSVCHK15M', 'NUMHSTPSVCHK60M' ],
datasrc => [
{ name => 'NUMHSTPSVCHK1M', label => 'Passive Checks 1m', min => '0', type => 'GAUGE', info => 'number of hosts passively checked in last 1 minutes.', draw => 'AREA' },
{ name => 'NUMHSTPSVCHK5M', label => 'Passive Checks 5m', min => '0', type => 'GAUGE', info => 'number of hosts passively checked in last 5 minutes.', draw => 'AREA' },
{ name => 'NUMHSTPSVCHK15M', label => 'Passive Checks 15m', min => '0', type => 'GAUGE', info => 'number of hosts passively checked in last 15 minutes.', draw => 'AREA' },
{ name => 'NUMHSTPSVCHK60M', label => 'Passive Checks 60m', min => '0', type => 'GAUGE', info => 'number of hosts passively checked in last 60 minutes.', draw => 'AREA' },
],
};
# multi-graph for number of service checks in x mins ( sub graph of checks graph )
$graphs{svcchkactcount} = {
config => {
args => '--lower-limit 0',
vlabel => 'Service Checks',
category => 'active',
title => 'Service Checks',
info => 'Total Number of Active Service Checks',
order => 'NUMSVCACTCHK60M NUMSVCACTCHK15M NUMSVCACTCHK5M NUMSVCACTCHK1M',
},
keys => [ 'NUMSVCACTCHK1M', 'NUMSVCACTCHK5M', 'NUMSVCACTCHK15M', 'NUMSVCACTCHK60M' ],
datasrc => [
{ name => 'NUMSVCACTCHK1M', label => 'Active Checks 1m', min => '0', type => 'GAUGE', info => 'number of services actively checked in last 1 minutes.', draw => 'AREA' },
{ name => 'NUMSVCACTCHK5M', label => 'Active Checks 5m', min => '0', type => 'GAUGE', info => 'number of services actively checked in last 5 minutes.', draw => 'AREA' },
{ name => 'NUMSVCACTCHK15M', label => 'Active Checks 15m', min => '0', type => 'GAUGE', info => 'number of services actively checked in last 15 minutes.', draw => 'AREA' },
{ name => 'NUMSVCACTCHK60M', label => 'Active Checks 60m', min => '0', type => 'GAUGE', info => 'number of services actively checked in last 60 minutes.', draw => 'AREA' },
],
};
# multi-graph for number of service checks in x mins ( sub graph of checks graph )
$graphs{svcchkpsvcount} = {
config => {
args => '--lower-limit 0',
vlabel => 'Service Checks',
category => 'passive',
title => 'Service Checks',
info => 'Total Number of Passive Service Checks',
order => 'NUMSVCPSVCHK60M NUMSVCPSVCHK15M NUMSVCPSVCHK5M NUMSVCPSVCHK1M',
},
keys => [ 'NUMSVCPSVCHK1M', 'NUMSVCPSVCHK5M', 'NUMSVCPSVCHK15M', 'NUMSVCPSVCHK60M' ],
datasrc => [
{ name => 'NUMSVCPSVCHK1M', label => 'Passive Checks 1m', min => '0', type => 'GAUGE', info => 'number of services passively checked in last 1 minutes.', draw => 'AREA' },
{ name => 'NUMSVCPSVCHK5M', label => 'Passive Checks 5m', min => '0', type => 'GAUGE', info => 'number of services passively checked in last 5 minutes.', draw => 'AREA' },
{ name => 'NUMSVCPSVCHK15M', label => 'Passive Checks 15m', min => '0', type => 'GAUGE', info => 'number of services passively checked in last 15 minutes.', draw => 'AREA' },
{ name => 'NUMSVCPSVCHK60M', label => 'Passive Checks 60m', min => '0', type => 'GAUGE', info => 'number of services passively checked in last 60 minutes.', draw => 'AREA' },
],
};
# multi-graph for external command count ( sub graph of checks graph )
$graphs{extcmdcount} = {
config => {
args => '--lower-limit 0',
vlabel => 'Ext Command Slots',
category => 'externalcmds',
title => 'External Commands',
info => 'External Command Buffer Slot Information',
},
keys => [ 'TOTCMDBUF', 'USEDCMDBUF', 'HIGHCMDBUF', 'NUMEXTCMDS1M', 'NUMEXTCMDS5M', 'NUMEXTCMDS15M' ],
datasrc => [
{ name => 'TOTCMDBUF', label => 'Total', min => '0', type => 'GAUGE', info => 'total number of external command buffer slots available.', draw => 'AREA' },
{ name => 'USEDCMDBUF', label => 'Current Used', min => '0', type => 'GAUGE', info => 'number of external command buffer slots currently in use.', draw => 'LINE2' },
{ name => 'HIGHCMDBUF', label => 'Peak Used', min => '0', type => 'GAUGE', info => 'highest number of external command buffer slots ever in use.', draw => 'LINE2' },
{ name => 'NUMEXTCMDS1M', label => 'Used last 1m', min => '0', type => 'GAUGE', info => 'number of external commands processed in last 1 minutes.', draw => 'LINE2' },
{ name => 'NUMEXTCMDS5M', label => 'Used last 5m', min => '0', type => 'GAUGE', info => 'number of external commands processed in last 5 minutes.', draw => 'LINE2' },
{ name => 'NUMEXTCMDS15M', label => 'Used last 15m', min => '0', type => 'GAUGE', info => 'number of external commands processed in last 15 minutes.', draw => 'LINE2' },
],
};
=head1 Munin Checks
These checks look for config / autoconf / suggest params
=head2 Config Check
This block of code looks at the argument that is possibly supplied,
should it be config, it then checks to make sure the plugin
specified exists, assuming it does, it will run the do_config
subroutine for the plugin specified, otherwise it dies complaining
about an unknown plugin.
=cut
if (defined $ARGV[0] && $ARGV[0] eq 'config') {
# Lets take the plugin from the execution name.
$0 =~ /nagios_multi_(.+)*/;
my $plugin = $1;
# And lets make sure we have a plugin called that.
die 'Unknown Plugin Specified: ' . ($plugin ? $plugin : '') unless $graphs{$plugin};
# Now lets go ahead and print out our config.
do_config($plugin);
exit 0;
}
=head2 Autoconf Check
This block of code looks at the argument that is possibly supplied,
should it be autoconf, we are going to print yes at this point since
we've already tested for our binary to exist and be executable, the
process will then exit.
=cut
if (defined $ARGV[0] && $ARGV[0] eq 'autoconf') {
# well we can execute the binary, so plugin should be good from here...
print "yes\n";
exit 0;
}
=head2 Suggest Check
This block of code looks at the argument that is possibly supplied,
should it be suggest, we are going to print the possible plugins
which can be specified. Note we only specify the root graphs for the
multigraphs, since the rest of the subgraphs will appear "behind" the
root graphs.
=cut
if (defined $ARGV[0] && $ARGV[0] eq 'suggest') {
# well we can execute the binary, so print possible root multigraph plugin names
my @rootplugins = ('services','hosts','checks');
foreach my $plugin (@rootplugins) {
print "$plugin\n";
}
exit 0;
}
=head1 Subroutines
Begin Subroutine calls to output data / config information
=head2 fetch_output
This subroutine is the main call for printing data for the plugin.
No parameters are taken as this is the default call if no arguments
are supplied from the command line.
=cut
fetch_output();
sub fetch_output {
# Lets figure out what plugin they want to run, and check that it exists
$0 =~ /nagios_multi_(.+)*/;
my $plugin = $1;
die 'Unknown Plugin Specified: ' . ($plugin ? $plugin : '') unless $graphs{$plugin};
# Lets set up our subgraphs array with all of the graphs which are extensions
# of the root graph / plugin
my @subgraphs;
if ($plugin eq 'services') {
@subgraphs = ('svcchkdetail','svcchksc','svcchklat','svcchkext');
} elsif ($plugin eq 'hosts') {
@subgraphs = ('hostchkdetail','hostchksc','hostchklat','hostchkext');
} elsif ($plugin eq 'checks') {
@subgraphs = ('svcchkactcount','hostchkactcount','extcmdcount');
if ($passive =~ /on/i) {
push(@subgraphs,'svcchkpsvcount');
push(@subgraphs,'hostchkpsvcount');
}
}
# Lets just double check the plugin you specified is a root graph / plugin
if (grep $_ eq $plugin, @subgraphs) {
die "Error: $plugin is not a valid root graph, valid graphs are: @subgraphs\n";
}
# Lets print out the data for our sub graphs / plugins
foreach my $subgraph (@subgraphs) {
print_sub_output($plugin,$subgraph);
}
# Lets print out the data for our main graph / plugin
print_root_output($plugin);
return;
}
=head2 print_root_output
This block of code prints out the return values for our root graphs. It takes
one parameter $plugin. Returns when completed
$plugin; main(root) graph we are calling up to print data values for
Example: print_root_output($plugin);
=cut
sub print_root_output {
# Lets get our plugin, set our graph information, and print for Munin to process
my ($plugin) = (@_);
my $graph = $graphs{$plugin};
print "multigraph nagios_$plugin\n";
# Getting keys to pass to nagiostats for data retrieval
# call up fetch_nagios_stats with the keys we just got.
my @keys = @{$graph->{keys}};
fetch_nagios_stats($plugin,@keys);
# print the results for the keys with the name for Munin to process
foreach my $dsrc (@{$graph->{datasrc}}) {
my $output = 0;
my %datasrc = %$dsrc;
while ( my ($key, $value) = each(%datasrc)) {
next if ($key ne 'name');
print "$dsrc->{name}.value $graph->{results}->{$value}\n";
}
}
return;
}
=head2 print_sub_output
This block of code prints out the return values for our root graphs. It takes
one parameter $plugin. Returns when completed
$plugin; main(root) being called, used for multigraph output
$subgraph; graph we are actually trying to print data values for
Example: print_sub_output($plugin,$subgraph);
=cut
sub print_sub_output {
# Lets get our plugin, set our graph information, and print for Munin to process
my ($plugin,$subgraph) = (@_);
my $graph = $graphs{$subgraph};
print "multigraph nagios_$plugin\.$subgraph\n";
# Getting keys to pass to nagiostats for data retrieval
# call up fetch_nagios_stats with the keys we just got.
my @keys = @{$graph->{keys}};
fetch_nagios_stats($subgraph,@keys);
# print the results for the keys with the name for Munin to process
foreach my $dsrc (@{$graph->{datasrc}}) {
my $output = 0;
my %datasrc = %$dsrc;
while ( my ($key, $value) = each(%datasrc)) {
next if ($key ne 'name');
print "$dsrc->{name}.value $graph->{results}->{$value}\n";
}
}
return;
}
=head2 do_config
This is the main call issued assuming we call up config and plugin specified exists
The subroutine takes one parameter $plugin, and returns when completed.
$plugin; main(root) graph being called
Example: do_config($plugin);
=cut
sub do_config {
# Lets get our plugin and set subgraphs to undef
my ($plugin) = (@_);
my @subgraphs;
if ($plugin eq 'services') {
# update subgraphs since our plugin is services
@subgraphs = ('svcchkdetail','svcchksc','svcchklat','svcchkext');
} elsif ($plugin eq 'hosts') {
# update subgraphs since our plugin is hosts
@subgraphs = ('hostchkdetail','hostchksc','hostchklat','hostchkext');
} elsif ($plugin eq 'checks') {
# update subgraphs since our plugin is checks
@subgraphs = ('svcchkactcount','hostchkactcount','extcmdcount');
if ($passive =~ /on/i) {
push(@subgraphs,'svcchkpsvcount');
push(@subgraphs,'hostchkpsvcount');
}
}
# Now that we know what graphs to reference, lets print out their config info
foreach my $subgraph (@subgraphs) {
print_sub_config($plugin,$subgraph);
}
# Now lets print out the config information for our root graph
print_root_config($plugin);
return;
}
=head2 print_sub_config
This subroutine prints out the config information for all of the subgraphs.
It takes two parameters, $plugin and $subgraph
$plugin; main(root) graph used for multigraph call
$subgraph; subgraph being called up.
Example: print_sub_config($plugin,$subgraph);
=cut
sub print_sub_config {
# Lets get our plugin and subgraph, after that print for Munin to process it.
my ($plugin,$subgraph) = (@_);
my $graph = $graphs{$subgraph};
print "multigraph nagios_$plugin.$subgraph\n";
# Lets print our subgraph's main config info.
my %graphconf = %{$graph->{config}};
while ( my ($key, $value) = each(%graphconf)) {
print "graph_$key $value\n";
}
# Lets print our subgraph's per graph config info.
foreach my $dsrc (@{$graph->{datasrc}}) {
my %datasrc = %$dsrc;
while ( my ($key, $value) = each(%datasrc)) {
next if ($key eq 'name');
print "$dsrc->{name}.$key $value\n";
}
}
return;
}
=head2 print_root_config
This subroutine prints out the config information for all of the main(root) graphs.
It takes one parameters, $plugin
$plugin; main(root) graph used for multigraph call
Example: print_root_config($plugin);
=cut
sub print_root_config {
# Lets get our plugin and graph, after that print for Munin to process it.
my ($plugin) = (@_);
my $graph = $graphs{$plugin};
print "multigraph nagios_$plugin\n";
# Lets print out graph's main config info.
my %graphconf = %{$graph->{config}};
while ( my ($key, $value) = each(%graphconf)) {
print "graph_$key $value\n";
}
# Lets print our graphs per graph config info.
foreach my $dsrc (@{$graph->{datasrc}}) {
my %datasrc = %$dsrc;
while ( my ($key, $value) = each(%datasrc)) {
next if ($key eq 'name');
print "$dsrc->{name}.$key $value\n";
}
}
return;
}
=head2 fetch_nagios_stats
This subroutine actually runs the nagiostats binary with the keys specified in an array
Two parameters are passed, $plugin and @keys, and it will return when complete.
$plugin; graph we are calling up, we use this to store the results in the hash
for easy recall later.
@keys; keys we want the values for from nagiostats binary.
Example: fetch_nagios_stats($plugin,@keys);
=cut
sub fetch_nagios_stats {
# Lets get our current plugin and list of keys we want info for, as well as reference our graph
my ($plugin,@keys) = (@_);
my $graph = $graphs{$plugin};
# Lets set our command to include our binary plus options, as well as join our array with ,'s
my $command = $binary . " -m -d " . join(",",@keys);
# Lets open the command and pipe it out for easy reading by line
open(CMD, "$command |") or die "Unable to execute command: $command\n";
# While a return exists from the command, store the value in the key specified
while (my $line = <CMD>) {
chomp($line);
my $key = shift(@keys);
$graph->{results}->{$key} = $line;
}
return;
}

View file

@ -1,2 +0,0 @@
Check http://aouyar.github.com/PyMunin/
to get the most recent versionof the PyMunin Multi graph Munin Plugins and documentation.

View file

@ -1,49 +0,0 @@
#!/bin/bash
#
# Plugin to monitor clock offset and delay, using ntpdate
#
# Parameters understood:
#
# config (required)
#
# Author: Rune Nordbøe Skillingstad <rune.skillingstad@ntnu.no>
#
# Magic markers - optional - used by installation scripts and
# munin-node-configure:
#
#%# family=manual
#%# capabilities=
#
NTPDATE="/usr/sbin/ntpdate"
PEER=$(basename $0 | sed -e 's/^ntpdate_//' -e 's/_/./g')
if [ ! -x "$NTPDATE" ]; then
echo "Can't find ntpdate executable"
exit 1
fi
if [ "$PEER" = "" ]; then
echo "Unknown peer"
exit 1
fi
if [ "$1" = "config" ]; then
echo "graph_title NTP offset and delay to peer $PEER"
echo "graph_args --base 1000 --vertical-label msec"
echo "offset.label Offset"
echo "offset.draw LINE2"
echo "delay.label Delay"
echo "delay.draw LINE2"
exit 0
fi
LANG=en_US
DATA=($($NTPDATE -q $PEER | awk '/^server.*offset/{gsub(/,/,"");if(dela==0||$8<dela){offs=$6;dela=$8;}}END{print offs*1000,dela*1000;}'))
[ -z "$DATA" -o "x$DATA" = "x0" ] && exit 1
echo "offset.value ${DATA[0]}"
echo "delay.value ${DATA[1]}"
exit 0

View file

@ -1,54 +0,0 @@
#!/usr/bin/perl -w
#
require LWP::UserAgent;
########################################################################################
#
# Installation / Configuration
#
# - place munin_xcache.php in a directory on your webserver
# - add the url config to plugin-conf.d/munin-node
#
#
# for more info see http://www.ohardt.net/dev/munin/
#
#
chomp(my $fqdn=`hostname -f`);
my $URL = exists $ENV{'url'} ? $ENV{'url'} : "http://user:pwd\@$fqdn/munin_xcache_new.php";
$URL = $URL . "?what=mem";
my $ua = LWP::UserAgent->new(timeout => 30);
if ( exists $ARGV[0] and $ARGV[0] eq "config" )
{
$URL = $URL . '&config';
my $response = $ua->request(HTTP::Request->new('GET',$URL . '&config' ));
print $response->content;
exit( 0 );
}
my $response = $ua->request(HTTP::Request->new('GET',$URL));
print $response->content;
exit( 0 );

Binary file not shown.