1 2 Previous Next 18 Replies Latest reply on Jun 13, 2019 1:12 AM by Andrew Waters

    Read Notes Field from VM Annotations in VCenter

    Arjun Thakur
      Share:|

      Hi All,

       

      Could you please suggest what would be best solution to read Notes attribute from VM's Annotations [ Which can be seen from Properties of a VM in VCenter Console]. Attached screen shot for your reference.

      Our requirement is to read this filed and populated it into Computer Description filed of each discovered hosts [both UNIX and Windows servers].

       

      We are planning to extract this info for all VMs using Vcenter CLI once VCenter SI is discovered and store that file on a temp location. Then we will write another script to read that file and populate Computer Description field for each host.

       

      If there is any other better way to achieve this please suggest.

       

        • 1. Re: Read Notes Field from VM Annotations in VCenter
          Andrew Waters

          You need get find the vSphere VirtualMachine and get the config.annotation value. How exactly you would do this depends upon the Discovery version you are using.

          • 2. Re: Read Notes Field from VM Annotations in VCenter
            Arjun Thakur

            Hi Andrew,

             

            Thanks for your response. We are currently  on BMC Discovery Version: 11.0.0.2-632444.

             

            Regards,

            A.T.

            • 3. Re: Read Notes Field from VM Annotations in VCenter
              Andrew Waters

              Then you could trigger off discovery of the ESXi/ESX Host and do something like

               

              triggers

                on host := Host created, confirmed where os_type matches regex "VMware ESXi?";

              end triggers;

               

              body

                if not host.vsphere_id then

                  stop; // No known vSphere HostSystem Managed Object.

                end if;

               

                // Starting at the Managed Object representing this Host in vSphere get the

                // associated VirtualMachines and their annotation.

                vms := discovery.vSphereTraverseToObjects(host, "HostSystem", host.vsphere_id,

                                                "vm", "VirtualMachine", [ "config.annotation" ]);

               

                if vms then

                  for vm in vms do

                    if vm.config_annotation then

                      // Do something with the value

                      // vm.vsphere_id is a value which represents the VirtualMachine Managed Object.

                    end if;

                  end for;

                end if;

              end body;

              Obviously this is incomplete (and hence untested) but it should give you the idea. It is preferable to do this at a higher level than individual virtual machines to reduce the load on the vCenter. It would be possible to do at the equivalent at the vCenter level. Just find all the VirtualMachine Managed Objects using discovery.vSphereFindObjects.

              3 of 3 people found this helpful
              • 4. Re: Read Notes Field from VM Annotations in VCenter
                Arjun Thakur

                Hi Andrew,

                 

                Thanks for sharing high level approach of the solution. I will try to implement this in our environment and keep you posted.

                 

                 

                Regards,

                 

                A.T.

                • 5. Re: Read Notes Field from VM Annotations in VCenter
                  Arjun Thakur

                  Hi Andrew,

                   

                  I tried to test the script by running it manually by creating a manual group for ESXi servers. However I found that the script is not going beyond if block:

                   

                  --------------

                  if not host.vsphere_id then

                      stop; // No known vSphere HostSystem Managed Object.

                    end if;

                  --------------

                   

                  When I try to echo vsphere_id, I see it is set as "None" for all the ESXi hosts. Any suggestions on what might be going wrong here.

                   

                  Thanks,

                  A.T.

                  1 of 1 people found this helpful
                  • 6. Re: Read Notes Field from VM Annotations in VCenter
                    Andrew Waters

                    That would be because you are using 11.0 rather than 11.1. You can find it by doing

                    # Use key expression to get vsphere_id from HostInfo node. Always returns a list.

                    vsphere_ids := host.#InferredElement:Inference:Primary:HostInfo.vsphere_id;

                     

                    if not vsphere_id then

                      stop; // No known vSphere HostSystem Managed Object

                    end if;

                     

                    vsphere_id = vsphere_ids[0];

                    Then you can use vsphere_id in place of host.vsphere_id

                    2 of 2 people found this helpful
                    • 7. Re: Read Notes Field from VM Annotations in VCenter
                      Arjun Thakur

                      Hi Andrew,

                       

                      Thanks for your help, using key expression as suggested by you, now I am able to get vsphere_ids.

                       

                      But still below traverse object query returns nothing:

                       

                      vms := discovery.vSphereTraverseToObjects(host, "HostSystem", vsphere_id, "vm", "VirtualMachine", [ "config.annotation" ]);

                       

                      I believe this traverse query should work with version 11.0, please suggest if this is otherwise.

                       

                       

                      Regards,

                      A.T.

                      • 8. Re: Read Notes Field from VM Annotations in VCenter
                        Andrew Waters

                        What is reported for the request in the DiscoveryAccess page?

                        • 9. Re: Read Notes Field from VM Annotations in VCenter
                          Arjun Thakur

                          Hi Andrew,

                           

                          I see below details in Access Report:

                           

                          It says No External Requests allowed. Any Idea whats going on here!!

                           

                          Regards,

                          A.T.

                          • 10. Re: Read Notes Field from VM Annotations in VCenter
                            Andrew Waters

                            That shows the initial vsphere_id you are passing in is not correct. If is None rather than something like ha-host

                            • 11. Re: Read Notes Field from VM Annotations in VCenter
                              Arjun Thakur

                              Hi Andrew,

                              We could develop below script which capture Notes and populated in Computer Description for each hosts except AIX servers. We trying to troubleshoot issue for AIX boxes:

                               

                              triggers

                               

                                   on host := Host created, confirmed where os_type matches regex "VMware ESXi?";

                               

                              end triggers;

                               

                               

                              body

                               

                                  log.debug("****%debug% Computer Description Pattern triggered****");

                               

                                  //Use key expression to get vsphere_id from HostInfo node. Always returns a list.

                                  vsphere_ids := host.#InferredElement:Inference:Primary:HostInfo.vsphere_id;

                               

                                   if not vsphere_ids then

                                      

                                      stop; // No known vSphere HostSystem Managed Object

                                      log.debug("****Exiting Pattern -No known vSphere HostSystem Managed Object****");

                               

                                  end if;

                               

                                  vsphere_id := vsphere_ids[0];

                                  //log.debug("+++=VsphereID:%vsphere_id% =+++");

                               

                               

                                  at := "";

                                  hst := "";

                               

                                  if not vsphere_id then

                               

                               

                                log.debug("****Exiting Pattern - No VSphere ID found****");

                                      stop; // No known vSphere HostSystem Managed Object.

                               

                                  end if;

                               

                                  // Starting at the Managed Object representing this Host in vSphere get the

                                  // associated VirtualMachines and their annotation.

                                  vms := discovery.vSphereTraverseToObjects(host, "HostSystem", vsphere_id, "vm", "VirtualMachine", [ "config.annotation", "config.name" ]);

                                  

                                  if vms then

                               

                                      for vm in vms do

                               

                                          if vm.config_annotation then

                               

                                                at := vm.config_annotation;

                               

                                                //log.debug("config_annotation-- %at% ");

                               

                                         vmhst := vm.config_name;

                               

                                                hst := text.lower(vmhst);

                               

                                                //log.debug("config_name-- %hst% ");

                                  

                                         // vm.vsphere_id is a value which represents the VirtualMachine Managed Object.

                                           

                                                //log.debug("------Scanning VM1 Annotation: %at%---Config:---%hst%---");

                                 

                                                Hostlists := search(Host where name matches "%hst%");

                               

                                                for hostlist in Hostlists do

                               

                                             //log.debug("Host Name:%hostlist.name%");

                               

                                             hostlist.descriptions := "%at%";

                               

                                             log.debug("Host Description:%hostlist.descriptions%");

                               

                                 end for;

                                 

                                          end if;

                               

                                      end for;

                               

                                  end if;

                               

                                        log.debug("------Reached End of Script-------");

                              end body;

                              end pattern;

                              • 12. Re: Read Notes Field from VM Annotations in VCenter
                                Martyn Shortley

                                Hi,

                                 

                                Slightly off-topic ... anyone tried getting the TAG data that is available in vSphere 6.0/6.5 ?

                                If so, what value needs to be passed into the discovery.vSphereTraverseToObjects call ... or do I need to use something completely different?

                                 

                                Regards,

                                Martyn

                                • 13. Re: Read Notes Field from VM Annotations in VCenter
                                  Andrew Waters

                                  Do you men 'tag' on the VirtualMachine object? If so then just 'tag' from the VirtualMachine (replacing the config.annotation with tag above) would do it.

                                  1 of 1 people found this helpful
                                  • 14. Re: Read Notes Field from VM Annotations in VCenter
                                    Martyn Shortley

                                    Many thanks Andrew.

                                    I've tried that now, but don't seem to be getting anything returned for "tag" ... but the query is not returning a failure code.

                                     

                                    Could this be a complex MOR attribute that is not yet supported as referred to in the documentation ( https://docs.bmc.com/docs/display/DISCO111/VMware+ESX+and+ESXi+discovery+using+discovery.vSphere+functions )

                                    as TAGS are part of categories and are assigned to entities ?

                                    VMware vSphere Tags and Categories - all you need to know about it    refers to the logic between them ... and lists a few PowerCLI commands.

                                     

                                    API manual shows "tag" as part of ManagedObject (which VirtualMachine Extends) ... which is what I assume you referred to in answering my original question ...

                                    https://code.vmware.com/apis/196/vsphere#https%3A%2F%2Fvdc-repo.vmware.com%2Fvmwb-repository%2Fdcr-public%2F6b586ed2-655…

                                    ... but as a set of "Tag" entities.

                                     

                                    Do you know of anyone using this successfully?

                                     

                                    Regards,

                                    Martyn.

                                    1 2 Previous Next