HomeGuidesAPI Reference
GuidesAPI ReferenceGitHubAirheads Developer CommunityLog In
Guides

Examples using UXI Python SDK

These are just a few examples but there are many API functions available within the UXI SDK.

Move an Agent to another Group

This example requires the Client ID, Client Secret, the Agent Name, and the Name of the Group to move the Agent To.

# import pyhpeuxi Module
from pyhpeuxi import *

# Login Credentials 
client_id="Your Client ID"
client_secret="Your Client Secret"

# Login Object
login_cred = HPEUXIApiLogin(client_id=client_id,client_secret=client_secret)

#### Parameters for Agent Name & New Group ####
agentName = "agentName"
moveAgentToGroup = "GroupName"
#### Parameters ####

# Get agents and return agentID if it matches the agentName variable
agents = OpenApi.get_agents(login_cred) 
agentID=""
for agent in agents['items']:
    if agent['name'] == agentName:
        agentID = agent['id']
        print("Agent details that have been matched:",agent)

# Get agents and return groupID if it matches the moveAgentToGroup variable
groups = OpenApi.get_groups(login_cred)
groupID = ""
for group in groups['items']:
    if group['name'] == moveAgentToGroup:
        print("Group Name Matched",moveAgentToGroup, " Group ID:",group['id'])
        groupID = group['id']

# Move agent to new group if obtained groupID and agentID 
if agentID and groupID:
    body={
    'groupId' : groupID, # The unique identifier of the group
    'agentId' : agentID, # The unique identifier of the agent
    }
    print(f'Moving Agent {agentName} to Group {moveAgentToGroup}, Output is: {OpenApi.new_group_agent(login_cred,body=body)}')

Rename Agent
The following example renames an Agent and requires the Client ID, Client Secret, the old (current) Agent Name and the New Agent Name.

from pyhpeuxi import *
#login credentials 
client_id="Your Client ID"
client_secret="Your Client Secret"

login_cred = HPEUXIApiLogin(client_id=client_id,client_secret=client_secret)
gg = OpenApi.get_groups(login_cred)
agents = OpenApi.get_agents(login_cred)

#Script Parameters #
oldAgentName = 'RXE40OHO5S'
newAgentName = 'RXE40OHO5S_Lab'
#Script Parameters #

print("Agent Details:",agents)

agentID=""
for agent in agents['items']:
    if oldAgentName == agent['name']:
        print("Found Agent",agent['name'])
        agentID = agent['id']

if agentID :
    body={'name' : newAgentName, 'notes' : 'Lab Agent - Windows 10 Work Machine'}
    print("Updating Agent Name and Notes:",OpenApi.update_agent(login_cred,id=agentID,body=body))

Export Inventory to CSV
In the following example, we get a complete inventory of all our resources and write the data to a collection of CSV files in a folder called csv. This can be useful for inventory management, reporting and obtaining resource ID's for when we need to make additional calls to the onboarding API.

import csv
import os
from pyhpeuxi import *

client_id="Your Client ID"
client_secret="Your Client Secret"

login_cred = HPEUXIApiLogin(client_id=client_id,client_secret=client_secret)

agents = OpenApi.get_agents(login_cred)
groups = OpenApi.get_groups(login_cred)
sensors = OpenApi.get_sensors(login_cred)
wiredNetworks = OpenApi.get_networks_wired(login_cred)
wirelessNetworks = OpenApi.get_networks_wireless(login_cred)
serviceTests = OpenApi.get_tests_service(login_cred)


Utils_UXI.export_to_csv(agents,'agents')
Utils_UXI.export_to_csv(groups,'groups')
Utils_UXI.export_to_csv(sensors,'sensors')
Utils_UXI.export_to_csv(wiredNetworks,'wiredNetworks')
Utils_UXI.export_to_csv(wirelessNetworks,'wirelessNetworks')
Utils_UXI.export_to_csv(serviceTests,'serviceTests')