VMware {code} Community
natxoasenjo
Enthusiast
Enthusiast

help with datetimeinfo


hi,


this is probably a simple question but I do not seem to get it right.


With this code:


# get all esx hosts in Datacenter

my $esxhost_view = Vim::find_entity_views(

    view_type  => 'HostSystem',

    properties =>

);


for my $host ( sort { $a->name cmp $b->name } @$esxhost_view ) {


    print $host->name . "\n";
    #print Dumper $host;
    print $host->config->dateTimeInfo;


}

I see I get all the required info from virtual center (both dumping it with Data::Dumper or with the --verbose flag on the script. But when I run it  I keep getting:


Can't call method "dateTimeInfo" on an undefined value at bin/check_esx_time line 30.


How do I get to the ntp config of the esx hosts? I found the vmware health check (<a class="jive-link-external-small" href="https://github.com/lamw/vghetto-scripts/blob/master/perl/vmwareHealthCheck.pl">https://github.com/lamw/vghetto-scripts/blob/master/perl/vmwareHealthCheck.pl</a>) which seems to do the same I am attempting (see from line 1665) but no cookie.


Thanks in advance for any assistance.

Reply
0 Kudos
3 Replies
natxoasenjo
Enthusiast
Enthusiast

sorry, I cannot seem to be able to edit this post and this forum messes with the code and has no preview button Smiley Sad

# get all esx hosts in Datacenter

my $esxhost_view = Vim::find_entity_views(

    view_type  => 'HostSystem',

    properties => [ 'name', 'config.dateTimeInfo', ]

);

for my $host ( sort { $a->name cmp $b->name } @$esxhost_view ) {

    print $host->name . "\n";

    #print Dumper $host;

    print $host->config->dateTimeInfo;

}

Reply
0 Kudos
natxoasenjo
Enthusiast
Enthusiast

not very pretty, but works:

my $ntpservers = $host->{'config.dateTimeInfo'}->ntpConfig->server;

    for ( @$ntpservers ) {

        print $_ , "\n";

}

Reply
0 Kudos
stumpr
Virtuoso
Virtuoso


You figured it out, but because you asked for 'config.dateTimeInfo', it was stored as that hash key.


You could use the get_property() method in the SDK, which will sort of try both forms:


 


$host->get_property('config.dateTimeInfo')->ntpConfig->server;


 


Should also work:


$host->get_property('config.dateTimeInfo.ntpConfig.server');


 


I don't use it much personally, I sort of fall back on the usual Perl hash syntax.

Reuben Stump | http://www.virtuin.com | @ReubenStump
Reply
0 Kudos