2013-03-10 09:23:13 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-03-19 01:02:29 +01:00
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
2013-03-10 09:23:13 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "livestatus/statustable.hpp"
|
2014-05-28 14:25:12 +02:00
|
|
|
#include "livestatus/livestatuslistener.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/icingaapplication.hpp"
|
|
|
|
#include "icinga/cib.hpp"
|
|
|
|
#include "icinga/host.hpp"
|
|
|
|
#include "icinga/service.hpp"
|
|
|
|
#include "base/dynamictype.hpp"
|
|
|
|
#include "base/utility.hpp"
|
|
|
|
#include "base/application.hpp"
|
2014-05-11 17:14:35 +02:00
|
|
|
#include <boost/foreach.hpp>
|
2013-03-10 09:23:13 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
StatusTable::StatusTable(void)
|
|
|
|
{
|
2013-03-10 18:49:14 +01:00
|
|
|
AddColumns(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void StatusTable::AddColumns(Table *table, const String& prefix,
|
|
|
|
const Column::ObjectAccessor& objectAccessor)
|
|
|
|
{
|
2013-10-03 18:58:48 +02:00
|
|
|
table->AddColumn(prefix + "neb_callbacks", Column(&Table::ZeroAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "neb_callbacks_rate", Column(&Table::ZeroAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
|
2013-10-03 18:58:48 +02:00
|
|
|
table->AddColumn(prefix + "requests", Column(&Table::ZeroAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "requests_rate", Column(&Table::ZeroAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
|
|
|
|
table->AddColumn(prefix + "connections", Column(&StatusTable::ConnectionsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "connections_rate", Column(&StatusTable::ConnectionsRateAccessor, objectAccessor));
|
|
|
|
|
2013-11-07 17:29:45 +01:00
|
|
|
table->AddColumn(prefix + "service_checks", Column(&StatusTable::ServiceChecksAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "service_checks_rate", Column(&StatusTable::ServiceChecksRateAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
|
2014-05-26 20:56:34 +02:00
|
|
|
table->AddColumn(prefix + "host_checks", Column(&StatusTable::HostChecksAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "host_checks_rate", Column(&StatusTable::HostChecksRateAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
|
2013-10-03 18:58:48 +02:00
|
|
|
table->AddColumn(prefix + "forks", Column(&Table::ZeroAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "forks_rate", Column(&Table::ZeroAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
|
2013-10-03 18:58:48 +02:00
|
|
|
table->AddColumn(prefix + "log_messages", Column(&Table::ZeroAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "log_messages_rate", Column(&Table::ZeroAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
|
|
|
|
table->AddColumn(prefix + "external_commands", Column(&StatusTable::ExternalCommandsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "external_commands_rate", Column(&StatusTable::ExternalCommandsRateAccessor, objectAccessor));
|
|
|
|
|
2013-10-03 18:58:48 +02:00
|
|
|
table->AddColumn(prefix + "livechecks", Column(&Table::ZeroAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "livechecks_rate", Column(&Table::ZeroAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
|
2013-10-03 18:58:48 +02:00
|
|
|
table->AddColumn(prefix + "livecheck_overflows", Column(&Table::ZeroAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "livecheck_overflows_rate", Column(&Table::ZeroAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
|
|
|
|
table->AddColumn(prefix + "nagios_pid", Column(&StatusTable::NagiosPidAccessor, objectAccessor));
|
2014-03-20 11:33:59 +01:00
|
|
|
table->AddColumn(prefix + "enable_notifications", Column(&StatusTable::EnableNotificationsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "execute_service_checks", Column(&StatusTable::ExecuteServiceChecksAccessor, objectAccessor));
|
2013-10-03 18:58:48 +02:00
|
|
|
table->AddColumn(prefix + "accept_passive_service_checks", Column(&Table::OneAccessor, objectAccessor));
|
2014-04-17 11:29:47 +02:00
|
|
|
table->AddColumn(prefix + "execute_host_checks", Column(&StatusTable::ExecuteHostChecksAccessor, objectAccessor));
|
2013-10-03 18:58:48 +02:00
|
|
|
table->AddColumn(prefix + "accept_passive_host_checks", Column(&Table::OneAccessor, objectAccessor));
|
2014-03-20 11:33:59 +01:00
|
|
|
table->AddColumn(prefix + "enable_event_handlers", Column(&StatusTable::EnableEventHandlersAccessor, objectAccessor));
|
2013-10-03 18:58:48 +02:00
|
|
|
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));
|
2014-02-10 14:02:17 +01:00
|
|
|
table->AddColumn(prefix + "check_host_freshness", Column(&Table::OneAccessor, objectAccessor));
|
2014-03-20 11:33:59 +01:00
|
|
|
table->AddColumn(prefix + "enable_flap_detection", Column(&StatusTable::EnableFlapDetectionAccessor, objectAccessor));
|
2014-03-12 15:21:56 +01:00
|
|
|
table->AddColumn(prefix + "process_performance_data", Column(&StatusTable::ProcessPerformanceDataAccessor, objectAccessor));
|
2013-10-03 18:58:48 +02:00
|
|
|
table->AddColumn(prefix + "check_external_commands", Column(&Table::OneAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
table->AddColumn(prefix + "program_start", Column(&StatusTable::ProgramStartAccessor, objectAccessor));
|
2013-10-03 18:58:48 +02:00
|
|
|
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(&Table::ZeroAccessor, objectAccessor));
|
2013-07-09 17:15:38 +02:00
|
|
|
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));
|
2013-10-03 18:58:48 +02:00
|
|
|
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));
|
2013-07-09 17:15:38 +02:00
|
|
|
table->AddColumn(prefix + "livestatus_version", Column(&StatusTable::LivestatusVersionAccessor, objectAccessor));
|
2013-10-03 18:58:48 +02:00
|
|
|
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));
|
2014-04-04 17:45:23 +02:00
|
|
|
|
|
|
|
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));
|
2013-03-10 09:23:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
String StatusTable::GetName(void) const
|
|
|
|
{
|
|
|
|
return "status";
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:30:27 +02:00
|
|
|
String StatusTable::GetPrefix(void) const
|
|
|
|
{
|
|
|
|
return "status";
|
|
|
|
}
|
|
|
|
|
2013-03-15 18:21:29 +01:00
|
|
|
void StatusTable::FetchRows(const AddRowFunction& addRowFn)
|
2013-03-10 09:23:13 +01:00
|
|
|
{
|
2014-11-08 21:17:16 +01:00
|
|
|
Object::Ptr obj = new Object();
|
2013-03-10 09:23:13 +01:00
|
|
|
|
|
|
|
/* Return a fake row. */
|
|
|
|
addRowFn(obj);
|
|
|
|
}
|
2013-07-09 17:15:38 +02:00
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::ConnectionsAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
2013-09-25 09:31:52 +02:00
|
|
|
return LivestatusListener::GetConnections();
|
2013-07-09 17:15:38 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::ConnectionsRateAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
2013-10-26 09:41:45 +02:00
|
|
|
return (LivestatusListener::GetConnections() / (Utility::GetTime() - Application::GetStartTime()));
|
2013-07-09 17:15:38 +02:00
|
|
|
}
|
|
|
|
|
2014-05-26 20:56:34 +02:00
|
|
|
Value StatusTable::HostChecksAccessor(const Value&)
|
|
|
|
{
|
|
|
|
long timespan = static_cast<long>(Utility::GetTime() - Application::GetStartTime());
|
|
|
|
return CIB::GetActiveHostChecksStatistics(timespan);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value StatusTable::HostChecksRateAccessor(const Value&)
|
|
|
|
{
|
|
|
|
long timespan = static_cast<long>(Utility::GetTime() - Application::GetStartTime());
|
|
|
|
return (CIB::GetActiveHostChecksStatistics(timespan) / (Utility::GetTime() - Application::GetStartTime()));
|
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::ServiceChecksAccessor(const Value&)
|
2013-11-07 17:29:45 +01:00
|
|
|
{
|
|
|
|
long timespan = static_cast<long>(Utility::GetTime() - Application::GetStartTime());
|
2014-05-26 20:56:34 +02:00
|
|
|
return CIB::GetActiveServiceChecksStatistics(timespan);
|
2013-11-07 17:29:45 +01:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::ServiceChecksRateAccessor(const Value&)
|
2013-11-07 17:29:45 +01:00
|
|
|
{
|
|
|
|
long timespan = static_cast<long>(Utility::GetTime() - Application::GetStartTime());
|
2014-05-26 20:56:34 +02:00
|
|
|
return (CIB::GetActiveServiceChecksStatistics(timespan) / (Utility::GetTime() - Application::GetStartTime()));
|
2013-11-07 17:29:45 +01:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::ExternalCommandsAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
2014-05-28 14:25:12 +02:00
|
|
|
return LivestatusQuery::GetExternalCommands();
|
2013-07-09 17:15:38 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::ExternalCommandsRateAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
2014-05-28 14:25:12 +02:00
|
|
|
return (LivestatusQuery::GetExternalCommands() / (Utility::GetTime() - Application::GetStartTime()));
|
2013-07-09 17:15:38 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::NagiosPidAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
|
|
|
return Utility::GetPid();
|
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::EnableNotificationsAccessor(const Value&)
|
|
|
|
{
|
|
|
|
return (IcingaApplication::GetInstance()->GetEnableNotifications() ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value StatusTable::ExecuteServiceChecksAccessor(const Value&)
|
|
|
|
{
|
2014-04-17 11:29:47 +02:00
|
|
|
return (IcingaApplication::GetInstance()->GetEnableServiceChecks() ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value StatusTable::ExecuteHostChecksAccessor(const Value&)
|
|
|
|
{
|
|
|
|
return (IcingaApplication::GetInstance()->GetEnableHostChecks() ? 1 : 0);
|
2014-03-20 11:33:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Value StatusTable::EnableEventHandlersAccessor(const Value&)
|
|
|
|
{
|
|
|
|
return (IcingaApplication::GetInstance()->GetEnableEventHandlers() ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
Value StatusTable::EnableFlapDetectionAccessor(const Value&)
|
|
|
|
{
|
|
|
|
return (IcingaApplication::GetInstance()->GetEnableFlapping() ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2014-03-12 15:21:56 +01:00
|
|
|
Value StatusTable::ProcessPerformanceDataAccessor(const Value&)
|
|
|
|
{
|
|
|
|
return (IcingaApplication::GetInstance()->GetEnablePerfdata() ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::ProgramStartAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
2013-11-11 15:19:47 +01:00
|
|
|
return static_cast<long>(Application::GetStartTime());
|
2013-07-09 17:15:38 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::NumHostsAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
2014-09-02 13:02:22 +02:00
|
|
|
return std::distance(DynamicType::GetObjectsByType<Host>().first, DynamicType::GetObjectsByType<Host>().second);
|
2013-07-09 17:15:38 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::NumServicesAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
2014-09-02 13:02:22 +02:00
|
|
|
return std::distance(DynamicType::GetObjectsByType<Service>().first, DynamicType::GetObjectsByType<Service>().second);
|
2013-07-09 17:15:38 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::ProgramVersionAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
2013-10-09 11:24:37 +02:00
|
|
|
return Application::GetVersion();
|
2013-07-09 17:15:38 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::LivestatusVersionAccessor(const Value&)
|
2013-10-03 19:52:56 +02:00
|
|
|
{
|
2013-10-09 11:24:37 +02:00
|
|
|
return Application::GetVersion();
|
2013-10-03 19:52:56 +02:00
|
|
|
}
|
|
|
|
|
2014-03-20 11:33:59 +01:00
|
|
|
Value StatusTable::LivestatusActiveConnectionsAccessor(const Value&)
|
2013-07-09 17:15:38 +02:00
|
|
|
{
|
2013-09-25 09:31:52 +02:00
|
|
|
return LivestatusListener::GetClientsConnected();
|
2013-07-09 17:15:38 +02:00
|
|
|
}
|
2014-04-04 17:45:23 +02:00
|
|
|
|
2014-05-22 09:02:44 +02:00
|
|
|
Value StatusTable::CustomVariableNamesAccessor(const Value&)
|
2014-04-04 17:45:23 +02:00
|
|
|
{
|
|
|
|
Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
|
|
|
|
|
|
|
|
if (!vars)
|
|
|
|
return Empty;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr cv = new Array();
|
2014-04-04 17:45:23 +02:00
|
|
|
|
|
|
|
String key;
|
|
|
|
Value value;
|
|
|
|
BOOST_FOREACH(tie(key, value), vars) {
|
|
|
|
cv->Add(key);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cv;
|
|
|
|
}
|
|
|
|
|
2014-05-22 09:02:44 +02:00
|
|
|
Value StatusTable::CustomVariableValuesAccessor(const Value&)
|
2014-04-04 17:45:23 +02:00
|
|
|
{
|
|
|
|
Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
|
|
|
|
|
|
|
|
if (!vars)
|
|
|
|
return Empty;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr cv = new Array();
|
2014-04-04 17:45:23 +02:00
|
|
|
|
|
|
|
String key;
|
|
|
|
Value value;
|
|
|
|
BOOST_FOREACH(tie(key, value), vars) {
|
|
|
|
cv->Add(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cv;
|
|
|
|
}
|
|
|
|
|
|
|
|
Value StatusTable::CustomVariablesAccessor(const Value&)
|
|
|
|
{
|
|
|
|
Dictionary::Ptr vars = IcingaApplication::GetInstance()->GetVars();
|
|
|
|
|
|
|
|
if (!vars)
|
|
|
|
return Empty;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr cv = new Array();
|
2014-04-04 17:45:23 +02:00
|
|
|
|
|
|
|
String key;
|
|
|
|
Value value;
|
|
|
|
BOOST_FOREACH(tie(key, value), vars) {
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr key_val = new Array();
|
2014-04-04 17:45:23 +02:00
|
|
|
key_val->Add(key);
|
|
|
|
key_val->Add(value);
|
|
|
|
cv->Add(key_val);
|
|
|
|
}
|
|
|
|
|
|
|
|
return cv;
|
|
|
|
}
|