On regroupe les plugins munin dans un rpertoire commun toutes les machines

darcs-hash:20060420130121-72cb0-50f87f8f01382a2ddc9afec1b1b6e02890d8d32c.gz
This commit is contained in:
salles 2006-04-20 15:01:21 +02:00
parent 674ee00ed0
commit f672fa493b
23 changed files with 1451 additions and 0 deletions

54
munin/amavis Executable file
View file

@ -0,0 +1,54 @@
#!/bin/sh
#
# Plugin to monitor the amavis mail filter.
#
# Usage: Place in /etc/lrrd/client.d/ (or link it there using ln -s)
#
# Parameters understood:
#
# config (required)
# autoconf (optional)
#
# Config variables:
#
# amavislog - file where amavis logs are written
#
TEMP_FILE=/tmp/lrrd-amavis
AMAVIS_LOG=/var/log/mail/mail.info
OFFSET=/var/lib/munin/plugin-state/amavis.offset
LOGTAIL=`which logtail`
if [ "$amavislog" ]; then AMAVIS_LOG=$amavislog ; fi
if [ "$1" = "autoconf" ]; then
if [ -f ${AMAVIS_LOG} -a -x ${LOGTAIL} ] ; then
echo yes
exit 0
else
echo no
exit 1
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title Amavis filter statistics'
echo 'graph_order virus spam_maybe spam_sure total'
echo 'graph_vlabel nb'
echo 'virus.label virus'
echo 'spam_maybe.label probably spam'
echo 'spam_sure.label surely spam'
echo 'total.label total'
exit 0
fi
logtail -o ${OFFSET} -f ${AMAVIS_LOG} ${OFFSET} | grep 'amavis\[.*\]:' > ${TEMP_FILE}
total=`cat ${TEMP_FILE} | wc -l`
virus=`grep infected ${TEMP_FILE} | wc -l`
spamm=`grep 'Passed.*Hits: 1[0-9][.]' ${TEMP_FILE} | wc -l`
spams=`grep 'Passed.*Hits: [2-9][0-9][0-9]*[.]' ${TEMP_FILE} | wc -l`
echo "virus.value ${virus}"
echo "spam_maybe.value ${spamm}"
echo "spam_sure.value ${spams}"
echo "total.value ${total}"

117
munin/audimat.py Executable file
View file

@ -0,0 +1,117 @@
#! /usr/bin/env python
# -*- coding: iso-8859-15 -*-
"""
Système de monitoring des abonnés au différents flux multicast
Frédéric Pauget, Nicolas Salles, Etienne Chové
"""
import sys, os
sys.path.append('/usr/scripts/gestion')
from hptools import hpswitch
from annuaires import all_switchs, uplink_prises
####################################################################
## Définition des chaines à audimater
####################################################################
# On construit un dictionnaire au format "ip" : "nom_de_la_chaine"
# On log les chaines qui font des annonces sap
# on essaie de télécharger le fichier sap.txt
# si on y arrive pas on continue avec l'ancien
chaines = {}
try :
os.system("/usr/bin/wget http://television.crans.org/sap.txt -O /tmp/sap.txt -q 2> /dev/null")
except :
pass
# lecture du fichier
diffusion = open ('/tmp/sap.txt','r')
for l in diffusion.readlines() :
chaines[l.rstrip().split(":")[1]] = l.split(":")[0].replace('.','_').replace('-','_')[0:18]
####################################################################
## Configuration pour munin
####################################################################
if 'autoconf' in sys.argv :
print "yes" # Surement y rajouter le up du backbone, ...
sys.exit(0)
if 'config' in sys.argv :
print "host_name backbone"
print "graph_title AudimatTV";
print "graph_args --base 1000";
print "graph_vlabel nb clients/chaines";
inc = 0
chaines = chaines.values()
chaines.sort()
for nom in chaines :
if not nom : continue
nom1 = nom.replace(' ','_')
print "%s.label %s" % (nom1, nom)
if inc == 0 :
print "%s.draw AREA" % nom1
else:
print "%s.draw STACK" % nom1
inc = 1
print "total.label Total"
sys.exit(0)
####################################################################
## Mesure de l'audimat, lancé par cron à cause du timeout de munin
####################################################################
if 'generate' in sys.argv :
stats = {} # { IP : [ prises ] }
for switch in all_switchs() :
# on vérifie que le switch est pingable
if os.system('ping -c 3 %s > /dev/null 2> /dev/null' % switch ) :
continue
sw = hpswitch(switch)
switch=switch.split('.')[0]
if switch[-1].isalpha() :
bat = switch[-1].lower()
sw_num = 0
else :
bat = switch[-3].lower()
sw_num = int(switch[-1])
for ip, liste in sw.multicast().items() :
stats.setdefault(ip,[])
for port in liste :
num_port = 100 * sw_num + int(port)
if num_port not in uplink_prises[bat].keys() :
stats[ip].append('%s%03i' % (bat, num_port) )
total = 0
f = open('/tmp/audimat','w')
for ip, nom in chaines.items() :
if not nom : continue
nb_clients = len(stats.get(ip,[]))
total += nb_clients
if 'prises' in sys.argv :
f.write( "%s (%i) : %s\n" % (nom, nb_clients, ', '.join(stats.get(ip,[])).upper() ) )
else :
f.write( "%s.value %i\n" % ( nom.replace(' ','_'), nb_clients ) )
f.write("total.value %i" % total )
sys.exit(0)
####################################################################
## Retour des audimats pour munin
####################################################################
try :
print file("/tmp/audimat").read()
except :
pass

