Module 1 · Lesson 87 of 103

Testing, review and demo

Test the sentinel with synthetic events and fixtures, package it with an idempotent install script, and review and demo it against the rubric.

  • Beginner to advanced
  • 6 min read
  • 13 min lab
What you will need

Ubuntu 24.04 with systemd (WSL2 with systemd enabled, VM or bare metal), sudo, curl and python3; a Raspberry Pi for the optional board notes

Your place in the module
By the end you can 3 objectives
  • Package the sentinel as a hardened systemd timer service with an idempotent install script.
  • Evaluate a peer's sentinel against the rubric and justify your design trade-offs in a demo.
  • Test detection, restart and rotation with synthetic events and bats fixtures
Video coming soonTesting, review and demo
The video for this lesson is being recorded. Read the lesson below in the meantime.
Recall first from Thresholds, alerting and running it
  • Thresholds and cooldowns are the difference between an alert people act on and noise they mute.
  • A oneshot service plus a timer needs no restart policy: the next tick is the recovery.
  • Log text is attacker-controlled: validate fields before they reach JSON, shell commands or alert bodies.
01

Testing and packaging

3 min read

The watcher now detects, alerts and runs on a timer. This lesson answers: how do you test and package the sentinel, and what does the review and demo show?

Because the rules match on SYSLOG_IDENTIFIER, you can inject realistic events with logger, no privileges needed:

bash
logger -p auth.info -t sshd \
  "Failed password for invalid user admin from 203.0.113.7 port 54321 ssh2"
logger -p kern.err -t kernel \
  "Out of memory: Killed process 4242 (stress-ng)"

Run the first command five times, then run a pass, and exactly one ssh-bruteforce alert must appear in journalctl -t sentinel. The address 203.0.113.7 belongs to the documentation range reserved for examples; never aim synthetic attacks at a real host. Real kernel OOM lines carry more fields after the process name, but the rule matches the prefix, so the short form exercises the same path.

For deterministic tests, use fixture files instead of the live journal. A fixture is a text file with the exact lines you want parsed, including the ISO timestamp shape of auth.log. Point a test config at the fixture and a temporary state directory, run in dry-run mode, and assert on the printed hits. With bats, from S09B:

bash
@test "five failures from one address produce one hit" {
  run ./bin/sentinel -c tests/test.conf -n
  [ "$status" -eq 0 ]
  [[ "$output" == *"ssh-bruteforce"*"203.0.113.7"* ]]
}

@test "a quiet fixture produces no hits" {
  run ./bin/sentinel -c tests/quiet.conf -n
  [ "$status" -eq 0 ]
  [ -z "$output" ]
}

The suite must also cover the two hard paths. Restart: run a pass that alerts, then run again with no new events, and assert zero alerts. Rotation: alert on a fixture, rename it, create a fresh file with new lines, run, and assert the new lines are detected from offset zero while the old ones are not re-alerted. These are the behaviours the rubric weights most heavily, because they are the ones a naive implementation fails.

Packaging is an install script plus a predictable layout:

bash
#!/bin/bash
set -euo pipefail
id sentinel &>/dev/null || \
  useradd --system --shell /usr/sbin/nologin sentinel
install -D -m 0755 bin/sentinel /usr/local/bin/sentinel
[ -e /etc/sentinel/sentinel.conf ] || \
  install -D -m 0644 etc/sentinel.conf /etc/sentinel/sentinel.conf
install -D -m 0644 systemd/sentinel.service /etc/systemd/system/sentinel.service
install -D -m 0644 systemd/sentinel.timer /etc/systemd/system/sentinel.timer
systemctl daemon-reload
systemctl enable --now sentinel.timer

Every line is idempotent: the user is created only if absent, an existing config is never overwritten, and install -D creates parent directories. /usr/local/bin is on the default PATH, so sentinel -h works from any shell; the unit uses the absolute path regardless. Run the script twice and nothing breaks; that is the property to demonstrate.

The README is part of the deliverable, not decoration. It needs: what the sentinel does and does not do, install and uninstall steps, every config key with its default, where state lives and how to reset it deliberately, how to run the tests, and your design decisions with their trade-offs. A reviewer who cannot operate your tool from the README alone will mark it down.

Review yourself before the reviewer does

Run shellcheck on every script and fix or justify each warning, then run the bats suite, before you hand the project over. Both tools are from S09A and S09B, and both catch the exact mistakes the rubric penalises: unquoted expansions, grep under set -e, and tests that only cover the happy path.

