Module: check_mk
Branch: master
Commit: 8fb1f020d6ff80c1a65c9474e6aef85572647f2c
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8fb1f020d6ff80…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Tue Jan 10 11:39:58 2017 +0100
Fetched livestatus from downstream.
Change-Id: If8f45bed3e75c87bde9c1c6fd9f531c1db38bd69
---
livestatus/src/DownCommColumn.cc | 2 +-
livestatus/src/DowntimeOrComment.cc | 16 +++++-------
livestatus/src/DowntimeOrComment.h | 2 +-
livestatus/src/OffsetBoolColumn.cc | 33 +++++++++++++++++++++++++
livestatus/src/OffsetBoolColumn.h | 49 +++++++++++++++++++++++++++++++++++++
livestatus/src/TableComments.cc | 3 ++-
livestatus/src/TableDowntimes.cc | 3 ++-
7 files changed, 94 insertions(+), 14 deletions(-)
diff --git a/livestatus/src/DownCommColumn.cc b/livestatus/src/DownCommColumn.cc
index 36fe24c..2b6fd30 100644
--- a/livestatus/src/DownCommColumn.cc
+++ b/livestatus/src/DownCommColumn.cc
@@ -63,7 +63,7 @@ bool DownCommColumn::match(DowntimeOrComment *dt, void *data) {
// TableDownComm always enumerates dowtimes/comments for both hosts and
// services, regardless of what we are interested in. So we have to skip the
// ones which have the wrong kind.
- if (_is_service != (dt->_is_service != 0)) {
+ if (_is_service != dt->_is_service) {
return false;
}
diff --git a/livestatus/src/DowntimeOrComment.cc b/livestatus/src/DowntimeOrComment.cc
index 014c9c4..3dee1a7 100644
--- a/livestatus/src/DowntimeOrComment.cc
+++ b/livestatus/src/DowntimeOrComment.cc
@@ -27,19 +27,15 @@
DowntimeOrComment::DowntimeOrComment(nebstruct_downtime_struct *dt,
unsigned long id)
: _type(dt->downtime_type)
+ , _is_service(dt->service_description != nullptr)
+ , _host(find_host(dt->host_name))
+ , _service(_is_service
+ ? find_service(dt->host_name, dt->service_description)
+ : nullptr)
, _entry_time(dt->entry_time)
, _author_name(dt->author_name)
, _comment(dt->comment_data)
- , _id(id) {
- _host = find_host(dt->host_name);
- if (dt->service_description != nullptr) {
- _service = find_service(dt->host_name, dt->service_description);
- _is_service = 1;
- } else {
- _service = nullptr;
- _is_service = 0;
- }
-}
+ , _id(id) {}
DowntimeOrComment::~DowntimeOrComment() = default;
diff --git a/livestatus/src/DowntimeOrComment.h b/livestatus/src/DowntimeOrComment.h
index 3d9c44a..70bf6bb 100644
--- a/livestatus/src/DowntimeOrComment.h
+++ b/livestatus/src/DowntimeOrComment.h
@@ -82,13 +82,13 @@
class DowntimeOrComment {
public:
int _type;
+ bool _is_service;
host *_host;
service *_service;
time_t _entry_time;
std::string _author_name;
std::string _comment;
unsigned long _id;
- int _is_service;
DowntimeOrComment(nebstruct_downtime_struct *dt, unsigned long id);
virtual ~DowntimeOrComment();
diff --git a/livestatus/src/OffsetBoolColumn.cc b/livestatus/src/OffsetBoolColumn.cc
new file mode 100644
index 0000000..578f584
--- /dev/null
+++ b/livestatus/src/OffsetBoolColumn.cc
@@ -0,0 +1,33 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | Copyright Mathias Kettner 2014 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.
+
+#include "OffsetBoolColumn.h"
+#include "Column.h"
+
+int32_t OffsetBoolColumn::getValue(void *row, contact * /* auth_user */) {
+ if (auto p = rowData<void>(row)) {
+ return *offset_cast<bool>(p, _offset) ? 1 : 0;
+ }
+ return 0;
+}
diff --git a/livestatus/src/OffsetBoolColumn.h b/livestatus/src/OffsetBoolColumn.h
new file mode 100644
index 0000000..929b923
--- /dev/null
+++ b/livestatus/src/OffsetBoolColumn.h
@@ -0,0 +1,49 @@
+// +------------------------------------------------------------------+
+// | ____ _ _ __ __ _ __ |
+// | / ___| |__ ___ ___| | __ | \/ | |/ / |
+// | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+// | | |___| | | | __/ (__| < | | | | . \ |
+// | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+// | |
+// | Copyright Mathias Kettner 2014 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.
+
+#ifndef OffsetBoolColumn_h
+#define OffsetBoolColumn_h
+
+#include "config.h" // IWYU pragma: keep
+#include <sys/types.h>
+#include <string>
+#include "OffsetIntColumn.h"
+
+#ifdef CMC
+#include "cmc.h"
+#else
+#include "nagios.h"
+#endif
+
+class OffsetBoolColumn : public OffsetIntColumn {
+public:
+ OffsetBoolColumn(const std::string& name, const std::string& description,
+ int offset, int indirect_offset, int extra_offset,
+ int extra_extra_offset)
+ : OffsetIntColumn(name, description, offset, indirect_offset,
+ extra_offset, extra_extra_offset) {}
+ int32_t getValue(void* row, contact* auth_user) override;
+};
+
+#endif // OffsetBoolColumn_h
diff --git a/livestatus/src/TableComments.cc b/livestatus/src/TableComments.cc
index fbee58d..c82a687 100644
--- a/livestatus/src/TableComments.cc
+++ b/livestatus/src/TableComments.cc
@@ -29,6 +29,7 @@
#include "DowntimeOrComment.h"
#include "DowntimesOrComments.h" // IWYU pragma: keep
#include "MonitoringCore.h"
+#include "OffsetBoolColumn.h"
#include "OffsetIntColumn.h"
#include "OffsetSStringColumn.h"
#include "OffsetTimeColumn.h"
@@ -61,7 +62,7 @@ TableComments::TableComments(const DowntimesOrComments
&downtimes_holder,
addColumn(make_unique<OffsetIntColumn>(
"type", "The type of the comment: 1 is host, 2 is service",
DANGEROUS_OFFSETOF(Comment, _type), -1, -1, -1));
- addColumn(make_unique<OffsetIntColumn>(
+ addColumn(make_unique<OffsetBoolColumn>(
"is_service",
"0, if this entry is for a host, 1 if it is for a service",
DANGEROUS_OFFSETOF(Comment, _is_service), -1, -1, -1));
diff --git a/livestatus/src/TableDowntimes.cc b/livestatus/src/TableDowntimes.cc
index 9b2fd64..11628d3 100644
--- a/livestatus/src/TableDowntimes.cc
+++ b/livestatus/src/TableDowntimes.cc
@@ -29,6 +29,7 @@
#include "DowntimeOrComment.h"
#include "DowntimesOrComments.h" // IWYU pragma: keep
#include "MonitoringCore.h"
+#include "OffsetBoolColumn.h"
#include "OffsetIntColumn.h"
#include "OffsetSStringColumn.h"
#include "OffsetTimeColumn.h"
@@ -62,7 +63,7 @@ TableDowntimes::TableDowntimes(const DowntimesOrComments
&downtimes_holder,
"type",
"The type of the downtime: 0 if it is active, 1 if it is pending",
DANGEROUS_OFFSETOF(Downtime, _type), -1, -1, -1));
- addColumn(make_unique<OffsetIntColumn>(
+ addColumn(make_unique<OffsetBoolColumn>(
"is_service",
"0, if this entry is for a host, 1 if it is for a service",
DANGEROUS_OFFSETOF(Downtime, _is_service), -1, -1, -1));