64
munin/batiments Executable file
View file

@ -0,0 +1,64 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
fichier = '/var/lib/munin/tmp/batiments'
import sys,os
try :
arg = sys.argv[1]
except :
arg = ''
if arg == "config" :
print 'host_name adherents'
print 'graph_title Adhérents par batiments'
print "graph_args --base 1000 --lower-limit 0"
print "graph_vlabel nb d'adhérents"
print 'bata.label Bâtiment A'
print 'bata.draw AREA'
print 'batb.label Bâtiment B'
print 'batb.draw STACK'
print 'batc.label Bâtiment C'
print 'batc.draw STACK'
print 'batg.label Bâtiment G'
print 'batg.draw STACK'
print 'bath.label Bâtiment H'
print 'bath.draw STACK'
print 'bati.label Bâtiment I'
print 'bati.draw STACK'
print 'batj.label Bâtiment J'
print 'batj.draw STACK'
print 'batm.label Bâtiment M'
print 'batm.draw STACK'
print 'batp.label PdJ'
print 'batp.draw STACK'
print 'wifi.label Wifi'
print 'wifi.draw STACK'
print 'total.label Total'
elif arg == "fichier" :
file = open(fichier,'w')
sys.path.append('/usr/scripts/gestion')
from ldap_crans import crans_ldap
db = crans_ldap()
def count(filtre) :
data = db.search(filtre)
return len(data['adherent']) + len(data['club'])
total = 0
for bat in 'abcghijmp' :
nb = count('paiement=ok&chbre=%s*' % bat)
total += nb
file.write("bat%s.value %d\n" % (bat, nb))
nb = count('paiement=ok&chbre=EXT')
total += nb
file.write("wifi.value %d\n" % nb)
file.write("total.value %d\n" % total)
file.close()
else :
os.system('cat %s' % fichier)

46
munin/blacklist Executable file
View file

@ -0,0 +1,46 @@
#!/bin/sh
if [ "$1" = "config" ]; then
echo 'host_name adherents'
echo 'graph_title Blacklist'
echo "graph_args --base 1000 --lower-limit 0"
echo "graph_vlabel nb de machines"
echo 'carte_et.label Certif. études'
echo 'carte_et.draw AREA'
echo 'chbre.label Chambre invalide'
echo 'chbre.draw STACK'
echo 'upload.label Upload'
echo 'upload.draw STACK'
echo 'p2p.label P2P'
echo 'p2p.draw STACK'
echo 'auto_upload.label Autodisc. Upload'
echo 'auto_upload.draw STACK'
echo 'auto_p2p.label Autodisc. P2P'
echo 'auto_p2p.draw STACK'
echo 'virus.label Virus'
echo 'virus.draw STACK'
echo 'warez.label Warez'
echo 'warez.draw STACK'
echo 'total.label Total'
exit 0
fi
echo -n "carte_et.value "
cat /etc/squid/blacklist_carte_et | wc -l
echo -n "chbre.value "
cat /etc/squid/blacklist_chbre | wc -l
echo -n "virus.value "
cat /etc/squid/blacklist_virus | wc -l
echo -n "upload.value "
cat /etc/squid/blacklist_upload | wc -l
echo -n "p2p.value "
cat /etc/squid/blacklist_p2p | wc -l
echo -n "auto_upload.value "
cat /etc/squid/blacklist_autodisc_upload | wc -l
echo -n "auto_p2p.value "
cat /etc/squid/blacklist_autodisc_p2p | wc -l
echo -n "warez.value "
cat /etc/squid/blacklist_warez | wc -l
echo -n "total.value "
cat /etc/squid/blacklist_* | wc -l

59
munin/hddtemp Executable file
View file

@ -0,0 +1,59 @@
#!/bin/sh
#
# Plugin to monitor harddrive temperatures through SMART.
#
# client-conf.d/-options:
#
# drives -- List drives to monitor. E.g. "hda hdc".
#
# $Log: hddtemp,v $
# Revision 1.1 2006-04-20 13:01:20 salles
# On regroupe les plugins munin dans un répertoire commun à toutes les machines
#
# Revision 1.1 2004/10/08 14:59:48 salles
# Ajout des scripts persos pour les graphes munins.
# Apparition d'un graphe pour compter les blacklistés.
#
# Revision 1.2 2004/01/29 19:39:00 jimmyo
# Generic plugins now use printf instead of echo -n, as this is more portable (SF#885564)
#
# Revision 1.1 2004/01/02 18:50:00 jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.2 2003/12/18 19:16:00 jimmyo
# Changes from Alexandre
#
# Revision 1.1 2003/12/18 19:04:37 jimmyo
# New plugin: Alexandre Dupouy contributed "hddtemp".
#
#
#%# family=contrib
HDDTEMP=/usr/sbin/hddtemp
drives="sda sdb sdc sdd"
if [ "$1" = "autoconf" ]; then
if [ -x "$HDDTEMP" ]; then
echo yes
exit 0
else
echo no
exit 1
fi
fi
if [ "$1" = "config" ]; then
echo 'graph_title HDD temperature'
echo 'graph_args --base 1000 -l 0'
echo 'graph_vlabel temp in °C'
for a in $drives ; do echo $a.label $a "`$HDDTEMP -q /dev/$a | cut -f 2 -d ':' | cut -d ' ' -f3`" ; done
exit 0
fi
for a in $drives ; do printf "$a.value " ; echo "`$HDDTEMP -q /dev/$a | cut -f 3 -d ':' | cut -d ' ' -f2`" | awk -F \° '{print $1}' ; done

44
munin/iptables_ Executable file
View file

