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