diff --git a/contrib/linux/config.yaml b/contrib/linux/config.yaml index 2f9aca8029..e69de29bb2 100644 --- a/contrib/linux/config.yaml +++ b/contrib/linux/config.yaml @@ -1,2 +0,0 @@ -file_watch_sensor: - file_paths: diff --git a/contrib/linux/sensors/file_watch_sensor.py b/contrib/linux/sensors/file_watch_sensor.py index 9c4e32fb36..12113c88db 100644 --- a/contrib/linux/sensors/file_watch_sensor.py +++ b/contrib/linux/sensors/file_watch_sensor.py @@ -9,17 +9,14 @@ class FileWatchSensor(Sensor): def __init__(self, sensor_service, config=None): super(FileWatchSensor, self).__init__(sensor_service=sensor_service, config=config) - self._config = self._config['file_watch_sensor'] - - self._file_paths = self._config.get('file_paths', []) self._trigger_ref = 'linux.file_watch.line' + self._logger = self._sensor_service.get_logger(__name__) + + self._file_paths = [] # stores a list of file paths we are monitoring self._tail = None def setup(self): - if not self._file_paths: - raise ValueError('No file_paths configured to monitor') - - self._tail = Tail(filenames=self._file_paths) + self._tail = Tail(filenames=[]) self._tail.handler = self._handle_line self._tail.should_run = True @@ -36,13 +33,25 @@ def cleanup(self): pass def add_trigger(self, trigger): - pass + if trigger['type'] not in ['linux.file_watch.file_path']: + return + + file_path = trigger['parameters']['file_path'] + self._tail.add_file(filename=file_path) + + self._logger.info('Added file "%s"' % (file_path)) def update_trigger(self, trigger): pass def remove_trigger(self, trigger): - pass + if trigger['type'] not in ['linux.file_watch.file_path']: + return + + file_path = trigger['parameters']['file_path'] + self._tail.remove_file(filename=file_path) + + self._logger.info('Removed file "%s"' % (file_path)) def _handle_line(self, file_path, line): trigger = self._trigger_ref diff --git a/contrib/linux/sensors/file_watch_sensor.yaml b/contrib/linux/sensors/file_watch_sensor.yaml index dbfd48a8ac..80199fa95e 100644 --- a/contrib/linux/sensors/file_watch_sensor.yaml +++ b/contrib/linux/sensors/file_watch_sensor.yaml @@ -3,6 +3,18 @@ entry_point: "file_watch_sensor.py" description: "Sensor which monitors files for new lines" trigger_types: + - + name: "file_watch.file_path" + description: "Trigger which represents a file path to be monitored" + parameters_schema: + type: "object" + properties: + file_path: + description: "Path to the file to monitor" + type: "string" + required: + - "file_path" + additionalProperties: false - name: "file_watch.line" description: "Trigger which indicates a new line has been detected"