Linux Server checks with Goss

I’ve been playing a little with goss recently. Goss is similar to TestInfra in that it allows you to write tests to validate your infrastructure. Goss uses yaml to specify the expected state rather than python code unittests like Testinfra. It also has a couple of other interesting features making it stand out from the crowd…

The first is a test auto-generation feature. Have a service you want to monitor? Simply run this…

goss autoadd nagios

Goss will autodiscover various things about that service. Here’s what it found out about the Nagios service….

    installed: true
    - 4.4.3
    enabled: true
    running: true
    exists: true
    uid: 999
    gid: 998
    - nagios
    home: /var/spool/nagios
    shell: /sbin/nologin
    exists: true
    gid: 998
    running: true

The state of the nagios service can then be validated with…

goss validate

Total Duration: 0.037s
Count: 13, Failed: 0, Skipped: 0

We can also setup a http health endpoint…

goss serve &
2019/08/14 15:05:42 Starting to listen on: :8080

When we hit the endpoint the tests are executed…

curl http://localhost:8080/healthz
2019/08/14 15:06:48 requesting health probe
2019/08/14 15:06:48 Stale cache, running tests

Total Duration: 0.036s
Count: 13, Failed: 0, Skipped: 0

We can also run the tests as a Nagios check…

goss validate --format nagios
GOSS OK - Count: 13, Failed: 0, Skipped: 0, Duration: 0.032s

Note the execution speeds above. Goss outperforms python-based testing tools like TestInfra by a significant margin.

Leave a Reply