Module: check_mk
Branch: master
Commit: 2c88bca4c24beca73df0c4a707ea110f3e2a4c2d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2c88bca4c24bec…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Apr 1 11:21:05 2019 +0200
Add tag columns, part 1.
Not fully functional for the NEB yet...
Change-Id: I9cce22baac9d42170cd1ee233e71ca6eeb7fe117
---
livestatus/src/TableContacts.cc | 15 +++++++++++++++
livestatus/src/TableHosts.cc | 15 +++++++++++++++
livestatus/src/TableServices.cc | 14 ++++++++++++++
livestatus/src/module.cc | 14 +++++++++-----
4 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/livestatus/src/TableContacts.cc b/livestatus/src/TableContacts.cc
index ece5f45..dff96b4 100644
--- a/livestatus/src/TableContacts.cc
+++ b/livestatus/src/TableContacts.cc
@@ -120,6 +120,21 @@ void TableContacts::addColumns(Table *table, const std::string
&prefix,
prefix + "custom_variables", "A dictionary of the custom
variables",
indirect_offset, -1, -1, DANGEROUS_OFFSETOF(contact, custom_variables),
table->core(), AttributeKind::custom_variables));
+
+ table->addColumn(std::make_unique<CustomVarsNamesColumn>(
+ prefix + "tag_names", "A list of all tags of the contact",
+ indirect_offset, -1, -1, DANGEROUS_OFFSETOF(contact, custom_variables),
+ table->core(), AttributeKind::tags));
+ table->addColumn(std::make_unique<CustomVarsValuesColumn>(
+ prefix + "tag_values",
+ "A list of the values of all tags of the contact", indirect_offset,
-1,
+ -1, DANGEROUS_OFFSETOF(contact, custom_variables), table->core(),
+ AttributeKind::tags));
+ table->addColumn(std::make_unique<CustomVarsDictColumn>(
+ prefix + "tags", "A dictionary of the tags", indirect_offset,
-1, -1,
+ DANGEROUS_OFFSETOF(contact, custom_variables), table->core(),
+ AttributeKind::tags));
+
table->addColumn(std::make_unique<AttributeListAsIntColumn>(
prefix + "modified_attributes",
"A bitmask specifying which attributes have been modified",
diff --git a/livestatus/src/TableHosts.cc b/livestatus/src/TableHosts.cc
index d6113c7..a135e24 100644
--- a/livestatus/src/TableHosts.cc
+++ b/livestatus/src/TableHosts.cc
@@ -502,6 +502,21 @@ void TableHosts::addColumns(Table *table, const std::string
&prefix,
DANGEROUS_OFFSETOF(host, custom_variables), table->core(),
AttributeKind::custom_variables));
+ table->addColumn(std::make_unique<CustomVarsNamesColumn>(
+ prefix + "tag_names", "A list of the names of all tags",
+ indirect_offset, extra_offset, -1,
+ DANGEROUS_OFFSETOF(host, custom_variables), table->core(),
+ AttributeKind::tags));
+ table->addColumn(std::make_unique<CustomVarsValuesColumn>(
+ prefix + "tag_values", "A list of the values of the tags",
+ indirect_offset, extra_offset, -1,
+ DANGEROUS_OFFSETOF(host, custom_variables), table->core(),
+ AttributeKind::tags));
+ table->addColumn(std::make_unique<CustomVarsDictColumn>(
+ prefix + "tags", "A dictionary of the tags",
indirect_offset,
+ extra_offset, -1, DANGEROUS_OFFSETOF(host, custom_variables),
+ table->core(), AttributeKind::tags));
+
// Add direct access to the custom macro _FILENAME. In a future version of
// Livestatus this will probably be configurable so access to further custom
// variable can be added, such that those variables are presented like
diff --git a/livestatus/src/TableServices.cc b/livestatus/src/TableServices.cc
index a3da9dc..c7cfd87 100644
--- a/livestatus/src/TableServices.cc
+++ b/livestatus/src/TableServices.cc
@@ -459,6 +459,20 @@ void TableServices::addColumns(Table *table, const std::string
&prefix,
indirect_offset, -1, -1, DANGEROUS_OFFSETOF(service, custom_variables),
table->core(), AttributeKind::custom_variables));
+ table->addColumn(std::make_unique<CustomVarsNamesColumn>(
+ prefix + "tag_names", "A list of the names of all tags of the
service",
+ indirect_offset, -1, -1, DANGEROUS_OFFSETOF(service, custom_variables),
+ table->core(), AttributeKind::tags));
+ table->addColumn(std::make_unique<CustomVarsValuesColumn>(
+ prefix + "tag_values",
+ "A list of the values of all tags of the service", indirect_offset,
-1,
+ -1, DANGEROUS_OFFSETOF(service, custom_variables), table->core(),
+ AttributeKind::tags));
+ table->addColumn(std::make_unique<CustomVarsDictColumn>(
+ prefix + "tags", "A dictionary of the tags", indirect_offset,
-1, -1,
+ DANGEROUS_OFFSETOF(service, custom_variables), table->core(),
+ AttributeKind::tags));
+
table->addColumn(std::make_unique<ServiceGroupsColumn>(
prefix + "groups", "A list of all service groups the service is
in",
indirect_offset, -1, -1, DANGEROUS_OFFSETOF(service, servicegroups_ptr),
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index f4bbc1d..f7189cd 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -706,18 +706,22 @@ public:
Attributes customAttributes(const void *holder,
AttributeKind kind) const override {
+ auto h = *static_cast<const customvariablesmember *const *>(holder);
Attributes attrs;
- for (auto cvm =
- *static_cast<const customvariablesmember *const *>(holder);
- cvm != nullptr; cvm = cvm->next) {
- // TODO(sp) Handle (non-)tag case!
+ for (auto cvm = h; cvm != nullptr; cvm = cvm->next) {
+ bool is_tag = mk::starts_with(cvm->variable_name, "_TAG_");
+ bool part_of_result = false;
switch (kind) {
case AttributeKind::custom_variables:
- attrs.emplace(cvm->variable_name, cvm->variable_value);
+ part_of_result = !is_tag;
break;
case AttributeKind::tags:
+ part_of_result = is_tag;
break;
}
+ if (part_of_result) {
+ attrs.emplace(cvm->variable_name, cvm->variable_value);
+ }
}
return attrs;
}