RESTful knowledge exchange
Post Reply
pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Relate VM objects to jobs

Post by pdrangeid » Oct 31, 2019 4:16 pm

I am trying to validate what VMs SHOULD be configured for Veeam, and which Are, and which backups have success within x days.

Basically validate that we have configured the correct machines for backup jobs, and they are indeed running.

Do do this I have all my machines in our asset management DB, and pulled that into a graphDB (neo4j). I am now using the VeeamAPI to query and validate that those VMs are indeed getting backed up.

I queried jobs via api/jobs
I queried a list of all the VMs using api/lookupSvc (got .Links where .HierarchyItemList ends with =Vm)
I queried restorepoints by api/query?type=VmRestorePoint&format=Entities&filter=HierarchyObjRef==%22"+vvm.id+"%22;CreationTime%3E"+backupdate

So now I know WHICH vms have backups completed successfully, and I put them into buckets (last 12 hours, last 1 day, 2 days, 7 days, 14 days, longer, or never)

The problem is that those VMs that have "NEVER" been backed up, I'm not sure if they are a part of any Veeam jobs. The VMs that are collected, appear to be all VMs that veeam "saw" through the integration with VMware. I tried digging into the api/jobs/{ID}/includes endpoint, but it seems to only show me the folder objects that define the job, and not the individual VMs that become a part of the backup.

Is there any way to query the api to determine which VMs are a part of which jobs?

jhoughes
Veeam Software
Posts: 118
Liked: 31 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Relate VM objects to jobs

Post by jhoughes » Oct 31, 2019 4:34 pm

The '/jobs/{ID}/includes' endpoint will show you the exact object which is targeted for the VM job, including any resource containers which may have been selected.

This means that if your jobs are targeting resource containers such as clusters/resource pools/VM folders/datastores/vSphere tags, then those are the HierarchyObjRef objects which will be returned by the endpoint.

In my case, for a job targeting a tag, this is what gets returned (trimmed for space):

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<ObjectsInJob xmlns="http://www.veeam.com/ent/v1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <ObjectInJob Href="http://ausveeambem.lab.fullstackgeek.net:9399/api/jobs/c56fc07e-38e6-4672-902f-87b834d73305/includes/8d75eba8-cebc-4b11-b31c-818a49a03002" Type="ObjectInJob">
        <ObjectInJobId>8d75eba8-cebc-4b11-b31c-818a49a03002</ObjectInJobId>
        <HierarchyObjRef>urn:VMware:Tag:fdd958d1-0a04-410a-964f-0f8f9c13a5fe.urn:vmomi:InventoryServiceTag:512c257c-4a66-4cce-9578-34bb8df48f4b:GLOBAL</HierarchyObjRef>
        <Name>VeeamTagTest</Name>
        <DisplayName>VeeamTagTest</DisplayName>
        <Order>0</Order>
        <GuestProcessingOptions>
        </GuestProcessingOptions>
    </ObjectInJob>
</ObjectsInJob>
Within this reference object, there is a specific type designation (a 'Tag' in my case), as documented here: https://helpcenter.veeam.com/docs/backu ... l?ver=95u4

You would need to query your vSphere environment to determine the VMs that are contained within each specific reference objects (in your case a VM folder), and therefore which job those VMs are contained within.
Husband, Father, Solutions Architect, Geek Extraordinaire | @AustinVMUG & @ATXPowerShell leader | vExpert | Cisco Champion | Tech Field Day Delegate | VCP 4/5/6 | VCP6-NV | VMware/Cisco UCS/Powershell/VEEAM Enthusiast

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Oct 31, 2019 4:56 pm

So, I cannot determine (from Veeam API alone) which VMs a Veeam job is protecting? and instead requires me to then query a VMware API?

