diff --git a/connectors/vmware/centreon_esxd b/connectors/vmware/centreon_esxd index 7a2b5679a..7bf17050f 100644 --- a/connectors/vmware/centreon_esxd +++ b/connectors/vmware/centreon_esxd @@ -64,7 +64,7 @@ require $libpath . '/command-toolsvm.pm'; require $libpath . '/command-uptimehost.pm'; -our $VERSION = "1.3"; +our $VERSION = "1.3.1"; our $session_id; our %sockets = (); our %child_proc; diff --git a/connectors/vmware/lib/command-uptimehost.pm b/connectors/vmware/lib/command-uptimehost.pm new file mode 100644 index 000000000..71a7784d5 --- /dev/null +++ b/connectors/vmware/lib/command-uptimehost.pm @@ -0,0 +1,43 @@ +sub uptimehost_check_args { + my ($lhost) = @_; + if (!defined($lhost) || $lhost eq "") { + writeLogFile(LOG_ESXD_ERROR, "ARGS error: need host name\n"); + return 1; + } + return 0; +} + +sub uptimehost_compute_args { + my $lhost = $_[0]; + return ($lhost); +} + +sub uptimehost_do { + my ($lhost) = @_; + + my %filters = ('name' => $lhost); + my @properties = ('runtime.bootTime'); + my $result = get_entities_host('HostSystem', \%filters, \@properties); + if (!defined($result)) { + return ; + } + + if ($module_date_parse_loaded == 0) { + my $status |= $MYERRORS_MASK{'UNKNOWN'}; + print_response($ERRORS{$MYERRORS{$status}} . "|Need to install DateTime::Format::ISO8601 Perl Module.\n"); + return ; + } + + my $create_time = DateTime::Format::ISO8601->parse_datetime($$result[0]->{'runtime.bootTime'}); + my $diff_time = time() - $create_time->epoch; + my $days = int($diff_time / 60 / 60 / 24); + + my $output = ''; + my $status = 0; # OK + + $output = "Uptime (in day): $days|uptime=" . $days . "day(s)\n"; + + print_response($ERRORS{$MYERRORS{$status}} . "|$output\n"); +} + +1;