From e2d1cf52d2e92916acc415763eb1a85b85224b02 Mon Sep 17 00:00:00 2001 From: Simon Gerber Date: Wed, 3 Jul 2024 15:12:03 +0200 Subject: [PATCH] Add Floaty self-test nagios check script Add the script to the generated packages as `/usr/lib/nagios/plugins/floaty-self-test` --- .goreleaser.yml | 5 +++++ README.md | 4 ++++ floaty-self-test.sh | 31 +++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100755 floaty-self-test.sh diff --git a/.goreleaser.yml b/.goreleaser.yml index ef143d7..48a5d1f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -43,6 +43,11 @@ nfpms: - deb - rpm - apk + contents: + - src: floaty-self-test.sh + dst: /usr/lib/nagios/plugins/floaty-self-test + file_info: + mode: 0755 release: prerelease: auto diff --git a/README.md b/README.md index a830c2a..6e10f38 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,10 @@ Keepalived. /bin/floaty --json-log --verbose --test /etc/floaty.yml ``` +The Debian, RPM and Alpine packages generated by `goreleaser` include script `floaty-self-test.sh` as `/usr/lib/nagios/plugins/floaty-self-test`. +This script runs Floaty in test mode and expects a config file as its only argument. +The script is intended to be used as a check script for an Icinga2 check. + ### FIFO mode Floaty can run in FIFO mode allowing it to process notification events through a FIFO instead of using notify scrips diff --git a/floaty-self-test.sh b/floaty-self-test.sh new file mode 100755 index 0000000..e90ff43 --- /dev/null +++ b/floaty-self-test.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +set -u -o pipefail + +if [ $# -eq 0 ]; then + echo "Usage: $0 /path/to/floaty-config.yaml" + exit 3 +elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then + echo "Usage: $0 /path/to/floaty-config.yaml" + exit 3 +fi + +floaty_bin=/usr/bin/floaty +config_file="$1" + +if [ ! -f "$config_file" ]; then + echo "Floaty config file doesn't exist: ${config_file}" + exit 3 +fi + +self_test_output=$("$floaty_bin" -T "$config_file" 2>&1) +self_test_exit=$? + +if [ $self_test_exit -eq 0 ]; then + echo "Floaty self-test passed" + exit 0 +else + echo -e "Floaty self-test failed\n" + echo -e "${self_test_output}" + exit 2 +fi