Skip to content
Snippets Groups Projects
inc_pluginfunctions.md 2.53 KiB

Shared functions

Init

All scripts start with sourcing a shared bash file

. `dirname $0`/inc_pluginfunctions

In that script are several functions starting with prefix ph. (=plugin helper)

Available functions

This is a list in alphabetic order

ph.abort [TEXT]

Shows error message and exit with status unknown.

ph.exit

Use at the end to send performance data and exit plugin with set statuscode

ph.getFileAge [FILE]

get age of a given file in sec

ph.getOS

get operating system as lowercase - centos/ debian/ ubuntu ...

ph.getOSMajor

get OS Major version as integer, i.e. 7 on a CentOS7

ph.getValueWithParam VALUE PARAMNAME "$@"

return default value or its override from command line.

Example:

typeset -i iWarnLimit=`ph.getValueWithParam 75 w "$@"`

This will set variable iWarnLimit based on CLI parameter -w [value] ... if it does not exist it gets the default 75.

ph.hasParamoption PARAMNAME "$@"

check if a letter was used as command line option and return as 0 (=no) or 1 (=yes)

Example:

bOptHelp=`ph.hasParamoption "h" "$@"`

if [ $bOptHelp -eq 1 -o $# -lt 1 ]; then
    _usage
    exit 0
fi

ph.setStatus [STATUS]

Set a status with keyword ok, warning, critical, unknown You can override it as often you want during the script. Based on the last setting the ph.exit function will set the exitcode.

ph.setStatusByLimit VALUE WARNLIMIT CRITLIMIT

set statuscode by verifying integer(!) value with crtical and warning limit

Example:

ph.setStatusByLimit $ramUsage $iWarnLimit $iCriticalLimit

ph.status [TEXT]

Show status as Text.

ph.execIfReady [FUNCTION] [ [WAITTIME] [MAXTRIES] ]

Execute a command and repeat max. MAXTRIES times if it fails.

ph.perfadd [VALUE] [OPTIONS…]

Add performance data. Their output will be written with ph.exit. So you are free to add perfomance data anywhere within your check script.

ph.perfdeltaspeed [VARNAME] [VALUE] [[unit] [isfloat]]

For increasing system counters: get changerate per second since last check.

Unit value can be

  • s or sec - for seconds
  • m or min - for minutes

Example:

# speed in byte per sec based on last stored value and its age
iSpeedRead=` ph.perfdeltaspeed "netio-${myinterface}-rx" $iRead`

ph.perfshow

dump performance data (if u are not using ph.exit)

ph.require [PROG [...PROG_N]]

check if a binary PROG exists in search path (=are installed) - if not then execution stops with showing a warning message and status unknown (using ph.abort).

Example:

ph.require bc lsblk