Added new type of AgentPolicy(LogParserPolicy). Now log parser XML can be uploaded...
authorTatjana Dubrovica <zev@radensolutions.com>
Thu, 21 Apr 2016 15:41:41 +0000 (18:41 +0300)
committerTatjana Dubrovica <zev@radensolutions.com>
Thu, 21 Apr 2016 15:41:41 +0000 (18:41 +0300)
28 files changed:
include/netxmsdb.h
include/nms_agent.h
include/nxcldefs.h
sql/schema.in
src/agent/core/nxagentd.cpp
src/agent/core/nxagentd.h
src/agent/core/policy.cpp
src/agent/subagents/logwatch/logwatch.cpp
src/agent/subagents/logwatch/logwatch.h
src/java/client/netxms-client/src/main/java/org/netxms/client/NXCSession.java
src/java/client/netxms-client/src/main/java/org/netxms/client/objects/AbstractObject.java
src/java/client/netxms-client/src/main/java/org/netxms/client/objects/AgentPolicyLogParser.java [new file with mode: 0644]
src/java/netxms-eclipse/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/api/ObjectAdapter.java
src/java/netxms-eclipse/PolicyManager/plugin.xml
src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/CreateAgentPolicyLogParser.java [new file with mode: 0644]
src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java [new file with mode: 0644]
src/server/core/Makefile.am
src/server/core/agent_policy.cpp
src/server/core/ap_config.cpp
src/server/core/ap_logparser.cpp [copied from src/server/core/ap_config.cpp with 68% similarity]
src/server/core/objects.cpp
src/server/core/session.cpp
src/server/include/nms_objects.h
src/server/tools/nxdbmgr/upgrade.cpp
webui/webapp/ObjectBrowser/src/org/netxms/ui/eclipse/objectbrowser/api/ObjectAdapter.java
webui/webapp/PolicyManager/plugin.xml
webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/CreateAgentPolicyLogParser.java [new file with mode: 0644]
webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java [new file with mode: 0644]

index d069265..4095bdd 100644 (file)
@@ -23,6 +23,6 @@
 #ifndef _netxmsdb_h
 #define _netxmsdb_h
 
-#define DB_FORMAT_VERSION   395
+#define DB_FORMAT_VERSION   396
 
 #endif
index 8faad03..b90d5c7 100644 (file)
 #define AGENT_POLICY_CONFIG      1
 #define AGENT_POLICY_LOG_PARSER  2
 
+/**
+ * Agent log parser policy folder
+ */
+#define LOGPARSER_AP_FOLDER _T("logparser_ap")
+
 /**
  * Error codes
  */
index 0224572..35463be 100644 (file)
 /**
  * Object types
  */
-#define OBJECT_GENERIC              0
-#define OBJECT_SUBNET               1
-#define OBJECT_NODE                 2
-#define OBJECT_INTERFACE            3
-#define OBJECT_NETWORK              4
-#define OBJECT_CONTAINER            5
-#define OBJECT_ZONE                 6
-#define OBJECT_SERVICEROOT          7
-#define OBJECT_TEMPLATE             8
-#define OBJECT_TEMPLATEGROUP        9
-#define OBJECT_TEMPLATEROOT         10
-#define OBJECT_NETWORKSERVICE       11
-#define OBJECT_VPNCONNECTOR         12
-#define OBJECT_CONDITION            13
-#define OBJECT_CLUSTER                       14
-#define OBJECT_POLICYGROUP          15
-#define OBJECT_POLICYROOT           16
-#define OBJECT_AGENTPOLICY          17
-#define OBJECT_AGENTPOLICY_CONFIG   18
-#define OBJECT_NETWORKMAPROOT       19
-#define OBJECT_NETWORKMAPGROUP      20
-#define OBJECT_NETWORKMAP           21
-#define OBJECT_DASHBOARDROOT        22
-#define OBJECT_DASHBOARD            23
-#define OBJECT_BUSINESSSERVICEROOT  27
-#define OBJECT_BUSINESSSERVICE      28
-#define OBJECT_NODELINK             29
-#define OBJECT_SLMCHECK             30
-#define OBJECT_MOBILEDEVICE         31
-#define OBJECT_RACK                 32
-#define OBJECT_ACCESSPOINT          33
+#define OBJECT_GENERIC               0
+#define OBJECT_SUBNET                1
+#define OBJECT_NODE                  2
+#define OBJECT_INTERFACE             3
+#define OBJECT_NETWORK               4
+#define OBJECT_CONTAINER             5
+#define OBJECT_ZONE                  6
+#define OBJECT_SERVICEROOT           7
+#define OBJECT_TEMPLATE              8
+#define OBJECT_TEMPLATEGROUP         9
+#define OBJECT_TEMPLATEROOT          10
+#define OBJECT_NETWORKSERVICE        11
+#define OBJECT_VPNCONNECTOR          12
+#define OBJECT_CONDITION             13
+#define OBJECT_CLUSTER                        14
+#define OBJECT_POLICYGROUP           15
+#define OBJECT_POLICYROOT            16
+#define OBJECT_AGENTPOLICY           17
+#define OBJECT_AGENTPOLICY_CONFIG    18
+#define OBJECT_NETWORKMAPROOT        19
+#define OBJECT_NETWORKMAPGROUP       20
+#define OBJECT_NETWORKMAP            21
+#define OBJECT_DASHBOARDROOT         22
+#define OBJECT_DASHBOARD             23
+#define OBJECT_BUSINESSSERVICEROOT   27
+#define OBJECT_BUSINESSSERVICE       28
+#define OBJECT_NODELINK              29
+#define OBJECT_SLMCHECK              30
+#define OBJECT_MOBILEDEVICE          31
+#define OBJECT_RACK                  32
+#define OBJECT_ACCESSPOINT           33
+#define OBJECT_AGENTPOLICY_LOGPARSER 34
 
 /** Base value for custom object classes */
 #define OBJECT_CUSTOM               10000