@ -0,0 +1,44 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# Compteur des règles iptables
import sys,commands,string
# On prend l'argument pour définir la table à analyser
TABLE = sys.argv[0].split('_')[1]
if TABLE :
IPTABLES = "iptables -t %s -L " % TABLE
else :
IPTABLES = "iptables -L "
try :
arg = sys.argv[1]
except :
arg = ''
CHAINS = commands.getoutput('%s | grep Chain | awk \'{print $2}\'' % IPTABLES).split('\n')
if arg == "config" :
print 'graph_title Firewall %s' % string.lower(TABLE)
print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category network'
print "graph_vlabel nb de regles"
for chain in CHAINS :
nom = string.lower(chain.replace('_', '').replace('-', ''))
label = chain.replace('_', '-')
print "%s.label %s" % (nom, label)
if CHAINS.index(chain) == 0 :
print "%s.draw AREA" % nom
else :
print "%s.draw STACK" % nom
if label == "TEST-MAC-IP" :
print "%s.warning 100:" % nom
print "%s.critical 1:" % nom
else :
for chain in CHAINS :
nom = string.lower(chain.replace('_', '').replace('-', ''))
value = int(commands.getoutput('%s %s | wc -l' % (IPTABLES, chain))) - 2
print "%s.value %d" % (nom, value)

22
munin/machines Executable file
View file

@ -0,0 +1,22 @@
#!/bin/sh
if [ "$1" = "config" ]; then
# echo 'host_name adherents'
echo 'graph_title Machines connectées'
echo "graph_args --base 1000 --lower-limit 0"
echo "graph_vlabel nombre de machines"
echo 'fixe.label Fixe'
echo 'fixe.draw AREA'
echo 'adm.label ADM'
echo 'adm.draw STACK'
echo 'ens.label ENS'
echo 'ens.draw STACK'
echo 'total.label Total'
exit 0
fi
echo "fixe.value" `arp -a -i crans | wc -l`
echo "adm.value" `arp -a -i crans.2 | wc -l`
echo "ens.value" `arp -a -i ens | wc -l`
echo "total.value" `arp -a | wc -l`

16
munin/mge_batt Executable file
View file

@ -0,0 +1,16 @@
#!/bin/sh
#
# Plugin to monitor MGE battery state.
if [ "$1" = "config" ]; then
echo 'host_name pulsar.crans.org'
echo 'graph_category Batteries'
echo 'graph_title Etat batteries'
echo 'graph_vlabel charge (%)'
echo 'pcent.label Charge'
exit 0
fi
cmd="snmpget -O vq -v1 -c public pulsar.adm.crans.org SNMPv2-SMI::enterprises.705.1."
echo "pcent.value $(${cmd}5.4.0)"

14
munin/mge_hygro Executable file
View file

@ -0,0 +1,14 @@
#!/bin/sh
if [ "$1" = "config" ]; then
echo 'host_name pulsar.crans.org'
echo 'graph_category Environnement'
echo 'graph_title Hygrométrie 0B'
echo 'graph_vlabel Humitidé (%)'
echo 'hygro.label Humidité 0B'
exit 0
fi
cmd="snmpget -O vq -v1 -c public pulsar.adm.crans.org SNMPv2-SMI::enterprises.705.1."
echo "hygro.value $(${cmd}8.2.0)"

24
munin/mge_intensite Executable file
View file

@ -0,0 +1,24 @@
#!/bin/sh
#
# Plugin to monitor MGE battery state.
if [ "$1" = "config" ]; then
echo 'host_name pulsar.crans.org'
echo 'graph_category B4'
echo 'graph_args --lower-limit 0'
echo 'graph_title Intensité'
echo 'graph_vlabel I (A)'
echo 'input.label Entrée'
echo 'input.min 0'
echo 'output.label Sortie'
echo 'output.min 0'
exit 0
fi
cmd="snmpget -O vq -v1 -c public pulsar.adm.crans.org SNMPv2-SMI::enterprises.705.1."
input=$(${cmd}6.2.1.6.0)
output=$(${cmd}7.2.1.5.0)
echo "input.value $(($input/10)).$(($input%10))"
echo "output.value $(($output/10)).$(($output%10))"

17
munin/mge_temp Executable file
View file

@ -0,0 +1,17 @@
#!/bin/sh
if [ "$1" = "config" ]; then
echo 'host_name pulsar.crans.org'
echo 'graph_category Environnement'
echo 'graph_title Température 0B'
echo 'graph_vlabel Température en (°C)'
echo 'temp.label Température 0B'
echo 'temp.warning 22'
echo 'temp.critical 24'
exit 0
fi
cmd="snmpget -O vq -v1 -c public pulsar.adm.crans.org SNMPv2-SMI::enterprises.705.1."
t=$(${cmd}8.1.0)
echo "temp.value $(($t/10)).$(($t%10))"

21
munin/mge_temps Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh
#
# Plugin to monitor MGE battery state.
if [ "$1" = "config" ]; then
echo 'host_name pulsar.crans.org'
echo 'graph_category Batteries'
echo 'graph_title Autonomie'
echo 'graph_vlabel t (minutes)'
echo 'remain.label Autonomie restante'
echo 'charg.label Temps de recharge'
exit 0
fi
cmd="snmpget -O vq -v1 -c public pulsar.adm.crans.org SNMPv2-SMI::enterprises.705.1."
remain=$(${cmd}5.1.0) # autonomie restante
charg=$(${cmd}5.8.0) # temps avant charge complère des batteries
echo "remain.value $(($remain/60)).$(($remain%60*10/6))"
echo "charg.value $(($charg/60)).$(($charg%60*10/6))"

