diff --git a/centreon-plugins/cloud/aws/custom/awscli.pm b/centreon-plugins/cloud/aws/custom/awscli.pm new file mode 100644 index 000000000..4ed939bbe --- /dev/null +++ b/centreon-plugins/cloud/aws/custom/awscli.pm @@ -0,0 +1,183 @@ +# +# 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 cloud::aws::custom::awscli; + +use strict; +use warnings; +use JSON; +use centreon::plugins::misc; + +sub new { + my ( $class, %options ) = @_; + my $self = {}; + bless $self, $class; + + # $options{options} = options object + # $options{output} = output object + # $options{exit_value} = integer + # $options{noptions} = integer + + if ( !defined( $options{output} ) ) { + print "Class Custom: Need to specify 'output' argument.\n"; + exit 3; + } + if ( !defined( $options{options} ) ) { + $options{output}->add_option_msg( short_msg => "Class Custom: Need to specify 'options' argument." ); + $options{output}->option_exit(); + } + + if ( !defined( $options{noptions} ) ) { + $options{options}->add_options( arguments => { + "region:s" => { name => 'region' }, + "command:s" => { name => 'command', default => 'aws' }, + "command-path:s" => { name => 'command_path' }, + "sudo" => { name => 'sudo' }, + } ); + } + $options{options}->add_help(package => __PACKAGE__, sections => 'AWSCLI OPTIONS', once => 1); + + $self->{output} = $options{output}; + $self->{mode} = $options{mode}; + return $self; +} + +# Method to manage multiples +sub set_options { + my ( $self, %options ) = @_; + + # options{options_result} + + $self->{option_results} = $options{option_results}; +} + +# Method to manage multiples +sub set_defaults { + my ( $self, %options ) = @_; + + # Manage default value + foreach ( keys %{ $options{default} } ) { + if ( $_ eq $self->{mode} ) { + for ( my $i = 0 ; $i < scalar( @{ $options{default}->{$_} } ) ; $i++ ) + { + foreach my $opt ( keys %{ $options{default}->{$_}[$i] } ) { + if ( !defined( $self->{option_results}->{$opt}[$i] ) ) { + $self->{option_results}->{$opt}[$i] = $options{default}->{$_}[$i]->{$opt}; + } + } + } + } + } +} + +sub check_options { + my ($self, %options) = @_; + return 0; +} + +sub execReq { + my ($self, $options) = @_; + my $jsoncontent; + + if (!defined($options->{output})) { + $options->{output} = 'json'; + } + + my $json = JSON->new; + my $json_encoded = $options->{command} . " " . $options->{subcommand}; + if (defined($self->{option_results}->{region})) { + $json_encoded = $json_encoded . " --region '". $self->{option_results}->{region} . "'"; + } + if (defined($options->{json})) { + $json_encoded = $json_encoded . " --cli-input-json '" . $json->encode( $options->{json} ) . "'"; + } + + $self->{option_results}->{timeout} = 30; + + if ($options->{output} eq 'text') { + $self->{stdout} = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $json_encoded + ); + my @return = split /\n/, $self->{stdout}; + $jsoncontent = $json->encode( [@return] ); + } else { + $jsoncontent = centreon::plugins::misc::execute( + output => $self->{output}, + options => $self->{option_results}, + sudo => $self->{option_results}->{sudo}, + command => $self->{option_results}->{command}, + command_path => $self->{option_results}->{command_path}, + command_options => $json_encoded + ); + } + if ($? > 0) { + $self->{output}->add_option_msg( short_msg => "Cannot run aws" ); + $self->{output}->option_exit(); + } + eval { $self->{command_return} = $json->decode($jsoncontent); }; + if ($@) { + $self->{output}->add_option_msg( short_msg => "Cannot decode json answer" ); + $self->{output}->option_exit(); + } + return $self->{command_return}; +} + +1; + +__END__ + +=head1 NAME + +AWS CLI API + +=head1 SYNOPSIS + +AWS cli API custom mode + +=over 8 + +=item B<--region> + +(optional) The region to use (should be configured directly in aws). + +=item B<--sudo> + +Use 'sudo' to execute the command. + +=item B<--command> + +(optional) Command to get information (Default: 'aws'). + +=item B<--command-path> + +(optional) Command path (Default: none). + +=back + +=head1 DESCRIPTION + +B. + +=cut diff --git a/centreon-plugins/cloud/aws/mode/cloudwatch.pm b/centreon-plugins/cloud/aws/mode/cloudwatch.pm new file mode 100644 index 000000000..a92ac3ef4 --- /dev/null +++ b/centreon-plugins/cloud/aws/mode/cloudwatch.pm @@ -0,0 +1,308 @@ +# +# 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 cloud::aws::mode::cloudwatch; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; +use POSIX; +use JSON; +use Module::Load; + +my $CloudwatchMetrics = { + cpu => "cloud::aws::mode::metrics::ec2instancecpu", + traffic' => "cloud::aws::mode::metrics::ec2instancenetwork", + cpucreditusage => "cloud::aws::mode::metrics::ec2instancecpucreditusage", + cpucreditbalance => "cloud::aws::mode::metrics::ec2instancecpucreditbalance", + bucketsize => "cloud::aws::mode::metrics::s3bucketsize", + rdscpu => "cloud::aws::mode::metrics::rdsinstancecpu", +}; + +my $StatisticsType = "Average,Minimum,Maximum,Sum,SampleCount"; +my $def_endtime = time(); + +my $apiRequest = { + 'command' => 'cloudwatch', + 'subcommand' => 'get-metric-statistics', +}; + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + + $options{options}->add_options( + arguments => { + "metric:s" => { name => 'metric' }, + "period:s" => { name => 'period', default => 300 }, + "starttime:s" => { name => 'starttime' }, + "endtime:s" => { name => 'endtime' }, + "statistics:s" => { name => 'statistics', default => 'Average' }, + "exclude-statistics:s" => { name => 'exclude-statistics' }, + "object:s" => { name => 'object' }, + "warning:s" => { name => 'warning' }, + "critical:s" => { name => 'critical' }, + } + ); + $self->{result} = {}; + + return $self; +} + +sub check_options { + my ( $self, %options ) = @_; + $self->SUPER::init(%options); + + $self->{option_results}->{def_endtime} = $def_endtime; + + 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}->{metric} ) ) { + $self->{output}->add_option_msg( + severity => 'UNKNOWN', + short_msg => "Please give a metric to watch (cpu, disk, ...)." + ); + $self->{output}->option_exit(); + } + + if ( !defined( $self->{option_results}->{object} ) ) { + $self->{output}->add_option_msg( + severity => 'UNKNOWN', + short_msg => "Please give the object to request (instanceid, ...)." + ); + $self->{output}->option_exit(); + } + + if ( !defined( $self->{option_results}->{endtime} ) ) { + $self->{option_results}->{endtime} = + strftime( "%FT%H:%M:%S.000Z", + gmtime( $self->{option_results}->{def_endtime} ) ); + } + + if ( !defined( $self->{option_results}->{starttime} ) ) { + $self->{option_results}->{starttime} = + strftime( "%FT%H:%M:%S.000Z", + gmtime( $self->{option_results}->{def_endtime} - 600 ) ); + } + + # Getting some parameters + # statistics + if ( $self->{option_results}->{statistics} eq 'all' ) { + @{ $self->{option_results}->{statisticstab} } = split( /,/, $StatisticsType ); + } + else { + @{ $self->{option_results}->{statisticstab} } = split( /,/, $self->{option_results}->{statistics} ); + foreach my $curstate ( @{ $self->{option_results}->{statisticstab} } ) { + if ( !grep { /^$curstate$/ } split( /,/, $StatisticsType ) ) { + $self->{output}->add_option_msg( + severity => 'UNKNOWN', + short_msg => "The statistic $curstate doesn't exist." + ); + $self->{output}->option_exit(); + } + } + } + + # exclusions + if (defined($self->{option_results}->{'exclude-statistics'})){ + my @excludetab = split(/,/, $self->{option_results}->{'exclude-statistics'}); + my %array1 = map { $_ => 1 } @excludetab; + @{$self->{option_results}->{statisticstab}} = grep { not $array1{$_} } @{$self->{option_results}->{statisticstab}}; + } + + # Force Average statistic + if ( ! grep $_ eq 'Average', @{$self->{option_results}->{statisticstab}} ) { + my $statistics = join(',',@{ $self->{option_results}->{statisticstab} }); + if ( ! $statistics eq '' ) { + $statistics = $statistics . ',Average'; + } + else { + $statistics = 'Average'; + } + @{ $self->{option_results}->{statisticstab} } = split( /,/, $statistics ); + } +} + +sub manage_selection { + my ( $self, $metric ) = @_; + my @result; + + my @Dimensions = ( + { + 'Value' => $self->{option_results}->{object}, + 'Name' => $metric->{ObjectName} + } + ); + + if ( defined( $metric->{ExtraDimensions} ) ) { + push @Dimensions, $metric->{ExtraDimensions}; + } + + $apiRequest->{json} = { + 'StartTime' => $self->{option_results}->{starttime}, + 'EndTime' => $self->{option_results}->{endtime}, + 'Period' => $self->{option_results}->{period}, + 'MetricName' => $metric->{MetricName}, + 'Unit' => $metric->{Unit}, + 'Statistics' => $self->{option_results}->{statisticstab}, + 'Dimensions' => [@Dimensions], + 'Namespace' => $metric->{NameSpace} + }; +} + +sub run { + my ( $self, %options ) = @_; + + my ( $msg, $exit_code, $awsapi ); + + if ( defined( $CloudwatchMetrics->{ $self->{option_results}->{metric} } ) ) + { + load $CloudwatchMetrics->{ $self->{option_results}->{metric} },qw/cloudwatchCheck/; + cloudwatchCheck($self); + } + else { + $self->{output} + ->add_option_msg( short_msg => "Wrong option. Cannot find metric '" + . $self->{option_results}->{metric} + . "'." ); + $self->{output}->option_exit(); + } + + foreach my $metric ( @{ $self->{metric} } ) { + $self->manage_selection($metric); + $awsapi = $options{custom}; + $self->{command_return} = $awsapi->execReq($apiRequest); + $self->{output}->perfdata_add( + label => sprintf( + $metric->{Labels}->{PerfData}, + unit => $metric->{Labels}->{Unit} + ), + value => sprintf( + $metric->{Labels}->{Value}, + $self->{command_return}->{Datapoints}[0]->{Average} + ), + warning => $self->{perfdata}->get_perfdata_for_output( label => 'warning' ), + critical => $self->{perfdata}->get_perfdata_for_output( label => 'critical' ), + #min => 0, + #max => 100 + ); + $exit_code = $self->{perfdata}->threshold_check( + value => $self->{command_return}->{Datapoints}[0]->{Average}, + threshold => [ + { label => 'critical', 'exit_litteral' => 'critical' }, + { label => 'warning', exit_litteral => 'warning' } + ] + ); + + $self->{output}->output_add( + long_msg => sprintf( + $metric->{Labels}->{LongOutput}, + $self->{command_return}->{Datapoints}[0]->{Average} + ) + ); + + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf( + $metric->{Labels}->{ShortOutput}, + $self->{command_return}->{Datapoints}[0]->{Average} + ) + ); + } + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Get cloudwatch metrics. +This doc is partly based on the official AWS CLI documentation. + +=over 8 + +=item B<--exclude-statistics> + +(optional) Statistics to exclude from the query. 'Average' can't be excluded. + +=item B<--metric> + +Metric to query. + +=item B<--period> + +(optional) The granularity, in seconds, of the returned datapoints. period must be at least 60 seconds and must be a multiple of 60. The default value is 300. + +=item B<--start-time> + +(optional) The time stamp to use for determining the first datapoint to return. The value specified is inclusive; results include datapoints with the time stamp specified. +exemple: 2014-04-09T23:18:00 + +=item B<--end-time> + +(optional) The time stamp to use for determining the last datapoint to return. The value specified is exclusive; results will include datapoints up to the time stamp specified. +exemple: 2014-04-09T23:18:00 + +=item B<--statistics> + +(optional) The metric statistics to return. For information about specific statistics returned by GetMetricStatistics, go to statistics in the Amazon CloudWatch Developer Guide. +Valid Values: Average | Sum | SampleCount | Maximum | Minimum +Average is the default and always included. +'all' for all statistics values. + +=item B<--object> + +Name of the object to request (InstanceId for an EC2 instance, for exemple). + +=item B<--warning> + +(optional) Threshold warning. + +=item B<--critical> + +(optional) Threshold critical. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/mode/instancestate.pm b/centreon-plugins/cloud/aws/mode/instancestate.pm new file mode 100644 index 000000000..966d68565 --- /dev/null +++ b/centreon-plugins/cloud/aws/mode/instancestate.pm @@ -0,0 +1,207 @@ +# +# 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 cloud::aws::mode::instancestate; + +use base qw(centreon::plugins::mode); + +use strict; +use warnings; +use centreon::plugins::misc; +use Data::Dumper; +use JSON; + +my %EC2_instance_states = ( + 'pending' => 'WARNING', + 'running' => 'OK', + 'shutting-down' => 'CRITICAL', + 'terminated' => 'CRITICAL', + 'stopping' => 'CRITICAL', + 'stopped' => 'CRITICAL' +); + +my $apiRequest = { + 'command' => 'ec2', + 'subcommand' => 'describe-instance-status', +}; + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + + $options{options}->add_options( + arguments => { + "state:s" => { name => 'state', default => 'all' }, + "no-includeallinstances" => { name => 'includeallinstances' }, + "exclude:s" => { name => 'exclude' }, + "instanceid:s" => { name => 'instanceid' } + } + ); + $self->{result} = {}; + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub manage_selection { + my ($self, %options) = @_; + + my (@result, $awsapi); + + # Getting some parameters + # includeallinstances + if (defined($self->{option_results}->{includeallinstances})) { + $self->{option_results}->{includeallinstances} = JSON::false; + } else { + $self->{option_results}->{includeallinstances} = JSON::true; + } + + # states + if ($self->{option_results}->{state} eq 'all') { + @{$self->{option_results}->{statetab} } = keys %EC2_instance_states; + } else { + @{$self->{option_results}->{statetab}} = split /,/, $self->{option_results}->{state}; + foreach my $curstate (@{$self->{option_results}->{statetab}}) { + if (!grep { /^$curstate$/ } keys(%EC2_instance_states)) { + $self->{output}->add_option_msg(severity => 'UNKNOWN', short_msg => "The state doesn't exist."); + $self->{output}->option_exit(); + } + } + } + + # exclusions + if (defined($self->{option_results}->{exclude})) { + my @excludetab = split /,/, $self->{option_results}->{exclude}; + my %array1 = map { $_ => 1 } @excludetab; + @{$self->{option_results}->{statetab}} = grep { not $array1{$_} } @{$self->{option_results}->{statetab}}; + } + my $states = join(',',@{$self->{option_results}->{statetab}}); + + # Getting data from AWS + # Building JSON + $apiRequest->{json} = { + 'DryRun' => JSON::false, + 'IncludeAllInstances' => $self->{option_results}->{includeallinstances}, + 'Filters' => [ + { + 'Name' => 'instance-state-name', + 'Values' => $self->{option_results}->{statetab}, + }], + }; + # InstanceIds + if (defined($self->{option_results}->{instanceid})) { + my @InstanceIds = split(/,/, $self->{option_results}->{instanceid}); + @{$apiRequest->{json}{InstanceIds}} = @InstanceIds; + } + + # Requesting API + $awsapi = $options{custom}; + $self->{command_return} = $awsapi->execReq($apiRequest); + + # Compute data + $self->{option_results}->{instancecount}->{total} = 0; + foreach my $curstate (@{$self->{option_results}->{statetab}}) { + $self->{option_results}->{instancecount}->{$curstate} = 0; + } + foreach my $l (@{$self->{command_return}->{InstanceStatuses}}) { + $self->{result}->{instance}->{$l->{InstanceId}} = $l->{InstanceState}->{Name}; + + # long output for each instance + $self->{output}->output_add(long_msg => "'" . $l->{InstanceId} . "' [state = " . $l->{InstanceState}->{Name} . ']'); + + foreach my $curstate (@{$self->{option_results}->{statetab}}) { + if ($l->{InstanceState}->{Name} eq $curstate) { + $self->{option_results}->{instancecount}->{$curstate}++; + } + } + $self->{option_results}->{instancecount}->{total}++; + } +} + +sub run { + my ( $self, %options ) = @_; + + my ( $msg, $exit_code ); + my $old_status = 'OK'; + + $self->manage_selection(%options); + + # Send formated data to Centreon + # Perf data + $self->{output}->perfdata_add( + label => 'total', + value => $self->{option_results}->{instancecount}->{'total'}, + ); + + foreach my $curstate (@{$self->{option_results}->{statetab}}) { + $self->{output}->perfdata_add( + label => $curstate, + value => $self->{option_results}->{instancecount}->{$curstate}, + ); + + # Most critical state + if ($self->{option_results}->{instancecount}->{$curstate} != 0) { + $exit_code = $EC2_instance_states{$curstate}; + $exit_code = $self->{output}->get_most_critical(status => [ $exit_code, $old_status ]); + $old_status = $exit_code; + } + } + + # Output message + $self->{output}->output_add( + severity => $exit_code, + short_msg => sprintf("Total instances: %s", $self->{option_results}->{instancecount}->{total}) + ); + + $self->{output}->display(); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +Get the state of your EC2 instances (running, stopped, ...) + +=over 8 + +=item B<--state> + +(optional) Specific state to query. + +=item B<--no-includeallinstances> + +(optional) Includes the health status for running instances only. + +=item B<--exclude> + +(optional) State to exclude from the query. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/mode/list.pm b/centreon-plugins/cloud/aws/mode/list.pm new file mode 100644 index 000000000..38da746c7 --- /dev/null +++ b/centreon-plugins/cloud/aws/mode/list.pm @@ -0,0 +1,245 @@ +# +# 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 cloud::aws::mode::list; + +use base qw(centreon::plugins::mode); +use strict; +use warnings; +use centreon::plugins::misc; +use Data::Dumper; +use JSON; + +my $AWSServices = 'EC2,S3,RDS'; +my @Disco_service_tab = ('EC2', 'RDS'); +my @EC2_instance_states = [ 'running', 'stopped' ]; + +my $awsapi; + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + + $options{options}->add_options( + arguments => { + "service:s" => { name => 'service', default => $AWSServices }, + "exclude:s" => { name => 'exclude' }, + } + ); + $self->{result} = {}; + return $self; +} + +sub check_options { + my ($self, %options) = @_; + $self->SUPER::init(%options); +} + +sub api_request { + my ($self, %options) = @_; + + @{$self->{option_results}->{servicetab}} = split( /,/, $self->{option_results}->{service} ); + foreach my $service (@{$self->{option_results}->{servicetab}}) { + $self->{result}->{count}->{$service} = 0; + if ($service eq 'EC2') { + $self->EC2(%options); + } elsif ($service eq 'S3') { + $self->S3(%options); + } elsif ($service eq 'RDS') { + $self->RDS(%options); + } else { + $self->{output}->add_option_msg(short_msg => "Service $service doesn't exists" ); + $self->{output}->option_exit(); + } + } +} + +sub EC2 { + my ( $self, %options ) = @_; + + my $apiRequest = { + 'command' => 'ec2', + 'subcommand' => 'describe-instances', + }; + + # Building JSON + $apiRequest->{json} = { + 'DryRun' => JSON::false, + 'Filters' => [ + { + 'Name' => 'instance-state-name', + 'Values' => @EC2_instance_states, + } + ], + }; + + # Requesting API + $awsapi = $options{custom}; + $self->{command_return} = $awsapi->execReq($apiRequest); + + # Compute data + foreach my $instance (@{$self->{command_return}->{Reservations}}) { + foreach my $tags (@{$instance->{Instances}[0]->{Tags}}) { + if ($tags->{Key} eq 'Name') { + $instance->{Instances}[0]->{Name} = $tags->{Value}; + } + } + $self->{result}->{'EC2'}->{$instance->{Instances}[0]->{InstanceId}} = + { + State => $instance->{Instances}[0]->{State}->{Name}, + Name => $instance->{Instances}[0]->{Name} + }; + + $self->{result}->{count}->{'EC2'}++; + } +} + +sub S3 { + my ( $self, %options ) = @_; + my ( @buckets, @return ) = (); + + my $apiRequest = { + 'command' => 's3', + 'subcommand' => 'ls', + 'output' => 'text' + }; + + # Requesting API + $awsapi = $options{custom}; + $self->{command_return} = $awsapi->execReq($apiRequest); + + # Exec command + foreach my $line (@{$self->{command_return}}) { + my ($date, $time, $name) = split / /, $line; + my $creationdate = $date . " " . $time; + push(@buckets, { Name => $name, CreationDate => $creationdate }); + } + + # Compute data + foreach my $bucket (@buckets) { + $self->{result}->{'S3'}->{ $bucket->{Name} } = + { Creation date => $bucket->{CreationDate} }; + $self->{result}->{count}->{'S3'}++; + } +} + +sub RDS { + my ( $self, %options ) = @_; + + my $apiRequest = { + 'command' => 'rds', + 'subcommand' => 'describe-db-instances', + }; + + # Requesting API + $awsapi = $options{custom}; + $self->{command_return} = $awsapi->execReq($apiRequest); + + # Compute data + foreach my $dbinstance (@{$self->{command_return}->{DBInstances}}) { + $self->{result}->{'RDS'}->{$dbinstance->{DBInstanceIdentifier}} = { + State => $dbinstance->{DBInstanceStatus}, + Name => $dbinstance->{DBInstanceIdentifier} + }; + $self->{result}->{count}->{RDS}++; + } +} + +sub disco_format { + my ( $self, %options ) = @_; + + my $names = [ 'name', 'id', 'state', 'service' ]; + $self->{output}->add_disco_format( elements => $names ); +} + +sub disco_show { + my ( $self, %options ) = @_; + + $self->api_request(%options); + foreach my $service (@Disco_service_tab) { + foreach my $device (keys %{$self->{result}->{$service}}) { + $self->{output}->add_disco_entry( + name => $self->{result}->{$service}->{$device}->{Name}, + id => $device, + state => $self->{result}->{$service}->{$device}->{State}, + service => $service, + ); + } + } +} + +sub run { + my ( $self, %options ) = @_; + + $self->api_request(%options); + + # Send formated data to Centreon + foreach my $service (@{$self->{option_results}->{servicetab}}) { + $self->{output}->output_add(long_msg => sprintf("AWS service: %s", $service)); + foreach my $device (keys %{$self->{result}->{$service}}) { + my $output = $device . " ["; + foreach my $value (sort(keys %{$self->{result}->{$service}->{$device}})) { + $output = + $output + . $value . " = " + . $self->{result}->{$service}->{$device}->{$value} . ", "; + } + $output =~ s/, $//; + $output = $output . "]"; + $self->{output}->output_add( long_msg => $output ); + } + $self->{output}->output_add( + short_msg => sprintf( "%s: %s", + $service, $self->{result}->{count}->{$service} ) + ); + } + + $self->{output}->display( + nolabel => 1, + force_ignore_perfdata => 1, + force_long_output => 1 + ); + $self->{output}->exit(); +} + +1; + +__END__ + +=head1 MODE + +List your EC2, RDS instance and S3 buckets + +=over 8 + +=item B<--service> + +(optional) List one particular service. + +=item B<--exclude> + +(optional) Service to exclude from the scan. + +=back + +=cut diff --git a/centreon-plugins/cloud/aws/mode/metrics/ec2instancecpu.pm b/centreon-plugins/cloud/aws/mode/metrics/ec2instancecpu.pm new file mode 100644 index 000000000..221427073 --- /dev/null +++ b/centreon-plugins/cloud/aws/mode/metrics/ec2instancecpu.pm @@ -0,0 +1,51 @@ +# +# 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 cloud::aws::mode::metrics::ec2instancecpu; + +use strict; +use warnings; +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(&cloudwatchCheck); + +my @Param; + +$Param[0] = { + 'NameSpace' => 'AWS/EC2', + 'MetricName' => 'CPUUtilization', + 'ObjectName' => 'InstanceId', + 'Unit' => 'Percent', + 'Labels' => { + 'ShortOutput' => "CPU Usage is %.2f%%", + 'LongOutput' => "CPU Usage is %.2f%%", + 'PerfData' => 'cpu', + 'Unit' => '%', + 'Value' => "%.2f", + } +}; + +sub cloudwatchCheck { + my ($self) = @_; + + @{ $self->{metric} } = @Param; +} + +1; diff --git a/centreon-plugins/cloud/aws/mode/metrics/ec2instancecpucreditbalance.pm b/centreon-plugins/cloud/aws/mode/metrics/ec2instancecpucreditbalance.pm new file mode 100644 index 000000000..4158f2dc8 --- /dev/null +++ b/centreon-plugins/cloud/aws/mode/metrics/ec2instancecpucreditbalance.pm @@ -0,0 +1,51 @@ +# +# 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 cloud::aws::mode::metrics::ec2instancecpucreditbalance; + +use strict; +use warnings; +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(&cloudwatchCheck); + +my @Param; + +$Param[0] = { + 'NameSpace' => 'AWS/EC2', + 'MetricName' => 'CPUCreditBalance', + 'ObjectName' => 'InstanceId', + 'Unit' => 'Count', + 'Labels' => { + 'ShortOutput' => "CPUCreditBalance is %.2f%%", + 'LongOutput' => "CPUCreditBalance is %.2f%%", + 'PerfData' => 'CPUCreditBalance', + 'Unit' => 'Count', + 'Value' => "%.2f", + } +}; + +sub cloudwatchCheck { + my ($self) = @_; + + @{ $self->{metric} } = @Param; +} + +1; diff --git a/centreon-plugins/cloud/aws/mode/metrics/ec2instancecpucreditusage.pm b/centreon-plugins/cloud/aws/mode/metrics/ec2instancecpucreditusage.pm new file mode 100644 index 000000000..7b41e2696 --- /dev/null +++ b/centreon-plugins/cloud/aws/mode/metrics/ec2instancecpucreditusage.pm @@ -0,0 +1,51 @@ +# +# 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 cloud::aws::mode::metrics::ec2instancecpucreditusage; + +use strict; +use warnings; +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(&cloudwatchCheck); + +my @Param; + +$Param[0] = { + 'NameSpace' => 'AWS/EC2', + 'MetricName' => 'CPUCreditUsage', + 'ObjectName' => 'InstanceId', + 'Unit' => 'Count', + 'Labels' => { + 'ShortOutput' => "CPUCreditUsage is %.2f%%", + 'LongOutput' => "CPUCreditUsage is %.2f%%", + 'PerfData' => 'CPUCreditUsage', + 'Unit' => 'Count', + 'Value' => "%.2f", + } +}; + +sub cloudwatchCheck { + my ($self) = @_; + + @{ $self->{metric} } = @Param; +} + +1; diff --git a/centreon-plugins/cloud/aws/mode/metrics/ec2instancenetwork.pm b/centreon-plugins/cloud/aws/mode/metrics/ec2instancenetwork.pm new file mode 100644 index 000000000..3eea9ef7f --- /dev/null +++ b/centreon-plugins/cloud/aws/mode/metrics/ec2instancenetwork.pm @@ -0,0 +1,65 @@ +# +# 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 cloud::aws::mode::metrics::ec2instancenetwork; + +use strict; +use warnings; +use Data::Dumper; +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(&cloudwatchCheck); + +my @Param; + +$Param[0] = { + 'NameSpace' => 'AWS/EC2', + 'MetricName' => 'NetworkIn', + 'ObjectName' => 'InstanceId', + 'Unit' => 'Bytes', + 'Labels' => { + 'ShortOutput' => "Traffic In %s Bytes", + 'LongOutput' => "Traffic In %s Bytes", + 'PerfData' => 'traffic_in', + 'Unit' => 'B', + 'Value' => "%.2f", + } +}; + +$Param[1] = { + 'NameSpace' => 'AWS/EC2', + 'MetricName' => 'NetworkOut', + 'ObjectName' => 'InstanceId', + 'Labels' => { + 'ShortOutput' => "Traffic Out %s Bytes", + 'LongOutput' => "Traffic Out %s Bytes", + 'PerfData' => 'traffic_out', + 'Unit' => 'B', + 'Value' => "%.2f", + } +}; + +sub cloudwatchCheck { + my ($self) = @_; + + @{ $self->{metric} } = @Param; +} + +1; diff --git a/centreon-plugins/cloud/aws/mode/metrics/rdsinstancecpu.pm b/centreon-plugins/cloud/aws/mode/metrics/rdsinstancecpu.pm new file mode 100644 index 000000000..48b8f88ec --- /dev/null +++ b/centreon-plugins/cloud/aws/mode/metrics/rdsinstancecpu.pm @@ -0,0 +1,53 @@ +# +# 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 cloud::aws::mode::metrics::rdsinstancecpu; + +use strict; +use warnings; +use POSIX; +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(&cloudwatchCheck); + +my @Param; + +$Param[0] = { + 'NameSpace' => 'AWS/RDS', + 'MetricName' => 'CPUUtilization', + 'ObjectName' => 'DBInstanceIdentifier', + 'Unit' => 'Percent', + 'Labels' => { + 'ShortOutput' => "CPU Usage is %.2f%%", + 'LongOutput' => "CPU Usage is %.2f%%", + 'PerfData' => 'cpu', + 'Unit' => '%', + 'Value' => "%.2f", + } +}; + +sub cloudwatchCheck { + my ($self) = @_; + + @{ $self->{metric} } = @Param; + $self->{option_results}->{starttime} = strftime( "%FT%H:%M:%S.000Z", gmtime( $self->{option_results}->{def_endtime} - 300 ) ); +} + +1; diff --git a/centreon-plugins/cloud/aws/mode/metrics/s3bucketsize.pm b/centreon-plugins/cloud/aws/mode/metrics/s3bucketsize.pm new file mode 100644 index 000000000..799ff2f41 --- /dev/null +++ b/centreon-plugins/cloud/aws/mode/metrics/s3bucketsize.pm @@ -0,0 +1,74 @@ +# +# 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 cloud::aws::mode::metrics::s3bucketsize; + +use strict; +use warnings; +use POSIX; +use Exporter; +our @ISA = qw(Exporter); +our @EXPORT = qw(&cloudwatchCheck); + +my @Param; + +$Param[0] = { + 'NameSpace' => 'AWS/S3', + 'MetricName' => 'BucketSizeBytes', + 'ObjectName' => 'BucketName', + 'Unit' => 'Bytes', + 'ExtraDimensions' => { + 'Name' => 'StorageType', + 'Value'=> 'StandardStorage' + }, + 'Labels' => { + 'ShortOutput' => "Bucket size is %s Bytes", + 'LongOutput' => "Bucket size is %s Bytes", + 'PerfData' => 'size', + 'Unit' => 'Bytes', + 'Value' => "%s", + } +}; +$Param[1] = { + 'NameSpace' => 'AWS/S3', + 'MetricName' => 'NumberOfObjects', + 'ObjectName' => 'BucketName', + 'Unit' => 'Count', + 'ExtraDimensions' => { + 'Name' => 'StorageType', + 'Value'=> 'AllStorageTypes' + }, + 'Labels' => { + 'ShortOutput' => "Number of objects is %s", + 'LongOutput' => "Number of objects is %s", + 'PerfData' => 'number', + 'Unit' => '', + 'Value' => "%s", + } +}; + +sub cloudwatchCheck { + my ($self) = @_; + + @{ $self->{metric} } = @Param; + $self->{option_results}->{starttime} = strftime( "%FT%H:%M:%S.000Z", gmtime( $self->{option_results}->{def_endtime} - 86400 ) ); +} + +1; diff --git a/centreon-plugins/cloud/aws/plugin.pm b/centreon-plugins/cloud/aws/plugin.pm new file mode 100644 index 000000000..30eafebb6 --- /dev/null +++ b/centreon-plugins/cloud/aws/plugin.pm @@ -0,0 +1,66 @@ +# +# 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 cloud::aws::plugin; + +use strict; +use warnings; +use base qw(centreon::plugins::script_custom); + +sub new { + my ( $class, %options ) = @_; + my $self = $class->SUPER::new( package => __PACKAGE__, %options ); + bless $self, $class; + + $self->{version} = '0.1'; + %{ $self->{modes} } = ( + 'instancestate' => 'cloud::aws::mode::instancestate', + 'list' => 'cloud::aws::mode::list', + 'cloudwatch' => 'cloud::aws::mode::cloudwatch', + ); + + $self->{custom_modes}{awscli} = 'cloud::aws::custom::awscli'; + return $self; +} + +sub init { + my ( $self, %options ) = @_; + + $self->SUPER::init(%options); +} + +1; + +__END__ + +=head1 PLUGIN DESCRIPTION + +Check Amazon AWS cloud. + +=over 8 + +For this plugin to work, you have to install and configure: +awscli (http://docs.aws.amazon.com/cli/latest/userguide/installing.html#install-bundle-other-os). +perl-json +perl-Module-Load + +=back + +=cut diff --git a/centreon-plugins/network/citrix/netscaler/common/mode/connections.pm b/centreon-plugins/network/citrix/netscaler/common/mode/connections.pm index 888099a3a..91e250130 100644 --- a/centreon-plugins/network/citrix/netscaler/common/mode/connections.pm +++ b/centreon-plugins/network/citrix/netscaler/common/mode/connections.pm @@ -24,6 +24,39 @@ use base qw(centreon::plugins::mode); use strict; use warnings; +use centreon::plugins::values; + +my $maps_counters = { + global => { + '000_active' => { set => { + key_values => [ { name => 'active' } ], + output_template => 'Active Server TCP connections : %s', + perfdatas => [ + { label => 'active_server', value => 'active_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + '001_server' => { set => { + key_values => [ { name => 'server' } ], + output_template => 'Server TCP connections : %s', + perfdatas => [ + { label => 'server', value => 'server_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + '002_client' => { set => { + key_values => [ { name => 'client' } ], + output_template => 'Client TCP connections : %s', + perfdatas => [ + { label => 'client', value => 'client_absolute', template => '%s', + unit => 'con', min => 0 }, + ], + } + }, + }, +}; sub new { my ($class, %options) = @_; @@ -33,13 +66,24 @@ sub new { $self->{version} = '1.0'; $options{options}->add_options(arguments => { - "warning-server:s" => { name => 'warning_server' }, - "critical-server:s" => { name => 'critical_server' }, - "warning-active:s" => { name => 'warning_active' }, - "critical-active:s" => { name => 'critical_active' }, - "warning-client:s" => { name => 'warning_client' }, - "critical-client:s" => { name => 'critical_client' }, }); + + foreach my $key (('global')) { + foreach (keys %{$maps_counters->{$key}}) { + my ($id, $name) = split /_/; + if (!defined($maps_counters->{$key}->{$_}->{threshold}) || $maps_counters->{$key}->{$_}->{threshold} != 0) { + $options{options}->add_options(arguments => { + 'warning-' . $name . ':s' => { name => 'warning-' . $name }, + 'critical-' . $name . ':s' => { name => 'critical-' . $name }, + }); + } + $maps_counters->{$key}->{$_}->{obj} = centreon::plugins::values->new(output => $self->{output}, + perfdata => $self->{perfdata}, + label => $name); + $maps_counters->{$key}->{$_}->{obj}->set(%{$maps_counters->{$key}->{$_}->{set}}); + } + } + return $self; } @@ -47,73 +91,79 @@ sub check_options { my ($self, %options) = @_; $self->SUPER::init(%options); - if (($self->{perfdata}->threshold_validate(label => 'warning-server', value => $self->{option_results}->{warning_server})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-server threshold '" . $self->{option_results}->{warning_server} . "'."); - $self->{output}->option_exit(); + foreach my $key (('global')) { + foreach (keys %{$maps_counters->{$key}}) { + $maps_counters->{$key}->{$_}->{obj}->init(option_results => $self->{option_results}); + } } - if (($self->{perfdata}->threshold_validate(label => 'critical-server', value => $self->{option_results}->{critical_server})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-server threshold '" . $self->{option_results}->{critical_server} . "'."); - $self->{output}->option_exit(); +} + +sub run_global { + my ($self, %options) = @_; + + my ($short_msg, $short_msg_append, $long_msg, $long_msg_append) = ('', '', '', ''); + my @exits; + foreach (sort keys %{$maps_counters->{global}}) { + my $obj = $maps_counters->{global}->{$_}->{obj}; + + $obj->set(instance => 'global'); + + my ($value_check) = $obj->execute(values => $self->{global}); + + if ($value_check != 0) { + $long_msg .= $long_msg_append . $obj->output_error(); + $long_msg_append = ', '; + next; + } + my $exit2 = $obj->threshold_check(); + push @exits, $exit2; + + my $output = $obj->output(); + $long_msg .= $long_msg_append . $output; + $long_msg_append = ', '; + + if (!$self->{output}->is_status(litteral => 1, value => $exit2, compare => 'ok')) { + $short_msg .= $short_msg_append . $output; + $short_msg_append = ', '; + } + + $obj->perfdata(); } - if (($self->{perfdata}->threshold_validate(label => 'warning-active', value => $self->{option_results}->{warning_active})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-active threshold '" . $self->{option_results}->{warning_active} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-active', value => $self->{option_results}->{critical_active})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-active threshold '" . $self->{option_results}->{critical_active} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'warning-client', value => $self->{option_results}->{warning_client})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong warning-client threshold '" . $self->{option_results}->{warning_client} . "'."); - $self->{output}->option_exit(); - } - if (($self->{perfdata}->threshold_validate(label => 'critical-client', value => $self->{option_results}->{critical_client})) == 0) { - $self->{output}->add_option_msg(short_msg => "Wrong critical-client threshold '" . $self->{option_results}->{critical_client} . "'."); - $self->{output}->option_exit(); + + my $exit = $self->{output}->get_most_critical(status => [ @exits ]); + if (!$self->{output}->is_status(litteral => 1, value => $exit, compare => 'ok')) { + $self->{output}->output_add(severity => $exit, + short_msg => "$short_msg" + ); + } else { + $self->{output}->output_add(short_msg => "$long_msg"); } } sub run { my ($self, %options) = @_; - # $options{snmp} = snmp object $self->{snmp} = $options{snmp}; + + $self->manage_selection(); + $self->run_global(); + + $self->{output}->display(); + $self->{output}->exit(); +} +sub manage_selection { + my ($self, %options) = @_; + + $self->{global} = { client => 0, server => 0, active => 0 }; my $oid_tcpCurServerConn = '.1.3.6.1.4.1.5951.4.1.1.46.1.0'; my $oid_tcpCurClientConn = '.1.3.6.1.4.1.5951.4.1.1.46.2.0'; my $oid_tcpActiveServerConn = '.1.3.6.1.4.1.5951.4.1.1.46.8.0'; my $result = $self->{snmp}->get_leef(oids => [$oid_tcpCurServerConn, $oid_tcpCurClientConn, $oid_tcpActiveServerConn ], nothing_quit => 1); - - my $exit_server = $self->{perfdata}->threshold_check(value => $result->{$oid_tcpCurServerConn}, - threshold => [ { label => 'critical-server', exit_litteral => 'critical' }, { label => 'warning-server', exit_litteral => 'warning' } ]); - my $exit_client = $self->{perfdata}->threshold_check(value => $result->{$oid_tcpCurClientConn}, - threshold => [ { label => 'critical-client', exit_litteral => 'critical' }, { label => 'warning-client', exit_litteral => 'warning' } ]); - my $exit_active = $self->{perfdata}->threshold_check(value => $result->{$oid_tcpActiveServerConn}, - threshold => [ { label => 'critical-active', exit_litteral => 'critical' }, { label => 'warning-active', exit_litteral => 'warning' } ]); - my $exit = $self->{output}->get_most_critical(status => [$exit_server, $exit_client, $exit_active]); - - $self->{output}->output_add(severity => $exit, - short_msg => sprintf("Connections: Client=%s Server=%s (activeServer=%s)", - $result->{$oid_tcpCurClientConn}, $result->{$oid_tcpCurServerConn}, $result->{$oid_tcpActiveServerConn})); - - $self->{output}->perfdata_add(label => "client", unit => 'con', - value => $result->{$oid_tcpCurClientConn}, - warning => $self->{option_results}->{warning_client}, - critical => $self->{option_results}->{critical_client}, - min => 0); - $self->{output}->perfdata_add(label => "server", unit => 'con', - value => $result->{$oid_tcpCurServerConn}, - warning => $self->{option_results}->{warning_server}, - critical => $self->{option_results}->{critical_server}, - min => 0); - $self->{output}->perfdata_add(label => "activeServer", unit => 'con', - value => $result->{$oid_tcpActiveServerConn}, - warning => $self->{option_results}->{warning_active}, - critical => $self->{option_results}->{critical_active}, - min => 0); - $self->{output}->display(); - $self->{output}->exit(); + $self->{global}->{client} = $result->{$oid_tcpCurClientConn}; + $self->{global}->{server} = $result->{$oid_tcpCurServerConn}; + $self->{global}->{active} = $result->{$oid_tcpActiveServerConn}; } - + 1; __END__ @@ -124,30 +174,16 @@ Check connections usage (Client, Server, ActiveServer) (NS-ROOT-MIBv2). =over 8 -=item B<--warning-server> +=item B<--warning-*> -Warning on number of server TCP connections +Threshold warning. +Can be: 'server', 'active', 'client'. -=item B<--critical-server> +=item B<--critical-*> -Critical on number of server TCP connections - -=item B<--warning-client> - -Warning on number of client TCP connections - -=item B<--critical-client> - -Critical on number of client TCP connections - -=item B<--warning-active> - -Warning on number of server Active TCP connections - -=item B<--critical-active> - -Critical on number of server Active TCP connections +Threshold critical. +Can be: 'server', 'active', 'client'. =back -=cut +=cut \ No newline at end of file diff --git a/centreon-plugins/network/juniper/common/screenos/mode/sessions.pm b/centreon-plugins/network/juniper/common/screenos/mode/sessions.pm index d890eb21e..9ee4e8f73 100644 --- a/centreon-plugins/network/juniper/common/screenos/mode/sessions.pm +++ b/centreon-plugins/network/juniper/common/screenos/mode/sessions.pm @@ -87,11 +87,13 @@ sub run { threshold => [ { label => 'critical', 'exit_litteral' => 'critical' }, { label => 'warning', exit_litteral => 'warning' } ]); my $exit_failed = $self->{perfdata}->threshold_check(value => $prct_failed, threshold => [ { label => 'critical-failed', 'exit_litteral' => 'critical' }, { label => 'warning-failed', exit_litteral => 'warning' } ]); - my $exit_code = $self->{output}->get_most_critical(status => [ $exit_failed, $exit_used ]); - $self->{output}->output_add(severity => $exit_code, + $self->{output}->output_add(severity => $exit_used, short_msg => sprintf("%.2f%% of the sessions limit reached (%d of max. %d)", $prct_used, $cp_used, $cp_total)); + $self->{output}->output_add(severity => $exit_failed, + short_msg => sprintf("%.2f%% of failed sessions (%d of max. %d)", + $prct_failed, $cp_failed, $cp_total)); $self->{output}->perfdata_add(label => 'sessions', value => $cp_used, diff --git a/centreon-plugins/os/aix/local/mode/errpt.pm b/centreon-plugins/os/aix/local/mode/errpt.pm index d81522a55..0308c1a26 100644 --- a/centreon-plugins/os/aix/local/mode/errpt.pm +++ b/centreon-plugins/os/aix/local/mode/errpt.pm @@ -225,8 +225,6 @@ Print error description in output. Filter resource (can use a regexp). -Set - =back =cut