Refactoring: Changed all check parameters starting with a 'p' to the new rulespec...
[check_mk.git] / livestatus / src / CommentColumn.cc
blob4ac4399f42a2d37772c48cf6221e39ec7a90d284
1 // +------------------------------------------------------------------+
2 // | ____ _ _ __ __ _ __ |
3 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
4 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
5 // | | |___| | | | __/ (__| < | | | | . \ |
6 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
7 // | |
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 "CommentColumn.h"
26 #include <algorithm>
27 #include <chrono>
28 #include <cstdint>
29 #include <iterator>
30 #include "MonitoringCore.h"
31 #include "Renderer.h"
32 #include "Row.h"
33 #include "nagios.h"
35 void CommentColumn::output(Row row, RowRenderer &r,
36 const contact * /*auth_user*/,
37 std::chrono::seconds /*timezone_offset*/) const {
38 ListRenderer l(r);
39 for (const auto &comment : comments_for_row(row)) {
40 if (_with_info) {
41 SublistRenderer s(l);
42 s.output(comment._id);
43 s.output(comment._author);
44 s.output(comment._comment);
45 if (_with_extra_info) {
46 s.output(comment._entry_type);
47 s.output(comment._entry_time);
49 } else {
50 l.output(comment._id);
55 std::vector<std::string> CommentColumn::getValue(
56 Row row, const contact * /*auth_user*/,
57 std::chrono::seconds /*timezone_offset*/) const {
58 std::vector<std::string> ids;
59 auto comments = comments_for_row(row);
60 std::transform(
61 comments.begin(), comments.end(), std::back_inserter(ids),
62 [](const auto &comment) { return std::to_string(comment._id); });
63 return ids;
66 std::vector<CommentData> CommentColumn::comments_for_row(Row row) const {
67 if (auto data = columnData<void>(row)) {
68 return _is_service
69 ? _mc->comments_for_service(
70 reinterpret_cast<const MonitoringCore::Service *>(
71 data))
72 : _mc->comments_for_host(
73 reinterpret_cast<const MonitoringCore::Host *>(data));
75 return {};