del(kayako): remove plugin (#2779)

This commit is contained in:
qgarnier 2021-05-07 16:13:57 +02:00 committed by GitHub
parent 23fd642b39
commit 0351c979e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 0 additions and 1520 deletions

View File

@ -1,133 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::api::mode::listdepartment;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
my %handlers = (ALRM => {} );
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"timeout:s" => { name => 'timeout' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
});
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
my $salt = '';
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64($salt, $self->{option_results}->{kayako_secret_key});
$self->{option_results}->{url_path} .= "/Base/Department&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = $self->{http}->set_options(%{$self->{option_results}});
my $xp = XML::XPath->new($webcontent);
my $nodes = $xp->find('departments/department');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List department:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
List departments of kayako
=over 8
=item B<--hostname>
IP Addr/FQDN of the webserver host (required)
=item B<--port>
Port used by Apache
=item B<--proto>
Specify https if needed
=item B<--urlpath>
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
=item B<--timeout>
Threshold for HTTP timeout.
=item B<--kayako-api-key>
This is your unique API key.
=item B<--kayako-secret-key>
The secret key is used to sign all the requests dispatched to Kayako.
=back
=cut

View File

@ -1,133 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::api::mode::listpriority;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
my %handlers = (ALRM => {} );
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"timeout:s" => { name => 'timeout' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
});
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{kayako_secret_key});
$self->{option_results}->{url_path} .= "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('ticketpriorities/ticketpriority');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List priority:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
List departmentf of kayako
=over 8
=item B<--hostname>
IP Addr/FQDN of the webserver host (required)
=item B<--port>
Port used by Apache
=item B<--proto>
Specify https if needed
=item B<--urlpath>
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
=item B<--timeout>
Threshold for HTTP timeout.
=item B<--kayako-api-key>
This is your unique API key.
=item B<--kayako-secret-key>
The secret key is used to sign all the requests dispatched to Kayako.
=back
=cut

View File

@ -1,131 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::api::mode::liststaff;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"timeout:s" => { name => 'timeout' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
});
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$self->{option_results}->{url_path} .= "/Base/Staff&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('staffusers/staff');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./username', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List staff:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
List departmentf of kayako
=over 8
=item B<--hostname>
IP Addr/FQDN of the webserver host (required)
=item B<--port>
Port used by Apache
=item B<--proto>
Specify https if needed
=item B<--urlpath>
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
=item B<--timeout>
Threshold for HTTP timeout.
=item B<--kayako-api-key>
This is your unique API key.
=item B<--kayako-secret-key>
The secret key is used to sign all the requests dispatched to Kayako.
=back
=cut

View File

