Added dummy tables: contactgroups and contacts.

This commit is contained in:
Gunnar Beutner 2013-03-10 09:55:46 +01:00
parent d7efa9e24c
commit 8bda3bc63c
9 changed files with 323 additions and 0 deletions

View File

@ -0,0 +1,58 @@
/******************************************************************************
* 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;
ContactGroupsTable::ContactGroupsTable(void)
{
AddColumn("name", &ContactGroupsTable::NameAccessor);
AddColumn("alias", &ContactGroupsTable::NameAccessor);
AddColumn("members", &ContactGroupsTable::MembersAccessor);
}
String ContactGroupsTable::GetName(void) const
{
return "contactgroups";
}
void ContactGroupsTable::FetchRows(const function<void (const Object::Ptr&)>& addRowFn)
{
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) {
addRowFn(object);
}
}
Value ContactGroupsTable::NameAccessor(const Object::Ptr& object)
{
return static_pointer_cast<UserGroup>(object)->GetName();
}
Value ContactGroupsTable::MembersAccessor(const Object::Ptr& object)
{
Array::Ptr members = boost::make_shared<Array>();
BOOST_FOREACH(const User::Ptr& user, static_pointer_cast<UserGroup>(object)->GetMembers()) {
members->Add(user->GetName());
}
return members;
}

View File

@ -0,0 +1,48 @@
/******************************************************************************
* 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 CONTACTGROUPSTABLE_H
#define CONTACTGROUPSTABLE_H
namespace livestatus
{
/**
* @ingroup livestatus
*/
class ContactGroupsTable : public Table
{
public:
typedef shared_ptr<ContactGroupsTable> Ptr;
typedef weak_ptr<ContactGroupsTable> WeakPtr;
ContactGroupsTable(void);
virtual String GetName(void) const;
protected:
virtual void FetchRows(const function<void (const Object::Ptr&)>& addRowFn);
static Value NameAccessor(const Object::Ptr& object);
static Value MembersAccessor(const Object::Ptr& object);
};
}
#endif /* CONTACTGROUPSTABLE_H */

View File

@ -0,0 +1,60 @@
/******************************************************************************
* 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;
ContactsTable::ContactsTable(void)
{
AddColumn("name", &ContactsTable::NameAccessor);
AddColumn("alias", &ContactsTable::NameAccessor);
AddColumn("email", &Table::EmptyStringAccessor);
AddColumn("pager", &Table::EmptyStringAccessor);
AddColumn("host_notification_period", &Table::EmptyStringAccessor);
AddColumn("service_notification_period", &Table::EmptyStringAccessor);
AddColumn("can_submit_commands", &Table::OneAccessor);
AddColumn("host_notifications_enabled", &Table::OneAccessor);
AddColumn("service_notifications_enabled", &Table::OneAccessor);
AddColumn("in_host_notification_period", &Table::OneAccessor);
AddColumn("in_service_notification_period", &Table::OneAccessor);
AddColumn("custom_variable_names", &Table::EmptyArrayAccessor);
AddColumn("custom_variable_values", &Table::EmptyArrayAccessor);
AddColumn("custom_variables", &Table::EmptyDictionaryAccessor);
AddColumn("modified_attributes", &Table::ZeroAccessor);
AddColumn("modified_attributes_list", &Table::EmptyArrayAccessor);
}
String ContactsTable::GetName(void) const
{
return "contacts";
}
void ContactsTable::FetchRows(const function<void (const Object::Ptr&)>& addRowFn)
{
BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) {
addRowFn(object);
}
}
Value ContactsTable::NameAccessor(const Object::Ptr& object)
{
return static_pointer_cast<User>(object)->GetName();
}

View File

@ -0,0 +1,48 @@
/******************************************************************************
* 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 CONTACTSTABLE_H
#define CONTACTSTABLE_H
namespace livestatus
{
/**
* @ingroup livestatus
*/
class ContactsTable : public Table
{
public:
typedef shared_ptr<ContactGroupsTable> Ptr;
typedef weak_ptr<ContactGroupsTable> WeakPtr;
ContactsTable(void);
virtual String GetName(void) const;
protected:
virtual void FetchRows(const function<void (const Object::Ptr&)>& addRowFn);
static Value NameAccessor(const Object::Ptr& object);
static Value MembersAccessor(const Object::Ptr& object);
};
}
#endif /* CONTACTSTABLE_H */

