IBM QRadar SOAR

IBM QRadar

Join this online user group to communicate across Security product users and IBM experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  ImportError: 'module' object has no attribute 'FunctionComponent'

    Posted Wed August 12, 2020 12:34 PM
    Question: How am I supposed to proper import function from one module to the resilient-circuits codegen template code. In more specific, how to import successfully addContent module on funct_f_add_content module, as shown in figure 1.

    addContent.py ( trying to import on funct_f_add_content module)

    Funct_f_add_content.py (How come the program can not be executed even with valid import python syntax)

     # Method 3: assign value via function from other module 'addContent' on variable 'addingContent3'

    from addContent import fnAddContent
    addingContent3 = fnAddContent("Ivan Testing 3")
    # #yield StatusMessage("fn_add_content '{0}'".format(a))
    results = {
    "content": addingContent3
    }

    By using method 3, with import other module, to make a simple add content on a note program and demonstrate how to import a self-custom module (addContent.py) with a function (fnAddContent(tmp_content)) on a template code (funct_f_add_content.py) generated by resilient-circuits codegen. However, the program cannot be executed to assign value by a function in different module (method 3). Once resilient-circuits run is executed it prompt out error messages as below:

    Failed to load 'AddcontentFunctionComponent = fn_add_content.components.addContent:FunctionComponent' from 'fn-add-content
    1.0.0'
    ...
    ImportError: 'module' object has no attribute 'FunctionComponent'


    For other positive references, (optional to read)


    Method 1 and method 2 are two successfully approaches to accomplish the add a note task by assigning value by a variable (method 1) and a function within the same module (method 2).

    ** Method 1 and 2 is trying to show the function successfully running by different approach to call (direct assign value on variable, and function within the same module) ***

    Method 1: Resilient-Circuits run running well on method 1 (directly assign value on variable 'addingContent1')


    Method 2: Resilient-Circuits run running well on method 2 (assign value via function within the same module 'funct_f_add_content' on variable 'addingContent2')



    ------------------------------
    Ivan To
    ------------------------------


  • 2.  RE: ImportError: 'module' object has no attribute 'FunctionComponent'

    Posted Wed August 12, 2020 02:12 PM
    Ivan,

    Try using 'from fn_add_content.components.addContent import fnAddContent' as your import statement in funct_f_add_content.py.


    ------------------------------
    Liam Mahoney
    ------------------------------



  • 3.  RE: ImportError: 'module' object has no attribute 'FunctionComponent'

    Posted Wed August 12, 2020 10:47 PM
    Edited by Ivan To Wed August 12, 2020 11:02 PM
    thanks for your advice. However, the issues is not able to resolve even giving a different way of calling the import. Is there the other way to resolve this issue. Thanks

    from fn_add_content.components.addContent import fnAddContent (As you could review in Part I, it failed to run during resilient-circuits run )

    Part I
    Failed to load 'AddcontentFunctionCompent =
    ImportError: 'module' object has no attribute 'FunctionComponent'

    Part II (unit testing) but could not be execute during resilient-circuits run.

    For Unit Testing of different way to import the modules, it could be run during unit testing  )


    from fn_add_content.components.addContent import fnAddContent
    #from fn_add_content.components.addContent import fnAddContent
    #from components.addContent import fnAddContent
    #from components.addContent import fnAddContent
    #from addContent import fnAddContent
    testing = fnAddContent("Testing the way of import fnAddContent v43")
    print(testing)


    ------------------------------
    Ivan To
    ------------------------------



  • 4.  RE: ImportError: 'module' object has no attribute 'FunctionComponent'

    Posted Thu August 13, 2020 03:40 AM
    In detail, ERRORS as below are generated by using import to introduce module to codegen template code.  Thnaks

    2020-08-13 10:42:50,436 ERROR [component_loader] Failed to load 'AddcontentFunctionComponent = fn_add_content.components.addContent:FunctionComponent' from 'fn-add-content 1.0.0'
    2020-08-13 10:42:50,437 DEBUG [filelock] Attempting to release lock 139854496915536 on /home/integration/.resilient/resilient_circuits_lockfile
    2020-08-13 10:42:50,437 INFO [filelock] Lock 139854496915536 released on /home/integration/.resilient/resilient_circuits_lockfile
    Traceback (most recent call last):
    File "/home/integration/resilient/bin/resilient-circuits", line 10, in <module>
    sys.exit(main())
    File "/home/integration/resilient/lib/python2.7/site-packages/resilient_circuits/bin/resilient_circuits_cmd.py", line 674, in main
    config_file=args.config_file)
    File "/home/integration/resilient/lib/python2.7/site-packages/resilient_circuits/bin/resilient_circuits_cmd.py", line 90, in run
    app.run(**kwargs)
    File "/home/integration/resilient/lib/python2.7/site-packages/resilient_circuits/app.py", line 341, in run
    application = App(*args, **kwargs)
    File "/home/integration/resilient/lib/python2.7/site-packages/resilient_circuits/app.py", line 189, in __init__
    self.do_initialization()
    File "/home/integration/resilient/lib/python2.7/site-packages/resilient_circuits/app.py", line 224, in do_initialization
    self.component_loader = ComponentLoader(self.opts)
    File "/home/integration/resilient/lib/python2.7/site-packages/resilient_circuits/component_loader.py", line 64, in __init__
    installed_components = self.discover_installed_components()
    File "/home/integration/resilient/lib/python2.7/site-packages/resilient_circuits/component_loader.py", line 90, in discover_installed_components
    return [ep.load() for ep in entry_points if ep.name not in self.noload]
    File "/home/integration/resilient/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2443, in load
    return self.resolve()
    File "/home/integration/resilient/lib/python2.7/site-packages/pkg_resources/__init__.py", line 2453, in resolve
    raise ImportError(str(exc))
    ImportError: 'module' object has no attribute 'FunctionComponent'

    ------------------------------
    Ivan To
    ------------------------------



  • 5.  RE: ImportError: 'module' object has no attribute 'FunctionComponent'

    Posted Thu August 13, 2020 09:47 AM
    Edited by Liam Mahoney Thu August 13, 2020 09:47 AM
    Ivan,

    If you move `fn_add_content/fn_add_content/components/addContent.py` to `fn_add_content/fn_add_content/util/` you will be able to import the file with `from fn_add_content.util.addContent import fnAddContent`. I'm guessing circuits loops through the components directory and assumes each python file there should be a function within the Resilient GUI.

    You may also need to move / delete `test.py` if that starts to give you issues after moving the `addContent.py` file to the `util` directory


    ------------------------------
    Liam Mahoney
    ------------------------------



  • 6.  RE: ImportError: 'module' object has no attribute 'FunctionComponent'

    Posted Thu August 13, 2020 12:49 PM
    Bravo.i.It is as what you are guessing, and get it fixed. Thanks for your advices

    ------------------------------
    Ivan To
    ------------------------------