diff --git a/.github/workflows/lint-markdown.yml b/.github/workflows/lint-markdown.yml new file mode 100644 index 0000000..798cd9e --- /dev/null +++ b/.github/workflows/lint-markdown.yml @@ -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/prettier_action@v4.3 + with: + prettier_options: --write ${{ steps.changed-files.outputs.markdown_all_changed_files }} diff --git a/.github/workflows/lint-shell.yml b/.github/workflows/lint-shell.yml new file mode 100644 index 0000000..1617be4 --- /dev/null +++ b/.github/workflows/lint-shell.yml @@ -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_smartarray.sh + shellcheck: + name: shellcheck + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Run ShellCheck + uses: ludeeus/action-shellcheck@2.0.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index f122695..e8760f5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,51 +1,86 @@ # Changelog + All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [1.3.0] - 2007-01-13 + ### Added + - Initial public release + ## [1.3.1] - 2007-01-19 + ### Changed + - Using tr to replace the string-output from camcontrol, for a more human-readable script, no changes in functionality. + ## [1.4.0] - 2007-02-08 + ### Changed + - If a volume didn't have a known state, it just wouldn't show that volume, it now exits with errorcode3 and outputs as "unknown state" + ## [1.4.1] - 2007-02-14 + ### Changed + - Patch by Christoph Schug applied to replace two (cut) systemcalls with one (sed) when getting DEVICESTRING. - Added quotes in various places for consistency - Don't set state to unknown if state is already critical (for code added in 1.4) - unset $ERR before doing anything to avoid problems if the variable is already set + ## [1.4.2] - 2007-02-27 + ### Changed + - The nagios web interface would only show one RAID volume, it seems nagios blocks "|" in the input and throws everything after that away. - Changed the "|" to a "/" in output - Thanks to Kai Gallasch for reporting this -## [1.4.3] - 2007-03-23 + +## [1.4.3] - 2007-03-23 + ### Changed + - Changed tr A-Z a-z to tr [:upper:] [:lower:] to prevent problems with various locales. - Thanks to Oliver Fromme for reporting this + ## [1.4.4] - 2007-04-20 + ### Added + - Added online expansion - Thanks to Mikael Antonsen for reporting this + ## [1.4.5] - 2007-10-08 + ### Changed + - Problems with status of ADG (Advanced Data Guarding) Volumes fixed. - Thanks to Peter Larsen for reporting this + ## [1.5.0] - 2014-06-25 + ### Added + - Can now email an address of choice, just use email address(es) as arguments to shellscript + ### Changed + - check if camcontrol binary exists on system before running script + ## [1.6.0] - 2014-11-18 + ### Changed + - HP Finally changed the SCSI output of their latest smart array controllers, updated script to be compatible with both versions - Thanks to Paul Yates for reporting this and providing sample output + ## [1.7.0] - 2014-11-19 + ### Added + - Added support for FreeBSD 10.1 and later - Thanks to Marc Peters for reporting this diff --git a/README.md b/README.md index a7793f3..75a87e0 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,43 @@ # monitor HP Smart Array from NRPE / cron for FreeBSD +[![CodeFactor](https://www.codefactor.io/repository/github/klintrup/check_smartarray/badge)](https://www.codefactor.io/repository/github/klintrup/check_smartarray) +[![License Apache 2.0](https://img.shields.io/github/license/Klintrup/check_smartarray)](https://github.com/Klintrup/check_smartarray/blob/main/LICENSE) +[![Latest Release](https://img.shields.io/github/v/release/Klintrup/check_smartarray)](https://github.com/Klintrup/check_smartarray/releases) +[![Contributors](https://img.shields.io/github/contributors-anon/Klintrup/check_smartarray)](https://github.com/Klintrup/check_smartarray/graphs/contributors) +[![Issues](https://img.shields.io/github/issues/Klintrup/check_smartarray)](https://github.com/Klintrup/check_smartarray/issues) +[![build](https://img.shields.io/github/actions/workflow/status/Klintrup/check_smartarray/lint-shell.yml)](https://github.com/Klintrup/check_smartarray/actions/workflows/lint-shell.yml) + ## Synopsis + I wrote this little check-script for nrpe/nagios to get the status of various raids in a box, and output the failed volumes if any such exist. ## Syntax -``$path/check_smartarray.sh [email] [email]`` + +`$path/check_smartarray.sh [email] [email]` If no arguments are specified, the script will assume its run for NRPE. If one or more email addresses are specified, the script will send an email in case an array reports an error. ## Output Examples -| output | description | -|--|--| -| ok | The device is reported as ok by the smart array controller | -| 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 | -| expanding | The RAID is expanding, will return to OK when done | + +| output | description | +| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| ok | The device is reported as ok by the smart array controller | +| 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 | +| expanding | The RAID is expanding, will return to OK when done | | ready for recovery | The RAID is ready for recovery, but not recovering. This can happen if automatic recovery is disabled, and on some smaller versions of the Smart Array Controllers where only one RAID volume can be rebuild at a time | -| unknown state | Volume is in an unknown state. Please submit a bug report so I can udate the script, include the following output. ``camcontrol devlist``, ``camcontrol inquiry da0 -D`` - run the inquiry for every volume on the system. | +| unknown state | Volume is in an unknown state. Please submit a bug report so I can udate the script, include the following output. `camcontrol devlist`, `camcontrol inquiry da0 -D` - run the inquiry for every volume on the system. | # Compability + Should work on all smartarray controllers though - if you test on another (working or not) controller, I would like to know, please mail me on soren at klintrup.dk. I have tested the script on the following controllers - * HP Smart Array 6i - * HP Smart Array 5i - * HP Smart Array P400 - * HP Smart Array P410 - * HP Smart Array P420 - * HP Smart Array P800 +- HP Smart Array 6i +- HP Smart Array 5i +- HP Smart Array P400 +- HP Smart Array P410 +- HP Smart Array P420 +- HP Smart Array P800 diff --git a/check_smartarray.sh b/check_smartarray.sh index 936592a..562f583 100644 --- a/check_smartarray.sh +++ b/check_smartarray.sh @@ -3,29 +3,34 @@ # Written by: Søren Klintrup # Get your copy from: https://github.com/Klintrup/check_smartarray/ +unset ERRORSTRING +unset OKSTRING +unset ERR + PATH="/sbin:/bin:/usr/sbin:/usr/bin" if [ -x "/sbin/camcontrol" ] then - DEVICES="$(camcontrol devlist|egrep "(HP|COMPAQ) RAID"|sed -Ee 's/.*(pass[0-9]{1,3}).*/\1/')" + # shellcheck disable=SC2086 + DEVICES="$(camcontrol devlist|grep -Ee "(HP|COMPAQ) RAID"|sed -Ee 's/.*(pass[0-9]{1,3}).*/\1/')" else ERRORSTRING="camcontrol binary does not exist on system" ERR=3 fi -unset ERRORSTRING -unset OKSTRING -unset ERR - for DEVICE in ${DEVICES} do + # shellcheck disable=SC2086 DEVICENAME="$(camcontrol devlist|grep ${DEVICE}|sed -Ee 's/.*(da[0-9]{1,3}).*/\1/')" + # shellcheck disable=SC2086 DEVICESTRING="$(camcontrol inquiry ${DEVICE} -D|sed -n -e 's/^[^<]*<\([^>]*\)>.*$/\1/p')" - if [ "$(echo ${DEVICESTRING}|tr [:upper:] [:lower:]|sed -Ee 's/.*(rea|int|exp|rec|fai|ok).*/\1/')" = "" ] + # shellcheck disable=SC2086 + if [ "$(echo ${DEVICESTRING}|tr '[:upper:]' '[:lower:]'|sed -Ee 's/.*(rea|int|exp|rec|fai|ok).*/\1/')" = "" ] then ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: unknown state" if ! [ "${ERR}" = 2 ];then ERR=3;fi else - case $(echo ${DEVICESTRING}|tr [:upper:] [:lower:]|sed -Ee 's/.*(rea|int|exp|rec|fai|ok).*/\1/') in + # shellcheck disable=SC2086 + case $(echo ${DEVICESTRING}|tr '[:upper:]' '[:lower:]'|sed -Ee 's/.*(rea|int|exp|rec|fai|ok).*/\1/') in int) ERR=2 ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: DEGRADED" @@ -35,15 +40,15 @@ do ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: FAILED" ;; rec) - if ! [ "${ERR}" = 2 -o "${ERR}" = 3 ]; then ERR=1;fi + if ! [ "${ERR}" = 2 ] || [ "${ERR}" = 3 ]; then ERR=1;fi ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: rebuilding" ;; exp) - if ! [ "${ERR}" = 2 -o "${ERR}" = 3 ]; then ERR=1;fi + if ! [ "${ERR}" = 2 ] || [ "${ERR}" = 3 ]; then ERR=1;fi ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: expanding" ;; rea) - if ! [ "${ERR}" = 2 -o "${ERR}" = 3 ]; then ERR=1;fi + if ! [ "${ERR}" = 2 ] || [ "${ERR}" = 3 ]; then ERR=1;fi ERRORSTRING="${ERRORSTRING} / ${DEVICENAME}: ready for recovery" ;; ok) @@ -57,12 +62,12 @@ if [ "${1}" ] then if [ "${ERRORSTRING}" ] then - echo "${ERRORSTRING} ${OKSTRING}"|sed s/"^\/ "//|mail -s "$(hostname -s): ${0} reports errors" -E ${*} + echo "${ERRORSTRING} ${OKSTRING}"|sed s/"^\/ "//|mail -s "$(hostname -s): ${0} reports errors" -E "${@}" fi else -if [ "${ERRORSTRING}" -o "${OKSTRING}" ] +if [ "${ERRORSTRING}" ] || [ "${OKSTRING}" ] then - echo ${ERRORSTRING} ${OKSTRING}|sed s/"^\/ "// + echo "${ERRORSTRING} ${OKSTRING}"|sed s/"^\/ "// exit ${ERR} else echo no raid volumes found