]> granicus.if.org Git - icinga2/blob - lib/livestatus/timeperiodstable.cpp
Merge pull request #6509 from gunnarbeutner/feature/real-constants
[icinga2] / lib / livestatus / timeperiodstable.cpp
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
4  *                                                                            *
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.                     *
9  *                                                                            *
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.                               *
14  *                                                                            *
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  ******************************************************************************/
19
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>
28
29 using namespace icinga;
30
31 TimePeriodsTable::TimePeriodsTable()
32 {
33         AddColumns(this);
34 }
35
36 void TimePeriodsTable::AddColumns(Table *table, const String& prefix,
37         const Column::ObjectAccessor& objectAccessor)
38 {
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));
42 }
43
44 String TimePeriodsTable::GetName() const
45 {
46         return "timeperiod";
47 }
48
49 String TimePeriodsTable::GetPrefix() const
50 {
51         return "timeperiod";
52 }
53
54 void TimePeriodsTable::FetchRows(const AddRowFunction& addRowFn)
55 {
56         for (const TimePeriod::Ptr& tp : ConfigType::GetObjectsByType<TimePeriod>()) {
57                 if (!addRowFn(tp, LivestatusGroupByNone, Empty))
58                         return;
59         }
60 }
61
62 Value TimePeriodsTable::NameAccessor(const Value& row)
63 {
64         return static_cast<TimePeriod::Ptr>(row)->GetName();
65 }
66
67 Value TimePeriodsTable::AliasAccessor(const Value& row)
68 {
69         return static_cast<TimePeriod::Ptr>(row)->GetDisplayName();
70 }
71
72 Value TimePeriodsTable::InAccessor(const Value& row)
73 {
74         return (static_cast<TimePeriod::Ptr>(row)->IsInside(Utility::GetTime()) ? 1 : 0);
75 }