+ add list cluters command

This commit is contained in:
garnier-quentin 2017-03-21 15:43:32 +01:00
parent a5eaa3bc72
commit edd843647b
2 changed files with 96 additions and 0 deletions

View File

@ -74,6 +74,7 @@ my @load_modules = (
'centreon::vmware::cmdgetmap',
'centreon::vmware::cmdhealthhost',
'centreon::vmware::cmdlimitvm',
'centreon::vmware::cmdlistclusters',
'centreon::vmware::cmdlistdatacenters',
'centreon::vmware::cmdlistdatastores',
'centreon::vmware::cmdlistnichost',

View File

@ -0,0 +1,95 @@
# 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 centreon::vmware::cmdlistclusters;
use base qw(centreon::vmware::cmdbase);
use strict;
use warnings;
use centreon::vmware::common;
sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(%options);
bless $self, $class;
$self->{commandName} = 'listclusters';
return $self;
}
sub checkArgs {
my ($self, %options) = @_;
if (defined($options{arguments}->{cluster}) && $options{arguments}->{cluster} eq "") {
$options{manager}->{output}->output_add(severity => 'UNKNOWN',
short_msg => "Argument error: cluster cannot be null");
return 1;
}
return 0;
}
sub initArgs {
my ($self, %options) = @_;
foreach (keys %{$options{arguments}}) {
$self->{$_} = $options{arguments}->{$_};
}
$self->{manager} = centreon::vmware::common::init_response();
$self->{manager}->{output}->{plugin} = $options{arguments}->{identity};
}
sub run {
my $self = shift;
my $multiple = 0;
my $filters = $self->build_filter(label => 'name', search_option => 'cluster', is_regexp => 'filter');
my @properties = ('name');
my $result = centreon::vmware::common::search_entities(command => $self, view_type => 'ClusterComputeResource', properties => \@properties, filter => $filters);
return if (!defined($result));
if (!defined($self->{disco_show})) {
$self->{manager}->{output}->output_add(severity => 'OK',
short_msg => 'List cluster(s):');
}
foreach my $cluster (@$result) {
if (defined($self->{disco_show})) {
$self->{manager}->{output}->add_disco_entry(name => $cluster->name);
} else {
$self->{manager}->{output}->output_add(long_msg => sprintf(" %s",
$cluster->name));
}
}
if (defined($self->{disco_show})) {
my $stdout;
{
local *STDOUT;
$self->{manager}->{output}->{option_results}->{output_xml} = 1;
open STDOUT, '>', \$stdout;
$self->{manager}->{output}->display_disco_show();
delete $self->{manager}->{output}->{option_results}->{output_xml};
$self->{manager}->{output}->output_add(severity => 'OK',
short_msg => $stdout);
}
}
}
1;