Repository API Question

RESTful knowledge exchange

Repository API Question

Veeam Logoby FracKen » Fri Mar 31, 2017 4:32 pm

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?
FracKen
Lurker
 
Posts: 2
Liked: never
Joined: Wed Apr 27, 2016 1:56 am
Full Name: Ken Dobbins

Re: Repository API Question

Veeam Logoby PTide » Fri Mar 31, 2017 8:11 pm

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
PTide
Veeam Software
 
Posts: 3022
Liked: 246 times
Joined: Tue May 19, 2015 1:46 pm

Re: Repository API Question

Veeam Logoby benyoung » Mon Apr 03, 2017 3:59 am 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.
benyoung
Service Provider
 
Posts: 36
Liked: 7 times
Joined: Wed May 25, 2016 3:29 am
Full Name: Ben Young

Re: Repository API Question

Veeam Logoby v.Eremin » Mon Apr 03, 2017 1:34 pm

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.
v.Eremin
Veeam Software
 
Posts: 13290
Liked: 971 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Repository API Question

Veeam Logoby FracKen » Tue Apr 04, 2017 3:57 pm

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.

:)
FracKen
Lurker
 
Posts: 2
Liked: never
Joined: Wed Apr 27, 2016 1:56 am
Full Name: Ken Dobbins

Re: Repository API Question

Veeam Logoby tdewin » Wed Apr 05, 2017 10:28 am

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: 1046
Liked: 361 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Re: Repository API Question

Veeam Logoby tdewin » Mon May 15, 2017 6:49 am 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
tdewin
Veeam Software
 
Posts: 1046
Liked: 361 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin


Return to RESTful API



Who is online

Users browsing this forum: No registered users and 2 guests