1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
#include "livestatus/statustable.hpp"
#include "livestatus/livestatuslistener.hpp"
#include "icinga/icingaapplication.hpp"
#include "icinga/cib.hpp"
#include "icinga/host.hpp"
#include "icinga/service.hpp"
#include "base/configtype.hpp"
#include "base/utility.hpp"
#include "base/application.hpp"
using namespace icinga;
StatusTable::StatusTable()
{
AddColumns(this);
}
void StatusTable::AddColumns(Table *table, const String& prefix,
const Column::ObjectAccessor& objectAccessor)
{
table->AddColumn(prefix + "neb_callbacks", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "neb_callbacks_rate", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "requests", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "requests_rate", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "connections", Column(&StatusTable::ConnectionsAccessor, objectAccessor));
table->AddColumn(prefix + "connections_rate", Column(&StatusTable::ConnectionsRateAccessor, objectAccessor));
table->AddColumn(prefix + "service_checks", Column(&StatusTable::ServiceChecksAccessor, objectAccessor));
table->AddColumn(prefix + "service_checks_rate", Column(&StatusTable::ServiceChecksRateAccessor, objectAccessor));
table->AddColumn(prefix + "host_checks", Column(&StatusTable::HostChecksAccessor, objectAccessor));
table->AddColumn(prefix + "host_checks_rate", Column(&StatusTable::HostChecksRateAccessor, objectAccessor));
table->AddColumn(prefix + "forks", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "forks_rate", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "log_messages", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "log_messages_rate", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "external_commands", Column(&StatusTable::ExternalCommandsAccessor, objectAccessor));
table->AddColumn(prefix + "external_commands_rate", Column(&StatusTable::ExternalCommandsRateAccessor, objectAccessor));
table->AddColumn(prefix + "livechecks", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "livechecks_rate", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "livecheck_overflows", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "livecheck_overflows_rate", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "nagios_pid", Column(&StatusTable::NagiosPidAccessor, objectAccessor));
table->AddColumn(prefix + "enable_notifications", Column(&StatusTable::EnableNotificationsAccessor, objectAccessor));
table->AddColumn(prefix + "execute_service_checks", Column(&StatusTable::ExecuteServiceChecksAccessor, objectAccessor));
table->AddColumn(prefix + "accept_passive_service_checks", Column(&Table::OneAccessor, objectAccessor));
table->AddColumn(prefix + "execute_host_checks", Column(&StatusTable::ExecuteHostChecksAccessor, objectAccessor));
table->AddColumn(prefix + "accept_passive_host_checks", Column(&Table::OneAccessor, objectAccessor));
table->AddColumn(prefix + "enable_event_handlers", Column(&StatusTable::EnableEventHandlersAccessor, objectAccessor));
table->AddColumn(prefix + "obsess_over_services", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "obsess_over_hosts", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "check_service_freshness", Column(&Table::OneAccessor, objectAccessor));
table->AddColumn(prefix + "check_host_freshness", Column(&Table::OneAccessor, objectAccessor));
table->AddColumn(prefix + "enable_flap_detection", Column(&StatusTable::EnableFlapDetectionAccessor, objectAccessor));
table->AddColumn(prefix + "process_performance_data", Column(&StatusTable::ProcessPerformanceDataAccessor, objectAccessor));
table->AddColumn(prefix + "check_external_commands", Column(&Table::OneAccessor, objectAccessor));
table->AddColumn(prefix + "program_start", Column(&StatusTable::ProgramStartAccessor, objectAccessor));
table->AddColumn(prefix + "last_command_check", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "last_log_rotation", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "interval_length", Column(&StatusTable::IntervalLengthAccessor, objectAccessor));
table->AddColumn(prefix + "num_hosts", Column(&StatusTable::NumHostsAccessor, objectAccessor));
table->AddColumn(prefix + "num_services", Column(&StatusTable::NumServicesAccessor, objectAccessor));
table->AddColumn(prefix + "program_version", Column(&StatusTable::ProgramVersionAccessor, objectAccessor));
table->AddColumn(prefix + "external_command_buffer_slots", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "external_command_buffer_usage", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "external_command_buffer_max", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "cached_log_messages", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "livestatus_version", Column(&StatusTable::LivestatusVersionAccessor, objectAccessor));
table->AddColumn(prefix + "livestatus_active_connections", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "livestatus_queued_connections", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "livestatus_threads", Column(&Table::ZeroAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variable_names", Column(&StatusTable::CustomVariableNamesAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variable_values", Column(&StatusTable::CustomVariableValuesAccessor, objectAccessor));
table->AddColumn(prefix + "custom_variables", Column(&StatusTable::CustomVariablesAccessor, objectAccessor));
}
String StatusTable::GetName() const
{
return "status";
}
String StatusTable::GetPrefix() const
{
return "status";
}
void StatusTable::FetchRows(const AddRowFunction& addRowFn)
{
Object::Ptr obj = new Object();
/* Return a fake row. */
addRowFn(obj, LivestatusGroupByNone, Empty);
}
Value StatusTable::ConnectionsAccessor(const Value&)
{
return LivestatusListener::GetConnections();
}
Value StatusTable::ConnectionsRateAccessor(const Value&)
{
return (LivestatusListener::GetConnections() / (Utility::GetTime() - Application::GetStartTime()));
}
Value StatusTable::HostChecksAccessor(const Value&)
{
auto timespan = static_cast<long>(Utility::GetTime() - Application::GetStartTime());
return CIB::GetActiveHostChecksStatistics(timespan);
}
Value StatusTable::HostChecksRateAccessor(const Value&)
{
auto timespan = static_cast<long>(Utility::GetTime() - Application::GetStartTime());
return (CIB::GetActiveHostChecksStatistics(timespan) / (Utility::GetTime() - Application::GetStartTime()));
}
Value StatusTable::ServiceChecksAccessor(const Value&)
{
auto timespan = static_cast<long>(Utility::GetTime() - Application::GetStartTime());
return CIB::GetActiveServiceChecksStatistics(timespan);
}
Value StatusTable::ServiceChecksRateAccessor(const Value&)
{
auto timespan = static_cast<long>(Utility::GetTime() - Application::GetStartTime());
return (CIB::GetActiveServiceChecksStatistics(timespan) / (Utility::GetTime() - Application::GetStartTime()));
}
Value StatusTable::ExternalCommandsAccessor(const Value&)
{
return LivestatusQuery::GetExternalCommands();
}
Value StatusTable::ExternalCommandsRateAccessor(const Value&)
{
return (LivestatusQuery::GetExternalCommands() / (Utility::GetTime() - Application::GetStartTime()));
}
Value StatusTable::NagiosPidAccessor(const Value&)
{
return Utility::GetPid();
}
Value StatusTable::EnableNotificationsAccessor(const Value&)
{
return (IcingaApplication::GetInstance()->GetEnableNotifications() ? 1 : 0);
}
Value StatusTable::ExecuteServiceChecksAccessor(const Value&)
{
return (IcingaApplication::GetInstance()->GetEnableServiceChecks() ? 1 : 0);
}
Value StatusTable::ExecuteHostChecksAccessor(const Value&)
{
return (IcingaApplication::GetInstance()->GetEnableHostChecks() ? 1 : 0);
}
Value StatusTable::EnableEventHandlersAccessor(const Value&)
{
return (IcingaApplication::GetInstance()->GetEnableEventHandlers() ? 1 : 0);
}
Value StatusTable::EnableFlapDetectionAccessor(const Value&)
{
return (IcingaApplication::GetInstance()->GetEnableFlapping() ? 1 : 0);
}
Value StatusTable::ProcessPerformanceDataAccessor(const Value&)
{
return (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0);
}
Value StatusTable::ProgramStartAccessor(const Value&)
{
return static_cast<long>(Application::GetStartTime());
}
Value StatusTable::IntervalLengthAccessor(const Value&)
{
return LIVESTATUS_INTERVAL_LENGTH;
}
Value StatusTable::NumHostsAccessor(const Value&)
{
return ConfigType::Get<Host>()->GetObjectCount();
}
Value StatusTable::NumServicesAccessor(const Value&)
{
return ConfigType::Get<Service>()->GetObjectCount();
}
Value StatusTable::ProgramVersionAccessor(const Value&)
{
return Application::GetAppVersion() + "-icinga2";
}
Value StatusTable::LivestatusVersionAccessor(const Value&)
{
return Application::GetAppVersion();
}
Value StatusTable::LivestatusActiveConnectionsAccessor(const Value&)
{
return LivestatusListener::GetClientsConnected();
}
Value StatusTable::CustomVariableNamesAccessor(const Value&)
{
Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
ArrayData result;
if (vars) {
ObjectLock olock(vars);
for (const auto& kv : vars) {
result.push_back(kv.first);
}
}
return new Array(std::move(result));
}
Value StatusTable::CustomVariableValuesAccessor(const Value&)
{
Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
ArrayData result;
if (vars) {
ObjectLock olock(vars);
for (const auto& kv : vars) {
result.push_back(kv.second);
}
}
return new Array(std::move(result));
}
Value StatusTable::CustomVariablesAccessor(const Value&)
{
Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
ArrayData result;
if (vars) {
ObjectLock olock(vars);
for (const auto& kv : vars) {
result.push_back(new Array({
kv.first,
kv.second
}));
}
}
return new Array(std::move(result));
}
|