23
munin/mge_tension Executable file
View file

@ -0,0 +1,23 @@
#!/bin/sh
#
# Plugin to monitor MGE battery state.
if [ "$1" = "config" ]; then
echo 'host_name pulsar.crans.org'
echo 'graph_category B4'
echo 'graph_title Tensions'
echo 'graph_vlabel U (V)'
echo 'input.label Entrée'
echo 'input.min 0'
echo 'output.label Sortie'
echo 'output.min 0'
exit 0
fi
cmd="snmpget -O vq -v1 -c public pulsar.adm.crans.org SNMPv2-SMI::enterprises.705.1."
input=$(${cmd}6.2.1.2.0)
output=$(${cmd}7.2.1.2.0)
echo "input.value $(($input/10)).$(($input%10))"
echo "output.value $(($output/10)).$(($output%10))"

18
munin/ntp_server Executable file
View file

@ -0,0 +1,18 @@
#!/bin/sh
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
if [ "$1" = "config" ]; then
echo "graph_title NTP servers offset"
echo 'graph_args --base 1000 -l 0 '
echo 'graph_vlabel offset in µsec'
ntpq -p | grep -i '^[*+-]' | awk '{gsub("^.","",$1) ; gsub("[.-]", "_", $1); print $1 ".label " $1}'
exit 0
fi;
ntpq -p | grep -i '^[*+-]' | awk '{gsub("^.","",$1) ; gsub("[.-]", "_", $1); print $1 ".value " $9}'

55
munin/ping_ Executable file
View file

@ -0,0 +1,55 @@
#!/bin/sh
#
# Copyright (C) 2004 Jimmy Olsen
#
# 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; version 2 dated June,
# 1991.
#
# 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.
#
#
# Plugin to monitor ping times
#
# Parameters:
#
# ping_args - Arguments to ping (default "-c 2")
# ping_args2 - Arguments after the host name (required for Solaris)
# ping - Ping program to use
# host - Host to ping
#
# Arguments for Solaris:
# ping_args -s
# ping_args2 56 2
#
#%# family=manual
file_host=`basename $0 | sed 's/^ping_//g'`
host=${host:-${file_host:-www.google.com}}
if [ "$1" = "config" ]; then
echo host_name $host
echo graph_title Ping times from sila
echo 'graph_args --base 1000 -l 0'
echo 'graph_vlabel seconds'
echo 'graph_category network'
echo 'graph_info This graph shows ping RTT statistics.'
echo "ping.label $host"
echo "ping.info Ping RTT statistics for $host."
echo 'ping.draw LINE2'
echo 'packetloss.label packet loss'
echo 'packetloss.graph no'
exit 0
fi
${ping:-ping} ${ping_args:-'-c 2'} ${host} ${ping_args2} | perl -n -e 'print "ping.value ", $1 / 1000, "\n" if m@min/avg/max.*\s\d+(?:\.\d+)?/(\d+(?:\.\d+)?)/\d+(?:\.\d+)?@; print "packetloss.value $1\n" if /(\d+)% packet loss/;'

162
munin/snmp__if__ Executable file
View file

@ -0,0 +1,162 @@
#!/usr/bin/perl -w
#
# $Log: snmp__if__,v $
# Revision 1.1 2006-04-20 13:01:21 salles
# On regroupe les plugins munin dans un répertoire commun à toutes les machines
#
# Revision 1.1 2004/11/14 10:36:39 salles
# Ajout des plugins personnalisés
#
# Revision 1.2 2004/07/27 14:32:46 salles
# nom en premier pour qu'on les ait dans l'ordre alphabétique. mo²
#
# Revision 1.1 2004/07/27 12:17:28 bernat
# Et tournez manège !
#
# Revision 1.1 2004/07/27 11:37:16 bernat
# Deplacement (encore !)
#
# Revision 1.1 2004/07/27 11:27:43 bernat
# Deplacement (pour pas qu'il soit executé)
#
# Revision 1.1 2004/07/27 11:19:26 bernat
# SNMP un peu modifié pour avoir le nom des bats en "clair"
#
# Revision 1.4 2004/04/30 16:58:14 jimmyo
# Added max.
#
# Revision 1.3 2004/02/22 20:17:58 jimmyo
# Typo fix
#
# Revision 1.2 2004/02/18 21:54:56 jimmyo
# Did a bit of work on the snmp-thingie.
#
# Revision 1.1 2004/01/02 18:50:00 jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.1 2003/12/19 20:53:45 jimmyo
# Created by jo
#
#
use strict;
use Net::SNMP;
my $DEBUG = 1;
my $host = $ENV{host} || undef;
my $port = $ENV{port} || 161;
my $community = $ENV{community} || "public";
my $iface = $ENV{interface} || undef;
my $name = undef;
my $response;
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
{
print "number 1.3.6.1.2.1.2.1.0\n";
print "index 1.3.6.1.2.1.2.2.1.1.\n";
print "require 1.3.6.1.2.1.2.2.1.3. ^6\$\n"; # Type
print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n"; # Speed
exit 0;
}
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_if_([^_]+)_(.+)$/)
{
$host = $1;
$name = $2;
$iface = $3;
if ($host =~ /^([^:]+):(\d+)$/)
{
$host = $1;
$port = $2;
}
}
else
{
print "# Debug: $0 -- $1 -- $3\n" if $DEBUG;
die "# Error: couldn't understand what I'm supposed to monitor.";
}
my $ifEntryDescr = "1.3.6.1.2.1.2.2.1.2.$iface";
my $ifEntrySpeed = "1.3.6.1.2.1.2.2.1.5.$iface";
my $ifEntryStatus = "1.3.6.1.2.1.2.2.1.8.$iface";
my $ifEntryInOctets = "1.3.6.1.2.1.2.2.1.10.$iface";
my $ifEntryOutOctets = "1.3.6.1.2.1.2.2.1.16.$iface";
my ($session, $error) = Net::SNMP->session(
-hostname => $host,
-community => $community,
-port => $port
);
if (!defined ($session))
{
die "Croaking: $error";
}
if ($ARGV[0] and $ARGV[0] eq "config")
{
print "host_name $host\n";
# if (!defined ($response = $session->get_request($ifEntryDescr)))
# {
# die "Croaking: " . $session->error();
# }
# my $name = $response->{$ifEntryDescr};
my $warn = undef;
if (defined ($response = $session->get_request($ifEntrySpeed)))
{
$warn = $response->{$ifEntrySpeed}/8;
}
print "graph_title $name traffic\n";
print "graph_order recv send\n";
print "graph_args --base 1000\n";
print "graph_vlabel bps in (-) / out (+)\n";
print "recv.label recv\n";
print "recv.type COUNTER\n";
print "recv.graph no\n";
print "recv.cdef recv,8,*\n";
print "recv.max 2000000000\n";
print "recv.warn ", (-$warn), "\n" if defined $warn;
print "send.label bps\n";
print "send.type COUNTER\n";
print "send.negative recv\n";
print "send.cdef send,8,*\n";
print "send.max 2000000000\n";
print "send.warn $warn\n" if defined $warn;
exit 0;
}
my $status = 1;
if (defined ($response = $session->get_request($ifEntryStatus)))
{
$status = $response->{$ifEntryStatus};
}
if ($status == 2)
{
print "recv.value U\n";
print "send.value U\n";
exit 0;
}
if (defined ($response = $session->get_request($ifEntryInOctets)))
{
print "recv.value ", $response->{$ifEntryInOctets}, "\n";
}
else
{
print "recv.value U\n";
}
if (defined ($response = $session->get_request($ifEntryOutOctets)))
{
print "send.value ", $response->{$ifEntryOutOctets}, "\n";
}
else
{
print "send.value U\n";
}

