On my last couple of projects I’ve generally been using test-kitchen with chef. Recently I’ve been working on porting my collections of chef cookbooks to ansible and as there is a kitchen-ansble module, I might as well use inspec for testing as I have a body of working configurations for test-kitchen.

On the other hand, as soon as I start digging into the cookbooks, I’ve realised that I don’t have much understanding on how the inspec matchers work.

The documentation says use match for regular expressions, and cmp for less restrictive comparisons, but the examples seem to mix them up arbitrarily.

#!/bin/bash

START_STRING="1 week ago"
FORMAT="%Y-%m-%d %H:%M:%S"
next_date=$(date +%s -d "$START_STRING")

while [ "$next_date" -le "$(date +%s)" ]; do
  curr_date=$next_date
  next_date=$(date +%s -d "@$((next_date + 3600))")
  curr_data_iso=$(date +"$FORMAT" -d "@$curr_date")
  next_date_iso=$(date +"$FORMAT" -d "@$next_date")
  echo -n "$curr_data_iso  $next_date_iso "
  count=$(journalctl --quiet --no-pager --since "$curr_data_iso" --until "$next_date_iso"  | wc -l )
  echo -n " $count "
        [ $count -gt 100 ] && nummer=100 || nummer=$count
  printf '=%.0s' $(seq 1 $nummer)
        echo ""
done
echo ""

fefew