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;