]> granicus.if.org Git - icinga2/blob - lib/livestatus/timeperiodstable.cpp
Merge pull request #7185 from Icinga/bugfix/gelfwriter-wrong-log-facility
[icinga2] / lib / livestatus / timeperiodstable.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "livestatus/timeperiodstable.hpp"
4 #include "icinga/icingaapplication.hpp"
5 #include "icinga/timeperiod.hpp"
6 #include "base/configtype.hpp"
7 #include "base/objectlock.hpp"
8 #include "base/convert.hpp"
9 #include "base/utility.hpp"
10 #include <boost/algorithm/string/replace.hpp>
11
12 using namespace icinga;
13
14 TimePeriodsTable::TimePeriodsTable()
15 {
16         AddColumns(this);
17 }
18
19 void TimePeriodsTable::AddColumns(Table *table, const String& prefix,
20         const Column::ObjectAccessor& objectAccessor)
21 {
22         table->AddColumn(prefix + "name", Column(&TimePeriodsTable::NameAccessor, objectAccessor));
23         table->AddColumn(prefix + "alias", Column(&TimePeriodsTable::AliasAccessor, objectAccessor));
24         table->AddColumn(prefix + "in", Column(&TimePeriodsTable::InAccessor, objectAccessor));
25 }
26
27 String TimePeriodsTable::GetName() const
28 {
29         return "timeperiod";
30 }
31
32 String TimePeriodsTable::GetPrefix() const
33 {
34         return "timeperiod";
35 }
36
37 void TimePeriodsTable::FetchRows(const AddRowFunction& addRowFn)
38 {
39         for (const TimePeriod::Ptr& tp : ConfigType::GetObjectsByType<TimePeriod>()) {
40                 if (!addRowFn(tp, LivestatusGroupByNone, Empty))
41                         return;
42         }
43 }
44
45 Value TimePeriodsTable::NameAccessor(const Value& row)
46 {
47         return static_cast<TimePeriod::Ptr>(row)->GetName();
48 }
49
50 Value TimePeriodsTable::AliasAccessor(const Value& row)
51 {
52         return static_cast<TimePeriod::Ptr>(row)->GetDisplayName();
53 }
54
55 Value TimePeriodsTable::InAccessor(const Value& row)
56 {
57         return (static_cast<TimePeriod::Ptr>(row)->IsInside(Utility::GetTime()) ? 1 : 0);
58 }