1 /******************************************************************************
3 * Copyright (C) 2012-2015 Icinga Development Team (http://www.icinga.org) *
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/commandstable.hpp"
21 #include "icinga/icingaapplication.hpp"
22 #include "icinga/checkcommand.hpp"
23 #include "icinga/eventcommand.hpp"
24 #include "icinga/notificationcommand.hpp"
25 #include "icinga/compatutility.hpp"
26 #include "base/dynamictype.hpp"
27 #include "base/objectlock.hpp"
28 #include "base/convert.hpp"
29 #include <boost/foreach.hpp>
30 #include <boost/algorithm/string/replace.hpp>
32 using namespace icinga;
34 CommandsTable::CommandsTable(void)
39 void CommandsTable::AddColumns(Table *table, const String& prefix,
40 const Column::ObjectAccessor& objectAccessor)
42 table->AddColumn(prefix + "name", Column(&CommandsTable::NameAccessor, objectAccessor));
43 table->AddColumn(prefix + "line", Column(&CommandsTable::LineAccessor, objectAccessor));
44 table->AddColumn(prefix + "custom_variable_names", Column(&CommandsTable::CustomVariableNamesAccessor, objectAccessor));
45 table->AddColumn(prefix + "custom_variable_values", Column(&CommandsTable::CustomVariableValuesAccessor, objectAccessor));
46 table->AddColumn(prefix + "custom_variables", Column(&CommandsTable::CustomVariablesAccessor, objectAccessor));
47 table->AddColumn(prefix + "modified_attributes", Column(&CommandsTable::ModifiedAttributesAccessor, objectAccessor));
48 table->AddColumn(prefix + "modified_attributes_list", Column(&CommandsTable::ModifiedAttributesListAccessor, objectAccessor));
51 String CommandsTable::GetName(void) const
56 String CommandsTable::GetPrefix(void) const
61 void CommandsTable::FetchRows(const AddRowFunction& addRowFn)
63 BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjectsByType<CheckCommand>()) {
66 BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjectsByType<EventCommand>()) {
69 BOOST_FOREACH(const DynamicObject::Ptr& object, DynamicType::GetObjectsByType<NotificationCommand>()) {
74 Value CommandsTable::NameAccessor(const Value& row)
76 Command::Ptr command = static_cast<Command::Ptr>(row);
78 return CompatUtility::GetCommandName(command);
81 Value CommandsTable::LineAccessor(const Value& row)
83 Command::Ptr command = static_cast<Command::Ptr>(row);
88 return CompatUtility::GetCommandLine(command);
91 Value CommandsTable::CustomVariableNamesAccessor(const Value& row)
93 Command::Ptr command = static_cast<Command::Ptr>(row);
101 ObjectLock olock(command);
102 vars = CompatUtility::GetCustomAttributeConfig(command);
108 Array::Ptr cv = new Array();
112 BOOST_FOREACH(tie(key, value), vars) {
119 Value CommandsTable::CustomVariableValuesAccessor(const Value& row)
121 Command::Ptr command = static_cast<Command::Ptr>(row);
126 Dictionary::Ptr vars;
129 ObjectLock olock(command);
130 vars = CompatUtility::GetCustomAttributeConfig(command);
136 Array::Ptr cv = new Array();
140 BOOST_FOREACH(tie(key, value), vars) {
147 Value CommandsTable::CustomVariablesAccessor(const Value& row)
149 Command::Ptr command = static_cast<Command::Ptr>(row);
154 Dictionary::Ptr vars;
157 ObjectLock olock(command);
158 vars = CompatUtility::GetCustomAttributeConfig(command);
164 Array::Ptr cv = new Array();
168 BOOST_FOREACH(tie(key, value), vars) {
169 Array::Ptr key_val = new Array();
178 Value CommandsTable::ModifiedAttributesAccessor(const Value& row)
180 Command::Ptr command = static_cast<Command::Ptr>(row);
186 return command->GetModifiedAttributes();
189 Value CommandsTable::ModifiedAttributesListAccessor(const Value& row)
191 Command::Ptr command = static_cast<Command::Ptr>(row);
196 return CompatUtility::GetModifiedAttributesList(command);