* { font-family: Consolas, Lucida Console, Courier New; font-size: 100%; }
h1 { font-size: 150%; }
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
pre { line-height: 100%; width: 100%; }
.highlight span { width: 100%; display:-moz-inline-stack; display:inline-block; zoom:1; *display:inline; }
body { background: #ffffff; }
body .c { color: #999988; font-style: italic } /* Comment */
body .err { color: #a61717; background-color: #e3d2d2 } /* Error */
body .k { font-weight: bold } /* Keyword */
body .o { font-weight: bold } /* Operator */
body .cm { color: #999988; font-style: italic } /* Comment.Multiline */
body .cp { color: #999999; font-weight: bold } /* Comment.Preproc */
body .c1 { color: #999988; font-style: italic } /* Comment.Single */
body .cs { color: #999999; font-weight: bold; font-style: italic } /* Comment.Special */
body .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #aa0000 } /* Generic.Error */
body .gh { color: #999999 } /* Generic.Heading */
body .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
body .go { color: #888888 } /* Generic.Output */
body .gp { color: #555555 } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #aaaaaa } /* Generic.Subheading */
body .gt { color: #aa0000 } /* Generic.Traceback */
body .kc { font-weight: bold } /* Keyword.Constant */
body .kd { font-weight: bold } /* Keyword.Declaration */
body .kp { font-weight: bold } /* Keyword.Pseudo */
body .kr { font-weight: bold } /* Keyword.Reserved */
body .kt { color: #445588; font-weight: bold } /* Keyword.Type */
body .m { color: #009999 } /* Literal.Number */
body .s { color: #bb8844 } /* Literal.String */
body .na { color: #008080 } /* Name.Attribute */
body .nb { color: #999999 } /* Name.Builtin */
body .nc { color: #445588; font-weight: bold } /* Name.Class */
body .no { color: #008080 } /* Name.Constant */
body .ni { color: #800080 } /* Name.Entity */
body .ne { color: #990000; font-weight: bold } /* Name.Exception */
body .nf { color: #990000; font-weight: bold } /* Name.Function */
body .nn { color: #555555 } /* Name.Namespace */
body .nt { color: #000080 } /* Name.Tag */
body .nv { color: #008080 } /* Name.Variable */
body .ow { font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #009999 } /* Literal.Number.Float */
body .mh { color: #009999 } /* Literal.Number.Hex */
body .mi { color: #009999 } /* Literal.Number.Integer */
body .mo { color: #009999 } /* Literal.Number.Oct */
body .sb { color: #bb8844 } /* Literal.String.Backtick */
body .sc { color: #bb8844 } /* Literal.String.Char */
body .sd { color: #bb8844 } /* Literal.String.Doc */
body .s2 { color: #bb8844 } /* Literal.String.Double */
body .se { color: #bb8844 } /* Literal.String.Escape */
body .sh { color: #bb8844 } /* Literal.String.Heredoc */
body .si { color: #bb8844 } /* Literal.String.Interpol */
body .sx { color: #bb8844 } /* Literal.String.Other */
body .sr { color: #808000 } /* Literal.String.Regex */
body .s1 { color: #bb8844 } /* Literal.String.Single */
body .ss { color: #bb8844 } /* Literal.String.Symbol */
body .bp { color: #999999 } /* Name.Builtin.Pseudo */
body .vc { color: #008080 } /* Name.Variable.Class */
body .vg { color: #008080 } /* Name.Variable.Global */
body .vi { color: #008080 } /* Name.Variable.Instance */
body .il { color: #009999 } /* Literal.Number.Integer.Long */
Info
Revision:3351
Author:victor
Date:2008-06-28 15:43:19 +0300 (Sat, 28 Jun 2008)
Comment:added NXSL function GetCustomAttribute(); all scripts now use environment with additional functions by default
Changes
U trunk/src/server/core/Makefile.am
U trunk/src/server/core/condition.cpp
U trunk/src/server/core/dcitem.cpp
U trunk/src/server/core/epp.cpp
U trunk/src/server/core/events.cpp
U trunk/src/server/core/nxcore.dsp
A trunk/src/server/core/nxslext.cpp
U trunk/src/server/include/nms_script.h
Diff
Modified: trunk/src/server/core/Makefile.am
===================================================================
--- trunk/src/server/core/Makefile.am 2008-06-27 11:36:17 UTC (rev 3350)
+++ trunk/src/server/core/Makefile.am 2008-06-28 12:43:19 UTC (rev 3351)
@@ -15,7 +15,7 @@
node.cpp nortel.cpp np.cpp nxmp_data.cpp \
nxmp_lex.yy.cpp nxmp_lexer.cpp \
nxmp_parser.cpp nxmp_parser.tab.cpp \
- nxsl_classes.cpp objects.cpp \
+ nxsl_classes.cpp nxslext.cpp objects.cpp \
objtools.cpp package.cpp poll.cpp radius.cpp \
rootobj.cpp script.cpp session.cpp situation.cpp \
sms.cpp snmp.cpp snmptrap.cpp subnet.cpp syncer.cpp \
Modified: trunk/src/server/core/condition.cpp
===================================================================
--- trunk/src/server/core/condition.cpp 2008-06-27 11:36:17 UTC (rev 3350)
+++ trunk/src/server/core/condition.cpp 2008-06-28 12:43:19 UTC (rev 3351)
@@ -394,7 +394,7 @@
void Condition::Check(void)
{
- NXSL_Environment *pEnv;
+ NXSL_ServerEnv *pEnv;
NXSL_Value **ppValueList, *pValue;
NetObj *pObject;
DCItem *pItem;
@@ -404,8 +404,7 @@
if ((m_pCompiledScript == NULL) || (m_iStatus == STATUS_UNMANAGED))
return;
- pEnv = new NXSL_Environment;
- pEnv->SetLibrary(g_pScriptLibrary);
+ pEnv = new NXSL_ServerEnv;
LockData();
ppValueList = (NXSL_Value **)malloc(sizeof(NXSL_Value *) * m_dwDCICount);
Modified: trunk/src/server/core/dcitem.cpp
===================================================================
--- trunk/src/server/core/dcitem.cpp 2008-06-27 11:36:17 UTC (rev 3350)
+++ trunk/src/server/core/dcitem.cpp 2008-06-28 12:43:19 UTC (rev 3351)
@@ -126,7 +126,12 @@
{ "GetDCIValue", F_GetDCIValue, 2 }
};
+void RegisterDCIFunctions(NXSL_Environment *pEnv)
+{
+ pEnv->RegisterFunctionSet(sizeof(m_nxslDCIFunctions) / sizeof(NXSL_ExtFunction), m_nxslDCIFunctions);
+}
+
//
// Default constructor for DCItem
//
@@ -996,7 +1001,7 @@
if (m_pScript != NULL)
{
NXSL_Value *pValue;
- NXSL_Environment *pEnv;
+ NXSL_ServerEnv *pEnv;
switch(m_iDataType)
{
@@ -1023,9 +1028,7 @@
break;
}
- pEnv = new NXSL_Environment;
- pEnv->SetLibrary(g_pScriptLibrary);
- pEnv->RegisterFunctionSet(sizeof(m_nxslDCIFunctions) / sizeof(NXSL_ExtFunction), m_nxslDCIFunctions);
+ pEnv = new NXSL_ServerEnv;
m_pScript->SetGlobalVariable(_T("$node"), new NXSL_Value(new NXSL_Object(&g_nxslNodeClass, m_pNode)));
if (m_pScript->Run(pEnv, 1, &pValue) == 0)
@@ -1871,14 +1874,13 @@
else if (!_tcsncmp(macro, _T("script:"), 7))
{
NXSL_Program *script;
- NXSL_Environment *pEnv;
+ NXSL_ServerEnv *pEnv;
g_pScriptLibrary->Lock();
script = g_pScriptLibrary->FindScript(&macro[7]);
if (script != NULL)
{
- pEnv = new NXSL_Environment;
- pEnv->SetLibrary(g_pScriptLibrary);
+ pEnv = new NXSL_ServerEnv;
if (m_pNode != NULL)
script->SetGlobalVariable(_T("$node"), new NXSL_Value(new NXSL_Object(&g_nxslNodeClass, m_pNode)));
Modified: trunk/src/server/core/epp.cpp
===================================================================
--- trunk/src/server/core/epp.cpp 2008-06-27 11:36:17 UTC (rev 3350)
+++ trunk/src/server/core/epp.cpp 2008-06-28 12:43:19 UTC (rev 3351)
@@ -277,7 +277,7 @@
BOOL EPRule::MatchScript(Event *pEvent)
{
- NXSL_Environment *pEnv;
+ NXSL_ServerEnv *pEnv;
NXSL_Value **ppValueList, *pValue;
NXSL_VariableSystem *pLocals, *pGlobals = NULL;
BOOL bRet = TRUE;
@@ -287,8 +287,7 @@
if (m_pScript == NULL)
return TRUE;
- pEnv = new NXSL_Environment;
- pEnv->SetLibrary(g_pScriptLibrary);
+ pEnv = new NXSL_ServerEnv;
pEnv->RegisterFunctionSet(g_nxslNumSituationFunctions, g_nxslSituationFunctions);
// Pass event's parameters as arguments and
Modified: trunk/src/server/core/events.cpp
===================================================================
--- trunk/src/server/core/events.cpp 2008-06-27 11:36:17 UTC (rev 3350)
+++ trunk/src/server/core/events.cpp 2008-06-28 12:43:19 UTC (rev 3351)
@@ -341,7 +341,7 @@
else
{
NXSL_Program *script;
- NXSL_Environment *pEnv;
+ NXSL_ServerEnv *pEnv;
scriptName[i] = 0;
StrStrip(scriptName);
@@ -350,8 +350,7 @@
script = g_pScriptLibrary->FindScript(scriptName);
if (script != NULL)
{
- pEnv = new NXSL_Environment;
- pEnv->SetLibrary(g_pScriptLibrary);
+ pEnv = new NXSL_ServerEnv;
if (pObject->Type() == OBJECT_NODE)
script->SetGlobalVariable(_T("$node"), new NXSL_Value(new NXSL_Object(&g_nxslNodeClass, pObject)));
script->SetGlobalVariable(_T("$event"), new NXSL_Value(new NXSL_Object(&g_nxslEventClass, this)));
Modified: trunk/src/server/core/nxcore.dsp
===================================================================
--- trunk/src/server/core/nxcore.dsp 2008-06-27 11:36:17 UTC (rev 3350)
+++ trunk/src/server/core/nxcore.dsp 2008-06-28 12:43:19 UTC (rev 3351)
@@ -362,6 +362,10 @@
# End Source File
# Begin Source File
+SOURCE=.\nxslext.cpp
+# End Source File
+# Begin Source File
+
SOURCE=.\objects.cpp
# End Source File
# Begin Source File
Added: trunk/src/server/core/nxslext.cpp
===================================================================
--- trunk/src/server/core/nxslext.cpp (rev 0)
+++ trunk/src/server/core/nxslext.cpp 2008-06-28 12:43:19 UTC (rev 3351)
@@ -0,0 +1,89 @@
+/*
+** NetXMS - Network Management System
+** Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Victor Kirhenshtein
+**
+** 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: nxslext.cpp
+**
+**/
+
+#include "nxcore.h"
+
+
+//
+// Externals
+//
+
+void RegisterDCIFunctions(NXSL_Environment *pEnv);
+
+
+//
+// Get node's custom attribute
+// First argument is a node object, and second is an attribute name
+//
+
+static int F_GetCustomAttribute(int argc, NXSL_Value **argv, NXSL_Value **ppResult)
+{
+ NXSL_Object *object;
+ Node *node;
+ const TCHAR *value;
+
+ if (!argv[0]->IsObject())
+ return NXSL_ERR_NOT_OBJECT;
+
+ if (!argv[1]->IsString())
+ return NXSL_ERR_NOT_STRING;
+
+ object = argv[0]->GetValueAsObject();
+ if (_tcscmp(object->Class()->Name(), "NetXMS_Node"))
+ return NXSL_ERR_BAD_CLASS;
+
+ node = (Node *)object->Data();
+ value = node->GetCustomAttribute(argv[1]->GetValueAsCString());
+ if (value != NULL)
+ {
+ *ppResult = new NXSL_Value(value);
+ }
+ else
+ {
+ *ppResult = new NXSL_Value; // Return NULL if DCI not found
+ }
+
+ return 0;
+}
+
+
+//
+// Additional server functions to use within all scripts
+//
+
+static NXSL_ExtFunction m_nxslServerFunctions[] =
+{
+ { "GetCustomAttribute", F_GetCustomAttribute, 2 }
+};
+
+
+//
+// Constructor for server default script environment
+//
+
+NXSL_ServerEnv::NXSL_ServerEnv()
+ : NXSL_Environment()
+{
+ SetLibrary(g_pScriptLibrary);
+ RegisterFunctionSet(sizeof(m_nxslServerFunctions) / sizeof(NXSL_ExtFunction), m_nxslServerFunctions);
+ RegisterDCIFunctions(this);
+}
Property changes on: trunk/src/server/core/nxslext.cpp
___________________________________________________________________
Added: svn:eol-style
+ native
Modified: trunk/src/server/include/nms_script.h
===================================================================
--- trunk/src/server/include/nms_script.h 2008-06-27 11:36:17 UTC (rev 3350)
+++ trunk/src/server/include/nms_script.h 2008-06-28 12:43:19 UTC (rev 3351)
@@ -65,6 +65,17 @@
//
+// Server's default script environment
+//
+
+class NXSL_ServerEnv : public NXSL_Environment
+{
+public:
+ NXSL_ServerEnv();
+};
+
+
+//
// Functions
//
Received on Sat Jun 28 2008 - 15:43:20 EEST
This archive was generated by hypermail 2.2.0 : Sat Jun 28 2008 - 15:38:29 EEST