@ -1,131 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::api::mode::liststatus;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"timeout:s" => { name => 'timeout' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
});
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
my $salt;
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{'kayako_secret_key'});
$self->{option_results}->{'url_path'} .= "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=";
$self->{http}->set_options(%{$self->{option_results}});
}
sub run {
my ($self, %options) = @_;
my $webcontent = $self->{http}->request();
my $xp = XML::XPath->new($webcontent);
my $nodes = $xp->find('ticketstatuses/ticketstatus');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$self->{output}->output_add(long_msg => "'" . $trim_title . "' [id = " . $trim_id . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List status:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
List departmentf of kayako
=over 8
=item B<--hostname>
IP Addr/FQDN of the webserver host (required)
=item B<--port>
Port used by Apache
=item B<--proto>
Specify https if needed
=item B<--urlpath>
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
=item B<--timeout>
Threshold for HTTP timeout.
=item B<--kayako-api-key>
This is your unique API key.
=item B<--kayako-secret-key>
The secret key is used to sign all the requests dispatched to Kayako.
=back
=cut

View File

@ -1,396 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::api::mode::ticketcount;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::statefile;
use centreon::plugins::http;
use XML::XPath;
use Digest::SHA qw(hmac_sha256_base64);
use Time::Local;
my $url_original_path;
my $start = "";
my $end = "";
my $priority_filter;
my @priority_filters;
my $ticket_total = 0;
my %tickets;
my $label;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"hostname:s" => { name => 'hostname' },
"port:s" => { name => 'port' },
"proto:s" => { name => 'proto' },
"urlpath:s" => { name => 'url_path', default => '/api/index.php?' },
"timeout:s" => { name => 'timeout' },
"kayako-api-key:s" => { name => 'kayako_api_key' },
"kayako-secret-key:s" => { name => 'kayako_secret_key' },
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
"department-id:s" => { name => 'department_id' },
"staff-id:s" => { name => 'staff_id' },
"status-id:s" => { name => 'status_id' },
"priority-id:s" => { name => 'priority_id' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"start-date:s" => { name => 'start_date' },
"end-date:s" => { name => 'end_date' },
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
$self->{statefile_value} = centreon::plugins::statefile->new(%options);
$self->{http} = centreon::plugins::http->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (!defined($self->{option_results}->{kayako_api_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify an API key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{kayako_secret_key})) {
$self->{output}->add_option_msg(short_msg => "Please specify a secret key for Kayako.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{department_id})) {
$self->{output}->add_option_msg(short_msg => "Please specify at least one department ID.");
$self->{output}->option_exit();
}
if (!defined($self->{option_results}->{staff_id})) {
$self->{option_results}->{staff_id} = "-1";
}
if (!defined($self->{option_results}->{status_id})) {
$self->{option_results}->{status_id} = "-1";
}
if (defined($self->{option_results}->{priority_id})) {
@priority_filters = split(/,/, $self->{option_results}->{priority_id});
}
if (defined($self->{option_results}->{start_date})) {
if ($self->{option_results}->{start_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){
$self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY).");
$self->{output}->option_exit();
} else {
my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{start_date});
$start = $self->{option_results}->{start_date};
$self->{option_results}->{start_date} = timelocal(0,0,0,$mday,$mon-1,$year);
}
}
if (defined($self->{option_results}->{end_date})) {
if ($self->{option_results}->{end_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){
$self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY).");
$self->{output}->option_exit();
} else {
my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{end_date});
$end = $self->{option_results}->{end_date};
$self->{option_results}->{end_date} = timelocal(59,59,23,$mday,$mon-1,$year);
}
}
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
$self->{statefile_cache}->check_options(%options);
$self->{statefile_value}->check_options(%options);
$self->{http}->set_options(%{$self->{option_results}});
}
sub reload_cache {
my ($self) = @_;
my $datas = {};
$datas->{last_timestamp} = time();
my $salt = '';
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64 ($salt, $self->{option_results}->{kayako_secret_key});
my $webcontent = $self->{http}->request(url_path => $url_original_path . "/Base/Department&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=");
my $xp = XML::XPath->new($webcontent);
my $nodes = $xp->find('departments/department');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$datas->{"department_".$trim_id} = $self->{output}->decode($trim_title);
}
$webcontent = $self->{http}->request(url_path => $url_original_path . "/Tickets/TicketPriority&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=");
$xp = XML::XPath->new( $webcontent );
$nodes = $xp->find('ticketpriorities/ticketpriority');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$datas->{"priority_".$trim_id} = $self->{output}->decode($trim_title);
}
$webcontent = $self->{http}->request(url_path => $url_original_path . "/Base/Staff&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=");
$xp = XML::XPath->new( $webcontent );
$nodes = $xp->find('staffusers/staff');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./username', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$datas->{"staff_".$trim_id} = $self->{output}->decode($trim_title);
}
$webcontent = $self->{http}->request(url_path => $url_original_path . "/Tickets/TicketStatus&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=");
$xp = XML::XPath->new( $webcontent );
$nodes = $xp->find('ticketstatuses/ticketstatus');
foreach my $actionNode ($nodes->get_nodelist) {
my ($id) = $xp->find('./id', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($title) = $xp->find('./title', $actionNode)->get_nodelist;
my $trim_title = centreon::plugins::misc::trim($title->string_value);
$datas->{"status_".$trim_id} = $self->{output}->decode($trim_title);
}
$self->{statefile_cache}->write(data => $datas);
}
sub run {
my ($self, %options) = @_;
my $salt = '';
$salt .= int(rand(10)) for 1..10;
my $digest = hmac_sha256_base64($salt, $self->{option_results}->{kayako_secret_key});
$url_original_path = $self->{option_results}->{url_path};
my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_api_' . ($self->{option_results}->{hostname}) . '_kayako');
my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
if ($has_cache_file == 0 ||
!defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
$self->reload_cache();
$self->{statefile_cache}->read();
}
my $webcontent = $self->{http}->request(url_path => $url_original_path . "/Tickets/Ticket/ListAll/" . $self->{option_results}->{department_id} . "/" . $self->{option_results}->{status_id} . "/" . $self->{option_results}->{staff_id} . "/-1/-1/1420120620/-1/-1&apikey=" . $self->{option_results}->{kayako_api_key} . "&salt=" . $salt . "&signature=" . $digest . "=");
my $xp = XML::XPath->new( $webcontent );
my $nodes = $xp->find('tickets/ticket');
foreach my $actionNode ($nodes->get_nodelist) {
my $date_verif = 0;
my ($id) = $xp->find('./displayid', $actionNode)->get_nodelist;
my $trim_id = centreon::plugins::misc::trim($id->string_value);
my ($priorityid) = $xp->find('./priorityid', $actionNode)->get_nodelist;
my $trim_priorityid = centreon::plugins::misc::trim($priorityid->string_value);
my ($date) = $xp->find('./lastactivity', $actionNode)->get_nodelist;
my $trim_date = centreon::plugins::misc::trim($date->string_value);
if (defined($self->{option_results}->{start_date}) and (defined($self->{option_results}->{end_date}))) {
if ($trim_date > $self->{option_results}->{start_date} and $trim_date < $self->{option_results}->{end_date}) {
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
if ($priority_filter == $trim_priorityid){
$tickets{$priority_filter}++;
$ticket_total++;
}
}
} else {
$ticket_total++;
}
}
} elsif (defined($self->{option_results}->{start_date}) and (!defined($self->{option_results}->{end_date}))) {
if ($trim_date > $self->{option_results}->{start_date}) {
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
if ($priority_filter == $trim_priorityid){
$tickets{$priority_filter}++;
$ticket_total++;
}
}
} else {
$ticket_total++;
}
}
} elsif (!defined($self->{option_results}->{start_date}) and (defined($self->{option_results}->{end_date}))) {
if ($trim_date < $self->{option_results}->{end_date}) {
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
if ($priority_filter == $trim_priorityid){
$tickets{$priority_filter}++;
$ticket_total++;
}
}
} else {
$ticket_total++;
}
}
} else {
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
if ($priority_filter == $trim_priorityid){
$tickets{$priority_filter}++;
$ticket_total++;
}
}
} else {
$ticket_total++;
}
}
}
###########
# Manage Output
###########
my $exit = $self->{perfdata}->threshold_check(value => $ticket_total, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $staff = "";
my $ticket_status = "";
my $period = "";
if (defined($self->{option_results}->{staff_id}) && ($self->{option_results}->{staff_id} =~ m/^\d*$/)) {
$staff = " for staff '" . $self->{statefile_cache}->get(name => 'staff_'.$self->{option_results}->{staff_id}) ."'";
}
if (defined($self->{option_results}->{status_id}) && ($self->{option_results}->{status_id} =~ m/^\d*$/)) {
$ticket_status = " in status '" . $self->{statefile_cache}->get(name => 'status_'.$self->{option_results}->{status_id}) ."'";
}
if (defined($self->{option_results}->{start_date}) || defined($self->{option_results}->{end_date})){
$period = " -";
}
if (defined($self->{option_results}->{start_date})){
$start = " Start: " . $start;
}
if (defined($self->{option_results}->{end_date})){
$end = " End: " . $end;
}
if (defined($self->{option_results}->{priority_id})){
foreach $priority_filter (@priority_filters) {
$label = $self->{statefile_cache}->get(name => 'priority_'.$priority_filter);
$self->{output}->perfdata_add(label => $label, value => $tickets{$priority_filter},
min => 0, max => $ticket_total);
}
}
$self->{output}->perfdata_add(label => 'Total', value => $ticket_total,
warning => $self->{perfdata}->get_perfdata_for_output(label => 'warning'),
critical => $self->{perfdata}->get_perfdata_for_output(label => 'critical'));
$self->{output}->output_add(severity => $exit,
short_msg => sprintf("%s tickets%s%s%s%s%s", $ticket_total, $staff, $ticket_status, $period, $start, $end));
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Count tickets of kayako
=over 8
=item B<--hostname>
IP Addr/FQDN of the webserver host (required)
=item B<--port>
Port used by Apache
=item B<--proto>
Specify https if needed
=item B<--urlpath>
This is the URL you should dispatch all GET, POST, PUT & DELETE requests to (Default: '/api/index.php?')
=item B<--timeout>
Threshold for HTTP timeout.
=item B<--kayako-api-key>
This is your unique API key. (required)
=item B<--kayako-secret-key>
The secret key is used to sign all the requests dispatched to Kayako. (required)
=item B<--reload-cache-time>
Time in seconds before reloading cache file (default: 180).
=item B<--department-id>
Filter the tickets by the specified department id, you can specify multiple id's by separating the values using a comma. Example: 1,2,3 .
You must define at least one id. (required)
=item B<--priority-id>
Filter the tickets by the specified ticket priority id, you can specify multiple id's by separating the values using a comma. Example: 1,2,3 .
By default, all ticket priority are included.
=item B<--staff-id>
Filter the tickets by the specified owner staff id, you can specify multiple id's by separating the values using a comma. Example: 1,2,3 .
By default, all staff users are included.
=item B<--status-id>
Filter the tickets by the specified ticket status id, you can specify multiple id's by separating the values using a comma. Example: 1,2,3 .
By default, the filter is on unresolved ticket statuses.
=item B<--warning>
Threshold warning.
=item B<--critical>
Threshold critical.
=item B<--start-date>
Filter on last activity. For example: 21-03-2014
=item B<--end-date>
Filter on last activity. For example: 21-03-2014
=back
=cut

View File

@ -1,52 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::api::plugin;
use strict;
use warnings;
use base qw(centreon::plugins::script_simple);
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$self->{version} = '0.1';
%{$self->{modes}} = (
'list-department' => 'apps::kayako::api::mode::listdepartment',
'list-priority' => 'apps::kayako::api::mode::listpriority',
'list-staff' => 'apps::kayako::api::mode::liststaff',
'list-status' => 'apps::kayako::api::mode::liststatus',
'ticket-count' => 'apps::kayako::api::mode::ticketcount',
);
return $self;
}
1;
__END__
=head1 PLUGIN DESCRIPTION
Check Kayako with REST API.
=cut

