Browse Source

Added NSX and SRM Checks

George Pochiscan 3 weeks ago
parent
commit
50f7e378fe

BIN
Check_NSX-1.4.mkp View File


BIN
SRM-1.0.mkp View File


+ 1440
- 0
local/share/check_mk/agents/special/agent_nsx
File diff suppressed because it is too large
View File


+ 173
- 0
local/share/check_mk/agents/special/agent_srm View File

@@ -0,0 +1,173 @@
1
+#!/usr/bin/env python
2
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2018             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+import re
28
+import sys, getopt
29
+import requests
30
+from requests.packages.urllib3.exceptions import InsecureRequestWarning # pylint: disable=import-error
31
+from HTMLParser import HTMLParser
32
+
33
+def usage():
34
+    sys.stderr.write("""Check_MK VMWare SRM
35
+
36
+USAGE: agent_srm [OPTIONS] HOST
37
+
38
+OPTIONS:
39
+  -h, --help                    Show this help message and exit
40
+  --address                     Host address
41
+  --no-cert-check               Disable certificate check
42
+""")
43
+    sys.exit(1)
44
+
45
+short_options = "h"
46
+long_options  = ["help", "address=", "demo", "no-cert-check"]
47
+
48
+try:
49
+    opts, args = getopt.getopt(sys.argv[1:], short_options, long_options)
50
+except getopt.GetoptError, err:
51
+    sys.stderr.write("%s\n" % err)
52
+    sys.exit(1)
53
+
54
+
55
+opt_demo = False
56
+opt_cert = True
57
+args_dict = {}
58
+resources = []
59
+
60
+for o,a in opts:
61
+    if o in [ "--address" ]:
62
+        args_dict["address"] = a
63
+    elif o in [ "--demo" ]:
64
+        opt_demo = True
65
+    elif o in [ "--no-cert-check" ]:
66
+        opt_cert = False
67
+    elif o in [ "-h", "--help" ]:
68
+        usage()
69
+
70
+class HTMLTableParser(HTMLParser):
71
+    def __init__(
72
+        self,
73
+        decode_html_entities=False,
74
+        data_separator=' ',
75
+    ):
76
+
77
+        HTMLParser.__init__(self)
78
+
79
+        self._parse_html_entities = decode_html_entities
80
+        self._data_separator = data_separator
81
+
82
+        self._in_td = False
83
+        self._in_th = False
84
+        self._current_table = []
85
+        self._current_row = []
86
+        self._current_cell = []
87
+        self.tables = []
88
+
89
+    def handle_starttag(self, tag, attrs):
90
+        if tag == 'td':
91
+            self._in_td = True
92
+        if tag == 'th':
93
+            self._in_th = True
94
+
95
+    def handle_data(self, data):
96
+        if self._in_td or self._in_th:
97
+            self._current_cell.append(data.strip())
98
+
99
+    def handle_charref(self, name):
100
+
101
+        if self._parse_html_entities:
102
+            self.handle_data(self.unescape('&#{};'.format(name)))
103
+
104
+    def handle_endtag(self, tag):
105
+        if tag == 'td':
106
+            self._in_td = False
107
+        elif tag == 'th':
108
+            self._in_th = False
109
+
110
+        if tag in ['td', 'th']:
111
+            final_cell = self._data_separator.join(self._current_cell).strip()
112
+            self._current_row.append(final_cell)
113
+            self._current_cell = []
114
+        elif tag == 'tr':
115
+            self._current_table.append(self._current_row)
116
+            self._current_row = []
117
+        elif tag == 'table':
118
+            self.tables.append(self._current_table)
119
+            self._current_table = []
120
+
121
+parser=HTMLTableParser()
122
+
123
+def query(url):
124
+    if opt_cert == False:
125
+        requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # pylint: disable=no-member
126
+    response     = requests.get(url, verify=opt_cert)
127
+    raw_html     = response.text
128
+    return raw_html
129
+output_lines = []
130
+def output(line):
131
+    output_lines.append(line)
132
+
133
+def query_srm():
134
+    if opt_demo:
135
+        return parser.feed(srm_status)
136
+    url = "https://%(address)s:9086/" % args_dict
137
+    return parser.feed(query(url))
138
+
139
+def process_srm_info():
140
+    output("<<<vcenter_srm:sep(9)>>>")
141
+    query_srm()
142
+    local_connection = parser.tables[0]
143
+    remote_connection = parser.tables[1]
144
+    i=2
145
+    for row in local_connection:
146
+        if str(row[0]) == "Service":
147
+	    output("LocalConnection %s\t%s\t%s" % (row[1],local_connection[i][1],local_connection[i+2][1]))
148
+	    i+=5
149
+
150
+    i=2
151
+    for row in remote_connection:
152
+        if str(row[0]) == "Service":
153
+            output("RemoteConnection %s\t%s\t%s" % (row[1],local_connection[i][1],remote_connection[i+2][1]))
154
+            i+=5
155
+
156
+def main():
157
+    try:
158
+        process_srm_info()
159
+        sys.stdout.write("\n".join(output_lines) + "\n")
160
+    except Exception, e:
161
+        sys.stderr.write("Connection error: %s" % e)
162
+        sys.exit(1)
163
+
164
+
165
+srm_status = \
166
+"""
167
+<!DOCTYPE html>
168
+<html><head>
169
+<meta http-equiv="content-type" content="text/html; charset=windows-1252"><style></style></head><body><h3>VMware vCenter Site Recovery Manager 6.5.1.6014840</h3><p>Name: <b>buc01m01vc01.test</b>, UUID: <b>d8fd8aea-a3ed-46e9-857e-509b80784c53</b>, Extension key: <b>com.vmware.vcDr</b></p><h4>VMware vCenter Server 6.5.0 build-7515524</h4><hr><p><a href="https://buc01m01srm01.test:9086/vcdr/vmomi/drserviceversions.xml">Supported VMODL versions</a></p><p><a href="https://buc01m01srm01.test:9086/vcdr/vmomi/drversion.xml">Inherent VMODL version</a></p><hr><h4>Local Connections</h4><table><tbody><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.cis.vcenterserver</td></tr><tr><td>URL</td><td>https://buc01m01vc01.test:443/sdk</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.cis.cs.inventory</td></tr><tr><td>URL</td><td>https://buc01m01vc01.test:443/invsvc/vmomi/sdk</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.cis.cs.lookup</td></tr><tr><td>URL</td><td>https://buc01psc01.test:443/lookupservice/sdk</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.cis.cs.identity</td></tr><tr><td>URL</td><td>https://buc01psc01.test/sso-adminserver/sdk/vsphere.local</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.cis.cs.authorization</td></tr><tr><td>URL</td><td>https://buc01m01vc01.test:443/invsvc/vmomi/sdk</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.cis.cs.license</td></tr><tr><td>URL</td><td>https://buc01psc01.test:443/ls/sdk</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr></tbody></table><h4>Paired with remote SRM with name 'clj01m01vc01.test' and uuid 'acf7df22-01bb-439a-b27e-9f8b83e23233'</h4><h4>Remote Connections</h4><table><tbody><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.cis.vcenterserver</td></tr><tr><td>URL</td><td>https://clj01m01vc01.test:443/sdk</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.dr.vcDr</td></tr><tr><td>URL</td><td>https://clj01m01srm01.test:9086/vcdr/vmomi/sdk</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.cis.cs.lookup</td></tr><tr><td>URL</td><td>https://clj01psc01.test:443/lookupservice/sdk</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr><tr><td>Service</td><td>com.vmware.cis.cs.identity</td></tr><tr><td>URL</td><td>https://clj01psc01.test/sso-adminserver/sdk/vsphere.local</td></tr><tr><td>Thumbprint</td><td>unknown</td></tr><tr><td>Status</td><td style="color:#080;">Connected</td></tr><tr><td>--------------------</td><td>--------------------------------------------------------------------------------</td></tr></tbody></table></body></html>"""
170
+
171
+if __name__ == "__main__":
172
+    main()
173
+

+ 14
- 0
local/share/check_mk/checkman/nsx_backup View File

@@ -0,0 +1,14 @@
1
+title: VMWare NSX: Backup time
2
+agents: agent_nsx
3
+catalog: Miscellaneous
4
+license: GPL
5
+distribution: check_mk
6
+description:
7
+ This check monitors the date of last backup.
8
+item:
9
+ Backup service.
10
+
11
+perfdata:
12
+ none
13
+inventory:
14
+ One service called "NSX Backups".

+ 15
- 0
local/share/check_mk/checkman/nsx_components View File

@@ -0,0 +1,15 @@
1
+title: VMWare NSX: Components status
2
+agents: agent_nsx
3
+catalog: Miscellaneous
4
+license: GPL
5
+distribution: check_mk
6
+description:
7
+ This check monitors the status of VMWare NSX Components
8
+item:
9
+ The item is composed from the Component Type.
10
+
11
+perfdata:
12
+ none
13
+inventory:
14
+ All NSX Components defined will be inventorized. 
15
+

+ 19
- 0
local/share/check_mk/checkman/nsx_controllers View File

@@ -0,0 +1,19 @@
1
+title: VMWare NSX: Controllers status
2
+agents: agent_nsx
3
+catalog: Miscellaneous
4
+license: GPL
5
+distribution: check_mk
6
+description:
7
+ This check monitors the status of VMWare NSX Constrollers
8
+• Deploying - controller is being deployed and the procedure has not completed yet.
9
+• Removing - controller is being removed and the procedure has not completed yet.
10
+• Running - controller has been deployed and can respond to API invocation.
11
+• Unknown - controller has been deployed but fails to respond to API invocation.
12
+item:
13
+ The item is composed from the Controller-id.
14
+
15
+perfdata:
16
+ none
17
+inventory:
18
+ All NSX Controllers defined will be inventorized. 
19
+

+ 15
- 0
local/share/check_mk/checkman/nsx_cpu View File

@@ -0,0 +1,15 @@
1
+title: VMWare NSX: CPU usage of NSX
2
+agents: agent_nsx
3
+catalog: Miscellaneous
4
+license: GPL
5
+distribution: check_mk
6
+description:
7
+ This check monitors the CPU usage.
8
+item:
9
+ Memory used
10
+
11
+perfdata:
12
+ One graph for CPU used in percentage
13
+inventory:
14
+ One service called "CPU Utilization".
15
+

+ 15
- 0
local/share/check_mk/checkman/nsx_edges View File

@@ -0,0 +1,15 @@
1
+title: VMWare NSX: Edges status
2
+agents: agent_nsx
3
+catalog: Miscellaneous
4
+license: GPL
5
+distribution: check_mk
6
+description:
7
+ This check monitors the status of VMWare NSX Edges
8
+item:
9
+ The item is composed from the edge-id.
10
+
11
+perfdata:
12
+ none
13
+inventory:
14
+ All NSX edges defined will be inventorized. 
15
+

+ 15
- 0
local/share/check_mk/checkman/nsx_mem View File

@@ -0,0 +1,15 @@
1
+title: VMWare NSX: Memory usage of NSX
2
+agents: agent_nsx
3
+catalog: Miscellaneous
4
+license: GPL
5
+distribution: check_mk
6
+description:
7
+ This check monitors the memory usage.
8
+item:
9
+ Memory used
10
+
11
+perfdata:
12
+ Two graphs for memory used and all memory
13
+inventory:
14
+ One service called "Memory Usage".
15
+

+ 14
- 0
local/share/check_mk/checkman/nsx_memory View File

@@ -0,0 +1,14 @@
1
+title: VMWare NSX: Memory usage of NSX
2
+agents: agent_nsx
3
+catalog: Miscellaneous
4
+license: GPL
5
+distribution: check_mk
6
+description:
7
+ This check monitors the memory usage.
8
+item:
9
+ Memory used
10
+
11
+perfdata:
12
+ Two graphs for memory used and all memory
13
+inventory:
14
+ One service called "Memory Usage".

+ 15
- 0
local/share/check_mk/checkman/nsx_storage View File

@@ -0,0 +1,15 @@
1
+title: VMWare NSX: Storage usage of NSX
2
+agents: agent_nsx
3
+catalog: Miscellaneous
4
+license: GPL
5
+distribution: check_mk
6
+description:
7
+ This check monitors the storage usage.
8
+item:
9
+ Memory used
10
+
11
+perfdata:
12
+ One graph for storage used in bytes, autoscaled
13
+inventory:
14
+ One service called "Storage used".
15
+

+ 14
- 0
local/share/check_mk/checkman/nsx_vcenter_connection View File

@@ -0,0 +1,14 @@
1
+title: VMWare NSX: vCenter Connection
2
+agents: agent_nsx
3
+catalog: Miscellaneous
4
+license: GPL
5
+distribution: check_mk
6
+description:
7
+ This check monitors the state of vCenter Connection.
8
+item:
9
+ vCenter Connection
10
+
11
+perfdata:
12
+ none
13
+inventory:
14
+ One service called "vCenter Connection".

+ 41
- 0
local/share/check_mk/checks/agent_nsx View File

@@ -0,0 +1,41 @@
1
+#!/usr/bin/python
2
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2017             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+def agent_nsx_arguments(params, hostname, ipaddress):
28
+    args = ''
29
+    args += "--address=%s " % hostname
30
+    args += "--user=%s " % params["user"]
31
+    args += "--password=%s " % params["password"]
32
+    
33
+    if "nsx_resource" in params:
34
+        for domain in params["nsx_resource"]:
35
+            args += "--nsx_resource=%s " % domain
36
+    if "cert" in params and params["cert"] == False:
37
+        args += "--no-cert-check "
38
+    return args
39
+
40
+special_agent_info['nsx'] = agent_nsx_arguments
41
+

+ 36
- 0
local/share/check_mk/checks/agent_srm View File

@@ -0,0 +1,36 @@
1
+#!/usr/bin/python
2
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2017             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+def agent_srm_arguments(params, hostname, ipaddress):
28
+    args = ''
29
+    args += "--address=%s " % hostname
30
+    
31
+    if "cert" in params and params["cert"] == False:
32
+        args += "--no-cert-check "
33
+    return args
34
+
35
+special_agent_info['srm'] = agent_srm_arguments
36
+

+ 431
- 0
local/share/check_mk/checks/check_nsx View File

@@ -0,0 +1,431 @@
1
+#!/usr/bin/python
2
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2018             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+import datetime
28
+
29
+def inventory_edges_status(info):
30
+    for name, edgeid, edgestatus, edgestate, edgetype in info:
31
+	yield ("Edge %s" % \
32
+                (edgeid), {})
33
+
34
+
35
+def check_edges_status(item, params, info):
36
+    for line in info:
37
+	edge = "Edge" + " " + line[1]
38
+        if edge==item:
39
+            edgename = line[0]
40
+            edgestatus = line[2]
41
+	    edgestate = line[3]
42
+	    edgetype = line[4]
43
+            if edgetype == "distributedRouter":
44
+	        if edgestate != "active":
45
+		    return 2, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus )
46
+       	        elif edgestatus == "GREEN":
47
+                    return 0, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus )
48
+	        elif edgestatus == "GREY":
49
+		    return 0, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus )
50
+                elif edgestatus == "YELLOW":
51
+                    return 1, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus )
52
+	        elif edgestatus == "RED":
53
+                    return 2, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus )
54
+                return 3, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus )
55
+            else:
56
+		if edgestatus == "GREEN":
57
+                    return 0, "Edge %s is %s" % (edgename, edgestatus)
58
+                elif edgestatus == "YELLOW":
59
+                    return 1, "Edge %s is %s" % (edgename, edgestatus)
60
+                elif edgestatus == "RED":
61
+                    return 2, "Edge %s is %s" % (edgename, edgestatus)
62
+                return 3, "Edge %s is %s" % (edgename, edgestatus)
63
+
64
+
65
+check_info['nsx_edges'] = {
66
+    'inventory_function'    : inventory_edges_status,
67
+    'check_function'        : check_edges_status,
68
+    'service_description'   : '%s', 
69
+    'has_perfdata'          : False,
70
+}
71
+
72
+#.
73
+#   .--Controller Status---------------------------------------------------.
74
+#   |             ____            _             _ _                        |
75
+#   |            / ___|___  _ __ | |_ _ __ ___ | | | ___ _ __              |
76
+#   |           | |   / _ \| '_ \| __| '__/ _ \| | |/ _ \ '__|             |
77
+#   |           | |__| (_) | | | | |_| | | (_) | | |  __/ |                |
78
+#   |            \____\___/|_| |_|\__|_|  \___/|_|_|\___|_|                |
79
+#   |                                                                      |
80
+#   |                    ____  _        _                                  |
81
+#   |                   / ___|| |_ __ _| |_ _   _ ___                      |
82
+#   |                   \___ \| __/ _` | __| | | / __|                     |
83
+#   |                    ___) | || (_| | |_| |_| \__ \                     |
84
+#   |                   |____/ \__\__,_|\__|\__,_|___/                     |
85
+#   |                                                                      |
86
+#   +----------------------------------------------------------------------+
87
+#   |                                                                      |
88
+#   '----------------------------------------------------------------------'
89
+
90
+def inventory_controller_status(info):
91
+    for name, id, status in info:
92
+        yield ("Controller %s" % \
93
+                (id), {})
94
+
95
+
96
+def check_controller_status(item, params, info):
97
+    for line in info:
98
+        controller = "Controller" + " " + line[1]
99
+        if controller==item:
100
+            controllername = line[0]
101
+            controllerstatus = line[2]
102
+            if controllerstatus == "RUNNING":
103
+                return 0, "Controller %s is %s" % (controllername, controllerstatus)
104
+            elif controllerstatus == "DEPLOYING":
105
+		return 1, "Controller %s is %s" % (controllername, controllerstatus)
106
+	    elif controllerstatus == "REMOVING":
107
+		return 1, "Controller %s is %s" % (controllername, controllerstatus)
108
+	    elif controllerstatus == "UNKNOWN":
109
+                return 2, "Controller %s is %s" % (controllername, controllerstatus)
110
+
111
+check_info['nsx_controller'] = {
112
+    'inventory_function'    : inventory_controller_status,
113
+    'check_function'        : check_controller_status,
114
+    'service_description'   : '%s',
115
+    'has_perfdata'          : False,
116
+}
117
+
118
+
119
+
120
+#.
121
+#   .--NSX Components------------------------------------------------------.
122
+#   |                           _   _ ______  __                           |
123
+#   |                          | \ | / ___\ \/ /                           |
124
+#   |                          |  \| \___ \\  /                            |
125
+#   |                          | |\  |___) /  \                            |
126
+#   |                          |_| \_|____/_/\_\                           |
127
+#   |                                                                      |
128
+#   |       ____                                             _             |
129
+#   |      / ___|___  _ __ ___  _ __   ___  _ __   ___ _ __ | |_ ___       |
130
+#   |     | |   / _ \| '_ ` _ \| '_ \ / _ \| '_ \ / _ \ '_ \| __/ __|      |
131
+#   |     | |__| (_) | | | | | | |_) | (_) | | | |  __/ | | | |_\__ \      |
132
+#   |      \____\___/|_| |_| |_| .__/ \___/|_| |_|\___|_| |_|\__|___/      |
133
+#   |                          |_|                                         |
134
+#   +----------------------------------------------------------------------+
135
+#   |                                                                      |
136
+#   '----------------------------------------------------------------------'
137
+def inventory_nsx_components(info):
138
+    for name, id, status in info:
139
+        yield ("Component %s" % \
140
+                (id), {})
141
+
142
+
143
+def check_nsx_components(item, params, info):
144
+    for line in info:
145
+	component = "Component" + " " + line[1]
146
+        if component==item:
147
+            component_name = line[0]
148
+            component_status = line[2]
149
+            if component_status == "RUNNING":
150
+                return 0, "Component %s is %s" % (component_name, component_status)
151
+            else:
152
+                return 2, "Component %s is %s" % (component_name, component_status)
153
+
154
+check_info['nsx_components'] = {
155
+    'inventory_function'    : inventory_nsx_components,
156
+    'check_function'        : check_nsx_components,
157
+    'service_description'   : '%s',
158
+    'has_perfdata'          : False,
159
+}
160
+
161
+#.
162
+#   .--NSX Backup----------------------------------------------------------.
163
+#   |         _   _ ______  __  ____             _                         |
164
+#   |        | \ | / ___\ \/ / | __ )  __ _  ___| | ___   _ _ __           |
165
+#   |        |  \| \___ \\  /  |  _ \ / _` |/ __| |/ / | | | '_ \          |
166
+#   |        | |\  |___) /  \  | |_) | (_| | (__|   <| |_| | |_) |         |
167
+#   |        |_| \_|____/_/\_\ |____/ \__,_|\___|_|\_\\__,_| .__/          |
168
+#   |                                                      |_|             |
169
+#   +----------------------------------------------------------------------+
170
+#   |                                                                      |
171
+#   '----------------------------------------------------------------------'
172
+def inventory_nsx_backups(info):
173
+    return [(None, {})]
174
+
175
+
176
+def check_nsx_backup(item, params, info):
177
+    warn, crit = params
178
+    if info:
179
+        last_backup = sorted(info, key=lambda tup: tup[2])[-1]
180
+        last_backup_size = last_backup[1]
181
+        last_backup_time = datetime.datetime.fromtimestamp(float(last_backup[2])/1000)
182
+        elapsed = datetime.datetime.now() - last_backup_time
183
+        if elapsed >= datetime.timedelta(days=crit):
184
+           return 2, "Last backup was taken more than %s days ago. Last backup date is %s " \
185
+	    	 	% (crit, last_backup_time)
186
+        elif elapsed >= datetime.timedelta(days=warn):
187
+           return 1, "Last backup was taken more than %s days ago. Last backup date is %s " \
188
+                        % (warn, last_backup_time)
189
+        else:
190
+           return 0, "Date of last backup is %s" % last_backup_time
191
+    else:
192
+        return 3, "Backup not available"
193
+
194
+check_info['nsx_backup'] = {
195
+    'inventory_function'    : inventory_nsx_backups,
196
+    'check_function'        : check_nsx_backup,
197
+    'service_description'   : 'NSX Backups',
198
+    'has_perfdata'          : False,
199
+    'group'                 : "backups",
200
+}
201
+
202
+#.
203
+#   .--Memory--------------------------------------------------------------.
204
+#   |               __  __                                                 |
205
+#   |              |  \/  | ___ _ __ ___   ___  _ __ _   _                 |
206
+#   |              | |\/| |/ _ \ '_ ` _ \ / _ \| '__| | | |                |
207
+#   |              | |  | |  __/ | | | | | (_) | |  | |_| |                |
208
+#   |              |_|  |_|\___|_| |_| |_|\___/|_|   \__, |                |
209
+#   |                                                |___/                 |
210
+#   +----------------------------------------------------------------------+
211
+nsx_memory_default_levels = ( 80.0, 90.0 )
212
+
213
+def nsx_convert(info):
214
+    data = {}
215
+    for line in info:
216
+        data[line[0]] = line[1:]
217
+    return data
218
+
219
+def inventory_nsx_mem(info):
220
+    data = nsx_convert(info)
221
+    return [(None, 'nsx_mem_default_levels')]
222
+
223
+def check_nsx_mem(item, params, info):
224
+    data = nsx_convert(info)
225
+    warn, crit = params
226
+    memory_usage = savefloat(data['UsedMemory'][0]) * 1024 * 1024
227
+    memory_size = savefloat(data['TotalMem'][0]) * 1024 * 1024
228
+    level = savefloat(data['UsedPercentage'][0])
229
+    state = 0
230
+    label = ''
231
+    if level >= crit:
232
+       state = 2
233
+       label = " (Levels at %d%%/%d%%)" % (warn, crit)
234
+    elif level >= warn:
235
+        state = 1
236
+        label = " (Levels at %d%%/%d%%)" % (warn, crit)
237
+    message = "%d%%%s used - %s/%s" % \
238
+    (level, label, get_bytes_human_readable(memory_usage), get_bytes_human_readable(memory_size))
239
+    perf = [("mem_used", memory_usage, warn * memory_size / 100, crit * memory_size / 100, 0, memory_size),
240
+            ("mem_total", memory_size)]
241
+    return(state, message, perf)
242
+
243
+
244
+check_info['nsx_memory'] = {
245
+  "inventory_function"      : inventory_nsx_mem,
246
+  "check_function"          : check_nsx_mem,
247
+  "service_description"     : "Memory used",
248
+  "group"                   : "nsx_memory",
249
+  "has_perfdata"            : True,
250
+  "default_levels_variable" : "nsx_mem_default_levels"
251
+}
252
+
253
+#.
254
+#   .--CPU-----------------------------------------------------------------.
255
+#   |                           ____ ____  _   _                           |
256
+#   |                          / ___|  _ \| | | |                          |
257
+#   |                         | |   | |_) | | | |                          |
258
+#   |                         | |___|  __/| |_| |                          |
259
+#   |                          \____|_|    \___/                           |
260
+#   |                                                                      |
261
+#   +----------------------------------------------------------------------+
262
+
263
+nsx_host_cpu_default_levels = {}
264
+
265
+def inventory_nsx_cpu(info):
266
+    data = nsx_convert(info).keys()
267
+    if 'usedPercentage' in data \
268
+        and 'totalNoOfCPUs' in data\
269
+        and 'capacity' in data:
270
+        return [(None, {})]
271
+
272
+def check_nsx_cpu(item, params, info):
273
+    data = nsx_convert(info)
274
+
275
+    if "usedPercentage" not in data:
276
+        return
277
+    #Asuming that there are 1 thread per core and one core per socket
278
+    #Asuming that capacity represents total capacity
279
+    
280
+    num_cpu = int(data['totalNoOfCPUs'][0])
281
+    total_capacity = int(data['capacity'][0])
282
+    used_capacity = float(data['usedCapacity'][0])
283
+    mhz_per_core = float(data['capacity'][0]) / num_cpu
284
+    
285
+
286
+    usage = used_capacity / total_capacity * 100
287
+    per_core = num_cpu / 100.0
288
+
289
+    infotext = "%.1f%%" % usage
290
+
291
+    # Convert legacy parameters
292
+    this_time = time.time()
293
+    state, infotext, perfdata = check_cpu_util(usage, params).next()
294
+
295
+    infotext += ", %.2fGHz/%.2fGHz" % (used_capacity / 1000.0, total_capacity / 1000.0)
296
+    infotext += ", %d sockets, %d cores/socket, %d threads" % (
297
+            num_cpu, 1 , 1)
298
+    return (state, infotext, perfdata)
299
+
300
+
301
+check_info['nsx_cpu'] = {
302
+   "inventory_function"      : inventory_nsx_cpu,
303
+   "check_function"          : check_nsx_cpu,
304
+   "service_description"     : "CPU utilization",
305
+   "group"                   : "cpu_utilization_os",
306
+   "has_perfdata"            : True,
307
+   "default_levels_variable" : "nsx_host_cpu_default_levels",
308
+   "includes"                : [ "cpu_util.include" ],
309
+}
310
+
311
+#.
312
+#   .--NSX vCenter Connection----------------------------------------------.
313
+#   |        _   _ ______  __         ____           _                     |
314
+#   |       | \ | / ___\ \/ / __   __/ ___|___ _ __ | |_ ___ _ __          |
315
+#   |       |  \| \___ \\  /  \ \ / / |   / _ \ '_ \| __/ _ \ '__|         |
316
+#   |       | |\  |___) /  \   \ V /| |__|  __/ | | | ||  __/ |            |
317
+#   |       |_| \_|____/_/\_\   \_/  \____\___|_| |_|\__\___|_|            |
318
+#   |                                                                      |
319
+#   |          ____                            _   _                       |
320
+#   |         / ___|___  _ __  _ __   ___  ___| |_(_) ___  _ __            |
321
+#   |        | |   / _ \| '_ \| '_ \ / _ \/ __| __| |/ _ \| '_ \           |
322
+#   |        | |__| (_) | | | | | | |  __/ (__| |_| | (_) | | | |          |
323
+#   |         \____\___/|_| |_|_| |_|\___|\___|\__|_|\___/|_| |_|          |
324
+#   |                                                                      |
325
+#   +----------------------------------------------------------------------+
326
+#   |                                                                      |
327
+#   '----------------------------------------------------------------------'
328
+def inventory_nsx_vcenter_connection(info):
329
+    return [(None, {})]
330
+
331
+
332
+def check_nsx_vcenter_connection(item, params, info):
333
+    if "true" in info[0]:
334
+        return 0, "vCenterConnection is true"
335
+    elif "false" in info[0]:
336
+        return 2, "vCenterConnection is false"
337
+
338
+check_info['nsx_vcenter_connection'] = {
339
+    'inventory_function'    : inventory_nsx_vcenter_connection,
340
+    'check_function'        : check_nsx_vcenter_connection,
341
+    'service_description'   : 'vCenter Connection',
342
+    'has_perfdata'          : False,
343
+}
344
+
345
+
346
+#.
347
+#   .--NSX Storage Info----------------------------------------------------.
348
+#   |        _   _ ______  __  ____  _                                     |
349
+#   |       | \ | / ___\ \/ / / ___|| |_ ___  _ __ __ _  __ _  ___         |
350
+#   |       |  \| \___ \\  /  \___ \| __/ _ \| '__/ _` |/ _` |/ _ \        |
351
+#   |       | |\  |___) /  \   ___) | || (_) | | | (_| | (_| |  __/        |
352
+#   |       |_| \_|____/_/\_\ |____/ \__\___/|_|  \__,_|\__, |\___|        |
353
+#   |                                                   |___/              |
354
+#   |                         ___        __                                |
355
+#   |                        |_ _|_ __  / _| ___                           |
356
+#   |                         | || '_ \| |_ / _ \                          |
357
+#   |                         | || | | |  _| (_) |                         |
358
+#   |                        |___|_| |_|_|  \___/                          |
359
+#   |                                                                      |
360
+#   +----------------------------------------------------------------------+
361
+#   |                                                                      |
362
+#   '----------------------------------------------------------------------'
363
+nsx_storage_default_levels = ( 70.0, 80.0 )
364
+
365
+def inventory_nsx_storage(info):
366
+    data = nsx_convert(info)
367
+    return [(None, 'nsx_storage_default_levels')]
368
+
369
+def check_nsx_storage(item, params, info):
370
+    warn,crit = params
371
+    data = nsx_convert(info)
372
+    used_storage = float(re.sub('G','', data['UsedStorage'][0],count =1))
373
+    total_storage = float(re.sub('G','', data['TotalStorage'][0],count =1))
374
+    free_storage = float(re.sub('G','', data['FreeStorage'][0],count =1))
375
+    used_percentage = float(re.sub('G','', data['UsedPercentage'][0],count =1))
376
+    perf = [("storage_used", used_storage * 1024 * 1024 * 1024, \
377
+	    warn * total_storage * 1024 * 1024 * 1024  / 100 , \
378
+	    crit * total_storage * 1024 * 1024 * 1024 / 100 , 0, total_storage * 1024 * 1024 * 1024)]
379
+    if used_percentage >= crit:
380
+	return 2, "Storage used is %sGB out of %sGB" % (used_storage, total_storage) , perf
381
+    elif used_percentage >= warn:
382
+        return 1, "Storage used is %sGB out of %sGB" % (used_storage, total_storage) , perf
383
+    else:
384
+        return 0, "Storage used is %sGB out of %sGB" % (used_storage, total_storage) , perf
385
+
386
+check_info['nsx_storage_info'] = {
387
+  "inventory_function"      : inventory_nsx_storage,
388
+  "check_function"          : check_nsx_storage,
389
+  "service_description"     : "Storage used",
390
+  "group"                   : "nsx_storage",
391
+  "has_perfdata"            : True,
392
+  "default_levels_variable" : "nsx_storage_default_levels",
393
+
394
+}
395
+
396
+
397
+
398
+####NSX_RESOURCES
399
+def inventory_nsx_resources(info):
400
+    for domain_name, component, status in info:
401
+        component_sn = component.split(".")[-1]
402
+        yield ("%s %s" % \
403
+                (domain_name, component_sn), {})
404
+
405
+
406
+def check_nsx_resources(item, params, info):
407
+    for line in info:
408
+        component = line[0] + " " + line[1].split(".")[-1]
409
+        if component==item:
410
+            domain_name = line[0]
411
+            component_name = line[1].split(".")[-1]
412
+            component_status = line[2]
413
+            if component_name == "hostRebootRequired":
414
+                if component_status == "false":
415
+                    return 0, "Host reboot is not required. "
416
+                else:
417
+                    return 1, "Host needs a reboot"
418
+
419
+            if component_status == "GREEN":
420
+                return 0, "Component %s is %s" % (component_name, component_status)
421
+            elif component_status =="UNKNOWN":
422
+                return 3, "Status is unknown"
423
+            else:
424
+                return 2, "Component %s is %s" % (component_name, component_status)
425
+
426
+check_info['nsx_resources'] = {
427
+    'inventory_function'    : inventory_nsx_resources,
428
+    'check_function'        : check_nsx_resources,
429
+    'service_description'   : '%s',
430
+    'has_perfdata'          : False,
431
+}

