Next step is to get the alerts over to an LLM. Picking the simplest option for this, which given that NATS is already in use, is to use a NATS stream.
First, create the stream with a retention policy that will keep the alerts for a day:
1nats stream add alerts_climatecore \
2 --subjects "alerts.climatecore.>" \
3 --storage file \
4 --retention limits \
5 --discard old \
6 --dupe-window 2m \
7 --max-msgs 20 \
8 --max-msgs-per-subject 20 \
9 --max-age 1d \
10 --max-msg-size 1024 \
11 --defaults
Next, add support for publishing alerts to the stream.
The alerts will now be published to the stream. We now need a stream for the LLM to push its notifications to. The notifications are the only actuators available in SynapSteward right now.
1# WorkQueue retention policy is used to ensure that the
2# notifications are not repeated even if a new consumer
3# joins the stream.
4
5nats stream add notifications \
6 --subjects "notifications.>" \
7 --storage file \
8 --retention workq \
9 --discard old \
10 --dupe-window 2m \
11 --max-msgs 100 \
12 --max-msgs-per-subject 20 \
13 --max-age 2d \
14 --max-msg-size 2048 \
15 --defaults
The LLM will publish notifications using a notifications.*
subject, which
will be picked up by the notifications
stream. But let us first get the
notifier service going:
https://github.com/venkytv/synapsteward-notifier
With a reliable systemd service:
# /etc/systemd/system/synapsteward-notifier.service
[Unit]
Description=SynapSteward notifier service
StartLimitIntervalSec=900
StartLimitBurst=5
[Service]
Type=exec
ExecStartPre=/usr/bin/timeout 18 sh -c 'while ! /usr/bin/nc -z localhost 4222; do sleep 1; done'
ExecStart=/usr/libexec/synapsteward-notifier
Restart=on-failure
RestartSec=30s
[Install]
WantedBy=multi-user.target
# /etc/systemd/system/synapsteward-notifier.service.d/override.conf
[Service]
Environment="PUSHOVER_API_TOKEN=axxxxxxxxx"
Environment="PUSHOVER_USER=uxxxxxxxx"
And the last thing for the day, a test notification:
1nats pub notifications.test '{"title": "foo", "message": "test notification"}'
Next week, will try and get the LLM to publish notifications to the stream.