1 /******************************************************************************
3 * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
5 * This program is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU General Public License *
7 * as published by the Free Software Foundation; either version 2 *
8 * of the License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software Foundation *
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ******************************************************************************/
20 #include "livestatus/timeperiodstable.hpp"
21 #include "icinga/icingaapplication.hpp"
22 #include "icinga/timeperiod.hpp"
23 #include "base/configtype.hpp"
24 #include "base/objectlock.hpp"
25 #include "base/convert.hpp"
26 #include "base/utility.hpp"
27 #include <boost/algorithm/string/replace.hpp>
29 using namespace icinga;
31 TimePeriodsTable::TimePeriodsTable()
36 void TimePeriodsTable::AddColumns(Table *table, const String& prefix,
37 const Column::ObjectAccessor& objectAccessor)
39 table->AddColumn(prefix + "name", Column(&TimePeriodsTable::NameAccessor, objectAccessor));
40 table->AddColumn(prefix + "alias", Column(&TimePeriodsTable::AliasAccessor, objectAccessor));
41 table->AddColumn(prefix + "in", Column(&TimePeriodsTable::InAccessor, objectAccessor));
44 String TimePeriodsTable::GetName() const
49 String TimePeriodsTable::GetPrefix() const
54 void TimePeriodsTable::FetchRows(const AddRowFunction& addRowFn)
56 for (const TimePeriod::Ptr& tp : ConfigType::GetObjectsByType<TimePeriod>()) {
57 if (!addRowFn(tp, LivestatusGroupByNone, Empty))
62 Value TimePeriodsTable::NameAccessor(const Value& row)
64 return static_cast<TimePeriod::Ptr>(row)->GetName();
67 Value TimePeriodsTable::AliasAccessor(const Value& row)
69 return static_cast<TimePeriod::Ptr>(row)->GetDisplayName();
72 Value TimePeriodsTable::InAccessor(const Value& row)
74 return (static_cast<TimePeriod::Ptr>(row)->IsInside(Utility::GetTime()) ? 1 : 0);