This seems very strange, as Veeam is highly aware of VMs. (I'm able to find them with the /api/query tool) but it doesn't track which VMs ended up attached to a particular job?

jhoughes
Veeam Software
Posts: 118
Liked: 31 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Relate VM objects to jobs

Post by jhoughes » Oct 31, 2019 4:56 pm

If you are wanting to at least check the last run of the backup job to see which VMs were included, you could follow the '/backupSessions' link to get all sessions of that specific job.

From there, you can parse out the most recent session, or any session on a particular date if you want to catch all retries as well.

From any specific backup session entity, you will get a '/taskSessions' link which will give you each task session for that particular backup job run.

Within the task session list, you'll have an entity for each VM which was included in the job run.

This would probably be the closest to a list of VMs that you will get for your intended purposes, at least off the top of my head. That list may still only be valid for a specific date or job run, as if a VM has moved within your environment then it may no longer a candidate within a backup job, once the vSphere inventory data is updated.
Husband, Father, Solutions Architect, Geek Extraordinaire | @AustinVMUG & @ATXPowerShell leader | vExpert | Cisco Champion | Tech Field Day Delegate | VCP 4/5/6 | VCP6-NV | VMware/Cisco UCS/Powershell/VEEAM Enthusiast

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Oct 31, 2019 5:00 pm

OK - that makes sense... I'll have to dig into the task session list.

Another question - I use folders, and will create 'VEEAM EXCLUDE" folders, which I then "exclude" from the job. How can I tell via the API that the folder within a job is marked for EXCLUSION vs INCLUSION.. they all looked the same at first glance when I saw the folder objects appearing in the "/job/include" query

jhoughes
Veeam Software
Posts: 118
Liked: 31 times
Joined: Apr 20, 2017 4:19 pm
Full Name: Joe Houghes
Location: Austin, TX
Contact:

Re: Relate VM objects to jobs

Post by jhoughes » Oct 31, 2019 5:04 pm

pdrangeid wrote:
Oct 31, 2019 4:56 pm
So, I cannot determine (from Veeam API alone) which VMs a Veeam job is protecting? and instead requires me to then query a VMware API?

This seems very strange, as Veeam is highly aware of VMs. (I'm able to find them with the /api/query tool) but it doesn't track which VMs ended up attached to a particular job?
The job is not targeting individual VMs, it is targeting a container (or sorts). There is a dynamic list of child objects within the job, which gets updated from the cache held by the broker service. The final list of VMs for the job run is created when the job session begins so that the session includes the proper child resources.

The information being presented back from the API endpoint is the actual resource included within the job, it just does not include child resources.
Husband, Father, Solutions Architect, Geek Extraordinaire | @AustinVMUG & @ATXPowerShell leader | vExpert | Cisco Champion | Tech Field Day Delegate | VCP 4/5/6 | VCP6-NV | VMware/Cisco UCS/Powershell/VEEAM Enthusiast

chris.arceneaux
Veeam Software
Posts: 138
Liked: 61 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Contact:

Re: Relate VM objects to jobs

Post by chris.arceneaux » Oct 31, 2019 5:50 pm

I’d be remiss if I didn’t mention another method for tracking unprotected VMs. If the Backup Jobs used vSphere tags as that container Joe mentioned, then you’d only need to find out which VMs are lacking a tag.

Another option to mention is that Veeam ONE has a pre-built report with this information.

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Nov 06, 2019 7:46 pm

Ok - getting really close.

I've got all the VMs via: base-veeam-api-url/lookupSvc
I get the Links where type=HierarchyItemList and retrieve the VM name and the vmid and I create unique nodes for each (:Veeamvm). I also store the .ObjectRef as a property for reference.

Then I'm querying the JobSession via base-veeam-api-url/query?type=BackupJobSession&format=Entities and then delve .Entities.BackupJobSessions.BackupJobSessions to get the unique session data.
Then I query the .Links (where .Type='BackupServerReference') and query that.

Finally I unwind .Refs (where .Type='BackupTaskSessionReference' ) with the intent to match a (:Veeamvm) So I can map a relationship [:INCLUDED_IN_VEEAM_JOB].

Here's the problem. The data in the .Links where .Type = "BackupTaskSessionReference" only "slightly" indicates the VM name:
"Name": "my.vm.fqdn@2019-10-24 05:39:46"

Unfortunately this doesn't use any unique "VM ids (not the vm-###, nor the veeam stil UID like urn:VMware:Vm:8708fde2-61ad-42ee-bed9-94ccf994a3a0.vm-487)

So if I ever collected 2 VMs with the same name (even in different folders, resource groups, etc) - I would have no way to identify WHICH vm the BackupTaskSessionReference is actually referring to.
the Href for the backuptasksessions/{id} at this point seems to be self-referring and just shows the same .Links data.
Shouldn't there be another property within the BackupTaskSessionReference link that provides the .uid or objid of the VM we are talking about?

chris.arceneaux
Veeam Software
Posts: 138
Liked: 61 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Contact:

Re: Relate VM objects to jobs

Post by chris.arceneaux » Nov 06, 2019 8:44 pm

Hi Paul,

Kudos on the effort! Looks like you've come pretty far. The method you've mentioned ends with the caveat that you mentioned in that you can't match to a unique ID. I have a method that should work for you though and provide you the unique ID to compare against.

1) /lookup?.... - You're already doing this to gather list of VMs with ObjectRef and placing them in an array.

2) /query?type=VmRestorePoint&format=Entities&pageSize=1000&page=1 - This API call will you give you restore points for every VM that Enterprise Manager knows about. Depending on the amount of restore points you have, the results will be paginated so keep that in mind in your code. Included in this call is the VM ObjectRef that you got from your first call. Added bonus: You also get a time stamp so you can exclude restore points older than XX number of days.

