Optimize nic info from 'listnichost' command
git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@76 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
5a24f16343
commit
a349a883d8
|
@ -130,6 +130,7 @@ sub print_usage () {
|
|||
print " --nic Physical nic name to check (required)\n";
|
||||
print " -w (--warning) Warning Threshold in percent (default 80)\n";
|
||||
print " -c (--critical) Critical Threshold in percent (default 90)\n";
|
||||
print " --filter Use regexp for --nic option (can check multiple nics at once)\n";
|
||||
print "\n";
|
||||
print "'memhost':\n";
|
||||
print " -e (--esx-host) Esx Host to check (required)\n";
|
||||
|
@ -473,12 +474,17 @@ sub nethost_check_arg {
|
|||
if (!defined($OPTION{critical})) {
|
||||
$OPTION{critical} = 90;
|
||||
}
|
||||
if (defined($OPTION{filter})) {
|
||||
$OPTION{filter} = 1;
|
||||
} else {
|
||||
$OPTION{filter} = 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub nethost_get_str {
|
||||
return join($separatorin,
|
||||
('nethost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{nic}, $OPTION{warning}, $OPTION{critical}));
|
||||
('nethost', $OPTION{vsphere}, $OPTION{'esx-host'}, $OPTION{nic}, $OPTION{filter}, $OPTION{warning}, $OPTION{critical}));
|
||||
}
|
||||
|
||||
sub countvmhost_check_arg {
|
||||
|
|
|
@ -39,30 +39,45 @@ sub initArgs {
|
|||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
my %nic_in_vswitch = ();
|
||||
|
||||
my %filters = ('name' => $self->{lhost});
|
||||
my @properties = ('config.network.pnic');
|
||||
my @properties = ('config.network.pnic', 'config.network.vswitch');
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'HostSystem', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
# Get Name from vswitch
|
||||
foreach (@{$$result[0]->{'config.network.vswitch'}}) {
|
||||
foreach my $keynic (@{$_->pnic}) {
|
||||
$nic_in_vswitch{$keynic} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
my $status = 0; # OK
|
||||
my $output_up = 'Nic Up List: ';
|
||||
my $output_down = 'Nic Down List: ';
|
||||
my $output_down_no_vswitch = 'Nic Down List (not in vswitch): ';
|
||||
my $output_up_append = "";
|
||||
my $output_down_append = "";
|
||||
my $output_down_no_vswitch_append = "";
|
||||
foreach (@{$$result[0]->{'config.network.pnic'}}) {
|
||||
if (defined($_->linkSpeed)) {
|
||||
$output_up .= $output_up_append . "'" . $_->device . "'";
|
||||
$output_up_append = ', ';
|
||||
} else {
|
||||
$output_down .= $output_down_append . "'" . $_->device . "'";
|
||||
$output_down_append = ', ';
|
||||
if (defined($nic_in_vswitch{$_->key})) {
|
||||
$output_down .= $output_down_append . "'" . $_->device . "'";
|
||||
$output_down_append = ', ';
|
||||
} else {
|
||||
$output_down_no_vswitch .= $output_down_no_vswitch_append . "'" . $_->device . "'";
|
||||
$output_down_no_vswitch_append = ', ';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output_up. $output_down.\n");
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output_up. $output_down. $output_down_no_vswitch.\n");
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -52,8 +52,9 @@ sub initArgs {
|
|||
my $self = shift;
|
||||
$self->{lhost} = $_[0];
|
||||
$self->{pnic} = $_[1];
|
||||
$self->{warn} = (defined($_[2]) ? $_[2] : 80);
|
||||
$self->{crit} = (defined($_[3]) ? $_[3] : 90);
|
||||
$self->{filter} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
||||
$self->{warn} = (defined($_[3]) ? $_[3] : 80);
|
||||
$self->{crit} = (defined($_[4]) ? $_[4] : 90);
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
|
Loading…
Reference in New Issue