Merge pull request #1579 from CPbN/3cx

3CX update
This commit is contained in:
qgarnier 2019-07-08 11:38:58 +02:00 committed by GitHub
commit 79b8413b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 22 deletions

View File

@ -194,9 +194,13 @@ sub request_api {
warning_status => '', unknown_status => '', critical_status => '%{http_code} < 200 or %{http_code} >= 300' warning_status => '', unknown_status => '', critical_status => '%{http_code} < 200 or %{http_code} >= 300'
); );
# Some content may be strangely returned, for example : "[{\"Category\":\"provider\",\"Count\":1}]" # Some content may be strangely returned, for example :
# 3CX < 16.0.2.910 : "[{\"Category\":\"provider\",\"Count\":1}]"
# 3CX >= 16.0.2.910 : {"tcxUpdate":"[{\"Category\":\"provider\",\"Count\":5},{\"Category\":\"sp150\",\"Count\":1}]","perPage":"[]"}
if (defined($options{eval_content}) && $options{eval_content} == 1) { if (defined($options{eval_content}) && $options{eval_content} == 1) {
$content = eval "$content"; if (my $evcontent = eval "$content") {
$content = $evcontent;
}
} }
my $decoded; my $decoded;
@ -249,6 +253,13 @@ sub internal_update_checker {
my ($self, %options) = @_; my ($self, %options) = @_;
my $status = $self->request_api(method => 'GET', url_path =>'/api/UpdateChecker/GetFromParams', eval_content => 1); my $status = $self->request_api(method => 'GET', url_path =>'/api/UpdateChecker/GetFromParams', eval_content => 1);
if (ref($status) eq 'HASH') {
$status = $status->{tcxUpdate};
if (ref($status) ne 'ARRAY') {
# See above note about strange content
$status = JSON::XS->new->utf8->decode($status);
}
}
return $status; return $status;
} }

View File

@ -29,15 +29,19 @@ use centreon::plugins::templates::catalog_functions qw(catalog_status_threshold)
sub custom_status_output { sub custom_status_output {
my ($self, %options) = @_; my ($self, %options) = @_;
my $msg = 'health : ' . $self->{result_values}->{health}; my $msg = '';
if ($self->{result_values}->{service} !~ /^Has[A-Z]/) {
$msg .= 'error ';
}
$msg .= ': ' . $self->{result_values}->{error};
return $msg; return $msg;
} }
sub custom_status_calc { sub custom_status_calc {
my ($self, %options) = @_; my ($self, %options) = @_;
$self->{result_values}->{health} = $options{new_datas}->{$self->{instance} . '_health'}; $self->{result_values}->{error} = $options{new_datas}->{$self->{instance} . '_error'};
$self->{result_values}->{display} = $options{new_datas}->{$self->{instance} . '_display'}; $self->{result_values}->{service} = $options{new_datas}->{$self->{instance} . '_service'};
return 0; return 0;
} }
@ -72,7 +76,7 @@ sub set_counters {
$self->{maps_counters}->{service} = [ $self->{maps_counters}->{service} = [
{ label => 'status', threshold => 0, set => { { label => 'status', threshold => 0, set => {
key_values => [ { name => 'health' }, { name => 'display' } ], key_values => [ { name => 'error' }, { name => 'service' } ],
closure_custom_calc => $self->can('custom_status_calc'), 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; },
@ -85,7 +89,7 @@ sub set_counters {
sub prefix_service_output { sub prefix_service_output {
my ($self, %options) = @_; my ($self, %options) = @_;
return "Service '" . $options{instance_value}->{display} . "' "; return "3CX '" . $options{instance_value}->{service} ."' ";
} }
sub new { sub new {
@ -93,10 +97,11 @@ sub new {
my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1); my $self = $class->SUPER::new(package => __PACKAGE__, %options, force_new_perfdata => 1);
bless $self, $class; bless $self, $class;
$self->{version} = '1.0';
$options{options}->add_options(arguments => { $options{options}->add_options(arguments => {
"unknown-status:s" => { name => 'unknown_status', default => '' }, "unknown-status:s" => { name => 'unknown_status', default => '' },
"warning-status:s" => { name => 'warning_status', default => '' }, "warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{health} =~ /false/' }, "critical-status:s" => { name => 'critical_status', default => '%{error} =~ /true/' },
}); });
return $self; return $self;
@ -122,27 +127,27 @@ sub manage_selection {
foreach my $item (keys %$single) { foreach my $item (keys %$single) {
# As of 3CX 15.5 / 16, we have Firewall, Phones, Trunks # As of 3CX 15.5 / 16, we have Firewall, Phones, Trunks
$self->{service}->{$item} = { $self->{service}->{$item} = {
display => $item, service => $item,
health => $single->{$item} ? 'true' : 'false', error => $single->{$item} ? 'false' : 'true',
}; };
} }
# As per 3CX support, $single->{Trunks} does not trigger if TrunksRegistered != TrunksTotal, # As per 3CX support, $single->{Trunks} does not trigger if TrunksRegistered != TrunksTotal,
# but only if "trunk is unsupported", so let's workaround # but only if "trunk is unsupported", so let's workaround
$self->{service}->{HasUnregisteredTrunks} = { $self->{service}->{HasUnregisteredTrunks} = {
display => 'HasUnregisteredTrunks', service => 'HasUnregisteredTrunks',
health => ($system->{TrunksRegistered} < $system->{TrunksTotal}) ? 'false' : 'true', error => ($system->{TrunksRegistered} < $system->{TrunksTotal}) ? 'true' : 'false',
}; };
$self->{service}->{HasNotRunningServices} = { $self->{service}->{HasNotRunningServices} = {
display => 'HasNotRunningServices', service => 'HasNotRunningServices',
health => $system->{HasNotRunningServices} ? 'false' : 'true', error => $system->{HasNotRunningServices} ? 'true' : 'false',
}; };
$self->{service}->{HasUnregisteredSystemExtensions} = { $self->{service}->{HasUnregisteredSystemExtensions} = {
display => 'HasUnregisteredSystemExtensions', service => 'HasUnregisteredSystemExtensions',
health => $system->{HasUnregisteredSystemExtensions} ? 'false' : 'true', error => $system->{HasUnregisteredSystemExtensions} ? 'true' : 'false',
}; };
$self->{service}->{HasUpdatesAvailable} = { $self->{service}->{HasUpdatesAvailable} = {
display => 'HasUpdatesAvailable', service => 'HasUpdatesAvailable',
health => scalar(@$update) ? 'false' : 'true', error => scalar(@$update) ? 'true' : 'false',
}; };
$self->{global} = { $self->{global} = {
@ -164,17 +169,17 @@ Check system health
=item B<--unknown-status> =item B<--unknown-status>
Set unknown threshold for status. Set unknown threshold for status.
Can used special variables like: %{health}, %{display} Can used special variables like: %{error}, %{service}
=item B<--warning-status> =item B<--warning-status>
Set warning threshold for status. Set warning threshold for status.
Can used special variables like: %{health}, %{display} Can used special variables like: %{error}, %{service}
=item B<--critical-status> =item B<--critical-status>
Set critical threshold for status (Default: '%{health} =~ /false/'). Set critical threshold for status (Default: '%{error} =~ /false/').
Can used special variables like: %{health}, %{display} Can used special variables like: %{error}, %{service}
=item B<--warning-*> B<--critical-*> =item B<--warning-*> B<--critical-*>