2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-07-09 18:33:27 +02:00
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "livestatus/servicegroupstable.hpp"
|
|
|
|
#include "icinga/servicegroup.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configtype.hpp"
|
2013-07-09 18:33:27 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
ServiceGroupsTable::ServiceGroupsTable()
|
2013-07-09 18:33:27 +02:00
|
|
|
{
|
|
|
|
AddColumns(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ServiceGroupsTable::AddColumns(Table *table, const String& prefix,
|
2017-12-19 15:50:05 +01:00
|
|
|
const Column::ObjectAccessor& objectAccessor)
|
2013-07-09 18:33:27 +02:00
|
|
|
{
|
|
|
|
table->AddColumn(prefix + "name", Column(&ServiceGroupsTable::NameAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "alias", Column(&ServiceGroupsTable::AliasAccessor, objectAccessor));
|
2013-07-11 12:43:27 +02:00
|
|
|
table->AddColumn(prefix + "notes", Column(&ServiceGroupsTable::NotesAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "notes_url", Column(&ServiceGroupsTable::NotesUrlAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "action_url", Column(&ServiceGroupsTable::ActionUrlAccessor, objectAccessor));
|
2013-07-09 18:33:27 +02:00
|
|
|
table->AddColumn(prefix + "members", Column(&ServiceGroupsTable::MembersAccessor, objectAccessor));
|
2013-07-11 12:43:27 +02:00
|
|
|
table->AddColumn(prefix + "members_with_state", Column(&ServiceGroupsTable::MembersWithStateAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "worst_service_state", Column(&ServiceGroupsTable::WorstServiceStateAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services", Column(&ServiceGroupsTable::NumServicesAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_ok", Column(&ServiceGroupsTable::NumServicesOkAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_warn", Column(&ServiceGroupsTable::NumServicesWarnAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_crit", Column(&ServiceGroupsTable::NumServicesCritAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_unknown", Column(&ServiceGroupsTable::NumServicesUnknownAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_pending", Column(&ServiceGroupsTable::NumServicesPendingAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_hard_ok", Column(&ServiceGroupsTable::NumServicesHardOkAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_hard_warn", Column(&ServiceGroupsTable::NumServicesHardWarnAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_hard_crit", Column(&ServiceGroupsTable::NumServicesHardCritAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_hard_unknown", Column(&ServiceGroupsTable::NumServicesHardUnknownAccessor, objectAccessor));
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
String ServiceGroupsTable::GetName() const
|
2013-07-09 18:33:27 +02:00
|
|
|
{
|
|
|
|
return "servicegroups";
|
|
|
|
}
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
String ServiceGroupsTable::GetPrefix() const
|
2014-06-25 11:30:27 +02:00
|
|
|
{
|
|
|
|
return "servicegroup";
|
|
|
|
}
|
|
|
|
|
2013-07-09 18:33:27 +02:00
|
|
|
void ServiceGroupsTable::FetchRows(const AddRowFunction& addRowFn)
|
|
|
|
{
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const ServiceGroup::Ptr& sg : ConfigType::GetObjectsByType<ServiceGroup>()) {
|
2015-03-04 12:03:35 +01:00
|
|
|
if (!addRowFn(sg, LivestatusGroupByNone, Empty))
|
|
|
|
return;
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServiceGroupsTable::NameAccessor(const Value& row)
|
2013-07-09 18:33:27 +02:00
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return sg->GetName();
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServiceGroupsTable::AliasAccessor(const Value& row)
|
2013-07-09 18:33:27 +02:00
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return sg->GetDisplayName();
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 12:43:27 +02:00
|
|
|
Value ServiceGroupsTable::NotesAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return sg->GetNotes();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NotesUrlAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return sg->GetNotesUrl();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::ActionUrlAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return sg->GetActionUrl();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value ServiceGroupsTable::MembersAccessor(const Value& row)
|
2013-07-09 18:33:27 +02:00
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
ArrayData result;
|
2013-07-09 18:33:27 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2018-01-11 11:17:38 +01:00
|
|
|
result.push_back(new Array({
|
|
|
|
service->GetHost()->GetName(),
|
|
|
|
service->GetShortName()
|
|
|
|
}));
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
return new Array(std::move(result));
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
2013-07-11 12:43:27 +02:00
|
|
|
|
|
|
|
Value ServiceGroupsTable::MembersWithStateAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
ArrayData result;
|
2013-07-16 13:26:16 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2018-01-11 11:17:38 +01:00
|
|
|
result.push_back(new Array({
|
|
|
|
service->GetHost()->GetName(),
|
|
|
|
service->GetShortName(),
|
|
|
|
service->GetHost()->GetState(),
|
|
|
|
service->GetState()
|
|
|
|
}));
|
2013-07-16 13:26:16 +02:00
|
|
|
}
|
|
|
|
|
2018-01-11 11:17:38 +01:00
|
|
|
return new Array(std::move(result));
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::WorstServiceStateAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2014-04-08 09:11:54 +02:00
|
|
|
Value worst_service = ServiceOK;
|
2013-07-12 16:47:37 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2013-07-12 16:47:37 +02:00
|
|
|
if (service->GetState() > worst_service)
|
|
|
|
worst_service = service->GetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
return worst_service;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return sg->GetMembers().size();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesOkAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 16:47:37 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetState() == ServiceOK)
|
2013-07-12 16:47:37 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesWarnAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 16:47:37 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetState() == ServiceWarning)
|
2013-07-12 16:47:37 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesCritAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 16:47:37 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetState() == ServiceCritical)
|
2013-07-12 16:47:37 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesUnknownAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 16:47:37 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetState() == ServiceUnknown)
|
2013-07-12 16:47:37 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesPendingAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 16:47:37 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2013-07-12 16:47:37 +02:00
|
|
|
if (!service->GetLastCheckResult())
|
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesHardOkAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 16:47:37 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetStateType() == StateTypeHard && service->GetState() == ServiceOK)
|
2013-07-12 16:47:37 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesHardWarnAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 16:47:37 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetStateType() == StateTypeHard && service->GetState() == ServiceWarning)
|
2013-07-12 16:47:37 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesHardCritAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 16:47:37 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetStateType() == StateTypeHard && service->GetState() == ServiceCritical)
|
2013-07-12 16:47:37 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value ServiceGroupsTable::NumServicesHardUnknownAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
ServiceGroup::Ptr sg = static_cast<ServiceGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!sg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 16:47:37 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Service::Ptr& service : sg->GetMembers()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetStateType() == StateTypeHard && service->GetState() == ServiceUnknown)
|
2013-07-12 16:47:37 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|