index 2faaa17..3c6f081 100644 (file)
@@ -771,7 +771,7 @@ COMMENT_COLUMN(dct_node_map.template_id, '')
 COMMENT_COLUMN(dct_node_map.node_id, '')
 
 /**
- * Nodes to subnets mapping 
+ * Nodes to subnets mapping
  */
 CREATE TABLE nsmap
 (
@@ -785,7 +785,7 @@ COMMENT_COLUMN(nsmap.subnet_id, '')
 COMMENT_COLUMN(nsmap.node_id, '')
 
 /**
- * Container members 
+ * Container members
  */
 CREATE TABLE container_members
 (
@@ -1871,7 +1871,6 @@ COMMENT_COLUMN(snmp_communities.community, '')
 /*
 ** Agent policies - common attributes
 */
-
 CREATE TABLE ap_common
 (
   id integer not null,
@@ -1880,10 +1879,10 @@ CREATE TABLE ap_common
   PRIMARY KEY(id)
 ) TABLE_TYPE;
 
-COMMENT_TABLE(ap_common, '')
-COMMENT_COLUMN(ap_common.id, '')
-COMMENT_COLUMN(ap_common.policy_type, '')
-COMMENT_COLUMN(ap_common.version, '')
+COMMENT_TABLE(ap_common, 'Agent policies common attributes')
+COMMENT_COLUMN(ap_common.id, 'Unique policy identifier')
+COMMENT_COLUMN(ap_common.policy_type, 'Policy type')
+COMMENT_COLUMN(ap_common.version, 'Policy version')
 
 /*
 ** Agent policies - node binding
@@ -1895,9 +1894,9 @@ CREATE TABLE ap_bindings
   PRIMARY KEY(policy_id,node_id)
 ) TABLE_TYPE;
 
-COMMENT_TABLE(ap_bindings, '')
-COMMENT_COLUMN(ap_bindings.policy_id, '')
-COMMENT_COLUMN(ap_bindings.node_id, '')
+COMMENT_TABLE(ap_bindings, 'Agent policies to node binding')
+COMMENT_COLUMN(ap_bindings.policy_id, 'Unique policy identifier')
+COMMENT_COLUMN(ap_bindings.node_id, 'Unique node identifier')
 
 /*
 ** Agent policies - configuration files
@@ -1909,9 +1908,23 @@ CREATE TABLE ap_config_files
   PRIMARY KEY(policy_id)
 ) TABLE_TYPE;
 
-COMMENT_TABLE(ap_config_files, '')
-COMMENT_COLUMN(ap_config_files.policy_id, '')
-COMMENT_COLUMN(ap_config_files.file_content, '')
+COMMENT_TABLE(ap_config_files, 'Agent policies configuration files')
+COMMENT_COLUMN(ap_config_files.policy_id, 'Unique policy identifier')
+COMMENT_COLUMN(ap_config_files.file_content, 'Policy file content')
+
+/**
+** Agent policies - log parser files
+*/
+CREATE TABLE ap_log_parser
+(
+  policy_id integer not null,
+  file_content SQL_TEXT null,
+  PRIMARY KEY(policy_id)
+) TABLE_TYPE;
+
+COMMENT_TABLE(ap_log_parser, 'Agent policies log parser files')
+COMMENT_COLUMN(ap_log_parser.policy_id, 'Unique policy identifier')
+COMMENT_COLUMN(ap_log_parser.file_content, 'Log parser policy file content')
 
 /*
 ** Default SNMP v3 USM credentials
@@ -1927,13 +1940,13 @@ CREATE TABLE usm_credentials
   PRIMARY KEY(id)
 ) TABLE_TYPE;
 
-COMMENT_TABLE(usm_credentials, '')
-COMMENT_COLUMN(usm_credentials.id, '')
-COMMENT_COLUMN(usm_credentials.user_name, '')
-COMMENT_COLUMN(usm_credentials.auth_method, '')
-COMMENT_COLUMN(usm_credentials.priv_method, '')
-COMMENT_COLUMN(usm_credentials.auth_password, '')
-COMMENT_COLUMN(usm_credentials.priv_password, '')
+COMMENT_TABLE(usm_credentials, 'Default SNMP v3 USM credentials')
+COMMENT_COLUMN(usm_credentials.id, 'SNMP v3 USM credential unique identifier')
+COMMENT_COLUMN(usm_credentials.user_name, 'SNMP v3 USM username')
+COMMENT_COLUMN(usm_credentials.auth_method, 'SNMP v3 USM authentication method')
+COMMENT_COLUMN(usm_credentials.priv_method, 'SNMP v3 USM encryption method')
+COMMENT_COLUMN(usm_credentials.auth_password, 'SNMP v3 USM authentication password')
+COMMENT_COLUMN(usm_credentials.priv_password, 'SNMP v3 USM encryption password')
 
 /*
 ** Network maps
index bd23695..b77a9da 100644 (file)
@@ -146,6 +146,7 @@ TCHAR g_szConfigServer[MAX_DB_STRING] = _T("not_set");
 TCHAR g_szRegistrar[MAX_DB_STRING] = _T("not_set");
 TCHAR g_szListenAddress[MAX_PATH] = _T("*");
 TCHAR g_szConfigIncludeDir[MAX_PATH] = AGENT_DEFAULT_CONFIG_D;
+TCHAR g_szLogParserDirectory[MAX_PATH] = _T("");
 TCHAR g_masterAgent[MAX_PATH] = _T("not_set");
 TCHAR g_szSNMPTrapListenAddress[MAX_PATH] = _T("*");
 UINT16 g_wListenPort = AGENT_LISTEN_PORT;
@@ -727,6 +728,14 @@ BOOL Initialize()
    DebugPrintf(INVALID_INDEX, 1, _T("Data directory: %s"), g_szDataDirectory);
    CreateFolder(g_szDataDirectory);
 
+   //Initialize log parser policy folder
+   TCHAR tail = g_szDataDirectory[_tcslen(g_szDataDirectory) - 1];
+       _sntprintf(g_szLogParserDirectory, MAX_PATH, _T("%s%s%s"), g_szDataDirectory,
+                  ((tail != '\\') && (tail != '/')) ? FS_PATH_SEPARATOR : _T(""),
+              LOGPARSER_AP_FOLDER FS_PATH_SEPARATOR);
+   DebugPrintf(INVALID_INDEX, 6, _T("Log parser policy directory: %s"), g_szLogParserDirectory);
+       CreateFolder(g_szLogParserDirectory);
+
        // Initialize persistent storage
        s_registry = new Config;
        s_registry->setTopLevelTag(_T("registry"));
index 0771622..1255a70 100644 (file)
@@ -627,6 +627,7 @@ extern TCHAR g_szConfigServer[];
 extern TCHAR g_szRegistrar[];
 extern TCHAR g_szListenAddress[];
 extern TCHAR g_szConfigIncludeDir[];
+extern TCHAR g_szLogParserDirectory[];
 extern TCHAR g_szDataDirectory[];
 extern TCHAR g_masterAgent[];
 extern TCHAR g_szSNMPTrapListenAddress[];
index 4c29240..094111c 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
 ** NetXMS multiplatform core agent
 ** Copyright (C) 2003-2013 Victor Kirhenshtein
 **
@@ -132,7 +132,45 @@ static UINT32 DeployConfig(UINT32 session, const uuid& guid, NXCPMessage *msg)
  */
 static UINT32 DeployLogParser(UINT32 session, const uuid& guid, NXCPMessage *msg)
 {
-       return ERR_NOT_IMPLEMENTED;
+   TCHAR path[MAX_PATH], name[64];
+       int fh;
+       UINT32 rcc;
+
+       _sntprintf(path, MAX_PATH, _T("%s%s.xml"), g_szLogParserDirectory
+               ,guid.toString(name));
+
+       fh = _topen(path, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, S_IRUSR | S_IWUSR);
+       if (fh != -1)
+       {
+               UINT32 size = msg->getFieldAsBinary(VID_CONFIG_FILE_DATA, NULL, 0);
+               BYTE *data = (BYTE *)malloc(size);
+               if (data != NULL)
+               {
+                       msg->getFieldAsBinary(VID_CONFIG_FILE_DATA, data, size);
+                       if (write(fh, data, size) == size)
+                       {
+                     DebugPrintf(session, 3, _T("Log parser file %s saved successfully"), path);
+                               rcc = ERR_SUCCESS;
+                       }
+                       else
+                       {
+                               rcc = ERR_IO_FAILURE;
+                       }
+                       free(data);
+               }
+               else
+               {
+                       rcc = ERR_MEM_ALLOC_FAILED;
+               }
+               close(fh);
+       }
+       else
+       {
+               DebugPrintf(session, 2, _T("DeployLogParser(): Error opening file %s for writing (%s)"), path, _tcserror(errno));
+               rcc = ERR_FILE_OPEN_ERROR;
+       }
+
+       return rcc;
 }
 
 /**
@@ -194,13 +232,11 @@ static UINT32 RemoveConfig(UINT32 session, const uuid& guid, NXCPMessage *msg)
  */
 static UINT32 RemoveLogParser(UINT32 session, const uuid& guid,  NXCPMessage *msg)
 {
-       TCHAR path[MAX_PATH], name[64], tail;
+       TCHAR path[MAX_PATH], name[64];
        UINT32 rcc;
 
-       tail = g_szConfigIncludeDir[_tcslen(g_szConfigIncludeDir) - 1];
-       _sntprintf(path, MAX_PATH, _T("%s%s%s.conf"), g_szConfigIncludeDir,
-                  ((tail != '\\') && (tail != '/')) ? FS_PATH_SEPARATOR : _T(""),
-              guid.toString(name));
+       _sntprintf(path, MAX_PATH, _T("%s%s.xml"), g_szLogParserDirectory
+               ,guid.toString(name));
 
        if (_tremove(path) != 0)
        {
@@ -276,7 +312,7 @@ UINT32 GetPolicyInventory(CommSession *session, NXCPMessage *msg)
        {
                msg->setField(VID_NUM_ELEMENTS, (UINT32)0);
        }
-       
+
        AgentCloseRegistry(false);
        return RCC_SUCCESS;
 }
index e661f25..98297b1 100644 (file)
@@ -216,6 +216,49 @@ static void AddParserFromConfig(const TCHAR *file)
        }
 }
 
+/**
+ * Add to logwatch everything inside logwatch policy folder
+ */
+static void AddLogwatchPolicyFiles()
+{
+   const TCHAR *dataDir = AgentGetDataDirectory();
+   TCHAR policyFolder[MAX_PATH];
+   TCHAR tail = dataDir[_tcslen(dataDir) - 1];
+       _sntprintf(policyFolder, MAX_PATH, _T("%s%s%s"), dataDir,
+                  ((tail != '\\') && (tail != '/')) ? FS_PATH_SEPARATOR : _T(""),
+              LOGPARSER_AP_FOLDER FS_PATH_SEPARATOR);
+
+   AgentWriteDebugLog(1, _T("AddLogwatchPolicyFiles(): Log parser policy directory: %s"), policyFolder);
+
+   _TDIR *dir = _topendir(policyFolder);
+   if (dir != NULL)
+   {
+      struct _tdirent *d;
+      while((d = _treaddir(dir)) != NULL)
+      {
+         if (!_tcscmp(d->d_name, _T(".")) || !_tcscmp(d->d_name, _T("..")))
+         {
+            continue;
+         }
+
+         TCHAR fullName[MAX_PATH];
+         _tcscpy(fullName, policyFolder);
+         _tcscat(fullName, FS_PATH_SEPARATOR);
+         _tcscat(fullName, d->d_name);
+
+         NX_STAT_STRUCT st;
+         if (CALL_STAT(fullName, &st) == 0)
+         {
+            if(S_ISREG(st.st_mode))
+            {
+               AddParserFromConfig(fullName);
+            }
+         }
+      }
+      _tclosedir(dir);
+   }
+}
+
 /**
  * Subagent initialization
  */
@@ -231,6 +274,7 @@ static BOOL SubagentInit(Config *config)
                for(int i = 0; i < parsers->getValueCount(); i++)
                        AddParserFromConfig(parsers->getValue(i));
        }
+   AddLogwatchPolicyFiles();
 
        // Create shutdown condition and start parsing threads
        s_shutdownCondition = ConditionCreate(TRUE);
index 1d7607f..7d28e6f 100644 (file)
@@ -27,5 +27,6 @@
 #include <nms_util.h>
 #include <nms_agent.h>
 #include <nxlpapi.h>
+#include <nxstat.h>
 
 #endif
index c5e1f5f..7e28ab8 100644 (file)
@@ -112,6 +112,7 @@ import org.netxms.client.objects.AbstractObject;
 import org.netxms.client.objects.AccessPoint;
 import org.netxms.client.objects.AgentPolicy;
 import org.netxms.client.objects.AgentPolicyConfig;
+import org.netxms.client.objects.AgentPolicyLogParser;
 import org.netxms.client.objects.BusinessService;
 import org.netxms.client.objects.BusinessServiceRoot;
 import org.netxms.client.objects.Cluster;
@@ -1072,6 +1073,9 @@ public class NXCSession
          case AbstractObject.OBJECT_AGENTPOLICY_CONFIG:
             object = new AgentPolicyConfig(msg, this);
             break;
+         case AbstractObject.OBJECT_AGENTPOLICY_LOGPARSER:
+            object = new AgentPolicyLogParser(msg, this);
+            break;
          case AbstractObject.OBJECT_BUSINESSSERVICE:
             object = new BusinessService(msg, this);
             break;
index 80d5e60..6db8600 100644 (file)
@@ -95,6 +95,7 @@ public abstract class AbstractObject
        public static final int OBJECT_MOBILEDEVICE = 31;
        public static final int OBJECT_RACK = 32;
        public static final int OBJECT_ACCESSPOINT = 33;
+       public static final int OBJECT_AGENTPOLICY_LOGPARSER = 34;
        public static final int OBJECT_CUSTOM = 10000;
        
        // Status calculation methods
diff --git a/src/java/client/netxms-client/src/main/java/org/netxms/client/objects/AgentPolicyLogParser.java b/src/java/client/netxms-client/src/main/java/org/netxms/client/objects/AgentPolicyLogParser.java
new file mode 100644 (file)
index 0000000..77fe416
--- /dev/null
@@ -0,0 +1,50 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2010 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.
+ */
+package org.netxms.client.objects;
+
+import org.netxms.base.NXCPCodes;
+import org.netxms.base.NXCPMessage;
+import org.netxms.client.NXCSession;
+
+/**
+ * Agent policy for deploying configuration files
+ *
+ */
+public class AgentPolicyLogParser extends AgentPolicy
+{
+       private String fileContent;
+
+       /**
+        * @param msg
+        * @param session
+        */
+       public AgentPolicyLogParser(NXCPMessage msg, NXCSession session)
+       {
+               super(msg, session);
+               fileContent = msg.getFieldAsString(NXCPCodes.VID_CONFIG_FILE_DATA);
+       }
+
+       /**
+        * @return the fileContent
+        */
+       public String getFileContent()
+       {
+               return fileContent;
+       }
+}
index 7d2135d..8ac3911 100644 (file)
@@ -92,6 +92,7 @@ public class ObjectAdapter implements IWorkbenchAdapter
                                return Activator.getImageDescriptor("icons/policy_group.png"); //$NON-NLS-1$
                        case AbstractObject.OBJECT_AGENTPOLICY:
                        case AbstractObject.OBJECT_AGENTPOLICY_CONFIG:
+                       case AbstractObject.OBJECT_AGENTPOLICY_LOGPARSER:
                                return Activator.getImageDescriptor("icons/policy.png"); //$NON-NLS-1$
                        case AbstractObject.OBJECT_NETWORKMAP:
                                return Activator.getImageDescriptor("icons/netmap.png"); //$NON-NLS-1$
index 7d8bd4e..02661dc 100644 (file)
              </instanceof>
           </enabledWhen>
         </page>
