]>
jfr.im git - munin-plugins.git/blob - asterisk_sippeers
6 asterix_sippeers - Plugin to monitor number of sip peers registered
10 The following configuration parameters are used by this plugin
13 env.host - hostname to connect to
14 env.port - port number to connect to
15 env.username - username used for authentication
16 env.secret - secret used for authentication
18 The "username" and "secret" parameters are mandatory, and have no
21 =head2 DEFAULT CONFIGURATION
29 Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
37 This program is free software; you can redistribute it and/or modify
38 it under the terms of the GNU General Public License as published by
39 the Free Software Foundation; version 2 dated June, 1991.
41 This program is distributed in the hope that it will be useful, but
42 WITHOUT ANY WARRANTY; without even the implied warranty of
43 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
44 General Public License for more details.
46 You should have received a copy of the GNU General Public License along
47 with this program; if not, write to the Free Software Foundation, Inc.,
48 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
50 If you improve this script please send your version to my email
51 address with the copyright notice upgrade with your name.
61 # #################################################################################
62 # Following example from current asterisk 1.4
64 #Name/username Host Dyn Nat ACL Port Status
65 #104-RANDALLBUILT/104-RAND 74.218.176.166 D 5060 Unmonitored
67 #102-ROCKSOLID/102-ROCKSOL (Unspecified) D 0 Unmonitored
68 #101-ROCKSOLID/101-ROCKSOL (Unspecified) D N 0 UNKNOWN
69 #20 sip peers [Monitored: 0 online, 1 offline Unmonitored: 2 online, 17 offline]
70 # #################################################################################
75 if ($ARGV[0] and $ARGV[0] eq "config")
77 print "graph_title Asterisk sip peers\n";
78 print "graph_args --base 1000 -l 0\n";
79 print "graph_order mon moff umon umoff\n";
80 print "graph_vlabel peers\n";
81 print "graph_category asterisk\n";
82 #print "peers.label total\n";
83 print "mon.draw AREA\n";
84 print "mon.label monitored online\n";
85 print "moff.draw STACK\n";
86 print "moff.label monitored offline\n";
87 print "umon.draw STACK\n";
88 print "umon.label unmonitored online\n";
89 print "umoff.draw STACK\n";
90 print "umoff.label unmonitored offline\n";
94 #graph_info The ... describes ....
95 #load.info Average load for the five minutes.
99 my $host = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
100 my $port = exists $ENV{'port'} ? $ENV{'port'} : "5038";
102 my $username = $ENV{'username'};
103 my $secret = $ENV{'secret'};
105 my $pop = new IO
::Socket
::INET
(PeerAddr
=> $host,
108 die "Could not create socket: $!\n" unless $pop;
110 ## Read connection message.
111 my $line = $pop->getline;
112 die $line unless $line =~ /^Asterisk/;
115 $pop->print("Action: login\n");
116 $pop->print("Username: $username\n");
117 $pop->print("Secret: $secret\n");
118 $pop->print("Events: off\n");
121 while ($line = $pop->getline)
123 last if $line eq "\r\n";
126 #Message: Authentication accepted
128 ## Request status of messages.
129 $pop->print("Action: command\n");
130 $pop->print("Command: sip show peers\n");
133 my ($peers,$monitor_online,$monitor_offline,$unmonitor_online,$unmonitor_offline)=(0,0,0,0,0);
135 while (($line = $pop->getline) and ($line ne "\r\n"))
137 $line =~ s/^Output: //;
138 my @fields = split(' ', $line);
140 #20 sip peers [Monitored: 0 online, 1 offline Unmonitored: 2 online, 17 offline]
141 if (($count > 10) and ($fields[1] eq 'sip' and $fields[2] eq 'peers')) {
143 $monitor_online = $fields[4];
144 $monitor_offline = $fields[6];
145 $unmonitor_online = $fields[9];
146 $unmonitor_offline = $fields[11];
147 #print STDERR "$peers $monitor_online $monitor_offline $unmonitor_online $unmonitor_offline\n";
152 $pop->print("Action: logoff\n");
155 ## Exhaust buffer before closing (to avoid polluting Asterisk's logs)
156 while ($line = $pop->getline) {}
158 #print "peers.value $peers\n";
159 print "mon.value $monitor_online\n";
160 print "moff.value $monitor_offline\n";
161 print "umon.value $unmonitor_online\n";
162 print "umoff.value $unmonitor_offline\n";