From e269a57cd2aa73c6529bf1d4c9d683c03ffce512 Mon Sep 17 00:00:00 2001 From: Stephane Duret Date: Thu, 23 Jul 2015 09:30:07 +0200 Subject: [PATCH] Creation of SQL mode for Kayako --- apps/kayako/{ => api}/mode/listdepartment.pm | 55 ++-- apps/kayako/{ => api}/mode/listpriority.pm | 53 ++-- apps/kayako/{ => api}/mode/liststaff.pm | 53 ++-- apps/kayako/{ => api}/mode/liststatus.pm | 53 ++-- apps/kayako/{ => api}/mode/ticketcount.pm | 53 ++-- apps/kayako/api/plugin.pm | 68 +++++ apps/kayako/plugin.pm | 53 ---- apps/kayako/sql/mode/listdepartment.pm | 89 ++++++ apps/kayako/sql/mode/listpriority.pm | 89 ++++++ apps/kayako/sql/mode/liststaff.pm | 89 ++++++ apps/kayako/sql/mode/liststatus.pm | 89 ++++++ apps/kayako/sql/mode/ticketcount.pm | 294 +++++++++++++++++++ apps/kayako/sql/plugin.pm | 120 ++++++++ 13 files changed, 1009 insertions(+), 149 deletions(-) rename apps/kayako/{ => api}/mode/listdepartment.pm (65%) rename apps/kayako/{ => api}/mode/listpriority.pm (65%) rename apps/kayako/{ => api}/mode/liststaff.pm (65%) rename apps/kayako/{ => api}/mode/liststatus.pm (65%) rename apps/kayako/{ => api}/mode/ticketcount.pm (88%) create mode 100644 apps/kayako/api/plugin.pm delete mode 100644 apps/kayako/plugin.pm create mode 100644 apps/kayako/sql/mode/listdepartment.pm create mode 100644 apps/kayako/sql/mode/listpriority.pm create mode 100644 apps/kayako/sql/mode/liststaff.pm create mode 100644 apps/kayako/sql/mode/liststatus.pm create mode 100644 apps/kayako/sql/mode/ticketcount.pm create mode 100644 apps/kayako/sql/plugin.pm diff --git a/apps/kayako/mode/listdepartment.pm b/apps/kayako/api/mode/listdepartment.pm similarity index 65% rename from apps/kayako/mode/listdepartment.pm rename to apps/kayako/api/mode/listdepartment.pm index a79bb30b3..16739ca98 100644 --- a/apps/kayako/mode/listdepartment.pm +++ b/apps/kayako/api/mode/listdepartment.pm @@ -1,24 +1,39 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET # -# Copyright 2015 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::mode::listdepartment; +package apps::kayako::api::mode::listdepartment; use base qw(centreon::plugins::mode); @@ -121,7 +136,7 @@ __END__ =head1 MODE -List departmentf of kayako +List departments of kayako =over 8 diff --git a/apps/kayako/mode/listpriority.pm b/apps/kayako/api/mode/listpriority.pm similarity index 65% rename from apps/kayako/mode/listpriority.pm rename to apps/kayako/api/mode/listpriority.pm index f80638faa..d89bd7b52 100644 --- a/apps/kayako/mode/listpriority.pm +++ b/apps/kayako/api/mode/listpriority.pm @@ -1,24 +1,39 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET # -# Copyright 2015 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::mode::listpriority; +package apps::kayako::api::mode::listpriority; use base qw(centreon::plugins::mode); diff --git a/apps/kayako/mode/liststaff.pm b/apps/kayako/api/mode/liststaff.pm similarity index 65% rename from apps/kayako/mode/liststaff.pm rename to apps/kayako/api/mode/liststaff.pm index 8420fb47b..02ee625c6 100644 --- a/apps/kayako/mode/liststaff.pm +++ b/apps/kayako/api/mode/liststaff.pm @@ -1,24 +1,39 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET # -# Copyright 2015 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::mode::liststaff; +package apps::kayako::api::mode::liststaff; use base qw(centreon::plugins::mode); diff --git a/apps/kayako/mode/liststatus.pm b/apps/kayako/api/mode/liststatus.pm similarity index 65% rename from apps/kayako/mode/liststatus.pm rename to apps/kayako/api/mode/liststatus.pm index 6284d7ed5..6f613321e 100644 --- a/apps/kayako/mode/liststatus.pm +++ b/apps/kayako/api/mode/liststatus.pm @@ -1,24 +1,39 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET # -# Copyright 2015 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::mode::liststatus; +package apps::kayako::api::mode::liststatus; use base qw(centreon::plugins::mode); diff --git a/apps/kayako/mode/ticketcount.pm b/apps/kayako/api/mode/ticketcount.pm similarity index 88% rename from apps/kayako/mode/ticketcount.pm rename to apps/kayako/api/mode/ticketcount.pm index 4374c5e05..d8b67ed92 100644 --- a/apps/kayako/mode/ticketcount.pm +++ b/apps/kayako/api/mode/ticketcount.pm @@ -1,24 +1,39 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET # -# Copyright 2015 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::mode::ticketcount; +package apps::kayako::api::mode::ticketcount; use base qw(centreon::plugins::mode); diff --git a/apps/kayako/api/plugin.pm b/apps/kayako/api/plugin.pm new file mode 100644 index 000000000..59bd5e685 --- /dev/null +++ b/apps/kayako/api/plugin.pm @@ -0,0 +1,68 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Stéphane Duret +# +#################################################################################### + +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; + # $options->{options} = options object + + $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 diff --git a/apps/kayako/plugin.pm b/apps/kayako/plugin.pm deleted file mode 100644 index 429a8b91e..000000000 --- a/apps/kayako/plugin.pm +++ /dev/null @@ -1,53 +0,0 @@ -# -# Copyright 2015 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::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; - # $options->{options} = options object - - $self->{version} = '0.1'; - %{$self->{modes}} = ( - 'list-department' => 'apps::kayako::mode::listdepartment', - 'list-priority' => 'apps::kayako::mode::listpriority', - 'list-staff' => 'apps::kayako::mode::liststaff', - 'list-status' => 'apps::kayako::mode::liststatus', - 'ticket-count' => 'apps::kayako::mode::ticketcount', - ); - - return $self; -} - -1; - -__END__ - -=head1 PLUGIN DESCRIPTION - -Check Selenium server. - -=cut diff --git a/apps/kayako/sql/mode/listdepartment.pm b/apps/kayako/sql/mode/listdepartment.pm new file mode 100644 index 000000000..3ef07e1ed --- /dev/null +++ b/apps/kayako/sql/mode/listdepartment.pm @@ -0,0 +1,89 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET +# +#################################################################################### + +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; + $self->{version} = '1.0'; + return $self; +} + + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '5'))) { + $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); + $self->{output}->option_exit(); + } + + $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 diff --git a/apps/kayako/sql/mode/listpriority.pm b/apps/kayako/sql/mode/listpriority.pm new file mode 100644 index 000000000..699a47cdb --- /dev/null +++ b/apps/kayako/sql/mode/listpriority.pm @@ -0,0 +1,89 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET +# +#################################################################################### + +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; + $self->{version} = '1.0'; + return $self; +} + + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '5'))) { + $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); + $self->{output}->option_exit(); + } + + $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 diff --git a/apps/kayako/sql/mode/liststaff.pm b/apps/kayako/sql/mode/liststaff.pm new file mode 100644 index 000000000..a4b60eb10 --- /dev/null +++ b/apps/kayako/sql/mode/liststaff.pm @@ -0,0 +1,89 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET +# +#################################################################################### + +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; + $self->{version} = '1.0'; + return $self; +} + + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '5'))) { + $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); + $self->{output}->option_exit(); + } + + $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 diff --git a/apps/kayako/sql/mode/liststatus.pm b/apps/kayako/sql/mode/liststatus.pm new file mode 100644 index 000000000..05817ad60 --- /dev/null +++ b/apps/kayako/sql/mode/liststatus.pm @@ -0,0 +1,89 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET +# +#################################################################################### + +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; + $self->{version} = '1.0'; + return $self; +} + + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub run { + my ($self, %options) = @_; + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '5'))) { + $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); + $self->{output}->option_exit(); + } + + $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 diff --git a/apps/kayako/sql/mode/ticketcount.pm b/apps/kayako/sql/mode/ticketcount.pm new file mode 100644 index 000000000..ca88304b3 --- /dev/null +++ b/apps/kayako/sql/mode/ticketcount.pm @@ -0,0 +1,294 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an timeelapsedutable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting timeelapsedutable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Author : Stéphane DURET +# +#################################################################################### + +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 %handlers = (ALRM => {} ); +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; + + $self->{version} = '1.0'; + $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}->to_utf8($row->{title}); + } + + $self->{sql}->query(query => "SELECT priorityid, title FROM swticketpriorities"); + while ((my $row = $self->{sql}->fetchrow_hashref())) { + $datas->{"priority_" . $row->{priorityid}} = $self->{output}->to_utf8($row->{title}); + } + + $self->{sql}->query(query => "SELECT staffid, username FROM swstaff"); + while ((my $row = $self->{sql}->fetchrow_hashref())) { + $datas->{"staff_" . $row->{staffid}} = $self->{output}->to_utf8($row->{username}); + } + + $self->{sql}->query(query => "SELECT ticketstatusid, title FROM swticketstatus"); + while ((my $row = $self->{sql}->fetchrow_hashref())) { + $datas->{"status_" . $row->{ticketstatusid}} = $self->{output}->to_utf8($row->{title}); + } + + $self->{statefile_cache}->write(data => $datas); +} + +sub run { + my ($self, %options) = @_; + $self->{sql} = $options{sql}; + + $self->{sql}->connect(); + + if (!($self->{sql}->is_version_minimum(version => '5'))) { + $self->{output}->add_option_msg(short_msg => "MySQL version '" . $self->{sql}->{version} . "' is not supported (need version >= '5.x')."); + $self->{output}->option_exit(); + } + + 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')); + + $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 diff --git a/apps/kayako/sql/plugin.pm b/apps/kayako/sql/plugin.pm new file mode 100644 index 000000000..0c965861d --- /dev/null +++ b/apps/kayako/sql/plugin.pm @@ -0,0 +1,120 @@ +############################################################################### +# Copyright 2005-2013 MERETHIS +# Centreon is developped by : Julien Mathis and Romain Le Merlus under +# GPL Licence 2.0. +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation ; either version 2 of the License. +# +# This program is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, see . +# +# Linking this program statically or dynamically with other modules is making a +# combined work based on this program. Thus, the terms and conditions of the GNU +# General Public License cover the whole combination. +# +# As a special exception, the copyright holders of this program give MERETHIS +# permission to link this program with independent modules to produce an executable, +# regardless of the license terms of these independent modules, and to copy and +# distribute the resulting executable under terms of MERETHIS choice, provided that +# MERETHIS also meet, for each linked independent module, the terms and conditions +# of the license of that module. An independent module is a module which is not +# derived from this program. If you modify this program, you may extend this +# exception to your version of the program, but you are not obliged to do so. If you +# do not wish to do so, delete this exception statement from your version. +# +# For more information : contact@centreon.com +# Authors : Stéphane Duret +# +#################################################################################### + +package apps::kayako::sql::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_sql); + +sub new { + my ($class, %options) = @_; + + my $self = $class->SUPER::new(package => __PACKAGE__, %options); + bless $self, $class; + # $options->{options} = options object + + $self->{version} = '0.1'; + %{$self->{modes}} = ( + 'list-department' => 'apps::kayako::sql::mode::listdepartment', + 'list-priority' => 'apps::kayako::sql::mode::listpriority', + 'list-staff' => 'apps::kayako::sql::mode::liststaff', + 'list-status' => 'apps::kayako::sql::mode::liststatus', + 'ticket-count' => 'apps::kayako::sql::mode::ticketcount', + ); + $self->{sql_modes}{psqlcmd} = 'database::postgres::psqlcmd'; + return $self; +} + +sub init { + my ($self, %options) = @_; + + $self->{options}->add_options( + arguments => { + 'host:s@' => { name => 'db_host' }, + 'port:s@' => { name => 'db_port' }, + 'database:s@' => { name => 'db_name' }, + } + ); + $self->{options}->parse_options(); + my $options_result = $self->{options}->get_options(); + $self->{options}->clean(); + + if (defined($options_result->{db_host})) { + @{$self->{sqldefault}->{dbi}} = (); + @{$self->{sqldefault}->{mysqlcmd}} = (); + for (my $i = 0; $i < scalar(@{$options_result->{db_host}}); $i++) { + $self->{sqldefault}->{dbi}[$i] = { data_source => 'mysql:host=' . $options_result->{db_host}[$i] }; + $self->{sqldefault}->{mysqlcmd}[$i] = { host => $options_result->{db_host}[$i] }; + if (defined($options_result->{db_port}[$i])) { + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';port=' . $options_result->{db_port}[$i]; + $self->{sqldefault}->{mysqlcmd}[$i]->{port} = $options_result->{db_port}[$i]; + } + if (!defined($options_result->{db_name}[$i]) || $options_result->{db_name}[$i] eq '') { + $self->{output}->add_option_msg(short_msg => "Need to specify '--database' option."); + $self->{output}->option_exit(); + }else{ + $self->{sqldefault}->{dbi}[$i]->{data_source} .= ';database=' . $options_result->{db_name}[$i]; + $self->{sqldefault}->{psqlcmd}[$i]->{dbname} = $options_result->{db_name}[$i]; + } + } + } + + $self->SUPER::init(%options); +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Kayako with MySQL Server. + +=item B<--host> + +Hostname to query. + +=item B<--port> + +Database Server Port. + +=item B<--database> + +Database Name. + +=back + +=cut