ph.status "timesync: a timesync service is active on this ${myos} host"
else
ph.setStatus "critical"
ph.status "timesync: there is no active timesync - you need to activate ntpd or timesyncd on this ${myos} host"
fi
fi
# /timedatectl
```
Use at the end to send performance data and exit plugin with set statuscode
### ph.exit
Use at the end to send performance data and exit plugin with set statuscode.
This is the last line of your check script.
Syntax:
```text
ph.exit
```
**ph.getFileAge** [FILE]
(no parameters)
### ph.getFileAge
get age of a given file in sec
**ph.getOS**
The file must be reachable by the monitoring user.
Syntax:
```text
ph.getFileAge [FILE]
```
Parameters:
1. FILE {string} - filename
### ph.getOS
get operating system as lowercase - centos/ debian/ ubuntu ...
**ph.getOSMajor**
Syntax:
```text
ph.getOS
```
(no parameters)
Example:
```shell
$ bash -c". inc_pluginfunctions; ph.getOS"
manjaro
```
In a script:
```shell
distro=$( ph.getOS )
case$distroin
"centos"|"almalinux")
# ... do something
;;
"debian"|"ubuntu")
# ... do something
;;
*)
ph.abort "UNKNOWN: distro [$distro] was detected but is not supported (yet)."
;;
esac
```
### ph.getOSMajor
get OS Major version as integer, i.e. 7 on a CentOS7
**ph.getValueWithParam** VALUE PARAMNAME "$@"
Syntax:
```text
ph.getOSMajor
```
return default value or its override from command line.
(no parameters)
### ph.getValueWithParam
Return default value or its override from command line.
Syntax:
```text
ph.getFileAge VALUE PARAMNAME "$@"
```
Parameters:
1. VALUE {integer} - the default value if the parameter (2nd param) was not set in the command line
2. PARAMNAME {char} - a single letter for the parameter to search
3. PARAM LIST {string} - list of all parameters to check; use "$@" set all current params from command line
Example:
``typeset -i iWarnLimit=`ph.getValueWithParam 75 w "$@"` ``
```shell
# set default / override from command line params
typeset-iiWarnLimit=$( ph.getValueWithParam 75 w "$@")
typeset-iiCriticalLimit=$( ph.getValueWithParam 90 c "$@")
```
This will set variable iWarnLimit based on CLI parameter -w [value] ... if it does not exist it gets the default 75.
**ph.hasParamoption** PARAMNAME "$@"
### ph.hasParamoption
check if a letter was used as command line option and return as 0 (=no) or 1 (=yes)
Syntax:
```text
ph.hasParamoption PARAMNAME "$@"
```
Parameters:
1. PARAMNAME{char} - a single letter for the parameter to search
2. PARAM LIST{string} - list of all parameters to check; use "$@" set all current params from command line
Example:
```bash
...
...
@@ -57,39 +210,74 @@ if [ $bOptHelp -eq 1 -o $# -lt 1 ]; then
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.perfadd
**ph.setStatusByLimit** VALUE WARNLIMIT CRITLIMIT
Add performance data. Their output will be written with ```ph.exit```. So you are free to add perfomance data anywhere within your check script.
set statuscode by verifying integer(!) value with crtical and warning limit
Syntax:
```txt
ph.perfadd LABEL VALUE [ WARNLEVEL CRITICAL [ MIN MAX ] ]
```
Parameters:
1. LABEL {string} - a label for the performance value; it must be unique for your script; The given value will be cleaned to lowercase; other chars than a-z, 0-9, minus will be deleted.
2. VALUE {integer|float} - your value; default (if missing): 0
3. WARNLEVEL {integer} - optional: warning level; not handled by graphite; default: empty string
4. CRITICAL {integer} - optional: critical level; not handled by graphite; default: empty string
5. MIN {integer} - optional: minimum value of graph; default: empty string
6. MAX {integer} - optional: maximum value of graph;; default: empty string
Execute a command and repeat max. MAXTRIES times if it fails.
ph.exit
```
**ph.perfadd** [VALUE] [OPTIONS…]
Add values and define limits for the graph: I will draw it from 0 to a fixed maximum value like for a given physical maximum or 100 for percent values.
Add performance data. Their output will be written with ph.exit. So you are free to add perfomance data anywhere within your check script.
Remark that here are empty values for warning and critical to skip them.
dump performance data (if u are not using ph.exit)
**ph.require** [PROG [...PROG_N]]
Syntax:
```text
ph.perfshow
```
(no parameters)
### ph.require
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).
Syntax:
```text
ph.require [PROG [...PROG_N]]
```
Parameters:
1. PROG - name of program to find in path
Example:
`ph.require bc lsblk`
Hint:
Do not place the requirement check before processing -h to show a help. The help should be visible in any case.
### ph.setStatus
Set a return status of your check with a keyword. This is easier to handle and to read than fiddling with Nagios exitcodes. You can override it as often you want during the script. Based on the last setting the ``ph.exit`` function will set the exitcode.
Syntax:
```text
ph.setStatus [STATUS]
```
Parameters:
1. STATUS {string} - a keyword for the return status.
* ok
* warning
* critical
* unknown
You get an error message when using another keyword.
The default value - if you do not set it anywhere - is "ok".
Example:
```shell
if[$iMyValue-lt$iWarnLimit];then
ph.setStatus "ok"
else
if[$iMyValue-ge$iCriticalLimit];then
ph.setStatus "critical"
else
ph.setStatus "warning"
fi
fi
ph.status "Return value was $iMyValue"
ph.exit
```
### ph.setStatusByLimit
Set statuscode by verifying integer only(!) value with critical and warning limit.
Syntax:
```text
ph.setStatusByLimit VALUE WARNLIMIT CRITLIMIT
```
Parameters:
1. VALUE {integer} - your discovered value
2. WARNLIMIT {integer} - warning limit
3. CRITLIMIT {integer} - critical limit
This function works in both directions:
* critcal value is HIGHER than warning value; eg. for cpu usage warn on 80% and critical on 90%
* critcal value is LOWER than warning value; eg. for free disk space warn on 10% space left and critical on 3%
Example:
If no warning or critical value is set they are 0 - and a check will return OK on any value. But if they were set then it reacts on these limits.