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

- have some dirs

This commit is contained in:
Steve Schnepp 2012-02-13 18:24:46 +01:00
parent 0b089ea777
commit 08346aac58
687 changed files with 0 additions and 0 deletions

129
plugins/time/freeboxuptime Executable file
View file

@ -0,0 +1,129 @@
#!/bin/bash
#
# Plugin made by Dju
# useful to know your freebox uptime, and to see when it has rebooted ;)
#
# Uses nmap to get the uptime (by tcp connection, RFC1323)
# ports usually opened on the freebox: 80 554 9100
#
# ----------------------------------------------------------------------------------------------------
# nmap example with the -O option
# on a freebox v5
#
# Starting Nmap 4.62 ( http://nmap.org ) at 2010-12-17 02:25 CET
# Interesting ports on mafreebox.freebox.fr (212.27.38.253):
# Not shown: 1712 filtered ports
# PORT STATE SERVICE
# 80/tcp open http
# 554/tcp open rtsp
# 9100/tcp open jetdirect
# Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
# Device type: remote management
# Running: HP embedded
# OS details: HP Onboard Administrator management console
# Uptime: 7.226 days (since Thu Dec 9 21:01:44 2010)
#
# OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
# Nmap done: 1 IP address (1 host up) scanned in 29.279 seconds
# ----------------------------------------------------------------------------------------------------
#
# by using nmap on a specific tcp port, the detection is pretty fast (2-5 seconds)
# with this command: nmap -O --osscan-guess -p80 remote_host
#
# if you dont want nmap to query your freebox each time, set CACHE_HOURS=n
# to keep the uptime in cache for n hours
# if not, set CACHE_HOURS=0
#
# to allow this plugin to use nmap, edit /etc/munin/plugin-conf.d/munin-node and add
# [FreeboxUptime]
# user root
#
# exit value if error:
# 1: nmap not installed
# 2: freebox not reachable by ping
# 3: uptime not found in nmap result
#
# Magic markers - optional - used by installation scripts and
# munin-config:
#
#%# family=manual
#%# capabilities=autoconf
CACHE_FILE=/var/lib/munin/plugin-state/FreeboxUptime.cache
CACHE_HOURS=3
NMAP=$(which nmap)
TCP_PORT=9100
FREEBOX_HOST=mafreebox.freebox.fr
# check if network connection is ok
if ping -c1 -w1 -s20 $FREEBOX_HOST 2>/dev/null > /dev/null; then
PING=1
else
PING=0
fi
if [ "$1" = "autoconf" ]; then
if [ -z "$NMAP" ]; then
echo "no (nmap not installed)"
exit 1
else
if [ $PING -eq 0 ]; then
echo "no (Freebox not reachable)"
exit 2
else
echo yes
exit 0
fi
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Freebox Uptime'
echo 'graph_category Time'
echo 'graph_args --base 1000 -l 0 '
echo 'graph_vlabel uptime in days'
graph_info="Shows the uptime of your freebox (cache: ${CACHE_HOURS}h"
if [ -f $CACHE_FILE ]; then
lastCheck=$(stat -c %z $CACHE_FILE | cut -d"." -f1)
lastReboot=$(awk -F"@" '{print $2}' $CACHE_FILE)
graph_info="${graph_info} - last check: ${lastCheck} - last reboot: $lastReboot"
else
graph_info="${graph_info})"
fi
echo "graph_info ${graph_info}"
echo 'uptime.label uptime'
echo 'uptime.draw AREA'
exit 0
fi
if [ -z "$NMAP" ]; then
exit 1
elif [ $PING -eq 0 ]; then
exit 2
else
use_nmap=1
if [ -f $CACHE_FILE ]; then
ts_cache=$(stat -c %Y $CACHE_FILE)
ts_now=$(date "+%s")
sec_diff=$(expr $ts_now - $ts_cache)
hours_diff=$(expr $sec_diff / 3600)
if [ $hours_diff -lt $CACHE_HOURS ]; then
use_nmap=0
uptime=$(cat $CACHE_FILE | awk -F"@" '{print $1}')
fi
fi
if [ $use_nmap -eq 1 ]; then
uptime=$(nmap -O --osscan-guess -p${TCP_PORT} ${FREEBOX_HOST} | grep Uptime)
if [ -z "$uptime" ]; then
exit 3
else
lastReboot=$(echo $uptime | grep -o '(since .*)' | sed 's/(since //g')
uptime=$(echo $uptime | awk '{print $2}')
echo "${uptime}@${lastReboot}" > $CACHE_FILE
fi
fi
echo "uptime.value ${uptime}"
fi

231
plugins/time/ntp_peers Executable file
View file

