Refactoring: Changed all check parameters starting with an 'o' to the new rulespec...
[check_mk.git] / checks / salesforce_instances
blobf688be292dfc25350ed59105772dea3cc0a3f8b0
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 # +------------------------------------------------------------------+
13 # This file is part of Check_MK.
14 # The official homepage is at http://mathias-kettner.de/check_mk.
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.
28 def parse_salesforce(info):
29 import json
31 pre_parsed = []
32 for line in info:
33 pre_parsed.append(json.loads(" ".join(line)))
35 parsed = {}
36 for entry in pre_parsed:
37 if entry.get("key"):
38 parsed.setdefault(entry.get("key"), entry)
39 return parsed
42 def inventory_salesforce_instances(parsed):
43 for instance, attrs in parsed.iteritems():
44 if attrs.get("isActive"):
45 yield instance, {}
48 def check_salesforce_instances(item, params, parsed):
49 map_states = {
50 "OK": (0, "OK"),
51 "MAJOR_INCIDENT_CORE": (2, "major incident core"),
52 "MINOR_INCIDENT_CORE": (1, "minor incident core"),
53 "MAINTENANCE_CORE": (0, "maintenance core"),
54 "INFORMATIONAL_CORE": (0, "informational core"),
55 "MAJOR_INCIDENT_NONCORE": (2, "major incident noncore"),
56 "MINOR_INCIDENT_NONCORE": (1, "minor incident noncore"),
57 "MAINTENANCE_NONCORE": (0, "maintenance noncore"),
58 "INFORMATIONAL_NONCORE": (0, "informational noncore"),
61 if item in parsed:
62 data = parsed[item]
63 status = data.get("status")
64 state, state_readable = map_states.get(status, (3, "unknown[%s]" % status))
65 yield state, "Status: %s" % state_readable
67 for key, title in [
68 ("environment", "Environment"),
69 ("releaseNumber", "Release Number"),
70 ("releaseVersion", "Release Version"),
72 if data.get(key):
73 yield 0, "%s: %s" % (title, data[key])
76 check_info['salesforce_instances'] = {
77 'parse_function': parse_salesforce,
78 'inventory_function': inventory_salesforce_instances,
79 'check_function': check_salesforce_instances,
80 'service_description': 'Salesforce Instance %s',