3) Loop through restore points and remove VMs with matching ObjectRefs from your lookupSvc array you created.

4) What's remaining in the lookupSvc array are VMs with no restore point so they're not protected.

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Nov 06, 2019 9:21 pm

Aah - forgot to mention - I actually had already collected the VM lists from the VMRestorePoint... I've got a great relationship between those.. I'm trying to add the job-to-vm relationship, and having a hard time get those mapped (it works, but using VM name only is going to be easy to mis-connect a vm that has the same vm name (I know not terribly likely, but still could happen)

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Nov 06, 2019 10:30 pm 1 person likes this post

FYI This is a quick example of the knowledge graph I am generating with this tool:

Image

chris.arceneaux
Veeam Software
Posts: 138
Liked: 61 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Contact:

Re: Relate VM objects to jobs

Post by chris.arceneaux » Nov 07, 2019 12:10 pm

Nice! To relate definitively VMs to Backup Jobs (without using vSphere APIs), the restore points would be the way to go. To demonstrate...

1) /vmRestorePoints?format=Entity - You're doing this already either through this call or using the QuerySvc.

2) One of the links in each vmRestorePoint will have a type of RestorePointReference.

Image

3) Making a GET request of the RestorePointReference will tell you the Backup Job name along with the job's unique ID. This information is found in the link with a type of BackupReference.

Image

With all this said, this approach will essentially add an extra API call for every vmRestorePoint you analyze. Depending on the size of your environment, this could add a good bit of time to your automation which might be a problem for you. If you need to optimize to reduce the run time of your automation, I recommend you leverage the vSphere API using the method Joe previously outlined.

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Nov 13, 2019 9:47 pm

Ok - I think I got that working..

How can I tell if a job is a "backup" or a "copy" job?

Also how can I tell if a folder item within a job include is INCLUDING or EXCLUDING the contents?

Thanks!

chris.arceneaux
Veeam Software
Posts: 138
Liked: 61 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Contact:

Re: Relate VM objects to jobs

Post by chris.arceneaux » Nov 13, 2019 10:04 pm

pdrangeid wrote: How can I tell if a job is a "backup" or a "copy" job?
Running GET /jobs?format=Entity will present you with the JobType field. You probably already have this information in a variable. If not, just put it in a variable early in your script for use later on.

Backup for a Backup Job and BackupCopy for a Backup Copy Job.
pdrangeid wrote: Also how can I tell if a folder item within a job include is INCLUDING or EXCLUDING the contents?
Can you provide a little more context?

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Nov 13, 2019 10:17 pm

http://<Enterprise-Manager>:9399/api/jobs/{ID}/includes/{ID}

I see VMware folders I created (like VeeamExclude) that I use to exclude the VMs contained within from the job.
How can Identify that these folders indicate EXCLUSION and not INCLUSION of the job?

