1 // +------------------------------------------------------------------+
2 // | ____ _ _ __ __ _ __ |
3 // | / ___| |__ ___ ___| | __ | \/ | |/ / |
4 // | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
5 // | | |___| | | | __/ (__| < | | | | . \ |
6 // | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
7 // | |
8 // | Copyright Mathias Kettner 2014 mk@mathias-kettner.de |
9 // +------------------------------------------------------------------+
10 //
11 // This file is part of Check_MK.
12 // The official homepage is at http://mathias-kettner.de/check_mk.
13 //
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 // ails. 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.
24
25 #include "TableStatus.h"
26 #include <time.h>
27 #include "GlobalCountersColumn.h"
28 #include "IntPointerColumn.h"
29 #include "Query.h"
30 #include "StatusSpecialIntColumn.h"
31 #include "StringPointerColumn.h"
32 #include "TimePointerColumn.h"
33 #include "global_counters.h"
34 #include "nagios.h"
35
36 // Nagios status values
37
38 extern time_t program_start;
39 extern int nagios_pid;
40 #ifndef NAGIOS4
41 extern time_t last_command_check;
42 #endif
43 extern time_t last_log_rotation;
44 extern int enable_notifications;
45 extern int execute_service_checks;
46 extern int accept_passive_service_checks;
47 extern int execute_host_checks;
48 extern int accept_passive_host_checks;
49 extern int enable_event_handlers;
50 extern int obsess_over_services;
51 extern int obsess_over_hosts;
52 extern int check_service_freshness;
53 extern int check_host_freshness;
54 extern int enable_flap_detection;
55 extern int process_performance_data;
56 extern int check_external_commands;
57 extern int num_cached_log_messages;
58 extern int interval_length;
59 extern int g_num_hosts;
60 extern int g_num_services;
61 extern int g_num_clientthreads;
62 extern int g_num_queued_connections;
63 extern int g_num_active_connections;
64
65 // Livecheck has been removed, but we still need to provide the
66 // columns - for compatibility
67 int livechecks_performed = 0;
68 int livecheck_overflows = 0;
69
70 #ifndef NAGIOS4
71 extern circular_buffer external_command_buffer;
72 extern int external_command_buffer_slots;
73 #else
74 // TODO: check if this data is available in nagios_squeue
75 #endif // NAGIOS4
76
TableStatus()77 TableStatus::TableStatus() {
78 addColumn(new GlobalCountersColumn(
79 "neb_callbacks", "The number of NEB call backs since program start",
80 COUNTER_NEB_CALLBACKS, false));
81 addColumn(new GlobalCountersColumn(
82 "neb_callbacks_rate",
83 "The averaged number of NEB call backs per second",
84 COUNTER_NEB_CALLBACKS, true));
85
86 addColumn(new GlobalCountersColumn(
87 "requests", "The number of requests to Livestatus since program start",
88 COUNTER_REQUESTS, false));
89 addColumn(new GlobalCountersColumn(
90 "requests_rate",
91 "The averaged number of request to Livestatus per second",
92 COUNTER_REQUESTS, true));
93
94 addColumn(new GlobalCountersColumn(
95 "connections",
96 "The number of client connections to Livestatus since program start",
97 COUNTER_CONNECTIONS, false));
98 addColumn(new GlobalCountersColumn("connections_rate",
99 "The averaged number of new client "
100 "connections to Livestatus per second",
101 COUNTER_CONNECTIONS, true));
102
103 addColumn(new GlobalCountersColumn(
104 "service_checks",
105 "The number of completed service checks since program start",
106 COUNTER_SERVICE_CHECKS, false));
107 addColumn(new GlobalCountersColumn(
108 "service_checks_rate",
109 "The averaged number of service checks per second",
110 COUNTER_SERVICE_CHECKS, true));
111
112 addColumn(new GlobalCountersColumn(
113 "host_checks", "The number of host checks since program start",
114 COUNTER_HOST_CHECKS, false));
115 addColumn(new GlobalCountersColumn(
116 "host_checks_rate", "the averaged number of host checks per second",
117 COUNTER_HOST_CHECKS, true));
118
119 addColumn(new GlobalCountersColumn(
120 "forks", "The number of process creations since program start",
121 COUNTER_FORKS, false));
122 addColumn(new GlobalCountersColumn(
123 "forks_rate", "the averaged number of forks checks per second",
124 COUNTER_FORKS, true));
125
126 addColumn(new GlobalCountersColumn(
127 "log_messages", "The number of new log messages since program start",
128 COUNTER_LOG_MESSAGES, false));
129 addColumn(new GlobalCountersColumn(
130 "log_messages_rate",
131 "the averaged number of new log messages per second",
132 COUNTER_LOG_MESSAGES, true));
133
134 addColumn(new GlobalCountersColumn(
135 "external_commands",
136 "The number of external commands since program start", COUNTER_COMMANDS,
137 false));
138 addColumn(new GlobalCountersColumn(
139 "external_commands_rate",
140 "the averaged number of external commands per second", COUNTER_COMMANDS,
141 true));
142
143 addColumn(new GlobalCountersColumn(
144 "livechecks", "The number of checks executed via livecheck",
145 COUNTER_LIVECHECKS, false));
146 addColumn(new GlobalCountersColumn(
147 "livechecks_rate",
148 "The averaged number of livechecks executes per second",
149 COUNTER_LIVECHECKS, true));
150
151 addColumn(new GlobalCountersColumn(
152 "livecheck_overflows",
153 "The number of times a check could not be executed "
154 "because now livecheck helper was free",
155 COUNTER_LIVECHECK_OVERFLOWS, false));
156 addColumn(
157 new GlobalCountersColumn("livecheck_overflows_rate",
158 "The number of livecheck overflows per second",
159 COUNTER_LIVECHECK_OVERFLOWS, true));
160
161 // Nagios program status data
162 addColumn(new IntPointerColumn("nagios_pid",
163 "The process ID of the Nagios main process",
164 &nagios_pid));
165 addColumn(new IntPointerColumn(
166 "enable_notifications",
167 "Whether notifications are enabled in general (0/1)",
168 &enable_notifications));
169 addColumn(new IntPointerColumn(
170 "execute_service_checks",
171 "Whether active service checks are activated in general (0/1)",
172 &execute_service_checks));
173 addColumn(new IntPointerColumn(
174 "accept_passive_service_checks",
175 "Whether passive service checks are activated in general (0/1)",
176 &accept_passive_service_checks));
177 addColumn(new IntPointerColumn(
178 "execute_host_checks",
179 "Whether host checks are executed in general (0/1)",
180 &execute_host_checks));
181 addColumn(new IntPointerColumn(
182 "accept_passive_host_checks",
183 "Whether passive host checks are accepted in general (0/1)",
184 &accept_passive_host_checks));
185 addColumn(new IntPointerColumn(
186 "enable_event_handlers",
187 "Whether event handlers are activated in general (0/1)",
188 &enable_event_handlers));
189 addColumn(new IntPointerColumn("obsess_over_services",
190 "Whether Nagios will obsess over service "
191 "checks and run the ocsp_command (0/1)",
192 &obsess_over_services));
193 addColumn(new IntPointerColumn(
194 "obsess_over_hosts",
195 "Whether Nagios will obsess over host checks (0/1)",
196 &obsess_over_hosts));
197 addColumn(new IntPointerColumn(
198 "check_service_freshness",
199 "Whether service freshness checking is activated in general (0/1)",
200 &check_service_freshness));
201 addColumn(new IntPointerColumn(
202 "check_host_freshness",
203 "Whether host freshness checking is activated in general (0/1)",
204 &check_host_freshness));
205 addColumn(new IntPointerColumn(
206 "enable_flap_detection",
207 "Whether flap detection is activated in general (0/1)",
208 &enable_flap_detection));
209 addColumn(new IntPointerColumn(
210 "process_performance_data",
211 "Whether processing of performance data is activated in general (0/1)",
212 &process_performance_data));
213 addColumn(new IntPointerColumn(
214 "check_external_commands",
215 "Whether Nagios checks for external commands at its command pipe (0/1)",
216 &check_external_commands));
217 addColumn(new TimePointerColumn(
218 "program_start", "The time of the last program start as UNIX timestamp",
219 reinterpret_cast<int *>(&program_start)));
220 #ifndef NAGIOS4
221 addColumn(new TimePointerColumn(
222 "last_command_check",
223 "The time of the last check for a command as UNIX timestamp",
224 reinterpret_cast<int *>(&last_command_check)));
225 #else
226 int dummy = 0;
227 addColumn(new TimePointerColumn("last_command_check",
228 "The time of the last check for a command "
229 "as UNIX timestamp (placeholder)",
230 &dummy));
231 #endif // NAGIOS4
232 addColumn(new TimePointerColumn(
233 "last_log_rotation", "Time time of the last log file rotation",
234 reinterpret_cast<int *>(&last_log_rotation)));
235 addColumn(new IntPointerColumn(
236 "interval_length", "The default interval length from nagios.cfg",
237 &interval_length));
238
239 addColumn(new IntPointerColumn("num_hosts", "The total number of hosts",
240 &g_num_hosts));
241 addColumn(new IntPointerColumn(
242 "num_services", "The total number of services", &g_num_services));
243
244 addColumn(new StringPointerColumn("program_version",
245 "The version of the monitoring daemon",
246 get_program_version()));
247
248 // External command buffer
249 #ifndef NAGIOS4
250 addColumn(
251 new IntPointerColumn("external_command_buffer_slots",
252 "The size of the buffer for the external commands",
253 &external_command_buffer_slots));
254 addColumn(new IntPointerColumn(
255 "external_command_buffer_usage",
256 "The number of slots in use of the external command buffer",
257 &(external_command_buffer.items)));
258 addColumn(new IntPointerColumn(
259 "external_command_buffer_max",
260 "The maximum number of slots used in the external command buffer",
261 &(external_command_buffer.high)));
262 #else
263 addColumn(new IntPointerColumn(
264 "external_command_buffer_slots",
265 "The size of the buffer for the external commands (placeholder)",
266 &dummy));
267 addColumn(new IntPointerColumn("external_command_buffer_usage",
268 "The number of slots in use of the external "
269 "command buffer (placeholder)",
270 &dummy));
271 addColumn(new IntPointerColumn("external_command_buffer_max",
272 "The maximum number of slots used in the "
273 "external command buffer (placeholder)",
274 &dummy));
275 #endif // NAGIOS4
276
277 // Livestatus' own status
278 addColumn(new IntPointerColumn(
279 "cached_log_messages",
280 "The current number of log messages MK Livestatus keeps in memory",
281 &num_cached_log_messages));
282 addColumn(new StringPointerColumn("livestatus_version",
283 "The version of the MK Livestatus module",
284 VERSION));
285 addColumn(new IntPointerColumn(
286 "livestatus_active_connections",
287 "The current number of active connections to MK Livestatus",
288 &g_num_active_connections));
289 addColumn(new IntPointerColumn("livestatus_queued_connections",
290 "The current number of queued connections "
291 "to MK Livestatus (that wait for a free "
292 "thread)",
293 &g_num_queued_connections));
294 addColumn(new IntPointerColumn("livestatus_threads",
295 "The maximum number of connections to MK "
296 "Livestatus that can be handled in parallel",
297 &g_num_clientthreads));
298
299 // Special stuff for Check_MK
300 addColumn(new StatusSpecialIntColumn("mk_inventory_last",
301 "The timestamp of the last time a "
302 "host has been inventorized by "
303 "Check_MK HW/SW-Inventory",
304 SPIC_MK_INVENTORY_LAST));
305 }
306
answerQuery(Query * query)307 void TableStatus::answerQuery(Query *query) { query->processDataset(this); }
308