View File

@ -37,6 +37,8 @@ using namespace icinga;
#include "filter.h"
#include "table.h"
#include "statustable.h"
#include "contactgroupstable.h"
#include "contactstable.h"
#include "component.h"
#endif /* I2LIVESTATUS_H */

View File

@ -19,6 +19,8 @@
</ProjectConfiguration>
</ItemGroup>
<ItemGroup>
<ClInclude Include="contactgroupstable.h" />
<ClInclude Include="contactstable.h" />
<ClInclude Include="filter.h" />
<ClInclude Include="i2-livestatus.h" />
<ClInclude Include="component.h" />
@ -30,6 +32,8 @@
<ItemGroup>
<ClCompile Include="component.cpp" />
<ClCompile Include="connection.cpp" />
<ClCompile Include="contactgroupstable.cpp" />
<ClCompile Include="contactstable.cpp" />
<ClCompile Include="filter.cpp" />
<ClCompile Include="query.cpp" />
<ClCompile Include="statustable.cpp" />

View File

@ -30,6 +30,12 @@
<ClInclude Include="filter.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="contactgroupstable.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="contactstable.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="component.cpp">
@ -50,5 +56,11 @@
<ClCompile Include="filter.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="contactgroupstable.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="contactstable.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
</Project>

View File

@ -29,6 +29,10 @@ Table::Ptr Table::GetByName(const String& name)
{
if (name == "status")
return boost::make_shared<StatusTable>();
else if (name == "contactgroups")
return boost::make_shared<ContactGroupsTable>();
else if (name == "contacts")
return boost::make_shared<ContactsTable>();
return Table::Ptr();
}
@ -79,3 +83,23 @@ Value Table::ZeroAccessor(const Object::Ptr&)
{
return 0;
}
Value Table::OneAccessor(const Object::Ptr&)
{
return 0;
}
Value Table::EmptyStringAccessor(const Object::Ptr&)
{
return "";
}
Value Table::EmptyArrayAccessor(const Object::Ptr&)
{
return boost::make_shared<Array>();
}
Value Table::EmptyDictionaryAccessor(const Object::Ptr&)
{
return boost::make_shared<Dictionary>();
}

View File

@ -0,0 +1,67 @@
/******************************************************************************
* 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 TABLE_H
#define TABLE_H
namespace livestatus
{
/**
* @ingroup livestatus
*/
class Table : public Object
{
public:
typedef shared_ptr<Table> Ptr;
typedef weak_ptr<Table> WeakPtr;
static Table::Ptr GetByName(const String& name);
typedef function<Value (const Object::Ptr&)> ColumnAccessor;
virtual String GetName(void) const = 0;
vector<Object::Ptr> FilterRows(const Filter::Ptr& filter);
ColumnAccessor GetColumn(const String& name) const;
vector<String> GetColumnNames(void) const;
protected:
Table(void);
void AddColumn(const String& name, const ColumnAccessor& accessor);
virtual void FetchRows(const function<void (const Object::Ptr&)>& addRowFn) = 0;
static Value ZeroAccessor(const Object::Ptr&);
static Value OneAccessor(const Object::Ptr&);
static Value EmptyStringAccessor(const Object::Ptr&);
static Value EmptyArrayAccessor(const Object::Ptr&);
static Value EmptyDictionaryAccessor(const Object::Ptr&);
private:
map<String, ColumnAccessor> m_Columns;
static void FilteredAddRow(vector<Object::Ptr>& rs, const Filter::Ptr& filter, const Object::Ptr& object);
};
}
#endif /* TABLE_H */