Cleanup config.nodes_of
[check_mk.git] / checks / aws_elbv2_target_groups
blob0f5867886ce93e91f36573b63d6f1953c357dd36
1 #!/usr/bin/python
2 # -*- encoding: utf-8; py-indent-offset: 4 -*-
3 # +------------------------------------------------------------------+
4 # | ____ _ _ __ __ _ __ |
5 # | / ___| |__ ___ ___| | __ | \/ | |/ / |
6 # | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
7 # | | |___| | | | __/ (__| < | | | | . \ |
8 # | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
9 # | |
10 # | Copyright Mathias Kettner 2019 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 #'TargetGroups': [
28 # {
29 # 'TargetGroupArn': 'string',
30 # 'TargetGroupName': 'string',
31 # 'Protocol': 'HTTP'|'HTTPS'|'TCP'|'TLS',
32 # 'Port': 123,
33 # 'VpcId': 'string',
34 # 'HealthCheckProtocol': 'HTTP'|'HTTPS'|'TCP'|'TLS',
35 # 'HealthCheckPort': 'string',
36 # 'HealthCheckEnabled': True|False,
37 # 'HealthCheckIntervalSeconds': 123,
38 # 'HealthCheckTimeoutSeconds': 123,
39 # 'HealthyThresholdCount': 123,
40 # 'UnhealthyThresholdCount': 123,
41 # 'HealthCheckPath': 'string',
42 # 'Matcher': {
43 # 'HttpCode': 'string'
44 # },
45 # 'LoadBalancerArns': [
46 # 'string',
47 # ],
48 # 'TargetType': 'instance'|'ip'|'lambda'
49 # 'TargetHealth': {
50 # 'State': 'initial'|'healthy'|'unhealthy'|'unused'|'draining'|'unavailable',
51 # 'Reason': 'Elb.RegistrationInProgress'|'Elb.InitialHealthChecking'|'Target.ResponseCodeMismatch'|
52 # 'Target.Timeout'|'Target.FailedHealthChecks'|'Target.NotRegistered'|'Target.NotInUse'|
53 # 'Target.DeregistrationInProgress'|'Target.InvalidState'|'Target.IpUnusable'|
54 # 'Target.HealthCheckDisabled'|'Elb.InternalError',
55 # 'Description': 'string'
56 # },
57 # },
60 def parse_aws_elbv2_target_groups(info):
61 application_target_groups, network_target_groups = [], []
62 for load_balancer_type, target_groups in parse_aws(info):
63 if load_balancer_type == 'application':
64 application_target_groups.extend(target_groups)
65 elif load_balancer_type == 'network':
66 network_target_groups.extend(target_groups)
67 return application_target_groups, network_target_groups
70 def check_aws_elbv2_target_groups(item, params, target_groups):
71 target_groups_by_state = {}
72 for target_group in target_groups:
73 target_groups_by_state.setdefault(
74 target_group.get('TargetHealth', {}).get('State', 'unknown'), []).append(target_group)
76 for state_readable, groups in target_groups_by_state.iteritems():
77 if state_readable in ['initial', 'healthy', 'unused', 'draining', 'unavailable']:
78 state = 0
79 elif state_readable in ['unhealthy']:
80 state = 2
81 else:
82 state = 3
83 yield state, '%s (%s)' % (state_readable, len(groups))
86 def inventory_aws_application_elb_target_groups(parsed):
87 application_target_groups, _network_target_groups = parsed
88 if application_target_groups:
89 return [(None, {})]
92 def check_aws_application_elb_target_groups(item, params, parsed):
93 application_target_groups, _network_target_groups = parsed
94 return check_aws_elbv2_target_groups(item, params, application_target_groups)
97 check_info['aws_elbv2_target_groups'] = {
98 'parse_function': parse_aws_elbv2_target_groups,
99 'inventory_function': inventory_aws_application_elb_target_groups,
100 'check_function': check_aws_application_elb_target_groups,
101 'service_description': 'AWS/ApplicationELB Target Groups',
102 'includes': ['aws.include'],
106 def inventory_aws_network_elb_target_groups(parsed):
107 _application_target_groups, network_target_groups = parsed
108 if network_target_groups:
109 return [(None, {})]
112 def check_aws_network_elb_target_groups(item, params, parsed):
113 _application_target_groups, network_target_groups = parsed
114 return check_aws_elbv2_target_groups(item, params, network_target_groups)
117 check_info['aws_elbv2_target_groups.network'] = {
118 'inventory_function': inventory_aws_network_elb_target_groups,
119 'check_function': check_aws_network_elb_target_groups,
120 'service_description': 'AWS/NetworkELB Target Groups',
121 'includes': ['aws.include'],