-
Notifications
You must be signed in to change notification settings - Fork 5
/
example.py
51 lines (36 loc) · 1.51 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env python
""" nagplug example plugin """
import nagplug
def main():
# Create a new nagplug.Plugin instance
sp = nagplug.Plugin(version='1.0')
# Add some arguments to parse
sp.add_arg('-w', '--warning', metavar="THRESHOLD", type=nagplug.Threshold,
help='Warning Threshold, see https://monitoring-plugins.org'
'/doc/guidelines.html#THRESHOLDFORMAT')
sp.add_arg('-c', '--critical', metavar="THRESHOLD", type=nagplug.Threshold,
help='Warning Threshold, see https://monitoring-plugins.org'
'/doc/guidelines.html#THRESHOLDFORMAT')
sp.add_arg('--value', required=True, metavar='VALUE', type=int)
# Parse the arguments
sp.parse_args()
# Set plugin timeout
sp.set_timeout()
# Get values and thresholds from command line
value = sp.args.value
t_warn = sp.args.warning
t_crit = sp.args.critical
# Check value against thresholds
code = sp.check_threshold(value, warning=t_warn, critical=t_crit)
# Add result to the stack
sp.add_result(code, 'value={0}'.format(value))
# Add some performance data to the stack
sp.add_perfdata('value', value, warning=t_warn, critical=t_crit,
minimum=0, maximum=100)
# Add some extra data if needed
if sp.args.verbose > 2:
sp.add_extdata('value has been determined to be {0}'.format(value))
# Exit printing the conclusions in a nagios-plugin compliant way
sp.finish()
if __name__ == '__main__':
main()