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