219
munin/snmp__if_err_ Executable file
View file

@ -0,0 +1,219 @@
#!/usr/bin/perl -w
#
# Copyright (C) 2004 Jimmy Olsen, Dagfinn Ilmari Mannsaaker
#
# 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; version 2 dated June,
# 1991.
#
# 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.
#
#
# $Log: snmp__if_err_,v $
# Revision 1.1 2006-04-20 13:01:21 salles
# On regroupe les plugins munin dans un répertoire commun à toutes les machines
#
# Revision 1.16 2004/12/10 18:51:43 jimmyo
# linux/apt* has been forced to LANG=C, to get predictable output.
#
# Revision 1.15 2004/12/10 10:47:47 jimmyo
# Change name from ${scale} to ${graph_period}, to be more consistent.
#
# Revision 1.14 2004/12/09 22:12:55 jimmyo
# Added "graph_period" option, to make "graph_sums" usable.
#
# Revision 1.13 2004/11/21 00:16:56 jimmyo
# Changed a lot of plugins so they use DERIVE instead of COUNTER.
#
# Revision 1.12 2004/11/20 22:37:21 jimmyo
# Strip strange characters.
#
# Revision 1.11 2004/11/20 22:10:49 jimmyo
# Clean up output of plugin a bit.
#
# Revision 1.10 2004/11/20 22:06:22 jimmyo
# Clean up output of plugin a bit.
#
# Revision 1.9 2004/11/16 20:08:26 jimmyo
# License cleanups.
#
# Revision 1.8 2004/11/12 20:28:03 ilmari
# No debugging info by default
#
# Revision 1.7 2004/09/08 15:25:33 ilmari
# Use /usr/bin/perl in all perl shebang lines.
#
# Revision 1.6 2004/09/07 13:19:22 ilmari
# SNMP plugins now honour the "host" environment variable if they can't deduce the hostname from zsh.
#
# Revision 1.5 2004/09/05 12:00:18 jimmyo
# Set family and capabilities.
#
# Revision 1.4 2004/09/04 21:58:28 jimmyo
# Set category and info fields.
#
# Revision 1.3 2004/09/04 19:12:14 jimmyo
# Accept ppp interfaces as well as ethernet interfaces.
#
# Revision 1.2 2004/04/30 22:20:22 jimmyo
# It should now even work. :-)
#
# Revision 1.1 2004/04/30 16:59:45 jimmyo
# New SNMP plugin: if_err
#
# Revision 1.3 2004/02/22 20:17:58 jimmyo
# Typo fix
#
# Revision 1.2 2004/02/18 21:54:56 jimmyo
# Did a bit of work on the snmp-thingie.
#
# Revision 1.1 2004/01/02 18:50:00 jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.1 2003/12/19 20:53:45 jimmyo
# Created by jo
#
#
#%# family=snmpauto
#%# capabilities=snmpconf
use strict;
use Net::SNMP;
my $DEBUG = 0;
my $host = $ENV{host} || undef;
my $port = $ENV{port} || 161;
my $community = $ENV{community} || "public";
my $iface = $ENV{interface} || undef;
my $response;
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
{
print "number 1.3.6.1.2.1.2.1.0\n";
print "index 1.3.6.1.2.1.2.2.1.1.\n";
print "require 1.3.6.1.2.1.2.2.1.3. ^(6|23)\$\n"; # Type
print "require 1.3.6.1.2.1.2.2.1.5. [1-9]\n"; # Speed
exit 0;
}
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_if_err_(.+)$/)
{
$host = $1;
$iface = $2;
if ($host =~ /^([^:]+):(\d+)$/)
{
$host = $1;
$port = $2;
}
}
elsif (!defined($host))
{
print "# Debug: $0 -- $1 -- $2\n" if $DEBUG;
die "# Error: couldn't understand what I'm supposed to monitor.";
}
my $ifEntryDescr = "1.3.6.1.2.1.31.1.1.1.18.$iface";
my $ifEntrySpeed = "1.3.6.1.2.1.2.2.1.5.$iface";
my $ifEntryStatus = "1.3.6.1.2.1.2.2.1.8.$iface";
my $ifEntryInErrors = "1.3.6.1.2.1.2.2.1.14.$iface";
my $ifEntryOutErrors = "1.3.6.1.2.1.2.2.1.20.$iface";
my ($session, $error) = Net::SNMP->session(
-hostname => $host,
-community => $community,
-port => $port
);
if (!defined ($session))
{
die "Croaking: $error";
}
if ($ARGV[0] and $ARGV[0] eq "config")
{
print "host_name $host\n";
if (!defined ($response = $session->get_request($ifEntryDescr)))
{
die "Croaking: " . $session->error();
}
my $name = $response->{$ifEntryDescr};
# $name =~ s/[^\w\s]//g;
my $warn = undef;
if (defined ($response = $session->get_request($ifEntrySpeed)))
{
$warn = $response->{$ifEntrySpeed}/8;
}
if (length ($name) > 15)
{
print "graph_title Interface $iface errors\n";
}
else
{
print "graph_title Interface $name errors\n";
}
print "graph_order recv send\n";
print "graph_args --base 1000\n";
print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
print "graph_category network\n";
print "graph_info This graph shows errors for the \"$name\" network interface.\n";
print "send.info Bits unsuccessfully sent/received by this interface.\n";
print "recv.label recv\n";
print "recv.type DERIVE\n";
print "recv.graph no\n";
print "recv.cdef recv,8,*\n";
print "recv.max 2000000000\n";
print "recv.min 0\n";
print "recv.warn ", (-$warn), "\n" if defined $warn;
print "send.label bps\n";
print "send.type DERIVE\n";
print "send.negative recv\n";
print "send.cdef send,8,*\n";
print "send.max 2000000000\n";
print "send.min 0\n";
print "send.warn 10\n";
exit 0;
}
my $status = 1;
if (defined ($response = $session->get_request($ifEntryStatus)))
{
$status = $response->{$ifEntryStatus};
}
if ($status == 2)
{
print "recv.value U\n";
print "send.value U\n";
exit 0;
}
if (defined ($response = $session->get_request($ifEntryInErrors)))
{
print "recv.value ", $response->{$ifEntryInErrors}, "\n";
}
else
{
print "recv.value U\n";
}
if (defined ($response = $session->get_request($ifEntryOutErrors)))
{
print "send.value ", $response->{$ifEntryOutErrors}, "\n";
}
else
{
print "send.value U\n";
}

