mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
c33bbb90e5
untar asterisk-fax and move asterisk-multigraph-munin-plugin
132 lines
4 KiB
Perl
Executable file
132 lines
4 KiB
Perl
Executable file
#!/usr/bin/perl
|
|
|
|
=head1 NAME
|
|
|
|
asterisk_fax_* - Plugin to monitor Asterisk fax parameters.
|
|
|
|
=head1 SUPPORTED VERSION
|
|
|
|
This plugin supports Asterisk 1.8.* and the SpanDSP fax modules.
|
|
|
|
=head1 CONFIGURATION
|
|
|
|
The following configuration parameters are used by this plugin
|
|
|
|
[asterisk*]
|
|
env.host - hostname to connect to. Defaults to localhost.
|
|
env.port - port number to connect to. Defaults to 5038.
|
|
env.username - username used for authentication. No default value.
|
|
env.secret - secret used for authentication. No default value.
|
|
env.timeout - AMI timeout value in seconds. Defaults to 5.
|
|
|
|
The "username" and "secret" parameters are mandatory, and have no
|
|
defaults.
|
|
|
|
=head1 DEFAULT CONFIGURATION
|
|
|
|
[asterisk*]
|
|
env.username manager
|
|
env.secret insecure
|
|
env.host 127.0.0.1
|
|
env.port 5038
|
|
env.timeout 5
|
|
|
|
=head1 REQUIRED PERL MODULES
|
|
|
|
This plugin requires the Asterisk::AMI module and its dependencies.
|
|
Its dependencies can be found here:
|
|
http://deps.cpantesters.org/?module=Asterisk::AMI;perl=latest
|
|
|
|
|
|
=head1 AUTHOR
|
|
|
|
Copyright (C) 2011 Frank DiGennaro <fsd@voipbusiness.us>
|
|
|
|
=head1 LICENSE
|
|
|
|
Gnu GPLv2
|
|
|
|
=begin comment
|
|
|
|
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.
|
|
|
|
If you improve this script please send your version to my email
|
|
address with the copyright notice upgrade with your name.
|
|
|
|
=end comment
|
|
|
|
=head1 MAGIC MARKERS
|
|
|
|
#%# family=contrib
|
|
|
|
=cut
|
|
|
|
use Carp;
|
|
use strict;
|
|
use Asterisk::AMI;
|
|
|
|
eval "use Asterisk::AMI";
|
|
print "Asterisk::AMI not found. Exiting...\n" if $@;
|
|
exit( 0 ) if $@;
|
|
|
|
if ( $ARGV[ 0 ] and $ARGV[ 0 ] eq "config" ) {
|
|
print "graph_title Asterisk Fax - Successful Faxes (T.38 and G.711)\n";
|
|
print "graph_args --base 1000 -l 0\n";
|
|
print "graph_vlabel Number of Successful Faxes\n";
|
|
print "graph_category asterisk\n";
|
|
print "t38_success.draw AREA\n";
|
|
print "t38_success.label Successful T.38 Faxes\n";
|
|
print "g711_success.draw AREA\n";
|
|
print "g711_success.label Successful G.711 Faxes\n";
|
|
exit ( 0 );
|
|
};
|
|
|
|
my $host = exists $ENV{ 'host' } ? $ENV{ 'host' } : "127.0.0.1";
|
|
my $port = exists $ENV{ 'port' } ? $ENV{ 'port' } : "5038";
|
|
my $timeout = exists $ENV{ 'timeout' } ? $ENV{ 'timeout' } : "5";
|
|
my $username = $ENV{ 'username' };
|
|
my $secret = $ENV{ 'secret' };
|
|
|
|
my $astman = Asterisk::AMI->new(PeerAddr => "$host",
|
|
PeerPort => "$port",
|
|
Username => "$username",
|
|
Secret => "$secret"
|
|
);
|
|
|
|
croak "Unable to connect to asterisk" unless ( $astman );
|
|
my $actionid = $astman->send_action({ Action => 'Command',
|
|
Command => 'fax show stats',
|
|
$timeout});
|
|
my $response = $astman->get_response( $actionid );
|
|
my $arrayref = $response->{CMD};
|
|
my $null = qq{};
|
|
my ( %faxstats, $section );
|
|
foreach my $line ( @$arrayref ) {
|
|
next if ( ( ! $line ) || ( $line =~ /-----------/ ) );
|
|
my ( $key, $value ) = split( ':', $line );
|
|
$section = $key if ( $value eq $null );
|
|
$key =~ s/\s+$//g;
|
|
$value =~ s/^\s+//g;
|
|
$faxstats{ "$section" }{ "$key" } = $value if ( $value ne $null );
|
|
};
|
|
$astman->disconnect;
|
|
|
|
print "t38_success.value $faxstats{'Spandsp T.38'}{'Success'}\n";
|
|
print "g711_success.value $faxstats{'Spandsp G.711'}{'Success'}\n";
|
|
|
|
exit( 0 );
|
|
|
|
|
|
|