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 1/5] 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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rErbmTg=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 z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9P}QYfjW474?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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U 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. +# +# +# $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 From 072320973a948d310d173eba4e72f256a41375db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sabati=C3=A9?= Date: Fri, 9 Jan 2015 19:20:17 +0100 Subject: [PATCH 2/5] ami mode and snmp mode --- apps/voip/asterisk/{ => ami}/lib/ami.pm | 0 apps/voip/asterisk/ami/mode/iax/showpeers.pm | 153 ++++++++++++++++ .../mode/sip/.asterisk_sipshowpeer.pm.swo | Bin .../mode/sip/.asterisk_sipshowpeer.pm.swp | Bin .../{ => ami}/mode/sip/.showpeers.pm.swp | Bin .../asterisk/{ => ami}/mode/sip/showpeers.pm | 155 ++++------------ apps/voip/asterisk/{ => ami}/plugin.pm | 5 +- .../asterisk/mode/sip/asterisk_sipshowpeer.pm | 139 --------------- apps/voip/asterisk/snmp/mode/activecalls.pm | 135 ++++++++++++++ .../asterisk/snmp/mode/activecallsbytrunk.pm | 168 ++++++++++++++++++ apps/voip/asterisk/snmp/plugin.pm | 68 +++++++ 11 files changed, 566 insertions(+), 257 deletions(-) rename apps/voip/asterisk/{ => ami}/lib/ami.pm (100%) create mode 100644 apps/voip/asterisk/ami/mode/iax/showpeers.pm rename apps/voip/asterisk/{ => ami}/mode/sip/.asterisk_sipshowpeer.pm.swo (100%) rename apps/voip/asterisk/{ => ami}/mode/sip/.asterisk_sipshowpeer.pm.swp (100%) rename apps/voip/asterisk/{ => ami}/mode/sip/.showpeers.pm.swp (100%) rename apps/voip/asterisk/{ => ami}/mode/sip/showpeers.pm (53%) rename apps/voip/asterisk/{ => ami}/plugin.pm (91%) delete mode 100644 apps/voip/asterisk/mode/sip/asterisk_sipshowpeer.pm create mode 100644 apps/voip/asterisk/snmp/mode/activecalls.pm create mode 100644 apps/voip/asterisk/snmp/mode/activecallsbytrunk.pm create mode 100644 apps/voip/asterisk/snmp/plugin.pm diff --git a/apps/voip/asterisk/lib/ami.pm b/apps/voip/asterisk/ami/lib/ami.pm similarity index 100% rename from apps/voip/asterisk/lib/ami.pm rename to apps/voip/asterisk/ami/lib/ami.pm diff --git a/apps/voip/asterisk/ami/mode/iax/showpeers.pm b/apps/voip/asterisk/ami/mode/iax/showpeers.pm new file mode 100644 index 000000000..286614139 --- /dev/null +++ b/apps/voip/asterisk/ami/mode/iax/showpeers.pm @@ -0,0 +1,153 @@ +################################################################################ +# 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::ami::mode::iax::showpeers; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; +use apps::voip::asterisk::ami::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' }, + "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) = @_; + + # Get data from asterisk + apps::voip::asterisk::lib::ami::connect($self); + $self->{command} = 'iax2 show peers'; + my @result = apps::voip::asterisk::lib::ami::action($self); + apps::voip::asterisk::lib::ami::quit(); + + # Compute data + foreach my $line (@result) { + next if ($line !~ /^(\w*)\/\w* .* (OK|Unreachable) \((.*)\)/); + 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; + } + + $self->{result}->{$trunkname} = {name => $trunkname, status => $trunkstatus, value => $trunkvalue}; + } + + # Send formated data to Centreon + my $msg; + $self->{output}->output_add(severity => 'OK', + short_msg => 'Everything is OK'); + + 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}, + # keep this lines for future upgrade of this plugin + #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(); +} + +1; + +__END__ + +=head1 MODE + +List partitions. + +=over 8 + +=item B<--hostname> + +Hostname to query. + +=item B<--filter-name> + +Filter on trunkname (regexp can be used). + +=back + +=cut diff --git a/apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swo b/apps/voip/asterisk/ami/mode/sip/.asterisk_sipshowpeer.pm.swo similarity index 100% rename from apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swo rename to apps/voip/asterisk/ami/mode/sip/.asterisk_sipshowpeer.pm.swo diff --git a/apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swp b/apps/voip/asterisk/ami/mode/sip/.asterisk_sipshowpeer.pm.swp similarity index 100% rename from apps/voip/asterisk/mode/sip/.asterisk_sipshowpeer.pm.swp rename to apps/voip/asterisk/ami/mode/sip/.asterisk_sipshowpeer.pm.swp diff --git a/apps/voip/asterisk/mode/sip/.showpeers.pm.swp b/apps/voip/asterisk/ami/mode/sip/.showpeers.pm.swp similarity index 100% rename from apps/voip/asterisk/mode/sip/.showpeers.pm.swp rename to apps/voip/asterisk/ami/mode/sip/.showpeers.pm.swp diff --git a/apps/voip/asterisk/mode/sip/showpeers.pm b/apps/voip/asterisk/ami/mode/sip/showpeers.pm similarity index 53% rename from apps/voip/asterisk/mode/sip/showpeers.pm rename to apps/voip/asterisk/ami/mode/sip/showpeers.pm index c92b49314..e38b9d3e1 100644 --- a/apps/voip/asterisk/mode/sip/showpeers.pm +++ b/apps/voip/asterisk/ami/mode/sip/showpeers.pm @@ -33,14 +33,14 @@ # #################################################################################### -package apps::voip::asterisk::mode::sip::showpeers; +package apps::voip::asterisk::ami::mode::sip::showpeers; use base qw(centreon::plugins::mode); use strict; use warnings; use centreon::plugins::misc; -use apps::voip::asterisk::lib::ami; +use apps::voip::asterisk::ami::lib::ami; use Data::Dumper; @@ -56,7 +56,6 @@ sub new { "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 }, }); @@ -87,89 +86,50 @@ sub check_options { sub run { my ($self, %options) = @_; - - apps::voip::asterisk::lib::ami::connect($self); - - $self->{command} = 'sip show peers'; + # Get data from asterisk + 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(); + + # Compute data + foreach my $line (@result) { + next if ($line !~ /^(\w*)\/\w* .* (OK|Unreachable) \((.*)\)/); + 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; + } + + $self->{result}->{$trunkname} = {name => $trunkname, status => $trunkstatus, value => $trunkvalue}; + } + + # Send formated data to Centreon + my $msg; + $self->{output}->output_add(severity => 'OK', + short_msg => 'Everything is OK'); + 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}, + # keep this lines for future upgrade of this plugin + #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(); } - -# 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__ @@ -180,50 +140,13 @@ 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). +Filter on trunkname (regexp can be used). =back diff --git a/apps/voip/asterisk/plugin.pm b/apps/voip/asterisk/ami/plugin.pm similarity index 91% rename from apps/voip/asterisk/plugin.pm rename to apps/voip/asterisk/ami/plugin.pm index ad44042d8..ae8c113ca 100644 --- a/apps/voip/asterisk/plugin.pm +++ b/apps/voip/asterisk/ami/plugin.pm @@ -33,7 +33,7 @@ # #################################################################################### -package apps::voip::asterisk::plugin; +package apps::voip::asterisk::ami::plugin; use strict; use warnings; @@ -49,7 +49,8 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'showpeers' => 'apps::voip::asterisk::mode::sip::showpeers', + 'sipshowpeers' => 'apps::voip::asterisk::ami::mode::sip::showpeers', + 'iaxshowpeers' => 'apps::voip::asterisk::ami::mode::iax::showpeers', ); return $self; diff --git a/apps/voip/asterisk/mode/sip/asterisk_sipshowpeer.pm b/apps/voip/asterisk/mode/sip/asterisk_sipshowpeer.pm deleted file mode 100644 index d5875d436..000000000 --- a/apps/voip/asterisk/mode/sip/asterisk_sipshowpeer.pm +++ /dev/null @@ -1,139 +0,0 @@ -#!/usr/bin/perl -w -# -# Copyright (C) 2005 Rodolphe Quiedeville -# -# 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. -# -# -# $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/snmp/mode/activecalls.pm b/apps/voip/asterisk/snmp/mode/activecalls.pm new file mode 100644 index 000000000..e7905bd53 --- /dev/null +++ b/apps/voip/asterisk/snmp/mode/activecalls.pm @@ -0,0 +1,135 @@ +################################################################################ +# 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 : Quentin Garnier +# +#################################################################################### + +package apps::voip::asterisk::snmp::mode::activecalls; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +my $oid_astBase = '.1.3.6.1.4.1.22736'; +my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0'; +#my $oid_AsteriskConfigCallsProcessed = $oid_AsteriskBase.'.1.2.6.0'; + +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 => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + "force-oid:s" => { name => 'force_oid', }, + }); + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_value}->check_options(%options); +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my ($result, $value); + + if (defined($self->{option_results}->{force_oid})) { + $result = $self->{snmp}->get_leef(oids => [ $self->{option_results}->{force_oid} ], nothing_quit => 1); + $value = $result->{$self->{option_results}->{force_oid}}; + } else { + $result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1); + $value = $result->{$oid_astConfigCallsActive}; + } + + my $exit_code = $self->{perfdata}->threshold_check(value => $value, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->perfdata_add(label => 'channels', + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("Current active calls: %s", $value) + ); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check system uptime. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=item B<--force-oid> + +Can choose your oid (numeric format only). + +=back + +=cut \ No newline at end of file diff --git a/apps/voip/asterisk/snmp/mode/activecallsbytrunk.pm b/apps/voip/asterisk/snmp/mode/activecallsbytrunk.pm new file mode 100644 index 000000000..789640697 --- /dev/null +++ b/apps/voip/asterisk/snmp/mode/activecallsbytrunk.pm @@ -0,0 +1,168 @@ +################################################################################ +# 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 : Quentin Garnier +# +#################################################################################### + +package apps::voip::asterisk::snmp::mode::activecallsbytrunk; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +my $oid_astBase = '.1.3.6.1.4.1.22736'; +my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0'; +#my $oid_AsteriskConfigCallsProcessed = $oid_AsteriskBase.'.1.2.6.0'; +my $oid_astChanName = $oid_astBase.'.1.5.2.1.2'; # need an index at the end +my $oid_astChanIndex = $oid_astBase.'.1.5.2.1.1'; # need an index at the end +my $oid_astNumChannels = $oid_astBase.'.1.5.1.0'; + +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 => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + "force-oid:s" => { name => 'force_oid', }, + "trunklist:s" => { name => 'trunklist', }, + }); + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_value}->check_options(%options); +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my ($result, $value); + my @callsbytrunk; + + # explode trunk list + my @trunklist = split(';',$self->{option_results}->{trunklist}); + foreach my $trunk (@trunklist) + { + push @callsbytrunk , { trunk => $trunk, num => 0}; + } + # get chanName and sum calls for each + $result = $self->{snmp}->get_leef(oids => [ $oid_astNumChannels ], nothing_quit => 1); + my $astNumChannels = $result->{$oid_astNumChannels}; + foreach my $i (1..$astNumChannels) { + $result = $self->{snmp}->get_leef(oids => [ $oid_astChanName.'.'.$i ], nothing_quit => 1); + $value = $result->{$oid_astChanName.'.'.$i}; + $value =~ /^(.*)\/(.*)-.*/; + my ($protocol, $trunkname) = ($1, $2); + foreach my $val (@callsbytrunk) + { + if ( $val->{trunk} eq $trunkname) + { + $val->{num}=$val->{num}+1; + } + } + } + +#print $callsbytrunk[1]->{num}; +#exit; + +# if (defined($self->{option_results}->{force_oid})) { +# $result = $self->{snmp}->get_leef(oids => [ $self->{option_results}->{force_oid} ], nothing_quit => 1); +# $value = $result->{$self->{option_results}->{force_oid}}; +# } else { + $result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1); + my $astConfigCallsActive = $result->{$oid_astConfigCallsActive}; +# } + +# my $exit_code = $self->{perfdata}->threshold_check(value => $value, +# threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + foreach $value (@callsbytrunk) + { + $self->{output}->perfdata_add(label => $value->{trunk}, + value => $value->{num}, +# warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), +# critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + } + $self->{output}->output_add(severity => 'OK', + short_msg => sprintf("Current active calls: %s", $astConfigCallsActive) + ); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check system uptime. + +=over 8 + +=item B<--warning> + +Threshold warning. + +=item B<--critical> + +Threshold critical. + +=item B<--force-oid> + +Can choose your oid (numeric format only). + +=back + +=cut \ No newline at end of file diff --git a/apps/voip/asterisk/snmp/plugin.pm b/apps/voip/asterisk/snmp/plugin.pm new file mode 100644 index 000000000..82254259d --- /dev/null +++ b/apps/voip/asterisk/snmp/plugin.pm @@ -0,0 +1,68 @@ +################################################################################ +# 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::snmp::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}} = ( + 'activecalls' => 'apps::voip::asterisk::snmp::mode::activecalls', + 'activecallsbytrunk' => 'apps::voip::asterisk::snmp::mode::activecallsbytrunk', + ); + + return $self; +} + + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check BlueMind through InfluxDB API + +=cut From 42724f7fffbf6ae8276bc0a4f07b48fe50b58546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sabati=C3=A9?= Date: Sun, 11 Jan 2015 23:32:54 +0100 Subject: [PATCH 3/5] merge total of calls and calls by trunk --- ...{activecallsbytrunk.pm => activecalls.old} | 71 ++++---------- apps/voip/asterisk/snmp/mode/activecalls.pm | 96 +++++++++++++++---- apps/voip/asterisk/snmp/plugin.pm | 1 - 3 files changed, 96 insertions(+), 72 deletions(-) rename apps/voip/asterisk/snmp/mode/{activecallsbytrunk.pm => activecalls.old} (62%) diff --git a/apps/voip/asterisk/snmp/mode/activecallsbytrunk.pm b/apps/voip/asterisk/snmp/mode/activecalls.old similarity index 62% rename from apps/voip/asterisk/snmp/mode/activecallsbytrunk.pm rename to apps/voip/asterisk/snmp/mode/activecalls.old index 789640697..e7905bd53 100644 --- a/apps/voip/asterisk/snmp/mode/activecallsbytrunk.pm +++ b/apps/voip/asterisk/snmp/mode/activecalls.old @@ -33,7 +33,7 @@ # #################################################################################### -package apps::voip::asterisk::snmp::mode::activecallsbytrunk; +package apps::voip::asterisk::snmp::mode::activecalls; use base qw(centreon::plugins::mode); @@ -44,9 +44,6 @@ use centreon::plugins::statefile; my $oid_astBase = '.1.3.6.1.4.1.22736'; my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0'; #my $oid_AsteriskConfigCallsProcessed = $oid_AsteriskBase.'.1.2.6.0'; -my $oid_astChanName = $oid_astBase.'.1.5.2.1.2'; # need an index at the end -my $oid_astChanIndex = $oid_astBase.'.1.5.2.1.1'; # need an index at the end -my $oid_astNumChannels = $oid_astBase.'.1.5.1.0'; sub new { my ($class, %options) = @_; @@ -56,10 +53,9 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, "force-oid:s" => { name => 'force_oid', }, - "trunklist:s" => { name => 'trunklist', }, }); $self->{statefile_value} = centreon::plugins::statefile->new(%options); return $self; @@ -87,54 +83,25 @@ sub run { $self->{snmp} = $options{snmp}; my ($result, $value); - my @callsbytrunk; - # explode trunk list - my @trunklist = split(';',$self->{option_results}->{trunklist}); - foreach my $trunk (@trunklist) - { - push @callsbytrunk , { trunk => $trunk, num => 0}; - } - # get chanName and sum calls for each - $result = $self->{snmp}->get_leef(oids => [ $oid_astNumChannels ], nothing_quit => 1); - my $astNumChannels = $result->{$oid_astNumChannels}; - foreach my $i (1..$astNumChannels) { - $result = $self->{snmp}->get_leef(oids => [ $oid_astChanName.'.'.$i ], nothing_quit => 1); - $value = $result->{$oid_astChanName.'.'.$i}; - $value =~ /^(.*)\/(.*)-.*/; - my ($protocol, $trunkname) = ($1, $2); - foreach my $val (@callsbytrunk) - { - if ( $val->{trunk} eq $trunkname) - { - $val->{num}=$val->{num}+1; - } - } - } - -#print $callsbytrunk[1]->{num}; -#exit; - -# if (defined($self->{option_results}->{force_oid})) { -# $result = $self->{snmp}->get_leef(oids => [ $self->{option_results}->{force_oid} ], nothing_quit => 1); -# $value = $result->{$self->{option_results}->{force_oid}}; -# } else { + if (defined($self->{option_results}->{force_oid})) { + $result = $self->{snmp}->get_leef(oids => [ $self->{option_results}->{force_oid} ], nothing_quit => 1); + $value = $result->{$self->{option_results}->{force_oid}}; + } else { $result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1); - my $astConfigCallsActive = $result->{$oid_astConfigCallsActive}; -# } - -# my $exit_code = $self->{perfdata}->threshold_check(value => $value, -# threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - foreach $value (@callsbytrunk) - { - $self->{output}->perfdata_add(label => $value->{trunk}, - value => $value->{num}, -# warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), -# critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); + $value = $result->{$oid_astConfigCallsActive}; } - $self->{output}->output_add(severity => 'OK', - short_msg => sprintf("Current active calls: %s", $astConfigCallsActive) + + my $exit_code = $self->{perfdata}->threshold_check(value => $value, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + $self->{output}->perfdata_add(label => 'channels', + value => $value, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("Current active calls: %s", $value) ); $self->{output}->display(); diff --git a/apps/voip/asterisk/snmp/mode/activecalls.pm b/apps/voip/asterisk/snmp/mode/activecalls.pm index e7905bd53..645e0cd73 100644 --- a/apps/voip/asterisk/snmp/mode/activecalls.pm +++ b/apps/voip/asterisk/snmp/mode/activecalls.pm @@ -43,7 +43,9 @@ use centreon::plugins::statefile; my $oid_astBase = '.1.3.6.1.4.1.22736'; my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0'; -#my $oid_AsteriskConfigCallsProcessed = $oid_AsteriskBase.'.1.2.6.0'; +my $oid_astChanName = $oid_astBase.'.1.5.2.1.2'; # need an index at the end +my $oid_astChanIndex = $oid_astBase.'.1.5.2.1.1'; # need an index at the end +my $oid_astNumChannels = $oid_astBase.'.1.5.1.0'; sub new { my ($class, %options) = @_; @@ -53,9 +55,12 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + "warnontrunk:s" => { name => 'warnontrunk', }, + "critontrunk:s" => { name => 'critontrunk', }, "force-oid:s" => { name => 'force_oid', }, + "trunklist:s" => { name => 'trunklist', }, }); $self->{statefile_value} = centreon::plugins::statefile->new(%options); return $self; @@ -73,6 +78,14 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } + if (($self->{perfdata}->threshold_validate(label => 'warnontrunk', value => $self->{option_results}->{warnontrunk})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warnontrunk} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critontrunk', value => $self->{option_results}->{critontrunk})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critontrunk} . "'."); + $self->{output}->option_exit(); + } $self->{statefile_value}->check_options(%options); } @@ -83,26 +96,59 @@ sub run { $self->{snmp} = $options{snmp}; my ($result, $value); + my @callsbytrunk; - if (defined($self->{option_results}->{force_oid})) { - $result = $self->{snmp}->get_leef(oids => [ $self->{option_results}->{force_oid} ], nothing_quit => 1); - $value = $result->{$self->{option_results}->{force_oid}}; - } else { - $result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1); - $value = $result->{$oid_astConfigCallsActive}; + # explode trunk list + my @trunklist = split(';',$self->{option_results}->{trunklist}); + foreach my $trunk (@trunklist) + { + push @callsbytrunk , { trunk => $trunk, num => 0}; + } + # get chanName and sum calls for each + $result = $self->{snmp}->get_leef(oids => [ $oid_astNumChannels ], nothing_quit => 1); + my $astNumChannels = $result->{$oid_astNumChannels}; + foreach my $i (1..$astNumChannels) { + $result = $self->{snmp}->get_leef(oids => [ $oid_astChanName.'.'.$i ], nothing_quit => 1); + $value = $result->{$oid_astChanName.'.'.$i}; + $value =~ /^(.*)\/(.*)-.*/; + my ($protocol, $trunkname) = ($1, $2); + foreach my $val (@callsbytrunk) + { + if ( $val->{trunk} eq $trunkname) + { + $val->{num}=$val->{num}+1; + } + } } - my $exit_code = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->perfdata_add(label => 'channels', - value => $value, + $result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1); + my $astConfigCallsActive = $result->{$oid_astConfigCallsActive}; + + # compute status based on total number of active calls + # ToDo: compute status based on each trunk .... + my $exit_code = $self->{perfdata}->threshold_check(value => $astConfigCallsActive, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("Current active calls: %s", $astConfigCallsActive) + ); + + # Perfdata on all active calls + $self->{output}->perfdata_add(label => 'Calls', + value => $astConfigCallsActive, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), min => 0); - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Current active calls: %s", $value) - ); + # Perfdata on number of calls for each trunk + foreach $value (@callsbytrunk) + { + $self->{output}->perfdata_add(label => $value->{trunk}, + value => $value->{num}, +# warning => $self->{perfdata}->get_perfdata_for_output(label => 'warnontrunk'), +# critical => $self->{perfdata}->get_perfdata_for_output(label => 'critontrunk'), + min => 0); + } $self->{output}->display(); $self->{output}->exit(); @@ -114,22 +160,34 @@ __END__ =head1 MODE -Check system uptime. +Check number of active calls (total and by trunk) =over 8 =item B<--warning> -Threshold warning. +Threshold warning for total number of calls. =item B<--critical> -Threshold critical. +Threshold critical for total number of calls. + +=item B<--warnontrunk> + +Threshold warning for trunks. + +=item B<--critontrunk> + +Threshold critical for trunks. =item B<--force-oid> Can choose your oid (numeric format only). +=item B<--trunklist> + +List of outgoing trunks + =back =cut \ No newline at end of file diff --git a/apps/voip/asterisk/snmp/plugin.pm b/apps/voip/asterisk/snmp/plugin.pm index 82254259d..fec52d97c 100644 --- a/apps/voip/asterisk/snmp/plugin.pm +++ b/apps/voip/asterisk/snmp/plugin.pm @@ -50,7 +50,6 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( 'activecalls' => 'apps::voip::asterisk::snmp::mode::activecalls', - 'activecallsbytrunk' => 'apps::voip::asterisk::snmp::mode::activecallsbytrunk', ); return $self; From 531a969b0577e358646b195fa4ccdba3c08f8328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sabati=C3=A9?= Date: Tue, 13 Jan 2015 16:27:41 +0100 Subject: [PATCH 4/5] asterisk: number of active and external calls --- apps/voip/asterisk/snmp/mode/activecalls.old | 135 ---------- apps/voip/asterisk/snmp/mode/activecalls.pm | 94 ++----- apps/voip/asterisk/snmp/mode/externalcalls.pm | 239 ++++++++++++++++++ apps/voip/asterisk/snmp/plugin.pm | 1 + 4 files changed, 258 insertions(+), 211 deletions(-) delete mode 100644 apps/voip/asterisk/snmp/mode/activecalls.old create mode 100644 apps/voip/asterisk/snmp/mode/externalcalls.pm diff --git a/apps/voip/asterisk/snmp/mode/activecalls.old b/apps/voip/asterisk/snmp/mode/activecalls.old deleted file mode 100644 index e7905bd53..000000000 --- a/apps/voip/asterisk/snmp/mode/activecalls.old +++ /dev/null @@ -1,135 +0,0 @@ -################################################################################ -# 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 : Quentin Garnier -# -#################################################################################### - -package apps::voip::asterisk::snmp::mode::activecalls; - -use base qw(centreon::plugins::mode); - -use strict; -use warnings; -use centreon::plugins::statefile; - -my $oid_astBase = '.1.3.6.1.4.1.22736'; -my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0'; -#my $oid_AsteriskConfigCallsProcessed = $oid_AsteriskBase.'.1.2.6.0'; - -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 => - { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "force-oid:s" => { name => 'force_oid', }, - }); - $self->{statefile_value} = centreon::plugins::statefile->new(%options); - return $self; -} - -sub check_options { - my ($self, %options) = @_; - $self->SUPER::init(%options); - - if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); - $self->{output}->option_exit(); - } - - $self->{statefile_value}->check_options(%options); -} - -sub run { - my ($self, %options) = @_; - # $options{snmp} = snmp object - $self->{snmp} = $options{snmp}; - - my ($result, $value); - - if (defined($self->{option_results}->{force_oid})) { - $result = $self->{snmp}->get_leef(oids => [ $self->{option_results}->{force_oid} ], nothing_quit => 1); - $value = $result->{$self->{option_results}->{force_oid}}; - } else { - $result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1); - $value = $result->{$oid_astConfigCallsActive}; - } - - my $exit_code = $self->{perfdata}->threshold_check(value => $value, - threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - $self->{output}->perfdata_add(label => 'channels', - value => $value, - warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), - critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), - min => 0); - - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Current active calls: %s", $value) - ); - - $self->{output}->display(); - $self->{output}->exit(); -} - -1; - -__END__ - -=head1 MODE - -Check system uptime. - -=over 8 - -=item B<--warning> - -Threshold warning. - -=item B<--critical> - -Threshold critical. - -=item B<--force-oid> - -Can choose your oid (numeric format only). - -=back - -=cut \ No newline at end of file diff --git a/apps/voip/asterisk/snmp/mode/activecalls.pm b/apps/voip/asterisk/snmp/mode/activecalls.pm index 645e0cd73..4c91cdda0 100644 --- a/apps/voip/asterisk/snmp/mode/activecalls.pm +++ b/apps/voip/asterisk/snmp/mode/activecalls.pm @@ -43,9 +43,7 @@ use centreon::plugins::statefile; my $oid_astBase = '.1.3.6.1.4.1.22736'; my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0'; -my $oid_astChanName = $oid_astBase.'.1.5.2.1.2'; # need an index at the end -my $oid_astChanIndex = $oid_astBase.'.1.5.2.1.1'; # need an index at the end -my $oid_astNumChannels = $oid_astBase.'.1.5.1.0'; +#my $oid_AsteriskConfigCallsProcessed = $oid_AsteriskBase.'.1.2.6.0'; sub new { my ($class, %options) = @_; @@ -55,12 +53,9 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning:s" => { name => 'warning', }, - "critical:s" => { name => 'critical', }, - "warnontrunk:s" => { name => 'warnontrunk', }, - "critontrunk:s" => { name => 'critontrunk', }, + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, "force-oid:s" => { name => 'force_oid', }, - "trunklist:s" => { name => 'trunklist', }, }); $self->{statefile_value} = centreon::plugins::statefile->new(%options); return $self; @@ -78,14 +73,6 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); $self->{output}->option_exit(); } - if (($self->{perfdata}->threshold_validate(label => 'warnontrunk', value => $self->{option_results}->{warnontrunk})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warnontrunk} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critontrunk', value => $self->{option_results}->{critontrunk})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critontrunk} . "'."); - $self->{output}->option_exit(); - } $self->{statefile_value}->check_options(%options); } @@ -96,59 +83,26 @@ sub run { $self->{snmp} = $options{snmp}; my ($result, $value); - my @callsbytrunk; - # explode trunk list - my @trunklist = split(';',$self->{option_results}->{trunklist}); - foreach my $trunk (@trunklist) - { - push @callsbytrunk , { trunk => $trunk, num => 0}; - } - # get chanName and sum calls for each - $result = $self->{snmp}->get_leef(oids => [ $oid_astNumChannels ], nothing_quit => 1); - my $astNumChannels = $result->{$oid_astNumChannels}; - foreach my $i (1..$astNumChannels) { - $result = $self->{snmp}->get_leef(oids => [ $oid_astChanName.'.'.$i ], nothing_quit => 1); - $value = $result->{$oid_astChanName.'.'.$i}; - $value =~ /^(.*)\/(.*)-.*/; - my ($protocol, $trunkname) = ($1, $2); - foreach my $val (@callsbytrunk) - { - if ( $val->{trunk} eq $trunkname) - { - $val->{num}=$val->{num}+1; - } - } + if (defined($self->{option_results}->{force_oid})) { + $result = $self->{snmp}->get_leef(oids => [ $self->{option_results}->{force_oid} ], nothing_quit => 1); + $value = $result->{$self->{option_results}->{force_oid}}; + } else { + $result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1); + $value = $result->{$oid_astConfigCallsActive}; } - $result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1); - my $astConfigCallsActive = $result->{$oid_astConfigCallsActive}; - - # compute status based on total number of active calls - # ToDo: compute status based on each trunk .... - my $exit_code = $self->{perfdata}->threshold_check(value => $astConfigCallsActive, - threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); - - $self->{output}->output_add(severity => $exit_code, - short_msg => sprintf("Current active calls: %s", $astConfigCallsActive) - ); - - # Perfdata on all active calls + my $exit_code = $self->{perfdata}->threshold_check(value => $value, + threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); $self->{output}->perfdata_add(label => 'Calls', - value => $astConfigCallsActive, + value => $value, warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), min => 0); - # Perfdata on number of calls for each trunk - foreach $value (@callsbytrunk) - { - $self->{output}->perfdata_add(label => $value->{trunk}, - value => $value->{num}, -# warning => $self->{perfdata}->get_perfdata_for_output(label => 'warnontrunk'), -# critical => $self->{perfdata}->get_perfdata_for_output(label => 'critontrunk'), - min => 0); - } + $self->{output}->output_add(severity => $exit_code, + short_msg => sprintf("Current active calls: %s", $value) + ); $self->{output}->display(); $self->{output}->exit(); @@ -160,34 +114,22 @@ __END__ =head1 MODE -Check number of active calls (total and by trunk) +Check system uptime. =over 8 =item B<--warning> -Threshold warning for total number of calls. +Threshold warning. =item B<--critical> -Threshold critical for total number of calls. - -=item B<--warnontrunk> - -Threshold warning for trunks. - -=item B<--critontrunk> - -Threshold critical for trunks. +Threshold critical. =item B<--force-oid> Can choose your oid (numeric format only). -=item B<--trunklist> - -List of outgoing trunks - =back =cut \ No newline at end of file diff --git a/apps/voip/asterisk/snmp/mode/externalcalls.pm b/apps/voip/asterisk/snmp/mode/externalcalls.pm new file mode 100644 index 000000000..0331f46d2 --- /dev/null +++ b/apps/voip/asterisk/snmp/mode/externalcalls.pm @@ -0,0 +1,239 @@ +################################################################################ +# 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 : Quentin Garnier +# +#################################################################################### + +package apps::voip::asterisk::snmp::mode::externalcalls; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::statefile; + +my $oid_astBase = '.1.3.6.1.4.1.22736'; +my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0'; +my $oid_astChanName = $oid_astBase.'.1.5.2.1.2'; # need an index at the end +my $oid_astChanIndex = $oid_astBase.'.1.5.2.1.1'; # need an index at the end +my $oid_astNumChannels = $oid_astBase.'.1.5.1.0'; + +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 => + { + "warning:s" => { name => 'warning', }, + "critical:s" => { name => 'critical', }, + "warnontrunk:s" => { name => 'warnontrunk', }, + "critontrunk:s" => { name => 'critontrunk', }, + "force-oid:s" => { name => 'force_oid', }, + "trunkusernamelist:s" => { name => 'trunkusernamelist', }, + "filter-name" => { name => 'filter-name' }, + }); + $self->{statefile_value} = centreon::plugins::statefile->new(%options); + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); + + if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'warnontrunk', value => $self->{option_results}->{warnontrunk})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warnontrunk} . "'."); + $self->{output}->option_exit(); + } + if (($self->{perfdata}->threshold_validate(label => 'critontrunk', value => $self->{option_results}->{critontrunk})) == 0) { + $self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critontrunk} . "'."); + $self->{output}->option_exit(); + } + + $self->{statefile_value}->check_options(%options); +} + +sub run { + my ($self, %options) = @_; + # $options{snmp} = snmp object + $self->{snmp} = $options{snmp}; + + my ($result, $value); + my (@callsbytrunk, @error_msg, @msg); + + # explode trunk list + my @trunkusernamelist = split(';',$self->{option_results}->{trunkusernamelist}); + foreach my $trunk (@trunkusernamelist) + { + if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' && + $trunk !~ /$self->{option_results}->{filter_name}/) { + $self->{output}->output_add(long_msg => "Skipping trunk '" . $trunk . "': no matching filter name"); + next; + } + push @callsbytrunk , { trunk => $trunk, num => 0}; + } + # get chanName and sum calls for each + $result = $self->{snmp}->get_leef(oids => [ $oid_astNumChannels ], nothing_quit => 1); + my $astNumChannels = $result->{$oid_astNumChannels}; + my $astConfigCallsActive = 0; + foreach my $i (1..$astNumChannels) { + $result = $self->{snmp}->get_leef(oids => [ $oid_astChanName.'.'.$i ], nothing_quit => 1); + $value = $result->{$oid_astChanName.'.'.$i}; + $value =~ /^(.*)\/(.*)-.*/; + my ($protocol, $trunkname) = ($1, $2); + foreach my $val (@callsbytrunk) + { + if ( $val->{trunk} eq $trunkname ) + { + $val->{num} = $val->{num}+1; + $astConfigCallsActive = $astConfigCallsActive+1; + } + } + } + + #$result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1); + #my $astConfigCallsActive = $result->{$oid_astConfigCallsActive}; + + # compute status based on total number of active calls + my $exit_code = $self->{perfdata}->threshold_check(value => $astConfigCallsActive, + threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); + push @msg, {msg => sprintf("Current external calls: %s", $astConfigCallsActive)}; + + # Perfdata on all active calls + $self->{output}->perfdata_add(label => 'Total calls', + value => $astConfigCallsActive, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'), + min => 0); + + # Perfdata on number of calls for each trunk + my ($temp_exit, $exit_msg); + my (@trunk_msg, @out_msg); + my $trunk_exit_code = 'ok'; + foreach $value (@callsbytrunk) + { + $temp_exit = $self->{perfdata}->threshold_check(value => $value->{num}, + threshold => [ { label => 'critontrunk', exit_litteral => 'critical' }, { label => 'warnontrunk', exit_litteral => 'warning' } ]); + $self->{output}->perfdata_add(label => $value->{trunk}, + value => $value->{num}, + warning => $self->{perfdata}->get_perfdata_for_output(label => 'warnontrunk'), + critical => $self->{perfdata}->get_perfdata_for_output(label => 'critontrunk'), + min => 0); + $self->{output}->output_add(long_msg => sprintf("%s : %s", $value->{trunk}, $value->{num})); + + $trunk_exit_code = $self->{output}->get_most_critical(status => [ $temp_exit, $trunk_exit_code ]); + # create msg for most critical data .... + if ($self->{output}->is_status(value => $temp_exit, compare => $trunk_exit_code, litteral => 1)) + { + push @trunk_msg, {msg => sprintf("'%s': %s", $value->{trunk}, $value->{num})}; + } + } + if (!$self->{output}->is_status(value => $exit_code, compare => 'ok', litteral => 1) && !$self->{output}->is_status(value => $trunk_exit_code, compare => 'ok', litteral => 1)) + { + unshift @trunk_msg, @msg; + $exit_code = $self->{output}->get_most_critical(status => [ $exit_code, $trunk_exit_code ]); + } + if (!$self->{output}->is_status(value => $trunk_exit_code, compare => 'ok', litteral => 1)) + { + @out_msg=@trunk_msg; + $exit_code = $trunk_exit_code ; + } + else + { + push @out_msg, @msg; + } + + $exit_msg = ''; + my $separator = ''; + foreach my $out (@out_msg) + { + $exit_msg .= $separator.$out->{msg}; + $separator = ', '; + } + $self->{output}->output_add(severity => $exit_code, + short_msg => $exit_msg + ); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Check number of active calls (total and by trunk) + +=over 8 + +=item B<--warning> + +Threshold warning for total number of calls. + +=item B<--critical> + +Threshold critical for total number of calls. + +=item B<--warnontrunk> + +Threshold warning for trunks. + +=item B<--critontrunk> + +Threshold critical for trunks. + +=item B<--force-oid> + +Can choose your oid (numeric format only). + +=item B<--trunkusernamelist> + +List of outgoing trunks' username. + +=item B<--filter-name> + +Filter on trunkname (regexp can be used). + +=back + +=cut \ No newline at end of file diff --git a/apps/voip/asterisk/snmp/plugin.pm b/apps/voip/asterisk/snmp/plugin.pm index fec52d97c..82afda1c5 100644 --- a/apps/voip/asterisk/snmp/plugin.pm +++ b/apps/voip/asterisk/snmp/plugin.pm @@ -50,6 +50,7 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( 'activecalls' => 'apps::voip::asterisk::snmp::mode::activecalls', + 'externalcalls' => 'apps::voip::asterisk::snmp::mode::externalcalls', ); return $self; From a20376e2f27484f26ac9470ae76c241e8026ac41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Sabati=C3=A9?= Date: Tue, 13 Jan 2015 17:25:54 +0100 Subject: [PATCH 5/5] asterisk: doc into plugin --- apps/voip/asterisk/ami/mode/iax/showpeers.pm | 16 ++++++++++++++++ apps/voip/asterisk/ami/mode/sip/showpeers.pm | 18 +++++++++++++++++- apps/voip/asterisk/snmp/mode/activecalls.pm | 2 +- apps/voip/asterisk/snmp/mode/externalcalls.pm | 8 ++++---- apps/voip/asterisk/snmp/plugin.pm | 1 - 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/apps/voip/asterisk/ami/mode/iax/showpeers.pm b/apps/voip/asterisk/ami/mode/iax/showpeers.pm index 286614139..5ea0fe5d5 100644 --- a/apps/voip/asterisk/ami/mode/iax/showpeers.pm +++ b/apps/voip/asterisk/ami/mode/iax/showpeers.pm @@ -144,10 +144,26 @@ List partitions. Hostname to query. +=item B<--port> + +port to connect. + +=item B<--username> + +username for conection. + +=item B<--password> + +password for conection. + =item B<--filter-name> Filter on trunkname (regexp can be used). +=item B<--timeout> + +connection timeout. + =back =cut diff --git a/apps/voip/asterisk/ami/mode/sip/showpeers.pm b/apps/voip/asterisk/ami/mode/sip/showpeers.pm index e38b9d3e1..1185517c2 100644 --- a/apps/voip/asterisk/ami/mode/sip/showpeers.pm +++ b/apps/voip/asterisk/ami/mode/sip/showpeers.pm @@ -142,12 +142,28 @@ List partitions. =item B<--hostname> -Hostname to query (need --remote). +Hostname to query. + +=item B<--port> + +port to connect. + +=item B<--username> + +username for conection. + +=item B<--password> + +password for conection. =item B<--filter-name> Filter on trunkname (regexp can be used). +=item B<--timeout> + +connection timeout. + =back =cut diff --git a/apps/voip/asterisk/snmp/mode/activecalls.pm b/apps/voip/asterisk/snmp/mode/activecalls.pm index 4c91cdda0..1dc4b7dc2 100644 --- a/apps/voip/asterisk/snmp/mode/activecalls.pm +++ b/apps/voip/asterisk/snmp/mode/activecalls.pm @@ -114,7 +114,7 @@ __END__ =head1 MODE -Check system uptime. +Check number of active calls. =over 8 diff --git a/apps/voip/asterisk/snmp/mode/externalcalls.pm b/apps/voip/asterisk/snmp/mode/externalcalls.pm index 0331f46d2..a07356400 100644 --- a/apps/voip/asterisk/snmp/mode/externalcalls.pm +++ b/apps/voip/asterisk/snmp/mode/externalcalls.pm @@ -202,17 +202,17 @@ __END__ =head1 MODE -Check number of active calls (total and by trunk) +Check number of external calls (total and by trunk) =over 8 =item B<--warning> -Threshold warning for total number of calls. +Threshold warning for total number of external calls. =item B<--critical> -Threshold critical for total number of calls. +Threshold critical for total number of external calls. =item B<--warnontrunk> @@ -232,7 +232,7 @@ List of outgoing trunks' username. =item B<--filter-name> -Filter on trunkname (regexp can be used). +Filter on trunk's username (regexp can be used). =back diff --git a/apps/voip/asterisk/snmp/plugin.pm b/apps/voip/asterisk/snmp/plugin.pm index 82afda1c5..f23803904 100644 --- a/apps/voip/asterisk/snmp/plugin.pm +++ b/apps/voip/asterisk/snmp/plugin.pm @@ -37,7 +37,6 @@ package apps::voip::asterisk::snmp::plugin; use strict; use warnings; -#use base qw(centreon::plugins::script_simple); use base qw(centreon::plugins::script_snmp); sub new {