chris.arceneaux
Veeam Software
Posts: 138
Liked: 61 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Contact:

Re: Relate VM objects to jobs

Post by chris.arceneaux » Nov 14, 2019 9:27 pm

I'm asking about this internally. I'll follow-up soon.

veremin
Product Manager
Posts: 17055
Liked: 1473 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Relate VM objects to jobs

Post by veremin » Nov 15, 2019 2:02 pm

Currently, this information regarding exclusions is not available via RESTful API. Thanks!

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Nov 19, 2019 7:14 pm 2 people like this post

I've got my script running in production now. Seems to be working pretty well. I'm not using this to troubleshoot veeam jobs (existing alerting works find for that) - this is more about validation that the correct VMs are indeed configured for backups, and have successfully completed according to a backup policy/decision that is assigned at the asset management level. This will support us in building workflows to identify VMs that are missing backups or not properly configured. If anyone is interested in building this in their own graph database, let me know and I will post the github link to the import scripts I'm using to accomplish this.

Thanks to the Veeam folks for their help!

Image

chris.arceneaux
Veeam Software
Posts: 138
Liked: 61 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Contact:

Re: Relate VM objects to jobs

Post by chris.arceneaux » Nov 19, 2019 7:17 pm

Good job @pdrangeid! I know I'd like the GitHub link. :D

Also, what tool are you using to generate the graph?

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Nov 19, 2019 7:30 pm 1 person likes this post

I'm using Neo4j GraphDB (https://neo4j.com/), and a combination of Powershell and .cypher (the native neo4j graph query language) scripts.

Here's a how-to for setting up using the free community edition of Neo4j:
https://blog.graphcommit.com/2019/11/co ... e-are.html

If you also want to "relate" the protected VMs to "VMware assets" this is the process to import your vCenter infrastructure into a graph (which you can then use to tie to the Veeam data):
https://blog.graphcommit.com/2019/11/im ... -into.html

I'll need to add a little bit of documentation to the Veeam import scripts, and I'll post something back here soon.

infraerik
Influencer
Posts: 16
Liked: never
Joined: Jul 24, 2019 10:04 am
Contact:

Re: Relate VM objects to jobs

Post by infraerik » Dec 03, 2019 12:04 pm

Just adding a vote to add the Exclusions object list into the results under <JobInfo>. I have some clients who default to backing up everything in a datacenter or a cluster, and then handle the odd ones by manually adding them to the exclusions list. Being able to include that in the reporting would be very useful.

oleg.feoktistov
Veeam Software
Posts: 56
Liked: 18 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Relate VM objects to jobs

Post by oleg.feoktistov » Dec 06, 2019 4:25 pm

Hi @infraerik. Thank you for your feedback! Marked it in my notes as a topic for further discussions.

pdrangeid
Influencer
Posts: 12
Liked: 5 times
Joined: Mar 07, 2018 5:16 pm
Full Name: Paul Drangeid
Contact:

Re: Relate VM objects to jobs

Post by pdrangeid » Dec 07, 2019 7:32 pm 1 person likes this post

Ok - I finally got the scripts posted online. Here's the how-to:

https://blog.graphcommit.com/2019/11/cr ... h-via.html
And the git repo for those scripts: https://github.com/pdrangeid/veeam-maint

Here's the pre-requisite (this configures a CYPHER interpreter for powershell, and gives you a secure way to store the credentials in the registry for automation):
https://blog.graphcommit.com/2019/12/gr ... oject.html
and the git repo for those scripts: https://github.com/pdrangeid/graph-commit

And finally, the pre-pre-requisite (if you are COMPLETELY new to Neo4j graph databases) This will get you your N4J server setup and running with the plugins you will need to run the project above:
https://blog.graphcommit.com/2019/11/co ... e-are.html

chris.arceneaux
Veeam Software
Posts: 138
Liked: 61 times
Joined: Jun 24, 2019 1:39 pm
Full Name: Chris Arceneaux
Contact:

Re: Relate VM objects to jobs

Post by chris.arceneaux » Dec 09, 2019 2:00 pm

Thanks for sharing @pdrangeid!

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests