Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions contrib/linux/config.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +0,0 @@
file_watch_sensor:
file_paths:
27 changes: 18 additions & 9 deletions contrib/linux/sensors/file_watch_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions contrib/linux/sensors/file_watch_sensor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down