2013-07-09 18:33:27 +02:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-03-19 01:02:29 +01:00
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
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"
|
|
|
|
#include "base/dynamictype.hpp"
|
2013-07-09 18:33:27 +02:00
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
|
|
|
|
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));
|
|
|
|
table->AddColumn(prefix + "worst_services_state", Column(&HostGroupsTable::WorstServicesStateAccessor, objectAccessor));
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
void HostGroupsTable::FetchRows(const AddRowFunction& addRowFn)
|
|
|
|
{
|
2013-08-20 11:06:04 +02:00
|
|
|
BOOST_FOREACH(const HostGroup::Ptr& hg, DynamicType::GetObjects<HostGroup>()) {
|
|
|
|
addRowFn(hg);
|
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
|
|
|
{
|
2013-07-10 14:06:46 +02:00
|
|
|
return static_cast<HostGroup::Ptr>(row)->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
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
return static_cast<HostGroup::Ptr>(row)->GetDisplayName();
|
2013-07-09 18:33:27 +02:00
|
|
|
}
|
|
|
|
|
2013-07-11 12:43:27 +02:00
|
|
|
Value HostGroupsTable::NotesAccessor(const Value& row)
|
|
|
|
{
|
2014-04-24 14:48:57 +02:00
|
|
|
return static_cast<HostGroup::Ptr>(row)->GetNotes();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NotesUrlAccessor(const Value& row)
|
|
|
|
{
|
2014-04-24 14:48:57 +02:00
|
|
|
return static_cast<HostGroup::Ptr>(row)->GetNotesUrl();
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::ActionUrlAccessor(const Value& row)
|
|
|
|
{
|
2014-04-24 14:48:57 +02:00
|
|
|
return static_cast<HostGroup::Ptr>(row)->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
|
|
|
{
|
2013-11-06 08:51:56 +01:00
|
|
|
Array::Ptr members = make_shared<Array>();
|
2013-07-09 18:33:27 +02:00
|
|
|
|
2013-07-10 14:06:46 +02:00
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->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)
|
|
|
|
{
|
2013-11-06 08:51:56 +01:00
|
|
|
Array::Ptr members = make_shared<Array>();
|
2013-07-16 13:26:16 +02:00
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
2013-11-06 08:51:56 +01:00
|
|
|
Array::Ptr member_state = make_shared<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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int worst_host = HostUp;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
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)
|
|
|
|
{
|
2013-08-20 12:50:24 +02:00
|
|
|
return static_cast<long>(static_cast<HostGroup::Ptr>(row)->GetMembers().size());
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumHostsPendingAccessor(const Value& row)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_hosts = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_hosts = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
if (host->GetState() == HostUp)
|
|
|
|
num_hosts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_hosts;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumHostsDownAccessor(const Value& row)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_hosts = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
if (host->GetState() == HostDown)
|
|
|
|
num_hosts++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_hosts;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumHostsUnreachAccessor(const Value& row)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_hosts = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->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
|
|
|
int num_services = 0;
|
|
|
|
HostGroup::Ptr hg = static_cast<HostGroup::Ptr>(row);
|
|
|
|
|
|
|
|
if (hg->GetMembers().size() == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(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
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::WorstServicesStateAccessor(const Value& row)
|
|
|
|
{
|
2014-04-08 09:11:54 +02:00
|
|
|
Value worst_service = ServiceOK;
|
2013-07-12 15:17:01 +02:00
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
|
|
|
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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
|
|
|
if (!service->GetLastCheckResult())
|
|
|
|
num_services++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return num_services;
|
2013-07-11 12:43:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Value HostGroupsTable::NumServicesOkAccessor(const Value& row)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(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)
|
|
|
|
{
|
2014-04-08 09:11:54 +02:00
|
|
|
Value worst_service = ServiceOK;
|
2013-07-12 15:17:01 +02:00
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(const Service::Ptr& service, host->GetServices()) {
|
|
|
|
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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(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)
|
|
|
|
{
|
2013-07-12 15:17:01 +02:00
|
|
|
int num_services = 0;
|
|
|
|
|
|
|
|
BOOST_FOREACH(const Host::Ptr& host, static_cast<HostGroup::Ptr>(row)->GetMembers()) {
|
|
|
|
BOOST_FOREACH(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
|
|
|
}
|