From 8e6facd5a91d715ea3fd79fdde5c3dcc7371fa15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sabati=C3=A9?= Date: Fri, 9 Jan 2015 16:04:46 +0100 Subject: [PATCH] init branch --- apps/voip/asterisk/lib/ami.pm | 119 +++++++++ .../mode/sip/.asterisk_sipshowpeer.pm.swo | Bin 0 -> 16384 bytes .../mode/sip/.asterisk_sipshowpeer.pm.swp | Bin 0 -> 16384 bytes apps/voip/asterisk/mode/sip/.showpeers.pm.swp | Bin 0 -> 24576 bytes .../asterisk/mode/sip/asterisk_sipshowpeer.pm | 139 +++++++++++ apps/voip/asterisk/mode/sip/showpeers.pm | 230 ++++++++++++++++++ apps/voip/asterisk/plugin.pm | 67 +++++ 7 files changed, 555 insertions(+) create mode 100644 apps/voip/asterisk/lib/ami.pm create mode 100644 apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swo create mode 100644 apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swp create mode 100644 apps/voip/asterisk/mode/sip/.showpeers.pm.swp create mode 100644 apps/voip/asterisk/mode/sip/asterisk_sipshowpeer.pm create mode 100644 apps/voip/asterisk/mode/sip/showpeers.pm create mode 100644 apps/voip/asterisk/plugin.pm diff --git a/apps/voip/asterisk/lib/ami.pm b/apps/voip/asterisk/lib/ami.pm new file mode 100644 index 000000000..29f21bc58 --- /dev/null +++ b/apps/voip/asterisk/lib/ami.pm @@ -0,0 +1,119 @@ +############################################################################### +# Copyright 2005-2015 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# 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 ; either version 2 of the License. +# +# 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, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Mathieu Cinquin +# +#################################################################################### + +package apps::voip::asterisk::lib::ami; + +use strict; +use warnings; +use Net::Telnet; +use Data::Dumper; + +my $ami_handle; +my $line; +my @lines; +my @result; + +sub quit { + $ami_handle->print("Action: logoff"); + $ami_handle->print(""); + $ami_handle->close(); +} + +sub connect { + my ($self, %options) = @_; + + my $connection_exit = defined($options{connection_exit}) ? $options{connection_exit} : 'unknown'; + + $ami_handle = new Net::Telnet (Telnetmode => 0, + Timeout => $self->{option_results}->{timeout}, + Errmode => 'return', + ); + + $ami_handle->open(Host => $self->{option_results}->{hostname}, + Port => $self->{option_results}->{port}, + ); + + if ($ami_handle->errmsg) { + $self->{output}->output_add(severity => $connection_exit, + short_msg => 'Unable to connect to AMI: ' . $ami_handle->errmsg); + $self->{output}->display(); + $self->{output}->exit(); + } + + # Check connection message. + $line = $ami_handle->getline; + if ($line !~ /^Asterisk/) { + $self->{output}->output_add(severity => $connection_exit, + short_msg => 'Unable to connect to AMI: ' . $line); + $self->{output}->display(); + $self->{output}->exit(); + } + + # Authentication. + $ami_handle->print("Action: login"); + $ami_handle->print("Username: $self->{option_results}->{username}"); + $ami_handle->print("Secret: $self->{option_results}->{password}"); + $ami_handle->print("Events: off"); + $ami_handle->print(""); + + # Check authentication message (second message). + $line = $ami_handle->getline; + $line = $ami_handle->getline; + if ($line !~ /^Message: Authentication accepted/) { + $self->{output}->output_add(severity => $connection_exit, + short_msg => 'Unable to connect to AMI: ' . $line); + $self->{output}->display(); + $self->{output}->exit(); + } + +} + +sub action { + my ($self) = @_; + + $ami_handle->print("Action: command"); + $ami_handle->print("Command: $self->{command}"); + $ami_handle->print(""); + + + my @return; + while (my $line = $ami_handle->getline(Timeout => 1)) { + push(@return,$line); + next if ($line !~ /END COMMAND/o); + } + return @return; +} + +1; diff --git a/apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swo b/apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swo new file mode 100644 index 0000000000000000000000000000000000000000..45abee12a90257be516c766f272cc9424e89efa5 GIT binary patch literal 16384 zcmeI2TWlOx8OIOh>Of1B@KB!kvb)5)$$DmX-Oy$on`~_-*%CWucbzuGi8DKUcK49k zIn%k=u}nZh0vd!+RS**5QXx?!9zci(5aO-n_5?3b5E2(bp`wTYbRBZ zcmXjh{jxjf`hEZNo$t&z)3Gi#mgqsF%J4bJ*f(2WZ9n_g1MJg>7z?C~RPo(DLq|+G zJe(u{Po&?k+V}nH^m_DtYhQhOnSEsnWC~;oWC~;oWC~;oWC~;o zWC~;oWC~;oWD5KjDqwe$Xa70%2LSy4|LFPuPj6=IkKjw-i=YdRf?waq*w4W8;FF*Q z4uco&W$ZWL^WYjd1P+4ly@|1>z?0zP;KN`I)WAdFr8hG61uzE=fnOb9>=)q2U>iIJ zE`l~V1!}+m1&{;xfxk>J_Gj=S_&xXu_&WF+_!#&oxCJDrgDG$r{QV7#{SEvMya2uf zo&z5OOW-`10|X9$3Gm|U8T&4H2HXNqfXko`ra&1S1TVjiu^)jSf^UP*fh}+e%z`pF z4(!U0KN~t1-=443qAvGfscUqfHtUuw}D?G9-akX22TSCI9LEWR&*>AJ~x^ASAG0I zco7vs-xYYDBaGe1$gO#~8K!IT&u&vyGTxA8_goq|${B^}-JaV_^-v$tqhgo$gvYzZ z!gQ&`Ciah0F>*E4y}H}IpxzSk>>;Pw_mg?GxVCw$v}WR8GLBL4!n@wL>IK|(26o5g zB`U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Tg=hsE7>R857HYRW)+GrzMHit{DClkT|Z=#<(|YA2q?$uQc9 zh79_8%O26M;CF;)B5}AhwaL`;|8sb*SI_$D`5%vd`twg*|06AbN!4YaOo2>+Oo2>+ sOo2>+Oo2>+Oo2>+Oo2>+Oo2>+{{;o|v>}GIaLbGA8?);9U;WMbU#1ho^Z)<= literal 0 HcmV?d00001 diff --git a/apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swp b/apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swp new file mode 100644 index 0000000000000000000000000000000000000000..5296ed9aaa51dcf9dc0c158fe574acfaab281f2a GIT binary patch literal 16384 zcmeHNTWlOx89tP20xeO(LwVxQ?h@}N>zUnkLz{JMvbCLfOYE54b=nXo&g{(D-9u*Q zOy^?9G64w*Xb`F@K)i6NkSG!l6^I8A;*D~9f)^+ViHo36QN$BaUbubd%&fh3QU!?@ z5Hr%3ojI5P{Qvh~&Wv-qm5a?KdeEpbT!$F@^3`WMUw`XC_GF&1K*~rp-|ZUOV$$Z} z)ZNCJaTu7c=$f9@7cw+`H|`5BG;Quh0hiw7sKN66(6qvc2O_*~4yD7*Q20A7>v#wU za?|HLF#O@&md*Mz1~LXT1NXA2TD78X^SPsRrWrEpNxTwfsBESfsBESfsBESfsBES zfsBESfsBESf&W4VEGPN)pH+VV!2kb`zW@LDX2$*id=dBp-~h*fU){&pPl4xwPXcY= z2=KzajQtw;9B>Ud3>*T!`zFRd4m<@s349n>1M0v-z)Npr?DN1Za2WXILB@U#{0P_v z9s@1{9pE%j2MnM9fzUj@Dbd<^&~a0`$?1DFJk0DpS}V}AvH z3%me)8+Z=*5U>QC2W9~R4gv>&7hliVcYtSrTfh^*WuO5}0%hP3@bc>z`yucH;G4i_ zfi2(?Fawl<6Ttnz%dchZFTnG_*MLs|9|W!fE#NJ{VSoX@e+^^50iFS#20jHm1zZMJ zfk%Kvpak3x{0x7v`3dlS;CsL~fM$@ZDfgJk9!g?ub+GZnVcePzF zmFU02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YfjW474?KJE>5dE9p$SW6sfOl}{=Y&tPX5WuhU2 zzE0Vr`UrkkcqR&mOOu;Seg8j)?|SvEufG5B>8G!M;Q8-q`%9`XyD|nc1~LXR1~LXR q1~LXR1~LXR1~LXR1~LXR2L2Zq$kT=x*266?vTn?%?|=0-=YIjo7s>em literal 0 HcmV?d00001 diff --git a/apps/voip/asterisk/mode/sip/.showpeers.pm.swp b/apps/voip/asterisk/mode/sip/.showpeers.pm.swp new file mode 100644 index 0000000000000000000000000000000000000000..6c94a68f62398ab52858e5e0181edb04eff1b1eb GIT binary patch literal 24576 zcmeI4dyFJUdB7X6590X1aYQ1cB&yrJ^UR{1nccm+V9$9sx7_aemV2%CfpK!l&^uGJ z)7hEsx$d6Z+pHEyNd9mhBp@P%AS}p3!U(WL2#RCkmHu#vG9xVo0RmI8G4% zSc3e%>c{jxZuhWkMIznOZ>JwsUsZkeRdv@_-`+h@+Ix0J^$j$172>IWWNIQ52` ztngOL@;xt<+j||Ix>Ks_;P77QD!st3w4J4jYcD%qQ0caN%Z?jV>e>x`?YX7ohTZK3 zl}nz}t=K`ReJ5C{bi9VH1l$Q)-fCBCKPY!Qdli^J&oz*1AksiDY?kiWzj%0TbVP0p z4jfQFeCuMaom>OC267GL8pt(}YarJ^u7O+wxd#3pX&~(0V7;66zB+F6+vDF?ZTY<+ zzTO}IzGKVt8{_Ns_;+c`^Y45&I+FZf+44NT%zttXE=Ea(Hc z2m|nMH(S=%;kRK5UJp0JBR^S|%P<8e z;K$*|;1+l_eEqeS^#ynoJ`JCO--q|Y1RR2cun(^6v#ifT9d3lr;IOE{e)u%bjbDdf zfXlE7b(n$yH~|0t8q0bgG~u04gWKV6ah&`C+z%gt2HXT+L!V!TtMD{@8AQjw1iuK` zW5co($A?t#yLs zA^{kFC}(PXLJiEewH;^`=um|%txBb?9R#bM-%wGV2jc2FO;tS5&`rnHjbhrqs9C-a zdhIZvo$E>NjiDihD@l~`a;oLJTF?u$@7f*x(pr$@{=aNN%L~Gn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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. +# +# +# $Log$ +# Revision 1.1 2005/10/22 21:04:01 rodo +# Created by Rodolphe Quiedeville +# +# Revision 1.2 2010/11/04 10:11 Guillaume Bour +# Allow channels monitoring per device (IAX/SIP/... account or trunk). +# To monitor a particular device, link asterisk_sipshowpeer_tech_identifier to this file, where: +# - tech is one of SIP, IAX, DAHDI, ... +# - identifier is account name (102, foo, ...) +# +# i.e: +# ls -s /path/to/asterisk_sipshowpeer /etc/munin/plugins/asterisk_sipshowpeer_trunk1 +# will monitor SIP/trunk1 device +# +# +# Parameters mandatory: +# +# username +# secret +# +#%# family=asterisk +#%# capabilities=autoconf + +use strict; + +my $ret = undef; +if (! eval "require Net::Telnet;") +{ + $ret = "Net::Telnet not found"; +} + +my $DEVICE=`basename $0`; +if ($DEVICE =~ /^asterisk_sipshowpeer_(.*)$/) +{ $DEVICE = "$1"; } +elsif (defined($ARGV[0])) +{ ($DEVICE) = @ARGV; } +else +{ $DEVICE = ''; } + +my $command = 'sip show peers'; + +my $host = exists $ENV{'host'} ? $ENV{'host'} : "10.50.1.65"; +my $port = exists $ENV{'port'} ? $ENV{'port'} : "5038"; + +#[asterisk_*] +#env.username xivo_munin_user +#env.secret jeSwupAd0 + +#my $username = $ENV{'username'}; +my $username = 'xivo_munin_user'; +#my $secret = $ENV{'secret'}; +my $secret = 'jeSwupAd0'; + +my $pop = new Net::Telnet (Telnetmode => 0); +$pop->open(Host => $host, + Port => $port); + +## Read connection message. +my $line = $pop->getline; +die $line unless $line =~ /^Asterisk/; + +## Send user name. +$pop->print("Action: login"); +$pop->print("Username: $username"); +$pop->print("Secret: $secret"); +$pop->print("Events: off"); +$pop->print(""); + +#Response: Success +#Message: Authentication accepted + +## Request status of messages. +$pop->print("Action: command"); +$pop->print("Command: ".$command); +$pop->print(""); +my @result = ('Nothing Monitored'); +my $nb = 0; +while (($line = $pop->getline) and ($line !~ /END COMMAND/o)) +{ +# print $line; + if ($DEVICE eq '') + { + $result[$nb] = $line if $line !~ /^Name|Unmonitored/; + } + else + { + $result[$nb] = $line if $line =~ /^$DEVICE/; + } + $nb++; +} +$pop->print("Action: logoff"); +$pop->print(""); +while (($line = $pop->getline) and ($line !~ /END COMMAND/o)) +{} +$pop->close(); + +my $peername; +my $status; +my $splitresult; + +foreach (@result) +{ + if ((defined($_)) && ($_ =~ /^.*\/.* /)) + { + chomp($_); + $peername = $status = $_; + $peername =~ /^(\w*)\/\w* .* (OK|Unreachable) (\(.*\))/; + $splitresult = $1.": ".$2; + if (defined($3)) + { + $splitresult = $splitresult." ".$3; + } + print $splitresult."\n"; + } +} + +# vim:syntax=perl diff --git a/apps/voip/asterisk/mode/sip/showpeers.pm b/apps/voip/asterisk/mode/sip/showpeers.pm new file mode 100644 index 000000000..c92b49314 --- /dev/null +++ b/apps/voip/asterisk/mode/sip/showpeers.pm @@ -0,0 +1,230 @@ +################################################################################ +# Copyright 2005-2015 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# 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 ; either version 2 of the License. +# +# 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, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Mathieu Cinquin +# +#################################################################################### + +package apps::voip::asterisk::mode::sip::showpeers; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; +use apps::voip::asterisk::lib::ami; + +use Data::Dumper; + +sub new { + my ($class, %options) = @_; + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + + $self->{version} = '1.0'; + $options{options}->add_options(arguments => + { + "hostname:s" => { name => 'hostname' }, + "port:s" => { name => 'port', default => 5038 }, + "username:s" => { name => 'username' }, + "password:s" => { name => 'password' }, + "trunkname:s" => { name => 'trunkname' }, + "filter-name:s" => { name => 'filter_name', }, + "timeout:s" => { name => 'timeout', default => 20 }, + }); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (!defined($self->{option_results}->{hostname})) { + $self->{output}->add_option_msg(short_msg => "Please set the --hostname option"); + $self->{output}->option_exit(); + } + + if (!defined($self->{option_results}->{username})) { + $self->{output}->add_option_msg(short_msg => "Please set the --username option"); + $self->{output}->option_exit(); + } + + if (!defined($self->{option_results}->{password})) { + $self->{output}->add_option_msg(short_msg => "Please set the --password option"); + $self->{output}->option_exit(); + } + +} + + +sub run { + my ($self, %options) = @_; + + apps::voip::asterisk::lib::ami::connect($self); + + $self->{command} = 'sip show peers'; + + my @result = apps::voip::asterisk::lib::ami::action($self); + + print "@result"; + + apps::voip::asterisk::lib::ami::quit(); + + + +} + + +# trunkname => $self->{option_results}->{trunkname}); +# my @lines = split /\n/, $stdout; +# # Header not needed +# #shift @lines; +# foreach my $line (@lines) { +# next if ($line !~ /^(.*): (.*) \((.*)\)/); +# my ($trunkname, $trunkstatus, $trunkvalue) = ($1, $2, $3); +# +# if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && +# $trunkname !~ /$self->{option_results}->{filter_name}/) { +# $self->{output}->output_add(long_msg => "Skipping trunk '" . $trunkname . "': no matching filter name"); +# next; +# } +# ##### +# # test +# ##### +# if ($trunkname eq '009900524') +# { +# $self->{result}->{$trunkname} = {name => $trunkname, status => $trunkstatus, value => $trunkvalue}; +# } +# else +# { +# $self->{result}->{$trunkname} = {name => $trunkname, status => 'Unknown', value => $trunkvalue}; +# } +# } +#} +# +#sub run { +# my ($self, %options) = @_; +# my $msg; +# $self->{output}->output_add(severity => 'OK', +# short_msg => 'Everything is OK'); +# $self->manage_selection(); +# +# foreach my $name (sort(keys %{$self->{result}})) { +# $msg = sprintf("Trunk: %s %s", $self->{result}->{$name}->{name}, $self->{result}->{$name}->{status}); +# $self->{output}->perfdata_add(label => $self->{result}->{$name}->{name}, +# value => $self->{result}->{$name}->{value}, +# #warning => $self->{perfdata}->get_perfdata_for_output(label => 'warn1'), +# #critical => $self->{perfdata}->get_perfdata_for_output(label => 'crit1'), +# min => 0); +# if (!$self->{output}->is_status(value => $self->{result}->{$name}->{status}, compare => 'ok', litteral => 1)) { +# $self->{output}->output_add(severity => $self->{result}->{$name}->{status}, +# short_msg => $msg); +# } +# } +# +# $self->{output}->display(); +# $self->{output}->exit(); +#} +# +#sub disco_format { +# my ($self, %options) = @_; +# +# $self->{output}->add_disco_format(elements => ['name']); +#} +# +#sub disco_show { +# my ($self, %options) = @_; +# +# $self->manage_selection(); +# foreach my $name (sort(keys %{$self->{result}})) { +# $self->{output}->add_disco_entry(name => $name, +# ); +# } +#} + +1; + +__END__ + +=head1 MODE + +List partitions. + +=over 8 + +=item B<--remote> + +Execute command remotely in 'ssh'. + +=item B<--hostname> + +Hostname to query (need --remote). + +=item B<--ssh-option> + +Specify multiple options like the user (example: --ssh-option='-l=centreon-engine' --ssh-option='-p=52'). + +=item B<--ssh-path> + +Specify ssh command path (default: none) + +=item B<--ssh-command> + +Specify ssh command (default: 'ssh'). Useful to use 'plink'. + +=item B<--timeout> + +Timeout in seconds for the command (Default: 30). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +Command to get information (Default: 'cat'). +Can be changed if you have output in a file. + +=item B<--command-path> + +Command path (Default: none). + +=item B<--command-options> + +Command options (Default: '/proc/partitions 2>&1'). + +=item B<--filter-name> + +Filter partition name (regexp can be used). + +=back + +=cut diff --git a/apps/voip/asterisk/plugin.pm b/apps/voip/asterisk/plugin.pm new file mode 100644 index 000000000..ad44042d8 --- /dev/null +++ b/apps/voip/asterisk/plugin.pm @@ -0,0 +1,67 @@ +################################################################################ +# Copyright 2005-2014 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# 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 ; either version 2 of the License. +# +# 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, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Mathieu Cinquin +# +#################################################################################### + +package apps::voip::asterisk::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_simple); +#use base qw(centreon::plugins::script_snmp); + +sub new { + my ($class, %options) = @_; + + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'showpeers' => 'apps::voip::asterisk::mode::sip::showpeers', + ); + + return $self; +} + + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check BlueMind through InfluxDB API + +=cut