Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
3516b86
Initial commit for libsensors: basic design and spec implementation
isbm Feb 11, 2026
f55a4d8
Update libdpq with sensors facility
isbm Feb 11, 2026
ce2fc89
Define default sensors directory
isbm Feb 11, 2026
c28e654
Track minion id better
isbm Feb 11, 2026
34cde2f
Implement sensors loader
isbm Feb 11, 2026
ba8a62a
Add an example of sensors loader
isbm Feb 11, 2026
81b8a67
Add loader merge UT
isbm Feb 11, 2026
ef13f55
Add profile matcher UT
isbm Feb 11, 2026
9e75926
Add sensors check parser UT
isbm Feb 11, 2026
1a249f2
Fix the loader when fs traversal order is not guaranteed by Walkdir
isbm Feb 11, 2026
531f12c
Add deps
isbm Feb 11, 2026
58c97ae
Add sensor interface for future implementations
isbm Feb 11, 2026
76b3853
Implement fsnotify based on filescream lib
isbm Feb 11, 2026
67fb768
Implement registry and register fsnotify sensor
isbm Feb 11, 2026
e9e5faf
Lintfix the complex type
isbm Feb 11, 2026
72e5863
Add UT for registry testing
isbm Feb 11, 2026
479dd99
Add UT for spec items loader
isbm Feb 11, 2026
35bca51
Add more examples, add makefile to run them
isbm Feb 11, 2026
f5f2f02
Add random selector crate dep
isbm Feb 12, 2026
87a7934
Update sensors example
isbm Feb 12, 2026
b214818
Rework random intervals
isbm Feb 12, 2026
aea4907
Add UT to verify randomity of the config
isbm Feb 12, 2026
3e5df19
Fix UT for changes
isbm Feb 12, 2026
ac692a7
Reorganise logs
isbm Feb 12, 2026
14016cc
Wire-up deps
isbm Feb 13, 2026
87c0d1e
Add events config to the sensors
isbm Feb 13, 2026
5138b11
Wire up events reactor to the sensors facility
isbm Feb 13, 2026
8ff08a5
Autocreate fileserver exposed dirs
isbm Feb 14, 2026
d788a1d
Tight up minion resources
isbm Feb 14, 2026
b3d86f1
Autodownload sensors config to the minions
isbm Feb 14, 2026
6ca60a8
Add sensors root getter to the config
isbm Feb 15, 2026
1cbf191
Rename models root getter for move obvious name
isbm Feb 15, 2026
6842cd4
Fix doc header
isbm Feb 15, 2026
98367b6
Document new options for the global config
isbm Feb 15, 2026
da8459c
Update events descr in the sensors example
isbm Feb 15, 2026
0b9aba6
Update fsnotify output routing rules
isbm Feb 15, 2026
9ed8280
Use real eid
isbm Feb 15, 2026
09edbd4
Use '|' pipe instead '/' slash in the event routing ruleset
isbm Feb 15, 2026
311ae13
Move loglevel output
isbm Feb 15, 2026
9d2c3a9
Add UT for action response
isbm Feb 15, 2026
8e22527
Update documentation, start describing sensors
isbm Feb 16, 2026
73f7de8
Add fsnotify doc
isbm Feb 17, 2026
ec01f98
Drop event rename idea, use just tag
isbm Feb 17, 2026
5a6794d
Implement sensor id tag
isbm Feb 17, 2026
d4ae2cf
Fixed example
isbm Feb 17, 2026
bd94bac
Remove an empty line
isbm Feb 17, 2026
0bc46e9
Fix docstrings
isbm Feb 17, 2026
559707b
Stop seeding every time
isbm Feb 17, 2026
dd2c858
Drop a commented code
isbm Feb 17, 2026
fbd87ad
Add sensors restart (on --sync)
isbm Feb 17, 2026
db866f9
Cleanup shutdowns
isbm Feb 17, 2026
2e7ea96
Update docs
isbm Feb 19, 2026
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
74 changes: 68 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ members = [
"sysclient",
"libdpq",
"libsysproto",
"libcommon"]
"libcommon",
"libsensors"]

[profile.release]
strip = true
Expand Down
94 changes: 94 additions & 0 deletions docs/eventsensors/fsnotify.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
``fsnotify``: React to Filesystem Events
=================================================

The ``fsnotify`` sensor uses the fsnotify library to monitor file system events.
It can detect events such as file creation, modification, deletion, and more.
This sensor is useful for monitoring specific directories or files for changes.

Synopsis
--------

Sensor configuration as follows:

.. code-block::

<id>:
[profile]:
- <id>
description: <description>
listener: fsnotify
opts:
- <file event> # created | changed | deleted
args:
path: <path>
tag: <event name> # optional, default is fsnotify

``profile``
^^^^^^^^^^^

**Optional**

The list of profiles to which this sensor belongs. If current Minion is attached to
any other profile, the sensor will be inactive.

``description``
^^^^^^^^^^^^^^^

A human-readable description of the sensor.

``listener``
^^^^^^^^^^^^

The type of listener used by the sensor. In this case, it is ``fsnotify``.

``opts``
^^^^^^^^^^

A list of file events to monitor. Possible values include:

- ``created``: Triggered when a file is created.
- ``changed``: Triggered when a file is modified.
- ``deleted``: Triggered when a file is deleted.

``args``
^^^^^^^^^^
Arguments specific to the listener. For the ``fsnotify`` sensor, the following argument is required:

- ``path``: The path to the file or directory to monitor.

``tag``
^^^^^^^^^^

