mirror of https://github.com/Icinga/icinga2.git
Implement filters for "and" and "or".
This commit is contained in:
parent
8bda3bc63c
commit
ad77c873ba
|
@ -4,12 +4,16 @@ pkglib_LTLIBRARIES = \
|
|||
livestatus.la
|
||||
|
||||
livestatus_la_SOURCES = \
|
||||
andfilter.cpp \
|
||||
andfilter.h \
|
||||
component.cpp \
|
||||
component.h \
|
||||
connection.cpp \
|
||||
connection.h \
|
||||
filter.cpp \
|
||||
filter.h \
|
||||
orfilter.cpp \
|
||||
orfilter.h \
|
||||
query.cpp \
|
||||
query.h \
|
||||
statustable.cpp \
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 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 "i2-livestatus.h"
|
||||
|
||||
using namespace icinga;
|
||||
using namespace livestatus;
|
||||
|
||||
AndFilter::AndFilter(void)
|
||||
{ }
|
||||
|
||||
bool AndFilter::Apply(const Object::Ptr& object)
|
||||
{
|
||||
BOOST_FOREACH(const Filter::Ptr& filter, m_Filters) {
|
||||
if (!filter->Apply(object))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void AndFilter::AddSubFilter(const Filter::Ptr& filter)
|
||||
{
|
||||
m_Filters.push_back(filter);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 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 ANDFILTER_H
|
||||
#define ANDFILTER_H
|
||||
|
||||
namespace livestatus
|
||||
{
|
||||
|
||||
/**
|
||||
* @ingroup livestatus
|
||||
*/
|
||||
class AndFilter : public Filter
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<AndFilter> Ptr;
|
||||
typedef weak_ptr<AndFilter> WeakPtr;
|
||||
|
||||
AndFilter(void);
|
||||
|
||||
virtual bool Apply(const Object::Ptr& object);
|
||||
|
||||
void AddSubFilter(const Filter::Ptr& filter);
|
||||
|
||||
private:
|
||||
vector<Filter::Ptr> m_Filters;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* ANDFILTER_H */
|
|
@ -35,6 +35,8 @@ using namespace icinga;
|
|||
#include "connection.h"
|
||||
#include "query.h"
|
||||
#include "filter.h"
|
||||
#include "orfilter.h"
|
||||
#include "andfilter.h"
|
||||
#include "table.h"
|
||||
#include "statustable.h"
|
||||
#include "contactgroupstable.h"
|
||||
|
|
|
@ -19,22 +19,26 @@
|
|||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="andfilter.h" />
|
||||
<ClInclude Include="contactgroupstable.h" />
|
||||
<ClInclude Include="contactstable.h" />
|
||||
<ClInclude Include="filter.h" />
|
||||
<ClInclude Include="i2-livestatus.h" />
|
||||
<ClInclude Include="component.h" />
|
||||
<ClInclude Include="connection.h" />
|
||||
<ClInclude Include="orfilter.h" />
|
||||
<ClInclude Include="query.h" />
|
||||
<ClInclude Include="statustable.h" />
|
||||
<ClInclude Include="table.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="andfilter.cpp" />
|
||||
<ClCompile Include="component.cpp" />
|
||||
<ClCompile Include="connection.cpp" />
|
||||
<ClCompile Include="contactgroupstable.cpp" />
|
||||
<ClCompile Include="contactstable.cpp" />
|
||||
<ClCompile Include="filter.cpp" />
|
||||
<ClCompile Include="orfilter.cpp" />
|
||||
<ClCompile Include="query.cpp" />
|
||||
<ClCompile Include="statustable.cpp" />
|
||||
<ClCompile Include="table.cpp" />
|
||||
|
|
|
@ -36,6 +36,12 @@
|
|||
<ClInclude Include="contactstable.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="orfilter.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="andfilter.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="component.cpp">
|
||||
|
@ -62,5 +68,11 @@
|
|||
<ClCompile Include="contactstable.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="orfilter.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="andfilter.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -0,0 +1,44 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 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 "i2-livestatus.h"
|
||||
|
||||
using namespace icinga;
|
||||
using namespace livestatus;
|
||||
|
||||
OrFilter::OrFilter(void)
|
||||
{ }
|
||||
|
||||
bool OrFilter::Apply(const Object::Ptr& object)
|
||||
{
|
||||
if (m_Filters.empty())
|
||||
return true;
|
||||
|
||||
BOOST_FOREACH(const Filter::Ptr& filter, m_Filters) {
|
||||
if (filter->Apply(object))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OrFilter::AddSubFilter(const Filter::Ptr& filter)
|
||||
{
|
||||
m_Filters.push_back(filter);
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 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 ORFILTER_H
|
||||
#define ORFILTER_H
|
||||
|
||||
namespace livestatus
|
||||
{
|
||||
|
||||
/**
|
||||
* @ingroup livestatus
|
||||
*/
|
||||
class OrFilter : public Filter
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<OrFilter> Ptr;
|
||||
typedef weak_ptr<OrFilter> WeakPtr;
|
||||
|
||||
OrFilter(void);
|
||||
|
||||
virtual bool Apply(const Object::Ptr& object);
|
||||
|
||||
void AddSubFilter(const Filter::Ptr& filter);
|
||||
|
||||
private:
|
||||
vector<Filter::Ptr> m_Filters;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* ORFILTER_H */
|
Loading…
Reference in New Issue