Open topic with navigation

TIBCO® Enterprise Administrator 2.4.2

# A Sample Python Script to Manage Agents

The sample Python script can be used to manage an agent associated with the TIBCO Enterprise Administrator server.

Ensure that before running the sample script, you have followed the steps in Setting up Python Scripting. The following Python script can be used to register, reconnect, or unregister an agent.

    import tibco.tea
    import pprint

    server = tibco.tea.EnterpriseAdministrator()

    def registerAgent( name, url,description):

     try:
       server.agents.registerAgent(name,url,description)
       print('Agent ' + name + ' registered succesfully')
     except Exception as e:
       details=e.args[0]
       print(details)
    def unregister(name):
        try:
          agent = server.agents.members[name]
          agent.unregister()
          print('Agent ' + name + ' unregistered')
        except KeyError as e:
         print('Agent "'+ name +'" not found to unregister')
    def reconnect(name):
        try:
          agent = server.agents.members[name]
          agent.reconnect()
          print('Agent  '+ name + ' reconnected')
        except KeyError as e:
             print('Agent "'+ name +'" not found to reconnect')

    print('-------------------Register Hello World Agent------------------')
    registerAgent('HelloWorld','http://localhost:1234/helloworldagent','HelloWorldAgent')
    print('------------------- Register tomcat Agent------------------')
    registerAgent('tomcat','http://localhost:8082/tomcatagent','tomcat' )
    print('-----Reconnect Hello World Agent------')
    reconnect('HelloWorld')
    print('-----Unregister Hello World Agent------------')
    unregister('HelloWorld')

Assuming you have saved this file as AgentManagement.py, you can run it by navigating to the location and running the command, AgentManagement. This yields the following output:

    C:\TEA>python AgentManagement_Sushma.py
    -------------------Register Hello World Agent----------------------------------------------
    Agent 'HelloWorld' is already registered with url 'http://localhost:1234/helloworldagent'.
    ------------------- Register tomcat Agent--------------------------------------------------
    Agent 'Tomcat' is already registered with url 'http://localhost:8082/tomcatagent'.
    -----Reconnect Hello World Agent-----------------------------------------------------------
    Agent  HelloWorld reconnected
    -----Unregister Hello World Agent-----------------------------------------------------------
    Agent HelloWorld unregistered

Note: You can use the usual debugging mechanisms, such as pdb, to debug the Python scripts used for invoking TEA operations.

Did you find this helpful?

Yes No
Great!
Thanks for taking the time to give us some feedback.
Sorry about that

Why wasn't this helpful? (check all that apply)

Could not find what I was looking for
Instructions confusing or unclear
Instructions did not work

Want to tell us more?

Please select at least one option or provide details about the issue!!

Error occurred while submitting feedback.

Error2 occurred while submitting feedback.

TIBCO® Enterprise Administrator

Copyright © 1996-2025. Cloud Software Group, Inc. All Rights Reserved.