Module: check_mk
Branch: master
Commit: 5d4c69a6fba0bed7655e37cafb6b0eb4c02afb73
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5d4c69a6fba0be…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue May 15 08:38:56 2018 +0200
Added new downtimes_with_extra_info column to hosts/services.
This new column contains all information about a given downtime.
Change-Id: I1dad120e724aa3277c66bceb0d91732845eb7ad6
---
livestatus/src/DowntimeColumn.cc | 37 ++++++++++++++++++++++++++++++-------
livestatus/src/DowntimeColumn.h | 6 ++++--
livestatus/src/MonitoringCore.h | 8 ++++++++
livestatus/src/TableHosts.cc | 13 ++++++++++---
livestatus/src/TableServices.cc | 11 +++++++++--
livestatus/src/module.cc | 14 +++++++++++++-
6 files changed, 74 insertions(+), 15 deletions(-)
diff --git a/livestatus/src/DowntimeColumn.cc b/livestatus/src/DowntimeColumn.cc
index 7f75bc0..41bef80 100644
--- a/livestatus/src/DowntimeColumn.cc
+++ b/livestatus/src/DowntimeColumn.cc
@@ -23,6 +23,8 @@
// Boston, MA 02110-1301 USA.
#include "DowntimeColumn.h"
+#include <cstdint>
+#include <type_traits>
#include "MonitoringCore.h"
#include "Renderer.h"
#include "Row.h"
@@ -36,13 +38,34 @@ void DowntimeColumn::output(Row row, RowRenderer &r,
std::chrono::seconds /*timezone_offset*/) const {
ListRenderer l(r);
for (const auto &downtime : downtimes_for_row(row)) {
- if (_with_info) {
- SublistRenderer s(l);
- s.output(downtime._id);
- s.output(downtime._author);
- s.output(downtime._comment);
- } else {
- l.output(downtime._id);
+ switch (_with_info) {
+ case info::none:
+ l.output(downtime._id);
+ break;
+ case info::medium: {
+ SublistRenderer s(l);
+ s.output(downtime._id);
+ s.output(downtime._author);
+ s.output(downtime._comment);
+ break;
+ }
+ case info::full: {
+ SublistRenderer s(l);
+ s.output(downtime._id);
+ s.output(downtime._author);
+ s.output(downtime._comment);
+ s.output(downtime._origin_is_rule);
+ s.output(downtime._entry_time);
+ s.output(downtime._start_time);
+ s.output(downtime._end_time);
+ s.output(downtime._fixed);
+ s.output(std::chrono::duration_cast<std::chrono::seconds>(
+ downtime._duration)
+ .count());
+ s.output(downtime._recurring);
+ s.output(downtime._pending);
+ break;
+ }
}
}
}
diff --git a/livestatus/src/DowntimeColumn.h b/livestatus/src/DowntimeColumn.h
index 553a90b..0ec04f7 100644
--- a/livestatus/src/DowntimeColumn.h
+++ b/livestatus/src/DowntimeColumn.h
@@ -38,10 +38,12 @@ class RowRenderer;
class DowntimeColumn : public ListColumn {
public:
+ enum class info { none, medium, full };
+
DowntimeColumn(const std::string &name, const std::string &description,
int indirect_offset, int extra_offset,
int extra_extra_offset, int offset, MonitoringCore *mc,
- bool is_service, bool with_info)
+ bool is_service, info with_info)
: ListColumn(name, description, indirect_offset, extra_offset,
extra_extra_offset, offset)
, _mc(mc)
@@ -58,7 +60,7 @@ public:
private:
MonitoringCore *_mc;
bool _is_service;
- bool _with_info;
+ info _with_info;
std::vector<DowntimeData> downtimes_for_row(Row row) const;
};
diff --git a/livestatus/src/MonitoringCore.h b/livestatus/src/MonitoringCore.h
index 88666bb..09f0892 100644
--- a/livestatus/src/MonitoringCore.h
+++ b/livestatus/src/MonitoringCore.h
@@ -43,6 +43,14 @@ struct DowntimeData {
unsigned long _id;
std::string _author;
std::string _comment;
+ bool _origin_is_rule;
+ std::chrono::system_clock::time_point _entry_time;
+ std::chrono::system_clock::time_point _start_time;
+ std::chrono::system_clock::time_point _end_time;
+ bool _fixed;
+ std::chrono::seconds _duration;
+ int32_t _recurring;
+ bool _pending;
};
struct CommentData {
diff --git a/livestatus/src/TableHosts.cc b/livestatus/src/TableHosts.cc
index 4e62876..fb5c515 100644
--- a/livestatus/src/TableHosts.cc
+++ b/livestatus/src/TableHosts.cc
@@ -456,11 +456,18 @@ void TableHosts::addColumns(Table *table, const std::string
&prefix,
table->addColumn(std::make_unique<DowntimeColumn>(
prefix + "downtimes",
"A list of the ids of all scheduled downtimes of this host",
- indirect_offset, extra_offset, -1, 0, table->core(), false, false));
+ indirect_offset, extra_offset, -1, 0, table->core(), false,
+ DowntimeColumn::info::none));
table->addColumn(std::make_unique<DowntimeColumn>(
prefix + "downtimes_with_info",
- "A list of the all scheduled downtimes of the host with id, author and
comment",
- indirect_offset, extra_offset, -1, 0, table->core(), false, true));
+ "A list of the scheduled downtimes of the host with id, author and
comment",
+ indirect_offset, extra_offset, -1, 0, table->core(), false,
+ DowntimeColumn::info::medium));
+ table->addColumn(std::make_unique<DowntimeColumn>(
+ prefix + "downtimes_with_extra_info",
+ "A list of the scheduled downtimes of the host with id, author, comment,
origin, entry_time, start_time, end_time, fixed, duration, recurring and
is_pending",
+ indirect_offset, extra_offset, -1, 0, table->core(), false,
+ DowntimeColumn::info::full));
table->addColumn(std::make_unique<CommentColumn>(
prefix + "comments", "A list of the ids of all comments of this
host",
indirect_offset, extra_offset, -1, 0, table->core(), false, false,
diff --git a/livestatus/src/TableServices.cc b/livestatus/src/TableServices.cc
index 8d1f0fd..e0e3866 100644
--- a/livestatus/src/TableServices.cc
+++ b/livestatus/src/TableServices.cc
@@ -409,11 +409,18 @@ void TableServices::addColumns(Table *table, const std::string
&prefix,
indirect_offset, -1, -1, 0));
table->addColumn(std::make_unique<DowntimeColumn>(
prefix + "downtimes", "A list of all downtime ids of the
service",
- indirect_offset, -1, -1, 0, table->core(), true, false));
+ indirect_offset, -1, -1, 0, table->core(), true,
+ DowntimeColumn::info::none));
table->addColumn(std::make_unique<DowntimeColumn>(
prefix + "downtimes_with_info",
"A list of all downtimes of the service with id, author and comment",
- indirect_offset, -1, -1, 0, table->core(), true, true));
+ indirect_offset, -1, -1, 0, table->core(), true,
+ DowntimeColumn::info::medium));
+ table->addColumn(std::make_unique<DowntimeColumn>(
+ prefix + "downtimes_with_extra_info",
+ "A list of all downtimes of the service with id, author, comment, origin,
entry_time, start_time, end_time, fixed, duration, recurring and is_pending",
+ indirect_offset, -1, -1, 0, table->core(), true,
+ DowntimeColumn::info::full));
table->addColumn(std::make_unique<CommentColumn>(
prefix + "comments", "A list of all comment ids of the
service",
indirect_offset, -1, -1, 0, table->core(), true, false, false));
diff --git a/livestatus/src/module.cc b/livestatus/src/module.cc
index 9085ad4..6f01b19 100644
--- a/livestatus/src/module.cc
+++ b/livestatus/src/module.cc
@@ -703,7 +703,19 @@ private:
for (const auto &entry : fl_store->_downtimes) {
auto *dt = static_cast<Downtime *>(entry.second.get());
if (dt->_host == h && dt->_service == s) {
- result.push_back({dt->_id, dt->_author_name, dt->_comment});
+ result.push_back({
+ dt->_id,
+ dt->_author_name,
+ dt->_comment,
+ false,
+ std::chrono::system_clock::from_time_t(dt->_entry_time),
+ std::chrono::system_clock::from_time_t(dt->_start_time),
+ std::chrono::system_clock::from_time_t(dt->_end_time),
+ dt->_fixed != 0,
+ std::chrono::seconds(dt->_duration),
+ 0,
+ dt->_type != 0,
+ });
}
}
return result;