+        <page
+              class="org.netxms.ui.eclipse.policymanager.propertypages.ParserFile"
+              id="org.netxms.ui.eclipse.policymanager.propertypages.ParserFile"
+              name="Log Parser File">
+           <enabledWhen>
+              <instanceof
+                    value="org.netxms.client.objects.AgentPolicyLogParser">
+              </instanceof>
+           </enabledWhen>
+        </page>
   </extension>
 
    <extension
                label="%action.label.CreatePolicyGrp"
                menubarPath="objectcreation">
          </action>
+         <action
+               class="org.netxms.ui.eclipse.policymanager.actions.CreateAgentPolicyLogParser"
+               enablesFor="1"
+               id="org.netxms.ui.eclipse.policymanager.popupActions.CreateAgentPolicyLogParser_PolicyRoot"
+               label="Create log parser policy(xml file)..."
+               menubarPath="objectcreation">
+         </action>
       </objectContribution>
       <objectContribution
             adaptable="false"
                label="%action.label.CreatePolicyGrp"
                menubarPath="objectcreation">
          </action>
+         <action
+               class="org.netxms.ui.eclipse.policymanager.actions.CreateAgentPolicyLogParser"
+               enablesFor="1"
+               id="org.netxms.ui.eclipse.policymanager.popupActions.CreateAgentPolicyLogParser_PolicyGroup"
+               label="Create log parser policy(xml file)..."
+               menubarPath="objectcreation">
+         </action>
       </objectContribution>
       <objectContribution
             adaptable="false"
