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 "TableServiceGroups.h"
28 #include "OffsetStringColumn.h"
30 #include "ServiceGroupMembersColumn.h"
31 #include "ServiceListStateColumn.h"
35 /* this might be a hack (accessing Nagios' internal structures.
36 Ethan: please help me here: how should this be code to be
38 extern servicegroup
*servicegroup_list
;
40 TableServiceGroups::TableServiceGroups(MonitoringCore
*mc
) : Table(mc
) {
41 addColumns(this, "", -1);
44 std::string
TableServiceGroups::name() const { return "servicegroups"; }
46 std::string
TableServiceGroups::namePrefix() const { return "servicegroup_"; }
49 void TableServiceGroups::addColumns(Table
*table
, const std::string
&prefix
,
50 int indirect_offset
) {
51 table
->addColumn(std::make_unique
<OffsetStringColumn
>(
52 prefix
+ "name", "The name of the service group", indirect_offset
, -1,
53 -1, DANGEROUS_OFFSETOF(servicegroup
, group_name
)));
54 table
->addColumn(std::make_unique
<OffsetStringColumn
>(
55 prefix
+ "alias", "An alias of the service group", indirect_offset
, -1,
56 -1, DANGEROUS_OFFSETOF(servicegroup
, alias
)));
57 table
->addColumn(std::make_unique
<OffsetStringColumn
>(
58 prefix
+ "notes", "Optional additional notes about the service group",
59 indirect_offset
, -1, -1, DANGEROUS_OFFSETOF(servicegroup
, notes
)));
60 table
->addColumn(std::make_unique
<OffsetStringColumn
>(
62 "An optional URL to further notes on the service group",
63 indirect_offset
, -1, -1, DANGEROUS_OFFSETOF(servicegroup
, notes_url
)));
64 table
->addColumn(std::make_unique
<OffsetStringColumn
>(
65 prefix
+ "action_url",
66 "An optional URL to custom notes or actions on the service group",
67 indirect_offset
, -1, -1, DANGEROUS_OFFSETOF(servicegroup
, action_url
)));
68 table
->addColumn(std::make_unique
<ServiceGroupMembersColumn
>(
70 "A list of all members of the service group as host/service pairs",
71 indirect_offset
, -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
),
72 table
->core(), false));
73 table
->addColumn(std::make_unique
<ServiceGroupMembersColumn
>(
74 prefix
+ "members_with_state",
75 "A list of all members of the service group with state and has_been_checked",
76 indirect_offset
, -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
),
77 table
->core(), true));
79 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
80 prefix
+ "worst_service_state",
81 "The worst soft state of all of the groups services (OK <= WARN <= UNKNOWN <= CRIT)",
82 indirect_offset
, -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
),
83 table
->core(), ServiceListStateColumn::Type::worst_state
));
84 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
85 prefix
+ "num_services", "The total number of services in the group",
86 indirect_offset
, -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
),
87 table
->core(), ServiceListStateColumn::Type::num
));
88 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
89 prefix
+ "num_services_ok",
90 "The number of services in the group that are OK", indirect_offset
, -1,
91 -1, DANGEROUS_OFFSETOF(servicegroup
, members
), table
->core(),
92 ServiceListStateColumn::Type::num_ok
));
93 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
94 prefix
+ "num_services_warn",
95 "The number of services in the group that are WARN", indirect_offset
,
96 -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
), table
->core(),
97 ServiceListStateColumn::Type::num_warn
));
98 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
99 prefix
+ "num_services_crit",
100 "The number of services in the group that are CRIT", indirect_offset
,
101 -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
), table
->core(),
102 ServiceListStateColumn::Type::num_crit
));
103 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
104 prefix
+ "num_services_unknown",
105 "The number of services in the group that are UNKNOWN", indirect_offset
,
106 -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
), table
->core(),
107 ServiceListStateColumn::Type::num_unknown
));
108 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
109 prefix
+ "num_services_pending",
110 "The number of services in the group that are PENDING", indirect_offset
,
111 -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
), table
->core(),
112 ServiceListStateColumn::Type::num_pending
));
113 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
114 prefix
+ "num_services_hard_ok",
115 "The number of services in the group that are OK", indirect_offset
, -1,
116 -1, DANGEROUS_OFFSETOF(servicegroup
, members
), table
->core(),
117 ServiceListStateColumn::Type::num_hard_ok
));
118 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
119 prefix
+ "num_services_hard_warn",
120 "The number of services in the group that are WARN", indirect_offset
,
121 -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
), table
->core(),
122 ServiceListStateColumn::Type::num_hard_warn
));
123 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
124 prefix
+ "num_services_hard_crit",
125 "The number of services in the group that are CRIT", indirect_offset
,
126 -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
), table
->core(),
127 ServiceListStateColumn::Type::num_hard_crit
));
128 table
->addColumn(std::make_unique
<ServiceListStateColumn
>(
129 prefix
+ "num_services_hard_unknown",
130 "The number of services in the group that are UNKNOWN", indirect_offset
,
131 -1, -1, DANGEROUS_OFFSETOF(servicegroup
, members
), table
->core(),
132 ServiceListStateColumn::Type::num_hard_unknown
));
135 void TableServiceGroups::answerQuery(Query
*query
) {
136 for (servicegroup
*sg
= servicegroup_list
; sg
!= nullptr; sg
= sg
->next
) {
137 if (!query
->processDataset(Row(sg
))) {
143 Row
TableServiceGroups::findObject(const std::string
&objectspec
) const {
144 return Row(find_servicegroup(const_cast<char *>(objectspec
.c_str())));
147 bool TableServiceGroups::isAuthorized(Row row
, const contact
*ctc
) const {
148 return is_authorized_for_service_group(core(), rowData
<servicegroup
>(row
),