3CX check for updates

This commit is contained in:
CPbN 2019-05-27 17:21:49 +02:00
parent 39b7cbabdc
commit c3d1373649
2 changed files with 31 additions and 4 deletions

View File

@ -194,6 +194,12 @@ sub request_api {
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}]"
if ($content =~ /^"(\[.*\])"$/) {
$content = $1;
$content =~ s/\\"/"/g;
}
my $decoded;
eval {
$decoded = JSON::XS->new->utf8->decode($content);
@ -240,6 +246,20 @@ sub api_system_status {
return $status;
}
sub internal_update_checker {
my ($self, %options) = @_;
my $status = $self->request_api(method => 'GET', url_path =>'/api/UpdateChecker/GetFromParams');
return $status;
}
sub api_update_checker {
my ($self, %options) = @_;
my $status = $self->internal_update_checker();
return $status;
}
1;
__END__

View File

@ -96,8 +96,8 @@ sub new {
$self->{version} = '1.0';
$options{options}->add_options(arguments => {
"unknown-status:s" => { name => 'unknown_status', default => '' },
"warning-status:s" => { name => 'warning_status', default => '' },
"critical-status:s" => { name => 'critical_status', default => '%{health} =~ /false/' },
"warning-status:s" => { name => 'warning_status', default => '%{display} =~ /HasUpdatesAvailable/ && %{health} =~ /true/' },
"critical-status:s" => { name => 'critical_status', default => '%{display} !~ /HasUpdatesAvailable/ && %{health} =~ /false/' },
});
return $self;
@ -117,6 +117,7 @@ sub manage_selection {
my $single = $options{custom}->api_single_status();
my $system = $options{custom}->api_system_status();
my $update = $options{custom}->api_update_checker();
$self->{service} = {};
foreach my $item (keys %$single) {
@ -134,6 +135,10 @@ sub manage_selection {
display => 'HasUnregisteredSystemExtensions',
health => $self->{system}->{HasUnregisteredSystemExtensions} ? 'false' : 'true',
};
$self->{service}->{HasUpdatesAvailable} = {
display => 'HasUpdatesAvailable',
health => scalar(@$update) ? 'true' : 'false',
};
$self->{global} = {
calls_active => $system->{CallsActive},
@ -158,12 +163,14 @@ Can used special variables like: %{health}, %{display}
=item B<--warning-status>
Set warning threshold for status.
Set warning threshold for status
(Default: '%{display} =~ /HasUpdatesAvailable/ && %{health} =~ /true/').
Can used special variables like: %{health}, %{display}
=item B<--critical-status>
Set critical threshold for status (Default: '%{health} =~ /false/').
Set critical threshold for status
(Default: '%{display} !~ /HasUpdatesAvailable/ && %{health} =~ /false/').
Can used special variables like: %{health}, %{display}
=item B<--warning-*> B<--critical-*>