Skip to content

Commit

Permalink
Merge pull request #3 from Klintrup/shellcheck-recommendations
Browse files Browse the repository at this point in the history
add shellcheck
  • Loading branch information
Klintrup authored Dec 1, 2023
2 parents 73ec17a + 9b833ea commit 3080938
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 72 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[*.sh]
# like -i=4
indent_style = space
indent_size = 2

shell_variant = posix # --language-variant
binary_next_line = true
switch_case_indent = true # --case-indent
space_redirects = true
keep_padding = true
function_next_line = true # --func-next-line
28 changes: 28 additions & 0 deletions .github/workflows/lint-markdown.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
on:
pull_request:

name: lint-markdown
permissions:
contents: write

jobs:
prettier:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v40
with:
files_yaml: |
markdown:
- '**.md'
- name: Prettify code
if: steps.changed-files.outputs.markdown_any_changed == 'true'
uses: creyD/[email protected]
with:
prettier_options: --write ${{ steps.changed-files.outputs.markdown_all_changed_files }}
22 changes: 22 additions & 0 deletions .github/workflows/lint-shell.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
pull_request:

name: lint-shell
permissions:
contents: write

jobs:
sh:
name: sh-noexec-verify
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck
run: sh -n check_zpool.sh
shellcheck:
name: shellcheck
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run ShellCheck
uses: ludeeus/[email protected]
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
# monitor zfs from nagios/NRPE or cron on FreeBSD

