mirror of https://github.com/Icinga/icinga2.git
Fix inheritance for config types.
This commit is contained in:
parent
d950c4e88e
commit
b8669d67ca
|
@ -0,0 +1,58 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "base/sysloglogger.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
using namespace icinga;
|
||||
|
||||
/**
|
||||
* Constructor for the SyslogLogger class.
|
||||
*/
|
||||
SyslogLogger::SyslogLogger(const Dictionary::Ptr& serializedUpdate)
|
||||
: Logger(serializedUpdate)
|
||||
{ }
|
||||
|
||||
/**
|
||||
* Processes a log entry and outputs it to syslog.
|
||||
*
|
||||
* @param entry The log entry.
|
||||
*/
|
||||
void SyslogLogger::ProcessLogEntry(const LogEntry& entry)
|
||||
{
|
||||
int severity;
|
||||
switch (entry.Severity) {
|
||||
case LogDebug:
|
||||
severity = LOG_DEBUG;
|
||||
break;
|
||||
case LogWarning:
|
||||
severity = LOG_WARNING;
|
||||
break;
|
||||
case LogCritical:
|
||||
severity = LOG_CRIT;
|
||||
break;
|
||||
case LogInformation:
|
||||
default:
|
||||
severity = LOG_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
syslog(severity | LOG_USER, "%s", entry.Message.CStr());
|
||||
}
|
||||
#endif /* _WIN32 */
|
|
@ -0,0 +1,50 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SYSLOGLOGGER_H
|
||||
#define SYSLOGLOGGER_H
|
||||
|
||||
#include "base/i2-base.h"
|
||||
#include "base/logger.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
/**
|
||||
* A logger that logs to syslog.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class I2_BASE_API SyslogLogger : public Logger
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<SyslogLogger> Ptr;
|
||||
typedef weak_ptr<SyslogLogger> WeakPtr;
|
||||
|
||||
explicit SyslogLogger(const Dictionary::Ptr& serializedUpdate);
|
||||
|
||||
protected:
|
||||
virtual void ProcessLogEntry(const LogEntry& entry);
|
||||
};
|
||||
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#endif /* SYSLOGLOGGER_H */
|
|
@ -0,0 +1,58 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#include "base/sysloglogger.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
using namespace icinga;
|
||||
|
||||
/**
|
||||
* Constructor for the SyslogLogger class.
|
||||
*/
|
||||
SyslogLogger::SyslogLogger(const Dictionary::Ptr& serializedUpdate)
|
||||
: Logger(serializedUpdate)
|
||||
{ }
|
||||
|
||||
/**
|
||||
* Processes a log entry and outputs it to syslog.
|
||||
*
|
||||
* @param entry The log entry.
|
||||
*/
|
||||
void SyslogLogger::ProcessLogEntry(const LogEntry& entry)
|
||||
{
|
||||
int severity;
|
||||
switch (entry.Severity) {
|
||||
case LogDebug:
|
||||
severity = LOG_DEBUG;
|
||||
break;
|
||||
case LogWarning:
|
||||
severity = LOG_WARNING;
|
||||
break;
|
||||
case LogCritical:
|
||||
severity = LOG_CRIT;
|
||||
break;
|
||||
case LogInformation:
|
||||
default:
|
||||
severity = LOG_INFO;
|
||||
break;
|
||||
}
|
||||
|
||||
syslog(severity | LOG_USER, "%s", entry.Message.CStr());
|
||||
}
|
||||
#endif /* _WIN32 */
|
|
@ -0,0 +1,50 @@
|
|||
/******************************************************************************
|
||||
* Icinga 2 *
|
||||
* Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/) *
|
||||
* *
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License *
|
||||
* as published by the Free Software Foundation; either version 2 *
|
||||
* of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program; if not, write to the Free Software Foundation *
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef SYSLOGLOGGER_H
|
||||
#define SYSLOGLOGGER_H
|
||||
|
||||
#include "base/i2-base.h"
|
||||
#include "base/logger.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
namespace icinga
|
||||
{
|
||||
|
||||
/**
|
||||
* A logger that logs to syslog.
|
||||
*
|
||||
* @ingroup base
|
||||
*/
|
||||
class I2_BASE_API SyslogLogger : public Logger
|
||||
{
|
||||
public:
|
||||
typedef shared_ptr<SyslogLogger> Ptr;
|
||||
typedef weak_ptr<SyslogLogger> WeakPtr;
|
||||
|
||||
explicit SyslogLogger(const Dictionary::Ptr& serializedUpdate);
|
||||
|
||||
protected:
|
||||
virtual void ProcessLogEntry(const LogEntry& entry);
|
||||
};
|
||||
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
|
||||
#endif /* SYSLOGLOGGER_H */
|
|
@ -511,7 +511,7 @@ union yyalloc
|
|||
/* YYFINAL -- State number of the termination state. */
|
||||
#define YYFINAL 2
|
||||
/* YYLAST -- Last index in YYTABLE. */
|
||||
#define YYLAST 85
|
||||
#define YYLAST 83
|
||||
|
||||
/* YYNTOKENS -- Number of terminals. */
|
||||
#define YYNTOKENS 43
|
||||
|
@ -589,7 +589,7 @@ static const yytype_int8 yyrhs[] =
|
|||
-1, 56, -1, 55, 38, 56, -1, 21, 3, -1,
|
||||
20, 3, -1, 22, 49, 3, -1, 22, 19, 39,
|
||||
48, 40, 3, -1, 22, 49, 3, 52, -1, -1,
|
||||
30, 3, -1, 13, -1, 14, -1, 15, -1, 16,
|
||||
30, 48, -1, 13, -1, 14, -1, 15, -1, 16,
|
||||
-1, 17, -1, 18, -1, 19, -1, -1, 59, 60,
|
||||
48, 3, 64, 65, -1, 61, 26, -1, 27, -1,
|
||||
-1, 61, 62, -1, 24, -1, 25, -1, -1, 3,
|
||||
|
@ -714,29 +714,29 @@ static const yytype_int8 yydefgoto[] =
|
|||
|
||||
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
|
||||
STATE-NUM. */
|
||||
#define YYPACT_NINF -48
|
||||
#define YYPACT_NINF -49
|
||||
static const yytype_int8 yypact[] =
|
||||
{
|
||||
-48, 12, -48, -48, -48, -48, -48, -48, -48, -48,
|
||||
7, 10, -48, -48, -48, -48, -48, 13, -48, -6,
|
||||
-48, -48, -48, 39, -48, 39, 32, -48, -48, -48,
|
||||
34, -48, -48, -48, -48, 14, 15, 44, 23, 46,
|
||||
24, -48, -48, -48, -48, 26, 39, -48, 2, 58,
|
||||
-3, 25, 27, -48, 63, 64, 1, 31, 33, -48,
|
||||
-48, -48, -48, -48, -48, -48, 66, -2, -48, 39,
|
||||
-48, -48, 35, 67, -48, 2, 30, -48, -48, -48,
|
||||
-2, -48, -48, -48, -48, -48, 39, 23, -48, 43,
|
||||
36, 37, -48, 40, -48, -2, -48, -2, 70, -48,
|
||||
-48, -48
|
||||
-49, 12, -49, -49, -49, -49, -49, -49, -49, -49,
|
||||
7, 10, -49, -49, -49, -49, -49, -1, -49, -4,
|
||||
-49, -49, -49, 39, -49, 39, 31, -49, -49, -49,
|
||||
21, -49, -49, -49, -49, 6, 14, 39, 1, 45,
|
||||
9, -49, -49, -49, -49, 23, 39, -49, 38, 59,
|
||||
-3, 27, 28, -49, 62, 64, 2, 32, 30, -49,
|
||||
-49, -49, -49, -49, -49, -49, 67, -2, -49, 39,
|
||||
-49, -49, 33, 68, -49, 38, 34, -49, -49, -49,
|
||||
-2, -49, -49, -49, -49, -49, 39, 1, -49, 42,
|
||||
35, 36, -49, 40, -49, -2, -49, -2, 70, -49,
|
||||
-49, -49
|
||||
};
|
||||
|
||||
/* YYPGOTO[NTERM-NUM]. */
|
||||
static const yytype_int8 yypgoto[] =
|
||||
{
|
||||
-48, -48, -48, -48, -48, -23, 20, -48, -48, -10,
|
||||
-48, -48, -48, 4, -48, -48, -48, -48, -48, -48,
|
||||
-48, -48, 41, -48, -48, 16, -7, -48, -48, -48,
|
||||
-48, -47
|
||||
-49, -49, -49, -49, -49, -23, 19, -49, -49, -9,
|
||||
-49, -49, -49, 4, -49, -49, -49, -49, -49, -49,
|
||||
-49, -49, 41, -49, -49, 13, -6, -49, -49, -49,
|
||||
-49, -48
|
||||
};
|
||||
|
||||
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
|
||||
|
@ -746,33 +746,33 @@ static const yytype_int8 yypgoto[] =
|
|||
static const yytype_int8 yytable[] =
|
||||
{
|
||||
29, 77, 30, 78, 79, 61, 62, 63, 64, 65,
|
||||
20, 21, 2, 22, 3, 4, 5, 6, 7, 8,
|
||||
72, 24, 54, 55, 56, 3, 4, 5, 6, 7,
|
||||
8, 9, 12, 92, 46, -15, 23, 36, 66, 80,
|
||||
10, 11, 27, 12, 37, 39, 28, 41, 99, 44,
|
||||
100, 61, 62, 63, 64, 65, 31, 32, 33, 42,
|
||||
46, 60, 68, 93, 49, 69, 70, 71, 74, 76,
|
||||
87, 75, 89, 101, 86, 97, 73, 94, 96, 88,
|
||||
98, 47, 95, 0, 0, 85
|
||||
20, 21, 2, 22, 41, 3, 4, 5, 6, 7,
|
||||
8, 72, 23, 24, 36, 3, 4, 5, 6, 7,
|
||||
8, 9, 92, 12, 46, -15, 37, 42, 66, 80,
|
||||
10, 11, 27, 12, 39, 46, 28, 99, 44, 100,
|
||||
61, 62, 63, 64, 65, 31, 32, 33, 54, 55,
|
||||
56, 49, 60, 93, 68, 70, 69, 71, 75, 74,
|
||||
76, 87, 86, 101, 97, 73, 89, 96, 94, 88,
|
||||
98, 47, 85, 95
|
||||
};
|
||||
|
||||
#define yypact_value_is_default(yystate) \
|
||||
((yystate) == (-48))
|
||||
((yystate) == (-49))
|
||||
|
||||
#define yytable_value_is_error(yytable_value) \
|
||||
YYID (0)
|
||||
|
||||
static const yytype_int8 yycheck[] =
|
||||
static const yytype_uint8 yycheck[] =
|
||||
{
|
||||
23, 3, 25, 5, 6, 8, 9, 10, 11, 12,
|
||||
3, 4, 0, 3, 13, 14, 15, 16, 17, 18,
|
||||
19, 27, 20, 21, 22, 13, 14, 15, 16, 17,
|
||||
18, 19, 31, 80, 36, 23, 23, 3, 41, 41,
|
||||
28, 29, 3, 31, 30, 30, 7, 3, 95, 3,
|
||||
97, 8, 9, 10, 11, 12, 24, 25, 26, 36,
|
||||
36, 3, 37, 86, 38, 38, 3, 3, 37, 3,
|
||||
3, 38, 42, 3, 39, 38, 56, 87, 42, 75,
|
||||
40, 40, 89, -1, -1, 69
|
||||
3, 4, 0, 3, 37, 13, 14, 15, 16, 17,
|
||||
18, 19, 23, 27, 3, 13, 14, 15, 16, 17,
|
||||
18, 19, 80, 31, 36, 23, 30, 36, 41, 41,
|
||||
28, 29, 3, 31, 30, 36, 7, 95, 3, 97,
|
||||
8, 9, 10, 11, 12, 24, 25, 26, 20, 21,
|
||||
22, 38, 3, 86, 37, 3, 38, 3, 38, 37,
|
||||
3, 3, 39, 3, 38, 56, 42, 42, 87, 75,
|
||||
40, 40, 69, 89
|
||||
};
|
||||
|
||||
/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
|
||||
|
@ -783,7 +783,7 @@ static const yytype_uint8 yystos[] =
|
|||
28, 29, 31, 45, 46, 47, 49, 51, 58, 59,
|
||||
3, 4, 3, 23, 27, 60, 61, 3, 7, 48,
|
||||
48, 24, 25, 26, 62, 50, 3, 30, 57, 30,
|
||||
64, 3, 36, 52, 3, 63, 36, 65, 53, 38,
|
||||
64, 48, 36, 52, 3, 63, 36, 65, 53, 38,
|
||||
48, 66, 67, 68, 20, 21, 22, 54, 55, 56,
|
||||
3, 8, 9, 10, 11, 12, 41, 69, 37, 38,
|
||||
3, 3, 19, 49, 37, 38, 3, 3, 5, 6,
|
||||
|
|
|
@ -270,7 +270,7 @@ typerule: T_REQUIRE T_STRING
|
|||
;
|
||||
|
||||
type_inherits_specifier: /* empty */
|
||||
| T_INHERITS T_STRING
|
||||
| T_INHERITS identifier
|
||||
{
|
||||
m_Type->SetParent($2);
|
||||
free($2);
|
||||
|
|
|
@ -57,7 +57,25 @@ DebugInfo ConfigType::GetDebugInfo(void) const
|
|||
return m_DebugInfo;
|
||||
}
|
||||
|
||||
void ConfigType::ValidateItem(const ConfigItem::Ptr& item) const
|
||||
void ConfigType::AddParentRules(std::vector<TypeRuleList::Ptr>& ruleLists, const ConfigType::Ptr& item)
|
||||
{
|
||||
ConfigType::Ptr parent;
|
||||
if (item->m_Parent.IsEmpty()) {
|
||||
if (item->GetName() != "DynamicObject")
|
||||
parent = ConfigCompilerContext::GetContext()->GetType("DynamicObject");
|
||||
} else {
|
||||
parent = ConfigCompilerContext::GetContext()->GetType(item->m_Parent);
|
||||
}
|
||||
|
||||
if (parent) {
|
||||
AddParentRules(ruleLists, parent);
|
||||
|
||||
ObjectLock plock(parent);
|
||||
ruleLists.push_back(parent->m_RuleList);
|
||||
}
|
||||
}
|
||||
|
||||
void ConfigType::ValidateItem(const ConfigItem::Ptr& item)
|
||||
{
|
||||
/* Don't validate abstract items. */
|
||||
if (item->IsAbstract())
|
||||
|
@ -70,20 +88,8 @@ void ConfigType::ValidateItem(const ConfigItem::Ptr& item) const
|
|||
DebugInfo debugInfo = item->GetDebugInfo();
|
||||
locations.push_back("Object '" + item->GetName() + "' (Type: '" + item->GetType() + "') at " + debugInfo.Path + ":" + Convert::ToString(debugInfo.FirstLine));
|
||||
|
||||
ConfigType::Ptr parent;
|
||||
if (m_Parent.IsEmpty()) {
|
||||
if (GetName() != "DynamicObject")
|
||||
parent = ConfigCompilerContext::GetContext()->GetType("DynamicObject");
|
||||
} else {
|
||||
parent = ConfigCompilerContext::GetContext()->GetType(m_Parent);
|
||||
}
|
||||
|
||||
std::vector<TypeRuleList::Ptr> ruleLists;
|
||||
if (parent) {
|
||||
ObjectLock plock(parent);
|
||||
ruleLists.push_back(parent->m_RuleList);
|
||||
}
|
||||
|
||||
AddParentRules(ruleLists, GetSelf());
|
||||
ruleLists.push_back(m_RuleList);
|
||||
|
||||
ValidateDictionary(attrs, ruleLists, locations);
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
|
||||
DebugInfo GetDebugInfo(void) const;
|
||||
|
||||
void ValidateItem(const ConfigItem::Ptr& object) const;
|
||||
void ValidateItem(const ConfigItem::Ptr& object);
|
||||
|
||||
private:
|
||||
String m_Name; /**< The type name. */
|
||||
|
@ -65,6 +65,8 @@ private:
|
|||
const std::vector<TypeRuleList::Ptr>& ruleLists, std::vector<String>& locations);
|
||||
|
||||
static String LocationToString(const std::vector<String>& locations);
|
||||
|
||||
static void AddParentRules(std::vector<TypeRuleList::Ptr>& ruleLists, const ConfigType::Ptr& item);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue