Automic Workload Automation

 View Only
  • 1.  Create a job which will execute python script.

    Posted Apr 02, 2024 09:42 AM

    I watched documentation on UC4 (automic automation) but couldn't find the help where I can create a job and execute my python script.

    I have developed on python script for web scrapping. This script doesn't required any input parameters. I want to create on job on UC4 in which this job will execute this python script. also I have to execute this python script. where I have to save this file in order to execute this script. because we have 4 environments for UC4. I have questions like, where to keep the python script in order to point the location and which command to use and where.

    PS - I am using UC4 web interface version is "Automic web interface 21.0.8". I am very much new to UC4 hence step by step approach would be highly appreciated. Thank you !



  • 2.  RE: Create a job which will execute python script.

    Posted Apr 02, 2024 04:11 PM

    Hello Rupesh Kadam,

    a possible solution for your use case is to configure your automic, for usage with external interpreters. Try to follow the manual description :BEGIN_EXT_INTERPRETERS... :END_EXT_INTERPRETERS . If you have further questions feel free to ask.

    Best regards

    Andrzej Golaszewski




  • 3.  RE: Create a job which will execute python script.

    Posted Apr 03, 2024 11:01 AM

    We actually use this method.  This is one example.  Note: I'm still a rookie at python.

    This actually makes a REST call against automic to get some agent host information.

    set PATH=%PATH%;d:\python\python310;d:\python\python310\scripts
     
     
    :BEGIN_EXT_INT Python
     
    import requests
    import json
    import socket
     
    url = "hostname:8088/ae/api/v1/0060/system/agents?active=True"
     
    payload = {}
    headers = {
      'Authorization': 'redacted'
    }
     
    response = requests.request("GET", url, headers=headers, data=payload)
     
    #print(response.text)
    #print(response)
    data = json.loads(response.text)
     
    # Iterating through the json
    # list
     
    for i in data['data']:
        hostname="notfound"
        try:
          hostname = socket.gethostbyaddr(i["ip_address"])[0]
        except socket.error:
            pass
        print("OUTDATA;",i["name"],";",i["ip_address"],";",i["software"],";",hostname)
     
     
    :END_EXT_INT Python
     
     
    ! insert these lines in your script to determine if an error occurred
    !
    @set retcode=%errorlevel%
    @if NOT %ERRORLEVEL% == 0 goto :retcode




  • 4.  RE: Create a job which will execute python script.

    Posted Apr 03, 2024 03:36 AM

    As Andrzej wrote - one of the methods is to define python as external interpretor. 
    This will alow you to execute python commands (python code) from within the job (process tab).

    However there is another option.
    A normal OS job (WIN or UNIX) which will start the python script.
    With the remark that you should have python installed with all required modules.
    The user defiend in the LOGIN object should have python in the env path(user profile path).

    In order to execute the same script on multiple servers/environments without placing variations of the script locally on every server, you can utilize the STORE object and the script statements ":ATTACH_RES"
    You have the option to chose betwen tasks specific cache or client specific cache.

    It would look something like this -

    :ATTACH_RES "STORE.OBJ_NAME", "my_script.py", T
    python3 &$AGENT_RESOURCES_TASK#my_script.py -argument1 -argument2

    OR

    cd &$AGENT_RESOURCES_CLIENT#

    python3 my_script.py

    Where STORE.OBJ_NAME is your STORE object, 'my_script.py' is your python script and "&$AGENT_RESOURCES_TASK#" is predefined variable for the tasks specific cache directory.

    LINK to the Docu - CLICK & CLICK



    ------------------------------
    ------------------------------
    Automic SME @ DXC.Technology
    ------------------------------
    ------------------------------



  • 5.  RE: Create a job which will execute python script.

    Posted Apr 04, 2024 07:02 AM
    Edited by Michael A. Lowry Apr 04, 2024 07:01 AM