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