Révision 0fbb34b2
Ported by Cerien to 1.6
| plugins/other/asterisk_sippeers | ||
|---|---|---|
| 1 |
#!/usr/bin/perl -w |
|
| 2 |
# |
|
| 3 |
# Copyright (C) 2009 Paul McCormack <paul@paulmccormack.com> |
|
| 4 |
# |
|
| 5 |
# This program is free software; you can redistribute it and/or |
|
| 6 |
# modify it under the terms of the GNU General Public License |
|
| 7 |
# as published by the Free Software Foundation; version 2 dated June, |
|
| 8 |
# 1991. |
|
| 9 |
# |
|
| 10 |
# This program is distributed in the hope that it will be useful, |
|
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 13 |
# GNU General Public License for more details. |
|
| 14 |
# |
|
| 15 |
# You should have received a copy of the GNU General Public License |
|
| 16 |
# along with this program; if not, write to the Free Software |
|
| 17 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
| 18 |
# |
|
| 19 |
# If you improve this script please send your version to my email address |
|
| 20 |
# with the copyright notice upgrade with your name. |
|
| 21 |
# |
|
| 22 |
# Plugin to monitor number of sip peers registered |
|
| 23 |
# |
|
| 24 |
# |
|
| 25 |
#%# family=asterisk |
|
| 26 |
|
|
| 27 |
use strict; |
|
| 28 |
|
|
| 29 |
if ($ARGV[0] and $ARGV[0] eq "autoconf") |
|
| 30 |
{
|
|
| 31 |
print "yes\n"; |
|
| 32 |
exit 0; |
|
| 33 |
} |
|
| 34 |
|
|
| 35 |
if ($ARGV[0] and $ARGV[0] eq "config") |
|
| 36 |
{
|
|
| 37 |
print "graph_title Asterisk connected sip peers\n"; |
|
| 38 |
print "graph_args --base 1000 -l 0\n"; |
|
| 39 |
print "graph_vlabel peers\n"; |
|
| 40 |
print "graph_category asterisk\n"; |
|
| 41 |
print "peers_online.label peers online\n"; |
|
| 42 |
print "peers_offline.label peers offline\n"; |
|
| 43 |
print "unmon_online.label unmonitored online\n"; |
|
| 44 |
print "unmon_offline.label unmonitored offline\n"; |
|
| 45 |
print "peers_offline.warning 1\n"; |
|
| 46 |
print "peers_offline.critical 2\n"; |
|
| 47 |
exit 0; |
|
| 48 |
} |
|
| 49 |
|
|
| 50 |
open(LINE, 'asterisk -rx "sip show peers"|'); |
|
| 51 |
|
|
| 52 |
my ($online)=(0,0); |
|
| 53 |
my ($offline)=(0,0); |
|
| 54 |
my ($unmon_online)=(0,0); |
|
| 55 |
my ($unmon_offline)=(0,0); |
|
| 56 |
|
|
| 57 |
while (<LINE>) |
|
| 58 |
{
|
|
| 59 |
$online = $1 if ($_ =~ /Monitored: (\d+) online/); |
|
| 60 |
$offline = $1 if ($_ =~ /Monitored: \d+ online, (\d+) offline/); |
|
| 61 |
$unmon_online = $1 if ($_ =~ /Unmonitored: (\d+) online/); |
|
| 62 |
$unmon_offline = $1 if ($_ =~ /Unmonitored: \d+ online, (\d+) offline/); |
|
| 63 |
} |
|
| 64 |
|
|
| 65 |
close(LINE); |
|
| 66 |
|
|
| 67 |
print "peers_online.value $online\n"; |
|
| 68 |
print "peers_offline.value $offline\n"; |
|
| 69 |
print "unmon_online.value $unmon_online\n"; |
|
| 70 |
print "unmon_offline.value $unmon_offline\n"; |
|
| 71 |
|
|
| 1 |
#!/usr/bin/perl -w |
|
| 2 |
# -*- perl -*- |
|
| 3 |
|
|
| 4 |
=head1 NAME |
|
| 5 |
|
|
| 6 |
asterix_sippeers - Plugin to monitor number of sip peers registered |
|
| 7 |
|
|
| 8 |
=head1 CONFIGURATION |
|
| 9 |
|
|
| 10 |
The following configuration parameters are used by this plugin |
|
| 11 |
|
|
| 12 |
[asterisk_sippeers] |
|
| 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 |
|
| 17 |
|
|
| 18 |
The "username" and "secret" parameters are mandatory, and have no |
|
| 19 |
defaults. |
|
| 20 |
|
|
| 21 |
=head2 DEFAULT CONFIGURATION |
|
| 22 |
|
|
| 23 |
[asterisk_sippeers] |
|
| 24 |
env.host 127.0.0.1 |
|
| 25 |
env.port 5038 |
|
| 26 |
|
|
| 27 |
=head1 AUTHOR |
|
| 28 |
|
|
| 29 |
Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> |
|
| 30 |
|
|
| 31 |
Ported to Asterisk 1.6 by cerien.jean@gmail.com |
|
| 32 |
|
|
| 33 |
=head1 LICENSE |
|
| 34 |
|
|
| 35 |
Gnu GPLv2 |
|
| 36 |
|
|
| 37 |
=begin comment |
|
| 38 |
|
|
| 39 |
This program is free software; you can redistribute it and/or modify |
|
| 40 |
it under the terms of the GNU General Public License as published by |
|
| 41 |
the Free Software Foundation; version 2 dated June, 1991. |
|
| 42 |
|
|
| 43 |
This program is distributed in the hope that it will be useful, but |
|
| 44 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 45 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 46 |
General Public License for more details. |
|
| 47 |
|
|
| 48 |
You should have received a copy of the GNU General Public License |
|
| 49 |
along with this program; if not, write to the Free Software |
|
| 50 |
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
| 51 |
USA. |
|
| 52 |
|
|
| 53 |
If you improve this script please send your version to my email |
|
| 54 |
address with the copyright notice upgrade with your name. |
|
| 55 |
|
|
| 56 |
=end comment |
|
| 57 |
|
|
| 58 |
=head1 MAGIC MARKERS |
|
| 59 |
|
|
| 60 |
#%# family=contrib |
|
| 61 |
|
|
| 62 |
=cut |
|
| 63 |
|
|
| 64 |
# ################################################################################# |
|
| 65 |
# Following example from current asterisk 1.4 |
|
| 66 |
#> sip show peers |
|
| 67 |
#Name/username Host Dyn Nat ACL Port Status |
|
| 68 |
#104-RANDALLBUILT/104-RAND 74.218.176.166 D 5060 Unmonitored |
|
| 69 |
#... |
|
| 70 |
#102-ROCKSOLID/102-ROCKSOL (Unspecified) D 0 Unmonitored |
|
| 71 |
#101-ROCKSOLID/101-ROCKSOL (Unspecified) D N 0 UNKNOWN |
|
| 72 |
#20 sip peers [Monitored: 0 online, 1 offline Unmonitored: 2 online, 17 offline] |
|
| 73 |
# ################################################################################# |
|
| 74 |
|
|
| 75 |
use strict; |
|
| 76 |
|
|
| 77 |
my $ret = undef; |
|
| 78 |
if (! eval "require Net::Telnet;") |
|
| 79 |
{
|
|
| 80 |
$ret = "Net::Telnet not found"; |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
if ($ARGV[0] and $ARGV[0] eq "config") |
|
| 84 |
{
|
|
| 85 |
print "graph_title Asterisk sip peers\n"; |
|
| 86 |
print "graph_args --base 1000 -l 0\n"; |
|
| 87 |
print "graph_order mon moff umon umoff\n"; |
|
| 88 |
print "graph_vlabel peers\n"; |
|
| 89 |
print "graph_category asterisk\n"; |
|
| 90 |
#print "peers.label total\n"; |
|
| 91 |
print "mon.draw AREA\n"; |
|
| 92 |
print "mon.label monitored online\n"; |
|
| 93 |
print "moff.draw STACK\n"; |
|
| 94 |
print "moff.label monitored offline\n"; |
|
| 95 |
print "umon.draw STACK\n"; |
|
| 96 |
print "umon.label unmonitored online\n"; |
|
| 97 |
print "umoff.draw STACK\n"; |
|
| 98 |
print "umoff.label unmonitored offline\n"; |
|
| 99 |
#graph_scale no |
|
| 100 |
#load.warning 10 |
|
| 101 |
#load.critical 120 |
|
| 102 |
#graph_info The ... describes .... |
|
| 103 |
#load.info Average load for the five minutes. |
|
| 104 |
exit 0; |
|
| 105 |
} |
|
| 106 |
|
|
| 107 |
my $host = exists $ENV{'host'} ? $ENV{'host'} : "127.0.0.1";
|
|
| 108 |
my $port = exists $ENV{'port'} ? $ENV{'port'} : "5038";
|
|
| 109 |
|
|
| 110 |
my $username = $ENV{'username'};
|
|
| 111 |
my $secret = $ENV{'secret'};
|
|
| 112 |
|
|
| 113 |
my $pop = new Net::Telnet (Telnetmode => 0); |
|
| 114 |
$pop->open(Host => $host, |
|
| 115 |
Port => $port); |
|
| 116 |
|
|
| 117 |
## Read connection message. |
|
| 118 |
my $line = $pop->getline; |
|
| 119 |
die $line unless $line =~ /^Asterisk/; |
|
| 120 |
|
|
| 121 |
## Send user name. |
|
| 122 |
$pop->print("Action: login");
|
|
| 123 |
$pop->print("Username: $username");
|
|
| 124 |
$pop->print("Secret: $secret");
|
|
| 125 |
$pop->print("Events: off");
|
|
| 126 |
$pop->print("");
|
|
| 127 |
|
|
| 128 |
#Response: Success |
|
| 129 |
#Message: Authentication accepted |
|
| 130 |
|
|
| 131 |
## Request status of messages. |
|
| 132 |
$pop->print("Action: command");
|
|
| 133 |
$pop->print("Command: sip show peers");
|
|
| 134 |
$pop->print("");
|
|
| 135 |
|
|
| 136 |
my ($peers,$monitor_online,$monitor_offline,$unmonitor_online,$unmonitor_offline)=(0,0,0,0,0); |
|
| 137 |
|
|
| 138 |
while (($line = $pop->getline) and ($line !~ /END COMMAND/o)) |
|
| 139 |
{
|
|
| 140 |
my @fields = split(' ', $line);
|
|
| 141 |
my $count = @fields; |
|
| 142 |
#20 sip peers [Monitored: 0 online, 1 offline Unmonitored: 2 online, 17 offline] |
|
| 143 |
if (($count > 10) and ($fields[1] eq 'sip' and $fields[2] eq 'peers')) {
|
|
| 144 |
$peers = $fields[0]; |
|
| 145 |
$monitor_online = $fields[4]; |
|
| 146 |
$monitor_offline = $fields[6]; |
|
| 147 |
$unmonitor_online = $fields[9]; |
|
| 148 |
$unmonitor_offline = $fields[11]; |
|
| 149 |
#print STDERR "$peers $monitor_online $monitor_offline $unmonitor_online $unmonitor_offline\n"; |
|
| 150 |
last; |
|
| 151 |
} |
|
| 152 |
} |
|
| 153 |
|
|
| 154 |
$pop->print("Action: logoff");
|
|
| 155 |
$pop->print("");
|
|
| 156 |
|
|
| 157 |
# purge the last lines to avoid error message on CLI |
|
| 158 |
while ($line = $pop->getline) |
|
| 159 |
{
|
|
| 160 |
# print STDERR " $line \n"; |
|
| 161 |
} |
|
| 162 |
#print "peers.value $peers\n"; |
|
| 163 |
print "mon.value $monitor_online\n"; |
|
| 164 |
print "moff.value $monitor_offline\n"; |
|
| 165 |
print "umon.value $unmonitor_online\n"; |
|
| 166 |
print "umoff.value $unmonitor_offline\n"; |
|
| 167 |
|
|
| 168 |
# vim:syntax=perl |
|
Formats disponibles : Unified diff