121
munin/snmp__load Executable file
View file

@ -0,0 +1,121 @@
#!/usr/bin/perl -w
#
# $Log: snmp__load,v $
# Revision 1.1 2006-04-20 13:01:21 salles
# On regroupe les plugins munin dans un répertoire commun à toutes les machines
#
# Revision 1.1 2004/11/14 10:36:39 salles
# Ajout des plugins personnalisés
#
# Revision 1.2 2004/08/03 14:46:38 bernat
# Rattache les graphes a l'hote qu'on interroge
#
# Revision 1.1 2004/08/03 14:45:26 bernat
# Import initial
# Commit oublié de momo
#
# Revision 1.1 2004/05/01 10:50:53 jimmyo
# New SNMP plugins users and load.
#
# Revision 1.1 2004/04/30 20:13:53 jimmyo
# New SNMP plugin for number of procs.
#
# Revision 1.1 2004/04/29 22:29:57 jimmyo
# New SNMP plugin for disk usage.
#
# Revision 1.3 2004/02/22 20:17:58 jimmyo
# Typo fix
#
# Revision 1.2 2004/02/18 21:54:56 jimmyo
# Did a bit of work on the snmp-thingie.
#
# Revision 1.1 2004/01/02 18:50:00 jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.1 2003/12/19 20:53:45 jimmyo
# Created by jo
#
#
use strict;
use Net::SNMP;
my $DEBUG = 0;
my $MAXLABEL = 20;
my $host = $ENV{host} || undef;
my $port = $ENV{port} || 161;
my $community = $ENV{community} || "public";
my $iface = $ENV{interface} || undef;
my $response;
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
{
print "require 1.3.6.1.4.1.2021.10.1.3.2 [0-9]\n"; # Number
exit 0;
}
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_load$/)
{
$host = $1;
if ($host =~ /^([^:]+):(\d+)$/)
{
$host = $1;
$port = $2;
}
}
else
{
print "# Debug: $0 -- $1\n" if $DEBUG;
die "# Error: couldn't understand what I'm supposed to monitor.";
}
my ($session, $error) = Net::SNMP->session(
-hostname => $host,
-community => $community,
-port => $port
);
if (!defined ($session))
{
die "Croaking: $error";
}
if (defined $ARGV[0] and $ARGV[0] eq "config")
{
print "host_name $host\n";
print "graph_title Load average
graph_args --base 1000 -l 0
graph_vlabel load
load.label load
load.draw LINE2
";
exit 0;
}
print "load.value ", &get_single ($session, "1.3.6.1.4.1.2021.10.1.3.2"), "\n";
sub get_single
{
my $handle = shift;
my $oid = shift;
print "# Getting single $oid...\n" if $DEBUG;
$response = $handle->get_request ($oid);
if (!defined $response->{$oid})
{
return undef;
}
else
{
return $response->{$oid};
}
}

