Projet

Général

Profil

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

root / plugins / mpd / mpdstats_ @ e15ed8cb

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

1 238aaf5d ToM
#!/bin/sh
2
3
# vim: set ft=sh :
4
# -*- sh -*-
5
6
: << =cut
7
8
=head1 NAME
9
10
mpdstats_ - Munin plugin to monitor a MPD database
11
12
=head1 DEPENDENCIES
13
14
This plugin uses netcat(1) to communicate with the MPD daemon.
15
16
Tip: To see if it is already set up correctly, just run this plugin
17
with the parameter "autoconf". If you get a "yes", everything should
18
work like a charm already.
19
20
=head1 INSTALLATION
21
22
This wildcard plugin should be symlinked using one of these names:
23
mpdstats_artists, mpdstats_albums, mpdstats_songs
24
25
=head1 CONFIGURATION
26
27
No configuration should be required if run on the same server as
28
MPD. If the plugin is run from remote or in a non-default configuration,
29
please use the environment variables 'mpd_host' and 'mpd_port' to connect.
30
31
Also, if your netcat(1) binary is anywhere else than /bin/nc please define
32
it using the 'netcat' environment variable.
33
34
=head2 CONFIGURATION EXAMPLE
35
36
 [mpd_*]
37
  env.mpd_host 192.168.0.43
38
  env.mpd_port 6606
39
  env.netcat /usr/local/bin/nc
40
41
=head1 AUTHOR
42
43
Copyright (C) 2012 ToM <tom@leloop.org>
44
45
=head1 LICENSE
46
47
This program is free software; you can redistribute it and/or
48
modify it under the terms of the GNU General Public License
49
as published by the Free Software Foundation; version 2 dated June,
50
1991.
51
52
This program is distributed in the hope that it will be useful,
53
but WITHOUT ANY WARRANTY; without even the implied warranty of
54
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
55
GNU General Public License for more details.
56
57
You should have received a copy of the GNU General Public License
58
along with this program; if not, write to the Free Software
59
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
60
61
=head1 MAGIC MARKERS
62
63
 #%# family=auto
64
 #%# capabilities=autoconf suggest
65
66
=cut
67
68
69
70
MPDHOST=${mpd_host:-localhost}
71
MPDPORT=${mpd_port:-6600}
72
NCBIN=${netcat:-/bin/nc}
73
74
#
75
# FUNCTIONS
76
#
77
78
do_autoconf () {
79
    case "$ACTION" in
80
        albums|artists|songs)
81
            ;;
82
        *)
83
            echo "no (not a valid symlink name, please read the plugin doc)"
84
            exit 1
85
            ;;
86
    esac
87
88
    if [ ! -x $NCBIN ] ; then
89
        echo "no ($NCBIN: not found or not executable)"
90
        exit 1
91
    fi
92
93
    echo version | $NCBIN -q 2 $MPDHOST $MPDPORT 1>/dev/null 2>&1
94
    if [ "$?" != 0 ] ; then
95
        echo "no (connection failed)"
96
        exit 1
97
    fi
98
99
    echo "yes"
100
    exit 0
101
}
102
103
#
104
# MAIN
105
#
106
107
SCRIPTNAME=${0##*/}
108
ACTION=${SCRIPTNAME##*_}
109
110
case "$1" in
111
    autoconf)
112
        do_autoconf
113
        ;;
114
    suggest)
115
        echo "$ACTION"
116
        exit 0
117
        ;;
118
    config)
119
        echo "graph_category MPD
120
graph_title $ACTION in the database
121
graph_info Number of $ACTION in the database.
122
graph_vlabel $ACTION in the db
123
graph_args --base 1000 -l 0
124
graph_scale no
125
$ACTION.type GAUGE
126
$ACTION.draw LINE2
127
$ACTION.label $ACTION"
128
        exit 0
129
        ;;
130
    *)
131
        printf "$ACTION.value "
132
        echo stats | $NCBIN -q 2 $MPDHOST $MPDPORT | awk " /^${ACTION}/ {print \$2}"
133
        ;;
134
esac