inc_pluginfunctions.md 2.53 KB
Newer Older
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
1
# Shared functions
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
2

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
3
## Init
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
4

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
5
All scripts start with sourcing a shared bash file
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
6

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
7
``. `dirname $0`/inc_pluginfunctions``
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
8

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
9
In that script are several functions starting with prefix **ph.** (=plugin helper)
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
10

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
11
## Available functions
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
12
13
14
15

This is a list in alphabetic order

**ph.abort** [TEXT]
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
16

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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:

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
41
``typeset -i iWarnLimit=`ph.getValueWithParam 75 w "$@"` ``
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
42
43
44

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

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
**ph.hasParamoption** PARAMNAME "$@"

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

Example:

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

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

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
60
61
62
63
64
65
66
**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

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
67
set statuscode by verifying integer(!) value with crtical and warning limit 
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
68

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
69
70
Example:

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
71
``ph.setStatusByLimit $ramUsage $iWarnLimit $iCriticalLimit``
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
72
73
74
75
76
77
78
79
80
81
82
83
84

**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.

85
**ph.perfdeltaspeed** [VARNAME] [VALUE] [[unit] [isfloat]]
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
86
87
88

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

89
Unit value can be
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
90

91
92
93
* s or sec - for seconds
* m or min - for minutes

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
94
95
Example:

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
96
97
98
99
```txt
# speed in byte per sec based on last stored value and its age
iSpeedRead=` ph.perfdeltaspeed "netio-${myinterface}-rx" $iRead`
```
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
100
101
102
103
104

**ph.perfshow**

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

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
105
**ph.require** [PROG [...PROG_N]]
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
106

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
107
108
109
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:
Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
110

Hahn Axel (hahn)'s avatar
Hahn Axel (hahn) committed
111
`ph.require bc lsblk`