1 // +------------------------------------------------------------------+
2 // | ____ _ _ __ __ _ __ |
3 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
4 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
5 // | | |___| | | | __/ (__| < | | | | . \ |
6 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
8 // | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
9 // +------------------------------------------------------------------+
11 // This file is part of Check_MK.
12 // The official homepage is at http://mathias-kettner.de/check_mk.
14 // check_mk is free software; you can redistribute it and/or modify it
15 // under the terms of the GNU General Public License as published by
16 // the Free Software Foundation in version 2. check_mk is distributed
17 // in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
18 // out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
19 // PARTICULAR PURPOSE. See the GNU General Public License for more de-
20 // tails. You should have received a copy of the GNU General Public
21 // License along with GNU Make; see the file COPYING. If not, write
22 // to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 // Boston, MA 02110-1301 USA.
25 #include "TableDowntimes.h"
29 #include "DowntimeOrComment.h"
30 #include "DowntimesOrComments.h"
31 #include "MonitoringCore.h"
32 #include "OffsetBoolColumn.h"
33 #include "OffsetIntColumn.h"
34 #include "OffsetSStringColumn.h"
35 #include "OffsetTimeColumn.h"
39 #include "TableHosts.h"
40 #include "TableServices.h"
44 // TODO(sp): the dynamic data in this table must be locked with a mutex
46 TableDowntimes::TableDowntimes(MonitoringCore
*mc
) : Table(mc
) {
47 addColumn(std::make_unique
<OffsetSStringColumn
>(
48 "author", "The contact that scheduled the downtime", -1, -1, -1,
49 DANGEROUS_OFFSETOF(Downtime
, _author_name
)));
50 addColumn(std::make_unique
<OffsetSStringColumn
>(
51 "comment", "A comment text", -1, -1, -1,
52 DANGEROUS_OFFSETOF(Downtime
, _comment
)));
53 addColumn(std::make_unique
<OffsetIntColumn
>(
54 "id", "The id of the downtime", -1, -1, -1,
55 DANGEROUS_OFFSETOF(Downtime
, _id
)));
56 addColumn(std::make_unique
<OffsetTimeColumn
>(
57 "entry_time", "The time the entry was made as UNIX timestamp", -1, -1,
58 -1, DANGEROUS_OFFSETOF(Downtime
, _entry_time
)));
59 addColumn(std::make_unique
<OffsetIntColumn
>(
61 "The type of the downtime: 0 if it is active, 1 if it is pending", -1,
62 -1, -1, DANGEROUS_OFFSETOF(Downtime
, _type
)));
63 addColumn(std::make_unique
<OffsetBoolColumn
>(
65 "0, if this entry is for a host, 1 if it is for a service", -1, -1, -1,
66 DANGEROUS_OFFSETOF(Downtime
, _is_service
)));
68 addColumn(std::make_unique
<OffsetTimeColumn
>(
69 "start_time", "The start time of the downtime as UNIX timestamp", -1,
70 -1, -1, DANGEROUS_OFFSETOF(Downtime
, _start_time
)));
71 addColumn(std::make_unique
<OffsetTimeColumn
>(
72 "end_time", "The end time of the downtime as UNIX timestamp", -1, -1,
73 -1, DANGEROUS_OFFSETOF(Downtime
, _end_time
)));
74 addColumn(std::make_unique
<OffsetIntColumn
>(
75 "fixed", "A 1 if the downtime is fixed, a 0 if it is flexible", -1, -1,
76 -1, DANGEROUS_OFFSETOF(Downtime
, _fixed
)));
77 addColumn(std::make_unique
<OffsetIntColumn
>(
78 "duration", "The duration of the downtime in seconds", -1, -1, -1,
79 DANGEROUS_OFFSETOF(Downtime
, _duration
)));
80 addColumn(std::make_unique
<OffsetIntColumn
>(
82 "The id of the downtime this downtime was triggered by or 0 if it was not triggered by another downtime",
83 -1, -1, -1, DANGEROUS_OFFSETOF(Downtime
, _triggered_by
)));
85 TableHosts::addColumns(this, "host_", DANGEROUS_OFFSETOF(Downtime
, _host
),
87 TableServices::addColumns(this, "service_",
88 DANGEROUS_OFFSETOF(Downtime
, _service
),
89 false /* no hosts table */);
92 std::string
TableDowntimes::name() const { return "downtimes"; }
94 std::string
TableDowntimes::namePrefix() const { return "downtime_"; }
96 void TableDowntimes::answerQuery(Query
*query
) {
97 for (const auto &entry
: core()->impl
<Store
>()->_downtimes
) {
98 if (!query
->processDataset(Row(entry
.second
.get()))) {
104 bool TableDowntimes::isAuthorized(Row row
, const contact
*ctc
) const {
105 auto dtc
= rowData
<DowntimeOrComment
>(row
);
106 return is_authorized_for(core(), ctc
, dtc
->_host
, dtc
->_service
);