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