118
munin/snmp__processes Executable file
View file

@ -0,0 +1,118 @@
#!/usr/bin/perl -w
#
# $Log: snmp__processes,v $
# Revision 1.1 2006-04-20 13:01:21 salles
# On regroupe les plugins munin dans un répertoire commun à toutes les machines
#
# Revision 1.1 2004/11/14 10:36:39 salles
# Ajout des plugins personnalisés
#
# Revision 1.2 2004/08/03 14:46:38 bernat
# Rattache les graphes a l'hote qu'on interroge
#
# Revision 1.1 2004/08/03 14:45:26 bernat
# Import initial
# Commit oublié de momo
#
# Revision 1.1 2004/04/30 20:13:53 jimmyo
# New SNMP plugin for number of procs.
#
# Revision 1.1 2004/04/29 22:29:57 jimmyo
# New SNMP plugin for disk usage.
#
# Revision 1.3 2004/02/22 20:17:58 jimmyo
# Typo fix
#
# Revision 1.2 2004/02/18 21:54:56 jimmyo
# Did a bit of work on the snmp-thingie.
#
# Revision 1.1 2004/01/02 18:50:00 jimmyo
# Renamed occurrances of lrrd -> munin
#
# Revision 1.1.1.1 2004/01/02 15:18:07 jimmyo
# Import of LRRD CVS tree after renaming to Munin
#
# Revision 1.1 2003/12/19 20:53:45 jimmyo
# Created by jo
#
#
use strict;
use Net::SNMP;
my $DEBUG = 0;
my $MAXLABEL = 20;
my $host = $ENV{host} || undef;
my $port = $ENV{port} || 161;
my $community = $ENV{community} || "public";
my $iface = $ENV{interface} || undef;
my $response;
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf")
{
print "require 1.3.6.1.2.1.25.1.6.0 [0-9]\n"; # Number
exit 0;
}
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_processes$/)
{
$host = $1;
if ($host =~ /^([^:]+):(\d+)$/)
{
$host = $1;
$port = $2;
}
}
else
{
print "# Debug: $0 -- $1\n" if $DEBUG;
die "# Error: couldn't understand what I'm supposed to monitor.";
}
my ($session, $error) = Net::SNMP->session(
-hostname => $host,
-community => $community,
-port => $port
);
if (!defined ($session))
{
die "Croaking: $error";
}
if (defined $ARGV[0] and $ARGV[0] eq "config")
{
print "host_name $host\n";
print "graph_title Number of Processes
graph_args --base 1000 -l 0
graph_vlabel number of processes
processes.label processes
processes.draw LINE2
";
exit 0;
}
print "processes.value ", &get_single ($session, "1.3.6.1.2.1.25.1.6.0"), "\n";
sub get_single
{
my $handle = shift;
my $oid = shift;
print "# Getting single $oid...\n" if $DEBUG;
$response = $handle->get_request ($oid);
if (!defined $response->{$oid})
{
return undef;
}
else
{
return $response->{$oid};
}
}

132
munin/stats-batiment_ Executable file
View file

