Skip to main content

9 replies

April 3, 2023
April 3, 2023
March 31, 2023

We add the Python Code into PowerBi Source wizard.

Code can be found here :

import requests

import base64

import re

import xml.etree.ElementTree as ElementTree

import xml.etree.ElementTree as ET

from datetime import datetime, timedelta

from requests.packages.urllib3.exceptions import InsecureRequestWarning

import pandas as pd

 

# Disable SSL certificate validation warning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

 

# Set credentials for authentication

user = "administrator"

password = 'Password'

pair = f"{user}:{password}"

encoded_creds = base64.b64encode(pair.encode('ascii')).decode('ascii')

basic_auth_value = f"Basic {encoded_creds}"

 

# Set headers for authentication

headers = {

    'Authorization': basic_auth_value

}

 

# Disable SSL certificate validation

import ssl

 

ssl._create_default_https_context = ssl._create_unverified_context

 

# Authenticate and obtain session key

logon = requests.post('https://local host:9398/api/sessionMngr/?v=latest', headers=headers, verify=False)

response_headers = logon.headers

session_key = response_headers.get('X-RestSvcSessionId'.upper())

 

# Set the URL to the BackupTaskSession API endpoint

url = 'https://local host:9398/api/query?type=BackupTaskSession'

 

# Set headers with the session key

headers2 = {

    'X-RestSvcSessionId': session_key

}

March 31, 2023

# Send a GET request to the URL with the session key

response = requests.get(url, headers=headers2, verify=False)

 

# Create an empty DataFrame with the required columns

columns = ['Name', 'State', 'Result', 'CreationTimeUTC', 'EndTimeUTC', 'TotalSize', 'Reason']

df = pd.DataFrame(columns=columns)

 

# Parse the XML data

xml = ET.fromstring(response.content)

 

# Loop through each link and retrieve data

for link in xml.iter('{http://www.veeam.com/ent/v1.0}Link'):

    if link.get('Href').endswith('?format=Entity'):

        response = requests.get(link.get('Href'), headers=headers2, verify=False)

        xml_response = ET.fromstring(response.content)

 

        for backup_task_session in xml_response.iter('{http://www.veeam.com/ent/v1.0}BackupTaskSession'):

            reason_element = backup_task_session.find('{http://www.veeam.com/ent/v1.0}Reason')

            reason_value = reason_element.text if reason_element is not None else "N/A"

            result_element = backup_task_session.find('{http://www.veeam.com/ent/v1.0}Result')

            result_value = result_element.text if result_element is not None else "N/A"

            state_element = backup_task_session.find('{http://www.veeam.com/ent/v1.0}State')

            state_value = state_element.text if state_element is not None else "N/A"

            CreationTimeUTC_element = backup_task_session.find('{http://www.veeam.com/ent/v1.0}CreationTimeUTC')

            CreationTimeUTC_value = CreationTimeUTC_element.text if CreationTimeUTC_element is not None else "N/A"

            EndTimeUTC_element = backup_task_session.find('{http://www.veeam.com/ent/v1.0}EndTimeUTC')

            EndTimeUTC_value = EndTimeUTC_element.text if EndTimeUTC_element is not None else "N/A"

            TotalSize_element = backup_task_session.find('{http://www.veeam.com/ent/v1.0}TotalSize')

            TotalSize_value = TotalSize_element.text if TotalSize_element is not None else "N/A"

            name_element = name_value = xml_response.attrib['VmDisplayName']

            name_value = name_element if name_element is not None else "N/A"

 

            # Append the values to the DataFrame

            df = pd.concat([df, pd.DataFrame({

                'Name': name_value,

                'State': state_value,

                'Result': result_value,

                'CreationTimeUTC': CreationTimeUTC_value,

                'EndTimeUTC': EndTimeUTC_value,

                'TotalSize': TotalSize_value,

                'Reason': reason_value

            }, index=[0])], ignore_index=True)

 

        print(df)

March 31, 2023

# Disable SSL certificate validation warning

requests.packages.urllib3.disable_warnings(InsecureRequestWarning)

 

# Set credentials for authentication

user = "administrator"

password = 'Password'

pair = f"{user}:{password}"

encoded_creds = base64.b64encode(pair.encode('ascii')).decode('ascii')

basic_auth_value = f"Basic {encoded_creds}"

 

# Set headers for authentication

headers = {

    'Authorization': basic_auth_value

}

 

March 31, 2023

Code can be found here :

import requests

import base64

import re

import xml.etree.ElementTree as ElementTree

import xml.etree.ElementTree as ET

from datetime import datetime, timedelta

from requests.packages.urllib3.exceptions import InsecureRequestWarning

import pandas as pd

 

March 31, 2023

 

?name=image003.gif?name=image003.gif

https://gist.github.com/mritsurgeon/6309b08d673331ab5c03c12e1f23987a

?name=image004.png

Script will Run and Fetch the Data

?name=image005.png

 

You will then be presented with the Table from Panda Data Frame :

?name=image006.png

 

Here you can then Transform the Data to tables & reports.

The API in the script can be adapted to Veeam Backup & Replication , Veeam One , Veeam Backup for Office 365 and others….

Data Source allows to refresh so can automatically on schedule run the Python script and fetch the latest data to update tables & reports on dashboards.

Share your thoughts , comments.

Thanks for reading.

March 31, 2023

Let’s start:

I want to get all the latest backup sessions & their state from all backup servers , so I will use API to Veeam Enterprise Manager , I will call this API in Veeam RESTful API and transform it into a Pandas DataFrame.

In this Python code, the requests library is used to send HTTP requests to the Veeam enterprise Manager server, and the base64 library is used to encode the user credentials for authentication. The Pandas library is used to create an empty DataFrame with the required columns and to concatenate the retrieved data into the DataFrame.

The code starts by disabling SSL certificate validation warnings and setting the user credentials for authentication. The session key is obtained by sending a POST request to the sessionMngr API endpoint with the user credentials. The session key is then used in the headers for subsequent requests.

The URL is set to the BackupTaskSession API endpoint, and a GET request is sent to the URL with the session key in the headers. The XML response is parsed using the ElementTree library, and the data is retrieved using the iter() method. The retrieved data is then transformed and appended to the DataFrame.

Finally, the DataFrame is printed to the console. Which is then Imported into PowerBi as Data Source.

In PowerBi add a new Data Source , Search for Python As below :

 

?name=image002.png

 

We add the Python Code into PowerBi Source wizard.

March 31, 2023

Power BI is a powerful business intelligence tool that allows users to visualize data and gain insights from it. While Power BI provides built-in data connectors to various sources, including SQL Server, Oracle, Excel, and others, it also supports using custom connectors to access data from various other sources.

Python is a popular programming language that is widely used in data analysis and machine learning. With the help of Python, you can connect to various data sources, clean and preprocess data, perform statistical analysis, and create visualizations.

By using Python as a data source for Power BI, you can leverage the powerful data manipulation and analysis capabilities of Python within Power BI's intuitive and user-friendly interface. In this blog post, we will explore how to use Python as a data source for Power BI, including connecting to Python scripts, transforming data from Veeam.

When it comes to using Python as a source for Power BI, pandas is an essential tool that can help , pandas can be used to read data from various file formats such as CSV, Excel, and JSON, and to connect to various databases such as MySQL, PostgreSQL, and SQL Server. Pandas provides a simple and efficient way to read, manipulate, and transform data in Python, making it an essential tool when working with data that will be passed to Power BI.

Pandas is then a Pre-requisite.

//Terms and Conditions