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