Seeing what changed every day
Once lemano discover runs on a schedule (running discovery on a
schedule), lemano summary says what changed on your
servers, who changed it, and whether anything needs you. It reads the store
only and connects to no server, so it takes well under a second and can
run as often as you like.
Reading the summary
$ lemano summary
3 servers since yesterday 09:00: 1 not read, 1 changed, 1 unchanged.
db-01: not read
unreachable for 3h (3 passes)
next: lemano history db-01 --passes
web-01: changed, generation 4 -> 6
12 packages upgraded by apt (unattended-upgrade): bash, curl, libc6 and 9 more
File /etc/nginx/conf.d/app.conf added by alice (sudo)
Package htop installed by apt (alice)
next: lemano diff web-01 4 6
db-01 has not answered for three hours: its passes are failing, and the
block names the command that shows them. web-01 was upgraded by the
unattended-upgrade job, and alice added a file through sudo and
installed a package. app-01 did not change and is only counted. On a
quiet day:
$ lemano summary
1 server since 09:00: 1 unchanged.
The first line counts the servers by state over the last 24 hours. Below it comes one block for each server that needs you, in this order:
- With a condition: a changed host key, a changed machine identity, a
trial a revert left unfinished. The block names the command that
answers it (
lemano target rekey,lemano target confirm-identity,lemano target end-trial). - Not read: its next pass is overdue, a blind window is open, or its latest pass was unreachable, partial or could not read a kind.
- Changed: generations were written in the period.
Changes are grouped, never one line per object when they share a cause.
Package operations are grouped by the log that recorded them, with the
user when the log names one. Other objects are grouped by kind and by who
changed them, as the host’s logs recorded it (sudo, auditd), or
(unknown) when no log did. Changes made by lemano revert say so, and
reverts and trials are listed. After about ten lines the block points to
lemano diff, which shows every change field by field.
Servers that did not change and need nothing are only counted. When no server needs you, the first line is the whole output.
Other periods: --since 168h for a week, --since baseline for each
server’s changes since its accepted baseline,
with the commands to accept them (lemano baseline) or go back
(lemano revert --to). Servers that have no baseline yet are named on one
line at the end, and do not count as needing you.
A line at login
Because a quiet summary is a single line, it can sit in a shell’s login
file as it is. In ~/.profile (or ~/.bash_profile, ~/.zprofile) of the
account that owns the store:
lemano summaryOn a machine where the schedule runs under another account, read the file it writes instead:
cat /var/lib/lemano/summary.txtThe latest summary in a file
--out FILE writes the output to a file instead of standard output: a
temporary file in the same folder, then a rename over FILE, so a reader (a
web server, a dashboard, node_exporter) never sees half of it. A new file
gets the mode a shell redirect would give it (0666 less the umask); an
existing one keeps its mode. The timer and cron line of the scheduling
guide already keep /var/lib/lemano/summary.txt up to date.
For a dashboard or a web page, keep the JSON instead, which also lists the unchanged servers:
lemano summary -o json --out /var/lib/lemano/summary.jsonIts fields are described in the summary
reference. A summary names servers,
objects, users and packages; it never holds a file’s content, a sealed
value or a command line. Past summaries are not
kept: the store holds the history, and --since computes any period
again.
Prometheus
-o prometheus writes gauges in the Prometheus text format, one sample per
server, for node_exporter’s textfile collector. node_exporter reads the
*.prom files of the folder given to --collector.textfile.directory;
Lemano’s temporary file does not end in .prom, so it is never read half
written.
Add a drop-in to the service of the scheduling guide,
/etc/systemd/system/lemano-discover.service.d/prometheus.conf:
[Service]
ExecStopPost=/usr/local/bin/lemano summary -o prometheus --out /var/lib/node_exporter/textfile_collector/lemano.promThe folder must be writable by the lemano account and readable by
node_exporter. The gauges are listed in the
summary reference.
The file is written after each pass, so its gauges stop moving when the
passes stop: lemano_pass_overdue keeps the value of the last pass and
cannot say that no pass ran since. The rules below alert on ages instead,
which grow on their own: the age of the latest complete pass of each
server, and the age of the file itself (node_exporter’s
node_textfile_mtime_seconds), which catches a timer that stopped for
every server. Two hours suits the default interval of one hour; use about
two intervals. A third rule alerts on an open condition:
groups:
- name: lemano
rules:
- alert: LemanoNoCompletePass
expr: time() - lemano_last_complete_pass_timestamp_seconds > 2 * 3600
annotations:
summary: "No complete Lemano pass on {{ $labels.target }} for two hours"
description: "Run lemano history {{ $labels.target }} --passes on the machine that runs Lemano."
- alert: LemanoSummaryStale
expr: time() - node_textfile_mtime_seconds{file=~".*/lemano\\.prom"} > 2 * 3600
annotations:
summary: "Lemano has not written its summary on {{ $labels.instance }} for two hours"
description: "The passes stopped: check the timer with systemctl list-timers lemano-discover.timer."
- alert: LemanoCondition
expr: lemano_condition == 1
annotations:
summary: "{{ $labels.target }} has the condition {{ $labels.condition }}"
description: "Run lemano summary {{ $labels.target }} for the command that answers it."The drop-in and the rules are in docs/examples/.
A message in Slack or Teams
Lemano sends no message itself. A short script turns the JSON summary into
a chat message with jq and posts it with curl to an incoming webhook,
only when a server needs attention:
#!/bin/sh
# Posts Lemano's summary to a chat webhook when a target needs attention,
# and posts nothing otherwise. The webhook URL is read from a curl config
# file (one line: url = "https://..."), readable by this account only, so
# that it never appears on a command line, where other users of the
# machine could see it.
set -eu
config=${LEMANO_WEBHOOK_CONFIG:-/etc/lemano/webhook.curl}
status=0
summary=$(lemano summary -o json --detailed-exitcode) || status=$?
case $status in
0) exit 0 ;; # nothing needs attention
8) ;; # at least one target needs attention
*) exit "$status" ;;
esac
printf '%s\n' "$summary" | jq '{text: ([.headline] + [.targets[]
| select(.state != "unchanged")
| "\(.name): \(.state)" + (if .actions then " (" + (.actions | join("; ")) + ")" else "" end)]
| join("\n"))}' |
curl --silent --show-error --fail --config "$config" \
--header 'Content-Type: application/json' --data-binary @-The webhook URL is a secret: anyone who has it can post to the channel. Keep it in the curl config file, owned by the account that runs the script with mode 0600:
url = "https://hooks.slack.com/services/..."A command-line argument is visible to every user of the machine in the
process list; a file read by curl --config is not. The message is
{"text": "..."}, the body a Slack incoming webhook takes. A Teams
workflow that posts webhook requests to a channel expects its own body;
change the jq filter to match it.
Run the script after the summary, for example as one more ExecStopPost=
line of the service. The message names servers, objects and users; post it
only to a channel whose members may see them. The script is
docs/examples/summary-webhook.sh.
Exit codes
With --detailed-exitcode, lemano summary exits 8 when at least one
server needs attention and 0 otherwise; a failure keeps its own code. See
exit codes.