From f7940cf53a341e1683c8669687e8b43cd38c984d Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Fri, 26 Mar 2021 11:24:37 +0100 Subject: [PATCH] add filesystem checks check_fs_errors and check_fs_writable --- check_cpu.md | 48 ++++++++++++++++++++++++ check_fs_errors | 83 ++++++++++++++++++++++++++++++++++++++++ check_fs_writable | 96 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 227 insertions(+) create mode 100644 check_cpu.md create mode 100755 check_fs_errors create mode 100755 check_fs_writable diff --git a/check_cpu.md b/check_cpu.md new file mode 100644 index 0000000..5396dea --- /dev/null +++ b/check_cpu.md @@ -0,0 +1,48 @@ +# IML Checks for Icinga / Nagios + +[Home](readme.md) + +--- + +## check CPU + +### Introduction + +**check_cpu** is a plugin to check cpu usage and cpu io wait. +It reads cpu data from output of top command and shows + + hwi - Time spent handling hardware interrupt routines. (Whenever a peripheral unit want attention form the CPU, it literally pulls a line, to signal the CPU to service it) + swi - Time spent handling software interrupt routines. (a piece of code, calls an interrupt routine...) + st - Time spent on involuntary waits by virtual cpu while hypervisor is servicing another processor (stolen from a virtual machine) + + nice - Time spent running niced user processes (User defined priority) + wait - Time spent on waiting on IO peripherals (eg. disk) + +system - Time spent in kernel space + user - Time spent in user space + idle - Time spent in idle operations + +For all values it sends performance data. + +### Syntax + +``$ check_NAME [-c CRITICAL] [-w WARING] [-i CRITICAL_IO]`` + +#### Parameters + +```text + -w VALUE cpu usage warning level (default: 75) + -c VALUE cpu usage critical level (default: 90) + + -i VALUE io wait critical level (default: 50) + + -h or --help show this help. + +``` + +# Examples + +``check_cpu -w 60 -c 80 -i 40`` + check cpu usage. + It shows a warning if usage is higer 60%. + It shows critical status if usage is higer 80% or io wait is 40% diff --git a/check_fs_errors b/check_fs_errors new file mode 100755 index 0000000..7f96088 --- /dev/null +++ b/check_fs_errors @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# ====================================================================== +# +# Check filesystem errors +# +# +# requirements: +# - sudo permission on /bin/journalctl +# +# ---------------------------------------------------------------------- +# 2021-03-23 v0.0 <axel.hahn@iml.unibe.ch> +# ====================================================================== + + +. `dirname $0`/inc_pluginfunctions + + +# ---------------------------------------------------------------------- +# functions +# ---------------------------------------------------------------------- + +function showHelp(){ +cat <<EOF +______________________________________________________________________ + +CHECK_FS_ERRORS check if kernel logs inconsistency messages + +(c) Institute for Medical Education - Univerity of Bern +Licence: GNU GPL 3 +______________________________________________________________________ + + +SYNTAX: +`basename $0` [-h] + +OPTIONS: + + -h or --help show this help. + +PARAMETERS: + + none + +EXAMPLE: +`basename $0` + +EOF +} +# ---------------------------------------------------------------------- +# MAIN +# ---------------------------------------------------------------------- + +# --- check required tools +# ph.require bc top + + +# --- check param -h +case "$1" in + "--help"|"-h") + showHelp + exit 0 + ;; + *) +esac + + +# ----- MAKE CHECK + +out=$( sudo /bin/journalctl | grep 'kernel: ' | grep -v 'check_fs_errors' | grep -E '(error|fail)' | grep 'inconsistent' ) +test ! -z "$out" && ph.setStatus "critical" + + +# ----- OUTPUT + +ph.status "check if kernel logs inconsistency messages" +echo $out + + +# ----- CLEANUP AND BYE! + +ph.exit + +# ---------------------------------------------------------------------- diff --git a/check_fs_writable b/check_fs_writable new file mode 100755 index 0000000..544ed3d --- /dev/null +++ b/check_fs_writable @@ -0,0 +1,96 @@ +#!/usr/bin/env bash +# ====================================================================== +# +# Check filesystem ... is it readonly? +# +# requirements: +# - none +# +# ---------------------------------------------------------------------- +# 2021-03-23 v0.0 <axel.hahn@iml.unibe.ch> +# ====================================================================== + + +. `dirname $0`/inc_pluginfunctions + +dirs2test="/tmp /var/tmp" +out="" + +# ---------------------------------------------------------------------- +# functions +# ---------------------------------------------------------------------- + +function showHelp(){ +cat <<EOF +______________________________________________________________________ + +CHECK_FS_READONLY check if filesystem is readonly - v0.0 + +(c) Institute for Medical Education - Univerity of Bern +Licence: GNU GPL 3 +______________________________________________________________________ + + +SYNTAX: +`basename $0` [directory [more directories]] + +OPTIONS: + + -h or --help show this help. + +PARAMETERS: + + DIRECTORY where to touch a temporary file + +EXAMPLE: +`basename $0` /tmp /root /var/www + +EOF +} +# ---------------------------------------------------------------------- +# MAIN +# ---------------------------------------------------------------------- + +# --- check required tools +# ph.require bc top + + +# --- check param -h +case "$1" in + "--help"|"-h") + showHelp + exit 0 + ;; + *) +esac + +# params are directory names ... if a param was given it overrides the internal default +test $# -gt 0 && dirs2test="$*" + + +# ----- MAKE CHECK + +for mydir in $dirs2test +do + touchfile=$mydir/icinga_touch_testfile__${RANDOM}_${RANDOM} + out="$out + +--- touching something into $mydir + $( touch $touchfile && ls -l $touchfile && rm -f $touchfile 2>&1 )" + if [ $? -ne 0 ]; then + ph.setStatus "critical" + fi +done + + +# ----- OUTPUT + +ph.status "check if filesystem is writable in $dirs2test $out" +#echo "$out" + + +# ----- CLEANUP AND BYE! + +ph.exit + +# ---------------------------------------------------------------------- -- GitLab