Skip to content

Commit 906999d

Browse files
authored
Merge pull request #92 from vshn/feat/floaty-self-test-nagios-plugin
Add Floaty self-test nagios check script
2 parents 92aa387 + e2d1cf5 commit 906999d

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

.goreleaser.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ nfpms:
4343
- deb
4444
- rpm
4545
- apk
46+
contents:
47+
- src: floaty-self-test.sh
48+
dst: /usr/lib/nagios/plugins/floaty-self-test
49+
file_info:
50+
mode: 0755
4651

4752
release:
4853
prerelease: auto

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ Keepalived.
182182
/bin/floaty --json-log --verbose --test /etc/floaty.yml
183183
```
184184

185+
The Debian, RPM and Alpine packages generated by `goreleaser` include script `floaty-self-test.sh` as `/usr/lib/nagios/plugins/floaty-self-test`.
186+
This script runs Floaty in test mode and expects a config file as its only argument.
187+
The script is intended to be used as a check script for an Icinga2 check.
188+
185189
### FIFO mode
186190

187191
Floaty can run in FIFO mode allowing it to process notification events through a FIFO instead of using notify scrips

floaty-self-test.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
set -u -o pipefail
4+
5+
if [ $# -eq 0 ]; then
6+
echo "Usage: $0 /path/to/floaty-config.yaml"
7+
exit 3
8+
elif [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
9+
echo "Usage: $0 /path/to/floaty-config.yaml"
10+
exit 3
11+
fi
12+
13+
floaty_bin=/usr/bin/floaty
14+
config_file="$1"
15+
16+
if [ ! -f "$config_file" ]; then
17+
echo "Floaty config file doesn't exist: ${config_file}"
18+
exit 3
19+
fi
20+
21+
self_test_output=$("$floaty_bin" -T "$config_file" 2>&1)
22+
self_test_exit=$?
23+
24+
if [ $self_test_exit -eq 0 ]; then
25+
echo "Floaty self-test passed"
26+
exit 0
27+
else
28+
echo -e "Floaty self-test failed\n"
29+
echo -e "${self_test_output}"
30+
exit 2
31+
fi

0 commit comments

Comments
 (0)