The project layoutsentinel/binsentinelthe watcher scriptetcsentinel.confkey=value configsystemdsentinel.servicesentinel.timertestsfixturessynthetic log linessentinel.batsbats suiteinstall.shidempotent installerREADME.mddocs and decisionssentinel/binsentinelthe watcher scriptetcsentinel.confkey=value configsystemdsentinel.servicesentinel.timertestsfixturessynthetic log linessentinel.batsbats suiteinstall.shidempotent installerREADME.mddocs and decisions
The project layout: the script, config, units, tests with fixtures, install script and README, each with one clear job.
02

Common mistakes, review and demo

3 min read

These are the failures reviewers see most often, with the diagnosis that finds them:

Symptom Cause Diagnose Fix
Same alert after every restart state not committed, or written non-atomically inspect state files before and after a pass commit with temp-plus-rename; seed first run
Alert storm on first run no cursor seed, no cooldown count alerts against journal history seed from newest entry; add cooldowns
Watcher goes silent after a day tail -f across rename rotation ls -i the path; compare with saved inode use tail -F or the inode-and-offset pass
Pass dies on a quiet log grep exit 1 under pipefail bash -x the pass; check exit status detect with awk, or guard grep with
Webhook hangs the whole scan curl without a timeout time a pass with the receiver stopped --max-time, and treat failure as non-fatal
mail reports success, nothing arrives no MTA on the host ls /var/mail; check for postfix default to syslog or a webhook
Two alerts for one incident manual run overlaps the timer ps for two sentinel processes flock -n on a state-directory lock

The rubric, out of 100: detection correctness 25, state and restart behaviour 20, robustness 15, tests 15, packaging and documentation 15, review and demo 10. The demo must show, live, an injected attack producing one alert, a restart producing silence, and a rotation producing continued detection. Those three moments are the project's spine.

When you review a peer's sentinel, work in this order. Read the README and try to operate the tool from it alone. Run shellcheck and the test suite. Then try to break it: stop the webhook receiver mid-pass, rotate the watched file, kill a pass with SIGKILL and rerun, flood one address with a hundred failures and count the alerts. Read the config parser for sourcing or unvalidated values, and the alert builder for raw log text. Write feedback as observation, impact, suggestion: what you saw, what it causes, what would fix it. Vague praise and vague blame are both useless.

Presenting your own decisions follows a small template: context, options, choice, consequence. For example: the timer-versus-loop choice bought crash recovery for free at the cost of up to one minute of detection latency; the at-least-once ordering bought no silent misses at the cost of rare duplicates, which cooldowns absorb; identifier matching bought testability at the cost of also matching any program that tags itself sshd. A reviewer who hears the consequence named before they ask has met an engineer, not just a coder.

How the review scoresDetection25State andrestart20Robustness15Tests15Packagingand docs15Review anddemo10100 points; demoproves restartsilence and rotationsurvival
The review rubric: detection and state carry the most weight, and the demo must prove restart silence and rotation survival live.
03

Try it

1 min read

The lab pack walks the six milestones end to end: build the sentinel, run it against simulated failed SSH logins and OOM events, package it as a systemd timer, and prove it survives a restart without re-alerting. Keep your state files, your test output and your decision notes as you go, because the reviewed half asks you to run a peer's suite, try to break their watcher, and write feedback they can act on. The practice pack drills the design choices behind each milestone. When your sentinel can be installed, attacked, restarted and reviewed without surprises, you are ready for the OpsKit project studio, where these tools become a suite.

Key takeaways

  • logger -t sshd injects realistic events without privileges, and fixture files make detection tests deterministic.
  • An idempotent install script never overwrites an existing config and runs cleanly twice.
  • A dry run must neither alert nor commit state, so repeated runs report the same hits.
  • The demo must prove live: one injected attack produces one alert, a restart produces silence, and rotation keeps detection working.
Reflect
  1. Explain to a colleague, in two sentences: package the sentinel as a hardened systemd timer service with an idempotent install script.
  2. Which objective are you least sure about? Re-read that section, then do its exercise in the practice pack.
  3. What surprised you when you ran the commands yourself?
On a real board

Repeat the key commands on your Raspberry Pi or lab board over SSH or the serial console. Note anything that behaves differently from your PC, such as missing tools, a BusyBox shell or a read-only filesystem.

Find your next step

↑ ↓ to move · Enter to open · Esc to close