+ Add limit command
git-svn-id: http://svn.merethis.net/centreon-esxd/trunk@82 a5eaa968-4c79-4d68-970d-af6011b5b055
This commit is contained in:
parent
4286250506
commit
840697991b
|
@ -184,6 +184,12 @@ sub print_usage () {
|
|||
print " --warning Warning threshold in seconds (default: 3 days)\n";
|
||||
print " --critical Critical threshold in seconds (default: 5 days)\n";
|
||||
print "\n";
|
||||
print "'limitvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " --filter Use regexp for --vm option (can check multiples vm at once)\n";
|
||||
print " --warn Warning threshold if set (default)\n";
|
||||
print " --crit Critical threshold if set\n";
|
||||
print "\n";
|
||||
print "'datastoresvm':\n";
|
||||
print " --vm VM to check (required)\n";
|
||||
print " -w (--warning) Warning Threshold in IOPS (default none)\n";
|
||||
|
@ -612,6 +618,35 @@ sub snapshotvm_get_str {
|
|||
('snapshotvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{warning}, $OPTION{critical}));
|
||||
}
|
||||
|
||||
sub limitvm_check_arg {
|
||||
if (!defined($OPTION{vm})) {
|
||||
print "Option --vm is required\n";
|
||||
print_usage();
|
||||
exit $ERRORS{UNKNOWN};
|
||||
}
|
||||
if (defined($OPTION{filter})) {
|
||||
$OPTION{filter} = 1;
|
||||
} else {
|
||||
$OPTION{filter} = 0;
|
||||
}
|
||||
if ((!defined($OPTION{warn}) && !defined($OPTION{crit})) || defined($OPTION{warn})) {
|
||||
$OPTION{warn} = 1;
|
||||
} else {
|
||||
$OPTION{warn} = 0;
|
||||
}
|
||||
if (!defined($OPTION{crit})) {
|
||||
$OPTION{crit} = 0;
|
||||
} else {
|
||||
$OPTION{crit} = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub limitvm_get_str {
|
||||
return join($separatorin,
|
||||
('limitvm', $OPTION{vsphere}, $OPTION{vm}, $OPTION{filter}, $OPTION{warn}, $OPTION{crit}));
|
||||
}
|
||||
|
||||
sub datastoresvm_check_arg {
|
||||
if (!defined($OPTION{vm})) {
|
||||
print "Option --vm is required\n";
|
||||
|
@ -794,7 +829,7 @@ if (!defined($OPTION{usage})) {
|
|||
print_usage();
|
||||
exit $ERRORS{UNKNOWN};
|
||||
}
|
||||
if ($OPTION{usage} !~ /^(healthhost|datastore-usage|datastore-io|datastore-snapshots|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|uptimehost|cpuvm|toolsvm|snapshotvm|datastoresvm|memvm|swapvm|thinprovisioningvm|listhost|listdatastore|listnichost|getmap|stats)$/) {
|
||||
if ($OPTION{usage} !~ /^(healthhost|datastore-usage|datastore-io|datastore-snapshots|maintenancehost|statushost|cpuhost|datastoreshost|nethost|memhost|swaphost|countvmhost|uptimehost|cpuvm|toolsvm|snapshotvm|limitvm|datastoresvm|memvm|swapvm|thinprovisioningvm|listhost|listdatastore|listnichost|getmap|stats)$/) {
|
||||
print "Usage value is unknown\n";
|
||||
print_usage();
|
||||
exit $ERRORS{UNKNOWN};
|
||||
|
|
|
@ -31,6 +31,7 @@ my @load_modules = ('centreon::esxd::cmdcountvmhost',
|
|||
'centreon::esxd::cmddatastoreusage',
|
||||
'centreon::esxd::cmdgetmap',
|
||||
'centreon::esxd::cmdhealthhost',
|
||||
'centreon::esxd::cmdlimitvm',
|
||||
'centreon::esxd::cmdlistdatastore',
|
||||
'centreon::esxd::cmdlisthost',
|
||||
'centreon::esxd::cmdlistnichost',
|
||||
|
|
|
@ -0,0 +1,136 @@
|
|||
|
||||
package centreon::esxd::cmdlimitvm;
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use centreon::esxd::common;
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my $self = {};
|
||||
$self->{logger} = shift;
|
||||
$self->{obj_esxd} = shift;
|
||||
$self->{commandName} = 'limitvm';
|
||||
|
||||
bless $self, $class;
|
||||
return $self;
|
||||
}
|
||||
|
||||
sub getCommandName {
|
||||
my $self = shift;
|
||||
return $self->{commandName};
|
||||
}
|
||||
|
||||
sub checkArgs {
|
||||
my $self = shift;
|
||||
my ($vm) = @_;
|
||||
|
||||
if (!defined($vm) || $vm eq "") {
|
||||
$self->{logger}->writeLogError("ARGS error: need vm hostname");
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
sub initArgs {
|
||||
my $self = shift;
|
||||
$self->{lvm} = $_[0];
|
||||
$self->{filter} = (defined($_[1]) && $_[1] == 1) ? 1 : 0;
|
||||
$self->{warn} = (defined($_[2]) && $_[2] == 1) ? 1 : 0;
|
||||
$self->{crit} = (defined($_[3]) && $_[3] == 1) ? 1 : 0;
|
||||
if ($self->{warn} == 0 && $self->{crit} == 0) {
|
||||
$self->{warn} = 1;
|
||||
}
|
||||
}
|
||||
|
||||
sub run {
|
||||
my $self = shift;
|
||||
|
||||
my %filters = ();
|
||||
|
||||
if ($self->{filter} == 0) {
|
||||
$filters{name} = qr/^\Q$self->{lvm}\E$/;
|
||||
} else {
|
||||
$filters{name} = qr/$self->{lvm}/;
|
||||
}
|
||||
my @properties = ('name', 'config.hardware.device', 'config.cpuAllocation.limit', 'config.memoryAllocation.limit');
|
||||
my $result = centreon::esxd::common::get_entities_host($self->{obj_esxd}, 'VirtualMachine', \%filters, \@properties);
|
||||
if (!defined($result)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
my $status = 0; # OK
|
||||
my $output = "";
|
||||
my $output_append = '';
|
||||
my $output_warning = '';
|
||||
my $output_warning_append = '';
|
||||
my $output_critical = '';
|
||||
my $output_critical_append = '';
|
||||
my $output_unknown = '';
|
||||
my $output_unknown_append = '';
|
||||
|
||||
foreach my $virtual (@$result) {
|
||||
my $limit_set_warn = '';
|
||||
my $limit_set_crit = '';
|
||||
|
||||
# CPU Limit
|
||||
if ($self->{crit} == 1 && defined($virtual->{'config.cpuAllocation.limit'}) && $virtual->{'config.cpuAllocation.limit'} != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$limit_set_crit = "/CPU"
|
||||
} elsif ($self->{warn} == 1 && defined($virtual->{'config.cpuAllocation.limit'}) && $virtual->{'config.cpuAllocation.limit'} != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$limit_set_warn = "/CPU"
|
||||
}
|
||||
|
||||
# Memory Limit
|
||||
if ($self->{crit} == 1 && defined($virtual->{'config.memoryAllocation.limit'}) && $virtual->{'config.memoryAllocation.limit'} != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'CRITICAL');
|
||||
$limit_set_crit .= "/MEM"
|
||||
} elsif ($self->{warn} == 1 && defined($virtual->{'config.memoryAllocation.limit'}) && $virtual->{'config.memoryAllocation.limit'} != -1) {
|
||||
$status = centreon::esxd::common::errors_mask($status, 'WARNING');
|
||||
$limit_set_warn .= "/MEM"
|
||||
}
|
||||
|
||||
# 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"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Set
|
||||
if ($limit_set_crit ne '') {
|
||||
centreon::esxd::common::output_add(\$output_critical, \$output_critical_append, ", ",
|
||||
"[" . $virtual->{'name'}. "]$limit_set_crit");
|
||||
} elsif ($limit_set_warn ne '') {
|
||||
centreon::esxd::common::output_add(\$output_warning, \$output_warning_append, ", ",
|
||||
"[" . $virtual->{'name'}. "]$limit_set_warn");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($output_unknown ne "") {
|
||||
$output .= $output_append . "UNKNOWN - $output_unknown";
|
||||
$output_append = ". ";
|
||||
}
|
||||
if ($output_critical ne "") {
|
||||
$output .= $output_append . "CRITICAL - Limits for VMs: $output_critical";
|
||||
$output_append = ". ";
|
||||
}
|
||||
if ($output_warning ne "") {
|
||||
$output .= $output_append . "WARNING - Limits for VMs: $output_warning";
|
||||
}
|
||||
if ($status == 0) {
|
||||
$output .= $output_append . "Limits are ok";
|
||||
}
|
||||
|
||||
$self->{obj_esxd}->print_response(centreon::esxd::common::get_status($status) . "|$output\n");
|
||||
}
|
||||
|
||||
1;
|
|
@ -122,7 +122,7 @@ sub run {
|
|||
$output_append = ". ";
|
||||
}
|
||||
if ($output_warning ne "") {
|
||||
$output .= $output_append . "CRITICAL - Snapshots for VM older than " . ($self->{warning} / 86400) . " days: $output_warning";
|
||||
$output .= $output_append . "WARNING - Snapshots for VM older than " . ($self->{warning} / 86400) . " days: $output_warning";
|
||||
}
|
||||
if ($status == 0) {
|
||||
if ($self->{filter} == 1) {
|
||||
|
|
Loading…
Reference in New Issue