merge total of calls and calls by trunk
This commit is contained in:
parent
005be06ecc
commit
5d8aea03b2
|
@ -33,7 +33,7 @@
|
||||||
#
|
#
|
||||||
####################################################################################
|
####################################################################################
|
||||||
|
|
||||||
package apps::voip::asterisk::snmp::mode::activecallsbytrunk;
|
package apps::voip::asterisk::snmp::mode::activecalls;
|
||||||
|
|
||||||
use base qw(centreon::plugins::mode);
|
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_astBase = '.1.3.6.1.4.1.22736';
|
||||||
my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0';
|
my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0';
|
||||||
#my $oid_AsteriskConfigCallsProcessed = $oid_AsteriskBase.'.1.2.6.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 {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
|
@ -56,10 +53,9 @@ sub new {
|
||||||
$self->{version} = '1.0';
|
$self->{version} = '1.0';
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments =>
|
||||||
{
|
{
|
||||||
"warning:s" => { name => 'warning', },
|
"warning:s" => { name => 'warning', },
|
||||||
"critical:s" => { name => 'critical', },
|
"critical:s" => { name => 'critical', },
|
||||||
"force-oid:s" => { name => 'force_oid', },
|
"force-oid:s" => { name => 'force_oid', },
|
||||||
"trunklist:s" => { name => 'trunklist', },
|
|
||||||
});
|
});
|
||||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||||
return $self;
|
return $self;
|
||||||
|
@ -87,54 +83,25 @@ sub run {
|
||||||
$self->{snmp} = $options{snmp};
|
$self->{snmp} = $options{snmp};
|
||||||
|
|
||||||
my ($result, $value);
|
my ($result, $value);
|
||||||
my @callsbytrunk;
|
|
||||||
|
|
||||||
# explode trunk list
|
if (defined($self->{option_results}->{force_oid})) {
|
||||||
my @trunklist = split(';',$self->{option_results}->{trunklist});
|
$result = $self->{snmp}->get_leef(oids => [ $self->{option_results}->{force_oid} ], nothing_quit => 1);
|
||||||
foreach my $trunk (@trunklist)
|
$value = $result->{$self->{option_results}->{force_oid}};
|
||||||
{
|
} else {
|
||||||
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);
|
$result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1);
|
||||||
my $astConfigCallsActive = $result->{$oid_astConfigCallsActive};
|
$value = $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)
|
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}->display();
|
|
@ -43,7 +43,9 @@ use centreon::plugins::statefile;
|
||||||
|
|
||||||
my $oid_astBase = '.1.3.6.1.4.1.22736';
|
my $oid_astBase = '.1.3.6.1.4.1.22736';
|
||||||
my $oid_astConfigCallsActive = $oid_astBase.'.1.2.5.0';
|
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 {
|
sub new {
|
||||||
my ($class, %options) = @_;
|
my ($class, %options) = @_;
|
||||||
|
@ -53,9 +55,12 @@ sub new {
|
||||||
$self->{version} = '1.0';
|
$self->{version} = '1.0';
|
||||||
$options{options}->add_options(arguments =>
|
$options{options}->add_options(arguments =>
|
||||||
{
|
{
|
||||||
"warning:s" => { name => 'warning', },
|
"warning:s" => { name => 'warning', },
|
||||||
"critical:s" => { name => 'critical', },
|
"critical:s" => { name => 'critical', },
|
||||||
|
"warnontrunk:s" => { name => 'warnontrunk', },
|
||||||
|
"critontrunk:s" => { name => 'critontrunk', },
|
||||||
"force-oid:s" => { name => 'force_oid', },
|
"force-oid:s" => { name => 'force_oid', },
|
||||||
|
"trunklist:s" => { name => 'trunklist', },
|
||||||
});
|
});
|
||||||
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
|
||||||
return $self;
|
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}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
|
||||||
$self->{output}->option_exit();
|
$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);
|
$self->{statefile_value}->check_options(%options);
|
||||||
}
|
}
|
||||||
|
@ -83,26 +96,59 @@ sub run {
|
||||||
$self->{snmp} = $options{snmp};
|
$self->{snmp} = $options{snmp};
|
||||||
|
|
||||||
my ($result, $value);
|
my ($result, $value);
|
||||||
|
my @callsbytrunk;
|
||||||
|
|
||||||
if (defined($self->{option_results}->{force_oid})) {
|
# explode trunk list
|
||||||
$result = $self->{snmp}->get_leef(oids => [ $self->{option_results}->{force_oid} ], nothing_quit => 1);
|
my @trunklist = split(';',$self->{option_results}->{trunklist});
|
||||||
$value = $result->{$self->{option_results}->{force_oid}};
|
foreach my $trunk (@trunklist)
|
||||||
} else {
|
{
|
||||||
$result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1);
|
push @callsbytrunk , { trunk => $trunk, num => 0};
|
||||||
$value = $result->{$oid_astConfigCallsActive};
|
}
|
||||||
|
# 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,
|
$result = $self->{snmp}->get_leef(oids => [ $oid_astConfigCallsActive ], nothing_quit => 1);
|
||||||
threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
|
my $astConfigCallsActive = $result->{$oid_astConfigCallsActive};
|
||||||
$self->{output}->perfdata_add(label => 'channels',
|
|
||||||
value => $value,
|
# 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'),
|
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
|
||||||
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'),
|
||||||
min => 0);
|
min => 0);
|
||||||
|
|
||||||
$self->{output}->output_add(severity => $exit_code,
|
# Perfdata on number of calls for each trunk
|
||||||
short_msg => sprintf("Current active calls: %s", $value)
|
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}->display();
|
||||||
$self->{output}->exit();
|
$self->{output}->exit();
|
||||||
|
@ -114,22 +160,34 @@ __END__
|
||||||
|
|
||||||
=head1 MODE
|
=head1 MODE
|
||||||
|
|
||||||
Check system uptime.
|
Check number of active calls (total and by trunk)
|
||||||
|
|
||||||
=over 8
|
=over 8
|
||||||
|
|
||||||
=item B<--warning>
|
=item B<--warning>
|
||||||
|
|
||||||
Threshold warning.
|
Threshold warning for total number of calls.
|
||||||
|
|
||||||
=item B<--critical>
|
=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>
|
=item B<--force-oid>
|
||||||
|
|
||||||
Can choose your oid (numeric format only).
|
Can choose your oid (numeric format only).
|
||||||
|
|
||||||
|
=item B<--trunklist>
|
||||||
|
|
||||||
|
List of outgoing trunks
|
||||||
|
|
||||||
=back
|
=back
|
||||||
|
|
||||||
=cut
|
=cut
|
|
@ -50,7 +50,6 @@ sub new {
|
||||||
$self->{version} = '0.1';
|
$self->{version} = '0.1';
|
||||||
%{$self->{modes}} = (
|
%{$self->{modes}} = (
|
||||||
'activecalls' => 'apps::voip::asterisk::snmp::mode::activecalls',
|
'activecalls' => 'apps::voip::asterisk::snmp::mode::activecalls',
|
||||||
'activecallsbytrunk' => 'apps::voip::asterisk::snmp::mode::activecallsbytrunk',
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return $self;
|
return $self;
|
||||||
|
|
Loading…
Reference in New Issue