Fix errors and better management vsphere4/5
git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@83 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
840697991b
commit
452e7cdbbd
File diff suppressed because it is too large
Load Diff
|
@ -59,30 +59,45 @@ sub checkArgs {
|
|||
sub initArgs {
|
||||
my $self = shift;
|
||||
$self->{ds} = $_[0];
|
||||
$self->{warn} = (defined($_[1]) ? $_[1] : '');
|
||||
$self->{crit} = (defined($_[2]) ? $_[2] : '');
|
||||
$self->{warn2} = (defined($_[3]) ? $_[3] : '');
|
||||
$self->{crit2} = (defined($_[4]) ? $_[4] : '');
|
||||
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||
$self->{warn} = (defined($_[2]) ? $_[2] : '');
|
||||
$self->{crit} = (defined($_[3]) ? $_[3] : '');
|
||||
$self->{warn2} = (defined($_[4]) ? $_[4] : '');
|
||||
$self->{crit2} = (defined($_[5]) ? $_[5] : '');
|
||||
$self->{skip_errors} = (defined($_[6]) && $_[6] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
my %filters = ();
|
||||
|
||||
my %filters = ('summary.name' => $self->{ds});
|
||||
my @properties = ('summary.accessible', 'browser');
|
||||
if ($self->{filter} == 0) {
|
||||
$filters{name} = qr/^\Q$self->{ds}\E$/;
|
||||
} else {
|
||||
$filters{name} = qr/$self->{ds}/;
|
||||
}
|
||||
|
||||
my @properties = ('summary.accessible', 'summary.name', 'browser');
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'Datastore', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
return if (centreon::esxd::common::datastore_state($self->{obj_esxd}, $self->{ds}, $$result[0]->{'summary.accessible'}) == 0);
|
||||
|
||||
my @ds_array = ();
|
||||
my %ds_names = ();
|
||||
foreach my $entity_view (@$result) {
|
||||
next if (!centreon::esxd::common::is_accessible($entity_view->{'summary.accessible'}));
|
||||
if (defined($entity_view->browser)) {
|
||||
push @ds_array, $entity_view->browser;
|
||||
if ($self->{filter} == 1) {
|
||||
$ds_names{$entity_view->{mo_ref}->{value}} = $entity_view->{'summary.name'};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@properties = ();
|
||||
my $browse_ds;
|
||||
return if (!($browse_ds = centreon::esxd::common::get_view($self->{obj_esxd}, $$result[0]->{'browser'}, \@properties)));
|
||||
|
||||
my $snapshots;
|
||||
return if (!($snapshots = centreon::esxd::common::search_in_datastore($self->{obj_esxd}, $browse_ds, '[' . $self->{ds} . ']', [VmSnapshotFileQuery->new()])));
|
||||
my $result2;
|
||||
return if (!($result2 = centreon::esxd::common::get_views($self->{obj_esxd}, \@ds_array, \@properties)));
|
||||
|
||||
my $status = 0; # OK
|
||||
my $output = '';
|
||||
|
@ -91,46 +106,119 @@ sub run {
|
|||
my $output_warning_append = '';
|
||||
my $output_critical = "";
|
||||
my $output_critical_append = '';
|
||||
my $total_size = 0;
|
||||
my $output_warning_total = "";
|
||||
my $output_warning_total_append = '';
|
||||
my $output_critical_total = "";
|
||||
my $output_critical_total_append = '';
|
||||
my $output_unknown = '';
|
||||
my $output_unknown_append = '';
|
||||
my $output_ok_unit = '';
|
||||
my $perfdata = '';
|
||||
|
||||
foreach (@$snapshots) {
|
||||
if (defined($_->file)) {
|
||||
foreach my $x (@{$_->file}) {
|
||||
if (defined($self->{crit2}) && $self->{crit2} ne '' && $x->fileSize >= $self->{crit2}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||
"'" . $_->folderPath . ' => ' . $x->path . "'");
|
||||
} elsif (defined($self->{warn2}) && $self->{warn2} ne '' && $x->fileSize >= $self->{warn2}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
||||
"'" . $_->folderPath . ' => ' . $x->path . "'");
|
||||
}
|
||||
$total_size += $x->fileSize;
|
||||
foreach my $browse_ds (@$result2) {
|
||||
my $dsName;
|
||||
if ($self->{filter} == 1) {
|
||||
my $tmp_name = $browse_ds->{mo_ref}->{value};
|
||||
$tmp_name =~ s/^datastoreBrowser-//i;
|
||||
$dsName = $ds_names{$tmp_name};
|
||||
} else {
|
||||
$dsName = $self->{ds};
|
||||
}
|
||||
|
||||
my ($snapshots, $msg) = centreon::esxd::common::search_in_datastore($self->{obj_esxd}, $browse_ds, '[' . $dsName . ']', [VmSnapshotFileQuery->new()], 1);
|
||||
if (!defined($snapshots)) {
|
||||
$msg =~ s/\n/ /g;
|
||||
if ($msg =~ /NoPermissionFault/i) {
|
||||
$msg = "Not enough permissions";
|
||||
}
|
||||
if ($self->{skip_errors} == 0 || $self->{filter} == 0) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'UNKNOWN');
|
||||
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ",
|
||||
"'" . $dsName . "' $msg");
|
||||
}
|
||||
next;
|
||||
}
|
||||
|
||||
my $total_size = 0;
|
||||
my $lwarn = '';
|
||||
my $lcrit = '';
|
||||
foreach (@$snapshots) {
|
||||
if (defined($_->file)) {
|
||||
foreach my $x (@{$_->file}) {
|
||||
if (defined($self->{crit2}) && $self->{crit2} ne '' && $x->fileSize >= $self->{crit2}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$lwarn .= " [" . $_->folderPath . ']=>[' . $x->path . "]";
|
||||
} elsif (defined($self->{warn2}) && $self->{warn2} ne '' && $x->fileSize >= $self->{warn2}) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$lcrit .= " [" . $_->folderPath . ']=>[' . $x->path . "]";
|
||||
}
|
||||
$total_size += $x->fileSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($lcrit ne '') {
|
||||
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||
"'$dsName'" . $lcrit);
|
||||
}
|
||||
if ($lwarn ne '') {
|
||||
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
||||
"'$dsName'" . $lwarn);
|
||||
}
|
||||
|
||||
if (defined($self->{crit}) && $self->{crit} && $total_size >= $self->{crit}) {
|
||||
centreon::esxd::common::output_add(\$output_critical_total, \$output_critical_total_append, ", ",
|
||||
"'$dsName' Total snapshots used " . centreon::esxd::common::simplify_number($total_size / 1024 / 1024) . "MB");
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
} elsif (defined($self->{warn}) && $self->{warn} && $total_size >= $self->{warn}) {
|
||||
centreon::esxd::common::output_add(\$output_warning_total, \$output_warning_total_append, ", ",
|
||||
"'$dsName' Total snapshots used " . centreon::esxd::common::simplify_number($total_size / 1024 / 1024) . "MB");
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
} else {
|
||||
$output_ok_unit .= "'$dsName' Total snapshots size is ok.";
|
||||
}
|
||||
|
||||
if ($self->{filter} == 1) {
|
||||
$perfdata .= " 'total_size_" . $dsName . "'=" . $total_size . "o;$self->{warn};$self->{crit};0;";
|
||||
} else {
|
||||
$perfdata .= " 'total_size=" . $total_size . "o;$self->{warn};$self->{crit};0;";
|
||||
}
|
||||
}
|
||||
|
||||
if ($output_critical ne '') {
|
||||
$output .= "CRITICAL - Snapshot size exceed limit: $output_critical.";
|
||||
$output_append = " ";
|
||||
if ($output_unknown ne "") {
|
||||
$output .= $output_append . "UNKNOWN - $output_unknown";
|
||||
$output_append = ". ";
|
||||
}
|
||||
if ($output_warning ne '') {
|
||||
$output .= $output_append . "WARNING - Snapshot size exceed limit: $output_warning.";
|
||||
$output_append = " ";
|
||||
if ($output_critical_total ne '' || $output_critical ne '') {
|
||||
$output .= $output_append . "CRITICAL -";
|
||||
if ($output_critical_total ne '') {
|
||||
$output .= " " . $output_critical_total;
|
||||
$output_append = ' -';
|
||||
}
|
||||
if ($output_critical ne '') {
|
||||
$output .= $output_append . " Snapshots size exceed limit: " . $output_critical;
|
||||
}
|
||||
$output_append = '. ';
|
||||
}
|
||||
if ($output_warning_total ne '' || $output_warning ne '') {
|
||||
$output .= $output_append . "WARNING -";
|
||||
if ($output_warning_total ne '') {
|
||||
$output .= " " . $output_warning_total;
|
||||
$output_append = ' -';
|
||||
}
|
||||
if ($output_warning ne '') {
|
||||
$output .= $output_append . " Snapshots size exceed limit: " . $output_warning;
|
||||
}
|
||||
}
|
||||
if ($status == 0) {
|
||||
if ($self->{filter} == 1) {
|
||||
$output .= $output_append . "All Total snapshots size is ok";
|
||||
} else {
|
||||
$output .= $output_append . $output_ok_unit;
|
||||
}
|
||||
}
|
||||
|
||||
if (defined($self->{crit}) && $self->{crit} && $total_size >= $self->{crit}) {
|
||||
$output .= $output_append . "CRITICAL - Total snapshots size exceed limit: " . centreon::esxd::common::simplify_number($total_size / 1024 / 1024) . "MB.";
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
} elsif (defined($self->{warn}) && $self->{warn} && $total_size >= $self->{warn}) {
|
||||
$output .= $output_append . "WARNING - Total snapshots size exceed limit: " . centreon::esxd::common::simplify_number($total_size / 1024 / 1024) . "MB.";
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
} else {
|
||||
$output .= $output_append . "OK - Total snapshots size is ok.";
|
||||
}
|
||||
$output .= "|total_size=" . $total_size . "o;$self->{warn};$self->{crit};0;";
|
||||
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output|$perfdata\n");
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
@ -102,11 +102,14 @@ sub run {
|
|||
if (!centreon::esxd::common::is_accessible($ds->summary->accessible)) {
|
||||
if ($self->{skip_errors} == 0 || $self->{filter} == 0) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'UNKNOWN');
|
||||
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ",
|
||||
"'" . $ds->summary->name . "' not accessible. Can be disconnected");
|
||||
}
|
||||
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ",
|
||||
"'" . $ds->summary->name . "' not accessible. Can be disconnected");
|
||||
next;
|
||||
}
|
||||
|
||||
# capacity 0...
|
||||
next if ($ds->summary->capacity <= 0);
|
||||
|
||||
my $dsName = $ds->summary->name;
|
||||
my $capacity = $ds->summary->capacity;
|
||||
|
|
|
@ -38,6 +38,7 @@ sub initArgs {
|
|||
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||
$self->{warn} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
||||
$self->{crit} = (defined($_[3]) && $_[3] == 1) ? 1 : 0;
|
||||
$self->{disk} = (defined($_[4]) && $_[4] == 1) ? 1 : 0;
|
||||
if ($self->{warn} == 0 && $self->{crit} == 0) {
|
||||
$self->{warn} = 1;
|
||||
}
|
||||
|
@ -53,7 +54,12 @@ sub run {
|
|||
} else {
|
||||
$filters{name} = qr/$self->{lvm}/;
|
||||
}
|
||||
my @properties = ('name', 'config.hardware.device', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit');
|
||||
my @properties;
|
||||
push @properties, 'name', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit';
|
||||
if ($self->{disk} == 1) {
|
||||
push @properties, 'config.hardware.device';
|
||||
}
|
||||
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
|
@ -92,18 +98,20 @@ sub run {
|
|||
}
|
||||
|
||||
# Disk
|
||||
foreach my $device (@{$virtual->{'config.hardware.device'}}) {
|
||||
if ($device->isa('VirtualDisk')) {
|
||||
if ($self->{crit} == 1 && defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$limit_set_crit .= "/DISK"
|
||||
} elsif ($self->{warn} == 1 && defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$limit_set_warn .= "/DISK"
|
||||
if ($self->{disk} == 1) {
|
||||
foreach my $device (@{$virtual->{'config.hardware.device'}}) {
|
||||
if ($device->isa('VirtualDisk')) {
|
||||
if ($self->{crit} == 1 && defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$limit_set_crit .= "/DISK"
|
||||
} elsif ($self->{warn} == 1 && defined($device->storageIOAllocation->limit) && $device->storageIOAllocation->limit != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$limit_set_warn .= "/DISK"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Set
|
||||
if ($limit_set_crit ne '') {
|
||||
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||
|
|
|
@ -50,6 +50,7 @@ sub initArgs {
|
|||
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||
$self->{warning} = ((defined($_[2]) and $_[2] ne '') ? $_[2] : 86400 * 3);
|
||||
$self->{critical} = ((defined($_[3]) and $_[3] ne '') ? $_[3] : 86400 * 5);
|
||||
$self->{consolidate} = (defined($_[4]) && $_[4] == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
sub run {
|
||||
|
@ -68,7 +69,12 @@ sub run {
|
|||
} else {
|
||||
$filters{name} = qr/$self->{lvm}/;
|
||||
}
|
||||
my @properties = ('snapshot.rootSnapshotList', 'name');
|
||||
my @properties;
|
||||
push @properties, 'snapshot.rootSnapshotList', 'name';
|
||||
if ($self->{consolidate} == 1) {
|
||||
push @properties, 'runtime.consolidationNeeded';
|
||||
}
|
||||
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
|
@ -84,8 +90,16 @@ sub run {
|
|||
my $output_unknown = '';
|
||||
my $output_unknown_append = '';
|
||||
my $output_ok_unit = 'Snapshot(s) OK';
|
||||
my $consolidate_vms = '';
|
||||
my $consolidate_vms_append = '';
|
||||
|
||||
foreach my $virtual (@$result) {
|
||||
if ($self->{consolidate} == 1 && defined($virtual->{'runtime.consolidationNeeded'}) && ($virtual->{'runtime.consolidationNeeded'} == 1 || $virtual->{'runtime.consolidationNeeded'} =~ /^true$/i)) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$consolidate_vms .= $consolidate_vms_append . '[' . $virtual->{'name'} . ']';
|
||||
$consolidate_vms_append = ', ';
|
||||
}
|
||||
|
||||
if (!defined($virtual->{'snapshot.rootSnapshotList'})) {
|
||||
next;
|
||||
}
|
||||
|
@ -96,7 +110,7 @@ sub run {
|
|||
if (!defined($create_time)) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'UNKNOWN');
|
||||
centreon::esxd::common::output_add(\$output_unknown, \$output_unknown_append, ", ",
|
||||
"Can't Parse date '" . $snapshot->createTime . "' for vm '" . $virtual->{'name'} . "'");
|
||||
"Can't Parse date '" . $snapshot->createTime . "' for vm [" . $virtual->{'name'} . "]");
|
||||
next;
|
||||
}
|
||||
if (time() - $create_time >= $self->{critical}) {
|
||||
|
@ -117,6 +131,10 @@ sub run {
|
|||
$output .= $output_append . "UNKNOWN - $output_unknown";
|
||||
$output_append = ". ";
|
||||
}
|
||||
if ($consolidate_vms ne "") {
|
||||
$output .= $output_append . "CRITICAL - VMs need consolidation : " . $consolidate_vms;
|
||||
$output_append = ". ";
|
||||
}
|
||||
if ($output_critical ne "") {
|
||||
$output .= $output_append . "CRITICAL - Snapshots for VM older than " . ($self->{critical} / 86400) . " days: $output_critical";
|
||||
$output_append = ". ";
|
||||
|
|
|
@ -121,7 +121,7 @@ sub get_view {
|
|||
|
||||
sub search_in_datastore {
|
||||
my $obj_esxd = shift;
|
||||
my ($ds_browse, $ds_name, $query) = @_;
|
||||
my ($ds_browse, $ds_name, $query, $return) = @_;
|
||||
my $result;
|
||||
|
||||
my $files = FileQueryFlags->new(fileSize => 1,
|
||||
|
@ -136,6 +136,7 @@ sub search_in_datastore {
|
|||
searchSpec=>$hostdb_search_spec);
|
||||
};
|
||||
if ($@) {
|
||||
return (undef, $@) if (defined($return) && $return == 1);
|
||||
vmware_error($obj_esxd, $@);
|
||||
return undef;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue