Error while creating a poll sensor

(Jimmy0628) #1

I was trying to create a poll sensor to monitor a process on my sandbox, but failed with an error, which indicate my sensor initialization failed because of property of poll_interval.

init() got an unexpected keyword argument ‘poll_interval’

Has anybody encountered this problem before? I set the interval in the sensor yaml file to 10 seconds but the python code seems not recognizing this property.

Thank you

(Lindsay Hill) #2

Can you post your code and metadata?

(Jimmy0628) #3
class_name: "BuildSchedulerSensor"
entry_point: ""
description: "Test if the build scheduler process is still running"
    name: "BuildSchedulerTrigger"
    description: "A BuildSchedulerSensor trigger."
      type: "object"
import eventlet

from st2reactor.sensor.base import Sensor

class BuildSchedulerSensor(Sensor):
    def __init__(self, sensor_service, config):
        super(BuildSchedulerSensor, self).__init__(sensor_service=sensor_service, config=config)
        self._logger = self.sensor_service.get_logger(name=self.__class__.__name__)
        self._stop = False

    def setup(self):

    def run(self):
        while not self._stop:
            self._logger.debug('BuildSchedulerSensor dispatching trigger...')
            count = self.sensor_service.get_value('tt_devops_engine.count') or 0
            payload = {'greeting': 'Yo, StackStorm!', 'count': int(count) + 1}
            self.sensor_service.dispatch(trigger='tt_devops_engine.event1', payload=payload)
            self.sensor_service.set_value('tt_devops_engine.count', payload['count'])

    def cleanup(self):
        self._stop = True

    # Methods required for programmable sensors.
    def add_trigger(self, trigger):

    def update_trigger(self, trigger):

    def remove_trigger(self, trigger):

(Jimmy0628) #4

Actually, I am just using the sample sensor, but failed to start

(Lindsay Hill) #5

Your code does not look like a PollingSensor. Look for “SamplePollingSensor” on this page Sensors and Triggers — StackStorm 2.10.1 documentation - note it inherits from PollingSensor, not Sensor

(Jimmy0628) #6

Thank you, I got this problem fixed by using polling sensor. :slight_smile: