All messages with codes 0x1100 - 0x11ff now forwarded to Reporting Server
[public/netxms.git] / src / server / core / reporting.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2013 Alex Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: reporting.cpp
20 **
21 **/
22
23 #include "nxcore.h"
24
25 class RSConnector : public ISC
26 {
27 public:
28 RSConnector(DWORD addr, DWORD port) : ISC(addr, port)
29 {
30 }
31
32 virtual void PrintMsg(const TCHAR *format, ...)
33 {
34 va_list args;
35 va_start(args, format);
36 DbgPrintf2(7, format, args);
37 va_end(args);
38 }
39 };
40
41 static RSConnector *m_connector = NULL;
42
43 THREAD_RESULT THREAD_CALL ReportingServerConnector(void *arg)
44 {
45 TCHAR hostname[256];
46 ConfigReadStr(_T("ReportingServerHostname"), hostname, 256, _T("localhost"));
47 DWORD port = ConfigReadInt(_T("ReportingServerPort"), 4710);
48
49 DbgPrintf(1, _T("Reporting Server connector started (%s:%d)"), hostname, port);
50
51 // Keep connection open
52 m_connector = new RSConnector(ResolveHostName(hostname), port);
53 while(!IsShutdownInProgress())
54 {
55 if (m_connector->Nop() == ISC_ERR_SUCCESS)
56 {
57 ThreadSleep(1);
58 }
59 else
60 {
61 if (m_connector->Connect(0) == ISC_ERR_SUCCESS)
62 {
63 DbgPrintf(6, _T("Connection to Reporting Server restored"));
64 }
65 else
66 {
67 ThreadSleep(1);
68 }
69 }
70 }
71 m_connector->Disconnect();
72 delete m_connector;
73 m_connector = NULL;
74
75 DbgPrintf(1, _T("Reporting Server connector stopped"));
76 return THREAD_OK;
77 }
78
79 CSCPMessage *ForwardMessageToReportingServer(CSCPMessage *request)
80 {
81 CSCPMessage *reply = NULL;
82
83 DWORD originalId = request->GetId();
84
85 if (m_connector != NULL)
86 {
87 request->SetId(0); // force ISC to generate unique ID
88 if (m_connector->SendMessage(request))
89 {
90 reply = m_connector->WaitForMessage(CMD_REQUEST_COMPLETED, request->GetId(), 10000);
91 }
92 }
93
94 if (reply != NULL)
95 {
96 reply->SetId(originalId);
97 }
98
99 return reply;
100 }