2013-07-09 18:33:27 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2017-01-10 15:54:22 +01:00
|
|
|
* Copyright (C) 2012-2017 Icinga Development Team (https://www.icinga.com/) *
|
2013-07-09 18:33:27 +02: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/hostgroupstable.hpp"
|
|
|
|
#include "icinga/hostgroup.hpp"
|
|
|
|
#include "icinga/host.hpp"
|
|
|
|
#include "icinga/service.hpp"
|
2015-08-15 20:28:05 +02:00
|
|
|
#include "base/configtype.hpp"
|
2013-07-09 18:33:27 +02:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
|
|
|
HostGroupsTable::HostGroupsTable(void)
|
|
|
|
{
|
|
|
|
AddColumns(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostGroupsTable::AddColumns(Table *table, const String& prefix,
|
|
|
|
const Column::ObjectAccessor& objectAccessor)
|
|
|
|
{
|
|
|
|
table->AddColumn(prefix + "name", Column(&HostGroupsTable::NameAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "alias", Column(&HostGroupsTable::AliasAccessor, objectAccessor));
|
2013-07-11 12:43:27 +02:00
|
|
|
table->AddColumn(prefix + "notes", Column(&HostGroupsTable::NotesAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "notes_url", Column(&HostGroupsTable::NotesUrlAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "action_url", Column(&HostGroupsTable::ActionUrlAccessor, objectAccessor));
|
2013-07-09 18:33:27 +02:00
|
|
|
table->AddColumn(prefix + "members", Column(&HostGroupsTable::MembersAccessor, objectAccessor));
|
2013-07-11 12:43:27 +02:00
|
|
|
table->AddColumn(prefix + "members_with_state", Column(&HostGroupsTable::MembersWithStateAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "worst_host_state", Column(&HostGroupsTable::WorstHostStateAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_hosts", Column(&HostGroupsTable::NumHostsAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_hosts_pending", Column(&HostGroupsTable::NumHostsPendingAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_hosts_up", Column(&HostGroupsTable::NumHostsUpAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_hosts_down", Column(&HostGroupsTable::NumHostsDownAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_hosts_unreach", Column(&HostGroupsTable::NumHostsUnreachAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services", Column(&HostGroupsTable::NumServicesAccessor, objectAccessor));
|
2017-02-08 13:00:51 +01:00
|
|
|
table->AddColumn(prefix + "worst_service_state", Column(&HostGroupsTable::WorstServiceStateAccessor, objectAccessor));
|
2013-07-11 12:43:27 +02:00
|
|
|
table->AddColumn(prefix + "num_services_pending", Column(&HostGroupsTable::NumServicesPendingAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_ok", Column(&HostGroupsTable::NumServicesOkAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_warn", Column(&HostGroupsTable::NumServicesWarnAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_crit", Column(&HostGroupsTable::NumServicesCritAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_unknown", Column(&HostGroupsTable::NumServicesUnknownAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "worst_service_hard_state", Column(&HostGroupsTable::WorstServiceHardStateAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_hard_ok", Column(&HostGroupsTable::NumServicesHardOkAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_hard_warn", Column(&HostGroupsTable::NumServicesHardWarnAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_hard_crit", Column(&HostGroupsTable::NumServicesHardCritAccessor, objectAccessor));
|
|
|
|
table->AddColumn(prefix + "num_services_hard_unknown", Column(&HostGroupsTable::NumServicesHardUnknownAccessor, objectAccessor));
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String HostGroupsTable::GetName(void) const
|
|
|
|
{
|
|
|
|
return "hostgroups";
|
|
|
|
}
|
|
|
|
|
2014-06-25 11:30:27 +02:00
|
|
|
String HostGroupsTable::GetPrefix(void) const
|
|
|
|
{
|
|
|
|
return "hostgroup";
|
|
|
|
}
|
|
|
|
|
2013-07-09 18:33:27 +02:00
|
|
|
void HostGroupsTable::FetchRows(const AddRowFunction& addRowFn)
|
|
|
|
{
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const HostGroup::Ptr& hg : ConfigType::GetObjectsByType<HostGroup>()) {
|
2015-03-04 12:03:35 +01:00
|
|
|
if (!addRowFn(hg, LivestatusGroupByNone, Empty))
|
|
|
|
return;
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value HostGroupsTable::NameAccessor(const Value& row)
|
2013-07-09 18:33:27 +02:00
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return hg->GetName();
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value HostGroupsTable::AliasAccessor(const Value& row)
|
2013-07-09 18:33:27 +02:00
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return hg->GetDisplayName();
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 12:43:27 +02:00
|
|
|
Value HostGroupsTable::NotesAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return hg->GetNotes();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NotesUrlAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return hg->GetNotesUrl();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::ActionUrlAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return hg->GetActionUrl();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
Value HostGroupsTable::MembersAccessor(const Value& row)
|
2013-07-09 18:33:27 +02:00
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr members = new Array();
|
2013-07-09 18:33:27 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
2013-07-09 18:33:27 +02:00
|
|
|
members->Add(host->GetName());
|
|
|
|
}
|
|
|
|
|
|
|
|
return members;
|
|
|
|
}
|
2013-07-11 12:43:27 +02:00
|
|
|
|
|
|
|
Value HostGroupsTable::MembersWithStateAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr members = new Array();
|
2013-07-16 13:26:16 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
2014-11-08 21:17:16 +01:00
|
|
|
Array::Ptr member_state = new Array();
|
2013-07-16 13:26:16 +02:00
|
|
|
member_state->Add(host->GetName());
|
|
|
|
member_state->Add(host->GetState());
|
|
|
|
members->Add(member_state);
|
|
|
|
}
|
|
|
|
|
|
|
|
return members;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::WorstHostStateAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int worst_host = HostUp;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
2013-07-12 15:17:01 +02:00
|
|
|
if (host->GetState() > worst_host)
|
|
|
|
worst_host = host->GetState();
|
|
|
|
}
|
|
|
|
|
|
|
|
return worst_host;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumHostsAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
return hg->GetMembers().size();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumHostsPendingAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_hosts = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
2014-04-03 15:36:13 +02:00
|
|
|
/* no checkresult */
|
|
|
|
if (!host->GetLastCheckResult())
|
2013-07-12 15:17:01 +02:00
|
|
|
num_hosts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_hosts;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumHostsUpAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_hosts = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
2013-07-12 15:17:01 +02:00
|
|
|
if (host->GetState() == HostUp)
|
|
|
|
num_hosts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_hosts;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumHostsDownAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_hosts = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
2013-07-12 15:17:01 +02:00
|
|
|
if (host->GetState() == HostDown)
|
|
|
|
num_hosts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_hosts;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumHostsUnreachAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_hosts = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
2014-04-08 08:54:49 +02:00
|
|
|
if (!host->IsReachable())
|
2013-07-12 15:17:01 +02:00
|
|
|
num_hosts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_hosts;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesAccessor(const Value& row)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
2015-02-15 16:48:09 +01:00
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
|
|
|
int num_services = 0;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
if (hg->GetMembers().size() == 0)
|
|
|
|
return 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
2013-10-03 18:58:48 +02:00
|
|
|
num_services += host->GetServices().size();
|
2013-07-12 15:17:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
2017-02-08 13:00:51 +01:00
|
|
|
Value HostGroupsTable::WorstServiceStateAccessor(const Value& row)
|
2013-07-11 12:43:27 +02:00
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2014-04-08 09:11:54 +02:00
|
|
|
Value worst_service = ServiceOK;
|
2013-07-12 15:17:01 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2013-07-12 15:17:01 +02:00
|
|
|
if (service->GetState() > worst_service)
|
|
|
|
worst_service = service->GetState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return worst_service;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesPendingAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2013-07-12 15:17:01 +02:00
|
|
|
if (!service->GetLastCheckResult())
|
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesOkAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetState() == ServiceOK)
|
2013-07-12 15:17:01 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesWarnAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetState() == ServiceWarning)
|
2013-07-12 15:17:01 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesCritAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetState() == ServiceCritical)
|
2013-07-12 15:17:01 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesUnknownAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetState() == ServiceUnknown)
|
2013-07-12 15:17:01 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::WorstServiceHardStateAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2014-04-08 09:11:54 +02:00
|
|
|
Value worst_service = ServiceOK;
|
2013-07-12 15:17:01 +02:00
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2013-07-12 15:17:01 +02:00
|
|
|
if (service->GetStateType() == StateTypeHard) {
|
|
|
|
if (service->GetState() > worst_service)
|
|
|
|
worst_service = service->GetState();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return worst_service;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesHardOkAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetStateType() == StateTypeHard && service->GetState() == ServiceOK)
|
2013-07-12 15:17:01 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesHardWarnAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetStateType() == StateTypeHard && service->GetState() == ServiceWarning)
|
2013-07-12 15:17:01 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesHardCritAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetStateType() == StateTypeHard && service->GetState() == ServiceCritical)
|
2013-07-12 15:17:01 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesHardUnknownAccessor(const Value& row)
|
|
|
|
{
|
2015-02-15 16:48:09 +01:00
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (!hg)
|
|
|
|
return Empty;
|
|
|
|
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
2016-08-25 06:19:44 +02:00
|
|
|
for (const Host::Ptr& host : hg->GetMembers()) {
|
|
|
|
for (const Service::Ptr& service : host->GetServices()) {
|
2014-04-08 09:11:54 +02:00
|
|
|
if (service->GetStateType() == StateTypeHard && service->GetState() == ServiceUnknown)
|
2013-07-12 15:17:01 +02:00
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|