Icinga2 Plugins: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
(→Script) |
|||
| Zeile 2: | Zeile 2: | ||
=Script= | =Script= | ||
| + | *cat /usr/lib/nagios/plugins/check_processes | ||
| + | </pre> | ||
| + | #!/bin/bash | ||
| + | function check_pgrep() | ||
| + | { | ||
| + | for PROC in $PROCS | ||
| + | do | ||
| + | PROCID=$(pgrep -x $PROC | head -1) | ||
| + | if test -z "$PROCID" | ||
| + | then | ||
| + | ERRLIST="$ERRLIST $PROC" | ||
| + | fi | ||
| + | done | ||
| + | if [[ -n $ERRLIST ]] | ||
| + | then | ||
| + | echo "MISSING:$ERRLIST" | ||
| + | exit 2 | ||
| + | else | ||
| + | echo "OK: $PROCS" | ||
| + | fi | ||
| + | } | ||
| + | while getopts ":p:" opt | ||
| + | do | ||
| + | case $opt in | ||
| + | p) PROCS=$OPTARG;; | ||
| + | \?) echo "USAGE: $0 -p PROC"; exit 2 ;; | ||
| + | :) | ||
| + | echo "Option -$OPTARG requires an argument." >&2 | ||
| + | exit 1 | ||
| + | ;; | ||
| + | esac | ||
| + | done | ||
| + | |||
| + | if test -n "$PROCS" | ||
| + | then | ||
| + | check_pgrep | ||
| + | else | ||
| + | echo "USAGE: $0 -p PROC" | ||
| + | exit 1 | ||
| + | fi | ||
| + | <pre> | ||
=Definition= | =Definition= | ||
Version vom 20. November 2018, 17:56 Uhr
Example
Script
- cat /usr/lib/nagios/plugins/check_processes
- !/bin/bash
function check_pgrep() { for PROC in $PROCS do
PROCID=$(pgrep -x $PROC | head -1) if test -z "$PROCID" then ERRLIST="$ERRLIST $PROC" fi
done if -n $ERRLIST then
echo "MISSING:$ERRLIST" exit 2
else
echo "OK: $PROCS"
fi }
while getopts ":p:" opt
do
case $opt in
p) PROCS=$OPTARG;;
\?) echo "USAGE: $0 -p PROC"; exit 2 ;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
if test -n "$PROCS" then check_pgrep else
echo "USAGE: $0 -p PROC"
exit 1 fi
=Definition=
<pre>
cat<<HERE >> /usr/share/icinga2/include/command-plugins.conf
object CheckCommand "processes" {
import "plugin-check-command"
command = [ PluginDir + "/check_processes" ]
timeout = 1m
arguments += {
"-p" = {
description = "Programnames"
required = true
value = "$processes_names$"
}
}
}
HERE