-
Notifications
You must be signed in to change notification settings - Fork 433
/
aws_ebs_summary
93 lines (77 loc) · 3.99 KB
/
aws_ebs_summary
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (C) 2019 tribe29 GmbH - License: GNU General Public License v2
# This file is part of Checkmk (https://checkmk.com). It is subject to the terms and
# conditions defined in the file COPYING, which is part of this source code package.
# NOTE: Careful when replacing the *-import below with a more specific import. This can cause
# problems because it might remove variables from the check-context which are necessary for
# resolving legacy discovery results such as [("SUMMARY", "diskstat_default_levels")]. Furthermore,
# it might also remove variables needed for accessing discovery rulesets.
from cmk.base.check_legacy_includes.aws import * # pylint: disable=wildcard-import,unused-wildcard-import
AWSEBSStorageTypes = {
"gp2": "General Purpose SSD",
"io1": "Provisioned IOPS SSD",
"st1": "Throughput Optimized HDD",
"sc1": "Cold HDD",
}
def parse_aws_summary(info):
parsed = {}
for row in parse_aws(info):
inst = parsed.setdefault(row['VolumeId'], row)
type_ = row['VolumeType']
inst.setdefault('type_readable', AWSEBSStorageTypes.get(type_, "unknown[%s]" % type_))
return parsed
# .--summary-------------------------------------------------------------.
# | |
# | ___ _ _ _ __ ___ _ __ ___ __ _ _ __ _ _ |
# | / __| | | | '_ ` _ \| '_ ` _ \ / _` | '__| | | | |
# | \__ \ |_| | | | | | | | | | | | (_| | | | |_| | |
# | |___/\__,_|_| |_| |_|_| |_| |_|\__,_|_| \__, | |
# | |___/ |
# '----------------------------------------------------------------------'
def check_aws_ebs_summary(item, params, parsed):
stores_by_state = {}
stores_by_type = {}
long_output = []
for volume_id, row in parsed.items():
stores_by_state.setdefault(row['State'], []).append(volume_id)
stores_by_type.setdefault(row['VolumeType'], []).append(volume_id)
long_output.append(
"Volume: %s, Status: %s, Type: %s, Encrypted: %s, Creation time: %s"\
% (volume_id, row['State'], row['VolumeType'], row['Encrypted'], row['CreateTime'])
)
yield 0, 'Stores: %s' % len(parsed)
for state, stores in stores_by_state.items():
yield 0, '%s: %s' % (state, len(stores))
for type_, stores in stores_by_type.items():
yield 0, '%s: %s' % (AWSEBSStorageTypes.get(type_, "unknown[%s]" % type_), len(stores))
if long_output:
yield 0, '\n%s' % '\n'.join(long_output)
check_info['aws_ebs_summary'] = {
'parse_function': parse_aws_summary,
'inventory_function': discover_single,
'check_function': check_aws_ebs_summary,
'service_description': 'AWS/EBS Summary',
}
#.
# .--health--------------------------------------------------------------.
# | _ _ _ _ |
# | | |__ ___ __ _| | |_| |__ |
# | | '_ \ / _ \/ _` | | __| '_ \ |
# | | | | | __/ (_| | | |_| | | | |
# | |_| |_|\___|\__,_|_|\__|_| |_| |
# | |
# '----------------------------------------------------------------------'
@get_parsed_item_data
def check_aws_ebs_summary_health(item, params, ebs_data):
metrics = ebs_data['VolumeStatus']
ebs_status = metrics["Status"]
yield 0 if ebs_status.lower() == 'ok' else 2, "Status: %s" % ebs_status
for row in metrics['Details']:
yield 0, "%s: %s" % (row['Name'], row['Status'])
check_info['aws_ebs_summary.health'] = {
'inventory_function': lambda p:\
inventory_aws_generic(p, ['VolumeStatus']),
'check_function': check_aws_ebs_summary_health,
'service_description': 'AWS/EBS Health %s',
}