REST API knowledge exchange
Post Reply
FracKen
Lurker
Posts: 2
Liked: never
Joined: Apr 27, 2016 1:56 am
Full Name: Ken Dobbins
Contact:

Repository API Question

Post by FracKen »

I have been using the following script to bring repository free space into my Nagios system however it creates issues. The biggest being that it is needed to be ran on each server individually.

powershell-f26/repository-size-t10674.html#p46401

I am trying to find a good example of an API script that I can run agains our enterprise manager. I have searched over the forums, google and the API manual on the veeam documentation. I am far from a developer but am very capable at following and modifying examples.

I have used this to create the session

https://github.com/snaumov/veeamrestapi

I tried this also. however I think it was a bit TOO feature rich for my simple needs.

https://github.com/stemid/veeamclient

Is there a simple python perl or shell script example that will simply connect and pull the repositories that I can try to expand on to get the data I need for my monitoring?
PTide
Product Manager
Posts: 6551
Liked: 765 times
Joined: May 19, 2015 1:46 pm
Contact:

Re: Repository API Question

Post by PTide »

Hi and welcome to the community!

I'm not a programmer either, but this quick and dirty example (Python 2.7.5) should give you some ideas:

Code: Select all

#import required modules
import xml.etree.ElementTree as ET
import base64
import requests

#define values
login='yourlogin'
password='yourpass'
apiurl='http://yourEM:9399/api/'

#try to contact EM api
contact=requests.get(apiurl)

#logon
auth=requests.post(apiurl+'/sessionMngr/?v=latest', auth=(login,password))

#get session ID from the response
auth=auth.text
root=ET.fromstring(auth)
session=root[2].text

#convert session ID to base64
session=base64.b64encode(bytes(session))

#request repository stats
repo=requests.get(apiurl+'reports/summary/repository', headers={"X-RestSvcSessionId":session});

#open a file to write into
f=open("/home/admin/nagios/repo_stats","a")
f.write(repo.text)

#close file
f.close()
Is that what you want? Please let me know how it works.

Thanks
benyoung
Veeam Software
Posts: 149
Liked: 47 times
Joined: May 25, 2016 3:29 am
Full Name: Ben Young
Contact:

Re: Repository API Question

Post by benyoung » 1 person likes this post

If i understand your post above then it is relatively simple to get the data you need out, but will vary from setup to setup

1) Login to Enterprise Manager API /api/sessionMngr/?v=latest to get Session ID required for subsequent posts to the API as a header.
2a) Query /api/repositories?format=Entity

You will have data presented back as

Code: Select all

<Repository Href="http://servername:9399/api/repositories/XXXXXX?format=Entity" Type="Repository" Name="Repo 1" UID="urn:veeam:Repository:XXXXX">
        <Links>
          links here.
        </Links>
        <Capacity>32405259812864</Capacity>
        <FreeSpace>22370661433344</FreeSpace>
        <Kind>WindowsLocal</Kind>
    </Repository>
<Repository Href="http://servername:9399/api/repositories/XXXXXX?format=Entity" Type="Repository" Name="Repo 2" UID="urn:veeam:Repository:XXXXX">
        <Links>
          links here.
        </Links>
        <Capacity>117374775525376</Capacity>
        <FreeSpace>59373762969600</FreeSpace>
        <Kind>Extendable</Kind>
    </Repository>
You can use the above to perform any calculations such as percentage etc and track via the UID attribute.

2b) HTTP Get the following as pointed out by the reply above - /api/reports/summary/repository
You will then get the following payload which you can do calculations on etc.

Code: Select all

<Period>
        <Name>REPO1</Name>
        <Capacity>32405259812864</Capacity>
        <FreeSpace>22370661433344</FreeSpace>
        <BackupSize>10034598379520</BackupSize>
    </Period>
    <Period>
        <Name>REPO2</Name>
        <Capacity>83933627613184</Capacity>
        <FreeSpace>65959795359744</FreeSpace>
        <BackupSize>17973832253440</BackupSize>
    </Period>
    <Period>
        <Name>REPO EXT 1</Name>
        <Capacity>16720573956096</Capacity>
        <FreeSpace>4902022610944</FreeSpace>
        <BackupSize>11818551345152</BackupSize>
    </Period>
    <Period>
        <Name>Scale Out X</Name>
        <Capacity>117374775525376</Capacity>
        <FreeSpace>59373762969600</FreeSpace>
        <BackupSize>58001012555776</BackupSize>
    </Period>

That is assuming you have you have a single back server manager and backup proxies running off this with storage presented to the manager.

If you have multiple environments with individual backup servers and enterprise manager then you would follow the same process but iterate through each of your enterprise managers in the environment.
veremin
Product Manager
Posts: 20406
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Repository API Question

Post by veremin »

Reports section of EM RESTful APIs has been developed mostly for internal use, so, if I were you, I would not rely on it heavily. Instead, I would get needed information from /repository/{id} entity. Thanks.
FracKen
Lurker
Posts: 2
Liked: never
Joined: Apr 27, 2016 1:56 am
Full Name: Ken Dobbins
Contact:

Re: Repository API Question

Post by FracKen »

Sorry for the delay.

I appreciate the feedback, I believe I can hammer at the provided information to make this work.

Thank You all so very much for your input.

:)
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Repository API Question

Post by tdewin »

Btw, if you try to parse the xml, remember that it has a namespace "http://www.veeam.com/ent/v1.0" For example, I used ElementTree, but then if you define the xpath, you need to take into account the namespace (https://docs.python.org/2/library/xml.e ... ttree.html)
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: Repository API Question

Post by tdewin » 1 person likes this post

For those looking for some very simple python examples, check this:
https://github.com/tdewin/veeamrestpython

This was made just to introduce some restful api at customers so I thought I share it here. This is highly unoptimized code without any function or classes just so you can see the flow of building the session, logging in etc.

The last example is actually starting an flr session, reading a file and logging out so it is pretty advanced. To look up the VM it uses the both the lookup service and the query service so it goes pretty far. Maybe the only thing that is missing is doing an edit or something like that.

It uses the requests framework which you can install with pip

Code: Select all

C:\Users\Administrator\AppData\Local\Programs\Python\Python36\Scripts\pip install requests
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests