diff --git a/Check_NSX-1.4.mkp b/Check_NSX-1.4.mkp new file mode 100644 index 0000000..cc1d149 Binary files /dev/null and b/Check_NSX-1.4.mkp differ diff --git a/SRM-1.0.mkp b/SRM-1.0.mkp new file mode 100644 index 0000000..804c32b Binary files /dev/null and b/SRM-1.0.mkp differ diff --git a/local/share/check_mk/agents/special/agent_nsx b/local/share/check_mk/agents/special/agent_nsx new file mode 100644 index 0000000..5be13dc --- /dev/null +++ b/local/share/check_mk/agents/special/agent_nsx @@ -0,0 +1,1440 @@ +#!/usr/bin/env python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +------------------------------------------------------------------+ +# | ____ _ _ __ __ _ __ | +# | / ___| |__ ___ ___| | __ | \/ | |/ / | +# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | +# | | |___| | | | __/ (__| < | | | | . \ | +# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | +# | | +# | Copyright Mathias Kettner 2018 mk@mathias-kettner.de | +# +------------------------------------------------------------------+ +# +# This file is part of Check_MK. +# The official homepage is at http://mathias-kettner.de/check_mk. +# +# check_mk is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation in version 2. check_mk is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- +# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more de- +# tails. You should have received a copy of the GNU General Public +# License along with GNU Make; see the file COPYING. If not, write +# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301 USA. + +import re +import sys, getopt +import requests +import xml.etree.ElementTree as ET +from requests.packages.urllib3.exceptions import InsecureRequestWarning # pylint: disable=import-error + +def usage(): + sys.stderr.write("""Check_MK VMWare NSX + +USAGE: agent_nsx [OPTIONS] HOST + +OPTIONS: + -h, --help Show this help message and exit + --address Host address + --user Username + --password Password + --no-cert-check Disable certificate check + --nsx_resource List of nsx resources +""") + sys.exit(1) + +short_options = "h" +long_options = ["help", "username=", "password=", "address=", "demo", "no-cert-check" , "nsx_resource="] + +try: + opts, args = getopt.getopt(sys.argv[1:], short_options, long_options) +except getopt.GetoptError, err: + sys.stderr.write("%s\n" % err) + sys.exit(1) + + +opt_demo = False +opt_cert = True +args_dict = {} +resources = [] + +for o,a in opts: + if o in [ "--address" ]: + args_dict["address"] = a + elif o in [ "--username" ]: + args_dict["username"] = a + elif o in [ "--password" ]: + args_dict["password"] = a + elif o in [ "--demo" ]: + opt_demo = True + elif o in [ "--no-cert-check" ]: + opt_cert = False + elif o in [ "--nsx_resource"]: + resources.append(a) + elif o in [ "-h", "--help" ]: + usage() + +def query(url): + if opt_cert == False: + requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # pylint: disable=no-member + response = requests.get(url, verify=opt_cert, auth=(args_dict["username"], args_dict["password"]), headers={'Accept':'application/xml'}) + raw_xml = response.text + # Remove namespace nonsense + if "uptime" in str(url): + return raw_xml + else: + raw_xml = re.sub(' xml="[^"]+"', '', raw_xml, count=1) + xml_instance = ET.fromstring(raw_xml) + return xml_instance + +output_lines = [] +def output(line): + output_lines.append(line) + +def process_edge_info(): + output("<<>>") + xml_instance = query_edges() + if xml_instance.iter('edgeSummary'): + tbody = xml_instance.iter('edgeSummary') + for child in tbody: + name=child.find('name').text + edgeid=child.find('id').text + edgestatus=child.find('edgeStatus').text + edgestate=child.find('state').text + edgetype=child.find('edgeType').text + output("%s\t%s\t%s\t%s\t%s" % (name, edgeid, edgestatus, edgestate, edgetype)) + +def process_controller_info(): + output("<<>>") + xml_instance = query_controllers() + if xml_instance.iter('controller'): + tbody = xml_instance.iter('controller') + for child in tbody: + name=child.find('name').text + controllerid=child.find('id').text + controllerstatus=child.find('status').text + output("%s\t%s\t%s" % (name, controllerid, controllerstatus)) + +def process_nsx_components_info(): + output("<<>>") + xml_instance = query_nsx_components() + if xml_instance.iter('component'): + tbody = xml_instance.iter('component') + for child in tbody: + component_name=child.find('name').text + component_id=child.find('componentId').text + component_status=child.find('status').text + output("%s\t%s\t%s" % (component_name, component_id, component_status)) + +def process_nsx_backup_info(): + output("<<>>") + xml_instance = query_nsx_backup() + if xml_instance.iter('backupFileProperties'): + tbody = xml_instance.iter('backupFileProperties') + for child in tbody: + backup_file = child.find('fileName').text + backup_size = child.find('fileSize').text + backup_creationtime=child.find('creationTime').text + output("%s\t%s\t%s" % (backup_file, backup_size, backup_creationtime)) + +def process_nsx_cpu(): + output("<<>>") + xml_instance = query_nsx_cpu() + if xml_instance.iter('cpuinfo'): + tbody = xml_instance.iter('cpuInfo') + for child in tbody: + totalNoOfCPUs = child.find('totalNoOfCPUs').text + capacity = child.find('capacity').text + usedCapacity=child.find('usedCapacity').text + freeCapacity = child.find('freeCapacity').text + usedPercentage = child.find('usedPercentage').text + output("totalNoOfCPUs %s\ncapacity %s\nusedCapacity %s\nfreeCapacity %s\nusedPercentage %s" % (totalNoOfCPUs, capacity, usedCapacity, usedCapacity, usedPercentage )) + +def process_nsx_memory(): + output("<<>>") + xml_instance = query_nsx_memory() + if xml_instance.iter('memInfo'): + tbody = xml_instance.iter('memInfo') + for child in tbody: + totalMemory = child.find('totalMemory').text + usedMemory = child.find('usedMemory').text + freeMemory=child.find('freeMemory').text + usedPercentage = child.find('usedPercentage').text + output("TotalMem %s\nUsedMemory %s\nFreeMemory %s\nUsedPercentage %s" % (totalMemory, usedMemory, freeMemory, usedPercentage)) + +def process_nsx_uptime(): + output("<<>>") + seconds = 0 + uptime=query_nsx_uptime() + raw_text=uptime.split() + uptime=[] + for word in raw_text: + element = re.sub(',','',word,count =1) + uptime.append(element) + if "year" in uptime: + seconds = int(31536000) * int(uptime[int(uptime.index("year"))-1]) + if "days" in uptime: + seconds += int(86400) * int(uptime[int(uptime.index("days"))-1]) + if "hours" in uptime: + seconds += int(3600) * int(uptime[int(uptime.index("hours"))-1]) + if "minutes" in uptime: + seconds += int(60) * int(uptime[int(uptime.index("minutes"))-1]) + output(str(seconds)) + +def process_nsx_vcenter_connection(): + output("<<>>") + xml_instance = query_nsx_vcenter_connection() + if xml_instance.iter('vcConfigStatus'): + tbody = xml_instance.iter('vcConfigStatus') + for child in tbody: + connected = child.find('connected').text + output("vCenterConnection %s" % (connected)) + +def process_nsx_storage_info(): + output("<<>>") + xml_instance = query_nsx_storage_info() + if xml_instance.iter('storageInfo'): + tbody = xml_instance.iter('storageInfo') + for child in tbody: + totalStorage = child.find('totalStorage').text + usedStorage = child.find('usedStorage').text + freeStorage=child.find('freeStorage').text + usedPercentage = child.find('usedPercentage').text + output("TotalStorage %s\nUsedStorage %s\nFreeStorage %s\nUsedPercentage %s" % (totalStorage, usedStorage, freeStorage, usedPercentage)) + +def process_nsx_resource_info(): + output("<<>>") + for i in range(len(resources)): + xml_instance = query_nsx_resources(resources[i]) + if xml_instance.iter('resourceStatuses'): + tbody = xml_instance.iter('resourceStatus') + for child in tbody: + hostRebootRequired = child.find('hostRebootRequired').text + output("%s\thostRebootRequired\t%s" % ( resources[i], hostRebootRequired) ) + feature_statuses = child.iter('nwFabricFeatureStatus') + for feature in feature_statuses: + featureId = feature.find('featureId').text + featurestatus = feature.find('status').text + output("%s\t%s\t%s" % (resources[i], featureId, featurestatus)) + +def query_edges(): + if opt_demo: + raw_xml = re.sub(' xml="[^"]+"', '', edge_status, count=1) + return ET.fromstring(edge_status) + url = "https://%(address)s/api/4.0/edges" % args_dict + return query(url) + +def query_controllers(): + if opt_demo: + raw_xml = re.sub(' xml="[^"]+"', '', controllers, count=1) + return ET.fromstring(controllers) + url = "https://%(address)s/api/2.0/vdn/controller" % args_dict + return query(url) + +def query_nsx_components(): + if opt_demo: + raw_xml = re.sub(' xml="[^"]+"', '', nsx_components, count=1) + return ET.fromstring(nsx_components) + url = "https://%(address)s/api/1.0/appliance-management/summary/components" % args_dict + return query(url) + +def query_nsx_backup(): + if opt_demo: + raw_xml = re.sub(' xml="[^"]+"', '', backup, count=1) + return ET.fromstring(backup) + url = "https://%(address)s/api/1.0/appliance-management/backuprestore/backups" % args_dict + return query(url) + +def query_nsx_memory(): + if opt_demo: + raw_xml = re.sub(' xml="[^"]+"', '', nsx_memory, count=1) + return ET.fromstring(nsx_memory) + url = "https://%(address)s/api/1.0/appliance-management/system/meminfo" % args_dict + return query(url) + +def query_nsx_cpu(): + if opt_demo: + raw_xml = re.sub(' xml="[^"]+"', '', nsx_cpu, count=1) + return ET.fromstring(nsx_cpu) + url = "https://%(address)s/api/1.0/appliance-management/system/cpuinfo" % args_dict + return query(url) + +def query_nsx_uptime(): + if opt_demo: + return nsx_uptime + url = "https://%(address)s/api/1.0/appliance-management/system/uptime" % args_dict + return query(url) + +def query_nsx_vcenter_connection(): + if opt_demo: + raw_xml = re.sub(' xml="[^"]+"', '', nsx_vcenter_connection, count=1) + return ET.fromstring(nsx_vcenter_connection) + url = "https://%(address)s/api/2.0/services/vcconfig/status" % args_dict + return query(url) + +def query_nsx_storage_info(): + if opt_demo: + raw_xml = re.sub(' xml="[^"]+"', '', nsx_storage_info, count=1) + return ET.fromstring(nsx_storage_info) + url = "https://%(address)s/api/1.0/appliance-management/system/storageinfo" % args_dict + return query(url) + +def query_nsx_resources(resource): + if opt_demo: + raw_xml = re.sub(' xml="[^"]+"', '', nsx_resource_domain_c7, count=1) + return ET.fromstring(nsx_resource_domain_c7) + uri = "api/2.0/nwfabric/status?resource=%s" % resource + url_1 = "https://%(address)s/" % args_dict + url = "%s%s" % (url_1, uri) + return query(url) + +def main(): + try: + # Get edges info + process_edge_info() + # Get Controllers info + process_controller_info() + # Get NSX Components + process_nsx_components_info() + # Get NSX Backup + process_nsx_backup_info() + # Get NSX Memory Usage + process_nsx_memory() + # Get NSX CPU Usage + process_nsx_cpu() + # Get Uptime + process_nsx_uptime() + # Get vCenter Conneciton + process_nsx_vcenter_connection() + # Get Storage info + process_nsx_storage_info() + # get Resources info + process_nsx_resource_info() + sys.stdout.write("\n".join(output_lines) + "\n") + except Exception, e: + sys.stderr.write("Connection error: %s" % e) + sys.exit(1) + +edge_status = \ +""" + + + + 256 + 0 + 5 + true + id + + + edge-1 + Edge + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 17 + + Edge + + clj01psc01 + + + false + 0 + false + edge-1 + deployed + gatewayServices + datacenter-2 + clj01-m01dc + default + 4.0 + GREEN + 1 + + 6.3.4 + 6.3.4-6795877 + large + clj01psc01.test + 2 + 0 + vm-42 + clj01psc01-0 + host-21 + clj01m01esx03.test + resgroup-8 + Resources + datastore-12 + clj01-m01-ds01 + 1528198369821 + msgbus-msgbus + false + + false + + Change Log Level + Add Edge Appliance + Delete Edge Appliance + Edit Edge Appliance + Edit CLI Credentials + Change FIPS mode + Change edge appliance size + Force Sync + Redeploy Edge + Change Edge Appliance Core Dump Configuration + Enable hypervisorAssist + Edit Highavailability + Edit Dns + Edit Syslog + Edit Automatic Rule Generation Settings + Disable SSH + Download Edge TechSupport Logs + + + + edge-70c025e2-aae0-4801-b0dd-27c07cb6d9ae + Edge + 42220EB5-0574-A0A4-031B-1DA658998F9E + 8a3ecfae-a3dd-4558-91b6-7430419e174b + 8 + + Edge + + uni01w01dlrbuc01-X_DMZA + + + true + 0 + false + edge-70c025e2-aae0-4801-b0dd-27c07cb6d9ae + active + distributedRouter + default + 4.0 + + jobdata-63834 + SUCCESS + + GREY + 2 + + 6.3.4 + compact + NSX-edge-70c025e2-aae0-4801-b0dd-27c07cb6d9ae + 0 + true + + + + edge-2 + Edge + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 21 + + Edge + + clj01m01esg01 + + + false + 0 + false + edge-2 + deployed + gatewayServices + datacenter-2 + clj01-m01dc + default + 4.0 + GREEN + 3 + + 6.3.4 + 6.3.4-6795877 + large + clj01m01esg01.test + 1 + 0 + vm-46 + clj01m01esg01-0 + host-10 + clj01m01esx01.test + resgroup-8 + Resources + datastore-12 + clj01-m01-ds01 + 1528198355972 + msgbus + false + + false + + Change Log Level + Add Edge Appliance + Delete Edge Appliance + Edit Edge Appliance + Edit CLI Credentials + Change FIPS mode + Change edge appliance size + Force Sync + Redeploy Edge + Change Edge Appliance Core Dump Configuration + Enable hypervisorAssist + Edit Highavailability + Edit Dns + Edit Syslog + Edit Automatic Rule Generation Settings + Disable SSH + Download Edge TechSupport Logs + + + + edge-3 + Edge + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 15 + + Edge + + clj01m01esg02 + + + false + 0 + false + edge-3 + deployed + gatewayServices + datacenter-2 + clj01-m01dc + default + 4.0 + GREEN + 3 + + 6.3.4 + 6.3.4-6795877 + large + clj01m01esg02.test + 1 + 0 + vm-47 + clj01m01esg02-0 + host-20 + clj01m01esx02.test + resgroup-8 + Resources + datastore-12 + clj01-m01-ds01 + 1528198356967 + msgbus + false + + false + + Change Log Level + Add Edge Appliance + Delete Edge Appliance + Edit Edge Appliance + Edit CLI Credentials + Change FIPS mode + Change edge appliance size + Force Sync + Redeploy Edge + Change Edge Appliance Core Dump Configuration + Enable hypervisorAssist + Edit Highavailability + Edit Dns + Edit Syslog + Edit Automatic Rule Generation Settings + Disable SSH + Download Edge TechSupport Logs + + + + edge-4 + Edge + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 21 + + Edge + + clj01m01lb01 + + + false + 0 + false + edge-4 + deployed + gatewayServices + datacenter-2 + clj01-m01dc + default + 4.0 + + jobdata-25970 + SUCCESS + + GREEN + 2 + + 6.3.4 + 6.3.4-6795877 + large + clj01m01lb01.test + 2 + 1 + vm-68 + clj01m01lb01-1 + host-20 + clj01m01esx02.test + resgroup-8 + Resources + datastore-11 + clj01-m01-ds03 + 1528198325165 + msgbus-msgbus + false + + false + + Change Log Level + Add Edge Appliance + Delete Edge Appliance + Edit Edge Appliance + Edit CLI Credentials + Change FIPS mode + Change edge appliance size + Force Sync + Redeploy Edge + Change Edge Appliance Core Dump Configuration + Enable hypervisorAssist + Edit Highavailability + Edit Dns + Edit Syslog + Edit Automatic Rule Generation Settings + Disable SSH + Download Edge TechSupport Logs + + + + edge-2c8970e8-14f4-40f1-a684-9971976b730e + Edge + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 13 + + Edge + + buc01m01udlr01 + + + true + 0 + false + edge-2c8970e8-14f4-40f1-a684-9971976b730e + deployed + distributedRouter + default + 4.0 + + jobdata-25968 + SUCCESS + + GREEN + 4 + + 6.3.4 + 6.3.4-6795877 + compact + NSX-edge-2c8970e8-14f4-40f1-a684-9971976b730e + 2 + 0 + vm-303 + edge-2c8970e8-14f4-40f1-a684-9971976b730e-0-buc01m01udlr01 + host-21 + clj01m01esx03.test + resgroup-8 + Resources + datastore-12 + clj01-m01-ds01 + 1528198329144 + msgbus-msgbus + false + + false + + Change Log Level + Add Edge Appliance + Delete Edge Appliance + Edit Edge Appliance + Edit CLI Credentials + Change FIPS mode + Force Sync + Redeploy Edge + Change Edge Appliance Core Dump Configuration + Edit Highavailability + Edit Dns + Edit Syslog + Disable SSH + Download Edge TechSupport Logs + + 30000 + default+edge-2c8970e8-14f4-40f1-a684-9971976b730e + ffcbdd18-6397-489c-a94f-19761b811d81 + + + TransportZone + universalvdnscope + + + + +""" + + +controllers = \ +""" + + + Controller + 0 + clj01m01nsxc01 + clj01m01nsxc01 + + false + 0 + controller-47 + 172.19.133.51 + RUNNING + NOT_STARTED + 6.3.7087288 + true + + vm-301 + VirtualMachine + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 7 + + VirtualMachine + + NSX_Controller_70ef8503-f49b-478f-96bb-08cd01bd3558 + + domain-c7 + ClusterComputeResource + clj01-m01-mgmt01 + + + + false + 0 + + + host-21 + HostSystem + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 3016 + + HostSystem + + clj01m01esx03.test + + domain-c7 + ClusterComputeResource + clj01-m01-mgmt01 + + + + false + 0 + + + resgroup-8 + ResourcePool + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 153 + + ResourcePool + + Resources + + domain-c7 + ClusterComputeResource + clj01-m01-mgmt01 + + + + false + 0 + + + domain-c7 + ClusterComputeResource + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 9 + + ClusterComputeResource + + clj01-m01-mgmt01 + + datacenter-2 + Datacenter + clj01-m01dc + + + + false + 0 + + 42224242-869B-7AA0-5855-FD2C6ADF7451 + false + + datastore-12 + Datastore + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 2 + + Datastore + + clj01-m01-ds01 + + + false + 0 + + + + controller-47 + 172.19.133.51 + 172.19.133.52 + true + SUCCESS + 1528198790434 + + + FALSE + POWERED_ON + + + Controller + 0 + clj01m01nsxc01 + clj01m01nsxc01 + + false + 0 + controller-48 + 172.19.133.52 + RUNNING + NOT_STARTED + 6.3.7087288 + true + + vm-302 + VirtualMachine + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 7 + + VirtualMachine + + NSX_Controller_cdecc3f5-11c5-461f-b6a8-e980dcc83cc4 + + domain-c7 + ClusterComputeResource + clj01-m01-mgmt01 + + + + false + 0 + + + host-21 + HostSystem + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 3016 + + HostSystem + + clj01m01esx03.test + + domain-c7 + ClusterComputeResource + clj01-m01-mgmt01 + + + + false + 0 + + + resgroup-8 + ResourcePool + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 153 + + ResourcePool + + Resources + + domain-c7 + ClusterComputeResource + clj01-m01-mgmt01 + + + + false + 0 + + + domain-c7 + ClusterComputeResource + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 9 + + ClusterComputeResource + + clj01-m01-mgmt01 + + datacenter-2 + Datacenter + clj01-m01dc + + + + false + 0 + + 42224242-869B-7AA0-5855-FD2C6ADF7451 + false + + datastore-12 + Datastore + 42224242-869B-7AA0-5855-FD2C6ADF7451 + feec058e-c396-4c37-96d2-a7169e92622a + 2 + + Datastore + + clj01-m01-ds01 + + + false + 0 + + + + controller-48 + 172.19.133.52 + 172.19.133.51 + true + SUCCESS + 1528198790484 + + + FALSE + POWERED_ON + +""" + +nsx_components = \ +""" + + + + COMMON + + + VPOSTGRES + vPostgres + vPostgres - Database service + RUNNING + true + false + + NSX + + COMMON + + + RABBITMQ + RabbitMQ + RabbitMQ - Messaging service + RUNNING + true + false + + NSX + + COMMON + + + + + NSXGRP + + + NSXREPLICATOR + NSX Replicator + NSX Replicator + RUNNING + true + false + + NSX + + + NSXGRP + + + NSX + NSX Manager + NSX Manager + RUNNING + true + true + + VPOSTGRES + RABBITMQ + + + NSXREPLICATOR + + NSXGRP + + 6 + 3 + 4 + 7087695 + + + + + + SYSTEM + + + SSH + SSH Service + Secure Shell + RUNNING + true + false + + SYSTEM + + + + +""" + + +backup = \ +""" + + + clj01m01nsx01_00_00_00_Tue05Jun2018 + 3614752 + 1528156800000 + + + clj01m01nsx01_00_00_00_Sun03Jun2018 + 3553312 + 1527984000000 + + + clj01m01nsx01_00_00_00_Sat02Jun2018 + 3532832 + 1527897600000 + + + clj01m01nsx01_00_00_00_Thu31May2018 + 3491872 + 1527724800000 + + + clj01m01nsx01_00_00_00_Wed30May2018 + 3471392 + 1527638400000 + + + clj01m01nsx01_00_00_00_Tue29May2018 + 3450912 + 1527552000000 + + + clj01m01nsx01_00_00_00_Mon28May2018 + 3430432 + 1527465600000 + + + clj01m01nsx01_00_00_00_Sun27May2018 + 3420192 + 1527379200000 + + + clj01m01nsx01_00_00_00_Sat26May2018 + 3399712 + 1527292800000 + + + clj01m01nsx01_00_00_00_Fri25May2018 + 3389472 + 1527206400000 + + + clj01m01nsx01_00_00_00_Thu24May2018 + 3328032 + 1527120000000 + + + clj01m01nsx01_00_00_00_Tue22May2018 + 3266592 + 1526947200000 + + + clj01m01nsx01_00_00_00_Mon21May2018 + 3246112 + 1526860800000 + + + clj01m01nsx01_00_00_00_Sun20May2018 + 3225632 + 1526774400000 + + + clj01m01nsx01_00_00_00_Sat19May2018 + 3205152 + 1526688000000 + + + clj01m01nsx01_00_00_00_Fri30Mar2018 + 2109472 + 1522368000000 + + + clj01m01nsx01_00_00_00_Fri18May2018 + 3184672 + 1526601600000 + + + clj01m01nsx01_00_00_00_Thu29Mar2018 + 2088992 + 1522281600000 + + + clj01m01nsx01_00_00_00_Thu17May2018 + 3153952 + 1526515200000 + + + clj01m01nsx01_00_00_00_Wed28Mar2018 + 2058272 + 1522195200000 + + + clj01m01nsx01_00_00_00_Wed16May2018 + 3143712 + 1526428800000 + + + clj01m01nsx01_00_00_00_Tue27Mar2018 + 2037792 + 1522108800000 + + + clj01m01nsx01_23_59_58_Mon14May2018 + 3143712 + 1526342398000 + + + clj01m01nsx01_00_00_00_Mon26Mar2018 + 2017312 + 1522022400000 + + + clj01m01nsx01_00_00_00_Mon14May2018 + 3143712 + 1526256000000 + + + clj01m01nsx01_00_00_00_Sun25Mar2018 + 1996832 + 1521936000000 + + + clj01m01nsx01_00_00_00_Sun13May2018 + 3112992 + 1526169600000 + + + clj01m01nsx01_00_00_00_Sat24Mar2018 + 1976352 + 1521849600000 + + + clj01m01nsx01_00_00_00_Sat12May2018 + 3133472 + 1526083200000 + + + clj01m01nsx01_00_00_00_Fri23Mar2018 + 1996832 + 1521763200000 + + + clj01m01nsx01_00_00_00_Thu22Mar2018 + 1914912 + 1521676800000 + + + clj01m01nsx01_00_00_00_Thu10May2018 + 3072032 + 1525910400000 + + + clj01m01nsx01_00_00_00_Wed21Mar2018 + 1822752 + 1521590400000 + + + clj01m01nsx01_00_00_00_Wed09May2018 + 3051552 + 1525824000000 + + + clj01m01nsx01_00_00_00_Tue20Mar2018 + 1740832 + 1521504000000 + + + clj01m01nsx01_00_00_00_Tue08May2018 + 2990112 + 1525737600000 + + + clj01m01nsx01_00_00_00_Mon19Mar2018 + 1658912 + 1521417600000 + + + clj01m01nsx01_00_00_00_Mon07May2018 + 2928672 + 1525651200000 + + + clj01m01nsx01_00_00_00_Sun18Mar2018 + 1576992 + 1521331200000 + + + clj01m01nsx01_00_00_00_Sun06May2018 + 2908192 + 1525564800000 + + + clj01m01nsx01_00_00_00_Sat17Mar2018 + 1495072 + 1521244800000 + + + clj01m01nsx01_00_00_00_Sat05May2018 + 2887712 + 1525478400000 + + + clj01m01nsx01_00_00_00_Fri16Mar2018 + 1402912 + 1521158400000 + + + clj01m01nsx01_00_00_00_Fri04May2018 + 2867232 + 1525392000000 + + + clj01m01nsx01_00_00_00_Thu15Mar2018 + 1320992 + 1521072000000 + + + clj01m01nsx01_00_00_00_Wed14Mar2018 + 1228832 + 1520985600000 + + + clj01m01nsx01_00_00_00_Tue13Mar2018 + 1146912 + 1520899200000 + + + clj01m01nsx01_00_00_00_Mon12Mar2018 + 1064992 + 1520812800000 + + + clj01m01nsx01_00_00_00_Sun11Mar2018 + 993312 + 1520726400000 + + + clj01m01nsx01_23_59_58_Fri09Mar2018 + 911392 + 1520639998000 + + + clj01m01nsx01_23_59_58_Thu08Mar2018 + 778272 + 1520553598000 + + + clj01m01nsx01_00_00_00_Thu08Mar2018 + 665632 + 1520467200000 + + + clj01m01nsx01_08_21_01_Wed07Mar2018 + 532512 + 1520410861000 + + + clj01m01nsx01_00_00_00_Mon04Jun2018 + 3573792 + 1528070400000 + + + clj01m01nsx01_00_00_00_Fri01Jun2018 + 3512352 + 1527811200000 + +""" + +nsx_memory = \ +""" + + 16025 MB + 5233 MB + 10792 MB + 33 +""" + +nsx_cpu = \ +""" + + 4 + 2196 MHZ + 17 MHZ + 2179 MHZ + 1 +""" + +nsx_vcenter_connection = \ +""" + + true + 1528202184756 +""" + + +nsx_storage_info = \ +""" + + 81G + 4.1G + 77G + 5 +""" + + +nsx_uptime = "7 days, 7 minutes" + +nsx_resource_domain_c7 = \ +""" + + + + domain-c7 + ClusterComputeResource + 4220F930-D7C1-D623-88EC-FB40297018CF + b473ae67-65db-48cb-ac8d-069e43df1c52 + 12 + + ClusterComputeResource + + buc01-m01-mgmt01 + + datacenter-2 + Datacenter + buc01-m01dc + + + + false + 0 + + false + + com.vmware.vshield.vsm.nwfabric.hostPrep + 6.3.4.7087695 + false + GREEN + true + true + false + + + com.vmware.vshield.vsm.vdr_mon + 5.5 + false + UNKNOWN + false + true + false + + + com.vmware.vshield.vsm.vxlan + 5.5 + false + GREEN + true + true + false + + + com.vmware.vshield.vsm.messagingInfra + false + GREEN + true + true + false + + + com.vmware.vshield.firewall + 5.5 + false + GREEN + + true + true + false + + +""" + +if __name__ == "__main__": + main() + diff --git a/local/share/check_mk/agents/special/agent_srm b/local/share/check_mk/agents/special/agent_srm new file mode 100644 index 0000000..054be00 --- /dev/null +++ b/local/share/check_mk/agents/special/agent_srm @@ -0,0 +1,173 @@ +#!/usr/bin/env python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +------------------------------------------------------------------+ +# | ____ _ _ __ __ _ __ | +# | / ___| |__ ___ ___| | __ | \/ | |/ / | +# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | +# | | |___| | | | __/ (__| < | | | | . \ | +# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | +# | | +# | Copyright Mathias Kettner 2018 mk@mathias-kettner.de | +# +------------------------------------------------------------------+ +# +# This file is part of Check_MK. +# The official homepage is at http://mathias-kettner.de/check_mk. +# +# check_mk is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation in version 2. check_mk is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- +# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more de- +# tails. You should have received a copy of the GNU General Public +# License along with GNU Make; see the file COPYING. If not, write +# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301 USA. + +import re +import sys, getopt +import requests +from requests.packages.urllib3.exceptions import InsecureRequestWarning # pylint: disable=import-error +from HTMLParser import HTMLParser + +def usage(): + sys.stderr.write("""Check_MK VMWare SRM + +USAGE: agent_srm [OPTIONS] HOST + +OPTIONS: + -h, --help Show this help message and exit + --address Host address + --no-cert-check Disable certificate check +""") + sys.exit(1) + +short_options = "h" +long_options = ["help", "address=", "demo", "no-cert-check"] + +try: + opts, args = getopt.getopt(sys.argv[1:], short_options, long_options) +except getopt.GetoptError, err: + sys.stderr.write("%s\n" % err) + sys.exit(1) + + +opt_demo = False +opt_cert = True +args_dict = {} +resources = [] + +for o,a in opts: + if o in [ "--address" ]: + args_dict["address"] = a + elif o in [ "--demo" ]: + opt_demo = True + elif o in [ "--no-cert-check" ]: + opt_cert = False + elif o in [ "-h", "--help" ]: + usage() + +class HTMLTableParser(HTMLParser): + def __init__( + self, + decode_html_entities=False, + data_separator=' ', + ): + + HTMLParser.__init__(self) + + self._parse_html_entities = decode_html_entities + self._data_separator = data_separator + + self._in_td = False + self._in_th = False + self._current_table = [] + self._current_row = [] + self._current_cell = [] + self.tables = [] + + def handle_starttag(self, tag, attrs): + if tag == 'td': + self._in_td = True + if tag == 'th': + self._in_th = True + + def handle_data(self, data): + if self._in_td or self._in_th: + self._current_cell.append(data.strip()) + + def handle_charref(self, name): + + if self._parse_html_entities: + self.handle_data(self.unescape('&#{};'.format(name))) + + def handle_endtag(self, tag): + if tag == 'td': + self._in_td = False + elif tag == 'th': + self._in_th = False + + if tag in ['td', 'th']: + final_cell = self._data_separator.join(self._current_cell).strip() + self._current_row.append(final_cell) + self._current_cell = [] + elif tag == 'tr': + self._current_table.append(self._current_row) + self._current_row = [] + elif tag == 'table': + self.tables.append(self._current_table) + self._current_table = [] + +parser=HTMLTableParser() + +def query(url): + if opt_cert == False: + requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # pylint: disable=no-member + response = requests.get(url, verify=opt_cert) + raw_html = response.text + return raw_html +output_lines = [] +def output(line): + output_lines.append(line) + +def query_srm(): + if opt_demo: + return parser.feed(srm_status) + url = "https://%(address)s:9086/" % args_dict + return parser.feed(query(url)) + +def process_srm_info(): + output("<<>>") + query_srm() + local_connection = parser.tables[0] + remote_connection = parser.tables[1] + i=2 + for row in local_connection: + if str(row[0]) == "Service": + output("LocalConnection %s\t%s\t%s" % (row[1],local_connection[i][1],local_connection[i+2][1])) + i+=5 + + i=2 + for row in remote_connection: + if str(row[0]) == "Service": + output("RemoteConnection %s\t%s\t%s" % (row[1],local_connection[i][1],remote_connection[i+2][1])) + i+=5 + +def main(): + try: + process_srm_info() + sys.stdout.write("\n".join(output_lines) + "\n") + except Exception, e: + sys.stderr.write("Connection error: %s" % e) + sys.exit(1) + + +srm_status = \ +""" + + +

VMware vCenter Site Recovery Manager 6.5.1.6014840

Name: buc01m01vc01.test, UUID: d8fd8aea-a3ed-46e9-857e-509b80784c53, Extension key: com.vmware.vcDr

VMware vCenter Server 6.5.0 build-7515524


Supported VMODL versions

Inherent VMODL version


Local Connections

----------------------------------------------------------------------------------------------------
Servicecom.vmware.cis.vcenterserver
URLhttps://buc01m01vc01.test:443/sdk
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------
Servicecom.vmware.cis.cs.inventory
URLhttps://buc01m01vc01.test:443/invsvc/vmomi/sdk
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------
Servicecom.vmware.cis.cs.lookup
URLhttps://buc01psc01.test:443/lookupservice/sdk
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------
Servicecom.vmware.cis.cs.identity
URLhttps://buc01psc01.test/sso-adminserver/sdk/vsphere.local
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------
Servicecom.vmware.cis.cs.authorization
URLhttps://buc01m01vc01.test:443/invsvc/vmomi/sdk
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------
Servicecom.vmware.cis.cs.license
URLhttps://buc01psc01.test:443/ls/sdk
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------

Paired with remote SRM with name 'clj01m01vc01.test' and uuid 'acf7df22-01bb-439a-b27e-9f8b83e23233'

Remote Connections

----------------------------------------------------------------------------------------------------
Servicecom.vmware.cis.vcenterserver
URLhttps://clj01m01vc01.test:443/sdk
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------
Servicecom.vmware.dr.vcDr
URLhttps://clj01m01srm01.test:9086/vcdr/vmomi/sdk
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------
Servicecom.vmware.cis.cs.lookup
URLhttps://clj01psc01.test:443/lookupservice/sdk
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------
Servicecom.vmware.cis.cs.identity
URLhttps://clj01psc01.test/sso-adminserver/sdk/vsphere.local
Thumbprintunknown
StatusConnected
----------------------------------------------------------------------------------------------------
""" + +if __name__ == "__main__": + main() + diff --git a/local/share/check_mk/checkman/nsx_backup b/local/share/check_mk/checkman/nsx_backup new file mode 100644 index 0000000..8c4dfdc --- /dev/null +++ b/local/share/check_mk/checkman/nsx_backup @@ -0,0 +1,14 @@ +title: VMWare NSX: Backup time +agents: agent_nsx +catalog: Miscellaneous +license: GPL +distribution: check_mk +description: + This check monitors the date of last backup. +item: + Backup service. + +perfdata: + none +inventory: + One service called "NSX Backups". diff --git a/local/share/check_mk/checkman/nsx_components b/local/share/check_mk/checkman/nsx_components new file mode 100644 index 0000000..6232707 --- /dev/null +++ b/local/share/check_mk/checkman/nsx_components @@ -0,0 +1,15 @@ +title: VMWare NSX: Components status +agents: agent_nsx +catalog: Miscellaneous +license: GPL +distribution: check_mk +description: + This check monitors the status of VMWare NSX Components +item: + The item is composed from the Component Type. + +perfdata: + none +inventory: + All NSX Components defined will be inventorized. + diff --git a/local/share/check_mk/checkman/nsx_controllers b/local/share/check_mk/checkman/nsx_controllers new file mode 100644 index 0000000..78bb4fe --- /dev/null +++ b/local/share/check_mk/checkman/nsx_controllers @@ -0,0 +1,19 @@ +title: VMWare NSX: Controllers status +agents: agent_nsx +catalog: Miscellaneous +license: GPL +distribution: check_mk +description: + This check monitors the status of VMWare NSX Constrollers +• Deploying - controller is being deployed and the procedure has not completed yet. +• Removing - controller is being removed and the procedure has not completed yet. +• Running - controller has been deployed and can respond to API invocation. +• Unknown - controller has been deployed but fails to respond to API invocation. +item: + The item is composed from the Controller-id. + +perfdata: + none +inventory: + All NSX Controllers defined will be inventorized. + diff --git a/local/share/check_mk/checkman/nsx_cpu b/local/share/check_mk/checkman/nsx_cpu new file mode 100644 index 0000000..bdbc6ff --- /dev/null +++ b/local/share/check_mk/checkman/nsx_cpu @@ -0,0 +1,15 @@ +title: VMWare NSX: CPU usage of NSX +agents: agent_nsx +catalog: Miscellaneous +license: GPL +distribution: check_mk +description: + This check monitors the CPU usage. +item: + Memory used + +perfdata: + One graph for CPU used in percentage +inventory: + One service called "CPU Utilization". + diff --git a/local/share/check_mk/checkman/nsx_edges b/local/share/check_mk/checkman/nsx_edges new file mode 100644 index 0000000..1a3caff --- /dev/null +++ b/local/share/check_mk/checkman/nsx_edges @@ -0,0 +1,15 @@ +title: VMWare NSX: Edges status +agents: agent_nsx +catalog: Miscellaneous +license: GPL +distribution: check_mk +description: + This check monitors the status of VMWare NSX Edges +item: + The item is composed from the edge-id. + +perfdata: + none +inventory: + All NSX edges defined will be inventorized. + diff --git a/local/share/check_mk/checkman/nsx_mem b/local/share/check_mk/checkman/nsx_mem new file mode 100644 index 0000000..33f64c2 --- /dev/null +++ b/local/share/check_mk/checkman/nsx_mem @@ -0,0 +1,15 @@ +title: VMWare NSX: Memory usage of NSX +agents: agent_nsx +catalog: Miscellaneous +license: GPL +distribution: check_mk +description: + This check monitors the memory usage. +item: + Memory used + +perfdata: + Two graphs for memory used and all memory +inventory: + One service called "Memory Usage". + diff --git a/local/share/check_mk/checkman/nsx_memory b/local/share/check_mk/checkman/nsx_memory new file mode 100644 index 0000000..e785410 --- /dev/null +++ b/local/share/check_mk/checkman/nsx_memory @@ -0,0 +1,14 @@ +title: VMWare NSX: Memory usage of NSX +agents: agent_nsx +catalog: Miscellaneous +license: GPL +distribution: check_mk +description: + This check monitors the memory usage. +item: + Memory used + +perfdata: + Two graphs for memory used and all memory +inventory: + One service called "Memory Usage". diff --git a/local/share/check_mk/checkman/nsx_storage b/local/share/check_mk/checkman/nsx_storage new file mode 100644 index 0000000..ffec152 --- /dev/null +++ b/local/share/check_mk/checkman/nsx_storage @@ -0,0 +1,15 @@ +title: VMWare NSX: Storage usage of NSX +agents: agent_nsx +catalog: Miscellaneous +license: GPL +distribution: check_mk +description: + This check monitors the storage usage. +item: + Memory used + +perfdata: + One graph for storage used in bytes, autoscaled +inventory: + One service called "Storage used". + diff --git a/local/share/check_mk/checkman/nsx_vcenter_connection b/local/share/check_mk/checkman/nsx_vcenter_connection new file mode 100644 index 0000000..752bd82 --- /dev/null +++ b/local/share/check_mk/checkman/nsx_vcenter_connection @@ -0,0 +1,14 @@ +title: VMWare NSX: vCenter Connection +agents: agent_nsx +catalog: Miscellaneous +license: GPL +distribution: check_mk +description: + This check monitors the state of vCenter Connection. +item: + vCenter Connection + +perfdata: + none +inventory: + One service called "vCenter Connection". diff --git a/local/share/check_mk/checks/agent_nsx b/local/share/check_mk/checks/agent_nsx new file mode 100644 index 0000000..1f6bbf6 --- /dev/null +++ b/local/share/check_mk/checks/agent_nsx @@ -0,0 +1,41 @@ +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +------------------------------------------------------------------+ +# | ____ _ _ __ __ _ __ | +# | / ___| |__ ___ ___| | __ | \/ | |/ / | +# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | +# | | |___| | | | __/ (__| < | | | | . \ | +# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | +# | | +# | Copyright Mathias Kettner 2017 mk@mathias-kettner.de | +# +------------------------------------------------------------------+ +# +# This file is part of Check_MK. +# The official homepage is at http://mathias-kettner.de/check_mk. +# +# check_mk is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation in version 2. check_mk is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- +# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more de- +# tails. You should have received a copy of the GNU General Public +# License along with GNU Make; see the file COPYING. If not, write +# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301 USA. + +def agent_nsx_arguments(params, hostname, ipaddress): + args = '' + args += "--address=%s " % hostname + args += "--user=%s " % params["user"] + args += "--password=%s " % params["password"] + + if "nsx_resource" in params: + for domain in params["nsx_resource"]: + args += "--nsx_resource=%s " % domain + if "cert" in params and params["cert"] == False: + args += "--no-cert-check " + return args + +special_agent_info['nsx'] = agent_nsx_arguments + diff --git a/local/share/check_mk/checks/agent_srm b/local/share/check_mk/checks/agent_srm new file mode 100644 index 0000000..21c5ce0 --- /dev/null +++ b/local/share/check_mk/checks/agent_srm @@ -0,0 +1,36 @@ +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +------------------------------------------------------------------+ +# | ____ _ _ __ __ _ __ | +# | / ___| |__ ___ ___| | __ | \/ | |/ / | +# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | +# | | |___| | | | __/ (__| < | | | | . \ | +# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | +# | | +# | Copyright Mathias Kettner 2017 mk@mathias-kettner.de | +# +------------------------------------------------------------------+ +# +# This file is part of Check_MK. +# The official homepage is at http://mathias-kettner.de/check_mk. +# +# check_mk is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation in version 2. check_mk is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- +# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more de- +# tails. You should have received a copy of the GNU General Public +# License along with GNU Make; see the file COPYING. If not, write +# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301 USA. + +def agent_srm_arguments(params, hostname, ipaddress): + args = '' + args += "--address=%s " % hostname + + if "cert" in params and params["cert"] == False: + args += "--no-cert-check " + return args + +special_agent_info['srm'] = agent_srm_arguments + diff --git a/local/share/check_mk/checks/check_nsx b/local/share/check_mk/checks/check_nsx new file mode 100644 index 0000000..e7a155c --- /dev/null +++ b/local/share/check_mk/checks/check_nsx @@ -0,0 +1,431 @@ +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +------------------------------------------------------------------+ +# | ____ _ _ __ __ _ __ | +# | / ___| |__ ___ ___| | __ | \/ | |/ / | +# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | +# | | |___| | | | __/ (__| < | | | | . \ | +# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | +# | | +# | Copyright Mathias Kettner 2018 mk@mathias-kettner.de | +# +------------------------------------------------------------------+ +# +# This file is part of Check_MK. +# The official homepage is at http://mathias-kettner.de/check_mk. +# +# check_mk is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation in version 2. check_mk is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- +# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more de- +# tails. You should have received a copy of the GNU General Public +# License along with GNU Make; see the file COPYING. If not, write +# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301 USA. + +import datetime + +def inventory_edges_status(info): + for name, edgeid, edgestatus, edgestate, edgetype in info: + yield ("Edge %s" % \ + (edgeid), {}) + + +def check_edges_status(item, params, info): + for line in info: + edge = "Edge" + " " + line[1] + if edge==item: + edgename = line[0] + edgestatus = line[2] + edgestate = line[3] + edgetype = line[4] + if edgetype == "distributedRouter": + if edgestate != "active": + return 2, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus ) + elif edgestatus == "GREEN": + return 0, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus ) + elif edgestatus == "GREY": + return 0, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus ) + elif edgestatus == "YELLOW": + return 1, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus ) + elif edgestatus == "RED": + return 2, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus ) + return 3, "Edge %s state is %s and status %s" % (edgename, edgestate, edgestatus ) + else: + if edgestatus == "GREEN": + return 0, "Edge %s is %s" % (edgename, edgestatus) + elif edgestatus == "YELLOW": + return 1, "Edge %s is %s" % (edgename, edgestatus) + elif edgestatus == "RED": + return 2, "Edge %s is %s" % (edgename, edgestatus) + return 3, "Edge %s is %s" % (edgename, edgestatus) + + +check_info['nsx_edges'] = { + 'inventory_function' : inventory_edges_status, + 'check_function' : check_edges_status, + 'service_description' : '%s', + 'has_perfdata' : False, +} + +#. +# .--Controller Status---------------------------------------------------. +# | ____ _ _ _ | +# | / ___|___ _ __ | |_ _ __ ___ | | | ___ _ __ | +# | | | / _ \| '_ \| __| '__/ _ \| | |/ _ \ '__| | +# | | |__| (_) | | | | |_| | | (_) | | | __/ | | +# | \____\___/|_| |_|\__|_| \___/|_|_|\___|_| | +# | | +# | ____ _ _ | +# | / ___|| |_ __ _| |_ _ _ ___ | +# | \___ \| __/ _` | __| | | / __| | +# | ___) | || (_| | |_| |_| \__ \ | +# | |____/ \__\__,_|\__|\__,_|___/ | +# | | +# +----------------------------------------------------------------------+ +# | | +# '----------------------------------------------------------------------' + +def inventory_controller_status(info): + for name, id, status in info: + yield ("Controller %s" % \ + (id), {}) + + +def check_controller_status(item, params, info): + for line in info: + controller = "Controller" + " " + line[1] + if controller==item: + controllername = line[0] + controllerstatus = line[2] + if controllerstatus == "RUNNING": + return 0, "Controller %s is %s" % (controllername, controllerstatus) + elif controllerstatus == "DEPLOYING": + return 1, "Controller %s is %s" % (controllername, controllerstatus) + elif controllerstatus == "REMOVING": + return 1, "Controller %s is %s" % (controllername, controllerstatus) + elif controllerstatus == "UNKNOWN": + return 2, "Controller %s is %s" % (controllername, controllerstatus) + +check_info['nsx_controller'] = { + 'inventory_function' : inventory_controller_status, + 'check_function' : check_controller_status, + 'service_description' : '%s', + 'has_perfdata' : False, +} + + + +#. +# .--NSX Components------------------------------------------------------. +# | _ _ ______ __ | +# | | \ | / ___\ \/ / | +# | | \| \___ \\ / | +# | | |\ |___) / \ | +# | |_| \_|____/_/\_\ | +# | | +# | ____ _ | +# | / ___|___ _ __ ___ _ __ ___ _ __ ___ _ __ | |_ ___ | +# | | | / _ \| '_ ` _ \| '_ \ / _ \| '_ \ / _ \ '_ \| __/ __| | +# | | |__| (_) | | | | | | |_) | (_) | | | | __/ | | | |_\__ \ | +# | \____\___/|_| |_| |_| .__/ \___/|_| |_|\___|_| |_|\__|___/ | +# | |_| | +# +----------------------------------------------------------------------+ +# | | +# '----------------------------------------------------------------------' +def inventory_nsx_components(info): + for name, id, status in info: + yield ("Component %s" % \ + (id), {}) + + +def check_nsx_components(item, params, info): + for line in info: + component = "Component" + " " + line[1] + if component==item: + component_name = line[0] + component_status = line[2] + if component_status == "RUNNING": + return 0, "Component %s is %s" % (component_name, component_status) + else: + return 2, "Component %s is %s" % (component_name, component_status) + +check_info['nsx_components'] = { + 'inventory_function' : inventory_nsx_components, + 'check_function' : check_nsx_components, + 'service_description' : '%s', + 'has_perfdata' : False, +} + +#. +# .--NSX Backup----------------------------------------------------------. +# | _ _ ______ __ ____ _ | +# | | \ | / ___\ \/ / | __ ) __ _ ___| | ___ _ _ __ | +# | | \| \___ \\ / | _ \ / _` |/ __| |/ / | | | '_ \ | +# | | |\ |___) / \ | |_) | (_| | (__| <| |_| | |_) | | +# | |_| \_|____/_/\_\ |____/ \__,_|\___|_|\_\\__,_| .__/ | +# | |_| | +# +----------------------------------------------------------------------+ +# | | +# '----------------------------------------------------------------------' +def inventory_nsx_backups(info): + return [(None, {})] + + +def check_nsx_backup(item, params, info): + warn, crit = params + if info: + last_backup = sorted(info, key=lambda tup: tup[2])[-1] + last_backup_size = last_backup[1] + last_backup_time = datetime.datetime.fromtimestamp(float(last_backup[2])/1000) + elapsed = datetime.datetime.now() - last_backup_time + if elapsed >= datetime.timedelta(days=crit): + return 2, "Last backup was taken more than %s days ago. Last backup date is %s " \ + % (crit, last_backup_time) + elif elapsed >= datetime.timedelta(days=warn): + return 1, "Last backup was taken more than %s days ago. Last backup date is %s " \ + % (warn, last_backup_time) + else: + return 0, "Date of last backup is %s" % last_backup_time + else: + return 3, "Backup not available" + +check_info['nsx_backup'] = { + 'inventory_function' : inventory_nsx_backups, + 'check_function' : check_nsx_backup, + 'service_description' : 'NSX Backups', + 'has_perfdata' : False, + 'group' : "backups", +} + +#. +# .--Memory--------------------------------------------------------------. +# | __ __ | +# | | \/ | ___ _ __ ___ ___ _ __ _ _ | +# | | |\/| |/ _ \ '_ ` _ \ / _ \| '__| | | | | +# | | | | | __/ | | | | | (_) | | | |_| | | +# | |_| |_|\___|_| |_| |_|\___/|_| \__, | | +# | |___/ | +# +----------------------------------------------------------------------+ +nsx_memory_default_levels = ( 80.0, 90.0 ) + +def nsx_convert(info): + data = {} + for line in info: + data[line[0]] = line[1:] + return data + +def inventory_nsx_mem(info): + data = nsx_convert(info) + return [(None, 'nsx_mem_default_levels')] + +def check_nsx_mem(item, params, info): + data = nsx_convert(info) + warn, crit = params + memory_usage = savefloat(data['UsedMemory'][0]) * 1024 * 1024 + memory_size = savefloat(data['TotalMem'][0]) * 1024 * 1024 + level = savefloat(data['UsedPercentage'][0]) + state = 0 + label = '' + if level >= crit: + state = 2 + label = " (Levels at %d%%/%d%%)" % (warn, crit) + elif level >= warn: + state = 1 + label = " (Levels at %d%%/%d%%)" % (warn, crit) + message = "%d%%%s used - %s/%s" % \ + (level, label, get_bytes_human_readable(memory_usage), get_bytes_human_readable(memory_size)) + perf = [("mem_used", memory_usage, warn * memory_size / 100, crit * memory_size / 100, 0, memory_size), + ("mem_total", memory_size)] + return(state, message, perf) + + +check_info['nsx_memory'] = { + "inventory_function" : inventory_nsx_mem, + "check_function" : check_nsx_mem, + "service_description" : "Memory used", + "group" : "nsx_memory", + "has_perfdata" : True, + "default_levels_variable" : "nsx_mem_default_levels" +} + +#. +# .--CPU-----------------------------------------------------------------. +# | ____ ____ _ _ | +# | / ___| _ \| | | | | +# | | | | |_) | | | | | +# | | |___| __/| |_| | | +# | \____|_| \___/ | +# | | +# +----------------------------------------------------------------------+ + +nsx_host_cpu_default_levels = {} + +def inventory_nsx_cpu(info): + data = nsx_convert(info).keys() + if 'usedPercentage' in data \ + and 'totalNoOfCPUs' in data\ + and 'capacity' in data: + return [(None, {})] + +def check_nsx_cpu(item, params, info): + data = nsx_convert(info) + + if "usedPercentage" not in data: + return + #Asuming that there are 1 thread per core and one core per socket + #Asuming that capacity represents total capacity + + num_cpu = int(data['totalNoOfCPUs'][0]) + total_capacity = int(data['capacity'][0]) + used_capacity = float(data['usedCapacity'][0]) + mhz_per_core = float(data['capacity'][0]) / num_cpu + + + usage = used_capacity / total_capacity * 100 + per_core = num_cpu / 100.0 + + infotext = "%.1f%%" % usage + + # Convert legacy parameters + this_time = time.time() + state, infotext, perfdata = check_cpu_util(usage, params).next() + + infotext += ", %.2fGHz/%.2fGHz" % (used_capacity / 1000.0, total_capacity / 1000.0) + infotext += ", %d sockets, %d cores/socket, %d threads" % ( + num_cpu, 1 , 1) + return (state, infotext, perfdata) + + +check_info['nsx_cpu'] = { + "inventory_function" : inventory_nsx_cpu, + "check_function" : check_nsx_cpu, + "service_description" : "CPU utilization", + "group" : "cpu_utilization_os", + "has_perfdata" : True, + "default_levels_variable" : "nsx_host_cpu_default_levels", + "includes" : [ "cpu_util.include" ], +} + +#. +# .--NSX vCenter Connection----------------------------------------------. +# | _ _ ______ __ ____ _ | +# | | \ | / ___\ \/ / __ __/ ___|___ _ __ | |_ ___ _ __ | +# | | \| \___ \\ / \ \ / / | / _ \ '_ \| __/ _ \ '__| | +# | | |\ |___) / \ \ V /| |__| __/ | | | || __/ | | +# | |_| \_|____/_/\_\ \_/ \____\___|_| |_|\__\___|_| | +# | | +# | ____ _ _ | +# | / ___|___ _ __ _ __ ___ ___| |_(_) ___ _ __ | +# | | | / _ \| '_ \| '_ \ / _ \/ __| __| |/ _ \| '_ \ | +# | | |__| (_) | | | | | | | __/ (__| |_| | (_) | | | | | +# | \____\___/|_| |_|_| |_|\___|\___|\__|_|\___/|_| |_| | +# | | +# +----------------------------------------------------------------------+ +# | | +# '----------------------------------------------------------------------' +def inventory_nsx_vcenter_connection(info): + return [(None, {})] + + +def check_nsx_vcenter_connection(item, params, info): + if "true" in info[0]: + return 0, "vCenterConnection is true" + elif "false" in info[0]: + return 2, "vCenterConnection is false" + +check_info['nsx_vcenter_connection'] = { + 'inventory_function' : inventory_nsx_vcenter_connection, + 'check_function' : check_nsx_vcenter_connection, + 'service_description' : 'vCenter Connection', + 'has_perfdata' : False, +} + + +#. +# .--NSX Storage Info----------------------------------------------------. +# | _ _ ______ __ ____ _ | +# | | \ | / ___\ \/ / / ___|| |_ ___ _ __ __ _ __ _ ___ | +# | | \| \___ \\ / \___ \| __/ _ \| '__/ _` |/ _` |/ _ \ | +# | | |\ |___) / \ ___) | || (_) | | | (_| | (_| | __/ | +# | |_| \_|____/_/\_\ |____/ \__\___/|_| \__,_|\__, |\___| | +# | |___/ | +# | ___ __ | +# | |_ _|_ __ / _| ___ | +# | | || '_ \| |_ / _ \ | +# | | || | | | _| (_) | | +# | |___|_| |_|_| \___/ | +# | | +# +----------------------------------------------------------------------+ +# | | +# '----------------------------------------------------------------------' +nsx_storage_default_levels = ( 70.0, 80.0 ) + +def inventory_nsx_storage(info): + data = nsx_convert(info) + return [(None, 'nsx_storage_default_levels')] + +def check_nsx_storage(item, params, info): + warn,crit = params + data = nsx_convert(info) + used_storage = float(re.sub('G','', data['UsedStorage'][0],count =1)) + total_storage = float(re.sub('G','', data['TotalStorage'][0],count =1)) + free_storage = float(re.sub('G','', data['FreeStorage'][0],count =1)) + used_percentage = float(re.sub('G','', data['UsedPercentage'][0],count =1)) + perf = [("storage_used", used_storage * 1024 * 1024 * 1024, \ + warn * total_storage * 1024 * 1024 * 1024 / 100 , \ + crit * total_storage * 1024 * 1024 * 1024 / 100 , 0, total_storage * 1024 * 1024 * 1024)] + if used_percentage >= crit: + return 2, "Storage used is %sGB out of %sGB" % (used_storage, total_storage) , perf + elif used_percentage >= warn: + return 1, "Storage used is %sGB out of %sGB" % (used_storage, total_storage) , perf + else: + return 0, "Storage used is %sGB out of %sGB" % (used_storage, total_storage) , perf + +check_info['nsx_storage_info'] = { + "inventory_function" : inventory_nsx_storage, + "check_function" : check_nsx_storage, + "service_description" : "Storage used", + "group" : "nsx_storage", + "has_perfdata" : True, + "default_levels_variable" : "nsx_storage_default_levels", + +} + + + +####NSX_RESOURCES +def inventory_nsx_resources(info): + for domain_name, component, status in info: + component_sn = component.split(".")[-1] + yield ("%s %s" % \ + (domain_name, component_sn), {}) + + +def check_nsx_resources(item, params, info): + for line in info: + component = line[0] + " " + line[1].split(".")[-1] + if component==item: + domain_name = line[0] + component_name = line[1].split(".")[-1] + component_status = line[2] + if component_name == "hostRebootRequired": + if component_status == "false": + return 0, "Host reboot is not required. " + else: + return 1, "Host needs a reboot" + + if component_status == "GREEN": + return 0, "Component %s is %s" % (component_name, component_status) + elif component_status =="UNKNOWN": + return 3, "Status is unknown" + else: + return 2, "Component %s is %s" % (component_name, component_status) + +check_info['nsx_resources'] = { + 'inventory_function' : inventory_nsx_resources, + 'check_function' : check_nsx_resources, + 'service_description' : '%s', + 'has_perfdata' : False, +} diff --git a/local/share/check_mk/checks/check_srm b/local/share/check_mk/checks/check_srm new file mode 100644 index 0000000..429269a --- /dev/null +++ b/local/share/check_mk/checks/check_srm @@ -0,0 +1,59 @@ +#!/usr/bin/python +# -*- encoding: utf-8; py-indent-offset: 4 -*- +# +------------------------------------------------------------------+ +# | ____ _ _ __ __ _ __ | +# | / ___| |__ ___ ___| | __ | \/ | |/ / | +# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / | +# | | |___| | | | __/ (__| < | | | | . \ | +# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ | +# | | +# | Copyright Mathias Kettner 2018 mk@mathias-kettner.de | +# +------------------------------------------------------------------+ +# +# This file is part of Check_MK. +# The official homepage is at http://mathias-kettner.de/check_mk. +# +# check_mk is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation in version 2. check_mk is distributed +# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with- +# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. See the GNU General Public License for more de- +# tails. You should have received a copy of the GNU General Public +# License along with GNU Make; see the file COPYING. If not, write +# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, +# Boston, MA 02110-1301 USA. + +#<<>> +#LocalConnection com.vmware.cis.vcenterserver https://buc01m01vc01.test:443/sdk Connected +#LocalConnection com.vmware.cis.cs.inventory https://buc01m01vc01.test:443/invsvc/vmomi/sdk Connected +#LocalConnection com.vmware.cis.cs.lookup https://buc01psc01.test:443/lookupservice/sdk Connected +#LocalConnection com.vmware.cis.cs.identity https://buc01psc01.test/sso-adminserver/sdk/vsphere.local Connected +#LocalConnection com.vmware.cis.cs.authorization https://buc01m01vc01.test:443/invsvc/vmomi/sdk Connected +#LocalConnection com.vmware.cis.cs.license https://buc01psc01.test:443/ls/sdk Connected +#RemoteConnection com.vmware.cis.vcenterserver https://buc01m01vc01.test:443/sdk Connected +#RemoteConnection com.vmware.dr.vcDr https://buc01m01vc01.test:443/invsvc/vmomi/sdk Connected +#RemoteConnection com.vmware.cis.cs.lookup https://buc01psc01.test:443/lookupservice/sdk Connected +#RemoteConnection com.vmware.cis.cs.identity https://buc01psc01.test/sso-adminserver/sdk/vsphere.locaConnected + +import datetime + +def inventory_srm_status(info): + for servicename, url, state in info: + yield ("%s" % (servicename), {}) + + +def check_srm_status(item, params, info): + for line in info: + if line[0]==item: + if line[2]=="Connected": + return 0, "OK, %s is %s; %s" % (item,line[2],line[1]) + else: + return 1, "CRIT, %s is %s; %s" % (item,line[2],line[1]) + +check_info['vcenter_srm'] = { + 'inventory_function' : inventory_srm_status, + 'check_function' : check_srm_status, + 'service_description' : '%s', + 'has_perfdata' : False, +}