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