@ -0,0 +1,231 @@
#!/usr/bin/perl -w
# -*- perl -*-
# Plugin to monitor offsets to multiple NTP peers.
# NB currently only works for IPv4 peers
#
# (c)2008 Chris Hastie: chris (at) oak (hyphen) wood (dot) co (dot) uk
#
# Updated to version 1.1 by;
# (c)2010 Uffe Norberg: uffe (dot) norberg (at) gmail (dot) com
#
# Parameters understood:
#
# config (required)
# autoconf (optional - used by munin-node-configure)
#
# Config variables:
#
# ntpq - path to ntpq program
# statedir - directory in which to place state file
# hostname_<key> - override hostname for peer <key>. <key> is
# an IPv4 address with dots replaced by underscores.
# Useful for reference clocks, eg
# env.hostname_127_127_43_0 .GPS.
#
#
# This program 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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, see <http://www.gnu.org/licenses/>.
#
# Change log
# v1.0.0 2008-07-21 Chris Hastie
# initial release
#
# v1.1.0 2010-12-07 Uffe Norberg
# - Changed default statedir to /var/lib/munin/plugin-state (Debian default)
# - Changed config output to make rrdtool draw finer lines in graph
# - Changed config output so that rrdtool draws milli- and microseconds correctly
#
#
# Magic markers - optional - used by installation scripts and
# munin-node-configure:
#%# family=contrib
#%# capabilities=autoconf
use strict;
use Socket;
my $NTPQ = $ENV{ntpq} || "ntpq";
my $COMMAND = "$NTPQ -np";
my $statedir = $ENV{statedir} || '/var/lib/munin/plugin-state';
my $statefile = "$statedir/ntp_peers.state";
# autoconf
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
`$NTPQ -c help >/dev/null 2>/dev/null`;
if ($? eq "0") {
if (`$NTPQ -np | wc -l` > 0) {
print "yes\n";
exit 0;
} else {
print "no (unable to list peers)\n";
exit 1;
}
} else {
print "no (ntpq not found)\n";
exit 1;
}
}
my %peers;
# retrieve cached list of IPs and hostnames
if (-f "$statefile") {
open (IN, "$statefile") or exit 4;
while (<IN>) {
if (/^([0-9\.]+):(.*)$/) {
$peers{$1}{'name'} = $2;
}
}
close IN;
}
# do custom IP lookups
for my $key (map {/^hostname_(.+)/} keys %ENV) {
my $ip = &desanitize_field($key);
$peers{$ip}{'name'} = $ENV{"hostname_$key"}
}
# get data from ntpq
open(SERVICE, "$COMMAND |")
or die("Could not execute '$COMMAND': $!");
while (<SERVICE>) {
if (/^[-+*#](\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})(\s+\S+){7}\s+(\S+)/) {
my $name = &lookupname($1);
$peers{$1}{'value'} = $3;
}
}
close(SERVICE);
# config
if ($ARGV[0] and $ARGV[0] eq 'config') {
print "graph_title NTP peer offsets\n";
print "graph_args --base 1000 --vertical-label seconds --lower-limit 0\n";
# print "graph_vlabel ms\n";
print "graph_category time\n";
print "graph_info Offset (in ms) to the server's NTP peers\n";
print "graph_order ";
foreach my $key (sort by_name keys %peers) {
print &sanitize_field($peers{$key}{'name'}) . " ";
}
print "\n";
foreach my $peer (keys %peers) {
print &sanitize_field($peers{$peer}{'name'}) . ".label " . $peers{$peer}{'name'} . "\n";
print &sanitize_field($peers{$peer}{'name'}) . ".draw " . "LINE" . "\n";
print &sanitize_field($peers{$peer}{'name'}) . ".cdef " . &sanitize_field($peers{$peer}{'name'}) . ",1000,/" . "\n";
}
exit 0;
}
# send output
foreach my $peer (keys %peers) {
print &sanitize_field($peers{$peer}{'name'}) . ".value " . &getpeeroffset($peer) . "\n";
}
# save list of peer IPs and hostnames
if(-l $statefile) {
die("$statefile is a symbolic link, refusing to touch it.");
}
open (OUT, ">$statefile") or exit 4;
foreach my $i (keys %peers) {
print OUT "$i:" . $peers{$i}{'name'} . "\n";
}
close OUT;
# sorts by hostname
sub by_name {
return $peers{$a}{'name'} cmp $peers{$b}{'name'};
}
# create a valid munin field name from the hostname
sub sanitize_field () {
my $field = shift;
# replace illegal characters with an underscore
$field =~ s/[^A-Za-z0-9_]/_/g;
# prepend an underscore if name starts with a number
$field =~ s/^([^A-Za-z_])/_$1/;
# truncate to 19 characters
if (length($field) > 19) {
$field = substr($field, 0, 19);
}
return $field
}
# get an IP address from the underscore escaped
# value of env.hostname_<key>
sub desanitize_field () {
my $field = shift;
$field =~ s/_/\./g;
return $field
}
# lookup hostnames
sub lookupname () {
my $ip = shift;
# have we already got it?
if ($peers{$ip}{'name'}) {
return $peers{$ip}{'name'};
}
# else look it up
my $iaddr = inet_aton($ip);
my $name = gethostbyaddr($iaddr, AF_INET) || $ip;
# add to cache
$peers{$ip}{'name'} = $name;
return $name;
}
# returns the offset, or U if it is undefined
sub getpeeroffset() {
my $ip = shift;
my $rtn = 'U';
if (exists($peers{$ip}{'value'})) {
$rtn = $peers{$ip}{'value'};
}
return $rtn
}
=pod
=head1 Description
ntp_peers - A munin plugin to monitor offsets to multiple NTP peers and
graph them on a single graph
=head1 Parameters understood:
config (required)
autoconf (optional - used by munin-node-configure)
=head1 Configuration variables:
All configuration parameters are optional
ntpq - path to ntpq program
statedir - directory in which to place state file
hostname_<key> - override hostname for peer <key>. <key> is
an IPv4 address with dots replaced by underscores.
Useful for reference clocks, eg
env.hostname_127_127_43_0 .GPS.
=head1 Known issues
ntp_peers will not monitor IPv6 peers
=cut