Refactoring: Changed all check parameters starting with a 'p' to the new rulespec...
[check_mk.git] / livestatus / src / TableStatus.cc
blobb09aebca14a8bbb10833f4a1be6b41330058a7af
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 "TableStatus.h"
26 #include <atomic>
27 #include <ctime>
28 #include <memory>
29 #include "AtomicInt32PointerColumn.h"
30 #include "Column.h"
31 #include "DoublePointerColumn.h"
32 #include "IntPointerColumn.h"
33 #include "Query.h"
34 #include "Row.h"
35 #include "StatusSpecialIntColumn.h"
36 #include "StringPointerColumn.h"
37 #include "TimePointerColumn.h"
38 #include "global_counters.h"
39 #include "nagios.h"
41 extern time_t program_start;
42 extern int nagios_pid;
43 #ifndef NAGIOS4
44 extern time_t last_command_check;
45 #endif
46 extern time_t last_log_rotation;
47 extern int enable_notifications;
48 extern int execute_service_checks;
49 extern int accept_passive_service_checks;
50 extern int execute_host_checks;
51 extern int accept_passive_host_checks;
52 extern int enable_event_handlers;
53 extern int obsess_over_services;
54 extern int obsess_over_hosts;
55 extern int check_service_freshness;
56 extern int check_host_freshness;
57 extern int enable_flap_detection;
58 extern int process_performance_data;
59 extern int check_external_commands;
60 extern int num_cached_log_messages;
61 extern int interval_length;
62 extern int g_num_hosts;
63 extern int g_num_services;
64 extern int g_livestatus_threads;
65 extern int g_num_queued_connections;
66 extern std::atomic_int32_t g_livestatus_active_connections;
68 #ifndef NAGIOS4
69 extern circular_buffer external_command_buffer;
70 extern int external_command_buffer_slots;
71 #else
72 // TODO: check if this data is available in nagios_squeue
73 namespace {
74 time_t dummy_time = 0;
75 int dummy_int = 0;
76 } // namespace
77 #endif // NAGIOS4
79 TableStatus::TableStatus(MonitoringCore *mc) : Table(mc) {
80 addCounterColumns("neb_callbacks", "NEB callbacks", Counter::neb_callbacks);
81 addCounterColumns("requests", "requests to Livestatus", Counter::requests);
82 addCounterColumns("connections", "client connections to Livestatus",
83 Counter::connections);
84 addCounterColumns("service_checks", "completed service checks",
85 Counter::service_checks);
86 addCounterColumns("host_checks", "host checks", Counter::host_checks);
87 addCounterColumns("forks", "process creations", Counter::forks);
88 addCounterColumns("log_messages", "new log messages",
89 Counter::log_messages);
90 addCounterColumns("external_commands", "external commands",
91 Counter::commands);
92 addCounterColumns("livechecks", "checks executed via livecheck",
93 Counter::livechecks);
94 addCounterColumns(
95 "livecheck_overflows",
96 "times a check could not be executed because no livecheck helper was free",
97 Counter::livecheck_overflows);
99 // Nagios program status data
100 addColumn(std::make_unique<IntPointerColumn>(
101 "nagios_pid", "The process ID of the Nagios main process",
102 &nagios_pid));
103 addColumn(std::make_unique<IntPointerColumn>(
104 "enable_notifications",
105 "Whether notifications are enabled in general (0/1)",
106 &enable_notifications));
107 addColumn(std::make_unique<IntPointerColumn>(
108 "execute_service_checks",
109 "Whether active service checks are activated in general (0/1)",
110 &execute_service_checks));
111 addColumn(std::make_unique<IntPointerColumn>(
112 "accept_passive_service_checks",
113 "Whether passive service checks are activated in general (0/1)",
114 &accept_passive_service_checks));
115 addColumn(std::make_unique<IntPointerColumn>(
116 "execute_host_checks",
117 "Whether host checks are executed in general (0/1)",
118 &execute_host_checks));
119 addColumn(std::make_unique<IntPointerColumn>(
120 "accept_passive_host_checks",
121 "Whether passive host checks are accepted in general (0/1)",
122 &accept_passive_host_checks));
123 addColumn(std::make_unique<IntPointerColumn>(
124 "enable_event_handlers",
125 "Whether event handlers are activated in general (0/1)",
126 &enable_event_handlers));
127 addColumn(std::make_unique<IntPointerColumn>(
128 "obsess_over_services",
129 "Whether Nagios will obsess over service checks and run the ocsp_command (0/1)",
130 &obsess_over_services));
131 addColumn(std::make_unique<IntPointerColumn>(
132 "obsess_over_hosts",
133 "Whether Nagios will obsess over host checks (0/1)",
134 &obsess_over_hosts));
135 addColumn(std::make_unique<IntPointerColumn>(
136 "check_service_freshness",
137 "Whether service freshness checking is activated in general (0/1)",
138 &check_service_freshness));
139 addColumn(std::make_unique<IntPointerColumn>(
140 "check_host_freshness",
141 "Whether host freshness checking is activated in general (0/1)",
142 &check_host_freshness));
143 addColumn(std::make_unique<IntPointerColumn>(
144 "enable_flap_detection",
145 "Whether flap detection is activated in general (0/1)",
146 &enable_flap_detection));
147 addColumn(std::make_unique<IntPointerColumn>(
148 "process_performance_data",
149 "Whether processing of performance data is activated in general (0/1)",
150 &process_performance_data));
151 addColumn(std::make_unique<IntPointerColumn>(
152 "check_external_commands",
153 "Whether Nagios checks for external commands at its command pipe (0/1)",
154 &check_external_commands));
155 addColumn(std::make_unique<TimePointerColumn>(
156 "program_start", "The time of the last program start as UNIX timestamp",
157 &program_start));
158 #ifndef NAGIOS4
159 addColumn(std::make_unique<TimePointerColumn>(
160 "last_command_check",
161 "The time of the last check for a command as UNIX timestamp",
162 &last_command_check));
163 #else
164 addColumn(std::make_unique<TimePointerColumn>(
165 "last_command_check",
166 "The time of the last check for a command as UNIX timestamp (placeholder)",
167 &dummy_time));
168 #endif // NAGIOS4
169 addColumn(std::make_unique<TimePointerColumn>(
170 "last_log_rotation", "Time time of the last log file rotation",
171 &last_log_rotation));
172 addColumn(std::make_unique<IntPointerColumn>(
173 "interval_length", "The default interval length from nagios.cfg",
174 &interval_length));
176 addColumn(std::make_unique<IntPointerColumn>(
177 "num_hosts", "The total number of hosts", &g_num_hosts));
178 addColumn(std::make_unique<IntPointerColumn>(
179 "num_services", "The total number of services", &g_num_services));
181 addColumn(std::make_unique<StringPointerColumn>(
182 "program_version", "The version of the monitoring daemon",
183 get_program_version()));
185 // External command buffer
186 #ifndef NAGIOS4
187 addColumn(std::make_unique<IntPointerColumn>(
188 "external_command_buffer_slots",
189 "The size of the buffer for the external commands",
190 &external_command_buffer_slots));
191 addColumn(std::make_unique<IntPointerColumn>(
192 "external_command_buffer_usage",
193 "The number of slots in use of the external command buffer",
194 &(external_command_buffer.items)));
195 addColumn(std::make_unique<IntPointerColumn>(
196 "external_command_buffer_max",
197 "The maximum number of slots used in the external command buffer",
198 &(external_command_buffer.high)));
199 #else
200 addColumn(std::make_unique<IntPointerColumn>(
201 "external_command_buffer_slots",
202 "The size of the buffer for the external commands (placeholder)",
203 &dummy_int));
204 addColumn(std::make_unique<IntPointerColumn>(
205 "external_command_buffer_usage",
206 "The number of slots in use of the external command buffer (placeholder)",
207 &dummy_int));
208 addColumn(std::make_unique<IntPointerColumn>(
209 "external_command_buffer_max",
210 "The maximum number of slots used in the external command buffer (placeholder)",
211 &dummy_int));
212 #endif // NAGIOS4
214 // Livestatus' own status
215 addColumn(std::make_unique<IntPointerColumn>(
216 "cached_log_messages",
217 "The current number of log messages MK Livestatus keeps in memory",
218 &num_cached_log_messages));
219 addColumn(std::make_unique<StringPointerColumn>(
220 "livestatus_version", "The version of the MK Livestatus module",
221 VERSION));
222 addColumn(std::make_unique<AtomicInt32PointerColumn>(
223 "livestatus_active_connections",
224 "The current number of active connections to MK Livestatus",
225 &g_livestatus_active_connections));
226 addColumn(std::make_unique<IntPointerColumn>(
227 "livestatus_queued_connections",
228 "The current number of queued connections to MK Livestatus (that wait for a free thread)",
229 &g_num_queued_connections));
230 addColumn(std::make_unique<IntPointerColumn>(
231 "livestatus_threads",
232 "The maximum number of connections to MK Livestatus that can be handled in parallel",
233 &g_livestatus_threads));
235 // Special stuff for Check_MK
236 addColumn(std::make_unique<StatusSpecialIntColumn>(
237 "mk_inventory_last",
238 "The timestamp of the last time a host has been inventorized by Check_MK HW/SW-Inventory",
239 -1, -1, -1, 0, mc, StatusSpecialIntColumn::Type::mk_inventory_last));
242 void TableStatus::addCounterColumns(const std::string &name,
243 const std::string &description,
244 Counter which) {
245 addColumn(std::make_unique<DoublePointerColumn>(
246 name, "The number of " + description + " since program start",
247 counterAddress(which)));
248 addColumn(std::make_unique<DoublePointerColumn>(
249 name + "_rate", "The averaged number of " + description + " per second",
250 counterRateAddress(which)));
253 std::string TableStatus::name() const { return "status"; }
255 std::string TableStatus::namePrefix() const { return "status_"; }
257 void TableStatus::answerQuery(Query *query) {
258 query->processDataset(Row(this));