-
Notifications
You must be signed in to change notification settings - Fork 3
/
check_dynasynthetic.py
executable file
·102 lines (73 loc) · 3.17 KB
/
check_dynasynthetic.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/usr/bin/env python
"""
This file is part of the open source project py-dynasynthetic
(see https://github.com/micha-k/py-dynasynthetic).
Author: Michael Kessel
Contact: I have an email account 'dev' on a host called 'michaelkessel' listed
in the toplevel domain 'de'.
check_dynasynthetic.py - Executable to use as a nagios plugin
usage: check_dynasynthetic.py monitor [-h] -m METRIC -s SLOT [-w WARN]
[-c CRITICAL] -u USER -p PASSWORD
arguments:
-h, --help show this help message and exit
-m METRIC, --metric METRIC Name of the metric to display
-s SLOT, --slot SLOT Slot to select data from
-w WARN, --warn WARN Value for warning result
-c CRITICAL, --critical CRITICAL Value for critical result
-u USER, --user USER Username to access data
-p PASSWORD, --password PASSWORD MD5 hash of the password to use
"""
import nagiosplugin
from nagiosplugin.performance import Performance
from nagiosplugin.result import Result
from nagiosplugin.state import Ok, Warn, Critical
from dynasynthetic import CommandlineClient as CC
class DynatraceMetric(nagiosplugin.Resource):
def __init__(self, data):
self.data = data
def probe(self):
yield nagiosplugin.Metric(self.data['name'],
self.data['value'],
min=0,
context='metric')
class DynatraceMetricSummary(nagiosplugin.Summary):
def __init__(self, data):
self.data = data
def summary_output(self):
return '%s: %s (in %s, %s)' % (self.data['name'],
self.data['value'],
self.data['unit'],
self.data['info'])
def ok(self, results):
return self.summary_output()
def problem(self, results):
return self.summary_output()
def verbose(self, results):
return self.summary_output()
class CommandlineClientAsScalarContext(nagiosplugin.ScalarContext):
def __init__(self, name, data, warning=False, critical=False,
fmt_metric='', result_cls=Result):
self.data = data
super(CommandlineClientAsScalarContext, self).\
__init__(name, warning, critical, fmt_metric, result_cls)
def evaluate(self, metric, resource):
if self.data['result_string'] == 'CRITICAL':
return self.result_cls(Critical, False, metric)
elif self.data['result_string'] == 'WARNING':
return self.result_cls(Warn, None, metric)
else:
return self.result_cls(Ok, None, metric)
def performance(self, metric, resource):
return Performance(metric.name, metric.value)
@nagiosplugin.guarded
def main():
cli = CC.CommandlineClient()
cli.dispatch()
data = cli.result_parsable()
check = nagiosplugin.Check(
DynatraceMetric(data=data),
CommandlineClientAsScalarContext('metric', data, False, False),
DynatraceMetricSummary(data=data))
check.main()
if __name__ == '__main__':
main()