class SampleSensor(Sensor): """ * self.sensor_service - provides utilities like - get_logger() - returns logger instance specific to this sensor. - dispatch() for dispatching triggers into the system. * self._config - contains parsed configuration that was specified as config.yaml in the pack. """
def setup(self): # Setup stuff goes here. For example, you might establish connections # to external system once and reuse it. This is called only once by the system. pass
def run(self): # This is where the crux of the sensor work goes. # This is called once by the system. # (If you want to sleep for regular intervals and keep # interacting with your external system, you'd inherit from PollingSensor.) # For example, let's consider a simple flask app. You'd run the flask app here. # You can dispatch triggers using sensor_service like so: # self.sensor_service(trigger, payload, trace_tag) # # You can refer to the trigger as dict # # { "name": ${trigger_name}, "pack": ${trigger_pack} } # # or just simply by reference as string. # # i.e. dispatch(${trigger_pack}.${trigger_name}, payload) # # E.g.: dispatch('examples.foo_sensor', {'k1': 'stuff', 'k2': 'foo'}) # # trace_tag is a tag you would like to associate with the dispatched TriggerInstance # # Typically the trace_tag is unique and a reference to an external event. pass
def cleanup(self): # This is called when the st2 system goes down. You can perform cleanup operations like # closing the connections to external system here. pass
def add_trigger(self, trigger): # This method is called when trigger is created pass
def update_trigger(self, trigger): # This method is called when trigger is updated pass
def remove_trigger(self, trigger): # This method is called when trigger is deleted pass
# A list of strings, assuming value will be provided at runtime or # key value pairs where value is the default value when value # is not provided at runtime. input: - arg1 - arg2: abc
# A list of key value pairs. vars: - var1: 123 - var2: True - var3: null
# A dictionary of task definition. The order of execution is # determined by inbound task transition and the condition of # the outbound transition. tasks: task1: action: core.noop next: - do: task2 task2: action: core.noop
# A list of key value pairs to output. output: - var3: <% ctx().arg1 %> - var4: var41: 456 var42: def - var5: - 1.0 - 2.0 - 3.0