Skip to content

Commit

Permalink
Add Floaty self-test nagios check script
Browse files Browse the repository at this point in the history
Add the script to the generated packages as
`/usr/lib/nagios/plugins/floaty-self-test`
  • Loading branch information
simu committed Jul 8, 2024
1 parent 92aa387 commit e2d1cf5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions floaty-self-test.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e2d1cf5

Please sign in to comment.