Can't you have multiple functions in a Python script (Insight module)?

Losing my mind a bit here.

I have the usual run function, inside that function I call another function I’ve defined at the bottom.
It causes unexplainable errors, and I cannot seem to figure it out. Something as simple as this:

def search_object(hostname, urlv):
    schema = 'aql/objects' # gate for assets/insight
    path = urlv + schema # combine
    auth = HTTPBasicAuth("svc.dklyitsm01.SDUpd", secret_key)
    ## bla bla do stuff
    ci_data = "bla"
        
    return(ci_data)


def run(params={}):
    import json
    import requests
    from requests.auth import HTTPBasicAuth

    hostname = params.get('message') # get input
    hostname = str(hostname)
    urlv = "https://example.com"

    ci_data = search_object(hostname, urlv)


    return ({"result1": str(ci_data)})



Causes "insightconnect_plugin_runtime.exceptions.PluginException: An error occurred during plugin execution!

Could not run supplied script Response was: search_object() missing 1 required positional argument: ‘urlv’"

Why? As you can see I’m clearly passing 2 args as required, and both vars are available.

I have a feeling it’s because insight considers my “search_object” to be my “run” function, but if I reverse the order I just get another error instead, breaking even more things.

Does the plugin just not support multiple functions?

Turns out you can make in-function functions.

So inside the def you can define additional features. Also turns out the main function doesn’t have to be named “run” but can be arbitrary named.

Topic can be closed.