- Added portable ICMP PING function
[public/netxms.git] / src / server / core / np.cpp
CommitLineData
282349dd
VK
1/*
2** Project X - Network Management System
3** Copyright (C) 2003 Victor 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** $module: discovery.cpp
20**
21**/
22
23#include "nms_core.h"
24
25
26//
27// Poll new node for configuration
28//
29
30static void PollNode(DWORD dwIpAddr, DWORD dwNetMask, DWORD dwFlags)
31{
32 Node *pNode;
33static DWORD id=1;
34
35 printf("Polling IP: %s\n", IpToStr(dwIpAddr, NULL));
36/*
37 // Check for node existence
38 pNode = FindObjectByAddr(dwIpAddr);
39 if (pNode != NULL)
40 {
41 char szBuffer[32];
42
43 WriteLog(MSG_NODE_EXIST, EVENTLOG_WARNING_TYPE, "s", IpToStr(dwIpAddr, szBuffer));
44 return;
45 }
46
47 pNode = new Node(id++, dwIpAddr, dwFlags, 0);
48 AddNode(pNode, dwIpAddr, dwNetMask);*/
49}
50
51
52//
53// Node poller thread (poll new nodes and put them into the database)
54//
55
56void NodePoller(void *arg)
57{
58 DB_RESULT hResult;
59
60 while(!ShutdownInProgress())
61 {
62 ThreadSleep(30);
63 if (ShutdownInProgress())
64 break;
65
66 hResult = DBSelect(g_hCoreDB, "SELECT id,ip_addr,ip_netmask,discovery_flags FROM NewNodes");
67 if (hResult != 0)
68 {
69 int i, iNumRows;
70 DWORD dwId, dwIpAddr, dwNetMask, dwFlags;
71 char szQuery[256];
72
73 iNumRows = DBGetNumRows(hResult);
74 for(i = 0; i < iNumRows; i++)
75 {
76 dwId = DBGetFieldULong(hResult, i, 0);
77 dwIpAddr = DBGetFieldULong(hResult, i, 1);
78 dwNetMask = DBGetFieldULong(hResult, i, 2);
79 dwFlags = DBGetFieldULong(hResult, i, 3);
80
81 PollNode(dwIpAddr, dwNetMask, dwFlags);
82
83 // Delete processed node
84 sprintf(szQuery, "DELETE FROM NewNodes WHERE id=%ld", dwId);
85 DBQuery(g_hCoreDB, szQuery);
86 }
87 DBFreeResult(hResult);
88 }
89 }
90}