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