Added request for service status to AgentConnection class
authorVictor Kirhenshtein <victor@netxms.org>
Fri, 21 Jan 2005 21:42:01 +0000 (21:42 +0000)
committerVictor Kirhenshtein <victor@netxms.org>
Fri, 21 Jan 2005 21:42:01 +0000 (21:42 +0000)
src/server/include/nxsrvapi.h
src/server/libnxsrv/agent.cpp

index aba1946..13ef5bc 100644 (file)
@@ -184,6 +184,8 @@ public:
    DWORD ExecAction(TCHAR *pszAction, int argc, TCHAR **argv);
    DWORD UploadFile(TCHAR *pszFile);
    DWORD StartUpgrade(TCHAR *pszPkgName);
    DWORD ExecAction(TCHAR *pszAction, int argc, TCHAR **argv);
    DWORD UploadFile(TCHAR *pszFile);
    DWORD StartUpgrade(TCHAR *pszPkgName);
+   DWORD CheckNetworkService(DWORD *pdwStatus, DWORD dwIpAddr, int iServiceType, WORD wPort = 0, 
+                             WORD wProto = 0, TCHAR *pszRequest = NULL, TCHAR *pszResponce = NULL);
 
    DWORD GetNumDataLines(void) { return m_dwNumDataLines; }
    const TCHAR *GetDataLine(DWORD dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); }
 
    DWORD GetNumDataLines(void) { return m_dwNumDataLines; }
    const TCHAR *GetDataLine(DWORD dwIndex) { return dwIndex < m_dwNumDataLines ? m_ppDataLines[dwIndex] : _T("(error)"); }
index a2d982d..c41b9a1 100644 (file)
@@ -771,3 +771,59 @@ DWORD AgentConnection::StartUpgrade(TCHAR *pszPkgName)
 
    return dwResult;
 }
 
    return dwResult;
 }
+
+
+//
+// Check status of network service via agent
+//
+
+DWORD AgentConnection::CheckNetworkService(DWORD *pdwStatus, DWORD dwIpAddr, int iServiceType, 
+                                           WORD wPort, WORD wProto, 
+                                           TCHAR *pszRequest, TCHAR *pszResponce)
+{
+   DWORD dwRqId, dwResult;
+   CSCPMessage msg, *pResponce;
+   static WORD m_wDefaultPort[] = { 7, 22, 110, 25, 21, 80 };
+
+   if (!m_bIsConnected)
+      return ERR_NOT_CONNECTED;
+
+   dwRqId = m_dwRequestId++;
+
+   msg.SetCode(CMD_CHECK_NETWORK_SERVICE);
+   msg.SetId(dwRqId);
+   msg.SetVariable(VID_IP_ADDRESS, dwIpAddr);
+   msg.SetVariable(VID_SERVICE_TYPE, (WORD)iServiceType);
+   msg.SetVariable(VID_IP_PORT, 
+      (wPort != 0) ? wPort : 
+         m_wDefaultPort[((iServiceType >=NETSRV_CUSTOM) && 
+                         (iServiceType <= NETSRV_HTTP)) ? iServiceType : 0]);
+   msg.SetVariable(VID_IP_PORT, (wProto != 0) ? wProto : (WORD)IPPROTO_TCP);
+   msg.SetVariable(VID_SERVICE_REQUEST, pszRequest);
+   msg.SetVariable(VID_SERVICE_RESPONCE, pszResponce);
+
+   if (SendMessage(&msg))
+   {
+      // Wait up to 90 seconds for results
+      pResponce = WaitForMessage(CMD_REQUEST_COMPLETED, dwRqId, 90000);
+      if (pResponce != NULL)
+      {
+         dwResult = pResponce->GetVariableLong(VID_RCC);
+         if (dwResult == ERR_SUCCESS)
+         {
+            *pdwStatus = pResponce->GetVariableLong(VID_SERVICE_STATUS);
+         }
+         delete pResponce;
+      }
+      else
+      {
+         dwResult = ERR_REQUEST_TIMEOUT;
+      }
+   }
+   else
+   {
+      dwResult = ERR_CONNECTION_BROKEN;
+   }
+
+   return dwResult;
+}