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