From 6fa8cff2062c03a3743a0edf046153396fb70f9d Mon Sep 17 00:00:00 2001 From: garnier-quentin Date: Tue, 18 Jun 2019 08:40:48 +0200 Subject: [PATCH] enhance proxmox error --- apps/proxmox/ve/restapi/custom/api.pm | 21 +++++++++------------ apps/proxmox/ve/restapi/mode/listnodes.pm | 6 +++--- apps/proxmox/ve/restapi/mode/nodeusage.pm | 17 ++++++++--------- apps/proxmox/ve/restapi/mode/version.pm | 6 +++--- apps/proxmox/ve/restapi/mode/vmusage.pm | 21 ++++++++++----------- 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/apps/proxmox/ve/restapi/custom/api.pm b/apps/proxmox/ve/restapi/custom/api.pm index 055452e4c..273533390 100644 --- a/apps/proxmox/ve/restapi/custom/api.pm +++ b/apps/proxmox/ve/restapi/custom/api.pm @@ -45,15 +45,14 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "port:s" => { name => 'port'}, - "proto:s" => { name => 'proto' }, - "api-username:s" => { name => 'api_username' }, - "api-password:s" => { name => 'api_password' }, - "realm:s" => { name => 'realm' }, - "timeout:s" => { name => 'timeout' }, - "timeout:s" => { name => 'timeout', default => 30 }, - "reload-cache-time:s" => { name => 'reload_cache_time', default => 7200 }, + 'hostname:s' => { name => 'hostname' }, + 'port:s' => { name => 'port'}, + 'proto:s' => { name => 'proto' }, + 'api-username:s' => { name => 'api_username' }, + 'api-password:s' => { name => 'api_password' }, + 'realm:s' => { name => 'realm' }, + 'timeout:s' => { name => 'timeout' }, + 'reload-cache-time:s' => { name => 'reload_cache_time', default => 7200 }, }); } @@ -96,7 +95,6 @@ sub check_options { $self->{port} = (defined($self->{option_results}->{port})) ? $self->{option_results}->{port} : 8006; $self->{proto} = (defined($self->{option_results}->{proto})) ? $self->{option_results}->{proto} : 'https'; $self->{timeout} = (defined($self->{option_results}->{timeout})) ? $self->{option_results}->{timeout} : 10; - $self->{ssl_opt} = (defined($self->{option_results}->{ssl_opt})) ? $self->{option_results}->{ssl_opt} : undef; $self->{api_username} = (defined($self->{option_results}->{api_username})) ? $self->{option_results}->{api_username} : undef; $self->{api_password} = (defined($self->{option_results}->{api_password})) ? $self->{option_results}->{api_password} : undef; $self->{realm} = (defined($self->{option_results}->{realm})) ? $self->{option_results}->{realm} : 'pam'; @@ -137,11 +135,10 @@ sub build_options_for_httplib { $self->{option_results}->{hostname} = $self->{hostname}; $self->{option_results}->{port} = $self->{port}; $self->{option_results}->{proto} = $self->{proto}; - $self->{option_results}->{ssl_opt} = $self->{ssl_opt}; $self->{option_results}->{timeout} = $self->{timeout}; $self->{option_results}->{warning_status} = ''; $self->{option_results}->{critical_status} = ''; - $self->{option_results}->{unknown_status} = ''; + $self->{option_results}->{unknown_status} = '%{http_code} < 200 or %{http_code} >= 300'; } sub settings { diff --git a/apps/proxmox/ve/restapi/mode/listnodes.pm b/apps/proxmox/ve/restapi/mode/listnodes.pm index 7ea6e1348..9299abcd8 100644 --- a/apps/proxmox/ve/restapi/mode/listnodes.pm +++ b/apps/proxmox/ve/restapi/mode/listnodes.pm @@ -31,9 +31,9 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); + return $self; } diff --git a/apps/proxmox/ve/restapi/mode/nodeusage.pm b/apps/proxmox/ve/restapi/mode/nodeusage.pm index 7c07ed031..4c129daad 100644 --- a/apps/proxmox/ve/restapi/mode/nodeusage.pm +++ b/apps/proxmox/ve/restapi/mode/nodeusage.pm @@ -255,15 +255,14 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "node-id:s" => { name => 'node_id' }, - "node-name:s" => { name => 'node_name' }, - "filter-name:s" => { name => 'filter_name' }, - "use-name" => { name => 'use_name' }, - "warning-node-status:s" => { name => 'warning_node_status', default => '' }, - "critical-node-status:s" => { name => 'critical_node_status', default => '' }, - }); + $options{options}->add_options(arguments => { + 'node-id:s' => { name => 'node_id' }, + 'node-name:s' => { name => 'node_name' }, + 'filter-name:s' => { name => 'filter_name' }, + 'use-name' => { name => 'use_name' }, + 'warning-node-status:s' => { name => 'warning_node_status', default => '' }, + 'critical-node-status:s' => { name => 'critical_node_status', default => '' }, + }); $self->{statefile_cache_nodes} = centreon::plugins::statefile->new(%options); return $self; diff --git a/apps/proxmox/ve/restapi/mode/version.pm b/apps/proxmox/ve/restapi/mode/version.pm index 88d024ddd..8f5161dfa 100644 --- a/apps/proxmox/ve/restapi/mode/version.pm +++ b/apps/proxmox/ve/restapi/mode/version.pm @@ -31,9 +31,9 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - }); + $options{options}->add_options(arguments => { + }); + return $self; } diff --git a/apps/proxmox/ve/restapi/mode/vmusage.pm b/apps/proxmox/ve/restapi/mode/vmusage.pm index 1568d748d..c840817f1 100644 --- a/apps/proxmox/ve/restapi/mode/vmusage.pm +++ b/apps/proxmox/ve/restapi/mode/vmusage.pm @@ -243,17 +243,16 @@ sub new { bless $self, $class; $self->{version} = '1.0'; - $options{options}->add_options(arguments => - { - "vm-id:s" => { name => 'vm_id' }, - "vm-name:s" => { name => 'vm_name' }, - "filter-name:s" => { name => 'filter_name' }, - "use-name" => { name => 'use_name' }, - "warning-vm-status:s" => { name => 'warning_vm_status', default => '' }, - "critical-vm-status:s" => { name => 'critical_vm_status', default => '' }, - }); - $self->{statefile_cache_vms} = centreon::plugins::statefile->new(%options); - return $self; + $options{options}->add_options(arguments => { + 'vm-id:s' => { name => 'vm_id' }, + 'vm-name:s' => { name => 'vm_name' }, + 'filter-name:s' => { name => 'filter_name' }, + 'use-name' => { name => 'use_name' }, + 'warning-vm-status:s' => { name => 'warning_vm_status', default => '' }, + 'critical-vm-status:s' => { name => 'critical_vm_status', default => '' }, + }); + $self->{statefile_cache_vms} = centreon::plugins::statefile->new(%options); + return $self; } sub check_options {