mirror of https://github.com/Icinga/icinga2.git
parent
a26df23e3d
commit
098dbe7506
|
@ -19,9 +19,18 @@ mkclass_target(listener.ti listener.th)
|
|||
|
||||
mkembedconfig_target(livestatus-type.conf livestatus-type.cpp)
|
||||
|
||||
add_library(livestatus SHARED aggregator.cpp andfilter.cpp attributefilter.cpp avgaggregator.cpp column.cpp combinerfilter.cpp commandstable.cpp commentstable.cpp contactgroupstable.cpp contactstable.cpp countaggregator.cpp downtimestable.cpp filter.cpp historytable.cpp hostgroupstable.cpp hoststable.cpp invavgaggregator.cpp invsumaggregator.cpp listener.cpp listener.th logutility.cpp logtable.cpp maxaggregator.cpp minaggregator.cpp negatefilter.cpp orfilter.cpp query.cpp servicegroupstable.cpp servicestable.cpp statehisttable.cpp statustable.cpp stdaggregator.cpp sumaggregator.cpp table.cpp timeperiodstable.cpp livestatus-type.cpp)
|
||||
add_library(livestatus SHARED aggregator.cpp andfilter.cpp attributefilter.cpp
|
||||
avgaggregator.cpp column.cpp combinerfilter.cpp commandstable.cpp
|
||||
commentstable.cpp contactgroupstable.cpp contactstable.cpp countaggregator.cpp
|
||||
downtimestable.cpp endpointstable.cpp filter.cpp historytable.cpp
|
||||
hostgroupstable.cpp hoststable.cpp invavgaggregator.cpp invsumaggregator.cpp
|
||||
listener.cpp listener.th logutility.cpp logtable.cpp maxaggregator.cpp
|
||||
minaggregator.cpp negatefilter.cpp orfilter.cpp query.cpp
|
||||
servicegroupstable.cpp servicestable.cpp statehisttable.cpp
|
||||
statustable.cpp stdaggregator.cpp sumaggregator.cpp table.cpp
|
||||
timeperiodstable.cpp livestatus-type.cpp)
|
||||
|
||||
target_link_libraries(livestatus ${Boost_LIBRARIES} base config icinga)
|
||||
target_link_libraries(livestatus ${Boost_LIBRARIES} base config icinga remote)
|
||||
|
||||
set_target_properties (
|
||||
livestatus PROPERTIES
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
||||
* *
|
||||
* 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. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "livestatus/endpointstable.h"
|
||||
#include "icinga/host.h"
|
||||
#include "icinga/service.h"
|
||||
#include "icinga/icingaapplication.h"
|
||||
#include "remote/endpoint.h"
|
||||
#include "base/dynamictype.h"
|
||||
#include "base/objectlock.h"
|
||||
#include "base/convert.h"
|
||||
#include "base/utility.h"
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
#include <boost/tuple/tuple.hpp>
|
||||
#include <boost/algorithm/string/replace.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
EndpointsTable::EndpointsTable(void)
|
||||
{
|
||||
AddColumns(this);
|
||||
}
|
||||
|
||||
void EndpointsTable::AddColumns(Table *table, const String& prefix,
|
||||
const Column::ObjectAccessor& objectAccessor)
|
||||
{
|
||||
table->AddColumn(prefix + "name", Column(&EndpointsTable::NameAccessor, objectAccessor));
|
||||
table->AddColumn(prefix + "identity", Column(&EndpointsTable::IdentityAccessor, objectAccessor));
|
||||
table->AddColumn(prefix + "node", Column(&EndpointsTable::NodeAccessor, objectAccessor));
|
||||
table->AddColumn(prefix + "is_connected", Column(&EndpointsTable::IsConnectedAccessor, objectAccessor));
|
||||
}
|
||||
|
||||
String EndpointsTable::GetName(void) const
|
||||
{
|
||||
return "endpoints";
|
||||
}
|
||||
|
||||
void EndpointsTable::FetchRows(const AddRowFunction& addRowFn)
|
||||
{
|
||||
BOOST_FOREACH(const Endpoint::Ptr& endpoint, DynamicType::GetObjects<Endpoint>()) {
|
||||
addRowFn(endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
Value EndpointsTable::NameAccessor(const Value& row)
|
||||
{
|
||||
Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
|
||||
|
||||
if (!endpoint)
|
||||
return Empty;
|
||||
|
||||
return endpoint->GetName();
|
||||
}
|
||||
|
||||
Value EndpointsTable::IdentityAccessor(const Value& row)
|
||||
{
|
||||
Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
|
||||
|
||||
if (!endpoint)
|
||||
return Empty;
|
||||
|
||||
return endpoint->GetName();
|
||||
}
|
||||
|
||||
Value EndpointsTable::NodeAccessor(const Value& row)
|
||||
{
|
||||
Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
|
||||
|
||||
if (!endpoint)
|
||||
return Empty;
|
||||
|
||||
return IcingaApplication::GetInstance()->GetNodeName();
|
||||
}
|
||||
|
||||
Value EndpointsTable::IsConnectedAccessor(const Value& row)
|
||||
{
|
||||
Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
|
||||
|
||||
if (!endpoint)
|
||||
return Empty;
|
||||
|
||||
unsigned int is_connected = endpoint->IsConnected() ? 1 : 0;
|
||||
|
||||
/* if identity is equal to node, fake is_connected */
|
||||
if (endpoint->GetName() == IcingaApplication::GetInstance()->GetNodeName())
|
||||
is_connected = 1;
|
||||
|
||||
return is_connected;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
||||
* *
|
||||
* 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. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef ENDPOINTSTABLE_H
|
||||
#define ENDPOINTSTABLE_H
|
||||
|
||||
#include "livestatus/table.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
/**
|
||||
* @ingroup livestatus
|
||||
*/
|
||||
class EndpointsTable : public Table
|
||||
{
|
||||
public:
|
||||
DECLARE_PTR_TYPEDEFS(EndpointsTable);
|
||||
|
||||
EndpointsTable(void);
|
||||
|
||||
static void AddColumns(Table *table, const String& prefix = String(),
|
||||
const Column::ObjectAccessor& objectAccessor = Column::ObjectAccessor());
|
||||
|
||||
virtual String GetName(void) const;
|
||||
|
||||
protected:
|
||||
virtual void FetchRows(const AddRowFunction& addRowFn);
|
||||
|
||||
static Value NameAccessor(const Value& row);
|
||||
static Value IdentityAccessor(const Value& row);
|
||||
static Value NodeAccessor(const Value& row);
|
||||
static Value IsConnectedAccessor(const Value& row);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* ENDPOINTSTABLE_H */
|
|
@ -28,6 +28,7 @@
|
|||
#include "livestatus/commandstable.h"
|
||||
#include "livestatus/commentstable.h"
|
||||
#include "livestatus/downtimestable.h"
|
||||
#include "livestatus/endpointstable.h"
|
||||
#include "livestatus/timeperiodstable.h"
|
||||
#include "livestatus/logtable.h"
|
||||
#include "livestatus/statehisttable.h"
|
||||
|
@ -71,6 +72,8 @@ Table::Ptr Table::GetByName(const String& name, const String& compat_log_path, c
|
|||
return make_shared<LogTable>(compat_log_path, from, until);
|
||||
else if (name == "statehist")
|
||||
return make_shared<StateHistTable>(compat_log_path, from, until);
|
||||
else if (name == "endpoints")
|
||||
return make_shared<EndpointsTable>();
|
||||
|
||||
return Table::Ptr();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
GET endpoints
|
||||
ResponseHeader: fixed16
|
||||
|
Loading…
Reference in New Issue