Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / other / uustat @ 31412baa

Historique | Voir | Annoter | Télécharger (2,91 ko)

1
#! /usr/bin/perl
2
# -*-  perl -*-
3
#
4
# $Id: uustat,v 1.2 2010-05-12 11:05:00 joey Exp $
5
#
6
# Plugin to UUCP traffic.
7
#
8
# Parameters understood:
9
#
10
#       config   (required)
11
#       autoconf (optional - used by munin-config)
12
#
13
# Environment
14
#       exclude: space separated list hosts to exclude.
15
#       category: category of this plugin, default 'postfix'
16
#       host.warning: Warning packages threshold, default none.
17
#       host.critical: Critical packages threshold, default none.
18
#
19
# Magic markers (optional - used by munin-config and installation scripts):
20
#
21
#  Copyright (C) 2010 Joey Schulze <joey@infodrom.org>
22
#
23
#  This program is free software; you can redistribute it and/or modify
24
#  it under the terms of the GNU General Public License as published by
25
#  the Free Software Foundation; version 2 dated June, 1991.
26
#
27
#  This program is distributed in the hope that it will be useful,
28
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
29
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
#  GNU General Public License for more details.
31
#
32
#  You should have received a copy of the GNU General Public License
33
#  along with this program;  if not, write to the Free Software
34
#  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
35
#
36
# Source: http://www.infodrom.org/Infodrom/tools/munin.html
37
#
38
#%# family=auto
39
#%# capabilities=autoconf
40

    
41
use strict;
42
use warnings;
43
use Munin::Plugin;
44

    
45
my $uustat = '/usr/bin/uustat';
46

    
47
my @exclude = split(/\s+/, $ENV{'exclude'} || '');
48

    
49
sub hosts
50
{
51
    my @hosts;
52
    my $cmd = $uustat . ' -m |';
53
    open my $up, $cmd or exit;
54
    while (<$up>) {
55
	push @hosts, (split / /)[0];
56
    }
57
    close $up;
58

    
59
    return @hosts;
60
}
61

    
62
sub count_jobs
63
{
64
    my $host = shift;
65
    my $cmd = $uustat . ' -s ' . $host . ' |';
66
    my $count = 0;
67
    open my $up, $cmd or exit;
68
    do $count++ while (<$up>);
69
    close $up;
70

    
71
    return $count;
72
}
73

    
74
sub host_excluded
75
{
76
    do {return 1 if $_ eq $_[0]} foreach @exclude;
77
    return 0;
78
}
79

    
80
if (@ARGV > 0 && $ARGV[0] eq 'autoconf') {
81
    if (-x $uustat) {
82
	print "yes\n";
83
	exit 0;
84
    } else {
85
        print "no\n";
86
        exit 1;
87
    }
88
}
89

    
90
if (@ARGV > 0 && $ARGV[0] eq 'config') {
91
    my $category = $ENV{'category'} || 'postfix';
92

    
93
    print "graph_title UUCP usage \n";
94
    print "graph_args -l 0\n";
95
    print "graph_vlabel packages\n";
96
    print "graph_scale no\n";
97
    printf "graph_category %s\n", $category;
98

    
99
    foreach my $host (hosts) {
100
	next if host_excluded $host;
101
	$host = clean_fieldname $host;
102
	my $warning = $ENV{$host.'.warning'} || undef;
103
	my $critical = $ENV{$host.'.critical'} || undef;
104

    
105
	printf "%s.label %s\n", $host, $host;
106
	printf "%s.warning %d\n", $host, $warning if defined $warning;
107
	printf "%s.critical %d\n", $host, $critical if defined $critical;
108
    }
109
    exit 0;
110
}
111

    
112
foreach my $host (hosts) {
113
    next if host_excluded $host;
114
    my $count = count_jobs $host;
115
    $host = clean_fieldname $host;
116

    
117
    printf "%s.value %d\n", $host, $count;
118
}