diff --git a/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/CreateAgentPolicyLogParser.java b/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/CreateAgentPolicyLogParser.java
new file mode 100644 (file)
index 0000000..038978e
--- /dev/null
@@ -0,0 +1,96 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2011 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.
+ */
+package org.netxms.ui.eclipse.policymanager.actions;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.netxms.client.NXCObjectCreationData;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.PolicyGroup;
+import org.netxms.client.objects.PolicyRoot;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog;
+import org.netxms.ui.eclipse.policymanager.Activator;
+import org.netxms.ui.eclipse.policymanager.Messages;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+
+/**
+ * @author Victor
+ *
+ */
+public class CreateAgentPolicyLogParser implements IObjectActionDelegate
+{
+       private IWorkbenchPart targetPart;
+       private AbstractObject currentObject;
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
+        */
+       @Override
+       public void setActivePart(IAction action, IWorkbenchPart targetPart)
+       {
+               this.targetPart = targetPart;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+        */
+       @Override
+       public void run(IAction action)
+       {
+               final CreateObjectDialog dlg = new CreateObjectDialog(targetPart.getSite().getShell(), Messages.get().CreateAgentPolicyConfig_AgentPolicy_Config);
+               if (dlg.open() == Window.OK)
+               {
+                       final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+                       new ConsoleJob(Messages.get().CreateAgentPolicyConfig_JobName, targetPart, Activator.PLUGIN_ID, null) {
+                               @Override
+                               protected void runInternal(IProgressMonitor monitor) throws Exception
+                               {
+                                       NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_AGENTPOLICY_LOGPARSER, dlg.getObjectName(), currentObject.getObjectId());
+                                       session.createObject(cd);
+                               }
+
+                               @Override
+                               protected String getErrorMessage()
+                               {
+                                       return Messages.get().CreateAgentPolicyConfig_JobError;
+                               }
+                       }.start();
+               }
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+        */
+       @Override
+       public void selectionChanged(IAction action, ISelection selection)
+       {
+               if (selection instanceof TreeSelection)
+               {
+                       currentObject = (AbstractObject)((TreeSelection)selection).getFirstElement();
+                       action.setEnabled((currentObject instanceof PolicyRoot) || (currentObject instanceof PolicyGroup));
+               }
+       }
+}
diff --git a/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java b/src/java/netxms-eclipse/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java
new file mode 100644 (file)
index 0000000..fb40927
--- /dev/null
@@ -0,0 +1,156 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2010 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.
+ */
+package org.netxms.ui.eclipse.policymanager.propertypages;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.PropertyPage;
+import org.netxms.client.NXCObjectModificationData;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AgentPolicyLogParser;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.policymanager.Activator;
+import org.netxms.ui.eclipse.policymanager.Messages;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+
+/**
+ * Property page for agent configuration policy
+ *
+ */
+public class ParserFile extends PropertyPage
+{
+       private Text textContent;
+       private String initialContent;
+       private AgentPolicyLogParser object;
+       
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+        */
+       @Override
+       protected Control createContents(Composite parent)
+       {
+               Composite dialogArea = new Composite(parent, SWT.NONE);
+               
+               object = (AgentPolicyLogParser)getElement().getAdapter(AgentPolicyLogParser.class);
+               if (object == null)     // Paranoid check
+                       return dialogArea;
+               
+               GridLayout layout = new GridLayout();
+               layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
+               layout.marginWidth = 0;
+               layout.marginHeight = 0;
+               //FormLayout layout = new FormLayout();
+      dialogArea.setLayout(layout);
+      
+               // File content
+      Label label = new Label(dialogArea, SWT.NONE);
+      label.setText(Messages.get().ConfigFile_File);
+      
+      initialContent = new String(object.getFileContent());
+      GridData gd = new GridData();
+      gd.grabExcessHorizontalSpace = true;
+      gd.grabExcessVerticalSpace = true;
+      gd.horizontalAlignment = GridData.FILL;
+      gd.verticalAlignment = GridData.FILL;
+      gd.heightHint = 0;
+      textContent = new Text(dialogArea, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+      textContent.setText(object.getFileContent());
+      textContent.setLayoutData(gd);
+      
+               return dialogArea;
+       }
+       
+       
+       /**
+        * Apply changes
+        * 
+        * @param isApply true if update operation caused by "Apply" button
+        */
+       protected void applyChanges(final boolean isApply)
+       {
+               if (textContent.getText().equals(initialContent))
+                       return;         // Nothing to apply
+               
+               if (isApply)
+                       setValid(false);
+               
+               final String newContent = new String(textContent.getText());
+               new ConsoleJob(Messages.get().ConfigFile_JobName, null, Activator.PLUGIN_ID, null) {
+                       @Override
+                       protected void runInternal(IProgressMonitor monitor) throws Exception
+                       {
+                               if (object != null)
+                               {
+                                       NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
+                                       md.setConfigFileContent(newContent);
+                                       ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
+                               }
+                               initialContent = newContent;
+                       }
+
+                       @Override
+                       protected void jobFinalize()
+                       {
+                               if (isApply)
+                               {
+                                  runInUIThread(new Runnable() {
+                  @Override
+                  public void run()
+                  {
+                     ParserFile.this.setValid(true);
+                  }
+               });
+                               }
+                       }
+
+                       @Override
+                       protected String getErrorMessage()
+                       {
+                               return Messages.get().ConfigFile_JobError;
+                       }
+               }.start();
+       }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.preference.PreferencePage#performOk()
+        */
+       @Override
+       public boolean performOk()
+       {
+               applyChanges(false);
+               return true;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.preference.PreferencePage#performApply()
+        */
+       @Override
+       protected void performApply()
+       {
+               applyChanges(true);
+       }
+}
index 8ccad6f..3986a0a 100644 (file)
@@ -3,7 +3,7 @@
 lib_LTLIBRARIES = libnxcore.la
 libnxcore_la_SOURCES =  accesspoint.cpp acl.cpp actions.cpp addrlist.cpp \
                        admin.cpp agent.cpp agent_policy.cpp alarm.cpp audit.cpp \
-                       ap_config.cpp ap_jobs.cpp beacon.cpp bizservice.cpp \
+                       ap_config.cpp ap_jobs.cpp ap_logparser.cpp beacon.cpp bizservice.cpp \
                        bizsvcroot.cpp bridge.cpp cas_validator.cpp cdp.cpp \
                        cert.cpp client.cpp cluster.cpp columnfilter.cpp \
                        components.cpp condition.cpp config.cpp container.cpp \
index c6bf315..36216cb 100644 (file)
@@ -218,9 +218,6 @@ void AgentPolicy::fillMessageInternal(NXCPMessage *msg)
  */
 UINT32 AgentPolicy::modifyFromMessageInternal(NXCPMessage *pRequest)
 {
-       if (pRequest->isFieldExist(VID_VERSION))
-               m_version = pRequest->getFieldAsUInt32(VID_VERSION);
-
    return NetObj::modifyFromMessageInternal(pRequest);
 }
 
index 6871fae..8a391d6 100644 (file)
 #include "nxcore.h"
 
 
-//
-// Agent policy default constructor
-//
-
+/**
+ * Agent policy default constructor
+ */
 AgentPolicyConfig::AgentPolicyConfig()
                   : AgentPolicy(AGENT_POLICY_CONFIG)
 {
@@ -34,10 +33,9 @@ AgentPolicyConfig::AgentPolicyConfig()
 }
 
 
-//
-// Constructor for user-initiated object creation
-//
-
+/**
+ * Constructor for user-initiated object creation
+ */
 AgentPolicyConfig::AgentPolicyConfig(const TCHAR *name)
                   : AgentPolicy(name, AGENT_POLICY_CONFIG)
 {
@@ -45,20 +43,18 @@ AgentPolicyConfig::AgentPolicyConfig(const TCHAR *name)
 }
 
 
-//
-// Destructor
-//
-
+/**
+ * Destructor
+ */
 AgentPolicyConfig::~AgentPolicyConfig()
 {
        safe_free(m_fileContent);
 }
 
 
-//
-// Save to database
-//
-
+/**
+ * Save to database
+ */
 BOOL AgentPolicyConfig::saveToDatabase(DB_HANDLE hdb)
 {
        lockProperties();
@@ -180,10 +176,9 @@ bool AgentPolicyConfig::createDeploymentMessage(NXCPMessage *msg)
 }
 
 
-//
-// Create uninstall message
-//
-
+/**
+ * Create uninstall message
+ */
 bool AgentPolicyConfig::createUninstallMessage(NXCPMessage *msg)
 {
        return AgentPolicy::createUninstallMessage(msg);
similarity index 68%
copy from src/server/core/ap_config.cpp
copy to src/server/core/ap_logparser.cpp
index 6871fae..234404c 100644 (file)
 
 #include "nxcore.h"
 
-
-//
-// Agent policy default constructor
-//
-
-AgentPolicyConfig::AgentPolicyConfig()
-                  : AgentPolicy(AGENT_POLICY_CONFIG)
+/**
+ * Agent policy default constructor
+ */
+AgentPolicyLogParser::AgentPolicyLogParser()
+                  : AgentPolicy(AGENT_POLICY_LOG_PARSER)
 {
        m_fileContent = NULL;
 }
 
 
-//
-// Constructor for user-initiated object creation
-//
-
-AgentPolicyConfig::AgentPolicyConfig(const TCHAR *name)
-                  : AgentPolicy(name, AGENT_POLICY_CONFIG)
+/**
+ * Constructor for user-initiated object creation
+ */
+AgentPolicyLogParser::AgentPolicyLogParser(const TCHAR *name)
+                  : AgentPolicy(name, AGENT_POLICY_LOG_PARSER)
 {
        m_fileContent = NULL;
 }
 
 
-//
-// Destructor
-//
-
-AgentPolicyConfig::~AgentPolicyConfig()
+/**
+ * Destructor
+ */
+AgentPolicyLogParser::~AgentPolicyLogParser()
 {
        safe_free(m_fileContent);
 }
 
 
-//
-// Save to database
-//
-
-BOOL AgentPolicyConfig::saveToDatabase(DB_HANDLE hdb)
+/**
+ * Save to database
+ */
+BOOL AgentPolicyLogParser::saveToDatabase(DB_HANDLE hdb)
 {
        lockProperties();
 
@@ -70,7 +65,7 @@ BOOL AgentPolicyConfig::saveToDatabase(DB_HANDLE hdb)
                size_t len = data.length() + 256;
                TCHAR *query = (TCHAR *)malloc(len * sizeof(TCHAR));
 
-               _sntprintf(query, len, _T("SELECT policy_id FROM ap_config_files WHERE policy_id=%d"), m_id);
+               _sntprintf(query, len, _T("SELECT policy_id FROM ap_log_parser WHERE policy_id=%d"), m_id);
                DB_RESULT hResult = DBSelect(hdb, query);
                if (hResult != NULL)
                {
@@ -78,10 +73,10 @@ BOOL AgentPolicyConfig::saveToDatabase(DB_HANDLE hdb)
                        DBFreeResult(hResult);
 
                        if (isNew)
-                               _sntprintf(query, len, _T("INSERT INTO ap_config_files (policy_id,file_content) VALUES (%d,%s)"),
+                               _sntprintf(query, len, _T("INSERT INTO ap_log_parser (policy_id,file_content) VALUES (%d,%s)"),
                                           m_id, (const TCHAR *)data);
                        else
-                               _sntprintf(query, len, _T("UPDATE ap_config_files SET file_content=%s WHERE policy_id=%d"),
+                               _sntprintf(query, len, _T("UPDATE ap_log_parser SET file_content=%s WHERE policy_id=%d"),
                                           (const TCHAR *)data, m_id);
                        success = DBQuery(hdb, query);
                }
@@ -99,12 +94,12 @@ BOOL AgentPolicyConfig::saveToDatabase(DB_HANDLE hdb)
 /**
  * Delete from database
  */
-bool AgentPolicyConfig::deleteFromDatabase(DB_HANDLE hdb)
+bool AgentPolicyLogParser::deleteFromDatabase(DB_HANDLE hdb)
 {
        bool success = AgentPolicy::deleteFromDatabase(hdb);
    if (success)
    {
-      success = executeQueryOnObject(hdb, _T("DELETE FROM ap_config_files WHERE policy_id=?"));
+      success = executeQueryOnObject(hdb, _T("DELETE FROM ap_log_parser WHERE policy_id=?"));
    }
    return success;
 }
@@ -112,7 +107,7 @@ bool AgentPolicyConfig::deleteFromDatabase(DB_HANDLE hdb)
 /**
  * Load from database
  */
-bool AgentPolicyConfig::loadFromDatabase(DB_HANDLE hdb, UINT32 dwId)
+bool AgentPolicyLogParser::loadFromDatabase(DB_HANDLE hdb, UINT32 dwId)
 {
        bool success = false;
 
@@ -120,7 +115,7 @@ bool AgentPolicyConfig::loadFromDatabase(DB_HANDLE hdb, UINT32 dwId)
        {
                TCHAR query[256];
 
-               _sntprintf(query, 256, _T("SELECT file_content FROM ap_config_files WHERE policy_id=%d"), dwId);
+               _sntprintf(query, 256, _T("SELECT file_content FROM ap_log_parser WHERE policy_id=%d"), dwId);
                DB_RESULT hResult = DBSelect(hdb, query);
                if (hResult != NULL)
                {
@@ -138,7 +133,7 @@ bool AgentPolicyConfig::loadFromDatabase(DB_HANDLE hdb, UINT32 dwId)
 /**
  * Create NXCP message with policy data
  */
-void AgentPolicyConfig::fillMessageInternal(NXCPMessage *msg)
+void AgentPolicyLogParser::fillMessageInternal(NXCPMessage *msg)
 {
    AgentPolicy::fillMessageInternal(msg);
        msg->setField(VID_CONFIG_FILE_DATA, CHECK_NULL_EX(m_fileContent));
@@ -147,7 +142,7 @@ void AgentPolicyConfig::fillMessageInternal(NXCPMessage *msg)
 /**
  * Modify policy from message
  */
-UINT32 AgentPolicyConfig::modifyFromMessageInternal(NXCPMessage *pRequest)
+UINT32 AgentPolicyLogParser::modifyFromMessageInternal(NXCPMessage *pRequest)
 {
        if (pRequest->isFieldExist(VID_CONFIG_FILE_DATA))
        {
@@ -161,7 +156,7 @@ UINT32 AgentPolicyConfig::modifyFromMessageInternal(NXCPMessage *pRequest)
 /**
  * Create deployment message
  */
-bool AgentPolicyConfig::createDeploymentMessage(NXCPMessage *msg)
+bool AgentPolicyLogParser::createDeploymentMessage(NXCPMessage *msg)
 {
        if (!AgentPolicy::createDeploymentMessage(msg))
                return false;
@@ -180,11 +175,10 @@ bool AgentPolicyConfig::createDeploymentMessage(NXCPMessage *msg)
 }
 
 
-//
-// Create uninstall message
-//
-
-bool AgentPolicyConfig::createUninstallMessage(NXCPMessage *msg)
+/**
+ * Create uninstall message
+ */
+bool AgentPolicyLogParser::createUninstallMessage(NXCPMessage *msg)
 {
        return AgentPolicy::createUninstallMessage(msg);
 }
index 5bc061d..b78bfcf 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
 ** NetXMS - Network Management System
 ** Copyright (C) 2003-2016 Victor Kirhenshtein
 **
@@ -223,19 +223,19 @@ void ObjectsInit()
        // Create "Policy Root" object
    g_pPolicyRoot = new PolicyRoot;
    NetObjInsert(g_pPolicyRoot, false, false);
-   
+
        // Create "Network Maps Root" object
    g_pMapRoot = new NetworkMapRoot;
    NetObjInsert(g_pMapRoot, false, false);
-   
+
        // Create "Dashboard Root" object
    g_pDashboardRoot = new DashboardRoot;
    NetObjInsert(g_pDashboardRoot, false, false);
-   
+
    // Create "Business Service Root" object
    g_pBusinessServiceRoot = new BusinessServiceRoot;
    NetObjInsert(g_pBusinessServiceRoot, false, false);
-   
+
        DbgPrintf(1, _T("Built-in objects created"));
 
        // Initialize service checks
@@ -255,9 +255,9 @@ void NetObjInsert(NetObj *pObject, bool newObject, bool importedObject)
          pObject->generateGuid();
 
       // Create tables for storing data collection values
-      if ((pObject->getObjectClass() == OBJECT_NODE) || 
-          (pObject->getObjectClass() == OBJECT_MOBILEDEVICE) || 
-          (pObject->getObjectClass() == OBJECT_CLUSTER) || 
+      if ((pObject->getObjectClass() == OBJECT_NODE) ||
+          (pObject->getObjectClass() == OBJECT_MOBILEDEVICE) ||
+          (pObject->getObjectClass() == OBJECT_CLUSTER) ||
           (pObject->getObjectClass() == OBJECT_ACCESSPOINT))
       {
          TCHAR szQuery[256], szQueryTemplate[256];
@@ -388,7 +388,7 @@ void NetObjInsert(NetObj *pObject, bool newObject, bool importedObject)
                                        }
                if (newObject)
                {
-                  PostEvent(EVENT_SUBNET_ADDED, g_dwMgmtNode, "isAd", pObject->getId(), pObject->getName(), 
+                  PostEvent(EVENT_SUBNET_ADDED, g_dwMgmtNode, "isAd", pObject->getId(), pObject->getName(),
                      &((Subnet *)pObject)->getIpAddress(), ((Subnet *)pObject)->getIpAddress().getMaskBits());
                }
             }
@@ -1489,6 +1489,9 @@ BOOL LoadObjects()
                                case AGENT_POLICY_CONFIG:
                                        policy = new AgentPolicyConfig();
                                        break;
+                               case AGENT_POLICY_LOG_PARSER:
+                                       policy = new AgentPolicyLogParser();
+                                       break;
                                default:
                                        policy = new AgentPolicy(type);
                                        break;
@@ -1820,7 +1823,7 @@ static void DumpObjectCallback(NetObj *object, void *data)
                                          object->getId(), object->getName(), object->getObjectClassName(),
                  GetStatusAsText(object->Status(), true),
                  object->isModified(), object->isDeleted());
-   ConsolePrintf(pCtx, _T("   Parents: <%s>\n   Childs: <%s>\n"), 
+   ConsolePrintf(pCtx, _T("   Parents: <%s>\n   Childs: <%s>\n"),
                  object->dbgGetParentList(dd->buffer), object->dbgGetChildList(&dd->buffer[4096]));
        time_t t = object->getTimeStamp();
        struct tm *ltm = localtime(&t);
@@ -1851,7 +1854,7 @@ static void DumpObjectCallback(NetObj *object, void *data)
          }
          break;
       case OBJECT_TEMPLATE:
-         ConsolePrintf(pCtx, _T("   Version: %d.%d\n"), 
+         ConsolePrintf(pCtx, _T("   Version: %d.%d\n"),
                        ((Template *)(object))->getVersionMajor(),
                        ((Template *)(object))->getVersionMinor());
          break;
@@ -1887,7 +1890,7 @@ bool IsValidParentClass(int iChildClass, int iParentClass)
                        break;
       case OBJECT_SERVICEROOT:
       case OBJECT_CONTAINER:
-         if ((iChildClass == OBJECT_CONTAINER) || 
+         if ((iChildClass == OBJECT_CONTAINER) ||
              (iChildClass == OBJECT_RACK) ||
              (iChildClass == OBJECT_NODE) ||
              (iChildClass == OBJECT_CLUSTER) ||
@@ -1902,19 +1905,19 @@ bool IsValidParentClass(int iChildClass, int iParentClass)
          break;
       case OBJECT_TEMPLATEROOT:
       case OBJECT_TEMPLATEGROUP:
-         if ((iChildClass == OBJECT_TEMPLATEGROUP) || 
+         if ((iChildClass == OBJECT_TEMPLATEGROUP) ||
              (iChildClass == OBJECT_TEMPLATE))
             return true;
          break;
       case OBJECT_TEMPLATE:
-         if ((iChildClass == OBJECT_NODE) || 
+         if ((iChildClass == OBJECT_NODE) ||
              (iChildClass == OBJECT_CLUSTER) ||
              (iChildClass == OBJECT_MOBILEDEVICE))
             return true;
          break;
       case OBJECT_NETWORKMAPROOT:
       case OBJECT_NETWORKMAPGROUP:
-         if ((iChildClass == OBJECT_NETWORKMAPGROUP) || 
+         if ((iChildClass == OBJECT_NETWORKMAPGROUP) ||
              (iChildClass == OBJECT_NETWORKMAP))
             return true;
          break;
@@ -1925,9 +1928,10 @@ bool IsValidParentClass(int iChildClass, int iParentClass)
          break;
       case OBJECT_POLICYROOT:
       case OBJECT_POLICYGROUP:
-         if ((iChildClass == OBJECT_POLICYGROUP) || 
+         if ((iChildClass == OBJECT_POLICYGROUP) ||
              (iChildClass == OBJECT_AGENTPOLICY) ||
-             (iChildClass == OBJECT_AGENTPOLICY_CONFIG))
+             (iChildClass == OBJECT_AGENTPOLICY_CONFIG) ||
+             (iChildClass == OBJECT_AGENTPOLICY_LOGPARSER))
             return true;
          break;
       case OBJECT_NODE:
@@ -1941,12 +1945,12 @@ bool IsValidParentClass(int iChildClass, int iParentClass)
             return true;
          break;
                case OBJECT_BUSINESSSERVICEROOT:
-                       if ((iChildClass == OBJECT_BUSINESSSERVICE) || 
+                       if ((iChildClass == OBJECT_BUSINESSSERVICE) ||
                            (iChildClass == OBJECT_NODELINK))
             return true;
          break;
                case OBJECT_BUSINESSSERVICE:
-                       if ((iChildClass == OBJECT_BUSINESSSERVICE) || 
+                       if ((iChildClass == OBJECT_BUSINESSSERVICE) ||
                            (iChildClass == OBJECT_NODELINK) ||
                            (iChildClass == OBJECT_SLMCHECK))
             return true;
@@ -2102,8 +2106,8 @@ bool IsAgentPolicyObject(NetObj *object)
  */
 bool IsEventSource(int objectClass)
 {
-       return (objectClass == OBJECT_NODE) || 
-              (objectClass == OBJECT_CONTAINER) || 
-              (objectClass == OBJECT_CLUSTER) || 
+       return (objectClass == OBJECT_NODE) ||
+              (objectClass == OBJECT_CONTAINER) ||
+              (objectClass == OBJECT_CLUSTER) ||
                         (objectClass == OBJECT_MOBILEDEVICE);
 }
index 73f03b2..e8a440e 100644 (file)
@@ -5016,6 +5016,11 @@ void ClientSession::createObject(NXCPMessage *pRequest)
                                                                   NetObjInsert(object, true, false);
                                                                   object->calculateCompoundStatus();   // Force status change to NORMAL
                                                                   break;
+                        case OBJECT_AGENTPOLICY_LOGPARSER:
+                                                                  object = new AgentPolicyLogParser(szObjectName);
+                                                                  NetObjInsert(object, true, false);
+                                                                  object->calculateCompoundStatus();   // Force status change to NORMAL
+                                                                  break;
                                                           case OBJECT_CLUSTER:
                                                                   object = new Cluster(szObjectName, zoneId);
                                                                   NetObjInsert(object, true, false);
index 45b3693..3891600 100644 (file)
@@ -2041,6 +2041,31 @@ public:
        virtual bool createUninstallMessage(NXCPMessage *msg);
 };
 
+/**
+ * Log parser configuration policy object
+ */
+class NXCORE_EXPORTABLE AgentPolicyLogParser : public AgentPolicy
+{
+ protected:
+   TCHAR *m_fileContent;
+
+   virtual void fillMessageInternal(NXCPMessage *pMsg);
+   virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
+ public:
+   AgentPolicyLogParser();
+   AgentPolicyLogParser(const TCHAR *name);
+   virtual ~AgentPolicyLogParser();
+
+   virtual int getObjectClass() const { return OBJECT_AGENTPOLICY_LOGPARSER; }
+
+   virtual BOOL saveToDatabase(DB_HANDLE hdb);
+   virtual bool deleteFromDatabase(DB_HANDLE hdb);
+   virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
+
+       virtual bool createDeploymentMessage(NXCPMessage *msg);
+       virtual bool createUninstallMessage(NXCPMessage *msg);
+};
+
 /**
  * Policy group object
  */
index 1ccb1e1..606cdc7 100644 (file)
@@ -641,6 +641,21 @@ static int NextFreeEPPruleID()
        return ruleId;
 }
 
+/**
+ * Upgrade from V395 to V396
+ */
+static BOOL H_UpgradeFromV395(int currVersion, int newVersion)
+{
+   CHK_EXEC(CreateTable(
+      _T("CREATE TABLE ap_log_parser (")
+      _T("   policy_id integer not null,")
+      _T("   file_content $SQL:TEXT null,")
+      _T("   PRIMARY KEY(policy_id))")));
+
+   CHK_EXEC(SQLQuery(_T("UPDATE metadata SET var_value='396' WHERE var_name='SchemaVersion'")));
+   return TRUE;
+}
+
 /**
  * Upgrade from V394 to V395
  */
@@ -9482,6 +9497,7 @@ static struct
    { 392, 393, H_UpgradeFromV392 },
    { 393, 394, H_UpgradeFromV393 },
    { 394, 395, H_UpgradeFromV394 },
+   { 395, 396, H_UpgradeFromV395 },
    { 0, 0, NULL }
 };
 
index 7d2135d..8ac3911 100644 (file)
@@ -92,6 +92,7 @@ public class ObjectAdapter implements IWorkbenchAdapter
                                return Activator.getImageDescriptor("icons/policy_group.png"); //$NON-NLS-1$
                        case AbstractObject.OBJECT_AGENTPOLICY:
                        case AbstractObject.OBJECT_AGENTPOLICY_CONFIG:
+                       case AbstractObject.OBJECT_AGENTPOLICY_LOGPARSER:
                                return Activator.getImageDescriptor("icons/policy.png"); //$NON-NLS-1$
                        case AbstractObject.OBJECT_NETWORKMAP:
                                return Activator.getImageDescriptor("icons/netmap.png"); //$NON-NLS-1$
index 7d8bd4e..02661dc 100644 (file)
              </instanceof>
           </enabledWhen>
         </page>
+        <page
+              class="org.netxms.ui.eclipse.policymanager.propertypages.ParserFile"
+              id="org.netxms.ui.eclipse.policymanager.propertypages.ParserFile"
+              name="Log Parser File">
+           <enabledWhen>
+              <instanceof
+                    value="org.netxms.client.objects.AgentPolicyLogParser">
+              </instanceof>
+           </enabledWhen>
+        </page>
   </extension>
 
    <extension
                label="%action.label.CreatePolicyGrp"
                menubarPath="objectcreation">
          </action>
+         <action
+               class="org.netxms.ui.eclipse.policymanager.actions.CreateAgentPolicyLogParser"
+               enablesFor="1"
+               id="org.netxms.ui.eclipse.policymanager.popupActions.CreateAgentPolicyLogParser_PolicyRoot"
+               label="Create log parser policy(xml file)..."
+               menubarPath="objectcreation">
+         </action>
       </objectContribution>
       <objectContribution
             adaptable="false"
                label="%action.label.CreatePolicyGrp"
                menubarPath="objectcreation">
          </action>
+         <action
+               class="org.netxms.ui.eclipse.policymanager.actions.CreateAgentPolicyLogParser"
+               enablesFor="1"
+               id="org.netxms.ui.eclipse.policymanager.popupActions.CreateAgentPolicyLogParser_PolicyGroup"
+               label="Create log parser policy(xml file)..."
+               menubarPath="objectcreation">
+         </action>
       </objectContribution>
       <objectContribution
             adaptable="false"
diff --git a/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/CreateAgentPolicyLogParser.java b/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/actions/CreateAgentPolicyLogParser.java
new file mode 100644 (file)
index 0000000..038978e
--- /dev/null
@@ -0,0 +1,96 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2011 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.
+ */
+package org.netxms.ui.eclipse.policymanager.actions;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.TreeSelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.ui.IObjectActionDelegate;
+import org.eclipse.ui.IWorkbenchPart;
+import org.netxms.client.NXCObjectCreationData;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AbstractObject;
+import org.netxms.client.objects.PolicyGroup;
+import org.netxms.client.objects.PolicyRoot;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.objectbrowser.dialogs.CreateObjectDialog;
+import org.netxms.ui.eclipse.policymanager.Activator;
+import org.netxms.ui.eclipse.policymanager.Messages;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+
+/**
+ * @author Victor
+ *
+ */
+public class CreateAgentPolicyLogParser implements IObjectActionDelegate
+{
+       private IWorkbenchPart targetPart;
+       private AbstractObject currentObject;
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
+        */
+       @Override
+       public void setActivePart(IAction action, IWorkbenchPart targetPart)
+       {
+               this.targetPart = targetPart;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
+        */
+       @Override
+       public void run(IAction action)
+       {
+               final CreateObjectDialog dlg = new CreateObjectDialog(targetPart.getSite().getShell(), Messages.get().CreateAgentPolicyConfig_AgentPolicy_Config);
+               if (dlg.open() == Window.OK)
+               {
+                       final NXCSession session = (NXCSession)ConsoleSharedData.getSession();
+                       new ConsoleJob(Messages.get().CreateAgentPolicyConfig_JobName, targetPart, Activator.PLUGIN_ID, null) {
+                               @Override
+                               protected void runInternal(IProgressMonitor monitor) throws Exception
+                               {
+                                       NXCObjectCreationData cd = new NXCObjectCreationData(AbstractObject.OBJECT_AGENTPOLICY_LOGPARSER, dlg.getObjectName(), currentObject.getObjectId());
+                                       session.createObject(cd);
+                               }
+
+                               @Override
+                               protected String getErrorMessage()
+                               {
+                                       return Messages.get().CreateAgentPolicyConfig_JobError;
+                               }
+                       }.start();
+               }
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
+        */
+       @Override
+       public void selectionChanged(IAction action, ISelection selection)
+       {
+               if (selection instanceof TreeSelection)
+               {
+                       currentObject = (AbstractObject)((TreeSelection)selection).getFirstElement();
+                       action.setEnabled((currentObject instanceof PolicyRoot) || (currentObject instanceof PolicyGroup));
+               }
+       }
+}
diff --git a/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java b/webui/webapp/PolicyManager/src/org/netxms/ui/eclipse/policymanager/propertypages/ParserFile.java
new file mode 100644 (file)
index 0000000..fb40927
--- /dev/null
@@ -0,0 +1,156 @@
+/**
+ * NetXMS - open source network management system
+ * Copyright (C) 2003-2010 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.
+ */
+package org.netxms.ui.eclipse.policymanager.propertypages;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.PropertyPage;
+import org.netxms.client.NXCObjectModificationData;
+import org.netxms.client.NXCSession;
+import org.netxms.client.objects.AgentPolicyLogParser;
+import org.netxms.ui.eclipse.jobs.ConsoleJob;
+import org.netxms.ui.eclipse.policymanager.Activator;
+import org.netxms.ui.eclipse.policymanager.Messages;
+import org.netxms.ui.eclipse.shared.ConsoleSharedData;
+import org.netxms.ui.eclipse.tools.WidgetHelper;
+
+/**
+ * Property page for agent configuration policy
+ *
+ */
+public class ParserFile extends PropertyPage
+{
+       private Text textContent;
+       private String initialContent;
+       private AgentPolicyLogParser object;
+       
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
+        */
+       @Override
+       protected Control createContents(Composite parent)
+       {
+               Composite dialogArea = new Composite(parent, SWT.NONE);
+               
+               object = (AgentPolicyLogParser)getElement().getAdapter(AgentPolicyLogParser.class);
+               if (object == null)     // Paranoid check
+                       return dialogArea;
+               
+               GridLayout layout = new GridLayout();
+               layout.verticalSpacing = WidgetHelper.OUTER_SPACING;
+               layout.marginWidth = 0;
+               layout.marginHeight = 0;
+               //FormLayout layout = new FormLayout();
+      dialogArea.setLayout(layout);
+      
+               // File content
+      Label label = new Label(dialogArea, SWT.NONE);
+      label.setText(Messages.get().ConfigFile_File);
+      
+      initialContent = new String(object.getFileContent());
+      GridData gd = new GridData();
+      gd.grabExcessHorizontalSpace = true;
+      gd.grabExcessVerticalSpace = true;
+      gd.horizontalAlignment = GridData.FILL;
+      gd.verticalAlignment = GridData.FILL;
+      gd.heightHint = 0;
+      textContent = new Text(dialogArea, SWT.MULTI | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
+      textContent.setText(object.getFileContent());
+      textContent.setLayoutData(gd);
+      
+               return dialogArea;
+       }
+       
+       
+       /**
+        * Apply changes
+        * 
+        * @param isApply true if update operation caused by "Apply" button
+        */
+       protected void applyChanges(final boolean isApply)
+       {
+               if (textContent.getText().equals(initialContent))
+                       return;         // Nothing to apply
+               
+               if (isApply)
+                       setValid(false);
+               
+               final String newContent = new String(textContent.getText());
+               new ConsoleJob(Messages.get().ConfigFile_JobName, null, Activator.PLUGIN_ID, null) {
+                       @Override
+                       protected void runInternal(IProgressMonitor monitor) throws Exception
+                       {
+                               if (object != null)
+                               {
+                                       NXCObjectModificationData md = new NXCObjectModificationData(object.getObjectId());
+                                       md.setConfigFileContent(newContent);
+                                       ((NXCSession)ConsoleSharedData.getSession()).modifyObject(md);
+                               }
+                               initialContent = newContent;
+                       }
+
+                       @Override
+                       protected void jobFinalize()
+                       {
+                               if (isApply)
+                               {
+                                  runInUIThread(new Runnable() {
+                  @Override
+                  public void run()
+                  {
+                     ParserFile.this.setValid(true);
+                  }
+               });
+                               }
+                       }
+
+                       @Override
+                       protected String getErrorMessage()
+                       {
+                               return Messages.get().ConfigFile_JobError;
+                       }
+               }.start();
+       }
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.preference.PreferencePage#performOk()
+        */
+       @Override
+       public boolean performOk()
+       {
+               applyChanges(false);
+               return true;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.preference.PreferencePage#performApply()
+        */
+       @Override
+       protected void performApply()
+       {
+               applyChanges(true);
+       }
+}