From 675d214032a626871a94b8d7350dfd8db0548be3 Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Thu, 14 May 2015 12:34:19 +0200 Subject: [PATCH] + plugin github: use owner despite user (like in github doc api) --- apps/github/mode/commits.pm | 16 +++++++--------- apps/github/mode/issues.pm | 12 ++++++------ apps/github/mode/pullrequests.pm | 12 ++++++------ 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/apps/github/mode/commits.pm b/apps/github/mode/commits.pm index 890adee50..0601b0b43 100644 --- a/apps/github/mode/commits.pm +++ b/apps/github/mode/commits.pm @@ -58,7 +58,7 @@ sub new { "credentials" => { name => 'credentials' }, "username:s" => { name => 'username' }, "password:s" => { name => 'password' }, - "user:s" => { name => 'user' }, + "owner:s" => { name => 'owner' }, "repository:s" => { name => 'repository' }, "timeout:s" => { name => 'timeout', default => '3' }, }); @@ -84,8 +84,8 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Please set the repository option"); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{user})) { - $self->{output}->add_option_msg(short_msg => "Please set the user option"); + if (!defined($self->{option_results}->{owner})) { + $self->{output}->add_option_msg(short_msg => "Please set the owner option"); $self->{output}->option_exit(); } @@ -95,9 +95,7 @@ sub check_options { sub run { my ($self, %options) = @_; - my $repository = $self->{option_results}->{repository}; - $repository =~ tr/\//_/; - $self->{statefile_value}->read(statefile => 'github_' . $repository . '_' . $self->{option_results}->{user} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode}); + $self->{statefile_value}->read(statefile => 'github_' . $self->{option_results}->{repository} . '_' . $self->{option_results}->{owner} . '_' . centreon::plugins::httplib::get_port($self) . '_' . $self->{mode}); my $old_timestamp = $self->{statefile_value}->get(name => 'last_timestamp'); my $new_datas = {}; @@ -114,7 +112,7 @@ sub run { # Change date format from epoch to iso8601 my $old_iso8601 = DateTime->from_epoch(epoch => $old_timestamp)."Z"; - $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{user}."/".$self->{option_results}->{repository}."/commits"; + $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository}."/commits"; my $query_form_get = { per_page => '1000', since => $old_iso8601 }; my $jsoncontent = centreon::plugins::httplib::connect($self, query_form_get => $query_form_get , connection_exit => 'critical'); @@ -181,9 +179,9 @@ Specify username Specify password -=item B<--user> +=item B<--owner> -Specify GitHub's user +Specify GitHub's owner =item B<--repository> diff --git a/apps/github/mode/issues.pm b/apps/github/mode/issues.pm index d635e1598..b97f4dc52 100644 --- a/apps/github/mode/issues.pm +++ b/apps/github/mode/issues.pm @@ -58,7 +58,7 @@ sub new { "password:s" => { name => 'password' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "user:s" => { name => 'user' }, + "owner:s" => { name => 'owner' }, "repository:s" => { name => 'repository' }, "label:s" => { name => 'label', default => '' }, "timeout:s" => { name => 'timeout', default => '3' }, @@ -83,8 +83,8 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Please set the repository option"); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{user})) { - $self->{output}->add_option_msg(short_msg => "Please set the user option"); + if (!defined($self->{option_results}->{owner})) { + $self->{output}->add_option_msg(short_msg => "Please set the owner option"); $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { @@ -101,7 +101,7 @@ sub run { my ($self, %options) = @_; - $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{user}."/".$self->{option_results}->{repository} . "/issues"; + $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository} . "/issues"; my $query_form_get; if (defined($self->{option_results}->{label}) && $self->{option_results}->{label} ne '') { @@ -196,9 +196,9 @@ Threshold warning. Threshold critical. -=item B<--user> +=item B<--owner> -Specify GitHub's user +Specify GitHub's owner =item B<--repository> diff --git a/apps/github/mode/pullrequests.pm b/apps/github/mode/pullrequests.pm index 0a1843cef..09ba8dcbf 100644 --- a/apps/github/mode/pullrequests.pm +++ b/apps/github/mode/pullrequests.pm @@ -58,7 +58,7 @@ sub new { "password:s" => { name => 'password' }, "warning:s" => { name => 'warning' }, "critical:s" => { name => 'critical' }, - "user:s" => { name => 'user' }, + "owner:s" => { name => 'owner' }, "repository:s" => { name => 'repository' }, "timeout:s" => { name => 'timeout', default => '3' }, }); @@ -82,8 +82,8 @@ sub check_options { $self->{output}->add_option_msg(short_msg => "Please set the repository option"); $self->{output}->option_exit(); } - if (!defined($self->{option_results}->{user})) { - $self->{output}->add_option_msg(short_msg => "Please set the user option"); + if (!defined($self->{option_results}->{owner})) { + $self->{output}->add_option_msg(short_msg => "Please set the owner option"); $self->{output}->option_exit(); } if (($self->{perfdata}->threshold_validate(label => 'warning', value => $self->{option_results}->{warning})) == 0) { @@ -99,7 +99,7 @@ sub check_options { sub run { my ($self, %options) = @_; - $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{user}."/".$self->{option_results}->{repository}."/pulls"; + $self->{option_results}->{url_path} = "/repos/".$self->{option_results}->{owner}."/".$self->{option_results}->{repository}."/pulls"; my $query_form_get = { state => 'open', per_page => '1000' }; @@ -178,9 +178,9 @@ Threshold warning. Threshold critical. -=item B<--user> +=item B<--owner> -Specify GitHub's user +Specify GitHub's owner =item B<--repository>