enhance cisco phone usage

This commit is contained in:
garnier-quentin 2020-09-22 13:32:57 +02:00
parent de80552e36
commit e1146418a1
1 changed files with 63 additions and 58 deletions

View File

@ -24,22 +24,26 @@ use base qw(centreon::plugins::templates::counter);
use strict; use strict;
use warnings; use warnings;
use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold); use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold_ng);
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'status : ' . $self->{result_values}->{status}; my $msg = 'status : ' . $self->{result_values}->{status};
$msg .= ' [Description: ' . $self->{result_values}->{description} . ']' if (defined($self->{result_values}->{description}) && $self->{result_values}->{description} ne ''); $msg .= ' [description: ' . $self->{result_values}->{description} . ']' if (defined($self->{result_values}->{description}) && $self->{result_values}->{description} ne '');
return $msg; return $msg;
} }
sub custom_status_calc { sub prefix_phone_output {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{status} = $options{new_datas}->{$self->{instance} . '_ccmPhoneStatus'}; return "Phone '" . $options{instance_value}->{name} . "' ";
$self->{result_values}->{description} = $options{new_datas}->{$self->{instance} . 'ccmPhoneDescription'}; }
return 0;
sub prefix_global_output {
my ($self, %options) = @_;
return "Total ";
} }
sub set_counters { sub set_counters {
@ -47,26 +51,25 @@ sub set_counters {
$self->{maps_counters_type} = [ $self->{maps_counters_type} = [
{ name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' }, { name => 'global', type => 0, cb_prefix_output => 'prefix_global_output' },
{ name => 'phone', type => 1, cb_prefix_output => 'prefix_phone_output', message_multiple => 'All phones are ok' }, { name => 'phone', type => 1, cb_prefix_output => 'prefix_phone_output', message_multiple => 'All phones are ok' }
]; ];
$self->{maps_counters}->{phone} = [ $self->{maps_counters}->{phone} = [
{ label => 'status', threshold => 0, set => { { label => 'status', type => 2, critical_default => '%{status} !~ /^registered/', set => {
key_values => [ { name => 'ccmPhoneDescription' }, { name => 'ccmPhoneStatus' }, { name => 'ccmPhoneName' } ], key_values => [ { name => 'status' }, { name => 'status' }, { name => 'name' } ],
closure_custom_calc => $self->can('custom_status_calc'),
closure_custom_output => $self->can('custom_status_output'), closure_custom_output => $self->can('custom_status_output'),
closure_custom_perfdata => sub { return 0; }, closure_custom_perfdata => sub { return 0; },
closure_custom_threshold_check => \&catalog_status_threshold, closure_custom_threshold_check => \&catalog_status_threshold_ng
}
} }
},
]; ];
my @map = ( my @map = (
['total-registered', 'Registered : %s', 'registered'], ['total-registered', 'registered: %s', 'registered'],
['total-unregistered', 'Unregistered : %s', 'unregistered'], ['total-unregistered', 'unregistered: %s', 'unregistered'],
['total-rejected', 'Rejected : %s', 'rejected'], ['total-rejected', 'rejected: %s', 'rejected'],
['total-unknown', 'Unknown : %s', 'unknown'], ['total-unknown', 'unknown: %s', 'unknown'],
['total-partiallyregistered', 'Partially Registered : %s', 'partiallyregistered'], ['total-partiallyregistered', 'partially registered: %s', 'partiallyregistered']
); );
$self->{maps_counters}->{global} = []; $self->{maps_counters}->{global} = [];
@ -77,10 +80,10 @@ sub set_counters {
key_values => [ { name => $_->[2] } ], key_values => [ { name => $_->[2] } ],
output_template => $_->[1], output_template => $_->[1],
perfdatas => [ perfdatas => [
{ label => $label, value => $_->[2] , template => '%s', min => 0 }, { label => $label, template => '%s', min => 0 }
], ]
} }
}, };
} }
} }
@ -90,41 +93,22 @@ sub new {
bless $self, $class; bless $self, $class;
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
'warning-status:s' => { name => 'warning_status', default => '' }, 'filter-name:s' => { name => 'filter_name' },
'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /^registered/' }, 'filter-description:s' => { name => 'filter_description' }
}); });
return $self; return $self;
} }
sub check_options { my $mapping_status = {
my ($self, %options) = @_;
$self->SUPER::check_options(%options);
$self->change_macros(macros => ['warning_status', 'critical_status']);
}
sub prefix_phone_output {
my ($self, %options) = @_;
return "Phone '" . $options{instance_value}->{ccmPhoneName} . "' ";
}
sub prefix_global_output {
my ($self, %options) = @_;
return "Total ";
}
my %mapping_status = (
1 => 'unknown', 2 => 'registered', 3 => 'unregistered', 1 => 'unknown', 2 => 'registered', 3 => 'unregistered',
4 => 'rejected', 5 => 'partiallyregistered', 4 => 'rejected', 5 => 'partiallyregistered'
); };
my $mapping = { my $mapping = {
ccmPhoneDescription => { oid => '.1.3.6.1.4.1.9.9.156.1.2.1.1.4' }, description => { oid => '.1.3.6.1.4.1.9.9.156.1.2.1.1.4' }, # ccmPhoneDescription
ccmPhoneStatus => { oid => '.1.3.6.1.4.1.9.9.156.1.2.1.1.7', map => \%mapping_status }, status => { oid => '.1.3.6.1.4.1.9.9.156.1.2.1.1.7', map => $mapping_status }, # ccmPhoneStatus
ccmPhoneName => { oid => '.1.3.6.1.4.1.9.9.156.1.2.1.1.20' }, name => { oid => '.1.3.6.1.4.1.9.9.156.1.2.1.1.20' } # ccmPhoneName
}; };
sub manage_selection { sub manage_selection {
@ -132,9 +116,9 @@ sub manage_selection {
my $snmp_result = $options{snmp}->get_multiple_table( my $snmp_result = $options{snmp}->get_multiple_table(
oids => [ oids => [
{ oid => $mapping->{ccmPhoneDescription}->{oid} }, { oid => $mapping->{description}->{oid} },
{ oid => $mapping->{ccmPhoneStatus}->{oid} }, { oid => $mapping->{status}->{oid} },
{ oid => $mapping->{ccmPhoneName}->{oid} } { oid => $mapping->{name}->{oid} }
], ],
return_type => 1, return_type => 1,
nothing_quit => 1 nothing_quit => 1
@ -143,12 +127,25 @@ sub manage_selection {
$self->{phone} = {}; $self->{phone} = {};
$self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 }; $self->{global} = { unknown => 0, registered => 0, unregistered => 0, rejected => 0, partiallyregistered => 0 };
foreach my $oid (keys %$snmp_result) { foreach my $oid (keys %$snmp_result) {
next if ($oid !~ /^$mapping->{ccmPhoneStatus}->{oid}\.(.*)/); next if ($oid !~ /^$mapping->{status}->{oid}\.(.*)/);
my $instance = $1; my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance); my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);
$self->{phone}->{$instance} = { %$result }; if (defined($result->{name}) &&
$self->{global}->{$result->{ccmPhoneStatus}}++; defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&
$result->{name} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(long_msg => "skipping phone '" . $instance . "': no matching filter.", debug => 1);
next;
}
if (defined($result->{description}) &&
defined($self->{option_results}->{filter_description}) && $self->{option_results}->{filter_description} ne '' &&
$result->{description} !~ /$self->{option_results}->{filter_description}/) {
$self->{output}->output_add(long_msg => "skipping phone '" . $instance . "': no matching filter.", debug => 1);
next;
}
$self->{phone}->{$instance} = $result;
$self->{global}->{ $result->{status} }++;
} }
} }
@ -167,15 +164,23 @@ Check phone usage.
Only display some counters (regexp can be used). Only display some counters (regexp can be used).
Example: --filter-counters='status' Example: --filter-counters='status'
=item B<--filter-name>
Filter phone by name (can be a regexp).
=item B<--filter-description>
Filter phone by description (can be a regexp).
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status (Default: ''). Set warning threshold for status.
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}, %{description}
=item B<--critical-status> =item B<--critical-status>
Set critical threshold for status (Default: '%{status} !~ /^registered/'). Set critical threshold for status (Default: '%{status} !~ /^registered/').
Can used special variables like: %{status}, %{display} Can used special variables like: %{status}, %{name}, %{description}
=item B<--warning-*> B<--critical-*> =item B<--warning-*> B<--critical-*>