diff --git a/apps/salesforce/restapi/custom/api.pm b/apps/salesforce/restapi/custom/api.pm index f70c32fc9..5ee420c07 100644 --- a/apps/salesforce/restapi/custom/api.pm +++ b/apps/salesforce/restapi/custom/api.pm @@ -41,9 +41,9 @@ sub new { if (!defined($options{noptions})) { $options{options}->add_options(arguments => { - "hostname:s" => { name => 'hostname' }, - "timeout:s" => { name => 'timeout' }, - "api-versions:s" => { name => 'api_version' }, + 'hostname:s' => { name => 'hostname' }, + 'timeout:s' => { name => 'timeout' }, + 'api-versions:s' => { name => 'api_version' } }); } $options{options}->add_help(package => __PACKAGE__, sections => 'REST API OPTIONS', once => 1); @@ -110,20 +110,24 @@ sub request_api { $self->settings(); - my $content = $self->{http}->request(method => 'GET', url_path => '/' . $self->{api_version} . $options{path}, - critical_status => '', warning_status => '', unknown_status => ''); + my $content = $self->{http}->request( + method => 'GET', + url_path => '/' . $self->{api_version} . $options{path}, + critical_status => '', + warning_status => '', + unknown_status => '' + ); my $decoded; eval { $decoded = decode_json($content); }; if ($@) { - $self->{output}->output_add(long_msg => $content, debug => 1); $self->{output}->add_option_msg(short_msg => "Cannot decode json response"); $self->{output}->option_exit(); } if ($self->{http}->get_code() != 200) { - $self->{output}->add_option_msg(short_msg => "Connection issue: " . $decoded->{msg}); + $self->{output}->add_option_msg(short_msg => "Connection issue: " . $decoded->{message}); $self->{output}->option_exit(); } @@ -165,4 +169,3 @@ API base url path (Default: '/v1'). B. =cut - diff --git a/apps/salesforce/restapi/mode/sfdcinstance.pm b/apps/salesforce/restapi/mode/sfdcinstance.pm index ac941ada3..33ceafcc1 100644 --- a/apps/salesforce/restapi/mode/sfdcinstance.pm +++ b/apps/salesforce/restapi/mode/sfdcinstance.pm @@ -30,21 +30,26 @@ sub custom_status_output { my ($self, %options) = @_; return sprintf( - "Salesforce '%s' instance status is '%s' (active:'%s') ", - $self->{result_values}->{name}, + "status is '%s' (active:'%s') ", $self->{result_values}->{status}, $self->{result_values}->{active} ); } +sub prefix_volume_output { + my ($self, %options) = @_; + + return "Salesforce '" . $options{instance_value}->{name} . "' instance "; +} + sub set_counters { my ($self, %options) = @_; $self->{maps_counters_type} = [ - { name => 'status', type => 1 }, + { name => 'salesforce', type => 1, cb_prefix_output => 'prefix_salesforce_output', message_multiple => 'All salesforce instances are ok' } ]; - $self->{maps_counters}->{status} = [ + $self->{maps_counters}->{salesforce} = [ { label => 'status', threshold => 0, set => { key_values => [ { name => 'status' }, { name => 'active' }, { name => 'name' } ], closure_custom_calc => \&catalog_status_calc, @@ -61,7 +66,7 @@ sub set_counters { min => 0, label_extra_instance => 1 }, ], } - }, + } ]; } @@ -75,8 +80,9 @@ sub new { 'alias' => { name => 'use_alias' }, 'unknown-status:s' => { name => 'unknown_status', default => '' }, 'warning-status:s' => { name => 'warning_status', default => '' }, - 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /OK/' }, + 'critical-status:s' => { name => 'critical_status', default => '%{status} !~ /OK/' } }); + return $self; } @@ -85,7 +91,6 @@ sub check_options { $self->SUPER::check_options(%options); $self->change_macros(macros => ['unknown_status', 'warning_status', 'critical_status']); - } sub manage_selection { @@ -96,14 +101,13 @@ sub manage_selection { foreach my $instance (@{$self->{option_results}->{instance}}) { my $result = $options{custom}->request_api(path => $instance_path . $instance . '/status'); - $self->{status}->{$instance} = { + $self->{salesforce}->{$instance} = { active => $result->{isActive}, incident => scalar(@{$result->{Incidents}}), name => $instance, - status => $result->{status}, + status => $result->{status} }; } - } 1; @@ -139,4 +143,3 @@ Set critical threshold for instance status (Default: '%{status} !~ /OK/'). =back =cut - diff --git a/apps/salesforce/restapi/plugin.pm b/apps/salesforce/restapi/plugin.pm index 3b2ae71cd..0fd4c57d3 100644 --- a/apps/salesforce/restapi/plugin.pm +++ b/apps/salesforce/restapi/plugin.pm @@ -31,7 +31,7 @@ sub new { $self->{version} = '0.1'; %{$self->{modes}} = ( - 'sfdc-instance' => 'apps::salesforce::restapi::mode::sfdcinstance', + 'sfdc-instance' => 'apps::salesforce::restapi::mode::sfdcinstance', ); $self->{custom_modes}{api} = 'apps::salesforce::restapi::custom::api'; return $self;