diff --git a/components/livestatus/contactgroupstable.cpp b/components/livestatus/contactgroupstable.cpp new file mode 100644 index 000000000..6db954375 --- /dev/null +++ b/components/livestatus/contactgroupstable.cpp @@ -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& addRowFn) +{ + BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("UserGroup")) { + addRowFn(object); + } +} + +Value ContactGroupsTable::NameAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetName(); +} + +Value ContactGroupsTable::MembersAccessor(const Object::Ptr& object) +{ + Array::Ptr members = boost::make_shared(); + + BOOST_FOREACH(const User::Ptr& user, static_pointer_cast(object)->GetMembers()) { + members->Add(user->GetName()); + } + + return members; +} \ No newline at end of file diff --git a/components/livestatus/contactgroupstable.h b/components/livestatus/contactgroupstable.h new file mode 100644 index 000000000..94c353f65 --- /dev/null +++ b/components/livestatus/contactgroupstable.h @@ -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 Ptr; + typedef weak_ptr WeakPtr; + + ContactGroupsTable(void); + + virtual String GetName(void) const; + +protected: + virtual void FetchRows(const function& addRowFn); + + static Value NameAccessor(const Object::Ptr& object); + static Value MembersAccessor(const Object::Ptr& object); +}; + +} + +#endif /* CONTACTGROUPSTABLE_H */ diff --git a/components/livestatus/contactstable.cpp b/components/livestatus/contactstable.cpp new file mode 100644 index 000000000..ebc216d8f --- /dev/null +++ b/components/livestatus/contactstable.cpp @@ -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& addRowFn) +{ + BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjects("User")) { + addRowFn(object); + } +} + +Value ContactsTable::NameAccessor(const Object::Ptr& object) +{ + return static_pointer_cast(object)->GetName(); +} diff --git a/components/livestatus/contactstable.h b/components/livestatus/contactstable.h new file mode 100644 index 000000000..6efe2d536 --- /dev/null +++ b/components/livestatus/contactstable.h @@ -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 Ptr; + typedef weak_ptr WeakPtr; + + ContactsTable(void); + + virtual String GetName(void) const; + +protected: + virtual void FetchRows(const function& addRowFn); + + static Value NameAccessor(const Object::Ptr& object); + static Value MembersAccessor(const Object::Ptr& object); +}; + +} + +#endif /* CONTACTSTABLE_H */ diff --git a/components/livestatus/i2-livestatus.h b/components/livestatus/i2-livestatus.h index 1d2904fd4..765173feb 100644 --- a/components/livestatus/i2-livestatus.h +++ b/components/livestatus/i2-livestatus.h @@ -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 */ diff --git a/components/livestatus/livestatus.vcxproj b/components/livestatus/livestatus.vcxproj index e330d7fb9..dc0a478d4 100644 --- a/components/livestatus/livestatus.vcxproj +++ b/components/livestatus/livestatus.vcxproj @@ -19,6 +19,8 @@ + + @@ -30,6 +32,8 @@ + + diff --git a/components/livestatus/livestatus.vcxproj.filters b/components/livestatus/livestatus.vcxproj.filters index 732473d02..a3f9f6b58 100644 --- a/components/livestatus/livestatus.vcxproj.filters +++ b/components/livestatus/livestatus.vcxproj.filters @@ -30,6 +30,12 @@ Headerdateien + + Headerdateien + + + Headerdateien + @@ -50,5 +56,11 @@ Quelldateien + + Quelldateien + + + Quelldateien + \ No newline at end of file diff --git a/components/livestatus/table.cpp b/components/livestatus/table.cpp index 61e2c1629..518c9c9ca 100644 --- a/components/livestatus/table.cpp +++ b/components/livestatus/table.cpp @@ -29,6 +29,10 @@ Table::Ptr Table::GetByName(const String& name) { if (name == "status") return boost::make_shared(); + else if (name == "contactgroups") + return boost::make_shared(); + else if (name == "contacts") + return boost::make_shared(); 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(); +} + +Value Table::EmptyDictionaryAccessor(const Object::Ptr&) +{ + return boost::make_shared(); +} diff --git a/components/livestatus/table.h b/components/livestatus/table.h new file mode 100644 index 000000000..82a9f9ce5 --- /dev/null +++ b/components/livestatus/table.h @@ -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 Ptr; + typedef weak_ptr
WeakPtr; + + static Table::Ptr GetByName(const String& name); + + typedef function ColumnAccessor; + + virtual String GetName(void) const = 0; + + vector FilterRows(const Filter::Ptr& filter); + + ColumnAccessor GetColumn(const String& name) const; + vector GetColumnNames(void) const; + +protected: + Table(void); + + void AddColumn(const String& name, const ColumnAccessor& accessor); + + virtual void FetchRows(const function& 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 m_Columns; + + static void FilteredAddRow(vector& rs, const Filter::Ptr& filter, const Object::Ptr& object); +}; + +} + +#endif /* TABLE_H */