Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
Update check_nvme.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderjackson authored Dec 12, 2022
1 parent 941aa84 commit db6ed28
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions check_nvme.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
#!/bin/bash
#
# Simple Nagios check for nvme using nvme-cli
# Author: Sam McLeod https://smcleod.net
# Original Author: Sam McLeod https://smcleod.net
# https://github.com/sammcj/nagios/blob/master/check_nvme.sh
# Maintainer : Pierre D. - https://dutiko.com/
#
# v3 : change detection method
# v2.3 : check if script is runned as root/sudo, exit with unknown error if not
# v2.2 : add check to detect if nvme disks are detected, exit with unknown error if not
# v2.1 : add checks to detect if nvme-cli is present, exit with unknown error if not
# v1 : Original
#
# Requirements:
# nvme-cli - git clone https://github.com/linux-nvme/nvme-cli
Expand All @@ -13,26 +21,30 @@ DISKS=$(lsblk -e 11,253 -dn -o NAME | grep nvme)
CRIT=false
MESSAGE=""

command -v sudo nvme >/dev/null 2>&1 || { echo >&2 "UNKNOWN: nvme-cli not found ; please install it" ; exit 3; }
if [ -z "$DISKS" ] ; then echo "UNKNOWN: no nvme disks found"; exit 3; fi

for DISK in $DISKS ; do
# Check for critical_warning
$(sudo nvme smart-log /dev/$DISK | awk 'FNR == 2 && $3 != 0 {exit 1}')
if [ $? == 1 ]; then
CRITICAL_WARNING=$(sudo nvme smart-log /dev/$DISK | grep "critical_warning" | awk '{print $3}')
if [ $CRITICAL_WARNING -ne 0 ]; then
CRIT=true
MESSAGE="$MESSAGE $DISK has critical warning "
MESSAGE="$MESSAGE $DISK has $CRITICAL_WARNING critical warning "
fi

# Check media_errors
$(sudo nvme smart-log /dev/$DISK | awk 'FNR == 15 && $3 != 0 {exit 1}')
if [ $? == 1 ]; then
MEDIA_ERRORS=$(sudo nvme smart-log /dev/$DISK | grep "media_errors" | awk '{print $3}')
if [ $MEDIA_ERRORS -ne 0 ]; then
CRIT=true
MESSAGE="$MESSAGE $DISK has media errors "
MESSAGE="$MESSAGE $DISK has $MEDIA_ERRORS media errors "
fi

# Check num_err_log_entries
$(sudo nvme smart-log /dev/$DISK | awk 'FNR == 16 && $3 != 0 {exit 1}')
if [ $? == 1 ]; then
NUM_ERR_LOG_ENTRIES=$(sudo nvme smart-log /dev/$DISK | grep ""num_err_log_entries | awk '{print $3}')
if [ $NUM_ERR_LOG_ENTRIES -ne 0 ]; then
CRIT=true
MESSAGE="$MESSAGE $DISK has errors logged "
MESSAGE="$MESSAGE $DISK has $NUM_ERR_LOG_ENTRIES errors logged "
fi
done

Expand Down

0 comments on commit db6ed28

Please sign in to comment.