+ 59
- 0
local/share/check_mk/checks/check_srm View File

@@ -0,0 +1,59 @@
1
+#!/usr/bin/python
2
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
3
+# +------------------------------------------------------------------+
4
+# |             ____ _               _        __  __ _  __           |
5
+# |            / ___| |__   ___  ___| | __   |  \/  | |/ /           |
6
+# |           | |   | '_ \ / _ \/ __| |/ /   | |\/| | ' /            |
7
+# |           | |___| | | |  __/ (__|   <    | |  | | . \            |
8
+# |            \____|_| |_|\___|\___|_|\_\___|_|  |_|_|\_\           |
9
+# |                                                                  |
10
+# | Copyright Mathias Kettner 2018             mk@mathias-kettner.de |
11
+# +------------------------------------------------------------------+
12
+#
13
+# This file is part of Check_MK.
14
+# The official homepage is at http://mathias-kettner.de/check_mk.
15
+#
16
+# check_mk is free software;  you can redistribute it and/or modify it
17
+# under the  terms of the  GNU General Public License  as published by
18
+# the Free Software Foundation in version 2.  check_mk is  distributed
19
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY;  with-
20
+# out even the implied warranty of  MERCHANTABILITY  or  FITNESS FOR A
21
+# PARTICULAR PURPOSE. See the  GNU General Public License for more de-
22
+# tails. You should have  received  a copy of the  GNU  General Public
23
+# License along with GNU Make; see the file  COPYING.  If  not,  write
24
+# to the Free Software Foundation, Inc., 51 Franklin St,  Fifth Floor,
25
+# Boston, MA 02110-1301 USA.
26
+
27
+#<<<vcenter_srm>>>
28
+#LocalConnection com.vmware.cis.vcenterserver	https://buc01m01vc01.test:443/sdk	Connected
29
+#LocalConnection com.vmware.cis.cs.inventory	https://buc01m01vc01.test:443/invsvc/vmomi/sdk	Connected
30
+#LocalConnection com.vmware.cis.cs.lookup	https://buc01psc01.test:443/lookupservice/sdk	Connected
31
+#LocalConnection com.vmware.cis.cs.identity	https://buc01psc01.test/sso-adminserver/sdk/vsphere.local	Connected
32
+#LocalConnection com.vmware.cis.cs.authorization	https://buc01m01vc01.test:443/invsvc/vmomi/sdk	Connected
33
+#LocalConnection com.vmware.cis.cs.license	https://buc01psc01.test:443/ls/sdk	Connected
34
+#RemoteConnection com.vmware.cis.vcenterserver	https://buc01m01vc01.test:443/sdk	Connected
35
+#RemoteConnection com.vmware.dr.vcDr	https://buc01m01vc01.test:443/invsvc/vmomi/sdk	Connected
36
+#RemoteConnection com.vmware.cis.cs.lookup	https://buc01psc01.test:443/lookupservice/sdk	Connected
37
+#RemoteConnection com.vmware.cis.cs.identity	https://buc01psc01.test/sso-adminserver/sdk/vsphere.locaConnected
38
+
39
+import datetime
40
+
41
+def inventory_srm_status(info):
42
+    for servicename, url, state in info:
43
+	yield ("%s" % (servicename), {})
44
+
45
+
46
+def check_srm_status(item, params, info):
47
+    for line in info:
48
+        if line[0]==item:
49
+           if line[2]=="Connected":
50
+               return 0, "OK, %s is %s; %s" % (item,line[2],line[1])
51
+	   else:
52
+	       return 1, "CRIT, %s is %s; %s" % (item,line[2],line[1])
53
+
54
+check_info['vcenter_srm'] = {
55
+    'inventory_function'    : inventory_srm_status,
56
+    'check_function'        : check_srm_status,
57
+    'service_description'   : '%s', 
58
+    'has_perfdata'          : False,
59
+}

Loading…
Cancel
Save