VMware {code} Community
tadRimmey
Contributor
Contributor

Perl Interface to vCenter

Perl Interface to vCenter

Hello, 

Here at Penn State we have some legacy Perl code that creates an inventory of VMs to display to users who are not logged into vSphere client. We are using a custom Perl module (named VM55.pm) to connect to vCenter.  Our VM55.pm Perl module uses the VIMRuntime.pm, VIRuntime.pm, VICommon.pm and VILib.pm modules.  

We need to add some recently created vSphere Custom Attributes, aka properties, to our VM55.pm code so we can display the new Custom Attributes on the user interface pages.  Here is an example from our VM55.pm code of how we are successfully getting some of the existing properties from vCenter: 

$customPropertiesHash{"config.hardware.numCoresPerSocket"} = "";
$customPropertiesHash{"config.hardware.device"} = "";
$customPropertiesHash{"config.cpuAllocation.shares.shares"} = "";
$customPropertiesHash{"config.annotation"} = "";                             ##This string works correctly to get the old backup data listed in the "Notes" section of the properties. 

My question is, what is the wording and syntax of the string data that denotes the new custom attributes string data?  I need to get the Last Backup date information.  Below I show some of my attempts that have not worked: 

#$customPropertiesHash{"config.customFields"} = ""; 
#$customPropertiesHash{"config.custom.fields"} = "";
#$customPropertiesHash{"config.customAttributes"} = "";
#$customPropertiesHash{"config.customFields.lastBackup"} = "";  

I can run a script in PowerCLI to get the properties from vCenter as shown below, including the Last Backup data:

"Name": "deploy-test-c864",
"CustomFields": "[Application/Service, ] [Backup, ] [Backup Status, Backup Job ID [111282] Client: [vcenter.blue.psu.edu], Backup Set: [defaultBackupSet], Subclient: [Zone-A] Parent Backup Job ID [108449]] [Budget Owner, ] [ClusterInvariantVMMId, ] [Customer, ] [Fixing Contact, ] [Last Backup, 4/25/2022 7:55:28 AM] [OS, ] [OS Patched, ] [Production Level, ] [Server Type, ] [Technical Contacts, ] [VRM Owner, ] [vrmManagedMachine, ]"

I am going to try other strings such as "config.customAttributes.lastBackup", "summary.customFields.lastBackup", "summary.config.customFields.lastBackup" and so on.  This is not a very efficient process to find the correct string data.  

I would greatly appreciate any help or opinions in this matter. 

Thank you, 

Tad Rimmey

Penn State University

0 Kudos
1 Reply
tadRimmey
Contributor
Contributor

Hello, 

I would like to add some comments and observations about this issue.  

Our goal is to get the latest backup data from vCenter.  We have recently switched from Veeam backup to Commvault.  When I run this command:

Get-VM -Name xxx-Xxxxx |Select-Object -Property CustomFields

The data for the Veeam backup is listed in this manner:

"CustomFields": [
"[Application/Service, ]",
"[Backup, ]",
"[Backup Status, Backup Job ID [125036] Client: [vcenter.blue.psu.edu], Backup Set: [defaultBackupSet], Subclient: [Zone-B] Parent Backup Job ID [123697]]",
"[Budget Owner, ]",
"[ClusterInvariantVMMId, ]",
"[Customer, ]",
"[Fixing Contact, ]",
"[Last Backup, 4/29/2022 1:21:01 AM]",
"[OS, ]",
"[OS Patched, ]",
"[Production Level, ]",
"[Server Type, ]",
"[Technical Contacts, ]",
"[VRM Owner, ]",
"[vrmManagedMachine, ]"

When I run this command for the same VM  

Get-Annotation -Entity xxx-Xxxxx

I get this data

AnnotatedEntity Name Value
--------------- ---- -----
xxx-Xxxxx Application/Service
xxx-Xxxxx Backup
xxx-Xxxxx Backup Status Backup Job ID [125036] Client: [vcenter.blue.p...

xxx-Xxxxx Last Backup 4/29/2022 1:21:01 AM

When I run this command string:

$vm = Get-VM -Name xxx-Xxxxx

Get-Annotation -Entity $vm -CustomAttribute *

I also get this output:

AnnotatedEntity Name Value
--------------- ---- -----
xxx-Xxxxx Application/Service
xxx-Xxxxx Backup
xxx-Xxxxx Backup Status Backup Job ID [125036] Client: [vcenter.blue.p...

xxx-Xxxxx Last Backup 4/29/2022 1:21:01 AM

What I am puzzled about here is that VMware seems to be calling the same data by at least two different names, "CustomFields" and "CustomAttributes".    I need to have the correct name to add to the custom Perl module we use to connect to the vCenters.  

I realize I am posting a lot of stuff, but I want to be clear about the issue. 

Thank you, 

Tad 

 

0 Kudos