mirror of https://github.com/Icinga/icinga2.git
Implemented ConfigItemBuilder class.
This commit is contained in:
parent
e0bf25e907
commit
37cf22aaf0
|
@ -32,6 +32,7 @@ libcib_la_CPPFLAGS = \
|
|||
-DI2_CIB_BUILD \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/dyn \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/icinga \
|
||||
-I${top_srcdir}/third-party/popen-noshell
|
||||
|
@ -46,6 +47,7 @@ libcib_la_LIBADD = \
|
|||
$(BOOST_SIGNALS_LIB) \
|
||||
$(BOOST_THREAD_LIB) \
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/dyn/libdyn.la \
|
||||
${top_builddir}/jsonrpc/libjsonrpc.la \
|
||||
${top_builddir}/icinga/libicinga.la \
|
||||
${top_builddir}/third-party/popen-noshell/libpopen_noshell.la
|
||||
|
|
|
@ -14,9 +14,12 @@ void CIB::RequireInformation(InformationType types)
|
|||
Component::Ptr component = app->GetComponent("cibsync");
|
||||
|
||||
if (!component) {
|
||||
ConfigObject::Ptr cibsyncComponentConfig = boost::make_shared<ConfigObject>("component", "cibsync");
|
||||
cibsyncComponentConfig->SetLocal(true);
|
||||
cibsyncComponentConfig->Commit();
|
||||
ConfigItemBuilder::Ptr cb = boost::make_shared<ConfigItemBuilder>();
|
||||
cb->SetType("component");
|
||||
cb->SetName("cibsync");
|
||||
cb->SetLocal(true);
|
||||
ConfigItem::Ptr ci = cb->Compile();
|
||||
ci->Commit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
* updates from all the other Icinga components.
|
||||
*/
|
||||
|
||||
#include <i2-dyn.h>
|
||||
#include <i2-icinga.h>
|
||||
|
||||
#ifdef I2_CIB_BUILD
|
||||
|
|
|
@ -11,6 +11,7 @@ checker_la_SOURCES = \
|
|||
checker_la_CPPFLAGS = \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/dyn \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/icinga \
|
||||
-I${top_srcdir}/cib
|
||||
|
@ -26,6 +27,7 @@ checker_la_LIBADD = \
|
|||
$(BOOST_SIGNALS_LIB) \
|
||||
$(BOOST_THREAD_LIB) \
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/dyn/libdyn.la \
|
||||
${top_builddir}/jsonrpc/libjsonrpc.la \
|
||||
${top_builddir}/icinga/libicinga.la \
|
||||
${top_builddir}/cib/libcib.la
|
||||
|
|
|
@ -11,6 +11,7 @@ cibsync_la_SOURCES = \
|
|||
cibsync_la_CPPFLAGS = \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/dyn \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/icinga \
|
||||
-I${top_srcdir}/cib
|
||||
|
@ -26,6 +27,7 @@ cibsync_la_LIBADD = \
|
|||
$(BOOST_SIGNALS_LIB) \
|
||||
$(BOOST_THREAD_LIB) \
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/dyn/libdyn.la \
|
||||
${top_builddir}/jsonrpc/libjsonrpc.la \
|
||||
${top_builddir}/icinga/libicinga.la \
|
||||
${top_builddir}/cib/libcib.la
|
||||
|
|
|
@ -11,6 +11,7 @@ compat_la_SOURCES = \
|
|||
compat_la_CPPFLAGS = \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/dyn \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/icinga \
|
||||
-I${top_srcdir}/cib
|
||||
|
@ -26,6 +27,7 @@ compat_la_LIBADD = \
|
|||
$(BOOST_SIGNALS_LIB) \
|
||||
$(BOOST_THREAD_LIB) \
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/dyn/libdyn.la \
|
||||
${top_builddir}/jsonrpc/libjsonrpc.la \
|
||||
${top_builddir}/icinga/libicinga.la \
|
||||
${top_builddir}/cib/libcib.la
|
||||
|
|
|
@ -73,7 +73,8 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
|||
Dictionary::Iterator it;
|
||||
for (it = serviceDescs->Begin(); it != serviceDescs->End(); it++) {
|
||||
Variant desc = it->second;
|
||||
ConfigItem::Ptr serviceItem;
|
||||
|
||||
ConfigItemBuilder::Ptr builder = boost::make_shared<ConfigItemBuilder>(item->GetDebugInfo());
|
||||
|
||||
string name;
|
||||
|
||||
|
@ -82,60 +83,34 @@ void ConvenienceComponent::HostCommittedHandler(const ConfigItem::Ptr& item)
|
|||
namebuf << item->GetName() << "-" << string(desc);
|
||||
name = namebuf.str();
|
||||
|
||||
serviceItem = boost::make_shared<ConfigItem>("service", name, item->GetDebugInfo());
|
||||
serviceItem->AddParent(desc);
|
||||
builder->SetType("service");
|
||||
builder->SetName(name);
|
||||
|
||||
ExpressionList::Ptr exprl = boost::make_shared<ExpressionList>();
|
||||
|
||||
Expression localExpr("__local", OperatorSet, 1, item->GetDebugInfo());
|
||||
exprl->AddExpression(localExpr);
|
||||
|
||||
Expression abstractExpr("__abstract", OperatorSet, 0, item->GetDebugInfo());
|
||||
exprl->AddExpression(abstractExpr);
|
||||
|
||||
Expression typeExpr("__type", OperatorSet, "service", item->GetDebugInfo());
|
||||
exprl->AddExpression(typeExpr);
|
||||
|
||||
Expression nameExpr("__name", OperatorSet, name, item->GetDebugInfo());
|
||||
exprl->AddExpression(nameExpr);
|
||||
|
||||
Expression hostExpr("host_name", OperatorSet, item->GetName(), item->GetDebugInfo());
|
||||
exprl->AddExpression(hostExpr);
|
||||
|
||||
Expression aliasExpr("alias", OperatorSet, string(desc), item->GetDebugInfo());
|
||||
exprl->AddExpression(aliasExpr);
|
||||
builder->AddParent(desc);
|
||||
builder->AddExpression("host_name", OperatorSet, item->GetName());
|
||||
builder->AddExpression("alias", OperatorSet, string(desc));
|
||||
|
||||
Dictionary::Ptr macros;
|
||||
if (host->GetProperty("macros", ¯os)) {
|
||||
Expression macrosExpr("macros", OperatorPlus, macros, item->GetDebugInfo());
|
||||
exprl->AddExpression(macrosExpr);
|
||||
}
|
||||
if (host->GetProperty("macros", ¯os))
|
||||
builder->AddExpression("macros", OperatorPlus, macros);
|
||||
|
||||
long checkInterval;
|
||||
if (host->GetProperty("check_interval", &checkInterval)) {
|
||||
Expression checkExpr("check_interval", OperatorSet, checkInterval, item->GetDebugInfo());
|
||||
exprl->AddExpression(checkExpr);
|
||||
}
|
||||
if (host->GetProperty("check_interval", &checkInterval))
|
||||
builder->AddExpression("check_interval", OperatorSet, checkInterval);
|
||||
|
||||
long retryInterval;
|
||||
if (host->GetProperty("retry_interval", &retryInterval)) {
|
||||
Expression retryExpr("retry_interval", OperatorSet, retryInterval, item->GetDebugInfo());
|
||||
exprl->AddExpression(retryExpr);
|
||||
}
|
||||
if (host->GetProperty("retry_interval", &retryInterval))
|
||||
builder->AddExpression("retry_interval", OperatorSet, retryInterval);
|
||||
|
||||
Dictionary::Ptr sgroups;
|
||||
if (host->GetProperty("servicegroups", &sgroups)) {
|
||||
Expression sgroupsExpr("servicegroups", OperatorPlus, sgroups, item->GetDebugInfo());
|
||||
exprl->AddExpression(sgroupsExpr);
|
||||
}
|
||||
if (host->GetProperty("servicegroups", &sgroups))
|
||||
builder->AddExpression("servicegroups", OperatorPlus, sgroups);
|
||||
|
||||
Dictionary::Ptr checkers;
|
||||
if (host->GetProperty("checkers", &checkers)) {
|
||||
Expression checkersExpr("checkers", OperatorSet, checkers, item->GetDebugInfo());
|
||||
exprl->AddExpression(checkersExpr);
|
||||
}
|
||||
if (host->GetProperty("checkers", &checkers))
|
||||
builder->AddExpression("checkers", OperatorSet, checkers);
|
||||
|
||||
serviceItem->SetExpressionList(exprl);
|
||||
ConfigItem::Ptr serviceItem = builder->Compile();
|
||||
ConfigObject::Ptr service = serviceItem->Commit();
|
||||
|
||||
newServices->SetProperty(name, serviceItem);
|
||||
|
|
|
@ -11,6 +11,7 @@ delegation_la_SOURCES = \
|
|||
delegation_la_CPPFLAGS = \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/dyn \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/icinga \
|
||||
-I${top_srcdir}/cib
|
||||
|
@ -26,6 +27,7 @@ delegation_la_LIBADD = \
|
|||
$(BOOST_SIGNALS_LIB) \
|
||||
$(BOOST_THREAD_LIB) \
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/dyn/libdyn.la \
|
||||
${top_builddir}/jsonrpc/libjsonrpc.la \
|
||||
${top_builddir}/icinga/libicinga.la \
|
||||
${top_builddir}/cib/libcib.la
|
||||
|
|
|
@ -11,6 +11,7 @@ demo_la_SOURCES = \
|
|||
demo_la_CPPFLAGS = \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/dyn \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/icinga
|
||||
|
||||
|
@ -25,5 +26,6 @@ demo_la_LIBADD = \
|
|||
$(BOOST_SIGNALS_LIB) \
|
||||
$(BOOST_THREAD_LIB) \
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/dyn/libdyn.la \
|
||||
${top_builddir}/jsonrpc/libjsonrpc.la \
|
||||
${top_builddir}/icinga/libicinga.la
|
||||
|
|
|
@ -13,6 +13,7 @@ discovery_la_SOURCES = \
|
|||
discovery_la_CPPFLAGS = \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/dyn \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/icinga \
|
||||
-I${top_srcdir}/cib
|
||||
|
@ -28,6 +29,7 @@ discovery_la_LIBADD = \
|
|||
$(BOOST_SIGNALS_LIB) \
|
||||
$(BOOST_THREAD_LIB) \
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/dyn/libdyn.la \
|
||||
${top_builddir}/jsonrpc/libjsonrpc.la \
|
||||
${top_builddir}/icinga/libicinga.la \
|
||||
${top_builddir}/cib/libcib.la
|
||||
|
|
|
@ -16,6 +16,8 @@ libdyn_la_SOURCES = \
|
|||
i2-dyn.h \
|
||||
configitem.cpp \
|
||||
configitem.h \
|
||||
configitembuilder.cpp \
|
||||
configitembuilder.h \
|
||||
debuginfo.h \
|
||||
expression.cpp \
|
||||
expression.h \
|
||||
|
|
|
@ -223,7 +223,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
|
|||
int yyparse(ConfigCompiler *context);
|
||||
|
||||
static stack<ExpressionList::Ptr> m_ExpressionLists;
|
||||
static ConfigItem::Ptr m_Object;
|
||||
static ConfigItemBuilder::Ptr m_Item;
|
||||
static bool m_Abstract;
|
||||
static bool m_Local;
|
||||
static Dictionary::Ptr m_Array;
|
||||
|
@ -543,10 +543,10 @@ static const yytype_int8 yyrhs[] =
|
|||
static const yytype_uint16 yyrline[] =
|
||||
{
|
||||
0, 100, 100, 101, 104, 104, 107, 113, 118, 113,
|
||||
148, 149, 152, 156, 162, 163, 166, 173, 174, 178,
|
||||
177, 189, 190, 192, 193, 194, 197, 205, 219, 228,
|
||||
229, 230, 231, 232, 238, 243, 247, 253, 254, 255,
|
||||
262, 261, 273, 279, 280, 282, 284, 285
|
||||
138, 139, 142, 146, 152, 153, 156, 163, 164, 168,
|
||||
167, 179, 180, 182, 183, 184, 187, 195, 209, 218,
|
||||
219, 220, 221, 222, 228, 233, 237, 243, 244, 245,
|
||||
252, 251, 263, 269, 270, 272, 274, 275
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -1588,9 +1588,9 @@ yyreduce:
|
|||
/* Line 1806 of yacc.c */
|
||||
#line 118 "config_parser.yy"
|
||||
{
|
||||
m_Object = boost::make_shared<ConfigItem>((yyvsp[(4) - (5)].text), (yyvsp[(5) - (5)].text), yylloc);
|
||||
free((yyvsp[(4) - (5)].text));
|
||||
free((yyvsp[(5) - (5)].text));
|
||||
m_Item = boost::make_shared<ConfigItemBuilder>(yylloc);
|
||||
m_Item->SetType((yyvsp[(4) - (5)].text));
|
||||
m_Item->SetName((yyvsp[(5) - (5)].text));
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -1603,29 +1603,19 @@ yyreduce:
|
|||
delete (yyvsp[(8) - (8)].variant);
|
||||
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object);
|
||||
|
||||
Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc);
|
||||
exprl->AddExpression(typeexpr);
|
||||
m_Item->AddExpressionList(exprl);
|
||||
m_Item->SetLocal(m_Local);
|
||||
m_Item->SetAbstract(m_Abstract);
|
||||
|
||||
Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc);
|
||||
exprl->AddExpression(nameexpr);
|
||||
|
||||
Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0, yylloc);
|
||||
exprl->AddExpression(abstractexpr);
|
||||
|
||||
Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0, yylloc);
|
||||
exprl->AddExpression(localexpr);
|
||||
|
||||
m_Object->SetExpressionList(exprl);
|
||||
|
||||
context->AddObject(m_Object);
|
||||
m_Object.reset();
|
||||
context->AddObject(m_Item->Compile());
|
||||
m_Item.reset();
|
||||
}
|
||||
break;
|
||||
|
||||
case 12:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 153 "config_parser.yy"
|
||||
#line 143 "config_parser.yy"
|
||||
{
|
||||
m_Abstract = true;
|
||||
}
|
||||
|
@ -1634,7 +1624,7 @@ yyreduce:
|
|||
case 13:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 157 "config_parser.yy"
|
||||
#line 147 "config_parser.yy"
|
||||
{
|
||||
m_Local = true;
|
||||
}
|
||||
|
@ -1643,9 +1633,9 @@ yyreduce:
|
|||
case 16:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 167 "config_parser.yy"
|
||||
#line 157 "config_parser.yy"
|
||||
{
|
||||
m_Object->AddParent((yyvsp[(1) - (1)].text));
|
||||
m_Item->AddParent((yyvsp[(1) - (1)].text));
|
||||
free((yyvsp[(1) - (1)].text));
|
||||
}
|
||||
break;
|
||||
|
@ -1653,7 +1643,7 @@ yyreduce:
|
|||
case 19:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 178 "config_parser.yy"
|
||||
#line 168 "config_parser.yy"
|
||||
{
|
||||
m_ExpressionLists.push(boost::make_shared<ExpressionList>());
|
||||
}
|
||||
|
@ -1662,7 +1652,7 @@ yyreduce:
|
|||
case 20:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 183 "config_parser.yy"
|
||||
#line 173 "config_parser.yy"
|
||||
{
|
||||
(yyval.variant) = new Variant(m_ExpressionLists.top());
|
||||
m_ExpressionLists.pop();
|
||||
|
@ -1672,7 +1662,7 @@ yyreduce:
|
|||
case 26:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 198 "config_parser.yy"
|
||||
#line 188 "config_parser.yy"
|
||||
{
|
||||
Expression expr((yyvsp[(1) - (3)].text), (yyvsp[(2) - (3)].op), *(yyvsp[(3) - (3)].variant), yylloc);
|
||||
free((yyvsp[(1) - (3)].text));
|
||||
|
@ -1685,7 +1675,7 @@ yyreduce:
|
|||
case 27:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 206 "config_parser.yy"
|
||||
#line 196 "config_parser.yy"
|
||||
{
|
||||
Expression subexpr((yyvsp[(3) - (6)].text), (yyvsp[(5) - (6)].op), *(yyvsp[(6) - (6)].variant), yylloc);
|
||||
free((yyvsp[(3) - (6)].text));
|
||||
|
@ -1704,7 +1694,7 @@ yyreduce:
|
|||
case 28:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 220 "config_parser.yy"
|
||||
#line 210 "config_parser.yy"
|
||||
{
|
||||
Expression expr((yyvsp[(1) - (1)].text), OperatorSet, (yyvsp[(1) - (1)].text), yylloc);
|
||||
free((yyvsp[(1) - (1)].text));
|
||||
|
@ -1716,7 +1706,7 @@ yyreduce:
|
|||
case 33:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 233 "config_parser.yy"
|
||||
#line 223 "config_parser.yy"
|
||||
{
|
||||
(yyval.op) = (yyvsp[(1) - (1)].op);
|
||||
}
|
||||
|
@ -1725,7 +1715,7 @@ yyreduce:
|
|||
case 34:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 239 "config_parser.yy"
|
||||
#line 229 "config_parser.yy"
|
||||
{
|
||||
(yyval.variant) = new Variant((yyvsp[(1) - (1)].text));
|
||||
free((yyvsp[(1) - (1)].text));
|
||||
|
@ -1735,7 +1725,7 @@ yyreduce:
|
|||
case 35:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 244 "config_parser.yy"
|
||||
#line 234 "config_parser.yy"
|
||||
{
|
||||
(yyval.variant) = new Variant((yyvsp[(1) - (1)].num));
|
||||
}
|
||||
|
@ -1744,7 +1734,7 @@ yyreduce:
|
|||
case 36:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 248 "config_parser.yy"
|
||||
#line 238 "config_parser.yy"
|
||||
{
|
||||
(yyval.variant) = new Variant();
|
||||
}
|
||||
|
@ -1753,7 +1743,7 @@ yyreduce:
|
|||
case 39:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 256 "config_parser.yy"
|
||||
#line 246 "config_parser.yy"
|
||||
{
|
||||
(yyval.variant) = (yyvsp[(1) - (1)].variant);
|
||||
}
|
||||
|
@ -1762,7 +1752,7 @@ yyreduce:
|
|||
case 40:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 262 "config_parser.yy"
|
||||
#line 252 "config_parser.yy"
|
||||
{
|
||||
m_Array = boost::make_shared<Dictionary>();
|
||||
}
|
||||
|
@ -1771,7 +1761,7 @@ yyreduce:
|
|||
case 41:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 267 "config_parser.yy"
|
||||
#line 257 "config_parser.yy"
|
||||
{
|
||||
(yyval.variant) = new Variant(m_Array);
|
||||
m_Array.reset();
|
||||
|
@ -1781,7 +1771,7 @@ yyreduce:
|
|||
case 42:
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 274 "config_parser.yy"
|
||||
#line 264 "config_parser.yy"
|
||||
{
|
||||
m_Array->AddUnnamedProperty(*(yyvsp[(1) - (1)].variant));
|
||||
delete (yyvsp[(1) - (1)].variant);
|
||||
|
@ -1791,7 +1781,7 @@ yyreduce:
|
|||
|
||||
|
||||
/* Line 1806 of yacc.c */
|
||||
#line 1795 "config_parser.cc"
|
||||
#line 1785 "config_parser.cc"
|
||||
default: break;
|
||||
}
|
||||
/* User semantic actions sometimes alter yychar, and that requires
|
||||
|
@ -2029,6 +2019,6 @@ yyreturn:
|
|||
|
||||
|
||||
/* Line 2067 of yacc.c */
|
||||
#line 287 "config_parser.yy"
|
||||
#line 277 "config_parser.yy"
|
||||
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ void yyerror(YYLTYPE *locp, ConfigCompiler *context, const char *err)
|
|||
int yyparse(ConfigCompiler *context);
|
||||
|
||||
static stack<ExpressionList::Ptr> m_ExpressionLists;
|
||||
static ConfigItem::Ptr m_Object;
|
||||
static ConfigItemBuilder::Ptr m_Item;
|
||||
static bool m_Abstract;
|
||||
static bool m_Local;
|
||||
static Dictionary::Ptr m_Array;
|
||||
|
@ -116,9 +116,9 @@ object:
|
|||
}
|
||||
attributes T_OBJECT T_IDENTIFIER T_STRING
|
||||
{
|
||||
m_Object = boost::make_shared<ConfigItem>($4, $5, yylloc);
|
||||
free($4);
|
||||
free($5);
|
||||
m_Item = boost::make_shared<ConfigItemBuilder>(yylloc);
|
||||
m_Item->SetType($4);
|
||||
m_Item->SetName($5);
|
||||
}
|
||||
inherits_specifier expressionlist
|
||||
{
|
||||
|
@ -126,22 +126,12 @@ inherits_specifier expressionlist
|
|||
delete $8;
|
||||
ExpressionList::Ptr exprl = dynamic_pointer_cast<ExpressionList>(exprl_object);
|
||||
|
||||
Expression typeexpr("__type", OperatorSet, m_Object->GetType(), yylloc);
|
||||
exprl->AddExpression(typeexpr);
|
||||
m_Item->AddExpressionList(exprl);
|
||||
m_Item->SetLocal(m_Local);
|
||||
m_Item->SetAbstract(m_Abstract);
|
||||
|
||||
Expression nameexpr("__name", OperatorSet, m_Object->GetName(), yylloc);
|
||||
exprl->AddExpression(nameexpr);
|
||||
|
||||
Expression abstractexpr("__abstract", OperatorSet, m_Abstract ? 1 : 0, yylloc);
|
||||
exprl->AddExpression(abstractexpr);
|
||||
|
||||
Expression localexpr("__local", OperatorSet, m_Local ? 1 : 0, yylloc);
|
||||
exprl->AddExpression(localexpr);
|
||||
|
||||
m_Object->SetExpressionList(exprl);
|
||||
|
||||
context->AddObject(m_Object);
|
||||
m_Object.reset();
|
||||
context->AddObject(m_Item->Compile());
|
||||
m_Item.reset();
|
||||
}
|
||||
;
|
||||
|
||||
|
@ -165,7 +155,7 @@ inherits_list: inherits_item
|
|||
|
||||
inherits_item: T_STRING
|
||||
{
|
||||
m_Object->AddParent($1);
|
||||
m_Item->AddParent($1);
|
||||
free($1);
|
||||
}
|
||||
;
|
||||
|
|
|
@ -21,8 +21,11 @@
|
|||
|
||||
using namespace icinga;
|
||||
|
||||
ConfigItem::ConfigItem(const string& type, const string& name, const DebugInfo& debuginfo)
|
||||
: m_Type(type), m_Name(name), m_DebugInfo(debuginfo)
|
||||
ConfigItem::ConfigItem(const string& type, const string& name,
|
||||
const ExpressionList::Ptr& exprl, const vector<string>& parents,
|
||||
const DebugInfo& debuginfo)
|
||||
: m_Type(type), m_Name(name), m_ExpressionList(exprl),
|
||||
m_Parents(parents), m_DebugInfo(debuginfo)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -46,21 +49,11 @@ ExpressionList::Ptr ConfigItem::GetExpressionList(void) const
|
|||
return m_ExpressionList;
|
||||
}
|
||||
|
||||
void ConfigItem::SetExpressionList(const ExpressionList::Ptr& exprl)
|
||||
{
|
||||
m_ExpressionList = exprl;
|
||||
}
|
||||
|
||||
vector<string> ConfigItem::GetParents(void) const
|
||||
{
|
||||
return m_Parents;
|
||||
}
|
||||
|
||||
void ConfigItem::AddParent(const string& parent)
|
||||
{
|
||||
m_Parents.push_back(parent);
|
||||
}
|
||||
|
||||
void ConfigItem::CalculateProperties(Dictionary::Ptr dictionary) const
|
||||
{
|
||||
vector<string>::const_iterator it;
|
||||
|
|
|
@ -32,16 +32,16 @@ public:
|
|||
|
||||
typedef ObjectMap<pair<string, string>, ConfigItem::Ptr> TNMap;
|
||||
|
||||
ConfigItem(const string& type, const string& name, const DebugInfo& debuginfo);
|
||||
ConfigItem(const string& type, const string& name,
|
||||
const ExpressionList::Ptr& exprl, const vector<string>& parents,
|
||||
const DebugInfo& debuginfo);
|
||||
|
||||
string GetType(void) const;
|
||||
string GetName(void) const;
|
||||
|
||||
vector<string> GetParents(void) const;
|
||||
void AddParent(const string& parent);
|
||||
|
||||
ExpressionList::Ptr GetExpressionList(void) const;
|
||||
void SetExpressionList(const ExpressionList::Ptr& exprl);
|
||||
|
||||
void CalculateProperties(Dictionary::Ptr dictionary) const;
|
||||
|
||||
|
@ -59,9 +59,10 @@ public:
|
|||
private:
|
||||
string m_Type;
|
||||
string m_Name;
|
||||
DebugInfo m_DebugInfo;
|
||||
vector<string> m_Parents;
|
||||
|
||||
ExpressionList::Ptr m_ExpressionList;
|
||||
vector<string> m_Parents;
|
||||
DebugInfo m_DebugInfo;
|
||||
|
||||
ConfigObject::WeakPtr m_ConfigObject;
|
||||
|
||||
|
|
|
@ -0,0 +1,86 @@
|
|||
#include "i2-dyn.h"
|
||||
|
||||
using namespace icinga;
|
||||
|
||||
ConfigItemBuilder::ConfigItemBuilder(void)
|
||||
: m_Local(false), m_Abstract(false),
|
||||
m_ExpressionList(boost::make_shared<ExpressionList>())
|
||||
{
|
||||
m_DebugInfo.FirstLine = 0;
|
||||
m_DebugInfo.FirstColumn = 0;
|
||||
m_DebugInfo.LastLine = 0;
|
||||
m_DebugInfo.LastColumn = 0;
|
||||
}
|
||||
|
||||
ConfigItemBuilder::ConfigItemBuilder(const DebugInfo& debugInfo)
|
||||
: m_Local(false), m_Abstract(false),
|
||||
m_ExpressionList(boost::make_shared<ExpressionList>())
|
||||
{
|
||||
m_DebugInfo = debugInfo;
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::SetType(const string& type)
|
||||
{
|
||||
m_Type = type;
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::SetName(const string& name)
|
||||
{
|
||||
m_Name = name;
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::SetLocal(bool local)
|
||||
{
|
||||
m_Local = local;
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::SetAbstract(bool abstract)
|
||||
{
|
||||
m_Abstract = abstract;
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::AddParent(const string& parent)
|
||||
{
|
||||
m_Parents.push_back(parent);
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::AddExpression(const Expression& expr)
|
||||
{
|
||||
m_ExpressionList->AddExpression(expr);
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::AddExpression(const string& key, ExpressionOperator op, const Variant& value)
|
||||
{
|
||||
Expression expr(key, op, value, m_DebugInfo);
|
||||
AddExpression(expr);
|
||||
}
|
||||
|
||||
void ConfigItemBuilder::AddExpressionList(const ExpressionList::Ptr& exprl)
|
||||
{
|
||||
AddExpression("", OperatorExecute, exprl);
|
||||
}
|
||||
|
||||
ConfigItem::Ptr ConfigItemBuilder::Compile(void)
|
||||
{
|
||||
assert(!m_Type.empty());
|
||||
assert(!m_Name.empty());
|
||||
|
||||
ExpressionList::Ptr exprl = boost::make_shared<ExpressionList>();
|
||||
|
||||
Expression execExpr("", OperatorExecute, m_ExpressionList, m_DebugInfo);
|
||||
exprl->AddExpression(execExpr);
|
||||
|
||||
Expression typeExpr("__type", OperatorSet, m_Type, m_DebugInfo);
|
||||
exprl->AddExpression(typeExpr);
|
||||
|
||||
Expression nameExpr("__name", OperatorSet, m_Name, m_DebugInfo);
|
||||
exprl->AddExpression(nameExpr);
|
||||
|
||||
Expression localExpr("__local", OperatorSet, m_Local, m_DebugInfo);
|
||||
exprl->AddExpression(localExpr);
|
||||
|
||||
Expression abstractExpr("__abstract", OperatorSet, m_Abstract, m_DebugInfo);
|
||||
exprl->AddExpression(abstractExpr);
|
||||
|
||||
return boost::make_shared<ConfigItem>(m_Type, m_Name, exprl, m_Parents, m_DebugInfo);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
#ifndef CONFIGITEMBUILDER_H
|
||||
#define CONFIGITEMBUILDER_H
|
||||
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
class ConfigItemBuilder : public Object
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<ConfigItemBuilder> Ptr;
|
||||
typedef weak_ptr<ConfigItemBuilder> WeakPtr;
|
||||
|
||||
ConfigItemBuilder(void);
|
||||
ConfigItemBuilder(const DebugInfo& debugInfo);
|
||||
|
||||
void SetType(const string& type);
|
||||
void SetName(const string& name);
|
||||
void SetLocal(bool local);
|
||||
void SetAbstract(bool abstract);
|
||||
|
||||
void AddParent(const string& parent);
|
||||
|
||||
void AddExpression(const Expression& expr);
|
||||
void AddExpression(const string& key, ExpressionOperator op, const Variant& value);
|
||||
void AddExpressionList(const ExpressionList::Ptr& exprl);
|
||||
|
||||
ConfigItem::Ptr Compile(void);
|
||||
|
||||
private:
|
||||
string m_Type;
|
||||
string m_Name;
|
||||
bool m_Local;
|
||||
bool m_Abstract;
|
||||
vector<string> m_Parents;
|
||||
ExpressionList::Ptr m_ExpressionList;
|
||||
DebugInfo m_DebugInfo;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif /* CONFIGITEMBUILDER */
|
|
@ -39,14 +39,14 @@ struct DebugInfo
|
|||
|
||||
union
|
||||
{
|
||||
int LastColumn;
|
||||
int last_column;
|
||||
int LastLine;
|
||||
int last_line;
|
||||
};
|
||||
|
||||
union
|
||||
{
|
||||
int LastLine;
|
||||
int last_line;
|
||||
int LastColumn;
|
||||
int last_column;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
@ -42,6 +42,14 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
|
|||
Dictionary::Ptr dict;
|
||||
|
||||
switch (m_Operator) {
|
||||
case OperatorExecute:
|
||||
if (!valueExprl)
|
||||
throw invalid_argument("Operand for OperatorExecute must be an ExpressionList.");
|
||||
|
||||
valueExprl->Execute(dictionary);
|
||||
|
||||
return;
|
||||
|
||||
case OperatorSet:
|
||||
if (valueExprl) {
|
||||
dict = boost::make_shared<Dictionary>();
|
||||
|
@ -85,9 +93,7 @@ void Expression::Execute(const Dictionary::Ptr& dictionary) const
|
|||
break;
|
||||
|
||||
default:
|
||||
assert(!"Not yet implemented.");
|
||||
|
||||
break;
|
||||
throw runtime_error("Not yet implemented.");
|
||||
}
|
||||
|
||||
dictionary->SetProperty(m_Key, newValue);
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace icinga
|
|||
|
||||
enum ExpressionOperator
|
||||
{
|
||||
OperatorExecute,
|
||||
OperatorSet,
|
||||
OperatorPlus,
|
||||
OperatorMinus,
|
||||
|
|
|
@ -48,6 +48,7 @@ using std::endl;
|
|||
#include "expression.h"
|
||||
#include "expressionlist.h"
|
||||
#include "configitem.h"
|
||||
#include "configitembuilder.h"
|
||||
#include "configcompiler.h"
|
||||
|
||||
#endif /* I2DYN_H */
|
||||
|
|
|
@ -11,6 +11,7 @@ icinga_CPPFLAGS = \
|
|||
-DI2_ICINGALAUNCHER_BUILD \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/dyn \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/icinga \
|
||||
-I${top_srcdir}
|
||||
|
@ -22,6 +23,7 @@ icinga_LDADD = \
|
|||
$(BOOST_SIGNALS_LIB) \
|
||||
$(BOOST_THREAD_LIB) \
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/dyn/libdyn.la \
|
||||
${top_builddir}/icinga/libicinga.la \
|
||||
-dlopen ${top_builddir}/components/checker/checker.la \
|
||||
-dlopen ${top_builddir}/components/cibsync/cibsync.la \
|
||||
|
|
|
@ -21,6 +21,7 @@ libicinga_la_CPPFLAGS = \
|
|||
-DI2_ICINGA_BUILD \
|
||||
$(BOOST_CPPFLAGS) \
|
||||
-I${top_srcdir}/base \
|
||||
-I${top_srcdir}/dyn \
|
||||
-I${top_srcdir}/jsonrpc \
|
||||
-I${top_srcdir}/cJSON \
|
||||
-I${top_srcdir}
|
||||
|
@ -33,5 +34,6 @@ libicinga_la_LDFLAGS = \
|
|||
|
||||
libicinga_la_LIBADD = \
|
||||
$(BOOST_THREAD_LIB) \
|
||||
${top_builddir}/jsonrpc/libjsonrpc.la \
|
||||
${top_builddir}/base/libbase.la
|
||||
${top_builddir}/base/libbase.la \
|
||||
${top_builddir}/dyn/libdyn.la \
|
||||
${top_builddir}/jsonrpc/libjsonrpc.la
|
||||
|
|
|
@ -28,6 +28,8 @@
|
|||
*/
|
||||
|
||||
#include <i2-base.h>
|
||||
#include <i2-dyn.h>
|
||||
#include <i2-dyn.h>
|
||||
#include <i2-jsonrpc.h>
|
||||
#include <set>
|
||||
|
||||
|
|
|
@ -62,15 +62,19 @@ int IcingaApplication::Main(const vector<string>& args)
|
|||
componentObjects->Start();
|
||||
|
||||
/* load convenience config component */
|
||||
ConfigObject::Ptr convenienceComponentConfig = boost::make_shared<ConfigObject>("component", "convenience");
|
||||
ConfigItemBuilder::Ptr convenienceComponentConfig = boost::make_shared<ConfigItemBuilder>();
|
||||
convenienceComponentConfig->SetType("component");
|
||||
convenienceComponentConfig->SetName("convenience");
|
||||
convenienceComponentConfig->SetLocal(true);
|
||||
convenienceComponentConfig->Commit();
|
||||
convenienceComponentConfig->Compile()->Commit();
|
||||
|
||||
/* load config file */
|
||||
ConfigObject::Ptr fileComponentConfig = boost::make_shared<ConfigObject>("component", "configfile");
|
||||
ConfigItemBuilder::Ptr fileComponentConfig = boost::make_shared<ConfigItemBuilder>();
|
||||
fileComponentConfig->SetType("component");
|
||||
fileComponentConfig->SetName("configfile");
|
||||
fileComponentConfig->SetLocal(true);
|
||||
fileComponentConfig->SetProperty("configFilename", args[1]);
|
||||
fileComponentConfig->Commit();
|
||||
fileComponentConfig->AddExpression("configFilename", OperatorSet, args[1]);
|
||||
fileComponentConfig->Compile()->Commit();
|
||||
|
||||
ConfigObject::Ptr icingaConfig = ConfigObject::GetObject("application", "icinga");
|
||||
|
||||
|
|
Loading…
Reference in New Issue