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