[![CodeFactor](https://www.codefactor.io/repository/github/klintrup/check_zpool/badge)](https://www.codefactor.io/repository/github/klintrup/check_zpool)
[![License Apache 2.0](https://img.shields.io/github/license/Klintrup/check_zpool)](https://github.com/Klintrup/check_zpool/blob/main/LICENSE)
[![Latest Release](https://img.shields.io/github/v/release/Klintrup/check_zpool)](https://github.com/Klintrup/check_zpool/releases)
[![Contributors](https://img.shields.io/github/contributors-anon/Klintrup/check_zpool)](https://github.com/Klintrup/check_zpool/graphs/contributors)
[![Issues](https://img.shields.io/github/issues/Klintrup/check_zpool)](https://github.com/Klintrup/check_zpool/issues)
[![build](https://img.shields.io/github/actions/workflow/status/Klintrup/check_zpool/shellcheck.yml)](https://github.com/Klintrup/check_zpool/actions/workflows/shellcheck.yml)

## Synopsis

Simple check-script for nrpe/nagios to get the status of various zpool volumes in a box, and output the failed volumes if any such exist.
Simple check-script for NRPE/nagios to get the status of various zpool volumes in a box, and output the failed volumes if any such exist.

## Syntax

``` bash
```bash
check_zpool.sh [email] [email]
```

Expand All @@ -16,19 +23,19 @@ If no arguments are specified, the script will assume its run for NRPE. If one o

`tank: DEGRADED / data: rebuilding / system: ok`

Failed/rebuilding volumes will always be first in the output string, to help diagnose the problem when recieving the output via pager/sms.
Failed/rebuilding volumes will always be first in the output string, to help diagnose the problem when receiving the output via pager/sms.

## Output examples

| output | description |
| -- | -- |
| ok | The device is reported as ok by zpool |
| DEGRADED | The RAID volume is degraded, it's still working but without the safety of RAID, and in some cases with severe performance loss. |
| rebuilding | The RAID is rebuilding, will return to OK when done |
| unknown state | Volume is in an unknown state. Please report this as an issue on [GitHub](https://github.com/Klintrup/check_zpool/issues) |
| output | description |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| ok | The device is reported as ok by zpool |
| DEGRADED | The RAID volume is degraded, it's still working but without the safety of RAID, and in some cases with severe performance loss. |
| rebuilding | The RAID is rebuilding, will return to OK when done |
| unknown state | Volume is in an unknown state. Please report this as an issue on [GitHub](https://github.com/Klintrup/check_zpool/issues) |

## Compability
## Compatibility

Should work on all versions of FreeBSD with zfs.

Tested on FreeBSD 8.0-10.1
Tested on FreeBSD 8.0-10.1
112 changes: 51 additions & 61 deletions check_zpool.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,62 @@
# NRPE check for zpool
# Written by: Søren Klintrup <github at klintrup.dk>
# Get your copy from https://github.com/Klintrup/check_zpool
# version 1.2

PATH="/sbin:/bin:/usr/sbin:/usr/bin"
if [ -x "/sbin/zpool" ]
then
DEVICES="$(zpool list -H -o name)"
else
ERRORSTRING="zpool binary does not exist on system"
ERR=3
fi
unset ERRORSTRING
unset OKSTRING
unset ERR

for DEVICE in ${DEVICES}
do
DEVICESTRING="$(zpool list -H -o health ${DEVICE})"
if [ "$(echo ${DEVICESTRING}|tr [:upper:] [:lower:]|sed -Ee 's/.*(degraded|faulted|offline|online|removed|unavail).*/\1/')" = "" ]
then
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: unknown state"
if ! [ "${ERR}" = 2 ];then ERR=3;fi
else
case $(echo ${DEVICESTRING}|tr [:upper:] [:lower:]|sed -Ee 's/.*(degraded|faulted|offline|online|removed|unavail).*/\1/') in
degraded)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: DEGRADED"
;;
faulted)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: FAULTED"
;;
offline)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: OFFLINE"
;;
removed)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: REMOVED"
;;
unavail)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: UNAVAIL"
;;
faulted)
ERR=3
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: FAULTED"
;;
online)
OKSTRING="${OKSTRING} / ${DEVICE}: online"
;;
esac
fi
if [ -x "/sbin/zpool" ]; then
DEVICES="$(zpool list -H -o name)"
else
ERRORSTRING="zpool binary does not exist on system"
ERR=3
fi

for DEVICE in ${DEVICES}; do
DEVICESTRING="$(zpool list -H -o health "${DEVICE}")"
if [ "$(echo "${DEVICESTRING}" | tr '[:upper:]' '[:lower:]' | sed -Ee 's/.*(degraded|faulted|offline|online|removed|unavail).*/\1/')" = "" ]; then
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: unknown state"
if ! [ "${ERR}" = 2 ]; then ERR=3; fi
else
case $(echo "${DEVICESTRING}" | tr '[:upper:]' '[:lower:]' | sed -Ee 's/.*(degraded|faulted|offline|online|removed|unavail).*/\1/') in
degraded)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: DEGRADED"
;;
faulted)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: FAULTED"
;;
offline)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: OFFLINE"
;;
removed)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: REMOVED"
;;
unavail)
ERR=2
ERRORSTRING="${ERRORSTRING} / ${DEVICE}: UNAVAIL"
;;
online)
OKSTRING="${OKSTRING} / ${DEVICE}: online"
;;
esac
fi
done
if [ "${1}" ]
then
if [ "${ERRORSTRING}" ]
then
echo "${ERRORSTRING} ${OKSTRING}"|sed s/"^\/ "//|mail -s "$(hostname -s): ${0} reports errors" -E ${*}
fi
if [ "${1}" ]; then
if [ "${ERRORSTRING}" ]; then
echo "${ERRORSTRING} ${OKSTRING}" | sed s/"^\/ "// | mail -s "$(hostname -s): ${0} reports errors" -E "${*}"
fi
else
if [ "${ERRORSTRING}" -o "${OKSTRING}" ]
then
echo "${ERRORSTRING} ${OKSTRING}"|sed -E s/"^[[:blank:]]{1,}\/ "//
exit ${ERR}
else
echo no zpool volumes found
exit 3
fi
fi
if [ "${ERRORSTRING}" ] || [ "${OKSTRING}" ]; then
echo "${ERRORSTRING} ${OKSTRING}" | sed -E s/"^[[:blank:]]{1,}\/ "//
exit ${ERR}
else
echo no zpool volumes found
exit 3
fi
fi

0 comments on commit 3080938

Please sign in to comment.