An optional tag to associate with the event. If specified, the event name will include this tag,
allowing for easier identification and filtering of events. Example:

.. code-block:: yaml

tag: my-tag

In case event is defined as ``some-id`` listening to ``/tmp`` directory, then if ``/tmp/foobar`` file
is created, this results to the following event name:

.. code-block:: text

some-id|fsnotify@my-tag|created@/tmp/foobar|0

Example
-------

Here is an example of how to use the ``fsnotify`` sensor to monitor a directory for file creation events:

.. code-block:: yaml

ssh_config_change:
description: Monitor SSH configuration changes
listener: fsnotify
opts:
- changed
args:
path: /etc/ssh/sshd_config

# If defined, an extra tag will be added to the event name:
# ssh_config_change|fsnotify@my-tag|changed@/etc/ssh/sshd_config|0
tag: my-tag

153 changes: 153 additions & 0 deletions docs/eventsensors/overview.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
Event Sensors
==============

.. note::

This document explains how to use **event sensors** and how Sysinspect routes events to handlers.

Overview
========

Every time in your system something happens. That "something" is an event. SysInspect can react to specific
events by listening to them in real time. This allows you to build powerful monitoring and automation solutions
that respond to changes in your system as they happen.

Sensors are defined separately from the models. While models are downloaded and refreshed on demand, every time
minion is calling them, sensors are always running in the background, listening for events right as Minion starts.
Sensor configuration cannot be changed on the fly just like that, because they are always running. Sensor updates
are applied on the next Minion restart or when you issue cluster sync command:

.. code-block:: bash

sysinspect --sync

This is because sensors facility must stop listening to the whole system, sync configuration, pick a proper profile
and start again.

Sensors, just like models, are merged together from a different snippets. On a Master, they are placed in the ``sensors``
subdirectory. By default it is under ``/etc/sysinspect/data/sensors``. The rest of the directory structure is completely
up to you. They are merged together into a single configuration on the Master and then distributed to Minions.

.. important::

If you accidentally define same IDs with the different configurations, the rule is "first wins" — the files are sorted
alphabetically.


Synopsis
--------

There are few important things to keep in mind when working with sensors:

1. **Local Mode Behavior**: When sensors are defined in your configuration, the local version of Sysinspect
will run continuously in the foreground. To run it as a background daemon, use the ``--daemon`` flag
with the ``sysinspect`` command.

2. **Event Handler Responsibility**: It is the responsibility of the user to define what actions should be
taken when events occur. Sensors themselves are purely passive listeners; they only emit the captured
event data in JSON format to the event handler. No automatic actions are triggered by sensors alone.

3. **Separation of Concerns**: Sensors are independent components and not part of any data model. They serve
as the listening configuration layer for a Sysinspect agent (whether SysMinion or local Sysinspect mode).
Their sole purpose is to detect and report system events. The decision of what to do in response, which
models to invoke, or whether to take any action at all, is entirely up to the user.

4. **Event Model Integration**: Event definitions are separated from models and moved into their own sensors
configuration namespace. Once an event is emitted, it can be routed to any handler, which can then trigger
models or other actions based on the event data.


Sensor Configuration Syntax
-----------------------------

The following shows the complete structure for configuring sensors. This YAML-based syntax defines how
sensors listen for events and emit notifications:

.. code-block:: text

sensors:
interval:
max: int # default 10
min: int # default 3
unit: seconds|minutes|hours

<id>:
profile:
- <profile1>
- <profile2>
description: <description of the sensor>
listener: <listener type>
interval: <interval in global units, optional, overrides global one>
opts:
- <option1>
- <option2>
args:
key: <value>
event: <event ID to emit on trigger, optional>

``profile``
^^^^^^^^^^^

**Optional**

This is the list of Minion profiles that matches the sensor. For example, if a minion has profile ``QNX``, then a sensor with
the profile ``Linux`` won't be picked up. IF not defined, **all sensors** will be applied.

``description``
^^^^^^^^^^^^^^^

A human-readable description of the sensor. This is purely informational and does not affect the sensor's behavior.

``listener``
^^^^^^^^^^^^

This specifies the type of implemented supported listener that the sensor uses to detect events.
Refer to the list of supported listeners in the documentation for more details on how to configure each listener type.

``interval``
^^^^^^^^^^^^

Typically, all sensors are made on polling, which means they check for events at regular intervals. This is a pragmatic choice
to provide a simple and consistent way to detect events across different systems and use cases. The ``interval`` field allows
you to specify how often the sensor should check for events. You can set it globally for all sensors or override it for individual sensors.

.. important::

Most sensors are **using polling** under the hood, in order to provide a consistent and simple way to detect events across different
systems and use cases.

The interval can be set manually or calculated randomly between a minimum and maximum value. This is useful to avoid thundering
herd problems when you have many sensors running at the same time.

``opts``
^^^^^^^^^^

**Optional**

This is a list of options specific to the listener type. Please refer to the documentation of a specific sensor.

``args``
^^^^^^^^^^

**Optional**

This is a dictionary of additional arguments that the listener might require. Please refer to the documentation
of a specific sensor for details on what arguments are needed.

``event``
^^^^^^^^^^

A sensor typically emits an event, constructing its own event path, based on the sensor specifics and implementation.
However, in some corner cases it might be necessary to define (override) the event ID with a specific static value.

Highly **not recommended** to use on a regular basis. But the feature is here if needed.

Available Sensors
=================

Here are the available sensors. This list is not exhaustive and may be updated as new sensors are added:

.. toctree::
:maxdepth: 1

fsnotify
Loading
Loading