Failed to load sensor class

My Flask sensor is active by if I make requests to the endpoint the using REST client the endpoint is found the endpoint, i.e, the Flask application is down. The log /var/log/st2/st2sensorcontainer.log:

2019-12-22 17:27:18,550 140359279589968 INFO process_container [-] Sensor linux.FileWatchSensor started
2019-12-22 17:27:18,550 140359279589968 INFO process_container [-] Running sensor hub.ClientData
2019-12-22 17:27:18,639 140359279589968 INFO process_container [-] Sensor hub.ClientData started
2019-12-22 17:27:26,107 140316348196976 ERROR (unknown file) [-] Traceback (most recent call last):

2019-12-22 17:27:26,108 140316348196976 ERROR (unknown file) [-]   File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 360, in <module>

2019-12-22 17:27:26,109 140316348196976 ERROR (unknown file) [-]     
2019-12-22 17:27:26,110 140316348196976 ERROR (unknown file) [-] parent_args=parent_args)

2019-12-22 17:27:26,110 140316348196976 ERROR (unknown file) [-]   File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 209, in __init__

2019-12-22 17:27:26,111 140316348196976 ERROR (unknown file) [-]     
2019-12-22 17:27:26,111 140316348196976 ERROR (unknown file) [-] self._sensor_instance = self._get_sensor_instance()

2019-12-22 17:27:26,112 140316348196976 ERROR (unknown file) [-]   File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 295, in _get_sensor_instance

2019-12-22 17:27:26,112 140316348196976 ERROR (unknown file) [-]     
2019-12-22 17:27:26,113 140316348196976 ERROR (unknown file) [-] raise exc_cls(msg)

2019-12-22 17:27:26,113 140316348196976 ERROR (unknown file) [-] Exception
2019-12-22 17:27:26,114 140316348196976 ERROR (unknown file) [-] : 
2019-12-22 17:27:26,114 140316348196976 ERROR (unknown file) [-] Failed to load sensor class from file "/opt/stackstorm/packs/hub/sensors/client_data.py" (sensor file most likely doesn't exist or contains invalid syntax): Directory "/opt/stackstorm/packs/hub/sensors" with plugins doesn't exist

Traceback (most recent call last):
  File "/opt/stackstorm/st2/local/lib/python2.7/site-packages/st2reactor/container/sensor_wrapper.py", line 288, in _get_sensor_instance
    class_name=self._class_name)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/loader.py", line 141, in register_plugin_class
    _register_plugin_path(plugin_dir)
  File "/opt/stackstorm/st2/lib/python2.7/site-packages/st2common/util/loader.py", line 52, in _register_plugin_path
    raise Exception('Directory "%s" with plugins doesn\'t exist' % (plugin_dir_abs_path))
Exception: Directory "/opt/stackstorm/packs/hub/sensors" with plugins doesn't exist

2019-12-22 17:27:26,114 140316348196976 ERROR (unknown file) [-] 

2019-12-22 17:27:26,344 140234734586608 INFO sensor_wrapper [-] No config found for sensor "FileWatchSensor"
2019-12-22 17:27:26,345 140234734586608 INFO sensor_wrapper [-] Watcher started
2019-12-22 17:27:26,346 140234734586608 INFO sensor_wrapper [-] Running sensor initialization code
2019-12-22 17:27:26,361 140234734586608 INFO sensor_wrapper [-] Running sensor in passive mode

How can I fix it, I have already read the code and have not found anything wrong, besides this, if I run /opt/stackstorm/st2/bin/st2sensorcontainer the Flask is up and I can make requests to the end point…

Please post your sensor code, and redact any sensitive information from it. It’s pretty much impossible to answer your question without having any idea what your code is doing.

This line seems to indicate the exact error:

Exception: Directory "/opt/stackstorm/packs/hub/sensors" with plugins doesn't exist

Can you verify that the directory /opt/stackstorm/packs/hub/sensors exists?

If it doesn’t exist, where is your sensor being loaded from (eg: which pack)?

If it does exist, have you checked your sensor into git? StackStorm requires packs to be git repositories.

I would make changes to your pack in one directory (eg: /home/vagrant/hub), and then run st2 pack install file://$(pwd) to install the pack, and reload pack data with st2ctl reload.

Please remember that the only context that we are aware of is what you post here. Posting only the traceback doesn’t tell us how you are running StackStorm, how you are developing your pack, what your pack is trying to do, how your sensor is structured/coded, what your sensor is trying to do, etc. The more information you give us, the better we are able to help you.

  1. The sensor it’s exactly like this one, the change I made was to add a Elasticsearch connection in the __init__ method:
def __init__(self, config):
    self._els = elasticsearch.Elasticsearch([
        {
            'host': config['host'],
            'port': config['port'],
            'use_ssl': config['use_ssl'],
            'http_auth': (config['user'], config['pass'])
        }
    ])
  1. Yes, it exists, I have checked all these folders / a few subfolders:

/opt/stackstorm/packs

/opt/stackstorm/virtualenvs

/st2-docker/st2.d

/opt/stackstorm/configs

  1. I have placed the pack inside the /opt/stackstorm/packs and granted the permisions chgrp -R st2packs /opt/stackstorm/packs/hub (before create the virtual environments)

  2. I’m using Docker and not Vegrant

  3. I have tried to install instead of copy and then grant the permissions / install the virtual environments

  4. Again: if I start the sensor container manually everything works fine, the problem its that this container its not starting automatically (I have created an issue in the Stack Storm Docker repository and by now I’m starting it manually after create the virtual environments in the /st2.d/virtualenv.sh)

Thanks for the feedback :slight_smile:

Observation: I have used prospector to check the Python sensor file and everything is okay