@ -0,0 +1,132 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# Gestion des prises dans les batiments
# Pour le moment on ne compte pas les prises CRANS
import sys,os,string
sys.path.append('/usr/scripts/gestion')
from annuaires import reverse, chbre_prises, bat_switchs, all_switchs, uplink_prises
from hptools import hpswitch
from ldap_crans import crans_ldap
# Le fichier de nombre d'adhérent par batiments
stats_batiments = "/var/lib/munin/tmp/batiments"
BAT = sys.argv[0].split('_')[1]
# Pour les batiments non manageables on indique le nb de prises
BAT_CHBRES = {'g' : 312}
def switch_prise(bat, prise) :
''' Renvoie le switch et la prise associé au numéro de la prise '''
switch = "bat%s-%i" % (bat, prise/100)
prise = prise % 100
return (switch, prise)
multiprise = map(lambda x : len(x[1])>1 and x[0], reverse(BAT).items())
while False in multiprise :
multiprise.remove(False)
try :
arg = sys.argv[1]
except :
arg = ''
if arg == "config" :
print 'host_name adherents'
print 'graph_title Batiment %s' % string.upper(BAT)
print 'graph_args --base 1000 --lower-limit 0'
# print 'graph_order activ enabled fixes reste prises chbres'
print "graph_vlabel nb de chambres"
print 'enabled.label Prises activées'
print 'enabled.draw AREA'
print 'fixes.label Prises fixes'
print 'fixes.draw STACK'
print 'reste.label Prises inutilisées'
print 'reste.draw STACK'
print 'crans.label Prises crans'
print 'crans.draw STACK'
print 'activ.label Prises actives'
print 'adherent.label Nb adhérents'
print 'prises.label Nb de prises'
print 'chbres.label Nb de chambres'
if BAT in BAT_CHBRES :
print 'connues.label Nb de chbres enreg.'
# print 'reste.warning 5:'
# print 'reste.critical 0:'
else :
PRISES_ENABLE = 0
for switch in all_switchs(BAT) :
try:
PRISES_ENABLE += hpswitch(switch).is_enable('all')
except:
PRISES_ENABLE += 0
# On élimine les prises "CRANS" stockés dans uplink_prises
for prise in uplink_prises[BAT].keys() :
switch, prise = switch_prise(BAT, prise)
try:
if hpswitch(switch).is_enable(prise) :
PRISES_ENABLE -= 1
except:
PRISES_ENABLE -= 0
print "enabled.value %d" % PRISES_ENABLE
PRISES_ACTIVES = 0
for switch in all_switchs(BAT) :
try:
PRISES_ACTIVES += hpswitch(switch).is_up('all')
except:
PRISES_ACTIVES += 0
# On élimine les prises "CRANS" stockés dans uplink_prises
for prise in uplink_prises[BAT].keys() :
switch, prise = switch_prise(BAT, prise)
try:
if hpswitch(switch).is_up(prise) :
PRISES_ACTIVES -= 1
except:
PRISES_ACTIVES -= 0
if multiprise != [] :
PRISES_ACTIVES -= len(multiprise)
for prise in multiprise :
PRISES_ACTIVES += len(reverse(BAT)[prise])
print "activ.value %d" % PRISES_ACTIVES
PRISES_FIXES = 0
if multiprise != [] :
PRISES_FIXES = - len(multiprise)
for prise in multiprise :
PRISES_FIXES += len(reverse(BAT)[prise])
print "fixes.value %d" % PRISES_FIXES
PRISES_CRANS = len(uplink_prises[BAT].keys())
print "crans.value %d" % PRISES_CRANS
NB_PRISES = 0
for switch in all_switchs(BAT) :
try:
NB_PRISES += hpswitch(switch).nb_prises()
except:
NB_PRISES += 0
NB_PRISES += PRISES_FIXES
print "prises.value %d" % NB_PRISES
print "reste.value %d" % int(NB_PRISES - PRISES_ENABLE - PRISES_FIXES - PRISES_CRANS)
fichier = open(stats_batiments, 'r')
#NB_ADHERENT = 0 # Plus génant qu'autre chose
for line in fichier.readlines():
if line[3:4] == BAT and line[:3] == "bat" :
NB_ADHERENT = line[11:].strip()
print "adherent.value %s" % NB_ADHERENT
if BAT in BAT_CHBRES.keys() :
print "chbres.value %d" % BAT_CHBRES[BAT]
print "connues.value %d" % len(chbre_prises[BAT].keys())
else :
print "chbres.value %d" % len(chbre_prises[BAT].keys())

41
munin/stats-ip Executable file
View file

@ -0,0 +1,41 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# Plugin pour visualiser l'utilisation des plages ip
import sys
sys.path.append('/usr/scripts/gestion')
from ldap_crans import crans_ldap
from config import NETs
from iptools import AddrInNet
ips = [ x.ip() for x in crans_ldap().search('ip=*')['machine'] ]
try :
arg = sys.argv[1]
except :
arg = ''
if arg == "config" :
print 'host_name adresses-ip'
print 'graph_title Statistiques adresses IP'
print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category network'
print "graph_vlabel % d'utilisation"
for subnet in NETs.keys():
nom = subnet.replace('-', '')
print "%s.label %s" % (nom, subnet)
print "%s.warning 92" % nom
print "%s.critical 98" % nom
else :
for subnet in NETs :
total = 0
for net in NETs[subnet]:
total += 2 ** ( 32 - int( net.split('/')[1] ) )
utilisees = len( [ ip for ip in ips if AddrInNet( ip, NETs[subnet] ) ] )
pourcentage = int((utilisees*100)/total)
nom = subnet.replace('-', '')
print "%s.value %d" % (nom, pourcentage)

43
munin/stats-ip_ Executable file
View file

@ -0,0 +1,43 @@
#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# Plugin pour visualiser l'utilisation des plages ip
import sys, string
sys.path.append('/usr/scripts/gestion')
from ldap_crans import crans_ldap
from config import NETs
from iptools import AddrInNet
ips = [ x.ip() for x in crans_ldap().search('ip=*')['machine'] ]
# On prend l'argument pour définir la plage d'ip à analyser
SUBNET = sys.argv[0].split('_')[1]
try :
arg = sys.argv[1]
except :
arg = ''
if arg == "config" :
if len(SUBNET) == 1 : NOM = "Bâtiment %s" % string.upper(SUBNET)
else: NOM = SUBNET
print 'host_name adresses-ip'
print 'graph_title Statistiques adresses IP - %s' % NOM
print 'graph_args --base 1000 --lower-limit 0'
print 'graph_category network'
print "graph_vlabel nb d'ips"
print "utilisees.label IP utilisées"
print "utilisees.draw AREA"
print "total.label Total disponibles"
else :
total = 0
for net in NETs[SUBNET]:
total += 2 ** ( 32 - int( net.split('/')[1] ) )
utilisees = len( [ ip for ip in ips if AddrInNet( ip, NETs[SUBNET] ) ] )
print "utilisees.value %d" % utilisees
print "total.value %s" % total

21
munin/uptime Executable file
View file

@ -0,0 +1,21 @@
#!/bin/sh
#
# Edité par mo² le 26 juillet 2004
#
if [ "$1" = "autoconf" ]; then
echo yes
exit 0
fi
if [ "$1" = "config" ]; then
echo 'graph_title Uptime'
echo 'graph_args --base 1000 -l 0 '
echo 'graph_vlabel uptime in days'
echo 'uptime.label uptime'
echo 'uptime.draw AREA'
exit 0
fi
cat /proc/uptime | env LC_ALL=C awk '{printf "uptime.value %.2f\n",$1/86400}'