embeddable application agent - initial version
authorVictor Kirhenshtein <victor@netxms.org>
Tue, 27 Nov 2012 12:57:12 +0000 (12:57 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Tue, 27 Nov 2012 12:57:12 +0000 (12:57 +0000)
20 files changed:
.gitattributes
include/appagent.h [new file with mode: 0644]
include/nms_util.h
netxms.sln
src/agent/Makefile.am
src/agent/appagent/appagent-internal.h [new file with mode: 0644]
src/agent/appagent/appagent.cpp [new file with mode: 0644]
src/agent/appagent/appagent.vcproj [new file with mode: 0644]
src/agent/appagent/client.cpp [new file with mode: 0644]
src/agent/appagent/message.cpp [new file with mode: 0644]
src/agent/core/master.cpp
src/agent/core/nxagentd.cpp
src/agent/libnxsd/libnxsd.vcproj
src/agent/subagents/dbquery/dbquery.vcproj
src/agent/tools/Makefile.am
src/agent/tools/nxappget/nxappget.cpp [new file with mode: 0644]
src/agent/tools/nxappget/nxappget.vcproj [new file with mode: 0644]
src/agent/tools/nxapush/nxapush.cpp
src/libnetxms/log.cpp
src/libnetxms/tools.cpp

index 639fd37..23296fe 100644 (file)
@@ -288,6 +288,7 @@ sdk/openssl/lib/x86/ssleay32.lib -text
 sdk/samples/C/subagent/sample-subagent.vcproj -text
 sdk/samples/Java/get-dci-from-server/pom.xml -text
 sdk/samples/Java/get-dci-from-server/src/main/java/org/netxms/samples/Sample.java -text
+src/agent/appagent/appagent.vcproj -text
 src/agent/core/epp.cpp -text
 src/agent/core/nxagentd-unicode.vcproj -text
 src/agent/core/nxagentd.vcproj -text
@@ -317,6 +318,7 @@ src/agent/subagents/ups/ups.vcproj -text
 src/agent/subagents/winnt/winnt.vcproj -text
 src/agent/subagents/winperf/winperf.vcproj -text
 src/agent/subagents/wmi/wmi.vcproj -text
+src/agent/tools/nxappget/nxappget.vcproj -text
 src/agent/tools/nxapush/nxapush.vcproj -text
 src/client/install/nxcon.iss -text
 src/client/nxalarm/nxalarm.vcproj -text
diff --git a/include/appagent.h b/include/appagent.h
new file mode 100644 (file)
index 0000000..1f7235c
--- /dev/null
@@ -0,0 +1,148 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2012 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: appagent.h
+**
+**/
+
+#ifndef _appagent_h_
+#define _appagent_h_
+
+#ifdef _WIN32
+#ifdef APPAGENT_EXPORTS
+#define APPAGENT_EXPORTABLE __declspec(dllexport)
+#else
+#define APPAGENT_EXPORTABLE __declspec(dllimport)
+#endif
+#else    /* _WIN32 */
+#define APPAGENT_EXPORTABLE
+#endif
+
+#include <nms_common.h>
+#include <nms_util.h>
+
+#ifdef _WIN32
+#include <aclapi.h>
+#else
+#include <sys/socket.h>
+#include <sys/un.h>
+#endif
+
+#ifndef SUN_LEN
+#define SUN_LEN(su) (sizeof(*(su)) - sizeof((su)->sun_path) + strlen((su)->sun_path))
+#endif
+
+#ifdef _WIN32
+#define HPIPE HANDLE
+#define INVALID_PIPE_HANDLE INVALID_HANDLE_VALUE
+#else
+#define HPIPE int
+#define INVALID_PIPE_HANDLE (-1)
+#endif
+
+/**
+ * Message constants
+ */
+#define APPAGENT_MSG_START_INDICATOR     "APPAGENT"
+#define APPAGENT_MSG_START_INDICATOR_LEN 8
+#define APPAGENT_MSG_SIZE_FIELD_LEN      2
+#define APPAGENT_MSG_HEADER_LEN          16
+
+/**
+ * Command codes
+ */
+#define APPAGENT_CMD_GET_METRIC          0x0001
+#define APPAGENT_CMD_LIST_METRICS        0x0002
+#define APPAGENT_CMD_REQUEST_COMPLETED   0x0003
+
+/**
+ * Request completion codes
+ */
+#define APPAGENT_RCC_SUCCESS             0
+#define APPAGENT_RCC_NO_SUCH_METRIC      1
+#define APPAGENT_RCC_NO_SUCH_INSTANCE    2
+#define APPAGENT_RCC_METRIC_READ_ERROR   3
+#define APPAGENT_RCC_COMM_FAILURE        4
+#define APPAGENT_RCC_BAD_REQUEST         5
+
+/**
+ * Communication message structure
+ */
+
+#ifdef __HP_aCC
+#pragma pack 1
+#else
+#pragma pack(1)
+#endif
+
+typedef struct __apagent_msg
+{
+       char prefix[APPAGENT_MSG_START_INDICATOR_LEN];
+       WORD length;            // message length including prefix and length field
+       WORD command;           // command code
+       WORD rcc;                       // request completion code
+       BYTE padding[2];
+       BYTE payload[1];        // actual payload size determined by message length
+} APPAGENT_MSG;
+
+#ifdef __HP_aCC
+#pragma pack
+#else
+#pragma pack()
+#endif
+
+/**
+ * Application agent metric definition
+ */
+typedef struct __appagent_metric
+{
+       const TCHAR *name;
+       const TCHAR *userArg;
+       int (*handler)(const TCHAR *, const TCHAR *, TCHAR *);
+       int type;
+       const TCHAR *description;
+} APPAGENT_METRIC;
+
+/**
+ * Agent initialization structure
+ */
+typedef struct __appagent_init
+{
+       const TCHAR *name;
+       const TCHAR *userId;
+       void (*messageDispatcher)(APPAGENT_MSG *);
+       void (*logger)(int, const TCHAR *, va_list);
+       int numMetrics;
+       APPAGENT_METRIC *metrics;
+} APPAGENT_INIT;
+
+/**
+ * Application-side API
+ */
+bool APPAGENT_EXPORTABLE AppAgentInit(APPAGENT_INIT *initData);
+void APPAGENT_EXPORTABLE AppAgentStart();
+void APPAGENT_EXPORTABLE AppAgentStop();
+
+/**
+ * Client-side API
+ */
+bool APPAGENT_EXPORTABLE AppAgentConnect(const TCHAR *name, HPIPE *hPipe);
+void APPAGENT_EXPORTABLE AppAgentDisconnect(HPIPE hPipe);
+int APPAGENT_EXPORTABLE AppAgentGetMetric(HPIPE hPipe, const TCHAR *name, TCHAR *value, int bufferSize);
+
+#endif
index 9b968f6..d292bf9 100644 (file)
 #define CT_IGNORE       6
 #define CT_MB_STRING    7
 
-
-//
-// Return codes for NxLoadConfig()
-//
-
+/**
+ * Return codes for NxLoadConfig()
+ */
 #define NXCFG_ERR_OK       0
 #define NXCFG_ERR_NOFILE   1
 #define NXCFG_ERR_SYNTAX   2
 
-
-//
-// nxlog_open() flags
-//
-
+/**
+ * nxlog_open() flags
+ */
 #define NXLOG_USE_SYSLOG               ((DWORD)0x00000001)
 #define NXLOG_PRINT_TO_STDOUT  ((DWORD)0x00000002)
 #define NXLOG_IS_OPEN         ((DWORD)0x80000000)
 
-
-//
-// nxlog rotation policy
-//
-
+/**
+ * nxlog rotation policy
+ */
 #define NXLOG_ROTATION_DISABLED  0
 #define NXLOG_ROTATION_DAILY     1
 #define NXLOG_ROTATION_BY_SIZE   2
 
-
-//
-// _tcsdup() replacement
-//
-
+/**
+ * _tcsdup() replacement
+ */
 #if defined(_WIN32) && defined(USE_WIN32_HEAP)
 #ifdef __cplusplus
 extern "C" {
@@ -134,11 +126,9 @@ WCHAR LIBNETXMS_EXPORTABLE *nx_wcsdup(const WCHAR *src);
 #endif
 #endif
 
-
-//
-// Class for serial communications
-//
-
+/**
+ * Class for serial communications
+ */
 #ifdef __cplusplus
 
 #ifndef _WIN32
index 7e2570a..7f1aab3 100644 (file)
@@ -5,21 +5,21 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libexpat", "src\libexpat\li
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnetxms", "src\libnetxms\libnetxms.vcproj", "{B1745870-F3ED-4ACB-B813-0C4F47EF0793}"
        ProjectSection(ProjectDependencies) = postProject
-               {6A88EF62-C4F2-4295-A833-549DAE4DF5ED} = {6A88EF62-C4F2-4295-A833-549DAE4DF5ED}
                {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
+               {6A88EF62-C4F2-4295-A833-549DAE4DF5ED} = {6A88EF62-C4F2-4295-A833-549DAE4DF5ED}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxlp", "src\libnxlp\libnxlp.vcproj", "{64EFC0C2-C67B-41F6-851D-F11DAB27A60B}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
-               {6A88EF62-C4F2-4295-A833-549DAE4DF5ED} = {6A88EF62-C4F2-4295-A833-549DAE4DF5ED}
                {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
+               {6A88EF62-C4F2-4295-A833-549DAE4DF5ED} = {6A88EF62-C4F2-4295-A833-549DAE4DF5ED}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxagentd", "src\agent\core\nxagentd.vcproj", "{57598B02-3295-4FE8-9322-94CE871CC84D}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "subagents", "subagents", "{451F583D-C2DB-4414-870C-7FA0189BE7DD}"
@@ -59,8 +59,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sms", "src\agent\subagents\
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "portcheck", "src\agent\subagents\portcheck\portcheck.vcproj", "{F66A27F0-2943-4A16-ACC7-B450314B5163}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ping", "src\agent\subagents\ping\ping.vcproj", "{C5CCF5DE-152E-40F3-AC6C-C5E54BB7C45F}"
@@ -75,8 +75,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "odbcquery", "src\agent\suba
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "logwatch", "src\agent\subagents\logwatch\logwatch.vcproj", "{F8A8749E-E539-4A3B-A21C-2C5C86AE33EA}"
        ProjectSection(ProjectDependencies) = postProject
-               {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ecs", "src\agent\subagents\ecs\ecs.vcproj", "{BBE9028E-725C-45C6-97C9-BFC443F19DB6}"
@@ -93,113 +93,113 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxmap", "src\libnxmap\li
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxcl", "src\libnxcl\libnxcl.vcproj", "{3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{39BF23C9-D903-4C20-8E88-19533A745625}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxalarm", "src\client\nxalarm\nxalarm.vcproj", "{F9FFAAE9-D669-451E-B9EF-18BC8AD37FAB}"
        ProjectSection(ProjectDependencies) = postProject
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxevent", "src\client\nxevent\nxevent.vcproj", "{C7A460E8-12A8-4FC7-9F59-C9C5CE17ED20}"
        ProjectSection(ProjectDependencies) = postProject
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxpush", "src\client\nxpush\nxpush.vcproj", "{B8671BF7-94E1-4615-A8C2-F5C78DB8C515}"
        ProjectSection(ProjectDependencies) = postProject
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsms", "src\client\nxsms\nxsms.vcproj", "{B0A70A32-A8F0-4071-8044-FDA3C834A5C5}"
        ProjectSection(ProjectDependencies) = postProject
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsnmp", "src\snmp\libnxsnmp\libnxsnmp.vcproj", "{7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {E7410EB4-3355-4C83-8E05-D2877581CDA1} = {E7410EB4-3355-4C83-8E05-D2877581CDA1}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxzlib", "src\zlib\nxzlib.vcproj", "{E7410EB4-3355-4C83-8E05-D2877581CDA1}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsnmpget", "src\snmp\nxsnmpget\nxsnmpget.vcproj", "{0A4CE471-020A-42C6-91C0-DFEFA7E815E0}"
        ProjectSection(ProjectDependencies) = postProject
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsnmpset", "src\snmp\nxsnmpset\nxsnmpset.vcproj", "{9EA98E79-EB7D-4F6C-8105-AC7B231ABB10}"
        ProjectSection(ProjectDependencies) = postProject
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsnmpwalk", "src\snmp\nxsnmpwalk\nxsnmpwalk.vcproj", "{5FA3AADC-3AD7-4B17-A581-D5E02DE17727}"
        ProjectSection(ProjectDependencies) = postProject
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxmibc", "src\snmp\nxmibc\nxmibc.vcproj", "{9F722C62-78FD-4D8C-A7C7-2815B09F1943}"
        ProjectSection(ProjectDependencies) = postProject
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsrv", "src\server\libnxsrv\libnxsrv.vcproj", "{CB89D905-C8BE-4027-B2D8-F96C245E9160}"
        ProjectSection(ProjectDependencies) = postProject
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxcore", "src\server\core\nxcore.vcproj", "{3B172035-5EEC-45A3-8471-2C390B7ED683}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
-               {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
-               {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
-               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
                {B2988503-1921-4B9F-BBC1-5E5CF62F335E} = {B2988503-1921-4B9F-BBC1-5E5CF62F335E}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
+               {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "nxsl", "nxsl", "{CE0DA89E-CF0C-452C-9C33-75A143355BDC}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsl", "src\libnxsl\libnxsl.vcproj", "{B2988503-1921-4B9F-BBC1-5E5CF62F335E}"
        ProjectSection(ProjectDependencies) = postProject
-               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {406AE5C7-343D-4C88-B8F3-84E46255B830} = {406AE5C7-343D-4C88-B8F3-84E46255B830}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxscript", "src\nxscript\nxscript.vcproj", "{BA263F92-D5A9-4F26-9606-5A1C1495FEA5}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {B2988503-1921-4B9F-BBC1-5E5CF62F335E} = {B2988503-1921-4B9F-BBC1-5E5CF62F335E}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "netxmsd", "src\server\netxmsd\netxmsd.vcproj", "{E417A0C4-41F1-4F87-8C33-8526ECB1F8AF}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {3B172035-5EEC-45A3-8471-2C390B7ED683} = {3B172035-5EEC-45A3-8471-2C390B7ED683}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{64482674-7B36-4A14-A612-247333174315}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxaction", "src\server\tools\nxaction\nxaction.vcproj", "{BF5CE6BA-C84A-4448-B1B7-1B355AC77D12}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxadm", "src\server\tools\nxadm\nxadm.vcproj", "{67E35735-2115-45FF-9E93-EE67AF5C9C2C}"
@@ -209,82 +209,82 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxadm", "src\server\tools\n
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxget", "src\server\tools\nxget\nxget.vcproj", "{1AC3C8D1-E309-4327-9E17-0E4CE0FC68CF}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxupload", "src\server\tools\nxupload\nxupload.vcproj", "{DA863269-ED58-4910-AA6A-2572A3EE745D}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxdbmgr", "src\server\tools\nxdbmgr\nxdbmgr.vcproj", "{4940613E-A11C-4259-95C8-8D23217EE60E}"
        ProjectSection(ProjectDependencies) = postProject
-               {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
-               {87CAA25D-991E-45E1-BB69-337D45121F19} = {87CAA25D-991E-45E1-BB69-337D45121F19}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {87CAA25D-991E-45E1-BB69-337D45121F19} = {87CAA25D-991E-45E1-BB69-337D45121F19}
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "smsdrv", "smsdrv", "{5818CCA9-B585-44B8-B29E-98B1DC278A3C}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "generic", "src\server\smsdrv\generic\generic.vcproj", "{41A5009F-4467-4D89-A171-5A919FEFE16E}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxagent", "src\server\smsdrv\nxagent\nxagent.vcproj", "{C317231C-B984-4423-ACF2-C19DE8B6AA3F}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "windows", "windows", "{69EC5B74-D466-422E-B8D1-1386B0421D54}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxlexer", "src\client\nxlexer\nxlexer.vcproj", "{F0FAC738-1BC6-46A5-A54A-8D7F2219302D}"
        ProjectSection(ProjectDependencies) = postProject
-               {8E5A517B-93AB-4EA8-BB53-AE6346756343} = {8E5A517B-93AB-4EA8-BB53-AE6346756343}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {8E5A517B-93AB-4EA8-BB53-AE6346756343} = {8E5A517B-93AB-4EA8-BB53-AE6346756343}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "scilexer", "src\client\scilexer\scilexer.vcproj", "{8E5A517B-93AB-4EA8-BB53-AE6346756343}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxuilib", "src\client\windows\nxuilib\nxuilib.vcproj", "{BECC966D-AFC8-48F6-97B1-2FE92062D7B4}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxav", "src\client\windows\nxav\nxav.vcproj", "{23F22F68-D562-4E80-8267-9F1DD9398357}"
        ProjectSection(ProjectDependencies) = postProject
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxnotify", "src\client\windows\nxnotify\nxnotify.vcproj", "{169A4446-A035-4CF7-8377-3C517ADF0C50}"
        ProjectSection(ProjectDependencies) = postProject
-               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxcon", "src\client\windows\nxcon\nxcon.vcproj", "{956DD617-0939-4B25-B8D0-E10AA645064E}"
        ProjectSection(ProjectDependencies) = postProject
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
-               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
-               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
                {AB386821-B630-49F5-95C3-677B9DCE1270} = {AB386821-B630-49F5-95C3-677B9DCE1270}
+               {BECC966D-AFC8-48F6-97B1-2FE92062D7B4} = {BECC966D-AFC8-48F6-97B1-2FE92062D7B4}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531} = {3CB9B8C6-E6BF-4002-A61A-7A21FEADB531}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxlptest", "src\nxlptest\nxlptest.vcproj", "{1EA79FC6-F395-43DF-9E3C-2030CA05ED1D}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {64EFC0C2-C67B-41F6-851D-F11DAB27A60B} = {64EFC0C2-C67B-41F6-851D-F11DAB27A60B}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxsqlite", "src\sqlite\nxsqlite.vcproj", "{87CAA25D-991E-45E1-BB69-337D45121F19}"
@@ -335,14 +335,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pgsql", "src\db\dbdrv\pgsql
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sqlite", "src\db\dbdrv\sqlite\sqlite.vcproj", "{AA18FD4D-7B01-4932-BA04-B0F54F001F66}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {87CAA25D-991E-45E1-BB69-337D45121F19} = {87CAA25D-991E-45E1-BB69-337D45121F19}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxconfig", "src\server\tools\nxconfig\nxconfig.vcproj", "{A76CCCF5-D70B-4307-B84C-219289CEAA6D}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "flow analyzer", "flow analyzer", "{89B3A66E-5853-4B14-A5E3-9E4C6524BE65}"
@@ -354,9 +354,9 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libipfix", "src\flow_analyz
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxflowd", "src\flow_analyzer\nxflowd\nxflowd.vcproj", "{D7F709ED-7483-49F0-8B17-ABB705606FEA}"
        ProjectSection(ProjectDependencies) = postProject
-               {2DEF303B-5FEF-4F5E-87C4-FB7895058F59} = {2DEF303B-5FEF-4F5E-87C4-FB7895058F59}
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {2DEF303B-5FEF-4F5E-87C4-FB7895058F59} = {2DEF303B-5FEF-4F5E-87C4-FB7895058F59}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db2", "src\db\dbdrv\db2\db2.vcproj", "{297D9A45-B928-4470-91B5-0E07A20C2405}"
@@ -366,8 +366,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db2", "src\db\dbdrv\db2\db2
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxap", "src\server\tools\nxap\nxap.vcproj", "{36749C31-C8C6-4DD2-A11C-E41ED86927C7}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libtre", "src\libtre\libtre.vcproj", "{406AE5C7-343D-4C88-B8F3-84E46255B830}"
@@ -376,50 +376,50 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "drivers", "drivers", "{5399
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "baystack", "src\server\drivers\baystack\baystack.vcproj", "{13A91F2E-A17B-4ABA-B5B2-285807BD7832}"
        ProjectSection(ProjectDependencies) = postProject
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
-               {DA651576-4E4F-448C-A0A3-9EDD15C81078} = {DA651576-4E4F-448C-A0A3-9EDD15C81078}
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {DA651576-4E4F-448C-A0A3-9EDD15C81078} = {DA651576-4E4F-448C-A0A3-9EDD15C81078}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ers8000", "src\server\drivers\ers8000\ers8000.vcproj", "{076E6815-4B6B-4F1E-A36C-CD3DD26EA5AC}"
        ProjectSection(ProjectDependencies) = postProject
-               {DA651576-4E4F-448C-A0A3-9EDD15C81078} = {DA651576-4E4F-448C-A0A3-9EDD15C81078}
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {DA651576-4E4F-448C-A0A3-9EDD15C81078} = {DA651576-4E4F-448C-A0A3-9EDD15C81078}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lib", "lib", "{D73BB67D-032B-4FB7-AEB8-5795B246A072}"
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "avaya-ers", "src\server\drivers\lib\avaya-ers\avaya-ers.vcproj", "{DA651576-4E4F-448C-A0A3-9EDD15C81078}"
        ProjectSection(ProjectDependencies) = postProject
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
                {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cisco", "src\server\drivers\lib\cisco\cisco.vcproj", "{375F95BD-EFBA-4AA3-8DA3-E79779A12896}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cat2900xl", "src\server\drivers\cat2900xl\cat2900xl.vcproj", "{FEEF505B-75AE-4E52-8177-51FFC4AB2ED2}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
                {375F95BD-EFBA-4AA3-8DA3-E79779A12896} = {375F95BD-EFBA-4AA3-8DA3-E79779A12896}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "portech", "src\server\smsdrv\portech\portech.vcproj", "{7D0A15A1-7F6E-480D-9926-13BB6DAA0E10}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "netscreen", "src\server\drivers\netscreen\netscreen.vcproj", "{500DE9BF-6FC1-4ACB-91A9-308BA1D37F37}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "informix", "src\db\dbdrv\informix\informix.vcproj", "{7DE4A043-48B8-4D66-8D3F-8CF5C757EEB5}"
@@ -429,34 +429,34 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "informix", "src\db\dbdrv\in
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "informix", "src\agent\subagents\informix\informix.vcproj", "{12F5AF3E-A688-4852-A0ED-921D0E088AC4}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dbemu", "src\server\smsdrv\dbemu\dbemu.vcproj", "{912783D2-CF6F-4040-B564-4E2436EB0827}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
-               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxinstall", "src\nxinstall\nxinstall.vcproj", "{C177FB94-66E8-424E-BDBE-A96C75D2672C}"
        ProjectSection(ProjectDependencies) = postProject
-               {B2988503-1921-4B9F-BBC1-5E5CF62F335E} = {B2988503-1921-4B9F-BBC1-5E5CF62F335E}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {B2988503-1921-4B9F-BBC1-5E5CF62F335E} = {B2988503-1921-4B9F-BBC1-5E5CF62F335E}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "catalyst", "src\server\drivers\catalyst\catalyst.vcproj", "{F343CDCB-1DB5-4563-86DF-6AF1596090B2}"
        ProjectSection(ProjectDependencies) = postProject
-               {375F95BD-EFBA-4AA3-8DA3-E79779A12896} = {375F95BD-EFBA-4AA3-8DA3-E79779A12896}
-               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
                {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
+               {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB} = {7DC90EE4-E31C-4F12-8F1E-81F10E9099FB}
+               {375F95BD-EFBA-4AA3-8DA3-E79779A12896} = {375F95BD-EFBA-4AA3-8DA3-E79779A12896}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "oracle", "src\agent\subagents\oracle\oracle.vcproj", "{90B762AB-B7BA-42D6-9819-C687AB3F59D0}"
        ProjectSection(ProjectDependencies) = postProject
-               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{896A7CDA-423A-460A-83E2-6ED37DAE187C}"
@@ -468,14 +468,14 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxapush", "src\agent\tools\
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "procurve", "src\server\drivers\procurve\procurve.vcproj", "{B51F1406-AF43-4396-96C0-31176DDAA3FB}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dell-pwc", "src\server\drivers\dell-pwc\dell-pwc.vcproj", "{4CD8D04D-375D-40B5-AB1C-C8AC8A38FB45}"
        ProjectSection(ProjectDependencies) = postProject
-               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+               {CB89D905-C8BE-4027-B2D8-F96C245E9160} = {CB89D905-C8BE-4027-B2D8-F96C245E9160}
        EndProjectSection
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "cisco-esw", "src\server\drivers\cisco-esw\cisco-esw.vcproj", "{15B67A25-48BB-4A05-8FF5-9FE747F6D3EB}"
@@ -487,7 +487,18 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libnxsd", "src\agent\libnxs
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "dbquery", "src\agent\subagents\dbquery\dbquery.vcproj", "{784D1668-124C-46D9-B985-51276FFA282A}"
        ProjectSection(ProjectDependencies) = postProject
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
                {F3E29541-3A0E-45EC-8BEC-E193F2401622} = {F3E29541-3A0E-45EC-8BEC-E193F2401622}
+       EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "appagent", "src\agent\appagent\appagent.vcproj", "{6B249E47-4BAF-4DE2-B62B-C6DD0330753F}"
+       ProjectSection(ProjectDependencies) = postProject
+               {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
+       EndProjectSection
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nxappget", "src\agent\tools\nxappget\nxappget.vcproj", "{21D35413-495C-4DD2-BDBF-7BD708C70B74}"
+       ProjectSection(ProjectDependencies) = postProject
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F} = {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}
                {B1745870-F3ED-4ACB-B813-0C4F47EF0793} = {B1745870-F3ED-4ACB-B813-0C4F47EF0793}
        EndProjectSection
 EndProject
@@ -1125,16 +1136,36 @@ Global
                {15B67A25-48BB-4A05-8FF5-9FE747F6D3EB}.Release|x64.Build.0 = Release|x64
                {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Debug|Win32.ActiveCfg = Debug|Win32
                {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Debug|Win32.Build.0 = Debug|Win32
-               {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Debug|x64.ActiveCfg = Debug|Win32
+               {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Debug|x64.ActiveCfg = Debug|x64
+               {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Debug|x64.Build.0 = Debug|x64
                {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Release|Win32.ActiveCfg = Release|Win32
                {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Release|Win32.Build.0 = Release|Win32
-               {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Release|x64.ActiveCfg = Release|Win32
+               {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Release|x64.ActiveCfg = Release|x64
+               {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A}.Release|x64.Build.0 = Release|x64
                {784D1668-124C-46D9-B985-51276FFA282A}.Debug|Win32.ActiveCfg = Debug|Win32
                {784D1668-124C-46D9-B985-51276FFA282A}.Debug|Win32.Build.0 = Debug|Win32
-               {784D1668-124C-46D9-B985-51276FFA282A}.Debug|x64.ActiveCfg = Debug|Win32
+               {784D1668-124C-46D9-B985-51276FFA282A}.Debug|x64.ActiveCfg = Debug|x64
+               {784D1668-124C-46D9-B985-51276FFA282A}.Debug|x64.Build.0 = Debug|x64
                {784D1668-124C-46D9-B985-51276FFA282A}.Release|Win32.ActiveCfg = Release|Win32
                {784D1668-124C-46D9-B985-51276FFA282A}.Release|Win32.Build.0 = Release|Win32
-               {784D1668-124C-46D9-B985-51276FFA282A}.Release|x64.ActiveCfg = Release|Win32
+               {784D1668-124C-46D9-B985-51276FFA282A}.Release|x64.ActiveCfg = Release|x64
+               {784D1668-124C-46D9-B985-51276FFA282A}.Release|x64.Build.0 = Release|x64
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}.Debug|Win32.ActiveCfg = Debug|Win32
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}.Debug|Win32.Build.0 = Debug|Win32
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}.Debug|x64.ActiveCfg = Debug|x64
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}.Debug|x64.Build.0 = Debug|x64
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}.Release|Win32.ActiveCfg = Release|Win32
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}.Release|Win32.Build.0 = Release|Win32
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}.Release|x64.ActiveCfg = Release|x64
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F}.Release|x64.Build.0 = Release|x64
+               {21D35413-495C-4DD2-BDBF-7BD708C70B74}.Debug|Win32.ActiveCfg = Debug|Win32
+               {21D35413-495C-4DD2-BDBF-7BD708C70B74}.Debug|Win32.Build.0 = Debug|Win32
+               {21D35413-495C-4DD2-BDBF-7BD708C70B74}.Debug|x64.ActiveCfg = Debug|x64
+               {21D35413-495C-4DD2-BDBF-7BD708C70B74}.Debug|x64.Build.0 = Debug|x64
+               {21D35413-495C-4DD2-BDBF-7BD708C70B74}.Release|Win32.ActiveCfg = Release|Win32
+               {21D35413-495C-4DD2-BDBF-7BD708C70B74}.Release|Win32.Build.0 = Release|Win32
+               {21D35413-495C-4DD2-BDBF-7BD708C70B74}.Release|x64.ActiveCfg = Release|x64
+               {21D35413-495C-4DD2-BDBF-7BD708C70B74}.Release|x64.Build.0 = Release|x64
        EndGlobalSection
        GlobalSection(SolutionProperties) = preSolution
                HideSolutionNode = FALSE
@@ -1153,6 +1184,7 @@ Global
                {57598B02-3295-4FE8-9322-94CE871CC84D} = {8BC9D64D-347C-41BE-A506-D21C8FB72D56}
                {896A7CDA-423A-460A-83E2-6ED37DAE187C} = {8BC9D64D-347C-41BE-A506-D21C8FB72D56}
                {DFE2F1AF-D5E5-49DD-B2AD-4F4FB8651D8A} = {8BC9D64D-347C-41BE-A506-D21C8FB72D56}
+               {6B249E47-4BAF-4DE2-B62B-C6DD0330753F} = {8BC9D64D-347C-41BE-A506-D21C8FB72D56}
                {E95263B5-A248-4163-95F3-E33CA679AEB3} = {451F583D-C2DB-4414-870C-7FA0189BE7DD}
                {EE54BC06-6B0F-4B91-9FC6-A5BB9ECBE577} = {451F583D-C2DB-4414-870C-7FA0189BE7DD}
                {4E190DD5-70DA-41EC-8D05-5EE8D74F3709} = {451F583D-C2DB-4414-870C-7FA0189BE7DD}
@@ -1229,5 +1261,6 @@ Global
                {DA651576-4E4F-448C-A0A3-9EDD15C81078} = {D73BB67D-032B-4FB7-AEB8-5795B246A072}
                {375F95BD-EFBA-4AA3-8DA3-E79779A12896} = {D73BB67D-032B-4FB7-AEB8-5795B246A072}
                {68B9F17F-A292-4DAB-8EA9-B87473BB0436} = {896A7CDA-423A-460A-83E2-6ED37DAE187C}
+               {21D35413-495C-4DD2-BDBF-7BD708C70B74} = {896A7CDA-423A-460A-83E2-6ED37DAE187C}
        EndGlobalSection
 EndGlobal
index 8f32b86..f2010c4 100644 (file)
@@ -8,4 +8,4 @@
 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
-SUBDIRS = libnxsd subagents core install tools
+SUBDIRS = appagent libnxsd subagents core install tools
diff --git a/src/agent/appagent/appagent-internal.h b/src/agent/appagent/appagent-internal.h
new file mode 100644 (file)
index 0000000..8d1be29
--- /dev/null
@@ -0,0 +1,52 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2012 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: appagent-internal.h
+**
+**/
+
+#ifndef _appagent_internal_h_
+#define _appagent_internal_h_
+
+#include <appagent.h>
+
+/**
+ * Message buffer
+ */
+class MessageBuffer
+{
+public:
+       static const int DATA_SIZE = 65536;
+
+       char m_data[DATA_SIZE];
+       int m_pos;
+
+       MessageBuffer() { m_pos = 0; }
+
+       int seek();
+       void shrink(int pos);
+};
+
+/**
+ * Internal functions
+ */
+APPAGENT_MSG *ReadMessageFromPipe(HPIPE hPipe, HANDLE hEvent, MessageBuffer *mb);
+bool SendMessageToPipe(HPIPE hPipe, APPAGENT_MSG *msg);
+APPAGENT_MSG *NewMessage(int command, int rcc, int length);
+
+#endif
diff --git a/src/agent/appagent/appagent.cpp b/src/agent/appagent/appagent.cpp
new file mode 100644 (file)
index 0000000..c5daf46
--- /dev/null
@@ -0,0 +1,349 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2012 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: appagent.cpp
+**
+**/
+
+#include "appagent-internal.h"
+
+/**
+ * Application agent config
+ */
+static APPAGENT_INIT s_config;
+static bool s_stop = false;
+static bool s_initialized = false;
+static HPIPE s_pipe = INVALID_PIPE_HANDLE;
+static THREAD s_connectorThread = INVALID_THREAD_HANDLE;
+
+/**
+ * Write log
+ */
+static void AppAgentWriteLog(int level, const TCHAR *format, ...)
+{
+       if (s_config.logger == NULL)
+               return;
+
+       va_list(args);
+       va_start(args, format);
+       s_config.logger(level, format, args);
+       va_end(args);
+}
+
+/**
+ * Get metric
+ */
+static APPAGENT_MSG *GetMetric(WCHAR *name, int length)
+{
+       TCHAR metricName[256];
+
+#ifdef UNICODE
+       nx_strncpy(metricName, name, min(length, 256));
+#else
+       WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, name, length, metricName, 256, NULL, NULL);
+       metricName[min(length, 255)] = 0;
+#endif
+
+       for(int i = 0; i < s_config.numMetrics; i++)
+       {
+               if (MatchString(s_config.metrics[i].name, metricName, FALSE))
+               {
+                       TCHAR value[256];
+                       int rcc = s_config.metrics[i].handler(metricName, s_config.metrics[i].userArg, value);
+
+                       APPAGENT_MSG *msg;
+                       if (rcc == APPAGENT_RCC_SUCCESS)
+                       {
+                               int len = (int)_tcslen(value) + 1;
+                               msg = NewMessage(APPAGENT_CMD_REQUEST_COMPLETED, rcc, len * sizeof(WCHAR));
+#ifdef UNICODE
+                               wcscpy((WCHAR *)msg->payload, value);
+#else
+                               MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, value, -1, (WCHAR *)msg->payload, len);
+#endif
+                       }
+                       else
+                       {
+                               msg = NewMessage(APPAGENT_CMD_REQUEST_COMPLETED, rcc, 0);
+                       }
+                       return msg;
+               }
+       }
+       return NewMessage(APPAGENT_CMD_REQUEST_COMPLETED, APPAGENT_RCC_NO_SUCH_METRIC, 0);
+}
+
+/**
+ * Process incoming request
+ */
+static void ProcessRequest(HPIPE hPipe)
+{
+       MessageBuffer *mb = new MessageBuffer;
+
+       AppAgentWriteLog(5, _T("ProcessRequest: connection established"));
+       while(true)
+       {
+               APPAGENT_MSG *msg = ReadMessageFromPipe(hPipe, NULL, mb);
+               if (msg == NULL)
+                       break;
+               AppAgentWriteLog(6, _T("ProcessRequest: received message %04X"), (unsigned int)msg->command);
+               APPAGENT_MSG *response;
+               switch(msg->command)
+               {
+                       case APPAGENT_CMD_GET_METRIC:
+                               response = GetMetric((WCHAR *)msg->payload, msg->length - APPAGENT_MSG_HEADER_LEN);
+                               break;
+                       default:
+                               response = NewMessage(APPAGENT_CMD_REQUEST_COMPLETED, APPAGENT_RCC_BAD_REQUEST, 0);
+                               break;
+               }
+               free(msg);
+               SendMessageToPipe(hPipe, response);
+               free(response);
+       }
+       AppAgentWriteLog(5, _T("ProcessRequest: connection closed"));
+       delete mb;
+}
+
+/**
+ * Connector thread for external push command
+ */
+#ifdef _WIN32
+
+static THREAD_RESULT THREAD_CALL AppAgentConnector(void *arg)
+{
+       SECURITY_ATTRIBUTES sa;
+       PSECURITY_DESCRIPTOR sd = NULL;
+       SID_IDENTIFIER_AUTHORITY sidAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
+       EXPLICIT_ACCESS ea;
+       PSID sidEveryone = NULL;
+       ACL *acl = NULL;
+       TCHAR errorText[1024];
+
+       // Create a well-known SID for the Everyone group.
+       if(!AllocateAndInitializeSid(&sidAuthWorld, 1, SECURITY_WORLD_RID, 0, 0, 0, 0, 0, 0, 0, &sidEveryone))
+       {
+               AppAgentWriteLog(2, _T("AppAgentConnector: AllocateAndInitializeSid failed (%s)"), GetSystemErrorText(GetLastError(), errorText, 1024));
+               goto cleanup;
+       }
+
+       // Initialize an EXPLICIT_ACCESS structure for an ACE.
+       // The ACE will allow either Everyone or given user to access pipe
+       ZeroMemory(&ea, sizeof(EXPLICIT_ACCESS));
+       ea.grfAccessPermissions = (FILE_GENERIC_READ | FILE_GENERIC_WRITE) & ~FILE_CREATE_PIPE_INSTANCE;
+       ea.grfAccessMode = SET_ACCESS;
+       ea.grfInheritance = NO_INHERITANCE;
+       if ((s_config.userId == NULL) || (s_config.userId[0] == 0) || !_tcscmp(s_config.userId, _T("*")))
+       {
+               ea.Trustee.TrusteeForm = TRUSTEE_IS_SID;
+               ea.Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
+               ea.Trustee.ptstrName  = (LPTSTR)sidEveryone;
+       }
+       else
+       {
+               ea.Trustee.TrusteeForm = TRUSTEE_IS_NAME;
+               ea.Trustee.TrusteeType = TRUSTEE_IS_USER;
+               ea.Trustee.ptstrName  = (LPTSTR)s_config.userId;
+               AppAgentWriteLog(2, _T("AppAgentConnector: will allow connections only for user %s"), s_config.userId);
+       }
+
+       // Create a new ACL that contains the new ACEs.
+       if (SetEntriesInAcl(1, &ea, NULL, &acl) != ERROR_SUCCESS)
+       {
+               AppAgentWriteLog(2, _T("AppAgentConnector: SetEntriesInAcl failed (%s)"), GetSystemErrorText(GetLastError(), errorText, 1024));
+               goto cleanup;
+       }
+
+       sd = (PSECURITY_DESCRIPTOR)LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
+       if (sd == NULL)
+       {
+               AppAgentWriteLog(2, _T("AppAgentConnector: LocalAlloc failed (%s)"), GetSystemErrorText(GetLastError(), errorText, 1024));
+               goto cleanup;
+       }
+
+       if (!InitializeSecurityDescriptor(sd, SECURITY_DESCRIPTOR_REVISION))
+       {
+               AppAgentWriteLog(2, _T("AppAgentConnector: InitializeSecurityDescriptor failed (%s)"), GetSystemErrorText(GetLastError(), errorText, 1024));
+               goto cleanup;
+       }
+
+       // Add the ACL to the security descriptor. 
+   if (!SetSecurityDescriptorDacl(sd, TRUE, acl, FALSE))
+       {
+               AppAgentWriteLog(2, _T("AppAgentConnector: SetSecurityDescriptorDacl failed (%s)"), GetSystemErrorText(GetLastError(), errorText, 1024));
+               goto cleanup;
+       }
+
+       TCHAR pipeName[MAX_PATH];
+       _sntprintf(pipeName, MAX_PATH, _T("\\\\.\\pipe\\appagent.%s"), s_config.name);
+       sa.nLength = sizeof(SECURITY_ATTRIBUTES);
+       sa.bInheritHandle = FALSE;
+       sa.lpSecurityDescriptor = sd;
+       s_pipe = CreateNamedPipe(pipeName, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE, 1, 8192, 8192, 0, &sa);
+       if (s_pipe == INVALID_HANDLE_VALUE)
+       {
+               AppAgentWriteLog(2, _T("AppAgentConnector: CreateNamedPipe failed (%s)"), GetSystemErrorText(GetLastError(), errorText, 1024));
+               goto cleanup;
+       }
+
+       AppAgentWriteLog(2, _T("AppAgentConnector: named pipe created, waiting for connection"));
+       int connectErrors = 0;
+       while(!s_stop)
+       {
+               BOOL connected = ConnectNamedPipe(s_pipe, NULL);
+               if (connected || (GetLastError() == ERROR_PIPE_CONNECTED))
+               {
+                       ProcessRequest(s_pipe);
+                       DisconnectNamedPipe(s_pipe);
+                       connectErrors = 0;
+               }
+               else
+               {
+                       AppAgentWriteLog(2, _T("AppAgentConnector: ConnectNamedPipe failed (%s)"), GetSystemErrorText(GetLastError(), errorText, 1024));
+                       connectErrors++;
+                       if (connectErrors > 10)
+                               break;  // Stop this connector if ConnectNamedPipe fails instantly
+               }
+       }
+
+cleanup:
+       if (s_pipe != NULL)
+       {
+               CloseHandle(s_pipe);
+               s_pipe = INVALID_PIPE_HANDLE;
+       }
+
+       if (sd != NULL)
+               LocalFree(sd);
+
+       if (acl != NULL)
+               LocalFree(acl);
+
+       if (sidEveryone != NULL)
+               FreeSid(sidEveryone);
+
+       AppAgentWriteLog(2, _T("AppAgentConnector: listener thread stopped"));
+       return THREAD_OK;
+}
+
+#else
+
+static THREAD_RESULT THREAD_CALL AppAgentConnector(void *arg)
+{
+       mode_t prevMask = 0;
+
+       s_pipe = socket(AF_UNIX, SOCK_STREAM, 0);
+       if (s_pipe == -1)
+       {
+               AppAgentWriteLog(2, _T("AppAgentConnector: socket failed (%s)"), _tcserror(errno));
+               goto cleanup;
+       }
+       
+       struct sockaddr_un addrLocal;
+       addrLocal.sun_family = AF_UNIX;
+       sprintf(addrLocal.sun_path, "/tmp/.appagent.%s", s_config.name);        
+       unlink(addrLocal.sun_path);
+       prevMask = umask(S_IWGRP | S_IWOTH);
+       if (bind(s_pipe, (struct sockaddr *)&addrLocal, SUN_LEN(&addrLocal)) == -1)
+       {
+               AppAgentWriteLog(2, _T("AppAgentConnector: bind failed (%s)"), _tcserror(errno));
+               umask(prevMask);
+               goto cleanup;
+       }
+       umask(prevMask);
+
+       if (listen(s_pipe, 5) == -1)
+       {
+               AppAgentWriteLog(2, _T("AppAgentConnector: listen failed (%s)"), _tcserror(errno));
+               goto cleanup;
+       }
+       
+       while(!s_stop)
+       {
+               struct sockaddr_un addrRemote;
+               socklen_t size = sizeof(struct sockaddr_un);
+               SOCKET cs = accept(s_pipe, (struct sockaddr *)&addrRemote, &size);
+               if (cs > 0)
+               {
+                       ProcessRequest(cs);
+                       shutdown(cs, 2);
+                       close(cs);
+               }
+               else
+               {
+                       AppAgentWriteLog(2, _T("AppAgentConnector: accept failed (%s)"), _tcserror(errno));
+               }
+       }
+
+cleanup:
+       if (s_pipe != -1)
+       {
+               close(s_pipe);
+               s_pipe = INVALID_PIPE_HANDLE;
+       }
+
+       AppAgentWriteLog(2, _T("AppAgentConnector: listener thread stopped"));
+       return THREAD_OK;
+}
+
+#endif
+
+/**
+ * Initialize application agent
+ */
+bool APPAGENT_EXPORTABLE AppAgentInit(APPAGENT_INIT *initData)
+{
+       if (s_initialized)
+               return false;   // already initialized
+
+       memcpy(&s_config, initData, sizeof(APPAGENT_INIT));
+       if ((s_config.name == NULL) || (s_config.name[0] == 0))
+               return false;
+       s_initialized = true;
+       return true;
+}
+
+/**
+ * Start application agent
+ */
+void APPAGENT_EXPORTABLE AppAgentStart()
+{
+       if ((s_initialized) && (s_connectorThread == INVALID_THREAD_HANDLE))
+               s_connectorThread = ThreadCreateEx(AppAgentConnector, 0, NULL);
+}
+
+/**
+ * Stop application agent
+ */
+void APPAGENT_EXPORTABLE AppAgentStop()
+{
+       if (s_initialized && (s_connectorThread != INVALID_THREAD_HANDLE))
+       {
+               s_stop = true;
+               if (s_pipe != INVALID_THREAD_HANDLE)
+               {
+#ifdef _WIN32
+                       CloseHandle(s_pipe);
+#else
+                       shutdown(s_pipe, SHUT_RDWR);
+#endif
+                       s_pipe = INVALID_PIPE_HANDLE;
+               }
+               ThreadJoin(s_connectorThread);
+               s_connectorThread = INVALID_THREAD_HANDLE;
+       }
+}
diff --git a/src/agent/appagent/appagent.vcproj b/src/agent/appagent/appagent.vcproj
new file mode 100644 (file)
index 0000000..901268c
--- /dev/null
@@ -0,0 +1,372 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       Name="appagent"\r
+       ProjectGUID="{6B249E47-4BAF-4DE2-B62B-C6DD0330753F}"\r
+       RootNamespace="appagent"\r
+       Keyword="Win32Proj"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+               <Platform\r
+                       Name="x64"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;APPAGENT_EXPORTS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalIncludeDirectories="..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;APPAGENT_EXPORTS"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Debug|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;APPAGENT_EXPORTS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalIncludeDirectories="..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;APPAGENT_EXPORTS"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\appagent.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\client.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath=".\message.cpp"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\appagent-internal.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\include\appagent.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"\r
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+                       >\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
diff --git a/src/agent/appagent/client.cpp b/src/agent/appagent/client.cpp
new file mode 100644 (file)
index 0000000..30025ba
--- /dev/null
@@ -0,0 +1,119 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2012 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: client.cpp
+**
+**/
+
+#include "appagent-internal.h"
+
+/**
+ * Connect to application agent
+ */
+bool APPAGENT_EXPORTABLE AppAgentConnect(const TCHAR *name, HPIPE *hPipe)
+{
+#ifdef _WIN32
+       TCHAR pipeName[MAX_PATH];
+       _sntprintf(pipeName, MAX_PATH, _T("\\\\.\\pipe\\appagent.%s"), name);
+
+reconnect:
+       *hPipe = CreateFile(pipeName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
+       if (*hPipe == INVALID_HANDLE_VALUE)
+       {
+               if (GetLastError() == ERROR_PIPE_BUSY)
+               {
+                       if (WaitNamedPipe(pipeName, 5000))
+                               goto reconnect;
+               }
+               return false;
+       }
+
+       DWORD pipeMode = PIPE_READMODE_MESSAGE;
+       SetNamedPipeHandleState(*hPipe, &pipeMode, NULL, NULL);
+#else
+       *hPipe = socket(AF_UNIX, SOCK_STREAM, 0);
+       if (*hPipe == -1)
+               return false;
+
+       struct sockaddr_un remote;
+       remote.sun_family = AF_UNIX;
+       sprintf(remote.sun_path, "/tmp/.appagent.%s", name);    
+       if (connect(*hPipe, (struct sockaddr *)&remote, SUN_LEN(&remote)) == -1)
+       {
+               close(*hPipe);
+               return false;
+       }
+#endif
+
+       return true;
+}
+
+/**
+ * Disconnect from application agent
+ */
+void APPAGENT_EXPORTABLE AppAgentDisconnect(HPIPE hPipe)
+{
+#ifdef _WIN32
+       CloseHandle(hPipe);
+#else
+       close(hPipe);
+#endif
+}
+
+/**
+ * Get metric from application agent
+ */
+int APPAGENT_EXPORTABLE AppAgentGetMetric(HPIPE hPipe, const TCHAR *name, TCHAR *value, int bufferSize)
+{
+       int rcc = APPAGENT_RCC_COMM_FAILURE;
+
+       APPAGENT_MSG *request = NewMessage(APPAGENT_CMD_GET_METRIC, 0, ((int)_tcslen(name) + 1) * sizeof(WCHAR));
+#ifdef UNICODE
+       wcscpy((WCHAR *)request->payload, name);
+#else
+       MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, (WCHAR *)request->payload, (int)strlen(name) + 1);
+#endif
+
+       if (SendMessageToPipe(hPipe, request))
+       {
+               MessageBuffer *mb = new MessageBuffer;
+               APPAGENT_MSG *response = ReadMessageFromPipe(hPipe, NULL, mb);
+               if (response != NULL)
+               {
+                       if (response->command == APPAGENT_CMD_REQUEST_COMPLETED)
+                       {
+                               rcc = response->rcc;
+                               if (rcc == APPAGENT_RCC_SUCCESS)
+                               {
+                                       int valueLen = (response->length - APPAGENT_MSG_HEADER_LEN) / sizeof(TCHAR);
+#ifdef UNICODE
+                                       nx_strncpy(value, (WCHAR *)response->payload, min(valueLen, bufferSize));
+#else
+                                       WideCharToMultiByte(CP_ACP, WC_COMPOSITECHECK | WC_DEFAULTCHAR, (WCHAR *)response->payload, valueLen, value, bufferSize, NULL, NULL);
+                                       value[min(valueLen, bufferSize - 1)] = 0;
+#endif
+                               }
+                       }
+                       free(response);
+               }
+               delete mb;
+       }
+
+       free(request);
+       return rcc;
+}
diff --git a/src/agent/appagent/message.cpp b/src/agent/appagent/message.cpp
new file mode 100644 (file)
index 0000000..970902d
--- /dev/null
@@ -0,0 +1,153 @@
+/* 
+** NetXMS - Network Management System
+** Copyright (C) 2003-2012 Victor Kirhenshtein
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU Lesser General Public License as published by
+** the Free Software Foundation; either version 3 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 Lesser General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**
+** File: appagent.cpp
+**/
+
+#include "appagent-internal.h"
+
+/**
+ * Message buffer - seek to message start
+ * 
+ * @return message length or -1 if message start not found
+ */
+int MessageBuffer::seek()
+{
+       if (m_pos < APPAGENT_MSG_START_INDICATOR_LEN + APPAGENT_MSG_SIZE_FIELD_LEN)
+               return -1;
+
+       for(int i = 0; i < m_pos - APPAGENT_MSG_START_INDICATOR_LEN - APPAGENT_MSG_SIZE_FIELD_LEN; i++)
+               if (!memcmp(&m_data[i], APPAGENT_MSG_START_INDICATOR, APPAGENT_MSG_START_INDICATOR_LEN))
+               {
+                       shrink(i);
+                       WORD len;
+                       memcpy(&len, &m_data[APPAGENT_MSG_START_INDICATOR_LEN], APPAGENT_MSG_SIZE_FIELD_LEN);
+                       return (int)len;
+               }
+
+       shrink(m_pos - APPAGENT_MSG_START_INDICATOR_LEN - APPAGENT_MSG_SIZE_FIELD_LEN + 1);
+       return -1;
+}
+
+/**
+ * Message buffer - shrink
+ *
+ * @param pos start position of remaining content
+ */
+void MessageBuffer::shrink(int pos)
+{
+       if (pos > m_pos)
+               pos = m_pos;
+       m_pos -= pos;
+       memmove(m_data, &m_data[pos], m_pos);
+}
+
+/**
+ * Receive message from pipe
+ */
+APPAGENT_MSG *ReadMessageFromPipe(HPIPE hPipe, HANDLE hEvent, MessageBuffer *mb)
+{
+       APPAGENT_MSG *msg = NULL;
+
+       int msgLen = mb->seek();
+       while((msgLen < 0) || (mb->m_pos < msgLen))
+       {
+#ifdef _WIN32
+               DWORD bytes;
+               if (hEvent != NULL)
+               {
+                       OVERLAPPED ov;
+
+                       memset(&ov, 0, sizeof(OVERLAPPED));
+                       ov.hEvent = hEvent;
+                       if (!ReadFile(hPipe, &mb->m_data[mb->m_pos], MessageBuffer::DATA_SIZE - mb->m_pos, NULL, &ov))
+                       {
+                               if (GetLastError() != ERROR_IO_PENDING)
+                                       return NULL;
+                       }
+                       if (!GetOverlappedResult(hPipe, &ov, &bytes, TRUE))
+                       {
+                               return NULL;
+                       }
+               }
+               else
+               {
+                       if (!ReadFile(hPipe, &mb->m_data[mb->m_pos], MessageBuffer::DATA_SIZE - mb->m_pos, &bytes, NULL))
+                               return NULL;
+               }
+#else
+               int bytes = RecvEx(hPipe, &mb->m_data[mb->m_pos], MessageBuffer::DATA_SIZE - mb->m_pos, 0, INFINITE);
+               if (bytes <= 0)
+                       return NULL;
+#endif
+               mb->m_pos += (int)bytes;
+               if (mb->m_pos == MessageBuffer::DATA_SIZE)
+               {
+                       mb->m_pos = 0;
+               }
+               else
+               {
+                       msgLen = mb->seek();
+               }
+       }
+
+       if (msgLen > 0)
+       {
+               msg = (APPAGENT_MSG *)malloc(msgLen);
+               memcpy(msg, mb->m_data, msgLen);
+               mb->shrink(msgLen);
+       }
+
+       return msg;
+}
+
+/*
+ * Send message to external subagent
+ */
+bool SendMessageToPipe(HPIPE hPipe, APPAGENT_MSG *msg)
+{
+       bool success = false;
+
+#ifdef _WIN32
+       DWORD bytes = 0;
+       if (WriteFile(hPipe, msg, msg->length, &bytes, NULL))
+       {
+               success = (bytes == msg->length);
+       }
+#else
+       int bytes = SendEx(hPipe, msg, msg->length, 0, NULL); 
+       success = (bytes == msg->length);
+#endif
+       return success;
+}
+
+/**
+ * Create new message
+ *
+ * @param command command code
+ * @param length payload length
+ */
+APPAGENT_MSG *NewMessage(int command, int rcc, int length)
+{
+       APPAGENT_MSG *msg = (APPAGENT_MSG *)malloc(length + APPAGENT_MSG_HEADER_LEN);
+       memcpy(msg->prefix, APPAGENT_MSG_START_INDICATOR, APPAGENT_MSG_START_INDICATOR_LEN);
+       msg->length = length + APPAGENT_MSG_HEADER_LEN;
+       msg->command = (WORD)command;
+       msg->rcc = (WORD)rcc;
+       return msg;
+}
index eafd73a..12b5546 100644 (file)
@@ -95,8 +95,15 @@ THREAD_RESULT THREAD_CALL MasterAgentListener(void *arg)
                }
                else
                {
-                       AgentWriteDebugLog(1, _T("Cannot connect to master agent, will retry in 5 seconds"));
-                       ThreadSleep(5);
+                       if (GetLastError() == ERROR_PIPE_BUSY)
+                       {
+                               WaitNamedPipe(pipeName, 5000);
+                       }
+                       else
+                       {
+                               AgentWriteDebugLog(1, _T("Cannot connect to master agent, will retry in 5 seconds"));
+                               ThreadSleep(5);
+                       }
                }
        }
        AgentWriteDebugLog(1, _T("Master agent listener stopped"));
index bb4eff5..5d1867b 100644 (file)
@@ -1004,11 +1004,9 @@ BOOL Initialize()
    return TRUE;
 }
 
-
-//
-// Shutdown routine
-//
-
+/**
+ * Shutdown agent
+ */
 void Shutdown()
 {
        DebugPrintf(INVALID_INDEX, 2, _T("Shutdown() called"));
@@ -1045,11 +1043,9 @@ void Shutdown()
 #endif
 }
 
-
-//
-// Common Main()
-//
-
+/**
+ * Common Main()
+ */
 void Main()
 {
    nxlog_write(MSG_AGENT_STARTED, NXLOG_INFO, NULL);
@@ -1094,11 +1090,9 @@ void Main()
    }
 }
 
-
-//
-// Do necessary actions on agent restart
-//
-
+/**
+ * Do necessary actions on agent restart
+ */
 static void DoRestartActions(DWORD dwOldPID)
 {
 #if defined(_WIN32)
@@ -1141,11 +1135,9 @@ static void DoRestartActions(DWORD dwOldPID)
 #endif
 }
 
-
-//
-// Create configuration file
-//
-
+/**
+ * Create configuration file
+ */
 static int CreateConfig(const char *pszServer, const char *pszLogFile, const char *pszFileStore,
                         const char *configIncludeDir, int iNumSubAgents, char **ppszSubAgentList)
 {
index 42f7f08..7eae6bf 100644 (file)
@@ -11,6 +11,9 @@
                <Platform\r
                        Name="Win32"\r
                />\r
+               <Platform\r
+                       Name="x64"\r
+               />\r
        </Platforms>\r
        <ToolFiles>\r
        </ToolFiles>\r
                                Name="VCPostBuildEventTool"\r
                        />\r
                </Configuration>\r
+               <Configuration\r
+                       Name="Debug|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;LIBNXSD_EXPORTS"\r
+                               MinimalRebuild="true"\r
+                               ExceptionHandling="0"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalIncludeDirectories="..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;LIBNXSD_EXPORTS"\r
+                               ExceptionHandling="0"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
        </Configurations>\r
        <References>\r
        </References>\r
index d3e384a..2fc71e2 100644 (file)
@@ -11,6 +11,9 @@
                <Platform\r
                        Name="Win32"\r
                />\r
+               <Platform\r
+                       Name="x64"\r
+               />\r
        </Platforms>\r
        <ToolFiles>\r
        </ToolFiles>\r
                                Name="VCPostBuildEventTool"\r
                        />\r
                </Configuration>\r
+               <Configuration\r
+                       Name="Debug|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;DBQUERY_EXPORTS"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       ConfigurationType="2"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalIncludeDirectories="..\..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;DBQUERY_EXPORTS"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="2"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
        </Configurations>\r
        <References>\r
        </References>\r
index b6f6246..9419245 100644 (file)
@@ -8,4 +8,4 @@
 # WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
-SUBDIRS = nxapush
+SUBDIRS = nxappget nxapush
diff --git a/src/agent/tools/nxappget/nxappget.cpp b/src/agent/tools/nxappget/nxappget.cpp
new file mode 100644 (file)
index 0000000..4526a27
--- /dev/null
@@ -0,0 +1,157 @@
+/* 
+** nxappget - command line tool for reading metrics from application agents
+** Copyright (C) 2006-2012 Raden Solutions
+**
+** 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.
+**
+**/
+
+#include <appagent.h>
+
+
+//
+// options
+//
+
+static int optVerbose = 1;
+static int optBatchSize = 0;
+
+#if HAVE_DECL_GETOPT_LONG
+static struct option longOptions[] =
+{
+       {"version",   no_argument,       NULL,        'V'},
+       {"help",      no_argument,       NULL,        'h'},
+       {"verbose",   no_argument,       NULL,        'v'},
+       {"quiet",     no_argument,       NULL,        'q'},
+       {NULL, 0, NULL, 0}
+};
+#endif
+
+#define SHORT_OPTIONS "Vhvq"
+
+/**
+ * Show online help
+ */
+static void usage(char *argv0)
+{
+       _tprintf(
+_T("NetXMS Application Agent GET  Version ") NETXMS_VERSION_STRING _T("\n")
+_T("Copyright (c) 2006-2012 Raden Solutions\n\n")
+_T("Usage: %hs agent_name metric_name\n")
+_T("  \n")
+_T("Options:\n")
+#if HAVE_GETOPT_LONG
+_T("  -V, --version              Display version information.\n")
+_T("  -h, --help                 Display this help message.\n")
+_T("  -v, --verbose              Enable verbose messages. Add twice for debug\n")
+_T("  -q, --quiet                Suppress all messages.\n\n")
+#else
+_T("  -V             Display version information.\n")
+_T("  -h             Display this help message.\n")
+_T("  -v             Enable verbose messages. Add twice for debug\n")
+_T("  -q             Suppress all messages.\n\n")
+#endif
+       , argv0);
+}
+
+/**
+ * Entry point
+ */
+int main(int argc, char *argv[])
+{
+       int ret = 0;
+       int c;
+
+       InitThreadLibrary();
+
+       BOOL bStart = TRUE;
+       opterr = 0;
+#if HAVE_DECL_GETOPT_LONG
+       while ((c = getopt_long(argc, argv, SHORT_OPTIONS, longOptions, NULL)) != -1)
+#else
+       while ((c = getopt(argc, argv, SHORT_OPTIONS)) != -1)
+#endif
+       {
+               switch(c)
+               {
+               case 'V': // version
+                       _tprintf(_T("nxappget (") NETXMS_VERSION_STRING _T(")\n"));
+                       exit(0);
+                       break;
+               case 'h': // help
+                       usage(argv[0]);
+                       exit(1);
+                       break;
+               case 'v': // verbose
+                       optVerbose++;
+                       break;
+               case 'q': // quiet
+                       optVerbose = 0;
+                       break;
+               case '?':
+                       exit(3);
+                       break;
+               }
+       }
+       
+       if (argc - optind < 2)
+       {
+               if (optVerbose > 0)
+               {
+                       printf("Not enough arguments\n\n");
+#if HAVE_GETOPT_LONG
+                       printf("Try `%s --help' for more information.\n", argv[0]);
+#else
+                       printf("Try `%s -h' for more information.\n", argv[0]);
+#endif
+               }
+               exit(1);
+       }
+
+#ifdef UNICODE
+       WCHAR *appName = WideStringFromMBString(argv[optind]);
+       WCHAR *metricName = WideStringFromMBString(argv[optind + 1]);
+#else
+       char *appName = argv[optind];
+       char *metricName argv[optind + 1];
+#endif
+       HPIPE hPipe;
+       if (AppAgentConnect(appName, &hPipe))
+       {
+               TCHAR value[256];
+               int rcc = AppAgentGetMetric(hPipe, metricName, value, 256);
+               if (rcc == APPAGENT_RCC_SUCCESS)
+               {
+                       _tprintf(_T("%s\n"), value);
+               }
+               else
+               {
+                       _tprintf(_T("ERROR: agent error %d\n"), rcc);
+               }
+               AppAgentDisconnect(hPipe);
+       }
+       else
+       {
+               if (optVerbose > 0)
+                       _tprintf(_T("ERROR: Cannot connect to application agent\n\n"));
+               ret = 2;
+       }
+#ifdef UNICODE
+       free(appName);
+       free(metricName);
+#endif
+
+       return ret;
+}
diff --git a/src/agent/tools/nxappget/nxappget.vcproj b/src/agent/tools/nxappget/nxappget.vcproj
new file mode 100644 (file)
index 0000000..3a96dc0
--- /dev/null
@@ -0,0 +1,376 @@
+<?xml version="1.0" encoding="Windows-1252"?>\r
+<VisualStudioProject\r
+       ProjectType="Visual C++"\r
+       Version="8.00"\r
+       Name="nxappget"\r
+       ProjectGUID="{21D35413-495C-4DD2-BDBF-7BD708C70B74}"\r
+       RootNamespace="nxappget"\r
+       Keyword="Win32Proj"\r
+       >\r
+       <Platforms>\r
+               <Platform\r
+                       Name="Win32"\r
+               />\r
+               <Platform\r
+                       Name="x64"\r
+               />\r
+       </Platforms>\r
+       <ToolFiles>\r
+       </ToolFiles>\r
+       <Configurations>\r
+               <Configuration\r
+                       Name="Debug|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="4"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|Win32"\r
+                       OutputDirectory="$(SolutionDir)$(ConfigurationName)"\r
+                       IntermediateDirectory="$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalIncludeDirectories="..\..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="1"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Debug|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               Optimization="0"\r
+                               AdditionalIncludeDirectories="..\..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"\r
+                               MinimalRebuild="true"\r
+                               BasicRuntimeChecks="3"\r
+                               RuntimeLibrary="3"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="2"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+               <Configuration\r
+                       Name="Release|x64"\r
+                       OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"\r
+                       IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"\r
+                       ConfigurationType="1"\r
+                       CharacterSet="1"\r
+                       WholeProgramOptimization="1"\r
+                       >\r
+                       <Tool\r
+                               Name="VCPreBuildEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCustomBuildTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXMLDataGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebServiceProxyGeneratorTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCMIDLTool"\r
+                               TargetEnvironment="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCCLCompilerTool"\r
+                               AdditionalIncludeDirectories="..\..\..\..\include"\r
+                               PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"\r
+                               RuntimeLibrary="2"\r
+                               UsePrecompiledHeader="0"\r
+                               WarningLevel="3"\r
+                               Detect64BitPortabilityProblems="true"\r
+                               DebugInformationFormat="3"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManagedResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCResourceCompilerTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPreLinkEventTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCLinkerTool"\r
+                               LinkIncremental="1"\r
+                               GenerateDebugInformation="true"\r
+                               SubSystem="1"\r
+                               OptimizeReferences="2"\r
+                               EnableCOMDATFolding="2"\r
+                               TargetMachine="17"\r
+                       />\r
+                       <Tool\r
+                               Name="VCALinkTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCManifestTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCXDCMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCBscMakeTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCFxCopTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCAppVerifierTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCWebDeploymentTool"\r
+                       />\r
+                       <Tool\r
+                               Name="VCPostBuildEventTool"\r
+                       />\r
+               </Configuration>\r
+       </Configurations>\r
+       <References>\r
+       </References>\r
+       <Files>\r
+               <Filter\r
+                       Name="Source Files"\r
+                       Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"\r
+                       UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"\r
+                       >\r
+                       <File\r
+                               RelativePath=".\nxappget.cpp"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Header Files"\r
+                       Filter="h;hpp;hxx;hm;inl;inc;xsd"\r
+                       UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"\r
+                       >\r
+                       <File\r
+                               RelativePath="..\..\..\..\include\appagent.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\..\include\netxms-version.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\..\include\nms_common.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\..\include\nms_threads.h"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\..\..\..\include\nms_util.h"\r
+                               >\r
+                       </File>\r
+               </Filter>\r
+               <Filter\r
+                       Name="Resource Files"\r
+                       Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"\r
+                       UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"\r
+                       >\r
+               </Filter>\r
+       </Files>\r
+       <Globals>\r
+       </Globals>\r
+</VisualStudioProject>\r
index da99350..10654ad 100644 (file)
@@ -80,9 +80,9 @@ static struct option longOptions[] =
 
 #define SHORT_OPTIONS "Vhvqb:"
 
-//
-//
-//
+/**
+ * Show online help
+ */
 static void usage(char *argv0)
 {
        _tprintf(
@@ -116,9 +116,9 @@ _T("      nxapush @file\n")
        , argv0);
 }
 
-//
-// Entry point
-//
+/**
+ * Entry point
+ */
 int main(int argc, char *argv[])
 {
        int ret = 0;
@@ -255,11 +255,9 @@ int main(int argc, char *argv[])
        return ret;
 }
 
-
-//
-// Values parser - clean string and split by '='
-//
-
+/**
+ * Values parser - clean string and split by '='
+ */
 static BOOL AddValue(TCHAR *pair)
 {
        BOOL ret = FALSE;
@@ -289,15 +287,23 @@ static BOOL AddValue(TCHAR *pair)
        return ret;
 }
 
-//
-// Initialize client library and connect to the server
-//
+/**
+ * Initialize and connect to the agent
+ */
 static BOOL Startup()
 {
 #ifdef _WIN32
+reconnect:
        s_hPipe = CreateFile(_T("\\\\.\\pipe\\nxagentd.push"), GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
        if (s_hPipe == INVALID_HANDLE_VALUE)
+       {
+               if (GetLastError() == ERROR_PIPE_BUSY)
+               {
+                       if (WaitNamedPipe(_T("\\\\.\\pipe\\nxagentd.push"), 5000))
+                               goto reconnect;
+               }
                return FALSE;
+       }
 
        DWORD pipeMode = PIPE_READMODE_MESSAGE;
        SetNamedPipeHandleState(s_hPipe, &pipeMode, NULL, NULL);
@@ -323,9 +329,9 @@ static BOOL Startup()
        return TRUE;
 }
 
-//
-// Send all DCIs
-//
+/**
+ * Send all DCIs
+ */
 static BOOL Send()
 {
        BOOL success = FALSE;
@@ -362,9 +368,9 @@ cleanup:
        return success;
 }
 
-//
-// Disconnect and cleanup
-//
+/**
+ * Disconnect and cleanup
+ */
 static BOOL Teardown()
 {
 #ifdef _WIN32
index d4c5201..254b413 100644 (file)
 
 #define MAX_LOG_HISTORY_SIZE   16
 
-
-//
-// Static data
-//
-
+/**
+ * Static data
+ */
 #ifdef _WIN32
 static HANDLE m_eventLogHandle = NULL;
 static HMODULE m_msgModuleHandle = NULL;
index 236d913..270b78b 100644 (file)
@@ -116,11 +116,9 @@ TCHAR LIBNETXMS_EXPORTABLE *SockaddrToStr(struct sockaddr *addr, TCHAR *buffer)
        }
 }
 
-
-//
-// Convert IPv6 address from binary form to string
-//
-
+/**
+ * Convert IPv6 address from binary form to string
+ */
 TCHAR LIBNETXMS_EXPORTABLE *Ip6ToStr(BYTE *addr, TCHAR *buffer)
 {
    static TCHAR internalBuffer[64];
@@ -163,11 +161,9 @@ TCHAR LIBNETXMS_EXPORTABLE *Ip6ToStr(BYTE *addr, TCHAR *buffer)
    return bufPtr;
 }
 
-
-//
-// Duplicate memory block
-//
-
+/**
+ * Duplicate memory block
+ */
 void LIBNETXMS_EXPORTABLE *nx_memdup(const void *pData, DWORD dwSize)
 {
    void *pNewData;