Module: check_mk
Branch: master
Commit: 8c8d530347c112505ca33c747a71e74bbf2f2275
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8c8d530347c112…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Feb 1 15:00:29 2019 +0100
aws_ec2_security_groups: New check which monitors AWS/EC2 security groups
Change-Id: I4587c6634086ec9dee164196b3b6ea675f4ba3ad
---
agents/special/agent_aws | 31 +++++++++++++++++++++++
checkman/aws_ec2_security_groups | 16 ++++++++++++
checks/aws_ec2_security_groups | 54 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+)
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index 0bc1ccf..a1fedff 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -442,6 +442,34 @@ class EC2Summary(AWSSectionGeneric):
return [AWSSectionResult("", [computed_content.content])]
+class EC2SecurityGroups(AWSSectionGeneric):
+ @property
+ def name(self):
+ return "ec2_security_groups"
+
+ @property
+ def interval(self):
+ return 300
+
+ def _get_colleague_contents(self):
+ colleague = self._received_results.get('ec2_summary')
+ if colleague and colleague.content:
+ return AWSColleagueContents(colleague.content, colleague.cache_timestamp)
+ return AWSColleagueContents({}, 0)
+
+ def _fetch_raw_content(self, colleague_contents):
+ return colleague_contents.content
+
+ def _compute_content(self, raw_content, colleague_contents):
+ return AWSComputedContent(raw_content.content, raw_content.cache_timestamp)
+
+ def _create_results(self, computed_content):
+ return [
+ AWSSectionResult(piggyback_hostname, rows.get('SecurityGroups', []))
+ for piggyback_hostname, rows in computed_content.content.iteritems()
+ ]
+
+
class EC2(AWSSectionCloudwatch):
@property
def name(self):
@@ -1179,12 +1207,14 @@ class AWSSectionsGeneric(AWSSections):
#---sections--------------------------------------------------------
elb_health = ELBHealth(elb_client, hostname, region)
+ ec2_security_groups = EC2SecurityGroups(None, hostname, region)
ec2 = EC2(cloudwatch_client, hostname, region)
ebs = EBS(cloudwatch_client, hostname, region)
elb = ELB(cloudwatch_client, hostname, region)
s3 = S3(cloudwatch_client, hostname, region)
#---register sections to distributors-------------------------------
+ ec2_summary_distributor.add(ec2_security_groups)
ec2_summary_distributor.add(ec2)
ec2_summary_distributor.add(ebs_summary)
ec2_summary_distributor.add(ebs)
@@ -1212,6 +1242,7 @@ class AWSSectionsGeneric(AWSSections):
# |-- elb
if 'ec2' in services:
self._sections.append(ec2_summary)
+ self._sections.append(ec2_security_groups)
self._sections.append(ec2)
if 'ebs' in services:
diff --git a/checkman/aws_ec2_security_groups b/checkman/aws_ec2_security_groups
new file mode 100644
index 0000000..0c4f757
--- /dev/null
+++ b/checkman/aws_ec2_security_groups
@@ -0,0 +1,16 @@
+title: AWS EC2 Security Groups
+agents: aws
+catalog: cloud/aws
+license: GPL
+distribution: check_mk
+description:
+ This check monitors the security groups attached to AWS EC2
+ instances.
+ To make this check work you have to configure the related
+ special agent {Amazon Web Services (AWS)}.
+
+ During discovery the security groups are remembered and if
+ one changes the check state will be CRIT.
+
+inventory:
+ One service is created.
diff --git a/checks/aws_ec2_security_groups b/checks/aws_ec2_security_groups
new file mode 100644
index 0000000..81d4519
--- /dev/null
+++ b/checks/aws_ec2_security_groups
@@ -0,0 +1,54 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2018 mk(a)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 inventory_aws_ec2_security_groups(parsed):
+ if parsed:
+ return [(None, "%r" % [group['GroupId'] for group in parsed])]
+
+
+def check_aws_ec2_security_groups(item, params, parsed):
+ for group in parsed:
+ state = 0
+ descr = group.get('Description')
+ if descr:
+ prefix = "[%s] " % descr
+ else:
+ prefix = ""
+ infotext = "%s%s: %s" % (prefix, group['GroupName'], group['GroupId'])
+ if group['GroupId'] not in params:
+ infotext += " (has changed)"
+ state = 2
+ yield state, infotext
+
+
+check_info['aws_ec2_security_groups'] = {
+ 'parse_function': parse_aws,
+ 'inventory_function': inventory_aws_ec2_security_groups,
+ 'check_function': check_aws_ec2_security_groups,
+ 'service_description': 'AWS/EC2 Security Groups',
+ 'includes': ['aws.include'],
+}
Module: check_mk
Branch: master
Commit: c9e0d02194a0ea21e01e58e8ade450b722577c30
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c9e0d02194a0ea…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 30 08:54:54 2019 +0100
Refactored host attributes to plugin registry
* Legacy plugin registration works for the common use cases.
Using declare_host_attribute() works as in previous versions.
The attribute classes have been replaced by factories that
create classes for the attributes on demand. This works for
the commonly used attribute types like ValueSpecAttribute,
NagiosTextAttribute and so on.
* The attribute declarations that used subclassing have already
been refactored. The others will be refactored in a future
commit.
* The host attributes registration and access to host attributes
is now exclusively done via host_attribute_registry.
CMK-1588
Change-Id: Ie7ff326797f0cf3685ca8102ce2263e3d1863840
---
cmk/gui/plugins/wato/__init__.py | 17 +-
cmk/gui/plugins/wato/builtin_attributes.py | 347 +++++----
cmk/gui/plugins/wato/utils/__init__.py | 15 +-
cmk/gui/plugins/webapi/utils.py | 6 +-
cmk/gui/wato/__init__.py | 2 -
cmk/gui/wato/pages/bulk_edit.py | 5 +-
cmk/gui/wato/pages/folders.py | 6 +-
cmk/gui/watolib/__init__.py | 3 -
cmk/gui/watolib/host_attributes.py | 847 ++++++++++++---------
cmk/gui/watolib/hosts_and_folders.py | 11 +-
tests/unit/cmk/gui/watolib/test_host_attributes.py | 77 +-
11 files changed, 755 insertions(+), 581 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=c9e0d02194…
Module: check_mk
Branch: master
Commit: 2dccf77234dd0adad58e7f1d268e37511cdb150d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2dccf77234dd0a…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Jan 29 17:33:07 2019 +0100
Cleaned up host attribute topic handling
* Topics are now represented by a dedicated class which
has an internal identifier, title and sort index.
* The previous implementation only had a title attribute
which made it dificult to handle localization and sorting
of the topics.
* Host attributes now directly hold a reference to their
host attribute topic object instead of relying on a
collection structure (_host_attributes)
More to come...
CMK-1588
Change-Id: I1952b6dc3e860e14915cc8b5bb37996027b1c58d
---
cmk/gui/plugins/wato/utils/__init__.py | 19 +--
cmk/gui/watolib/host_attributes.py | 182 +++++++++++++++++++--
tests/unit/cmk/gui/watolib/test_host_attributes.py | 93 +++++++++--
tests/unit/cmk/gui/watolib/test_watolib.py | 71 --------
4 files changed, 244 insertions(+), 121 deletions(-)
Diff: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commitdiff;h=2dccf77234…
Module: check_mk
Branch: master
Commit: 023b07e33f8c60f058f28960b72b3b0f335870bd
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=023b07e33f8c60…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 30 20:14:17 2019 +0100
Cleaned up initialization of config based host attributes
Instead of ad-hoc update or during legacy plugin loading the
config based host attributes (tag attributes and custom attributes)
are now updated automatically by a post config load hook.
CMK-1588
Change-Id: I01267967842156582fe4c2211201c3a1c97f3900
---
cmk/gui/wato/pages/host_tags.py | 3 ---
cmk/gui/watolib/__init__.py | 1 -
cmk/gui/watolib/host_attributes.py | 4 ++++
3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/cmk/gui/wato/pages/host_tags.py b/cmk/gui/wato/pages/host_tags.py
index 603732b..2a7c995 100644
--- a/cmk/gui/wato/pages/host_tags.py
+++ b/cmk/gui/wato/pages/host_tags.py
@@ -44,7 +44,6 @@ from cmk.gui.valuespec import (
)
from cmk.gui.watolib.host_tags import is_builtin_aux_tag
-from cmk.gui.watolib.host_attributes import update_config_based_host_attributes
from cmk.gui.plugins.wato.utils.main_menu import (
MainMenu,
@@ -487,7 +486,6 @@ class ModeEditHosttagGroup(ModeEditHosttagConfiguration):
# Make sure, that all tags are active (also manual ones from main.mk)
config.load_config()
- update_config_based_host_attributes()
add_change("edit-hosttags", _("Created new host tag group '%s'") % changed_tag_group.id)
return "hosttags", _("Created new host tag group '%s'") % changed_tag_group.title
else:
@@ -527,7 +525,6 @@ class ModeEditHosttagGroup(ModeEditHosttagConfiguration):
if message:
changed_hosttags_config.save()
config.load_config()
- update_config_based_host_attributes()
add_change("edit-hosttags",
_("Edited host tag group %s (%s)") % (message, self._get_taggroup_id()))
return "hosttags", message != True and message or None
diff --git a/cmk/gui/watolib/__init__.py b/cmk/gui/watolib/__init__.py
index 200ac16..399d214 100644
--- a/cmk/gui/watolib/__init__.py
+++ b/cmk/gui/watolib/__init__.py
@@ -318,7 +318,6 @@ def init_wato_datastructures(with_wato_lock=False):
cmk.gui.watolib.git.prepare_git_commit()
cmk.gui.watolib.sidebar_reload.reset()
- cmk.gui.watolib.host_attributes.update_config_based_host_attributes()
if os.path.exists(ConfigDomainCACertificates.trusted_cas_file) and\
not _need_to_create_sample_config():
diff --git a/cmk/gui/watolib/host_attributes.py b/cmk/gui/watolib/host_attributes.py
index e80aca6..5eb8e1b 100644
--- a/cmk/gui/watolib/host_attributes.py
+++ b/cmk/gui/watolib/host_attributes.py
@@ -537,6 +537,10 @@ def update_config_based_host_attributes():
Folder.invalidate_caches()
+# Make the config module initialize the host attributes after loading the config
+config.register_post_config_load_hook(update_config_based_host_attributes)
+
+
def _clear_config_based_host_attributes():
for attr in host_attribute_registry.attributes():
if attr.from_config():
Module: check_mk
Branch: master
Commit: c223e3725b0dbd22042059864b9bae85ce18b37f
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c223e3725b0dbd…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Jan 30 20:50:10 2019 +0100
Fixed tag attributes being put into the wrong topics
The IP address family tag was not put into the same
foldable container when using a localized GUI.
CMK-1588
Change-Id: I7a19936b79d5d748ca0278cdc01c27dd9c805b62
---
cmk/gui/watolib/host_attributes.py | 45 +++++++++++++++++++++++++++-----------
1 file changed, 32 insertions(+), 13 deletions(-)
diff --git a/cmk/gui/watolib/host_attributes.py b/cmk/gui/watolib/host_attributes.py
index 5eb8e1b..a536a20 100644
--- a/cmk/gui/watolib/host_attributes.py
+++ b/cmk/gui/watolib/host_attributes.py
@@ -577,7 +577,8 @@ def _declare_host_tag_attributes():
editable=attr_editable,
depends_on_tags=depends_on_tags,
depends_on_roles=depends_on_roles,
- topic=topic,
+ # TODO: We need to adapt the tag data structure to contain topic IDs
+ topic=_transform_attribute_topic_title_to_id(topic),
from_config=True,
)
@@ -614,24 +615,42 @@ def transform_pre_16_host_topics(custom_attributes):
This lead to issues with localized topics. We now have internal IDs for
all the topics and try to convert the values here to the new format.
- At least for unlocalized topics the conversion works. Localized topics
- are put into the "Custom attributes" topic once. Users will have to
- re-configure the topic, sorry :-/."""
- topics = [a_class() for a_class in host_attribute_topic_registry.values()]
+ We translate the titles which have been distributed with Check_MK to their
+ internal topic ID. No action should be needed. Custom topics or topics of
+ other languages are not translated. The attributes are put into the
+ "Custom attributes" topic once. Users will have to re-configure the topic,
+ sorry :-/."""
for custom_attr in custom_attributes:
- found = False
- for topic in topics:
- if custom_attr["topic"] == topic.title:
- custom_attr["topic"] = topic.ident
- found = True
- break
+ if custom_attr["topic"] in host_attribute_topic_registry:
+ continue
- if not found:
- custom_attr["topic"] = "custom_attributes"
+ custom_attr["topic"] = _transform_attribute_topic_title_to_id(custom_attr["topic"])
return custom_attributes
+def _transform_attribute_topic_title_to_id(topic_title):
+ _topic_title_to_id_map = {
+ u"Basic settings": "basic",
+ u"Address": "address",
+ u"Data sources": "data_sources",
+ u"Management Board": "management_board",
+ u"Network Scan": "network_scan",
+ u"Custom attributes": "custom_attributes",
+ u"Grundeinstellungen": "basic",
+ u"Adresse": "address",
+ u"Datenquellen": "data_sources",
+ u"Management-Board": "management_board",
+ u"Netzwerk-Scan": "network_scan",
+ u"Eigene Attribute": "custom_attributes",
+ }
+
+ try:
+ return _topic_title_to_id_map[topic_title]
+ except KeyError:
+ return "custom_attributes"
+
+
def host_attribute(name):
return host_attribute_registry[name]()