Skip to main content
Solved

question Python report "REST API" out put format


Juergen
Byte
Forum|alt.badge.img+8

Hello,

I use the REST API to read via Python the protection report (XML).

Now the output of this report describes first the columns and in the next session the records.  I use normally xml.etree.ElementTree, to read xml contend, but for this looks not useful, what is the easiest way to get this formatted output in dict or in a list. sorry i am new in python scripting.

regards Jürgen

 

Best answer by Juergen

@Mike Struening thanks, for support

In the meanwhile I solved my issue, if anyone has interesting here the code snip:

r = requests.get(<url|>, headers=<headers>)
        result = json.loads(r.text)
        #print(result["records"])
        for line in result["records"]:
            #print(line)
            # remove SLA excluded records
            #print(line[2], line[6], line[7], line[12], line[19])
            lastbackup["number"] = num
            lastbackup["Hostname"] = line[4]
            lastbackup["Client"] = line[5]
            lastbackup["Agent"] = line[6]
            lastbackup["Instance"] = line[8]
            lastbackup["Backupset"] = line[7]
            lastbackup["Subclient"] = line[9]
            lastbackup["JobId"] = line[15]
            lastbackup["Status"] = line[14]
            lastbackup["type"] = line[19]
            num = num + 1
            lastbackuplist.append(lastbackup)
            #print(lastbackup)
            lastbackup = {}

View original
Did this answer your question?
If you have a question or comment, please create a topic

3 replies

Juergen
Byte
Forum|alt.badge.img+8
  • Author
  • Byte
  • 43 replies
  • March 2, 2022

Hello,

Sorry this is a question for a Python forum, not for Commvault, is there a way to remove this topic?

Jürgen


Mike Struening
Vaulter
Forum|alt.badge.img+23

@Juergen , maybe better for a python forum, though why don’t we leave it up and see if anyone can advise?

Tagging in some of our peerrs who have asked python REST API questions and might have ideas!

@Anthony.Hodges , @drPhil , @mhamel 


Juergen
Byte
Forum|alt.badge.img+8
  • Author
  • Byte
  • 43 replies
  • Answer
  • March 4, 2022

@Mike Struening thanks, for support

In the meanwhile I solved my issue, if anyone has interesting here the code snip:

r = requests.get(<url|>, headers=<headers>)
        result = json.loads(r.text)
        #print(result["records"])
        for line in result["records"]:
            #print(line)
            # remove SLA excluded records
            #print(line[2], line[6], line[7], line[12], line[19])
            lastbackup["number"] = num
            lastbackup["Hostname"] = line[4]
            lastbackup["Client"] = line[5]
            lastbackup["Agent"] = line[6]
            lastbackup["Instance"] = line[8]
            lastbackup["Backupset"] = line[7]
            lastbackup["Subclient"] = line[9]
            lastbackup["JobId"] = line[15]
            lastbackup["Status"] = line[14]
            lastbackup["type"] = line[19]
            num = num + 1
            lastbackuplist.append(lastbackup)
            #print(lastbackup)
            lastbackup = {}


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings