- added support for check templates
authorAlex Kalimulin <alex@netxms.org>
Mon, 5 Sep 2011 22:23:45 +0000 (22:23 +0000)
committerAlex Kalimulin <alex@netxms.org>
Mon, 5 Sep 2011 22:23:45 +0000 (22:23 +0000)
src/server/core/nodelink.cpp
src/server/core/slmcheck.cpp
src/server/include/nms_objects.h

index 02884c4..c7f4182 100644 (file)
@@ -235,5 +235,21 @@ void NodeLink::execute()
 
 BOOL NodeLink::applyTemplates()
 {
+       for (int i = 0; i < int(m_dwParentCount); i++)
+       {
+               ServiceContainer *parent = (ServiceContainer*)m_pParentList[i];
+               if (parent->Type() != OBJECT_BUSINESSSERVICE)
+                       continue;
+               for (int k = 0; k < int(parent->getChildCount()); k++)
+               {
+                       if ((parent->getChildList())[k]->Type() == OBJECT_SLMCHECK && 
+                               ((SlmCheck*)parent->getChildList()[k])->isTemplate())
+                       {
+                               SlmCheck *autoCreated = new SlmCheck((SlmCheck*)parent->getChildList()[k]);
+                               linkObject(autoCreated);
+                       }
+               }
+       }
+
        return TRUE;
 }
index 2708ed7..c6314da 100644 (file)
@@ -39,7 +39,6 @@ SlmCheck::SlmCheck() : NetObj()
        m_currentTicketId = 0;
 }
 
-
 //
 // Constructor for new check object
 //
@@ -56,6 +55,21 @@ SlmCheck::SlmCheck(const TCHAR *name) : NetObj()
        m_currentTicketId = 0;
 }
 
+//
+// Used to create a new object from a check template
+//
+
+SlmCheck::SlmCheck(const SlmCheck *check)
+{
+       nx_strncpy(m_szName, check->m_szName, MAX_OBJECT_NAME);
+       m_type          = check->m_type;
+       m_script = (m_type == check_script) ? _tcsdup(check->m_script) : NULL;
+       m_threshold = NULL;
+       m_reason[0] = 0;
+       m_isTemplate = false;
+       m_currentTicketId = check->m_currentTicketId;
+       compileScript();
+}
 
 //
 // Service class destructor
@@ -68,6 +82,22 @@ SlmCheck::~SlmCheck()
        delete m_pCompiledScript;
 }
 
+//
+// Compile script if there is one
+//
+
+void SlmCheck::compileScript()
+{
+       if (m_type == check_script && m_script != NULL)
+       {
+               const int errorMsgLen = 512;
+               TCHAR errorMsg[errorMsgLen];
+
+               m_pCompiledScript = NXSLCompile(m_script, errorMsg, errorMsgLen);
+               if (m_pCompiledScript == NULL)
+                       nxlog_write(MSG_SLMCHECK_SCRIPT_COMPILATION_ERROR, NXLOG_WARNING, "dss", m_dwId, m_szName, errorMsg);
+       }
+}
 
 //
 // Create object from database data
@@ -115,16 +145,7 @@ BOOL SlmCheck::CreateFromDB(DWORD id)
                // FIXME: load threshold
        }
 
-       // Compile script if there is one
-       if (m_type == check_script && m_script != NULL)
-       {
-               const int errorMsgLen = 512;
-               TCHAR errorMsg[errorMsgLen];
-
-               m_pCompiledScript = NXSLCompile(m_script, errorMsg, errorMsgLen);
-               if (m_pCompiledScript == NULL)
-                       nxlog_write(MSG_SLMCHECK_SCRIPT_COMPILATION_ERROR, NXLOG_WARNING, "dss", m_dwId, m_szName, errorMsg);
-       }
+       compileScript();
 
        DBFreeResult(hResult);
        DBFreeStatement(hStmt);
index 0ce33b2..48e13ef 100644 (file)
@@ -362,6 +362,11 @@ public:
    void SetCustomAttributePV(const TCHAR *name, TCHAR *value) { m_customAttributes.setPreallocated(_tcsdup(name), value); Modify(); }
    void DeleteCustomAttribute(const TCHAR *name) { m_customAttributes.remove(name); Modify(); }
 
+   NetObj** getChildList() { return m_pChildList; }
+   DWORD getChildCount() { return m_dwChildCount; }
+   NetObj** getParentList() { return m_pParentList; }
+   DWORD getParentCount() { return m_dwParentCount; }
+
    // Debug methods
    const TCHAR *ParentList(TCHAR *szBuffer);
    const TCHAR *ChildList(TCHAR *szBuffer);
@@ -1575,10 +1580,12 @@ protected:
        bool insertTicket();
        void closeTicket();
        void setReason(const TCHAR *reason) { nx_strncpy(m_reason, CHECK_NULL_EX(reason), 256); }
+       void compileScript();
 
 public:
        SlmCheck();
        SlmCheck(const TCHAR *name);
+       SlmCheck(const SlmCheck *check);
        virtual ~SlmCheck();
 
        virtual int Type() { return OBJECT_SLMCHECK; }