Refactoring: Changed all check parameters starting with an 'e' to new rulespec regist...
[check_mk.git] / checks / aws.include
blobae9547cce600878e17649b8c6efcde9f260d34a0
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 # +------------------------------------------------------------------+
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.
27 AWSRegions = {
28 "ap-south-1": "Asia Pacific Mumbai",
29 "ap-northeast-3": "Asia Pacific Osaka-Local",
30 "ap-northeast-2": "Asia Pacific Seoul",
31 "ap-southeast-1": "Asia Pacific Singapore",
32 "ap-southeast-2": "Asia Pacific Sydney",
33 "ap-northeast-1": "Asia Pacific Tokyo",
34 "ca-central-1": "Canada Central",
35 "cn-north-1": "China Beijing",
36 "cn-northwest-1": "China Ningxia",
37 "eu-central-1": "EU Frankfurt",
38 "eu-west-1": "EU Ireland",
39 "eu-west-2": "EU London",
40 "eu-west-3": "EU Paris",
41 "eu-north-1": "EU Stockholm",
42 "sa-east-1": "South America Sao Paulo",
43 "us-east-2": "US East Ohio",
44 "us-east-1": "US East N. Virginia",
45 "us-west-1": "US West N. California",
46 "us-west-2": "US West Oregon",
49 factory_settings['aws_cpu_credits'] = {
50 'balance_levels_lower': (10, 5),
54 def parse_aws(info):
55 import json
56 loaded = []
57 for row in info:
58 try:
59 loaded.extend(json.loads(" ".join(row)))
60 except (TypeError, IndexError):
61 pass
62 return loaded
65 def _extract_aws_metrics(expected_metric_names, parsed):
66 values = {}
67 for row in parsed:
68 for expected_metric_name in expected_metric_names:
69 if row['Id'].startswith(expected_metric_name.lower()):
70 try:
71 values.setdefault(expected_metric_name, row['Values'][0])
72 except IndexError:
73 pass
74 break
75 return values
78 def _extract_aws_metrics_by_labels(expected_metric_names, parsed):
79 values_by_labels = {}
80 for row in parsed:
81 row_id = row['Id']
82 row_label = row['Label']
83 row_values = row['Values']
84 for expected_metric_name in expected_metric_names:
85 if not row_id.startswith(expected_metric_name.lower()):
86 continue
88 try:
89 value = row_values[0]
90 except IndexError:
91 continue
92 else:
93 values_by_labels.setdefault(row_label, {})\
94 .setdefault(expected_metric_name, value)
95 return values_by_labels