all pollers converted to single thread pool
[public/netxms.git] / src / server / include / nms_objects.h
CommitLineData
3f39fdc2 1/*
5039dede 2** NetXMS - Network Management System
e2c2154a 3** Copyright (C) 2003-2014 Victor Kirhenshtein
5039dede
AK
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: nms_objects.h
20**
21**/
22
23#ifndef _nms_objects_h_
24#define _nms_objects_h_
25
26#include <nms_agent.h>
5039dede 27#include <netxms_maps.h>
e2babedf 28#include <geolocation.h>
ab621f39 29#include "nxcore_jobs.h"
630e15d6 30#include "nms_topo.h"
5039dede 31
6fd6de0a
VK
32/**
33 * Forward declarations of classes
34 */
5039dede
AK
35class AgentConnection;
36class AgentConnectionEx;
37class ClientSession;
38class Queue;
6fd6de0a 39class DataCollectionTarget;
5039dede 40
6fd6de0a 41/**
dcc8b1bc 42 * Global variables used by inline methods
6fd6de0a 43 */
967893bb
VK
44extern UINT32 g_dwDiscoveryPollingInterval;
45extern UINT32 g_dwStatusPollingInterval;
46extern UINT32 g_dwConfigurationPollingInterval;
47extern UINT32 g_dwRoutingTableUpdateInterval;
48extern UINT32 g_dwTopologyPollingInterval;
49extern UINT32 g_dwConditionPollingInterval;
805171de 50extern UINT32 g_instancePollingInterval;
9708eff4 51extern INT16 g_defaultAgentCacheMode;
5039dede 52
dcc8b1bc
VK
53/**
54 * Utility functions used by inline methods
55 */
56bool NXCORE_EXPORTABLE ExecuteQueryOnObject(DB_HANDLE hdb, UINT32 objectId, const TCHAR *query);
57
6fd6de0a
VK
58/**
59 * Constants
60 */
5039dede
AK
61#define MAX_INTERFACES 4096
62#define MAX_ATTR_NAME_LEN 128
63#define INVALID_INDEX 0xFFFFFFFF
64
7243b4ad
VK
65/**
66 * Last events
67 */
5039dede
AK
68#define MAX_LAST_EVENTS 8
69
70#define LAST_EVENT_NODE_DOWN 0
66d15dff 71#define LAST_EVENT_AGENT_DOWN 1
5039dede 72
7243b4ad
VK
73/**
74 * Built-in object IDs
75 */
5a4dc0c6
VK
76#define BUILTIN_OID_NETWORK 1
77#define BUILTIN_OID_SERVICEROOT 2
78#define BUILTIN_OID_TEMPLATEROOT 3
79#define BUILTIN_OID_ZONE0 4
80#define BUILTIN_OID_POLICYROOT 5
81#define BUILTIN_OID_NETWORKMAPROOT 6
82#define BUILTIN_OID_DASHBOARDROOT 7
5a4dc0c6 83#define BUILTIN_OID_BUSINESSSERVICEROOT 9
5039dede 84
17ac348b
VK
85/**
86 * Node runtime (dynamic) flags
87 */
805171de
VK
88#define NDF_QUEUED_FOR_STATUS_POLL 0x000001
89#define NDF_QUEUED_FOR_CONFIG_POLL 0x000002
90#define NDF_UNREACHABLE 0x000004
91#define NDF_AGENT_UNREACHABLE 0x000008
92#define NDF_SNMP_UNREACHABLE 0x000010
93#define NDF_QUEUED_FOR_DISCOVERY_POLL 0x000020
94#define NDF_FORCE_STATUS_POLL 0x000040
95#define NDF_FORCE_CONFIGURATION_POLL 0x000080
96#define NDF_QUEUED_FOR_ROUTE_POLL 0x000100
97#define NDF_CPSNMP_UNREACHABLE 0x000200
98#define NDF_RECHECK_CAPABILITIES 0x000400
99#define NDF_POLLING_DISABLED 0x000800
100#define NDF_CONFIGURATION_POLL_PASSED 0x001000
101#define NDF_QUEUED_FOR_TOPOLOGY_POLL 0x002000
102#define NDF_DELETE_IN_PROGRESS 0x004000
103#define NDF_NETWORK_PATH_PROBLEM 0x008000
104#define NDF_QUEUED_FOR_INSTANCE_POLL 0x010000
5039dede 105
c1482463 106#define NDF_PERSISTENT (NDF_UNREACHABLE | NDF_NETWORK_PATH_PROBLEM | NDF_AGENT_UNREACHABLE | NDF_SNMP_UNREACHABLE | NDF_CPSNMP_UNREACHABLE)
4866d57b 107
d41923e1
VK
108#define __NDF_FLAGS_DEFINED
109
17ac348b
VK
110/**
111 * Cluster runtime flags
112 */
5039dede 113#define CLF_QUEUED_FOR_STATUS_POLL 0x0001
208d7427
VK
114#define CLF_DOWN 0x0002
115
116/**
117 * Poller types
118 */
119enum PollerType
120{
121 POLLER_TYPE_STATUS = 0,
122 POLLER_TYPE_CONFIGURATION = 1,
123 POLLER_TYPE_INSTANCE_DISCOVERY = 2,
124 POLLER_TYPE_ROUTING_TABLE = 3,
125 POLLER_TYPE_DISCOVERY = 4,
126 POLLER_TYPE_BUSINESS_SERVICE = 5,
127 POLLER_TYPE_CONDITION = 6,
128 POLLER_TYPE_TOPOLOGY = 7
129};
130
131/**
132 * Poller information
133 */
134class PollerInfo
135{
136private:
137 PollerType m_type;
138 NetObj *m_object;
139 TCHAR m_status[128];
140
141public:
142 PollerInfo(PollerType type, NetObj *object) { m_type = type; m_object = object; _tcscpy(m_status, _T("awaiting execution")); }
143 ~PollerInfo();
144
145 const PollerType getType() const { return m_type; }
146 NetObj *getObject() const { return m_object; }
147 const TCHAR *getStatus() const { return m_status; }
148
149 void startExecution() { _tcscpy(m_status, _T("started")); }
150 void setStatus(const TCHAR *status) { nx_strncpy(m_status, status, 128); }
151};
5039dede 152
17ac348b
VK
153/**
154 * Status poll types
155 */
156enum StatusPollType
157{
158 POLL_ICMP_PING = 0,
159 POLL_SNMP = 1,
160 POLL_NATIVE_AGENT =2
161};
5039dede 162
a84c073c
VK
163/**
164 * Auto bind/apply decisions
165 */
166enum AutoBindDecision
167{
168 AutoBindDecision_Ignore = -1,
169 AutoBindDecision_Unbind = 0,
170 AutoBindDecision_Bind = 1
171};
172
21c9acce
VK
173/**
174 * Zone types
175 */
5039dede
AK
176#define ZONE_TYPE_PASSIVE 0
177#define ZONE_TYPE_ACTIVE 1
178
21c9acce
VK
179/**
180 * Template update types
181 */
5039dede
AK
182#define APPLY_TEMPLATE 0
183#define REMOVE_TEMPLATE 1
184
6fd6de0a
VK
185/**
186 * Queued template update information
187 */
5039dede
AK
188struct TEMPLATE_UPDATE_INFO
189{
d140955e 190 int updateType;
5039dede 191 Template *pTemplate;
967893bb 192 UINT32 targetId;
d140955e 193 bool removeDCI;
5039dede
AK
194};
195
6fd6de0a 196/**
7243b4ad 197 * Object index element
6fd6de0a 198 */
5e39b8a3
VK
199struct INDEX_ELEMENT
200{
201 QWORD key;
202 NetObj *object;
203};
204
7243b4ad
VK
205/**
206 * Object index
207 */
5f0fc7a9 208class NXCORE_EXPORTABLE ObjectIndex
5e39b8a3
VK
209{
210private:
211 int m_size;
212 int m_allocated;
213 INDEX_ELEMENT *m_elements;
214 RWLOCK m_lock;
215
216 int findElement(QWORD key);
217
218public:
219 ObjectIndex();
220 ~ObjectIndex();
221
222 bool put(QWORD key, NetObj *object);
223 void remove(QWORD key);
224 NetObj *get(QWORD key);
225 NetObj *find(bool (*comparator)(NetObj *, void *), void *data);
226
a6312bd6 227 int size();
1201bac8 228 ObjectArray<NetObj> *getObjects(bool updateRefCount, bool (*filter)(NetObj *, void *) = NULL, void *userData = NULL);
5e39b8a3
VK
229
230 void forEach(void (*callback)(NetObj *, void *), void *data);
231};
232
c75e9ee4
VK
233struct InetAddressIndexEntry;
234
235/**
236 * Object index by IP address
237 */
238class NXCORE_EXPORTABLE InetAddressIndex
239{
240private:
241 InetAddressIndexEntry *m_root;
242 RWLOCK m_lock;
243
244public:
245 InetAddressIndex();
246 ~InetAddressIndex();
247
248 bool put(const InetAddress& addr, NetObj *object);
c30c0c0f 249 bool put(const InetAddressList *addrList, NetObj *object);
c75e9ee4 250 void remove(const InetAddress& addr);
c30c0c0f 251 void remove(const InetAddressList *addrList);
c75e9ee4
VK
252 NetObj *get(const InetAddress& addr);
253 NetObj *find(bool (*comparator)(NetObj *, void *), void *data);
254
255 int size();
256 ObjectArray<NetObj> *getObjects(bool updateRefCount, bool (*filter)(NetObj *, void *) = NULL, void *userData = NULL);
257
c30c0c0f 258 void forEach(void (*callback)(const InetAddress&, NetObj *, void *), void *data);
c75e9ee4
VK
259};
260
6fd6de0a
VK
261/**
262 * Node component
263 */
50d0de67
VK
264class Component
265{
266protected:
967893bb
VK
267 UINT32 m_index;
268 UINT32 m_class;
269 UINT32 m_ifIndex;
50d0de67
VK
270 TCHAR *m_name;
271 TCHAR *m_description;
272 TCHAR *m_model;
273 TCHAR *m_serial;
274 TCHAR *m_vendor;
275 TCHAR *m_firmware;
967893bb 276 UINT32 m_parentIndex;
50d0de67
VK
277 ObjectArray<Component> m_childs;
278
279public:
967893bb 280 Component(UINT32 index, const TCHAR *name);
50d0de67
VK
281 virtual ~Component();
282
967893bb 283 UINT32 updateFromSnmp(SNMP_Transport *snmp);
50d0de67
VK
284 void buildTree(ObjectArray<Component> *elements);
285
967893bb
VK
286 UINT32 getIndex() { return m_index; }
287 UINT32 getParentIndex() { return m_parentIndex; }
50d0de67 288
b368969c 289 UINT32 fillMessage(NXCPMessage *msg, UINT32 baseId);
8836184f 290
50d0de67
VK
291 void print(CONSOLE_CTX console, int level);
292};
293
7243b4ad
VK
294/**
295 * Node component tree
296 */
8836184f
VK
297class ComponentTree : public RefCountObject
298{
299private:
300 Component *m_root;
301
302public:
303 ComponentTree(Component *root);
304 virtual ~ComponentTree();
305
b368969c 306 void fillMessage(NXCPMessage *msg, UINT32 baseId);
8836184f
VK
307 void print(CONSOLE_CTX console) { if (m_root != NULL) m_root->print(console, 0); }
308
309 bool isEmpty() { return m_root == NULL; }
310 Component *getRoot() { return m_root; }
311};
312
caa04e26
VK
313/**
314 * Software package information
315 */
316class SoftwarePackage
317{
318private:
319 TCHAR *m_name;
320 TCHAR *m_version;
321 TCHAR *m_vendor;
322 time_t m_date;
323 TCHAR *m_url;
324 TCHAR *m_description;
325
326public:
327 SoftwarePackage(Table *table, int row);
328 ~SoftwarePackage();
329
b368969c 330 void fillMessage(NXCPMessage *msg, UINT32 baseId);
caa04e26
VK
331};
332
914580f5
VK
333/**
334 * Summary table flags
335 */
336#define SUMMARY_TABLE_MULTI_INSTANCE 0x0001
337
2da939ac
VK
338/**
339 * Summary table column flags
340 */
341#define COLUMN_DEFINITION_REGEXP_MATCH 0x0001
342
4a435beb
VK
343/**
344 * Column definition for DCI summary table
345 */
346class NXCORE_EXPORTABLE SummaryTableColumn
347{
348public:
349 TCHAR m_name[MAX_DB_STRING];
350 TCHAR m_dciName[MAX_PARAM_NAME];
967893bb 351 UINT32 m_flags;
4a435beb 352
b368969c 353 SummaryTableColumn(NXCPMessage *msg, UINT32 baseId);
4a435beb 354 SummaryTableColumn(TCHAR *configStr);
2096c8f0
VK
355
356 void createExportRecord(String &xml, int id);
4a435beb
VK
357};
358
359/**
360 * DCI summary table class
361 */
362class NXCORE_EXPORTABLE SummaryTable
363{
364private:
2096c8f0
VK
365 INT32 m_id;
366 uuid_t m_guid;
4a435beb 367 TCHAR m_title[MAX_DB_STRING];
967893bb 368 UINT32 m_flags;
4a435beb 369 ObjectArray<SummaryTableColumn> *m_columns;
2096c8f0 370 TCHAR *m_filterSource;
6b29839d 371 NXSL_VM *m_filter;
2852ef09
VK
372 AggregationFunction m_aggregationFunction;
373 time_t m_periodStart;
374 time_t m_periodEnd;
2096c8f0 375 TCHAR m_menuPath[MAX_DB_STRING];
4a435beb 376
2096c8f0 377 SummaryTable(INT32 id, DB_RESULT hResult);
4a435beb
VK
378
379public:
2096c8f0 380 static SummaryTable *loadFromDB(INT32 id, UINT32 *rcc);
5389f7b0 381
b368969c 382 SummaryTable(NXCPMessage *msg);
4a435beb
VK
383 ~SummaryTable();
384
385 bool filter(DataCollectionTarget *node);
386 Table *createEmptyResultTable();
387
388 int getNumColumns() { return m_columns->size(); }
389 SummaryTableColumn *getColumn(int index) { return m_columns->get(index); }
2852ef09
VK
390 AggregationFunction getAggregationFunction() { return m_aggregationFunction; }
391 time_t getPeriodStart() { return m_periodStart; }
392 time_t getPeriodEnd() { return m_periodEnd; }
914580f5 393 bool isMultiInstance() { return (m_flags & SUMMARY_TABLE_MULTI_INSTANCE) ? true : false; }
2096c8f0
VK
394
395 void createExportRecord(String &xml);
4a435beb
VK
396};
397
2df18cce
VK
398/**
399 * Base class for network objects
400 */
5039dede
AK
401class NXCORE_EXPORTABLE NetObj
402{
27de5dab
VK
403private:
404 static void onObjectDeleteCallback(NetObj *object, void *data);
405
fc381a38
VK
406 void getFullChildListInternal(ObjectIndex *list, bool eventSourceOnly);
407
5039dede 408protected:
c42b4551 409 UINT32 m_id;
3f7c0fe4 410 uuid_t m_guid;
967893bb
VK
411 UINT32 m_dwTimeStamp; // Last change time stamp
412 UINT32 m_dwRefCount; // Number of references. Object can be destroyed only when this counter is zero
c42b4551 413 TCHAR m_name[MAX_OBJECT_NAME];
5039dede
AK
414 TCHAR *m_pszComments; // User comments
415 int m_iStatus;
416 int m_iStatusCalcAlg; // Status calculation algorithm
417 int m_iStatusPropAlg; // Status propagation algorithm
418 int m_iFixedStatus; // Status if propagation is "Fixed"
419 int m_iStatusShift; // Shift value for "shifted" status propagation
420 int m_iStatusTranslation[4];
421 int m_iStatusSingleThreshold;
422 int m_iStatusThresholds[4];
01152a54
VK
423 bool m_isModified;
424 bool m_isDeleted;
425 bool m_isHidden;
426 bool m_isSystem;
f25b0d12 427 uuid_t m_image;
c42b4551 428 MUTEX m_mutexProperties; // Object data access mutex
5039dede
AK
429 MUTEX m_mutexRefCount; // Reference counter access mutex
430 RWLOCK m_rwlockParentList; // Lock for parent list
431 RWLOCK m_rwlockChildList; // Lock for child list
e2babedf 432 GeoLocation m_geoLocation;
56fa1092 433 PostalAddress *m_postalAddress;
c59466d2 434 ClientSession *m_pollRequestor;
967893bb 435 UINT32 m_submapId; // Map object which should be open on drill-down request
5039dede 436
967893bb 437 UINT32 m_dwChildCount; // Number of child objects
5039dede
AK
438 NetObj **m_pChildList; // Array of pointers to child objects
439
967893bb 440 UINT32 m_dwParentCount; // Number of parent objects
5039dede
AK
441 NetObj **m_pParentList; // Array of pointers to parent objects
442
443 AccessList *m_pAccessList;
444 BOOL m_bInheritAccessRights;
445 MUTEX m_mutexACL;
446
967893bb
VK
447 UINT32 m_dwNumTrustedNodes; // Trusted nodes
448 UINT32 *m_pdwTrustedNodes;
3f39fdc2 449
5039dede 450 StringMap m_customAttributes;
4f5d216b 451 StringObjectMap<ModuleData> *m_moduleData;
5039dede 452
c42b4551
VK
453 void lockProperties() { MutexLock(m_mutexProperties); }
454 void unlockProperties() { MutexUnlock(m_mutexProperties); }
e2c2154a
VK
455 void lockACL() { MutexLock(m_mutexACL); }
456 void unlockACL() { MutexUnlock(m_mutexACL); }
3f39fdc2 457 void LockParentList(BOOL bWrite)
458 {
459 if (bWrite)
5039dede
AK
460 RWLockWriteLock(m_rwlockParentList, INFINITE);
461 else
3f39fdc2 462 RWLockReadLock(m_rwlockParentList, INFINITE);
5039dede 463 }
3f7c0fe4 464 void UnlockParentList() { RWLockUnlock(m_rwlockParentList); }
3f39fdc2 465 void LockChildList(BOOL bWrite)
466 {
467 if (bWrite)
5039dede
AK
468 RWLockWriteLock(m_rwlockChildList, INFINITE);
469 else
3f39fdc2 470 RWLockReadLock(m_rwlockChildList, INFINITE);
5039dede 471 }
3f7c0fe4 472 void UnlockChildList() { RWLockUnlock(m_rwlockChildList); }
5039dede 473
c42b4551 474 void setModified(); // Used to mark object as modified
5039dede 475
50546cb7
VK
476 bool loadACLFromDB();
477 bool saveACLToDB(DB_HANDLE hdb);
478 bool loadCommonProperties();
479 bool saveCommonProperties(DB_HANDLE hdb);
480 bool loadTrustedNodes();
481 bool saveTrustedNodes(DB_HANDLE hdb);
c42b4551 482 bool executeQueryOnObject(DB_HANDLE hdb, const TCHAR *query) { return ExecuteQueryOnObject(hdb, m_id, query); }
5039dede 483
22ee6d97 484 virtual void prepareForDeletion();
967893bb 485 virtual void onObjectDelete(UINT32 dwObjectId);
8fe90adb
VK
486
487 virtual void fillMessageInternal(NXCPMessage *msg);
9289a3bb 488 virtual void fillMessageInternalStage2(NXCPMessage *msg);
8fe90adb
VK
489 virtual UINT32 modifyFromMessageInternal(NXCPMessage *msg);
490
4899db4d 491 void addLocationToHistory();
7221dde1
VK
492 bool isLocationTableExists();
493 bool createLocationHistoryTable(DB_HANDLE hdb);
5039dede
AK
494
495public:
496 NetObj();
497 virtual ~NetObj();
498
c42b4551 499 virtual int getObjectClass() { return OBJECT_GENERIC; }
3f39fdc2 500
c42b4551
VK
501 UINT32 getId() { return m_id; }
502 const TCHAR *getName() { return m_name; }
3f7c0fe4 503 int Status() { return m_iStatus; }
6ff21d27 504 int getPropagatedStatus();
967893bb 505 UINT32 getTimeStamp() { return m_dwTimeStamp; }
3f7c0fe4 506 void getGuid(uuid_t out) { memcpy(out, m_guid, UUID_LENGTH); }
74fde582 507 const TCHAR *getComments() { return CHECK_NULL_EX(m_pszComments); }
56fa1092 508 PostalAddress *getPostalAddress() { return m_postalAddress; }
befab155 509 void setPostalAddress(PostalAddress * addr) { delete m_postalAddress; m_postalAddress = addr; markAsModified();}
5039dede 510
01152a54
VK
511 bool isModified() { return m_isModified; }
512 bool isDeleted() { return m_isDeleted; }
513 bool isOrphaned() { return m_dwParentCount == 0; }
514 bool isEmpty() { return m_dwChildCount == 0; }
3f39fdc2 515
01152a54
VK
516 bool isSystem() { return m_isSystem; }
517 void setSystemFlag(bool flag) { m_isSystem = flag; }
5039dede 518
967893bb 519 UINT32 getRefCount();
21c9acce
VK
520 void incRefCount();
521 void decRefCount();
5039dede 522
967893bb
VK
523 bool isChild(UINT32 id);
524 bool isTrustedNode(UINT32 id);
5039dede
AK
525
526 void AddChild(NetObj *pObject); // Add reference to child object
527 void AddParent(NetObj *pObject); // Add reference to parent object
528
529 void DeleteChild(NetObj *pObject); // Delete reference to child object
530 void DeleteParent(NetObj *pObject); // Delete reference to parent object
531
9dea3344 532 void deleteObject(NetObj *initiator = NULL); // Prepare object for deletion
5039dede 533
01152a54 534 bool isHidden() { return m_isHidden; }
478d4ff4
VK
535 void hide();
536 void unhide();
c42b4551 537 void markAsModified() { lockProperties(); setModified(); unlockProperties(); } // external API to mar object as modified
5039dede 538
c42b4551
VK
539 virtual BOOL saveToDatabase(DB_HANDLE hdb);
540 virtual bool deleteFromDatabase(DB_HANDLE hdb);
541 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 542
c42b4551 543 void setId(UINT32 dwId) { m_id = dwId; setModified(); }
3f7c0fe4 544 void generateGuid() { uuid_generate(m_guid); }
c42b4551
VK
545 void setName(const TCHAR *pszName) { nx_strncpy(m_name, pszName, MAX_OBJECT_NAME); setModified(); }
546 void resetStatus() { m_iStatus = STATUS_UNKNOWN; setModified(); }
547 void setComments(TCHAR *text); /* text must be dynamically allocated */
5039dede 548
8fe90adb
VK
549 void fillMessage(NXCPMessage *msg);
550 UINT32 modifyFromMessage(NXCPMessage *msg);
5039dede 551
6ff21d27 552 virtual void postModify();
5039dede 553
b368969c 554 void commentsToMessage(NXCPMessage *pMsg);
5039dede 555
8fe90adb
VK
556 virtual void setMgmtStatus(BOOL bIsManaged);
557 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
558
967893bb
VK
559 UINT32 getUserRights(UINT32 dwUserId);
560 BOOL checkAccessRights(UINT32 dwUserId, UINT32 dwRequiredRights);
561 void dropUserAccess(UINT32 dwUserId);
5039dede 562
967893bb
VK
563 void addChildNodesToList(ObjectArray<Node> *nodeList, UINT32 dwUserId);
564 void addChildDCTargetsToList(ObjectArray<DataCollectionTarget> *dctList, UINT32 dwUserId);
3f39fdc2 565
84a815cd 566 const TCHAR *getCustomAttribute(const TCHAR *name) { return m_customAttributes.get(name); }
c42b4551
VK
567 void setCustomAttribute(const TCHAR *name, const TCHAR *value) { m_customAttributes.set(name, value); setModified(); }
568 void setCustomAttributePV(const TCHAR *name, TCHAR *value) { m_customAttributes.setPreallocated(_tcsdup(name), value); setModified(); }
569 void deleteCustomAttribute(const TCHAR *name) { m_customAttributes.remove(name); setModified(); }
5039dede 570
4f5d216b
VK
571 ModuleData *getModuleData(const TCHAR *module);
572 void setModuleData(const TCHAR *module, ModuleData *data);
573
64e87664 574 ObjectArray<NetObj> *getParentList(int typeFilter);
fca08da9 575 ObjectArray<NetObj> *getChildList(int typeFilter);
da9cf449 576 ObjectArray<NetObj> *getFullChildList(bool eventSourceOnly, bool updateRefCount);
fc381a38 577
67de55fd
VK
578 NetObj *findChildObject(const TCHAR *name, int typeFilter);
579
9dea3344
VK
580 int getChildCount() { return (int)m_dwChildCount; }
581 int getParentCount() { return (int)m_dwParentCount; }
582
06c104c6 583 virtual NXSL_Array *getParentsForNXSL();
d679defa 584 virtual NXSL_Array *getChildrenForNXSL();
06c104c6 585
27bbb906 586 virtual bool showThresholdSummary();
d1730ccf 587 virtual bool isEventSource();
27bbb906 588
9d850e8b
VK
589 void setStatusCalculation(int method, int arg1 = 0, int arg2 = 0, int arg3 = 0, int arg4 = 0);
590 void setStatusPropagation(int method, int arg1 = 0, int arg2 = 0, int arg3 = 0, int arg4 = 0);
591
f7e3eb5a
VK
592 void sendPollerMsg(UINT32 dwRqId, const TCHAR *pszFormat, ...);
593
5039dede 594 // Debug methods
fca08da9
VK
595 const TCHAR *dbgGetParentList(TCHAR *szBuffer);
596 const TCHAR *dbgGetChildList(TCHAR *szBuffer);
5039dede
AK
597};
598
fca08da9
VK
599/**
600 * Get object's reference count
601 */
967893bb 602inline UINT32 NetObj::getRefCount()
3f39fdc2 603{
967893bb 604 UINT32 dwRefCount;
5039dede 605
c17f6cbc 606 MutexLock(m_mutexRefCount);
5039dede
AK
607 dwRefCount = m_dwRefCount;
608 MutexUnlock(m_mutexRefCount);
3f39fdc2 609 return dwRefCount;
5039dede
AK
610}
611
fca08da9
VK
612/**
613 * Increment object's reference count
614 */
21c9acce 615inline void NetObj::incRefCount()
3f39fdc2 616{
c17f6cbc 617 MutexLock(m_mutexRefCount);
5039dede
AK
618 m_dwRefCount++;
619 MutexUnlock(m_mutexRefCount);
620}
621
fca08da9
VK
622/**
623 * Decrement object's reference count
624 */
21c9acce 625inline void NetObj::decRefCount()
3f39fdc2 626{
c17f6cbc 627 MutexLock(m_mutexRefCount);
3f39fdc2 628 if (m_dwRefCount > 0)
629 m_dwRefCount--;
5039dede
AK
630 MutexUnlock(m_mutexRefCount);
631}
632
2df18cce
VK
633/**
634 * Data collection template class
635 */
5039dede
AK
636class NXCORE_EXPORTABLE Template : public NetObj
637{
638protected:
16d6f798 639 ObjectArray<DCObject> *m_dcObjects;
2a964810 640 int m_dciLockStatus;
967893bb
VK
641 UINT32 m_dwVersion;
642 UINT32 m_flags;
9fd816cc 643 bool m_dciListModified;
5039dede 644 TCHAR m_szCurrDCIOwner[MAX_SESSION_NAME];
4262c0dc 645 TCHAR *m_applyFilterSource;
6b29839d 646 NXSL_VM *m_applyFilter;
b06436f4 647 RWLOCK m_dciAccessLock;
5039dede 648
22ee6d97 649 virtual void prepareForDeletion();
5039dede 650
8fe90adb
VK
651 virtual void fillMessageInternal(NXCPMessage *pMsg);
652 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
653
9fd816cc
VK
654 virtual void onDataCollectionChange();
655
7c521895
VK
656 void loadItemsFromDB();
657 void destroyItems();
e46d6c36 658 void updateInstanceDiscoveryItems(DCItem *dci);
7c521895 659
b06436f4
VK
660 void lockDciAccess(bool writeLock) { if (writeLock) { RWLockWriteLock(m_dciAccessLock, INFINITE); } else { RWLockReadLock(m_dciAccessLock, INFINITE); } }
661 void unlockDciAccess() { RWLockUnlock(m_dciAccessLock); }
5039dede 662
9fcf5d15 663 void deleteChildDCIs(UINT32 dcObjectId);
664 void destroyItem(DCObject *object, int index);
665
5039dede
AK
666public:
667 Template();
668 Template(const TCHAR *pszName);
9fedef8b 669 Template(ConfigEntry *config);
5039dede
AK
670 virtual ~Template();
671
c42b4551 672 virtual int getObjectClass() { return OBJECT_TEMPLATE; }
5039dede 673
c42b4551
VK
674 virtual BOOL saveToDatabase(DB_HANDLE hdb);
675 virtual bool deleteFromDatabase(DB_HANDLE hdb);
676 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 677
27f9598d 678 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
5039dede 679
7c521895
VK
680 int getVersionMajor() { return m_dwVersion >> 16; }
681 int getVersionMinor() { return m_dwVersion & 0xFFFF; }
5039dede 682
16d6f798
VK
683 int getItemCount() { return m_dcObjects->size(); }
684 bool addDCObject(DCObject *object, bool alreadyLocked = false);
b368969c 685 bool updateDCObject(UINT32 dwItemId, NXCPMessage *pMsg, UINT32 *pdwNumMaps, UINT32 **ppdwMapIndex, UINT32 **ppdwMapId);
967893bb
VK
686 bool deleteDCObject(UINT32 dcObjectId, bool needLock);
687 bool setItemStatus(UINT32 dwNumItems, UINT32 *pdwItemList, int iStatus);
688 int getItemType(UINT32 dwItemId);
0719f017 689 DCObject *getDCObjectById(UINT32 itemId, bool lock = true);
967893bb 690 DCObject *getDCObjectByTemplateId(UINT32 tmplItemId);
16d6f798 691 DCObject *getDCObjectByIndex(int index);
abb85c62
VK
692 DCObject *getDCObjectByName(const TCHAR *name);
693 DCObject *getDCObjectByDescription(const TCHAR *description);
694 NXSL_Value *getAllDCObjectsForNXSL(const TCHAR *name, const TCHAR *description);
9fd816cc
VK
695 bool lockDCIList(int sessionId, const TCHAR *pszNewOwner, TCHAR *pszCurrOwner);
696 bool unlockDCIList(int sessionId);
697 void setDCIModificationFlag() { m_dciListModified = true; }
967893bb 698 void sendItemsToClient(ClientSession *pSession, UINT32 dwRqId);
2a964810 699 BOOL isLockedBySession(int sessionId) { return m_dciLockStatus == sessionId; }
967893bb 700 UINT32 *getDCIEventsList(UINT32 *pdwCount);
25a1e9d0 701 StringSet *getDCIScriptList();
5039dede 702
6fd6de0a 703 BOOL applyToTarget(DataCollectionTarget *pNode);
a84c073c 704 AutoBindDecision isApplicable(Node *node);
9b64b406
VK
705 bool isAutoApplyEnabled() { return (m_flags & TF_AUTO_APPLY) ? true : false; }
706 bool isAutoRemoveEnabled() { return ((m_flags & (TF_AUTO_APPLY | TF_AUTO_REMOVE)) == (TF_AUTO_APPLY | TF_AUTO_REMOVE)) ? true : false; }
fb05c05b 707 void setAutoApplyFilter(const TCHAR *filter);
7c521895 708 void queueUpdate();
d140955e 709 void queueRemoveFromTarget(UINT32 targetId, bool removeDCI);
171c2fd6 710
badf9a95 711 void createNXMPRecord(String &str);
3f39fdc2 712
967893bb 713 bool enumDCObjects(bool (* pfCallback)(DCObject *, UINT32, void *), void *pArg);
7c521895 714 void associateItems();
5dbf115e 715
1fa2ca0e 716 UINT32 getLastValues(NXCPMessage *msg, bool objectTooltipOnly, bool overviewOnly, bool includeNoValueObjects);
5039dede
AK
717};
718
c30c0c0f
VK
719class Cluster;
720
2df18cce
VK
721/**
722 * Interface class
723 */
5039dede
AK
724class NXCORE_EXPORTABLE Interface : public NetObj
725{
726protected:
c30c0c0f
VK
727 UINT32 m_index;
728 BYTE m_macAddr[MAC_ADDR_LENGTH];
729 InetAddressList m_ipAddressList;
967893bb 730 UINT32 m_flags;
478d4ff4 731 TCHAR m_description[MAX_DB_STRING]; // Interface description - value of ifDescr for SNMP, equals to name for NetXMS agent
e95680e5 732 TCHAR m_alias[MAX_DB_STRING]; // Interface alias - value of ifAlias for SNMP, empty for NetXMS agent
e95680e5
VK
733 UINT32 m_type;
734 UINT32 m_mtu;
967893bb
VK
735 UINT32 m_bridgePortNumber; // 802.1D port number
736 UINT32 m_slotNumber; // Vendor/device specific slot number
737 UINT32 m_portNumber; // Vendor/device specific port number
738 UINT32 m_peerNodeId; // ID of peer node object, or 0 if unknown
739 UINT32 m_peerInterfaceId; // ID of peer interface object, or 0 if unknown
b833cbf5 740 LinkLayerProtocol m_peerDiscoveryProtocol; // Protocol used to discover peer node
1e6b68a6
VK
741 WORD m_adminState; // interface administrative state
742 WORD m_operState; // interface operational state
478d4ff4
VK
743 WORD m_dot1xPaeAuthState; // 802.1x port auth state
744 WORD m_dot1xBackendAuthState; // 802.1x backend auth state
c42b4551 745 UINT64 m_lastDownEventId;
c59466d2
VK
746 int m_pendingStatus;
747 int m_pollCount;
748 int m_requiredPollCount;
967893bb 749 UINT32 m_zoneId;
1babf64d 750 UINT32 m_pingTime;
751 time_t m_pingLastTimeStamp;
5039dede 752
c30c0c0f
VK
753 void icmpStatusPoll(UINT32 rqId, UINT32 nodeIcmpProxy, Cluster *cluster, InterfaceAdminState *adminState, InterfaceOperState *operState);
754 void paeStatusPoll(UINT32 rqId, SNMP_Transport *pTransport, Node *node);
aa16f82b 755
95e0c288 756protected:
967893bb 757 virtual void onObjectDelete(UINT32 dwObjectId);
95e0c288 758
8fe90adb
VK
759 virtual void fillMessageInternal(NXCPMessage *pMsg);
760 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
761
5039dede
AK
762public:
763 Interface();
c30c0c0f
VK
764 Interface(const InetAddressList& addrList, UINT32 zoneId, bool bSyntheticMask);
765 Interface(const TCHAR *name, const TCHAR *descr, UINT32 index, const InetAddressList& addrList, UINT32 ifType, UINT32 zoneId);
5039dede
AK
766 virtual ~Interface();
767
c42b4551
VK
768 virtual int getObjectClass() { return OBJECT_INTERFACE; }
769 virtual BOOL saveToDatabase(DB_HANDLE hdb);
770 virtual bool deleteFromDatabase(DB_HANDLE hdb);
771 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 772
06a93345 773 Node *getParentNode();
035745fc 774 UINT32 getParentNodeId();
5039dede 775
c30c0c0f
VK
776 const InetAddressList *getIpAddressList() { return &m_ipAddressList; }
777 const InetAddress& getFirstIpAddress();
967893bb 778 UINT32 getZoneId() { return m_zoneId; }
e95680e5
VK
779 UINT32 getIfIndex() { return m_index; }
780 UINT32 getIfType() { return m_type; }
781 UINT32 getMTU() { return m_mtu; }
967893bb
VK
782 UINT32 getBridgePortNumber() { return m_bridgePortNumber; }
783 UINT32 getSlotNumber() { return m_slotNumber; }
784 UINT32 getPortNumber() { return m_portNumber; }
785 UINT32 getPeerNodeId() { return m_peerNodeId; }
786 UINT32 getPeerInterfaceId() { return m_peerInterfaceId; }
b833cbf5 787 LinkLayerProtocol getPeerDiscoveryProtocol() { return m_peerDiscoveryProtocol; }
967893bb 788 UINT32 getFlags() { return m_flags; }
1e6b68a6
VK
789 int getAdminState() { return (int)m_adminState; }
790 int getOperState() { return (int)m_operState; }
791 int getDot1xPaeAuthState() { return (int)m_dot1xPaeAuthState; }
792 int getDot1xBackendAuthState() { return (int)m_dot1xBackendAuthState; }
478d4ff4 793 const TCHAR *getDescription() { return m_description; }
e95680e5
VK
794 const TCHAR *getAlias() { return m_alias; }
795 const BYTE *getMacAddr() { return m_macAddr; }
1babf64d 796 UINT32 getPingTime();
4c16cdc7
VK
797 bool isSyntheticMask() { return (m_flags & IF_SYNTHETIC_MASK) ? true : false; }
798 bool isPhysicalPort() { return (m_flags & IF_PHYSICAL_PORT) ? true : false; }
314c4f38 799 bool isLoopback() { return (m_flags & IF_LOOPBACK) ? true : false; }
09e834a1 800 bool isManuallyCreated() { return (m_flags & IF_CREATED_MANUALLY) ? true : false; }
314c4f38 801 bool isExcludedFromTopology() { return (m_flags & (IF_EXCLUDE_FROM_TOPOLOGY | IF_LOOPBACK)) ? true : false; }
e95680e5
VK
802 bool isFake() { return (m_index == 1) &&
803 (m_type == IFTYPE_OTHER) &&
c42b4551 804 (!_tcscmp(m_name, _T("lan0")) || !_tcscmp(m_name, _T("unknown"))) &&
e95680e5 805 (!memcmp(m_macAddr, "\x00\x00\x00\x00\x00\x00", 6)); }
eec253a8 806
c42b4551 807 UINT64 getLastDownEventId() { return m_lastDownEventId; }
c59466d2 808 void setLastDownEventId(QWORD id) { m_lastDownEventId = id; }
eec253a8 809
6e0d3549 810 void setMacAddr(const BYTE *pbNewMac);
c30c0c0f 811 void setIpAddress(const InetAddress& addr);
c42b4551
VK
812 void setBridgePortNumber(UINT32 bpn) { m_bridgePortNumber = bpn; setModified(); }
813 void setSlotNumber(UINT32 slot) { m_slotNumber = slot; setModified(); }
814 void setPortNumber(UINT32 port) { m_portNumber = port; setModified(); }
815 void setPhysicalPortFlag(bool isPhysical) { if (isPhysical) m_flags |= IF_PHYSICAL_PORT; else m_flags &= ~IF_PHYSICAL_PORT; setModified(); }
816 void setManualCreationFlag(bool isManual) { if (isManual) m_flags |= IF_CREATED_MANUALLY; else m_flags &= ~IF_CREATED_MANUALLY; setModified(); }
0717a453 817 void setPeer(Node *node, Interface *iface, LinkLayerProtocol protocol, bool reflection);
644f9e7a 818 void clearPeer() { lockProperties(); m_peerNodeId = 0; m_peerInterfaceId = 0; m_peerDiscoveryProtocol = LL_PROTO_UNKNOWN; setModified(); unlockProperties(); }
c42b4551 819 void setDescription(const TCHAR *descr) { lockProperties(); nx_strncpy(m_description, descr, MAX_DB_STRING); setModified(); unlockProperties(); }
e95680e5 820 void setAlias(const TCHAR *alias) { lockProperties(); nx_strncpy(m_alias, alias, MAX_DB_STRING); setModified(); unlockProperties(); }
c30c0c0f
VK
821 void addIpAddress(const InetAddress& addr);
822 void deleteIpAddress(InetAddress addr);
823 void setNetMask(const InetAddress& addr);
33560996 824 void setMTU(int mtu) { m_mtu = mtu; setModified(); }
5039dede 825
4c789f9e
VK
826 void updateZoneId();
827
c30c0c0f 828 void statusPoll(ClientSession *session, UINT32 rqId, Queue *eventQueue, Cluster *cluster, SNMP_Transport *snmpTransport, UINT32 nodeIcmpProxy);
3f39fdc2 829
967893bb 830 UINT32 wakeUp();
707b18df 831 void setExpectedState(int state);
1babf64d 832 void updatePingData();
5039dede
AK
833};
834
2df18cce
VK
835/**
836 * Network service class
837 */
b8014eee 838class NXCORE_EXPORTABLE NetworkService : public NetObj
5039dede
AK
839{
840protected:
c59466d2
VK
841 int m_serviceType; // SSH, POP3, etc.
842 Node *m_hostNode; // Pointer to node object which hosts this service
843 UINT32 m_pollerNode; // ID of node object which is used for polling
5039dede 844 // If 0, m_pHostNode->m_dwPollerNode will be used
c42b4551
VK
845 UINT16 m_proto; // Protocol (TCP, UDP, etc.)
846 UINT16 m_port; // TCP or UDP port number
c30c0c0f 847 InetAddress m_ipAddress;
c59466d2
VK
848 TCHAR *m_request; // Service-specific request
849 TCHAR *m_response; // Service-specific expected response
850 int m_pendingStatus;
851 int m_pollCount;
852 int m_requiredPollCount;
b8014eee 853 UINT32 m_responseTime; // Response time from last poll
5039dede 854
967893bb 855 virtual void onObjectDelete(UINT32 dwObjectId);
5039dede 856
8fe90adb
VK
857 virtual void fillMessageInternal(NXCPMessage *pMsg);
858 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
859
5039dede
AK
860public:
861 NetworkService();
862 NetworkService(int iServiceType, WORD wProto, WORD wPort,
863 TCHAR *pszRequest, TCHAR *pszResponse,
967893bb 864 Node *pHostNode = NULL, UINT32 dwPollerNode = 0);
5039dede
AK
865 virtual ~NetworkService();
866
c42b4551 867 virtual int getObjectClass() { return OBJECT_NETWORKSERVICE; }
5039dede 868
c42b4551
VK
869 virtual BOOL saveToDatabase(DB_HANDLE hdb);
870 virtual bool deleteFromDatabase(DB_HANDLE hdb);
871 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 872
c59466d2 873 void statusPoll(ClientSession *session, UINT32 rqId, Node *pollerNode, Queue *eventQueue);
5039dede 874
b8014eee 875 UINT32 getResponseTime() { return m_responseTime; }
5039dede
AK
876};
877
2df18cce
VK
878/**
879 * VPN connector class
880 */
b8014eee 881class NXCORE_EXPORTABLE VPNConnector : public NetObj
5039dede
AK
882{
883protected:
967893bb 884 UINT32 m_dwPeerGateway; // Object ID of peer gateway
c75e9ee4
VK
885 ObjectArray<InetAddress> *m_localNetworks;
886 ObjectArray<InetAddress> *m_remoteNetworks;
5039dede 887
8fe90adb
VK
888 virtual void fillMessageInternal(NXCPMessage *pMsg);
889 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
890
b8014eee 891 Node *getParentNode();
5039dede
AK
892
893public:
894 VPNConnector();
01152a54 895 VPNConnector(bool hidden);
5039dede
AK
896 virtual ~VPNConnector();
897
c42b4551 898 virtual int getObjectClass() { return OBJECT_VPNCONNECTOR; }
5039dede 899
c42b4551
VK
900 virtual BOOL saveToDatabase(DB_HANDLE hdb);
901 virtual bool deleteFromDatabase(DB_HANDLE hdb);
902 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 903
c75e9ee4
VK
904 bool isLocalAddr(const InetAddress& addr);
905 bool isRemoteAddr(const InetAddress& addr);
41fb4bf0 906 UINT32 getPeerGatewayId() { return m_dwPeerGateway; }
c75e9ee4 907 InetAddress getPeerGatewayAddr();
5039dede
AK
908};
909
6fd6de0a
VK
910/**
911 * Common base class for all objects capable of collecting data
912 */
913class NXCORE_EXPORTABLE DataCollectionTarget : public Template
914{
915protected:
ebb2dc70
VK
916 UINT32 m_pingTime;
917 time_t m_pingLastTimeStamp;
918
8fe90adb 919 virtual void fillMessageInternal(NXCPMessage *pMsg);
9289a3bb 920 virtual void fillMessageInternalStage2(NXCPMessage *pMsg);
8fe90adb
VK
921 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
922
6fd6de0a 923 virtual bool isDataCollectionDisabled();
ebb2dc70 924 virtual void updatePingData();
6fd6de0a 925
b8014eee
VK
926 NetObj *objectFromParameter(const TCHAR *param);
927
6fd6de0a
VK
928public:
929 DataCollectionTarget();
930 DataCollectionTarget(const TCHAR *name);
931 virtual ~DataCollectionTarget();
932
c42b4551 933 virtual bool deleteFromDatabase(DB_HANDLE hdb);
6fd6de0a 934
f94d5259 935 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
6fd6de0a 936
17b1ab4a
VK
937 virtual UINT32 getInternalItem(const TCHAR *param, size_t bufSize, TCHAR *buffer);
938 virtual UINT32 getScriptItem(const TCHAR *param, size_t bufSize, TCHAR *buffer);
6fd6de0a 939
b368969c
VK
940 UINT32 getTableLastValues(UINT32 dciId, NXCPMessage *msg);
941 UINT32 getThresholdSummary(NXCPMessage *msg, UINT32 baseId);
942 UINT32 getPerfTabDCIList(NXCPMessage *pMsg);
2852ef09 943 void getDciValuesSummary(SummaryTable *tableDefinition, Table *tableData);
6fd6de0a
VK
944
945 void updateDciCache();
5f648670 946 void cleanDCIData(DB_HANDLE hdb);
6fd6de0a 947 void queueItemsForPolling(Queue *pPollerQueue);
e63fca40 948 bool processNewDCValue(DCObject *dco, time_t currTime, const void *value);
6fd6de0a 949
967893bb
VK
950 bool applyTemplateItem(UINT32 dwTemplateId, DCObject *dcObject);
951 void cleanDeletedTemplateItems(UINT32 dwTemplateId, UINT32 dwNumItems, UINT32 *pdwItemList);
d140955e 952 virtual void unbindFromTemplate(UINT32 dwTemplateId, bool removeDCI);
d1730ccf
VK
953
954 virtual bool isEventSource();
f94d5259 955
cd68963b 956 int getMostCriticalDCIStatus();
ebb2dc70
VK
957
958 UINT32 getPingTime();
6fd6de0a
VK
959};
960
2df18cce
VK
961/**
962 * Mobile device class
963 */
6fd6de0a 964class NXCORE_EXPORTABLE MobileDevice : public DataCollectionTarget
2df18cce
VK
965{
966protected:
967 time_t m_lastReportTime;
968 TCHAR *m_deviceId;
f22c4f7c 969 TCHAR *m_vendor;
2df18cce 970 TCHAR *m_model;
f22c4f7c
VK
971 TCHAR *m_serialNumber;
972 TCHAR *m_osName;
973 TCHAR *m_osVersion;
974 TCHAR *m_userId;
171c2fd6 975 LONG m_batteryLevel;
c30c0c0f 976 InetAddress m_ipAddress;
2df18cce 977
8fe90adb
VK
978 virtual void fillMessageInternal(NXCPMessage *pMsg);
979 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
980
2df18cce
VK
981public:
982 MobileDevice();
171c2fd6 983 MobileDevice(const TCHAR *name, const TCHAR *deviceId);
2df18cce
VK
984 virtual ~MobileDevice();
985
c42b4551 986 virtual int getObjectClass() { return OBJECT_MOBILEDEVICE; }
2df18cce 987
c42b4551
VK
988 virtual BOOL loadFromDatabase(UINT32 dwId);
989 virtual BOOL saveToDatabase(DB_HANDLE hdb);
990 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2df18cce 991
26e2b253
VK
992 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
993
b368969c
VK
994 void updateSystemInfo(NXCPMessage *msg);
995 void updateStatus(NXCPMessage *msg);
6583a0f8 996
534e1b83 997 const TCHAR *getDeviceId() { return CHECK_NULL_EX(m_deviceId); }
eb0c0312 998
17b1ab4a 999 virtual UINT32 getInternalItem(const TCHAR *param, size_t bufSize, TCHAR *buffer);
2df18cce
VK
1000};
1001
8715a84c
VK
1002/**
1003 * Access point class
1004 */
1005class NXCORE_EXPORTABLE AccessPoint : public DataCollectionTarget
1006{
1007protected:
ac58ffe9 1008 UINT32 m_index;
c30c0c0f 1009 InetAddress m_ipAddress;
967893bb 1010 UINT32 m_nodeId;
8715a84c
VK
1011 BYTE m_macAddr[MAC_ADDR_LENGTH];
1012 TCHAR *m_vendor;
1013 TCHAR *m_model;
1014 TCHAR *m_serialNumber;
d5de1d1d 1015 ObjectArray<RadioInterfaceInfo> *m_radioInterfaces;
23ed00c4 1016 AccessPointState m_state;
9933e1d4 1017 AccessPointState m_prevState;
8715a84c 1018
8fe90adb
VK
1019 virtual void fillMessageInternal(NXCPMessage *pMsg);
1020 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1021
ebb2dc70
VK
1022 virtual void updatePingData();
1023
8715a84c
VK
1024public:
1025 AccessPoint();
ac58ffe9 1026 AccessPoint(const TCHAR *name, UINT32 index, const BYTE *macAddr);
8715a84c
VK
1027 virtual ~AccessPoint();
1028
c42b4551 1029 virtual int getObjectClass() { return OBJECT_ACCESSPOINT; }
8715a84c 1030
c42b4551
VK
1031 virtual BOOL loadFromDatabase(UINT32 dwId);
1032 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1033 virtual bool deleteFromDatabase(DB_HANDLE hdb);
8715a84c 1034
ac58ffe9 1035 void statusPoll(ClientSession *session, UINT32 rqId, Queue *eventQueue, Node *controller, SNMP_Transport *snmpTransport);
56d5289b 1036
ac58ffe9
VK
1037 UINT32 getIndex() { return m_index; }
1038 const BYTE *getMacAddr() { return m_macAddr; }
c30c0c0f 1039 const InetAddress& getIpAddress() { return m_ipAddress; }
f1989a3a 1040 bool isMyRadio(int rfIndex);
386f88e3 1041 bool isMyRadio(const BYTE *macAddr);
f1989a3a 1042 void getRadioName(int rfIndex, TCHAR *buffer, size_t bufSize);
23ed00c4 1043 AccessPointState getState() { return m_state; }
75ebb063 1044 Node *getParentNode();
8715a84c 1045
967893bb 1046 void attachToNode(UINT32 nodeId);
c30c0c0f 1047 void setIpAddress(const InetAddress& addr) { lockProperties(); m_ipAddress = addr; setModified(); unlockProperties(); }
ac58ffe9 1048 void updateRadioInterfaces(const ObjectArray<RadioInterfaceInfo> *ri);
f1989a3a 1049 void updateInfo(const TCHAR *vendor, const TCHAR *model, const TCHAR *serialNumber);
23ed00c4 1050 void updateState(AccessPointState state);
8715a84c
VK
1051};
1052
7de1151b
VK
1053/**
1054 * Cluster class
1055 */
1056class NXCORE_EXPORTABLE Cluster : public DataCollectionTarget
1057{
1058protected:
967893bb 1059 UINT32 m_dwClusterType;
c75e9ee4 1060 ObjectArray<InetAddress> *m_syncNetworks;
967893bb 1061 UINT32 m_dwNumResources;
7de1151b 1062 CLUSTER_RESOURCE *m_pResourceList;
967893bb 1063 UINT32 m_dwFlags;
7de1151b 1064 time_t m_tmLastPoll;
967893bb 1065 UINT32 m_zoneId;
7de1151b 1066
8fe90adb
VK
1067 virtual void fillMessageInternal(NXCPMessage *pMsg);
1068 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1069
7de1151b
VK
1070public:
1071 Cluster();
967893bb 1072 Cluster(const TCHAR *pszName, UINT32 zoneId);
7de1151b
VK
1073 virtual ~Cluster();
1074
c42b4551
VK
1075 virtual int getObjectClass() { return OBJECT_CLUSTER; }
1076 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1077 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1078 virtual BOOL loadFromDatabase(UINT32 dwId);
7de1151b 1079
d140955e 1080 virtual void unbindFromTemplate(UINT32 dwTemplateId, bool removeDCI);
0c97b51c 1081
c75e9ee4
VK
1082 bool isSyncAddr(const InetAddress& addr);
1083 bool isVirtualAddr(const InetAddress& addr);
967893bb
VK
1084 bool isResourceOnNode(UINT32 dwResource, UINT32 dwNode);
1085 UINT32 getZoneId() { return m_zoneId; }
7de1151b 1086
208d7427
VK
1087 void statusPoll(PollerInfo *poller);
1088 void statusPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
7de1151b 1089 void lockForStatusPoll() { m_dwFlags |= CLF_QUEUED_FOR_STATUS_POLL; }
3f39fdc2 1090 bool isReadyForStatusPoll()
7de1151b 1091 {
01152a54 1092 return ((m_iStatus != STATUS_UNMANAGED) && (!m_isDeleted) &&
7de1151b 1093 (!(m_dwFlags & CLF_QUEUED_FOR_STATUS_POLL)) &&
967893bb 1094 ((UINT32)time(NULL) - (UINT32)m_tmLastPoll > g_dwStatusPollingInterval))
7de1151b
VK
1095 ? true : false;
1096 }
85ae39bc 1097
967893bb 1098 UINT32 collectAggregatedData(DCItem *item, TCHAR *buffer);
a0ddfb29 1099 UINT32 collectAggregatedData(DCTable *table, Table **result);
7de1151b
VK
1100};
1101
a85fa05e 1102class Subnet;
296ae03d 1103struct SnmpProxyInfo;
a85fa05e 1104
84880c89
VK
1105/**
1106 * Node
1107 */
6fd6de0a 1108class NXCORE_EXPORTABLE Node : public DataCollectionTarget
5039dede 1109{
84880c89
VK
1110 friend class Subnet;
1111
e20d1c43
VK
1112private:
1113 void onSnmpProxyChange(UINT32 oldProxy);
1114
9f52bab4
VK
1115 static void onDataCollectionChangeAsyncCallback(void *);
1116
5039dede 1117protected:
c30c0c0f 1118 InetAddress m_ipAddress;
5ad2167d 1119 TCHAR m_primaryName[MAX_DNS_NAME];
967893bb
VK
1120 UINT32 m_dwFlags;
1121 UINT32 m_dwDynamicFlags; // Flags used at runtime by server
5039dede
AK
1122 int m_iPendingStatus;
1123 int m_iPollCount;
1124 int m_iRequiredPollCount;
967893bb 1125 UINT32 m_zoneId;
c42b4551 1126 UINT16 m_agentPort;
9708eff4
VK
1127 INT16 m_agentAuthMethod;
1128 INT16 m_agentCacheMode;
35f836fe 1129 TCHAR m_szSharedSecret[MAX_SECRET_LENGTH];
9708eff4
VK
1130 INT16 m_iStatusPollType;
1131 INT16 m_snmpVersion;
296ae03d 1132 UINT16 m_snmpPort;
9708eff4 1133 UINT16 m_nUseIfXTable;
5d2c5741 1134 SNMP_SecurityContext *m_snmpSecurity;
35f836fe
VK
1135 TCHAR m_szObjectId[MAX_OID_LEN * 4];
1136 TCHAR m_szAgentVersion[MAX_AGENT_VERSION_LEN];
1137 TCHAR m_szPlatformName[MAX_PLATFORM_NAME_LEN];
0ecc2200
VK
1138 TCHAR *m_sysDescription; // Agent's System.Uname or SNMP sysDescr
1139 TCHAR *m_sysName; // SNMP sysName
1140 TCHAR *m_lldpNodeId; // lldpLocChassisId combined with lldpLocChassisIdSubtype, or NULL for non-LLDP nodes
3a82d5ae 1141 ObjectArray<LLDP_LOCAL_PORT_INFO> *m_lldpLocalPortInfo;
9796ce45 1142 NetworkDeviceDriver *m_driver;
225b92bc 1143 DriverData *m_driverData;
86c126f5
VK
1144 ObjectArray<AgentParameterDefinition> *m_paramList; // List of supported parameters
1145 ObjectArray<AgentTableDefinition> *m_tableList; // List of supported tables
8573e935
VK
1146 time_t m_lastDiscoveryPoll;
1147 time_t m_lastStatusPoll;
1148 time_t m_lastConfigurationPoll;
805171de 1149 time_t m_lastInstancePoll;
8573e935
VK
1150 time_t m_lastTopologyPoll;
1151 time_t m_lastRTUpdate;
1152 time_t m_failTimeSNMP;
1153 time_t m_failTimeAgent;
1154 time_t m_downSince;
71e4ed3a 1155 time_t m_bootTime;
0ab347c0 1156 time_t m_agentUpTime;
5039dede
AK
1157 MUTEX m_hPollerMutex;
1158 MUTEX m_hAgentAccessMutex;
1d0d82b3 1159 MUTEX m_hSmclpAccessMutex;
5039dede
AK
1160 MUTEX m_mutexRTAccess;
1161 MUTEX m_mutexTopoAccess;
1162 AgentConnectionEx *m_pAgentConnection;
1d0d82b3 1163 SMCLP_Connection *m_smclpConnection;
42a3be4f
VK
1164 QWORD m_lastAgentTrapId; // ID of last received agent trap
1165 QWORD m_lastAgentPushRequestId; // ID of last received agent push request
489b117b 1166 UINT32 m_lastSNMPTrapId;
9208c84b
VK
1167 UINT32 m_pollerNode; // Node used for network service polling
1168 UINT32 m_agentProxy; // Node used as proxy for agent connection
1169 UINT32 m_snmpProxy; // Node used as proxy for SNMP requests
1170 UINT32 m_icmpProxy; // Node used as proxy for ICMP ping
9708eff4 1171 UINT64 m_qwLastEvents[MAX_LAST_EVENTS];
5039dede 1172 ROUTING_TABLE *m_pRoutingTable;
630e15d6 1173 ForwardingDatabase *m_fdb;
040c45fa 1174 LinkLayerNeighbors *m_linkLayerNeighbors;
7f632dfe 1175 VlanList *m_vlans;
0d75ea88 1176 VrrpInfo *m_vrrpInfo;
d5de1d1d 1177 ObjectArray<WirelessStationInfo> *m_wirelessStations;
f1989a3a
VK
1178 int m_adoptedApCount;
1179 int m_totalApCount;
3eab63f2 1180 BYTE m_baseBridgeAddress[MAC_ADDR_LENGTH]; // Bridge base address (dot1dBaseBridgeAddress in bridge MIB)
d5de1d1d 1181 nxmap_ObjList *m_pTopology;
040c45fa 1182 time_t m_topologyRebuildTimestamp;
ab621f39 1183 ServerJobQueue *m_jobQueue;
8836184f 1184 ComponentTree *m_components; // Hardware components
caa04e26 1185 ObjectArray<SoftwarePackage> *m_softwarePackages; // installed software packages
46ee6286 1186 ObjectArray<WinPerfObject> *m_winPerfObjects; // Windows performance objects
5039dede 1187
c17f6cbc 1188 void pollerLock() { MutexLock(m_hPollerMutex); }
7c521895 1189 void pollerUnlock() { MutexUnlock(m_hPollerMutex); }
5039dede 1190
c17f6cbc 1191 void agentLock() { MutexLock(m_hAgentAccessMutex); }
7c521895 1192 void agentUnlock() { MutexUnlock(m_hAgentAccessMutex); }
5039dede 1193
1d0d82b3
VK
1194 void smclpLock() { MutexLock(m_hSmclpAccessMutex); }
1195 void smclpUnlock() { MutexUnlock(m_hSmclpAccessMutex); }
1196
c17f6cbc 1197 void routingTableLock() { MutexLock(m_mutexRTAccess); }
7c521895 1198 void routingTableUnlock() { MutexUnlock(m_mutexRTAccess); }
5039dede 1199
074498ac
VK
1200 BOOL checkSNMPIntegerValue(SNMP_Transport *pTransport, const TCHAR *pszOID, int nValue);
1201 void checkOSPFSupport(SNMP_Transport *pTransport);
98762401 1202 void addVrrpInterfaces(InterfaceList *ifList);
024c3faf 1203 BOOL resolveName(BOOL useOnlyDNS);
7c521895 1204 void setAgentProxy(AgentConnection *pConn);
c75e9ee4 1205 void setPrimaryIPAddress(const InetAddress& addr);
5039dede 1206
967893bb 1207 UINT32 getInterfaceCount(Interface **ppInterface);
5039dede 1208
024c3faf 1209 void checkInterfaceNames(InterfaceList *pIfList);
c75e9ee4 1210 Subnet *createSubnet(const InetAddress& baseAddr, bool syntheticMask);
1f385e47 1211 void checkAgentPolicyBinding(AgentConnection *conn);
5a7d6a10 1212 void updatePrimaryIpAddr();
967893bb
VK
1213 bool confPollAgent(UINT32 dwRqId);
1214 bool confPollSnmp(UINT32 dwRqId);
76720a09
VK
1215 void checkBridgeMib(SNMP_Transport *pTransport);
1216 void checkIfXTable(SNMP_Transport *pTransport);
1824629a 1217 void executeHookScript(const TCHAR *hookName);
967893bb
VK
1218 bool checkNetworkPath(UINT32 dwRqId);
1219 bool checkNetworkPathElement(UINT32 nodeId, const TCHAR *nodeType, bool isProxy, UINT32 dwRqId);
5039dede 1220
6fd6de0a 1221 void applyUserTemplates();
f7e3eb5a 1222 void doInstanceDiscovery(UINT32 requestId);
a6312bd6 1223 StringMap *getInstanceList(DCItem *dci);
f7e3eb5a 1224 void updateInstances(DCItem *root, StringMap *instances, UINT32 requestId);
4262c0dc 1225
e9902466 1226 void syncDataCollectionWithAgent(AgentConnectionEx *conn);
296ae03d
VK
1227 void collectSnmpProxyInfo(SnmpProxyInfo *info);
1228 static void collectSNMPProxyInfoCallback(NetObj *node, void *data);
e9902466 1229
7c521895 1230 void updateContainerMembership();
dfed892b
VK
1231 bool updateInterfaceConfiguration(UINT32 rqid, int maskBits);
1232 bool deleteDuplicateInterfaces(UINT32 rqid);
4262c0dc 1233
41fb4bf0 1234 void buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedObject, bool vpnLink, bool includeEndNodes);
84880c89 1235
6fd6de0a
VK
1236 virtual bool isDataCollectionDisabled();
1237
22ee6d97 1238 virtual void prepareForDeletion();
967893bb 1239 virtual void onObjectDelete(UINT32 dwObjectId);
5039dede 1240
8fe90adb
VK
1241 virtual void fillMessageInternal(NXCPMessage *pMsg);
1242 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1243
ebb2dc70
VK
1244 virtual void updatePingData();
1245
9fd816cc
VK
1246 virtual void onDataCollectionChange();
1247
5039dede
AK
1248public:
1249 Node();
c75e9ee4 1250 Node(const InetAddress& addr, UINT32 dwFlags, UINT32 agentProxy, UINT32 snmpProxy, UINT32 dwZone);
5039dede
AK
1251 virtual ~Node();
1252
c42b4551 1253 virtual int getObjectClass() { return OBJECT_NODE; }
a723ea42 1254 UINT32 getIcmpProxy() { return m_icmpProxy; }
5039dede 1255
c42b4551
VK
1256 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1257 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1258 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 1259
ca0e18d2 1260 TCHAR *expandText(const TCHAR *textTemplate);
6e388680 1261
7c521895 1262 Cluster *getMyCluster();
5039dede 1263
c30c0c0f 1264 const InetAddress& getIpAddress() { return m_ipAddress; }
70d50eb1 1265 UINT32 getZoneId() { return m_zoneId; }
967893bb
VK
1266 UINT32 getFlags() { return m_dwFlags; }
1267 UINT32 getRuntimeFlags() { return m_dwDynamicFlags; }
c42b4551
VK
1268 void setFlag(UINT32 flag) { lockProperties(); m_dwFlags |= flag; setModified(); unlockProperties(); }
1269 void clearFlag(UINT32 flag) { lockProperties(); m_dwFlags &= ~flag; setModified(); unlockProperties(); }
7c521895
VK
1270 void setLocalMgmtFlag() { m_dwFlags |= NF_IS_LOCAL_MGMT; }
1271 void clearLocalMgmtFlag() { m_dwFlags &= ~NF_IS_LOCAL_MGMT; }
5039dede 1272
eec253a8
VK
1273 bool isSNMPSupported() { return m_dwFlags & NF_IS_SNMP ? true : false; }
1274 bool isNativeAgent() { return m_dwFlags & NF_IS_NATIVE_AGENT ? true : false; }
1275 bool isBridge() { return m_dwFlags & NF_IS_BRIDGE ? true : false; }
1276 bool isRouter() { return m_dwFlags & NF_IS_ROUTER ? true : false; }
1277 bool isLocalManagement() { return m_dwFlags & NF_IS_LOCAL_MGMT ? true : false; }
072e4643 1278 bool isPerVlanFdbSupported() { return (m_driver != NULL) ? m_driver->isPerVlanFdbSupported() : false; }
d5de1d1d 1279 bool isWirelessController() { return m_dwFlags & NF_IS_WIFI_CONTROLLER ? true : false; }
5039dede 1280
7c521895
VK
1281 LONG getSNMPVersion() { return m_snmpVersion; }
1282 const TCHAR *getSNMPObjectId() { return m_szObjectId; }
1283 const TCHAR *getAgentVersion() { return m_szAgentVersion; }
1284 const TCHAR *getPlatformName() { return m_szPlatformName; }
0ecc2200
VK
1285 const TCHAR *getObjectId() { return m_szObjectId; }
1286 const TCHAR *getSysName() { return CHECK_NULL_EX(m_sysName); }
ff0b91fd 1287 const TCHAR *getSysDescription() { return CHECK_NULL_EX(m_sysDescription); }
71e4ed3a 1288 time_t getBootTime() { return m_bootTime; }
0ecc2200 1289 const TCHAR *getLLDPNodeId() { return m_lldpNodeId; }
4005181b 1290 const BYTE *getBridgeId() { return m_baseBridgeAddress; }
8f3acc9b 1291 const TCHAR *getDriverName() { return (m_driver != NULL) ? m_driver->getName() : _T("GENERIC"); }
9708eff4
VK
1292 UINT16 getAgentPort() { return m_agentPort; }
1293 INT16 getAgentAuthMethod() { return m_agentAuthMethod; }
1294 INT16 getAgentCacheMode() { return (m_agentCacheMode == AGENT_CACHE_DEFAULT) ? g_defaultAgentCacheMode : m_agentCacheMode; }
5db0d494 1295 const TCHAR *getSharedSecret() { return m_szSharedSecret; }
5039dede 1296
0717a453 1297 bool isDown() { return (m_dwDynamicFlags & NDF_UNREACHABLE) ? true : false; }
8573e935 1298 time_t getDownTime() const { return m_downSince; }
5039dede 1299
eec253a8 1300 void addInterface(Interface *pInterface) { AddChild(pInterface); pInterface->AddParent(this); }
c30c0c0f 1301 Interface *createNewInterface(InterfaceInfo *ifInfo, bool manuallyCreated);
bf2ad753 1302 Interface *createNewInterface(const InetAddress& ipAddr, BYTE *macAddr);
c30c0c0f 1303 void deleteInterface(Interface *iface);
5039dede 1304
5a7d6a10 1305 void setPrimaryName(const TCHAR *name) { nx_strncpy(m_primaryName, name, MAX_DNS_NAME); }
c42b4551 1306 void setAgentPort(WORD port) { m_agentPort = port; }
296ae03d 1307 void setSnmpPort(WORD port) { m_snmpPort = port; }
c75e9ee4 1308 void changeIPAddress(const InetAddress& ipAddr);
967893bb 1309 void changeZone(UINT32 newZone);
5039dede 1310
7c521895 1311 ARP_CACHE *getArpCache();
98762401 1312 InterfaceList *getInterfaceList();
c75e9ee4
VK
1313 Interface *findInterfaceByIndex(UINT32 ifIndex);
1314 Interface *findInterfaceByName(const TCHAR *name);
eec253a8 1315 Interface *findInterfaceByMAC(const BYTE *macAddr);
c75e9ee4 1316 Interface *findInterfaceByIP(const InetAddress& addr);
967893bb
VK
1317 Interface *findInterfaceBySlotAndPort(UINT32 slot, UINT32 port);
1318 Interface *findBridgePort(UINT32 bridgePortNumber);
8f26db67 1319 AccessPoint *findAccessPointByMAC(const BYTE *macAddr);
386f88e3 1320 AccessPoint *findAccessPointByBSSID(const BYTE *bssid);
8f26db67 1321 AccessPoint *findAccessPointByRadioId(int rfIndex);
75ebb063 1322 ObjectArray<WirelessStationInfo> *getWirelessStations();
c75e9ee4 1323 bool isMyIP(const InetAddress& addr);
42c6d15b
VK
1324 void getInterfaceStatusFromSNMP(SNMP_Transport *pTransport, UINT32 dwIndex, InterfaceAdminState *adminState, InterfaceOperState *operState);
1325 void getInterfaceStatusFromAgent(UINT32 dwIndex, InterfaceAdminState *adminState, InterfaceOperState *operState);
58b3e451
VK
1326 ROUTING_TABLE *getRoutingTable();
1327 ROUTING_TABLE *getCachedRoutingTable() { return m_pRoutingTable; }
a9ad9f61 1328 LinkLayerNeighbors *getLinkLayerNeighbors();
7f632dfe 1329 VlanList *getVlans();
c75e9ee4
VK
1330 bool getNextHop(const InetAddress& srcAddr, const InetAddress& destAddr, InetAddress *nextHop, UINT32 *ifIndex, bool *isVpn, TCHAR *name);
1331 bool getOutwardInterface(const InetAddress& destAddr, InetAddress *srcAddr, UINT32 *srcIfIndex);
8836184f 1332 ComponentTree *getComponents();
71ea7674 1333 bool getLldpLocalPortInfo(BYTE *id, size_t idLen, LLDP_LOCAL_PORT_INFO *port);
5039dede 1334
58b3e451 1335 void setRecheckCapsFlag() { m_dwDynamicFlags |= NDF_RECHECK_CAPABILITIES; }
7c521895 1336 void setDiscoveryPollTimeStamp();
208d7427
VK
1337 void statusPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
1338 void statusPoll(PollerInfo *poller);
1339 void configurationPoll(PollerInfo *poller);
1340 void configurationPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller, int maskBits);
1341 void instanceDiscoveryPoll(PollerInfo *poller);
1342 void instanceDiscoveryPoll(ClientSession *session, UINT32 requestId, PollerInfo *poller);
1343 void topologyPoll(PollerInfo *poller);
1344 void topologyPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
b1bd1fb2 1345 void resolveVlanPorts(VlanList *vlanList);
967893bb 1346 void updateInterfaceNames(ClientSession *pSession, UINT32 dwRqId);
208d7427 1347 void routingTablePoll(PollerInfo *poller);
58b3e451 1348 void updateRoutingTable();
c30c0c0f 1349 void checkSubnetBinding();
ac58ffe9 1350 AccessPointState getAccessPointState(AccessPoint *ap, SNMP_Transport *snmpTransport);
72e97d1c 1351
7c521895
VK
1352 bool isReadyForStatusPoll();
1353 bool isReadyForConfigurationPoll();
805171de 1354 bool isReadyForInstancePoll();
7c521895
VK
1355 bool isReadyForDiscoveryPoll();
1356 bool isReadyForRoutePoll();
040c45fa 1357 bool isReadyForTopologyPoll();
0ab347c0 1358
7c521895
VK
1359 void lockForStatusPoll();
1360 void lockForConfigurationPoll();
805171de 1361 void lockForInstancePoll();
7c521895
VK
1362 void lockForDiscoveryPoll();
1363 void lockForRoutePoll();
040c45fa 1364 void lockForTopologyPoll();
7c521895 1365 void forceConfigurationPoll() { m_dwDynamicFlags |= NDF_FORCE_CONFIGURATION_POLL; }
5039dede 1366
27f9598d 1367 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
5039dede 1368
9fd816cc 1369 bool connectToAgent(UINT32 *error = NULL, UINT32 *socketError = NULL, bool *newConnection = NULL);
6fbaa926 1370 bool checkAgentTrapId(UINT64 id);
489b117b 1371 bool checkSNMPTrapId(UINT32 id);
6fbaa926 1372 bool checkAgentPushRequestId(UINT64 id);
6fd6de0a 1373
1d0d82b3
VK
1374 bool connectToSMCLP();
1375
17b1ab4a
VK
1376 virtual UINT32 getInternalItem(const TCHAR *param, size_t bufSize, TCHAR *buffer);
1377
1378 UINT32 getItemFromSNMP(WORD port, const TCHAR *param, size_t bufSize, TCHAR *buffer, int interpretRawValue);
db117859 1379 UINT32 getTableFromSNMP(WORD port, const TCHAR *oid, ObjectArray<DCTableColumn> *columns, Table **table);
967893bb 1380 UINT32 getListFromSNMP(WORD port, const TCHAR *oid, StringList **list);
69a4eaa6 1381 UINT32 getOIDSuffixListFromSNMP(WORD port, const TCHAR *oid, StringMap **values);
967893bb
VK
1382 UINT32 getItemFromCheckPointSNMP(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
1383 UINT32 getItemFromAgent(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
1384 UINT32 getTableFromAgent(const TCHAR *name, Table **table);
1385 UINT32 getListFromAgent(const TCHAR *name, StringList **list);
1386 UINT32 getItemForClient(int iOrigin, const TCHAR *pszParam, TCHAR *pszBuffer, UINT32 dwBufSize);
1387 UINT32 getTableForClient(const TCHAR *name, Table **table);
1388 UINT32 getItemFromSMCLP(const TCHAR *param, UINT32 bufSize, TCHAR *buffer);
6fd6de0a 1389
06c104c6 1390 virtual NXSL_Array *getParentsForNXSL();
0ae82278 1391 virtual NXSL_Array *getTemplatesForNXSL();
6adc4a1a 1392 NXSL_Array *getInterfacesForNXSL();
5039dede 1393
86c126f5 1394 void openParamList(ObjectArray<AgentParameterDefinition> **paramList);
c42b4551 1395 void closeParamList() { unlockProperties(); }
5039dede 1396
86c126f5 1397 void openTableList(ObjectArray<AgentTableDefinition> **tableList);
c42b4551 1398 void closeTableList() { unlockProperties(); }
074498ac 1399
cd9f247e 1400 AgentConnectionEx *createAgentConnection();
072e4643 1401 SNMP_Transport *createSnmpTransport(WORD port = 0, const TCHAR *context = NULL);
cd9f247e 1402 SNMP_SecurityContext *getSnmpSecurityContext();
e262f615 1403 UINT32 getEffectiveSnmpProxy();
5039dede 1404
b368969c
VK
1405 void writeParamListToMessage(NXCPMessage *pMsg, WORD flags);
1406 void writeWinPerfObjectsToMessage(NXCPMessage *msg);
1407 void writePackageListToMessage(NXCPMessage *msg);
1408 void writeWsListToMessage(NXCPMessage *msg);
5039dede 1409
967893bb 1410 UINT32 wakeUp();
5039dede 1411
84880c89 1412 void addService(NetworkService *pNetSrv) { AddChild(pNetSrv); pNetSrv->AddParent(this); }
c75e9ee4 1413 UINT32 checkNetworkService(UINT32 *pdwStatus, const InetAddress& ipAddr, int iServiceType, WORD wPort = 0,
b8014eee 1414 WORD wProto = 0, TCHAR *pszRequest = NULL, TCHAR *pszResponse = NULL, UINT32 *responseTime = NULL);
5039dede 1415
84880c89
VK
1416 QWORD getLastEventId(int nIndex) { return ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) ? m_qwLastEvents[nIndex] : 0; }
1417 void setLastEventId(int nIndex, QWORD qwId) { if ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) m_qwLastEvents[nIndex] = qwId; }
5039dede 1418
3f39fdc2 1419 UINT32 callSnmpEnumerate(const TCHAR *pszRootOid,
967893bb 1420 UINT32 (* pHandler)(UINT32, SNMP_Variable *, SNMP_Transport *, void *), void *pArg, const TCHAR *context = NULL);
5039dede 1421
84880c89 1422 nxmap_ObjList *getL2Topology();
967893bb 1423 nxmap_ObjList *buildL2Topology(UINT32 *pdwStatus, int radius, bool includeEndNodes);
630e15d6 1424 ForwardingDatabase *getSwitchForwardingDatabase();
75ebb063 1425 NetObj *findConnectionPoint(UINT32 *localIfId, BYTE *localMacAddr, int *type);
33ae8896 1426 void addHostConnections(LinkLayerNeighbors *nbs);
0003c4ba 1427 void addExistingConnections(LinkLayerNeighbors *nbs);
ab621f39 1428
967893bb 1429 nxmap_ObjList *buildIPTopology(UINT32 *pdwStatus, int radius, bool includeEndNodes);
84880c89 1430
ab621f39 1431 ServerJobQueue *getJobQueue() { return m_jobQueue; }
0ff10010 1432 int getJobCount(const TCHAR *type = NULL) { return m_jobQueue->getJobCount(type); }
5039dede 1433
225b92bc
VK
1434 DriverData *getDriverData() { return m_driverData; }
1435 void setDriverData(DriverData *data) { m_driverData = data; }
6a665011 1436};
5039dede 1437
6a665011
VK
1438/**
1439 * Set timestamp of last discovery poll to current time
1440 */
7c521895 1441inline void Node::setDiscoveryPollTimeStamp()
5039dede 1442{
8573e935 1443 m_lastDiscoveryPoll = time(NULL);
5039dede
AK
1444 m_dwDynamicFlags &= ~NDF_QUEUED_FOR_DISCOVERY_POLL;
1445}
1446
3f39fdc2 1447inline bool Node::isReadyForStatusPoll()
5039dede 1448{
01152a54 1449 if (m_isDeleted)
7c521895 1450 return false;
5039dede
AK
1451 if (m_dwDynamicFlags & NDF_FORCE_STATUS_POLL)
1452 {
1453 m_dwDynamicFlags &= ~NDF_FORCE_STATUS_POLL;
7c521895 1454 return true;
5039dede 1455 }
7c521895
VK
1456 return (m_iStatus != STATUS_UNMANAGED) &&
1457 (!(m_dwFlags & NF_DISABLE_STATUS_POLL)) &&
1458 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_STATUS_POLL)) &&
1459 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1460 (getMyCluster() == NULL) &&
805171de 1461 ((UINT32)(time(NULL) - m_lastStatusPoll) > g_dwStatusPollingInterval);
5039dede
AK
1462}
1463
3f39fdc2 1464inline bool Node::isReadyForConfigurationPoll()
1465{
01152a54 1466 if (m_isDeleted)
7c521895 1467 return false;
5039dede
AK
1468 if (m_dwDynamicFlags & NDF_FORCE_CONFIGURATION_POLL)
1469 {
1470 m_dwDynamicFlags &= ~NDF_FORCE_CONFIGURATION_POLL;
7c521895 1471 return true;
5039dede 1472 }
7c521895
VK
1473 return (m_iStatus != STATUS_UNMANAGED) &&
1474 (!(m_dwFlags & NF_DISABLE_CONF_POLL)) &&
1475 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_CONFIG_POLL)) &&
1476 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
805171de 1477 ((UINT32)(time(NULL) - m_lastConfigurationPoll) > g_dwConfigurationPollingInterval);
5039dede
AK
1478}
1479
3f39fdc2 1480inline bool Node::isReadyForDiscoveryPoll()
1481{
01152a54 1482 if (m_isDeleted)
7c521895 1483 return false;
c8076b19 1484 return (g_flags & AF_ENABLE_NETWORK_DISCOVERY) &&
7c521895 1485 (m_iStatus != STATUS_UNMANAGED) &&
5049e942 1486 (!(m_dwFlags & NF_DISABLE_DISCOVERY_POLL)) &&
7c521895
VK
1487 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_DISCOVERY_POLL)) &&
1488 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1489 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
805171de 1490 ((UINT32)(time(NULL) - m_lastDiscoveryPoll) > g_dwDiscoveryPollingInterval);
5039dede
AK
1491}
1492
3f39fdc2 1493inline bool Node::isReadyForRoutePoll()
1494{
01152a54 1495 if (m_isDeleted)
7c521895
VK
1496 return false;
1497 return (m_iStatus != STATUS_UNMANAGED) &&
1498 (!(m_dwFlags & NF_DISABLE_ROUTE_POLL)) &&
1499 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_ROUTE_POLL)) &&
1500 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
b6ead716 1501 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
805171de 1502 ((UINT32)(time(NULL) - m_lastRTUpdate) > g_dwRoutingTableUpdateInterval);
5039dede
AK
1503}
1504
3f39fdc2 1505inline bool Node::isReadyForTopologyPoll()
1506{
01152a54 1507 if (m_isDeleted)
040c45fa
VK
1508 return false;
1509 return (m_iStatus != STATUS_UNMANAGED) &&
1510 (!(m_dwFlags & NF_DISABLE_TOPOLOGY_POLL)) &&
1511 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_TOPOLOGY_POLL)) &&
1512 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
b6ead716 1513 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
805171de
VK
1514 ((UINT32)(time(NULL) - m_lastTopologyPoll) > g_dwTopologyPollingInterval);
1515}
1516
1517inline bool Node::isReadyForInstancePoll()
1518{
1519 if (m_isDeleted)
1520 return false;
1521 return (m_iStatus != STATUS_UNMANAGED) &&
1522 (!(m_dwFlags & NF_DISABLE_CONF_POLL)) &&
1523 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_INSTANCE_POLL)) &&
1524 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1525 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1526 ((UINT32)(time(NULL) - m_lastInstancePoll) > g_instancePollingInterval);
040c45fa
VK
1527}
1528
7c521895 1529inline void Node::lockForStatusPoll()
3f39fdc2 1530{
c42b4551 1531 lockProperties();
3f39fdc2 1532 m_dwDynamicFlags |= NDF_QUEUED_FOR_STATUS_POLL;
c42b4551 1533 unlockProperties();
5039dede
AK
1534}
1535
3f39fdc2 1536inline void Node::lockForConfigurationPoll()
1537{
c42b4551 1538 lockProperties();
3f39fdc2 1539 m_dwDynamicFlags |= NDF_QUEUED_FOR_CONFIG_POLL;
c42b4551 1540 unlockProperties();
5039dede
AK
1541}
1542
805171de
VK
1543inline void Node::lockForInstancePoll()
1544{
1545 lockProperties();
1546 m_dwDynamicFlags |= NDF_QUEUED_FOR_INSTANCE_POLL;
1547 unlockProperties();
1548}
1549
3f39fdc2 1550inline void Node::lockForDiscoveryPoll()
1551{
c42b4551 1552 lockProperties();
3f39fdc2 1553 m_dwDynamicFlags |= NDF_QUEUED_FOR_DISCOVERY_POLL;
c42b4551 1554 unlockProperties();
5039dede
AK
1555}
1556
3f39fdc2 1557inline void Node::lockForTopologyPoll()
1558{
c42b4551 1559 lockProperties();
3f39fdc2 1560 m_dwDynamicFlags |= NDF_QUEUED_FOR_TOPOLOGY_POLL;
c42b4551 1561 unlockProperties();
040c45fa
VK
1562}
1563
3f39fdc2 1564inline void Node::lockForRoutePoll()
1565{
c42b4551 1566 lockProperties();
3f39fdc2 1567 m_dwDynamicFlags |= NDF_QUEUED_FOR_ROUTE_POLL;
c42b4551 1568 unlockProperties();
5039dede
AK
1569}
1570
84880c89
VK
1571/**
1572 * Subnet
1573 */
5039dede
AK
1574class NXCORE_EXPORTABLE Subnet : public NetObj
1575{
41fb4bf0 1576 friend void Node::buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedSubnet, bool vpnLink, bool includeEndNodes);
84880c89 1577
5039dede 1578protected:
c30c0c0f 1579 InetAddress m_ipAddress;
967893bb 1580 UINT32 m_zoneId;
eec253a8 1581 bool m_bSyntheticMask;
5039dede 1582
ce47611c
VK
1583 virtual void prepareForDeletion();
1584
8fe90adb
VK
1585 virtual void fillMessageInternal(NXCPMessage *pMsg);
1586
ce47611c 1587 void buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedNode, bool includeEndNodes);
84880c89 1588
5039dede
AK
1589public:
1590 Subnet();
c75e9ee4 1591 Subnet(const InetAddress& addr, UINT32 dwZone, bool bSyntheticMask);
5039dede
AK
1592 virtual ~Subnet();
1593
c42b4551 1594 virtual int getObjectClass() { return OBJECT_SUBNET; }
5039dede 1595
c42b4551
VK
1596 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1597 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1598 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 1599
c75e9ee4 1600 void addNode(Node *node) { AddChild(node); node->AddParent(this); calculateCompoundStatus(TRUE); }
5039dede 1601
27bbb906
VK
1602 virtual bool showThresholdSummary();
1603
c30c0c0f 1604 const InetAddress& getIpAddress() { return m_ipAddress; }
967893bb 1605 UINT32 getZoneId() { return m_zoneId; }
eec253a8 1606 bool isSyntheticMask() { return m_bSyntheticMask; }
5039dede 1607
c75e9ee4 1608 void setCorrectMask(const InetAddress& addr);
80e0db05 1609
c75e9ee4 1610 bool findMacAddress(const InetAddress& ipAddr, BYTE *macAddr);
ceb0fc8d
VK
1611
1612 UINT32 *buildAddressMap(int *length);
5039dede
AK
1613};
1614
84880c89
VK
1615/**
1616 * Universal root object
1617 */
5039dede
AK
1618class NXCORE_EXPORTABLE UniversalRoot : public NetObj
1619{
1620public:
1621 UniversalRoot();
1622 virtual ~UniversalRoot();
1623
c42b4551 1624 virtual BOOL saveToDatabase(DB_HANDLE hdb);
27f9598d 1625 virtual void LoadFromDB();
5039dede 1626
27f9598d 1627 void LinkChildObjects();
5039dede
AK
1628 void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
1629};
1630
826fcc1f
VK
1631/**
1632 * Service root
1633 */
5039dede
AK
1634class NXCORE_EXPORTABLE ServiceRoot : public UniversalRoot
1635{
1636public:
1637 ServiceRoot();
1638 virtual ~ServiceRoot();
1639
c42b4551 1640 virtual int getObjectClass() { return OBJECT_SERVICEROOT; }
27bbb906
VK
1641
1642 virtual bool showThresholdSummary();
5039dede
AK
1643};
1644
826fcc1f
VK
1645/**
1646 * Template root
1647 */
5039dede
AK
1648class NXCORE_EXPORTABLE TemplateRoot : public UniversalRoot
1649{
1650public:
1651 TemplateRoot();
1652 virtual ~TemplateRoot();
1653
c42b4551 1654 virtual int getObjectClass() { return OBJECT_TEMPLATEROOT; }
27f9598d 1655 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
5039dede
AK
1656};
1657
27bbb906
VK
1658/**
1659 * Generic container object
1660 */
5039dede
AK
1661class NXCORE_EXPORTABLE Container : public NetObj
1662{
1663private:
967893bb
VK
1664 UINT32 *m_pdwChildIdList;
1665 UINT32 m_dwChildIdListSize;
5039dede
AK
1666
1667protected:
967893bb
VK
1668 UINT32 m_flags;
1669 UINT32 m_dwCategory;
6b29839d 1670 NXSL_VM *m_bindFilter;
4262c0dc 1671 TCHAR *m_bindFilterSource;
5039dede 1672
8fe90adb
VK
1673 virtual void fillMessageInternal(NXCPMessage *pMsg);
1674 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1675
5039dede
AK
1676public:
1677 Container();
967893bb 1678 Container(const TCHAR *pszName, UINT32 dwCategory);
5039dede
AK
1679 virtual ~Container();
1680
19455e40 1681 virtual int getObjectClass() { return OBJECT_CONTAINER; }
3f39fdc2 1682
c42b4551
VK
1683 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1684 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1685 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 1686
27bbb906
VK
1687 virtual bool showThresholdSummary();
1688
4547feec
VK
1689 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1690
967893bb 1691 UINT32 getCategory() { return m_dwCategory; }
5039dede 1692
926e8ce7
VK
1693 void linkChildObjects();
1694 void linkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
4262c0dc 1695
a84c073c 1696 AutoBindDecision isSuitableForNode(Node *node);
9b64b406 1697 bool isAutoBindEnabled() { return (m_flags & CF_AUTO_BIND) ? true : false; }
d9511cf8 1698 bool isAutoUnbindEnabled() { return ((m_flags & (CF_AUTO_BIND | CF_AUTO_UNBIND)) == (CF_AUTO_BIND | CF_AUTO_UNBIND)) ? true : false; }
15c5bcbf
VK
1699
1700 void setAutoBindFilter(const TCHAR *script);
5039dede
AK
1701};
1702
27bbb906
VK
1703/**
1704 * Template group object
1705 */
5039dede
AK
1706class NXCORE_EXPORTABLE TemplateGroup : public Container
1707{
1708public:
1709 TemplateGroup() : Container() { }
67de55fd 1710 TemplateGroup(const TCHAR *pszName) : Container(pszName, 0) { m_iStatus = STATUS_NORMAL; }
5039dede
AK
1711 virtual ~TemplateGroup() { }
1712
c42b4551 1713 virtual int getObjectClass() { return OBJECT_TEMPLATEGROUP; }
27f9598d 1714 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
5039dede 1715
27bbb906
VK
1716 virtual bool showThresholdSummary();
1717};
5039dede 1718
8715a84c
VK
1719/**
1720 * Rack object
1721 */
1722class NXCORE_EXPORTABLE Rack : public Container
1723{
1724protected:
1725 int m_height; // Rack height in units
1726
8fe90adb
VK
1727 virtual void fillMessageInternal(NXCPMessage *pMsg);
1728 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1729
8715a84c
VK
1730public:
1731 Rack();
1732 Rack(const TCHAR *name, int height);
1733 virtual ~Rack();
1734
c42b4551 1735 virtual int getObjectClass() { return OBJECT_RACK; }
8715a84c 1736
c42b4551
VK
1737 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1738 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1739 virtual BOOL loadFromDatabase(UINT32 dwId);
8715a84c
VK
1740};
1741
27bbb906
VK
1742/**
1743 * Zone object
1744 */
5039dede
AK
1745class Zone : public NetObj
1746{
1747protected:
967893bb
VK
1748 UINT32 m_zoneId;
1749 UINT32 m_agentProxy;
1750 UINT32 m_snmpProxy;
1751 UINT32 m_icmpProxy;
c75e9ee4
VK
1752 InetAddressIndex *m_idxNodeByAddr;
1753 InetAddressIndex *m_idxInterfaceByAddr;
1754 InetAddressIndex *m_idxSubnetByAddr;
5039dede 1755
8fe90adb
VK
1756 virtual void fillMessageInternal(NXCPMessage *pMsg);
1757 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1758
5039dede
AK
1759public:
1760 Zone();
967893bb 1761 Zone(UINT32 zoneId, const TCHAR *name);
5039dede
AK
1762 virtual ~Zone();
1763
c42b4551 1764 virtual int getObjectClass() { return OBJECT_ZONE; }
5039dede 1765
c42b4551
VK
1766 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1767 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1768 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 1769
27bbb906
VK
1770 virtual bool showThresholdSummary();
1771
967893bb
VK
1772 UINT32 getZoneId() { return m_zoneId; }
1773 UINT32 getAgentProxy() { return m_agentProxy; }
1774 UINT32 getSnmpProxy() { return m_snmpProxy; }
1775 UINT32 getIcmpProxy() { return m_icmpProxy; }
5039dede 1776
52c31148 1777 void addSubnet(Subnet *pSubnet) { AddChild(pSubnet); pSubnet->AddParent(this); }
5e39b8a3 1778
c75e9ee4 1779 void addToIndex(Subnet *subnet) { m_idxSubnetByAddr->put(subnet->getIpAddress(), subnet); }
c30c0c0f 1780 void addToIndex(Interface *iface) { m_idxInterfaceByAddr->put(iface->getIpAddressList(), iface); }
5f6e8d09 1781 void addToIndex(const InetAddress& addr, Interface *iface) { m_idxInterfaceByAddr->put(addr, iface); }
c75e9ee4
VK
1782 void addToIndex(Node *node) { m_idxNodeByAddr->put(node->getIpAddress(), node); }
1783 void removeFromIndex(Subnet *subnet) { m_idxSubnetByAddr->remove(subnet->getIpAddress()); }
c30c0c0f 1784 void removeFromIndex(Interface *iface);
5f6e8d09 1785 void removeFromInterfaceIndex(const InetAddress& addr) { m_idxInterfaceByAddr->remove(addr); }
c75e9ee4
VK
1786 void removeFromIndex(Node *node) { m_idxNodeByAddr->remove(node->getIpAddress()); }
1787 void updateInterfaceIndex(const InetAddress& oldIp, const InetAddress& newIp, Interface *iface);
1788 Subnet *getSubnetByAddr(const InetAddress& ipAddr) { return (Subnet *)m_idxSubnetByAddr->get(ipAddr); }
1789 Interface *getInterfaceByAddr(const InetAddress& ipAddr) { return (Interface *)m_idxInterfaceByAddr->get(ipAddr); }
1790 Node *getNodeByAddr(const InetAddress& ipAddr) { return (Node *)m_idxNodeByAddr->get(ipAddr); }
89135050
VK
1791 Subnet *findSubnet(bool (*comparator)(NetObj *, void *), void *data) { return (Subnet *)m_idxSubnetByAddr->find(comparator, data); }
1792 Interface *findInterface(bool (*comparator)(NetObj *, void *), void *data) { return (Interface *)m_idxInterfaceByAddr->find(comparator, data); }
16d6f798 1793 Node *findNode(bool (*comparator)(NetObj *, void *), void *data) { return (Node *)m_idxNodeByAddr->find(comparator, data); }
c30c0c0f 1794 void forEachSubnet(void (*callback)(const InetAddress& addr, NetObj *, void *), void *data) { m_idxSubnetByAddr->forEach(callback, data); }
5039dede
AK
1795};
1796
27bbb906
VK
1797/**
1798 * Entire network
1799 */
5039dede
AK
1800class NXCORE_EXPORTABLE Network : public NetObj
1801{
1802public:
1803 Network();
1804 virtual ~Network();
1805
19455e40 1806 virtual int getObjectClass() { return OBJECT_NETWORK; }
c42b4551 1807 virtual BOOL saveToDatabase(DB_HANDLE hdb);
5039dede 1808
27bbb906
VK
1809 virtual bool showThresholdSummary();
1810
5039dede
AK
1811 void AddSubnet(Subnet *pSubnet) { AddChild(pSubnet); pSubnet->AddParent(this); }
1812 void AddZone(Zone *pZone) { AddChild(pZone); pZone->AddParent(this); }
1813 void LoadFromDB(void);
1814};
1815
27bbb906
VK
1816/**
1817 * Condition
1818 */
5039dede
AK
1819class NXCORE_EXPORTABLE Condition : public NetObj
1820{
1821protected:
9fddfb91
VK
1822 UINT32 m_dciCount;
1823 INPUT_DCI *m_dciList;
1824 TCHAR *m_scriptSource;
6b29839d 1825 NXSL_VM *m_script;
9fddfb91
VK
1826 UINT32 m_activationEventCode;
1827 UINT32 m_deactivationEventCode;
1828 UINT32 m_sourceObject;
1829 int m_activeStatus;
1830 int m_inactiveStatus;
1831 bool m_isActive;
1832 time_t m_lastPoll;
1833 bool m_queuedForPolling;
5039dede 1834
8fe90adb
VK
1835 virtual void fillMessageInternal(NXCPMessage *pMsg);
1836 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1837
5039dede 1838public:
5039dede 1839 Condition();
01152a54 1840 Condition(bool hidden);
5039dede
AK
1841 virtual ~Condition();
1842
c42b4551 1843 virtual int getObjectClass() { return OBJECT_CONDITION; }
5039dede 1844
c42b4551
VK
1845 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1846 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1847 virtual BOOL loadFromDatabase(UINT32 dwId);
5039dede 1848
9fddfb91 1849 void lockForPoll();
208d7427
VK
1850 void doPoll(PollerInfo *poller);
1851 void check();
5039dede 1852
9fddfb91 1853 bool isReadyForPoll()
5039dede 1854 {
3f39fdc2 1855 return ((m_iStatus != STATUS_UNMANAGED) &&
9fddfb91
VK
1856 (!m_queuedForPolling) && (!m_isDeleted) &&
1857 ((UINT32)time(NULL) - (UINT32)m_lastPoll > g_dwConditionPollingInterval));
5039dede
AK
1858 }
1859
9fddfb91 1860 int getCacheSizeForDCI(UINT32 itemId, bool noLock);
5039dede
AK
1861};
1862
27bbb906
VK
1863/**
1864 * Generic agent policy object
1865 */
a6d66d3a
VK
1866class NXCORE_EXPORTABLE AgentPolicy : public NetObj
1867{
1868protected:
967893bb 1869 UINT32 m_version;
a6d66d3a 1870 int m_policyType;
a6d66d3a 1871
3f7c0fe4 1872 BOOL savePolicyCommonProperties(DB_HANDLE hdb);
45d84f8a 1873
8fe90adb
VK
1874 virtual void fillMessageInternal(NXCPMessage *pMsg);
1875 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1876
a6d66d3a
VK
1877public:
1878 AgentPolicy(int type);
45d84f8a 1879 AgentPolicy(const TCHAR *name, int type);
6e53f004 1880
c42b4551 1881 virtual int getObjectClass() { return OBJECT_AGENTPOLICY; }
6e53f004 1882
c42b4551
VK
1883 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1884 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1885 virtual BOOL loadFromDatabase(UINT32 dwId);
6e53f004 1886
b368969c
VK
1887 virtual bool createDeploymentMessage(NXCPMessage *msg);
1888 virtual bool createUninstallMessage(NXCPMessage *msg);
93599cfd
VK
1889
1890 void linkNode(Node *node) { AddChild(node); node->AddParent(this); }
1891 void unlinkNode(Node *node) { DeleteChild(node); node->DeleteParent(this); }
a6d66d3a
VK
1892};
1893
27bbb906
VK
1894/**
1895 * Agent config policy object
1896 */
f2bb4aa1
VK
1897class NXCORE_EXPORTABLE AgentPolicyConfig : public AgentPolicy
1898{
1899protected:
f2bb4aa1
VK
1900 TCHAR *m_fileContent;
1901
8fe90adb
VK
1902 virtual void fillMessageInternal(NXCPMessage *pMsg);
1903 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1904
f2bb4aa1
VK
1905public:
1906 AgentPolicyConfig();
45d84f8a 1907 AgentPolicyConfig(const TCHAR *name);
f2bb4aa1
VK
1908 virtual ~AgentPolicyConfig();
1909
c42b4551 1910 virtual int getObjectClass() { return OBJECT_AGENTPOLICY_CONFIG; }
f2bb4aa1 1911
c42b4551
VK
1912 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1913 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1914 virtual BOOL loadFromDatabase(UINT32 dwId);
f2bb4aa1 1915
b368969c
VK
1916 virtual bool createDeploymentMessage(NXCPMessage *msg);
1917 virtual bool createUninstallMessage(NXCPMessage *msg);
f2bb4aa1
VK
1918};
1919
27bbb906
VK
1920/**
1921 * Policy group object
1922 */
a6d66d3a
VK
1923class NXCORE_EXPORTABLE PolicyGroup : public Container
1924{
1925public:
1926 PolicyGroup() : Container() { }
27f9598d 1927 PolicyGroup(const TCHAR *pszName) : Container(pszName, 0) { }
a6d66d3a
VK
1928 virtual ~PolicyGroup() { }
1929
c42b4551 1930 virtual int getObjectClass() { return OBJECT_POLICYGROUP; }
27f9598d 1931 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
a6d66d3a 1932
27bbb906
VK
1933 virtual bool showThresholdSummary();
1934};
a6d66d3a 1935
27bbb906
VK
1936/**
1937 * Policy root
1938 */
a6d66d3a
VK
1939class NXCORE_EXPORTABLE PolicyRoot : public UniversalRoot
1940{
1941public:
1942 PolicyRoot();
1943 virtual ~PolicyRoot();
1944
c42b4551 1945 virtual int getObjectClass() { return OBJECT_POLICYROOT; }
27f9598d 1946 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
a6d66d3a
VK
1947};
1948
27bbb906
VK
1949/**
1950 * Network map root
1951 */
021dcda7
VK
1952class NXCORE_EXPORTABLE NetworkMapRoot : public UniversalRoot
1953{
1954public:
1955 NetworkMapRoot();
1956 virtual ~NetworkMapRoot();
1957
c42b4551 1958 virtual int getObjectClass() { return OBJECT_NETWORKMAPROOT; }
27f9598d 1959 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
021dcda7
VK
1960};
1961
27bbb906
VK
1962/**
1963 * Network map group object
1964 */
021dcda7
VK
1965class NXCORE_EXPORTABLE NetworkMapGroup : public Container
1966{
1967public:
1968 NetworkMapGroup() : Container() { }
27f9598d 1969 NetworkMapGroup(const TCHAR *pszName) : Container(pszName, 0) { }
021dcda7
VK
1970 virtual ~NetworkMapGroup() { }
1971
c42b4551 1972 virtual int getObjectClass() { return OBJECT_NETWORKMAPGROUP; }
27f9598d 1973 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
021dcda7 1974
27bbb906
VK
1975 virtual bool showThresholdSummary();
1976};
021dcda7 1977
27bbb906
VK
1978/**
1979 * Network map object
1980 */
021dcda7
VK
1981class NXCORE_EXPORTABLE NetworkMap : public NetObj
1982{
1983protected:
1984 int m_mapType;
967893bb 1985 UINT32 m_seedObject;
84880c89 1986 int m_discoveryRadius;
021dcda7 1987 int m_layout;
967893bb 1988 UINT32 m_flags;
e4acd770 1989 int m_backgroundColor;
291247b2 1990 int m_defaultLinkColor;
e4acd770 1991 int m_defaultLinkRouting;
465b3f2d 1992 uuid_t m_background;
1a74dc37
VK
1993 double m_backgroundLatitude;
1994 double m_backgroundLongitude;
1995 int m_backgroundZoom;
967893bb 1996 UINT32 m_nextElementId;
dba7a1a8
VK
1997 ObjectArray<NetworkMapElement> *m_elements;
1998 ObjectArray<NetworkMapLink> *m_links;
701726bc 1999 TCHAR *m_filterSource;
6b29839d 2000 NXSL_VM *m_filter;
dba7a1a8 2001
8fe90adb
VK
2002 virtual void fillMessageInternal(NXCPMessage *pMsg);
2003 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2004
dba7a1a8 2005 void updateObjects(nxmap_ObjList *objects);
967893bb
VK
2006 UINT32 objectIdFromElementId(UINT32 eid);
2007 UINT32 elementIdFromObjectId(UINT32 eid);
ef3ebcdf 2008
89ec7c82
VK
2009 void setFilter(const TCHAR *filter);
2010
021dcda7
VK
2011public:
2012 NetworkMap();
967893bb 2013 NetworkMap(int type, UINT32 seed);
021dcda7
VK
2014 virtual ~NetworkMap();
2015
c42b4551 2016 virtual int getObjectClass() { return OBJECT_NETWORKMAP; }
27f9598d 2017 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
021dcda7 2018
c42b4551
VK
2019 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2020 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2021 virtual BOOL loadFromDatabase(UINT32 dwId);
021dcda7 2022
4af351c7
VK
2023 virtual void onObjectDelete(UINT32 dwObjectId);
2024
2025 void updateContent();
5a883bb7
VK
2026
2027 int getBackgroundColor() { return m_backgroundColor; }
2028 void setBackgroundColor(int color) { m_backgroundColor = color; }
701726bc 2029
701726bc 2030 bool isAllowedOnMap(NetObj *object);
021dcda7
VK
2031};
2032
27bbb906
VK
2033/**
2034 * Dashboard tree root
2035 */
27f9598d
VK
2036class NXCORE_EXPORTABLE DashboardRoot : public UniversalRoot
2037{
2038public:
2039 DashboardRoot();
2040 virtual ~DashboardRoot();
2041
c42b4551 2042 virtual int getObjectClass() { return OBJECT_DASHBOARDROOT; }
27f9598d
VK
2043 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2044};
2045
27bbb906
VK
2046/**
2047 * Dashboard element
2048 */
27f9598d
VK
2049class DashboardElement
2050{
2051public:
2052 int m_type;
2053 TCHAR *m_data;
fceea457 2054 TCHAR *m_layout;
27f9598d 2055
fceea457
VK
2056 DashboardElement() { m_data = NULL; m_layout = NULL; }
2057 ~DashboardElement() { safe_free(m_data); safe_free(m_layout); }
27f9598d
VK
2058};
2059
27bbb906
VK
2060/**
2061 * Dashboard object
2062 */
27f9598d
VK
2063class NXCORE_EXPORTABLE Dashboard : public Container
2064{
2065protected:
2066 int m_numColumns;
967893bb 2067 UINT32 m_options;
27f9598d
VK
2068 ObjectArray<DashboardElement> *m_elements;
2069
8fe90adb
VK
2070 virtual void fillMessageInternal(NXCPMessage *pMsg);
2071 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2072
27f9598d
VK
2073public:
2074 Dashboard();
2075 Dashboard(const TCHAR *name);
2076 virtual ~Dashboard();
2077
c42b4551 2078 virtual int getObjectClass() { return OBJECT_DASHBOARD; }
27f9598d 2079 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
926e8ce7 2080
c42b4551
VK
2081 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2082 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2083 virtual BOOL loadFromDatabase(UINT32 dwId);
926e8ce7 2084
27bbb906
VK
2085 virtual bool showThresholdSummary();
2086};
27f9598d 2087
27bbb906
VK
2088/**
2089 * SLM check object
2090 */
fc958888
AK
2091class NXCORE_EXPORTABLE SlmCheck : public NetObj
2092{
2093protected:
140b8ada
VK
2094 static NXSL_VariableSystem m_nxslConstants;
2095
1621a079 2096 Threshold *m_threshold;
fc958888 2097 enum CheckType { check_undefined = 0, check_script = 1, check_threshold = 2 } m_type;
1621a079 2098 TCHAR *m_script;
6b29839d 2099 NXSL_VM *m_pCompiledScript;
1621a079 2100 TCHAR m_reason[256];
63c1ae35 2101 bool m_isTemplate;
967893bb
VK
2102 UINT32 m_templateId;
2103 UINT32 m_currentTicketId;
1621a079 2104
967893bb 2105 virtual void onObjectDelete(UINT32 objectId);
6ff21d27 2106
8fe90adb
VK
2107 virtual void fillMessageInternal(NXCPMessage *pMsg);
2108 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2109
2110 void setScript(const TCHAR *script);
967893bb 2111 UINT32 getOwnerId();
eb3d3e10 2112 NXSL_Value *getNodeObjectForNXSL();
636e0c72
VK
2113 bool insertTicket();
2114 void closeTicket();
2115 void setReason(const TCHAR *reason) { nx_strncpy(m_reason, CHECK_NULL_EX(reason), 256); }
28207240 2116 void compileScript();
fc958888
AK
2117
2118public:
2119 SlmCheck();
6ff21d27
VK
2120 SlmCheck(const TCHAR *name, bool isTemplate);
2121 SlmCheck(SlmCheck *tmpl);
fc958888
AK
2122 virtual ~SlmCheck();
2123
140b8ada
VK
2124 static void init();
2125
c42b4551 2126 virtual int getObjectClass() { return OBJECT_SLMCHECK; }
fc958888 2127
c42b4551
VK
2128 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2129 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2130 virtual BOOL loadFromDatabase(UINT32 dwId);
fc958888 2131
6ff21d27 2132 virtual void postModify();
fc958888 2133
ae3d7f46 2134 void execute();
6ff21d27
VK
2135 void updateFromTemplate(SlmCheck *tmpl);
2136
2137 bool isTemplate() { return m_isTemplate; }
967893bb 2138 UINT32 getTemplateId() { return m_templateId; }
1621a079 2139 const TCHAR *getReason() { return m_reason; }
fc958888
AK
2140};
2141
27bbb906
VK
2142/**
2143 * Service container - common logic for BusinessService, NodeLink and BusinessServiceRoot
2144 */
3f39fdc2 2145class NXCORE_EXPORTABLE ServiceContainer : public Container
fc958888 2146{
93d91beb
AK
2147 enum Period { DAY, WEEK, MONTH };
2148
fc958888 2149protected:
1b534360 2150 time_t m_prevUptimeUpdateTime;
1b534360 2151 int m_prevUptimeUpdateStatus;
93d91beb
AK
2152 double m_uptimeDay;
2153 double m_uptimeWeek;
2154 double m_uptimeMonth;
05c9a2f9
VK
2155 INT32 m_downtimeDay;
2156 INT32 m_downtimeWeek;
2157 INT32 m_downtimeMonth;
2158 INT32 m_prevDiffDay;
2159 INT32 m_prevDiffWeek;
2160 INT32 m_prevDiffMonth;
2161
2162 static INT32 logRecordId;
2163 static INT32 getSecondsInMonth();
2164 static INT32 getSecondsInPeriod(Period period) { return period == MONTH ? getSecondsInMonth() : (period == WEEK ? (3600 * 24 * 7) : (3600 * 24)); }
2165 static INT32 getSecondsSinceBeginningOf(Period period, time_t *beginTime = NULL);
93d91beb 2166
8fe90adb
VK
2167 virtual void fillMessageInternal(NXCPMessage *pMsg);
2168 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2169
3e2bf4aa 2170 void initServiceContainer();
93d91beb 2171 BOOL addHistoryRecord();
05c9a2f9 2172 double getUptimeFromDBFor(Period period, INT32 *downtime);
63c1ae35 2173
3e2bf4aa
AK
2174public:
2175 ServiceContainer();
4a1e58e5
VK
2176 ServiceContainer(const TCHAR *pszName);
2177
c42b4551
VK
2178 virtual BOOL loadFromDatabase(UINT32 dwId);
2179 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2180 virtual bool deleteFromDatabase(DB_HANDLE hdb);
4a1e58e5 2181
3e2bf4aa
AK
2182 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2183 virtual void setStatus(int newStatus);
d4036c05 2184
27bbb906
VK
2185 virtual bool showThresholdSummary();
2186
d4036c05 2187 void initUptimeStats();
f43056c7 2188 void updateUptimeStats(time_t currentTime = 0, BOOL updateChilds = FALSE);
3e2bf4aa
AK
2189};
2190
05c9a2f9
VK
2191/**
2192 * Business service root
2193 */
4a1e58e5 2194class NXCORE_EXPORTABLE BusinessServiceRoot : public ServiceContainer
3e2bf4aa
AK
2195{
2196public:
2197 BusinessServiceRoot();
2198 virtual ~BusinessServiceRoot();
2199
c42b4551 2200 virtual int getObjectClass() { return OBJECT_BUSINESSSERVICEROOT; }
4a1e58e5 2201
c42b4551 2202 virtual BOOL saveToDatabase(DB_HANDLE hdb);
4a1e58e5
VK
2203 void LoadFromDB();
2204
2205 void LinkChildObjects();
2206 void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
3e2bf4aa
AK
2207};
2208
f6cd5b2f
VK
2209/**
2210 * Business service object
2211 */
3e2bf4aa
AK
2212class NXCORE_EXPORTABLE BusinessService : public ServiceContainer
2213{
2214protected:
2215 bool m_busy;
f6cd5b2f 2216 bool m_pollingDisabled;
3e2bf4aa
AK
2217 time_t m_lastPollTime;
2218 int m_lastPollStatus;
2219
f6cd5b2f
VK
2220 virtual void prepareForDeletion();
2221
8fe90adb
VK
2222 virtual void fillMessageInternal(NXCPMessage *pMsg);
2223 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2224
fc958888 2225public:
1621a079
VK
2226 BusinessService();
2227 BusinessService(const TCHAR *name);
2228 virtual ~BusinessService();
fc958888 2229
c42b4551 2230 virtual int getObjectClass() { return OBJECT_BUSINESSSERVICE; }
fc958888 2231
c42b4551
VK
2232 virtual BOOL loadFromDatabase(UINT32 dwId);
2233 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2234 virtual bool deleteFromDatabase(DB_HANDLE hdb);
fc958888 2235
52c75f5c
AK
2236 bool isReadyForPolling();
2237 void lockForPolling();
208d7427
VK
2238 void poll(PollerInfo *poller);
2239 void poll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
6ff21d27
VK
2240
2241 void getApplicableTemplates(ServiceContainer *target, ObjectArray<SlmCheck> *templates);
fc958888
AK
2242};
2243
22ee6d97
VK
2244/**
2245 * Node link object for business service
2246 */
3e2bf4aa
AK
2247class NXCORE_EXPORTABLE NodeLink : public ServiceContainer
2248{
2249protected:
967893bb 2250 UINT32 m_nodeId;
3e2bf4aa 2251
967893bb 2252 virtual void onObjectDelete(UINT32 dwObjectId);
c50f77f7 2253
8fe90adb
VK
2254 virtual void fillMessageInternal(NXCPMessage *pMsg);
2255 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2256
6ff21d27
VK
2257 void applyTemplate(SlmCheck *tmpl);
2258
3e2bf4aa
AK
2259public:
2260 NodeLink();
967893bb 2261 NodeLink(const TCHAR *name, UINT32 nodeId);
3e2bf4aa
AK
2262 virtual ~NodeLink();
2263
c42b4551 2264 virtual int getObjectClass() { return OBJECT_NODELINK; }
3e2bf4aa 2265
c42b4551
VK
2266 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2267 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2268 virtual BOOL loadFromDatabase(UINT32 dwId);
3e2bf4aa 2269
3e2bf4aa 2270 void execute();
6ff21d27 2271 void applyTemplates();
3e2bf4aa 2272
967893bb 2273 UINT32 getNodeId() { return m_nodeId; }
3e2bf4aa
AK
2274};
2275
c30c0c0f
VK
2276/**
2277 * Get IP address for object
2278 */
2279inline const InetAddress& GetObjectIpAddress(NetObj *object)
2280{
2281 if (object->getObjectClass() == OBJECT_NODE)
2282 return ((Node *)object)->getIpAddress();
2283 if (object->getObjectClass() == OBJECT_SUBNET)
2284 return ((Subnet *)object)->getIpAddress();
2285 if (object->getObjectClass() == OBJECT_ACCESSPOINT)
2286 return ((AccessPoint *)object)->getIpAddress();
2287 return InetAddress::INVALID;
2288}
fc958888 2289
5039dede
AK
2290//
2291// Container category information
2292//
2293
2294struct CONTAINER_CATEGORY
2295{
967893bb 2296 UINT32 dwCatId;
35f836fe
VK
2297 TCHAR szName[MAX_OBJECT_NAME];
2298 TCHAR *pszDescription;
967893bb 2299 UINT32 dwImageId;
5039dede
AK
2300};
2301
2302
2303//
2304// Functions
2305//
2306
021dcda7 2307void ObjectsInit();
5039dede 2308
15c5bcbf 2309void NXCORE_EXPORTABLE NetObjInsert(NetObj *pObject, BOOL bNewObject);
5039dede
AK
2310void NetObjDeleteFromIndexes(NetObj *pObject);
2311void NetObjDelete(NetObj *pObject);
2312
c75e9ee4 2313void UpdateInterfaceIndex(const InetAddress& oldIpAddr, const InetAddress& newIpAddr, Interface *iface);
8836184f 2314ComponentTree *BuildComponentTree(Node *node, SNMP_Transport *snmp);
5039dede 2315
edecb8ef
VK
2316void NXCORE_EXPORTABLE MacDbAddAccessPoint(AccessPoint *ap);
2317void NXCORE_EXPORTABLE MacDbAddInterface(Interface *iface);
2318void NXCORE_EXPORTABLE MacDbAddObject(const BYTE *macAddr, NetObj *object);
2319void NXCORE_EXPORTABLE MacDbRemove(const BYTE *macAddr);
2320NetObj NXCORE_EXPORTABLE *MacDbFind(const BYTE *macAddr);
2321
967893bb 2322NetObj NXCORE_EXPORTABLE *FindObjectById(UINT32 dwId, int objClass = -1);
5039dede 2323NetObj NXCORE_EXPORTABLE *FindObjectByName(const TCHAR *name, int objClass);
1f385e47 2324NetObj NXCORE_EXPORTABLE *FindObjectByGUID(uuid_t guid, int objClass);
fffcff95 2325const TCHAR NXCORE_EXPORTABLE *GetObjectName(DWORD id, const TCHAR *defaultName);
5039dede 2326Template NXCORE_EXPORTABLE *FindTemplateByName(const TCHAR *pszName);
c75e9ee4 2327Node NXCORE_EXPORTABLE *FindNodeByIP(UINT32 zoneId, const InetAddress& ipAddr);
c30c0c0f 2328Node NXCORE_EXPORTABLE *FindNodeByIP(UINT32 zoneId, const InetAddressList *ipAddrList);
06a93345 2329Node NXCORE_EXPORTABLE *FindNodeByMAC(const BYTE *macAddr);
4005181b 2330Node NXCORE_EXPORTABLE *FindNodeByBridgeId(const BYTE *bridgeId);
eec253a8 2331Node NXCORE_EXPORTABLE *FindNodeByLLDPId(const TCHAR *lldpId);
c75e9ee4 2332Interface NXCORE_EXPORTABLE *FindInterfaceByIP(UINT32 zoneId, const InetAddress& ipAddr);
06a93345 2333Interface NXCORE_EXPORTABLE *FindInterfaceByMAC(const BYTE *macAddr);
478d4ff4 2334Interface NXCORE_EXPORTABLE *FindInterfaceByDescription(const TCHAR *description);
c75e9ee4
VK
2335Subnet NXCORE_EXPORTABLE *FindSubnetByIP(UINT32 zoneId, const InetAddress& ipAddr);
2336Subnet NXCORE_EXPORTABLE *FindSubnetForNode(UINT32 zoneId, const InetAddress& nodeAddr);
534e1b83 2337MobileDevice NXCORE_EXPORTABLE *FindMobileDeviceByDeviceID(const TCHAR *deviceId);
c6afd26a 2338AccessPoint NXCORE_EXPORTABLE *FindAccessPointByMAC(const BYTE *macAddr);
967893bb
VK
2339UINT32 NXCORE_EXPORTABLE FindLocalMgmtNode();
2340CONTAINER_CATEGORY NXCORE_EXPORTABLE *FindContainerCategory(UINT32 dwId);
2341Zone NXCORE_EXPORTABLE *FindZoneByGUID(UINT32 dwZoneGUID);
c75e9ee4
VK
2342Cluster NXCORE_EXPORTABLE *FindClusterByResourceIP(UINT32 zone, const InetAddress& ipAddr);
2343bool NXCORE_EXPORTABLE IsClusterIP(UINT32 zone, const InetAddress& ipAddr);
5039dede 2344
021dcda7 2345BOOL LoadObjects();
01ca557f 2346void DumpObjects(CONSOLE_CTX pCtx, const TCHAR *filter);
5039dede 2347
967893bb 2348void DeleteUserFromAllObjects(UINT32 dwUserId);
5039dede 2349
fc381a38 2350bool IsValidParentClass(int iChildClass, int iParentClass);
1f385e47 2351bool IsAgentPolicyObject(NetObj *object);
fc381a38 2352bool IsEventSource(int objectClass);
5039dede
AK
2353
2354int DefaultPropagatedStatus(int iObjectStatus);
2355int GetDefaultStatusCalculation(int *pnSingleThreshold, int **ppnThresholds);
2356
208d7427
VK
2357PollerInfo *RegisterPoller(PollerType type, NetObj *object);
2358void ShowPollers(CONSOLE_CTX console);
2359
fc381a38
VK
2360/**
2361 * Global variables
2362 */
fb05c05b
VK
2363extern Network NXCORE_EXPORTABLE *g_pEntireNet;
2364extern ServiceRoot NXCORE_EXPORTABLE *g_pServiceRoot;
2365extern TemplateRoot NXCORE_EXPORTABLE *g_pTemplateRoot;
2366extern PolicyRoot NXCORE_EXPORTABLE *g_pPolicyRoot;
926e8ce7
VK
2367extern NetworkMapRoot NXCORE_EXPORTABLE *g_pMapRoot;
2368extern DashboardRoot NXCORE_EXPORTABLE *g_pDashboardRoot;
1621a079 2369extern BusinessServiceRoot NXCORE_EXPORTABLE *g_pBusinessServiceRoot;
5039dede 2370
967893bb
VK
2371extern UINT32 NXCORE_EXPORTABLE g_dwMgmtNode;
2372extern UINT32 g_dwNumCategories;
5039dede 2373extern CONTAINER_CATEGORY *g_pContainerCatList;
35f836fe 2374extern const TCHAR *g_szClassName[];
5039dede
AK
2375extern BOOL g_bModificationsLocked;
2376extern Queue *g_pTemplateUpdateQueue;
2377
5f0fc7a9 2378extern ObjectIndex NXCORE_EXPORTABLE g_idxObjectById;
c75e9ee4
VK
2379extern InetAddressIndex NXCORE_EXPORTABLE g_idxSubnetByAddr;
2380extern InetAddressIndex NXCORE_EXPORTABLE g_idxInterfaceByAddr;
2381extern InetAddressIndex NXCORE_EXPORTABLE g_idxNodeByAddr;
5f0fc7a9
VK
2382extern ObjectIndex NXCORE_EXPORTABLE g_idxZoneByGUID;
2383extern ObjectIndex NXCORE_EXPORTABLE g_idxNodeById;
85ae39bc 2384extern ObjectIndex NXCORE_EXPORTABLE g_idxClusterById;
9aa67910 2385extern ObjectIndex NXCORE_EXPORTABLE g_idxMobileDeviceById;
c6afd26a 2386extern ObjectIndex NXCORE_EXPORTABLE g_idxAccessPointById;
5f0fc7a9 2387extern ObjectIndex NXCORE_EXPORTABLE g_idxConditionById;
6ff21d27 2388extern ObjectIndex NXCORE_EXPORTABLE g_idxServiceCheckById;
9d605305 2389
5039dede
AK
2390
2391#endif /* _nms_objects_h_ */