View File

@ -1,68 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::sql::mode::listdepartment;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub run {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->{sql}->connect();
$self->{sql}->query(query => "SELECT departmentid, title FROM swdepartments");
while ((my $row = $self->{sql}->fetchrow_hashref())) {
$self->{output}->output_add(long_msg => "'" . $row->{title} . "' [id = " . $row->{departmentid} . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List departments:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
List departments of kayako
=back
=cut

View File

@ -1,68 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::sql::mode::listpriority;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub run {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->{sql}->connect();
$self->{sql}->query(query => "SELECT priorityid, title FROM swticketpriorities");
while ((my $row = $self->{sql}->fetchrow_hashref())) {
$self->{output}->output_add(long_msg => "'" . $row->{title} . "' [id = " . $row->{priorityid} . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List priorities:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
List priorities of kayako
=back
=cut

View File

@ -1,68 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::sql::mode::liststaff;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub run {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->{sql}->connect();
$self->{sql}->query(query => "SELECT staffid, username FROM swstaff");
while ((my $row = $self->{sql}->fetchrow_hashref())) {
$self->{output}->output_add(long_msg => "'" . $row->{username} . "' [id = " . $row->{staffid} . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List staff:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
List staff of kayako
=back
=cut

View File

@ -1,68 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::sql::mode::liststatus;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}
sub run {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->{sql}->connect();
$self->{sql}->query(query => "SELECT ticketstatusid, title FROM swticketstatus");
while ((my $row = $self->{sql}->fetchrow_hashref())) {
$self->{output}->output_add(long_msg => "'" . $row->{title} . "' [id = " . $row->{ticketstatusid} . "]");
}
$self->{output}->output_add(severity => 'OK',
short_msg => 'List status:');
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}
1;
__END__
=head1 MODE
List status of kayako
=back
=cut

View File

@ -1,272 +0,0 @@
#
# Copyright 2021 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
package apps::kayako::sql::mode::ticketcount;
use base qw(centreon::plugins::mode);
use strict;
use warnings;
use centreon::plugins::statefile;
use Time::Local;
my $ticket_total = 0;
my %tickets;
my $label;
my $start = "";
my $end = "";
my $priority_filter;
my @priority_filters;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;
$options{options}->add_options(arguments => {
"reload-cache-time:s" => { name => 'reload_cache_time', default => 180 },
"department-id:s" => { name => 'department_id' },
"staff-id:s" => { name => 'staff_id' },
"status-id:s" => { name => 'status_id' },
"priority-id:s" => { name => 'priority_id' },
"warning:s" => { name => 'warning' },
"critical:s" => { name => 'critical' },
"start-date:s" => { name => 'start_date' },
"end-date:s" => { name => 'end_date' }
});
$self->{statefile_cache} = centreon::plugins::statefile->new(%options);
return $self;
}
sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
if (defined($self->{option_results}->{start_date})) {
if ($self->{option_results}->{start_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){
$self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY).");
$self->{output}->option_exit();
} else {
my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{'start_date'});
$start = $self->{option_results}->{start_date};
$self->{option_results}->{start_date} = timelocal(0,0,0,$mday,$mon-1,$year);
}
}
if (defined($self->{option_results}->{end_date})) {
if ($self->{option_results}->{end_date} !~ m/^\d{1,2}-\d{1,2}-\d{4}$/){
$self->{output}->add_option_msg(short_msg => "Please specify a valid date (DD-MM-YYYY).");
$self->{output}->option_exit();
} else {
my ($mday,$mon,$year) = split(/-/, $self->{option_results}->{end_date});
$end = $self->{option_results}->{end_date};
$self->{option_results}->{end_date} = timelocal(59,59,23,$mday,$mon-1,$year);
}
}
if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong warning threshold '" . $self->{option_results}->{warning} . "'.");
$self->{output}->option_exit();
}
if (($self->{perfdata}->threshold_validate(label => 'critical', value => $self->{option_results}->{critical})) == 0) {
$self->{output}->add_option_msg(short_msg => "Wrong critical threshold '" . $self->{option_results}->{critical} . "'.");
$self->{output}->option_exit();
}
if (defined($self->{option_results}->{priority_id})) {
@priority_filters = split(/,/, $self->{option_results}->{priority_id});
}
$self->{statefile_cache}->check_options(%options);
}
sub reload_cache {
my ($self) = @_;
my $datas = {};
$datas->{last_timestamp} = time();
$self->{sql}->query(query => "SELECT departmentid, title FROM swdepartments");
while ((my $row = $self->{sql}->fetchrow_hashref())) {
$datas->{"department_" . $row->{departmentid}} = $self->{output}->decode($row->{title});
}
$self->{sql}->query(query => "SELECT priorityid, title FROM swticketpriorities");
while ((my $row = $self->{sql}->fetchrow_hashref())) {
$datas->{"priority_" . $row->{priorityid}} = $self->{output}->decode($row->{title});
}
$self->{sql}->query(query => "SELECT staffid, username FROM swstaff");
while ((my $row = $self->{sql}->fetchrow_hashref())) {
$datas->{"staff_" . $row->{staffid}} = $self->{output}->decode($row->{username});
}
$self->{sql}->query(query => "SELECT ticketstatusid, title FROM swticketstatus");
while ((my $row = $self->{sql}->fetchrow_hashref())) {
$datas->{"status_" . $row->{ticketstatusid}} = $self->{output}->decode($row->{title});
}
$self->{statefile_cache}->write(data => $datas);
}
sub run {
my ($self, %options) = @_;
$self->{sql} = $options{sql};
$self->{sql}->connect();
my $has_cache_file = $self->{statefile_cache}->read(statefile => 'cache_sql_' . $self->{sql}->get_unique_id4save() . '_kayako');
my $timestamp_cache = $self->{statefile_cache}->get(name => 'last_timestamp');
if ($has_cache_file == 0 ||
!defined($timestamp_cache) || ((time() - $timestamp_cache) > (($self->{option_results}->{reload_cache_time}) * 60))) {
$self->reload_cache();
$self->{statefile_cache}->read();
}
my $query = "SELECT priorityid FROM swtickets WHERE ticketid IS NOT NULL";
if (defined($self->{option_results}->{'department_id'})) {
$query .= " AND departmentid IN (" . $self->{option_results}->{'department_id'} . ")";
}
if (defined($self->{option_results}->{'priority_id'})) {
$query .= " AND priorityid IN (" . $self->{option_results}->{'priority_id'} . ")";
}
if (defined($self->{option_results}->{'staff_id'})) {
$query .= " AND ownerstaffid IN (" . $self->{option_results}->{'staff_id'} . ")";
}
if (defined($self->{option_results}->{'status_id'})) {
$query .= " AND ticketstatusid IN (" . $self->{option_results}->{'status_id'} . ")";
}
if (defined($self->{option_results}->{'start_date'})) {
$query .= " AND lastactivity > " . $self->{option_results}->{'start_date'};
}
if (defined($self->{option_results}->{'end_date'})) {
$query .= " AND lastactivity < " . $self->{option_results}->{'end_date'};
}
$self->{sql}->query(query => $query);
while ((my $row = $self->{sql}->fetchrow_hashref())) {
if (defined($self->{option_results}->{priority_id})) {
foreach $priority_filter (@priority_filters) {
if ($priority_filter == $row->{priorityid}) {
$tickets{$priority_filter}++;
$ticket_total++;
}
}
} else {
$ticket_total++;
}
}
###########
# Manage Output
###########
my $exit = $self->{perfdata}->threshold_check(value => $ticket_total, threshold => [ { label => 'critical', exit_litteral => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]);
my $staff = "";
my $ticket_status = "";
my $period = "";
if (defined($self->{option_results}->{staff_id}) && ($self->{option_results}->{staff_id} =~ m/^\d*$/)) {
$staff = " for staff '" . $self->{statefile_cache}->get(name => 'staff_'.$self->{option_results}->{'staff_id'}) ."'";
}
if (defined($self->{option_results}->{status_id}) && ($self->{option_results}->{status_id} =~ m/^\d*$/)) {
$ticket_status = " in status '" . $self->{statefile_cache}->get(name => 'status_'.$self->{option_results}->{'status_id'}) ."'";
}
if (defined($self->{option_results}->{start_date}) || defined($self->{option_results}->{end_date})){
$period = " -";
}
if (defined($self->{option_results}->{start_date})){
$start = " Start: " . $start;
}
if (defined($self->{option_results}->{end_date})){
$end = " End: " . $end;
}
if (defined($self->{option_results}->{priority_id})) {
foreach $priority_filter (@priority_filters) {
$label = $self->{statefile_cache}->get(name => 'priority_' . $priority_filter);
$self->{output}->perfdata_add(label => $label, value => $tickets{$priority_filter},
min => 0, max => $ticket_total);
}
}
$self->{output}->perfdata_add(label => 'Total', value => $ticket_total,
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,
short_msg => sprintf("%s tickets%s%s%s%s%s", $ticket_total, $staff, $ticket_status, $period, $start, $end));
$self->{output}->display();
$self->{output}->exit();
}
1;
__END__
=head1 MODE
Count tickets of kayako
=over 8
=item B<--department-id>
Filter the tickets by the specified department id, you can specify multiple id's by separating the values using a comma. Example: 1,2,3 .
You must define at least one id. (required)
=item B<--priority-id>
Filter the tickets by the specified ticket priority id, you can specify multiple id's by separating the values using a comma. Example: 1,2,3 .
By default, all ticket priority are included.
=item B<--staff-id>
Filter the tickets by the specified owner staff id, you can specify multiple id's by separating the values using a comma. Example: 1,2,3 .
By default, all staff users are included.
=item B<--status-id>
Filter the tickets by the specified ticket status id, you can specify multiple id's by separating the values using a comma. Example: 1,2,3 .
By default, the filter is on unresolved ticket statuses.
=item B<--warning>
Threshold warning.
=item B<--critical>
Threshold critical.
=item B<--start-date>
Filter on last activity. For example: 21-03-2014
=item B<--end-date>
Filter on last activity. For example: 21-03-2014
=back
=cut