added uuid class; code rerfactoring
[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 NXCORE_EXPORTABLE 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 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 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 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() const { return OBJECT_GENERIC; }
500
501 UINT32 getId() const { return m_id; }
502 const TCHAR *getName() const { return m_name; }
503 int Status() const { return m_iStatus; }
504 int getPropagatedStatus();
505 UINT32 getTimeStamp() const { return m_dwTimeStamp; }
506 const uuid& getGuid() const { return m_guid; }
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() { m_guid = uuid::generate(); }
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() const { 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() const { 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() const { 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() const { 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() const { 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() const { 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() const { 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() const { 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 ProxyInfo;
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 AgentConnection *m_fileUpdateConn;
1188
1189 void pollerLock() { MutexLock(m_hPollerMutex); }
1190 void pollerUnlock() { MutexUnlock(m_hPollerMutex); }
1191
1192 void agentLock() { MutexLock(m_hAgentAccessMutex); }
1193 void agentUnlock() { MutexUnlock(m_hAgentAccessMutex); }
1194
1195 void smclpLock() { MutexLock(m_hSmclpAccessMutex); }
1196 void smclpUnlock() { MutexUnlock(m_hSmclpAccessMutex); }
1197
1198 void routingTableLock() { MutexLock(m_mutexRTAccess); }
1199 void routingTableUnlock() { MutexUnlock(m_mutexRTAccess); }
1200
1201 BOOL checkSNMPIntegerValue(SNMP_Transport *pTransport, const TCHAR *pszOID, int nValue);
1202 void checkOSPFSupport(SNMP_Transport *pTransport);
1203 void addVrrpInterfaces(InterfaceList *ifList);
1204 BOOL resolveName(BOOL useOnlyDNS);
1205 void setAgentProxy(AgentConnection *pConn);
1206 void setPrimaryIPAddress(const InetAddress& addr);
1207
1208 UINT32 getInterfaceCount(Interface **ppInterface);
1209
1210 void checkInterfaceNames(InterfaceList *pIfList);
1211 Subnet *createSubnet(const InetAddress& baseAddr, bool syntheticMask);
1212 void checkAgentPolicyBinding(AgentConnection *conn);
1213 void updatePrimaryIpAddr();
1214 bool confPollAgent(UINT32 dwRqId);
1215 bool confPollSnmp(UINT32 dwRqId);
1216 void checkBridgeMib(SNMP_Transport *pTransport);
1217 void checkIfXTable(SNMP_Transport *pTransport);
1218 void executeHookScript(const TCHAR *hookName);
1219 bool checkNetworkPath(UINT32 dwRqId);
1220 bool checkNetworkPathElement(UINT32 nodeId, const TCHAR *nodeType, bool isProxy, UINT32 dwRqId);
1221
1222 void applyUserTemplates();
1223 void doInstanceDiscovery(UINT32 requestId);
1224 StringMap *getInstanceList(DCItem *dci);
1225 void updateInstances(DCItem *root, StringMap *instances, UINT32 requestId);
1226
1227 void syncDataCollectionWithAgent(AgentConnectionEx *conn);
1228 void collectProxyInfo(ProxyInfo *info);
1229 static void collectProxyInfoCallback(NetObj *node, void *data);
1230
1231 void updateContainerMembership();
1232 bool updateInterfaceConfiguration(UINT32 rqid, int maskBits);
1233 bool deleteDuplicateInterfaces(UINT32 rqid);
1234
1235 void buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedObject, bool vpnLink, bool includeEndNodes);
1236
1237 virtual bool isDataCollectionDisabled();
1238
1239 virtual void prepareForDeletion();
1240 virtual void onObjectDelete(UINT32 dwObjectId);
1241
1242 virtual void fillMessageInternal(NXCPMessage *pMsg);
1243 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1244
1245 virtual void updatePingData();
1246
1247 virtual void onDataCollectionChange();
1248
1249 public:
1250 Node();
1251 Node(const InetAddress& addr, UINT32 dwFlags, UINT32 agentProxy, UINT32 snmpProxy, UINT32 dwZone);
1252 virtual ~Node();
1253
1254 virtual int getObjectClass() const { return OBJECT_NODE; }
1255 UINT32 getIcmpProxy() { return m_icmpProxy; }
1256
1257 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1258 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1259 virtual BOOL loadFromDatabase(UINT32 dwId);
1260
1261 TCHAR *expandText(const TCHAR *textTemplate);
1262
1263 Cluster *getMyCluster();
1264
1265 const InetAddress& getIpAddress() { return m_ipAddress; }
1266 UINT32 getZoneId() { return m_zoneId; }
1267 UINT32 getFlags() { return m_dwFlags; }
1268 UINT32 getRuntimeFlags() { return m_dwDynamicFlags; }
1269 void setFlag(UINT32 flag) { lockProperties(); m_dwFlags |= flag; setModified(); unlockProperties(); }
1270 void clearFlag(UINT32 flag) { lockProperties(); m_dwFlags &= ~flag; setModified(); unlockProperties(); }
1271 void setLocalMgmtFlag() { m_dwFlags |= NF_IS_LOCAL_MGMT; }
1272 void clearLocalMgmtFlag() { m_dwFlags &= ~NF_IS_LOCAL_MGMT; }
1273
1274 bool isSNMPSupported() { return m_dwFlags & NF_IS_SNMP ? true : false; }
1275 bool isNativeAgent() { return m_dwFlags & NF_IS_NATIVE_AGENT ? true : false; }
1276 bool isBridge() { return m_dwFlags & NF_IS_BRIDGE ? true : false; }
1277 bool isRouter() { return m_dwFlags & NF_IS_ROUTER ? true : false; }
1278 bool isLocalManagement() { return m_dwFlags & NF_IS_LOCAL_MGMT ? true : false; }
1279 bool isPerVlanFdbSupported() { return (m_driver != NULL) ? m_driver->isPerVlanFdbSupported() : false; }
1280 bool isWirelessController() { return m_dwFlags & NF_IS_WIFI_CONTROLLER ? true : false; }
1281
1282 LONG getSNMPVersion() { return m_snmpVersion; }
1283 const TCHAR *getSNMPObjectId() { return m_szObjectId; }
1284 const TCHAR *getAgentVersion() { return m_szAgentVersion; }
1285 const TCHAR *getPlatformName() { return m_szPlatformName; }
1286 const TCHAR *getObjectId() { return m_szObjectId; }
1287 const TCHAR *getSysName() { return CHECK_NULL_EX(m_sysName); }
1288 const TCHAR *getSysDescription() { return CHECK_NULL_EX(m_sysDescription); }
1289 time_t getBootTime() { return m_bootTime; }
1290 const TCHAR *getLLDPNodeId() { return m_lldpNodeId; }
1291 const BYTE *getBridgeId() { return m_baseBridgeAddress; }
1292 const TCHAR *getDriverName() { return (m_driver != NULL) ? m_driver->getName() : _T("GENERIC"); }
1293 UINT16 getAgentPort() { return m_agentPort; }
1294 INT16 getAgentAuthMethod() { return m_agentAuthMethod; }
1295 INT16 getAgentCacheMode() { return (m_agentCacheMode == AGENT_CACHE_DEFAULT) ? g_defaultAgentCacheMode : m_agentCacheMode; }
1296 const TCHAR *getSharedSecret() { return m_szSharedSecret; }
1297 AgentConnection *getFileUpdateConn() { return m_fileUpdateConn; }
1298
1299 bool isDown() { return (m_dwDynamicFlags & NDF_UNREACHABLE) ? true : false; }
1300 time_t getDownTime() const { return m_downSince; }
1301
1302 void addInterface(Interface *pInterface) { AddChild(pInterface); pInterface->AddParent(this); }
1303 Interface *createNewInterface(InterfaceInfo *ifInfo, bool manuallyCreated);
1304 Interface *createNewInterface(const InetAddress& ipAddr, BYTE *macAddr);
1305 void deleteInterface(Interface *iface);
1306
1307 void setPrimaryName(const TCHAR *name) { nx_strncpy(m_primaryName, name, MAX_DNS_NAME); }
1308 void setAgentPort(WORD port) { m_agentPort = port; }
1309 void setSnmpPort(WORD port) { m_snmpPort = port; }
1310 void changeIPAddress(const InetAddress& ipAddr);
1311 void changeZone(UINT32 newZone);
1312 void setFileUpdateConn(AgentConnection *conn);
1313
1314 ARP_CACHE *getArpCache();
1315 InterfaceList *getInterfaceList();
1316 Interface *findInterfaceByIndex(UINT32 ifIndex);
1317 Interface *findInterfaceByName(const TCHAR *name);
1318 Interface *findInterfaceByMAC(const BYTE *macAddr);
1319 Interface *findInterfaceByIP(const InetAddress& addr);
1320 Interface *findInterfaceBySlotAndPort(UINT32 slot, UINT32 port);
1321 Interface *findBridgePort(UINT32 bridgePortNumber);
1322 AccessPoint *findAccessPointByMAC(const BYTE *macAddr);
1323 AccessPoint *findAccessPointByBSSID(const BYTE *bssid);
1324 AccessPoint *findAccessPointByRadioId(int rfIndex);
1325 ObjectArray<WirelessStationInfo> *getWirelessStations();
1326 bool isMyIP(const InetAddress& addr);
1327 void getInterfaceStatusFromSNMP(SNMP_Transport *pTransport, UINT32 dwIndex, InterfaceAdminState *adminState, InterfaceOperState *operState);
1328 void getInterfaceStatusFromAgent(UINT32 dwIndex, InterfaceAdminState *adminState, InterfaceOperState *operState);
1329 ROUTING_TABLE *getRoutingTable();
1330 ROUTING_TABLE *getCachedRoutingTable() { return m_pRoutingTable; }
1331 LinkLayerNeighbors *getLinkLayerNeighbors();
1332 VlanList *getVlans();
1333 bool getNextHop(const InetAddress& srcAddr, const InetAddress& destAddr, InetAddress *nextHop, UINT32 *ifIndex, bool *isVpn, TCHAR *name);
1334 bool getOutwardInterface(const InetAddress& destAddr, InetAddress *srcAddr, UINT32 *srcIfIndex);
1335 ComponentTree *getComponents();
1336 bool getLldpLocalPortInfo(BYTE *id, size_t idLen, LLDP_LOCAL_PORT_INFO *port);
1337
1338 void setRecheckCapsFlag() { m_dwDynamicFlags |= NDF_RECHECK_CAPABILITIES; }
1339 void setDiscoveryPollTimeStamp();
1340 void statusPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
1341 void statusPoll(PollerInfo *poller);
1342 void configurationPoll(PollerInfo *poller);
1343 void configurationPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller, int maskBits);
1344 void instanceDiscoveryPoll(PollerInfo *poller);
1345 void instanceDiscoveryPoll(ClientSession *session, UINT32 requestId, PollerInfo *poller);
1346 void topologyPoll(PollerInfo *poller);
1347 void topologyPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
1348 void resolveVlanPorts(VlanList *vlanList);
1349 void updateInterfaceNames(ClientSession *pSession, UINT32 dwRqId);
1350 void routingTablePoll(PollerInfo *poller);
1351 void updateRoutingTable();
1352 void checkSubnetBinding();
1353 AccessPointState getAccessPointState(AccessPoint *ap, SNMP_Transport *snmpTransport);
1354
1355 bool isReadyForStatusPoll();
1356 bool isReadyForConfigurationPoll();
1357 bool isReadyForInstancePoll();
1358 bool isReadyForDiscoveryPoll();
1359 bool isReadyForRoutePoll();
1360 bool isReadyForTopologyPoll();
1361
1362 void lockForStatusPoll();
1363 void lockForConfigurationPoll();
1364 void lockForInstancePoll();
1365 void lockForDiscoveryPoll();
1366 void lockForRoutePoll();
1367 void lockForTopologyPoll();
1368 void forceConfigurationPoll() { m_dwDynamicFlags |= NDF_FORCE_CONFIGURATION_POLL; }
1369
1370 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1371
1372 bool connectToAgent(UINT32 *error = NULL, UINT32 *socketError = NULL, bool *newConnection = NULL);
1373 bool checkAgentTrapId(UINT64 id);
1374 bool checkSNMPTrapId(UINT32 id);
1375 bool checkAgentPushRequestId(UINT64 id);
1376
1377 bool connectToSMCLP();
1378
1379 virtual UINT32 getInternalItem(const TCHAR *param, size_t bufSize, TCHAR *buffer);
1380
1381 UINT32 getItemFromSNMP(WORD port, const TCHAR *param, size_t bufSize, TCHAR *buffer, int interpretRawValue);
1382 UINT32 getTableFromSNMP(WORD port, const TCHAR *oid, ObjectArray<DCTableColumn> *columns, Table **table);
1383 UINT32 getListFromSNMP(WORD port, const TCHAR *oid, StringList **list);
1384 UINT32 getOIDSuffixListFromSNMP(WORD port, const TCHAR *oid, StringMap **values);
1385 UINT32 getItemFromCheckPointSNMP(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
1386 UINT32 getItemFromAgent(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
1387 UINT32 getTableFromAgent(const TCHAR *name, Table **table);
1388 UINT32 getListFromAgent(const TCHAR *name, StringList **list);
1389 UINT32 getItemForClient(int iOrigin, const TCHAR *pszParam, TCHAR *pszBuffer, UINT32 dwBufSize);
1390 UINT32 getTableForClient(const TCHAR *name, Table **table);
1391 UINT32 getItemFromSMCLP(const TCHAR *param, UINT32 bufSize, TCHAR *buffer);
1392
1393 virtual NXSL_Array *getParentsForNXSL();
1394 virtual NXSL_Array *getTemplatesForNXSL();
1395 NXSL_Array *getInterfacesForNXSL();
1396
1397 void openParamList(ObjectArray<AgentParameterDefinition> **paramList);
1398 void closeParamList() { unlockProperties(); }
1399
1400 void openTableList(ObjectArray<AgentTableDefinition> **tableList);
1401 void closeTableList() { unlockProperties(); }
1402
1403 AgentConnectionEx *createAgentConnection();
1404 SNMP_Transport *createSnmpTransport(WORD port = 0, const TCHAR *context = NULL);
1405 SNMP_SecurityContext *getSnmpSecurityContext();
1406 UINT32 getEffectiveSnmpProxy();
1407
1408 void writeParamListToMessage(NXCPMessage *pMsg, WORD flags);
1409 void writeWinPerfObjectsToMessage(NXCPMessage *msg);
1410 void writePackageListToMessage(NXCPMessage *msg);
1411 void writeWsListToMessage(NXCPMessage *msg);
1412
1413 UINT32 wakeUp();
1414
1415 void addService(NetworkService *pNetSrv) { AddChild(pNetSrv); pNetSrv->AddParent(this); }
1416 UINT32 checkNetworkService(UINT32 *pdwStatus, const InetAddress& ipAddr, int iServiceType, WORD wPort = 0,
1417 WORD wProto = 0, TCHAR *pszRequest = NULL, TCHAR *pszResponse = NULL, UINT32 *responseTime = NULL);
1418
1419 QWORD getLastEventId(int nIndex) { return ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) ? m_qwLastEvents[nIndex] : 0; }
1420 void setLastEventId(int nIndex, QWORD qwId) { if ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) m_qwLastEvents[nIndex] = qwId; }
1421
1422 UINT32 callSnmpEnumerate(const TCHAR *pszRootOid,
1423 UINT32 (* pHandler)(UINT32, SNMP_Variable *, SNMP_Transport *, void *), void *pArg, const TCHAR *context = NULL);
1424
1425 nxmap_ObjList *getL2Topology();
1426 nxmap_ObjList *buildL2Topology(UINT32 *pdwStatus, int radius, bool includeEndNodes);
1427 ForwardingDatabase *getSwitchForwardingDatabase();
1428 NetObj *findConnectionPoint(UINT32 *localIfId, BYTE *localMacAddr, int *type);
1429 void addHostConnections(LinkLayerNeighbors *nbs);
1430 void addExistingConnections(LinkLayerNeighbors *nbs);
1431
1432 nxmap_ObjList *buildIPTopology(UINT32 *pdwStatus, int radius, bool includeEndNodes);
1433
1434 ServerJobQueue *getJobQueue() { return m_jobQueue; }
1435 int getJobCount(const TCHAR *type = NULL) { return m_jobQueue->getJobCount(type); }
1436
1437 DriverData *getDriverData() { return m_driverData; }
1438 void setDriverData(DriverData *data) { m_driverData = data; }
1439 };
1440
1441 /**
1442 * Set timestamp of last discovery poll to current time
1443 */
1444 inline void Node::setDiscoveryPollTimeStamp()
1445 {
1446 m_lastDiscoveryPoll = time(NULL);
1447 m_dwDynamicFlags &= ~NDF_QUEUED_FOR_DISCOVERY_POLL;
1448 }
1449
1450 inline bool Node::isReadyForStatusPoll()
1451 {
1452 if (m_isDeleted)
1453 return false;
1454 if (m_dwDynamicFlags & NDF_FORCE_STATUS_POLL)
1455 {
1456 m_dwDynamicFlags &= ~NDF_FORCE_STATUS_POLL;
1457 return true;
1458 }
1459 return (m_iStatus != STATUS_UNMANAGED) &&
1460 (!(m_dwFlags & NF_DISABLE_STATUS_POLL)) &&
1461 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_STATUS_POLL)) &&
1462 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1463 (getMyCluster() == NULL) &&
1464 ((UINT32)(time(NULL) - m_lastStatusPoll) > g_dwStatusPollingInterval);
1465 }
1466
1467 inline bool Node::isReadyForConfigurationPoll()
1468 {
1469 if (m_isDeleted)
1470 return false;
1471 if (m_dwDynamicFlags & NDF_FORCE_CONFIGURATION_POLL)
1472 {
1473 m_dwDynamicFlags &= ~NDF_FORCE_CONFIGURATION_POLL;
1474 return true;
1475 }
1476 return (m_iStatus != STATUS_UNMANAGED) &&
1477 (!(m_dwFlags & NF_DISABLE_CONF_POLL)) &&
1478 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_CONFIG_POLL)) &&
1479 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1480 ((UINT32)(time(NULL) - m_lastConfigurationPoll) > g_dwConfigurationPollingInterval);
1481 }
1482
1483 inline bool Node::isReadyForDiscoveryPoll()
1484 {
1485 if (m_isDeleted)
1486 return false;
1487 return (g_flags & AF_ENABLE_NETWORK_DISCOVERY) &&
1488 (m_iStatus != STATUS_UNMANAGED) &&
1489 (!(m_dwFlags & NF_DISABLE_DISCOVERY_POLL)) &&
1490 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_DISCOVERY_POLL)) &&
1491 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1492 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1493 ((UINT32)(time(NULL) - m_lastDiscoveryPoll) > g_dwDiscoveryPollingInterval);
1494 }
1495
1496 inline bool Node::isReadyForRoutePoll()
1497 {
1498 if (m_isDeleted)
1499 return false;
1500 return (m_iStatus != STATUS_UNMANAGED) &&
1501 (!(m_dwFlags & NF_DISABLE_ROUTE_POLL)) &&
1502 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_ROUTE_POLL)) &&
1503 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1504 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1505 ((UINT32)(time(NULL) - m_lastRTUpdate) > g_dwRoutingTableUpdateInterval);
1506 }
1507
1508 inline bool Node::isReadyForTopologyPoll()
1509 {
1510 if (m_isDeleted)
1511 return false;
1512 return (m_iStatus != STATUS_UNMANAGED) &&
1513 (!(m_dwFlags & NF_DISABLE_TOPOLOGY_POLL)) &&
1514 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_TOPOLOGY_POLL)) &&
1515 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1516 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1517 ((UINT32)(time(NULL) - m_lastTopologyPoll) > g_dwTopologyPollingInterval);
1518 }
1519
1520 inline bool Node::isReadyForInstancePoll()
1521 {
1522 if (m_isDeleted)
1523 return false;
1524 return (m_iStatus != STATUS_UNMANAGED) &&
1525 (!(m_dwFlags & NF_DISABLE_CONF_POLL)) &&
1526 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_INSTANCE_POLL)) &&
1527 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1528 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1529 ((UINT32)(time(NULL) - m_lastInstancePoll) > g_instancePollingInterval);
1530 }
1531
1532 inline void Node::lockForStatusPoll()
1533 {
1534 lockProperties();
1535 m_dwDynamicFlags |= NDF_QUEUED_FOR_STATUS_POLL;
1536 unlockProperties();
1537 }
1538
1539 inline void Node::lockForConfigurationPoll()
1540 {
1541 lockProperties();
1542 m_dwDynamicFlags |= NDF_QUEUED_FOR_CONFIG_POLL;
1543 unlockProperties();
1544 }
1545
1546 inline void Node::lockForInstancePoll()
1547 {
1548 lockProperties();
1549 m_dwDynamicFlags |= NDF_QUEUED_FOR_INSTANCE_POLL;
1550 unlockProperties();
1551 }
1552
1553 inline void Node::lockForDiscoveryPoll()
1554 {
1555 lockProperties();
1556 m_dwDynamicFlags |= NDF_QUEUED_FOR_DISCOVERY_POLL;
1557 unlockProperties();
1558 }
1559
1560 inline void Node::lockForTopologyPoll()
1561 {
1562 lockProperties();
1563 m_dwDynamicFlags |= NDF_QUEUED_FOR_TOPOLOGY_POLL;
1564 unlockProperties();
1565 }
1566
1567 inline void Node::lockForRoutePoll()
1568 {
1569 lockProperties();
1570 m_dwDynamicFlags |= NDF_QUEUED_FOR_ROUTE_POLL;
1571 unlockProperties();
1572 }
1573
1574 /**
1575 * Subnet
1576 */
1577 class NXCORE_EXPORTABLE Subnet : public NetObj
1578 {
1579 friend void Node::buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedSubnet, bool vpnLink, bool includeEndNodes);
1580
1581 protected:
1582 InetAddress m_ipAddress;
1583 UINT32 m_zoneId;
1584 bool m_bSyntheticMask;
1585
1586 virtual void prepareForDeletion();
1587
1588 virtual void fillMessageInternal(NXCPMessage *pMsg);
1589
1590 void buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedNode, bool includeEndNodes);
1591
1592 public:
1593 Subnet();
1594 Subnet(const InetAddress& addr, UINT32 dwZone, bool bSyntheticMask);
1595 virtual ~Subnet();
1596
1597 virtual int getObjectClass() const { return OBJECT_SUBNET; }
1598
1599 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1600 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1601 virtual BOOL loadFromDatabase(UINT32 dwId);
1602
1603 void addNode(Node *node) { AddChild(node); node->AddParent(this); calculateCompoundStatus(TRUE); }
1604
1605 virtual bool showThresholdSummary();
1606
1607 const InetAddress& getIpAddress() { return m_ipAddress; }
1608 UINT32 getZoneId() { return m_zoneId; }
1609 bool isSyntheticMask() { return m_bSyntheticMask; }
1610
1611 void setCorrectMask(const InetAddress& addr);
1612
1613 bool findMacAddress(const InetAddress& ipAddr, BYTE *macAddr);
1614
1615 UINT32 *buildAddressMap(int *length);
1616 };
1617
1618 /**
1619 * Universal root object
1620 */
1621 class NXCORE_EXPORTABLE UniversalRoot : public NetObj
1622 {
1623 public:
1624 UniversalRoot();
1625 virtual ~UniversalRoot();
1626
1627 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1628 virtual void LoadFromDB();
1629
1630 void LinkChildObjects();
1631 void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
1632 };
1633
1634 /**
1635 * Service root
1636 */
1637 class NXCORE_EXPORTABLE ServiceRoot : public UniversalRoot
1638 {
1639 public:
1640 ServiceRoot();
1641 virtual ~ServiceRoot();
1642
1643 virtual int getObjectClass() const { return OBJECT_SERVICEROOT; }
1644
1645 virtual bool showThresholdSummary();
1646 };
1647
1648 /**
1649 * Template root
1650 */
1651 class NXCORE_EXPORTABLE TemplateRoot : public UniversalRoot
1652 {
1653 public:
1654 TemplateRoot();
1655 virtual ~TemplateRoot();
1656
1657 virtual int getObjectClass() const { return OBJECT_TEMPLATEROOT; }
1658 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1659 };
1660
1661 /**
1662 * Generic container object
1663 */
1664 class NXCORE_EXPORTABLE Container : public NetObj
1665 {
1666 private:
1667 UINT32 *m_pdwChildIdList;
1668 UINT32 m_dwChildIdListSize;
1669
1670 protected:
1671 UINT32 m_flags;
1672 UINT32 m_dwCategory;
1673 NXSL_VM *m_bindFilter;
1674 TCHAR *m_bindFilterSource;
1675
1676 virtual void fillMessageInternal(NXCPMessage *pMsg);
1677 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1678
1679 public:
1680 Container();
1681 Container(const TCHAR *pszName, UINT32 dwCategory);
1682 virtual ~Container();
1683
1684 virtual int getObjectClass() const { return OBJECT_CONTAINER; }
1685
1686 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1687 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1688 virtual BOOL loadFromDatabase(UINT32 dwId);
1689
1690 virtual bool showThresholdSummary();
1691
1692 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1693
1694 UINT32 getCategory() { return m_dwCategory; }
1695
1696 void linkChildObjects();
1697 void linkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
1698
1699 AutoBindDecision isSuitableForNode(Node *node);
1700 bool isAutoBindEnabled() { return (m_flags & CF_AUTO_BIND) ? true : false; }
1701 bool isAutoUnbindEnabled() { return ((m_flags & (CF_AUTO_BIND | CF_AUTO_UNBIND)) == (CF_AUTO_BIND | CF_AUTO_UNBIND)) ? true : false; }
1702
1703 void setAutoBindFilter(const TCHAR *script);
1704 };
1705
1706 /**
1707 * Template group object
1708 */
1709 class NXCORE_EXPORTABLE TemplateGroup : public Container
1710 {
1711 public:
1712 TemplateGroup() : Container() { }
1713 TemplateGroup(const TCHAR *pszName) : Container(pszName, 0) { m_iStatus = STATUS_NORMAL; }
1714 virtual ~TemplateGroup() { }
1715
1716 virtual int getObjectClass() const { return OBJECT_TEMPLATEGROUP; }
1717 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1718
1719 virtual bool showThresholdSummary();
1720 };
1721
1722 /**
1723 * Rack object
1724 */
1725 class NXCORE_EXPORTABLE Rack : public Container
1726 {
1727 protected:
1728 int m_height; // Rack height in units
1729
1730 virtual void fillMessageInternal(NXCPMessage *pMsg);
1731 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1732
1733 public:
1734 Rack();
1735 Rack(const TCHAR *name, int height);
1736 virtual ~Rack();
1737
1738 virtual int getObjectClass() const { return OBJECT_RACK; }
1739
1740 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1741 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1742 virtual BOOL loadFromDatabase(UINT32 dwId);
1743 };
1744
1745 /**
1746 * Zone object
1747 */
1748 class Zone : public NetObj
1749 {
1750 protected:
1751 UINT32 m_zoneId;
1752 UINT32 m_agentProxy;
1753 UINT32 m_snmpProxy;
1754 UINT32 m_icmpProxy;
1755 InetAddressIndex *m_idxNodeByAddr;
1756 InetAddressIndex *m_idxInterfaceByAddr;
1757 InetAddressIndex *m_idxSubnetByAddr;
1758
1759 virtual void fillMessageInternal(NXCPMessage *pMsg);
1760 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1761
1762 public:
1763 Zone();
1764 Zone(UINT32 zoneId, const TCHAR *name);
1765 virtual ~Zone();
1766
1767 virtual int getObjectClass() const { return OBJECT_ZONE; }
1768
1769 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1770 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1771 virtual BOOL loadFromDatabase(UINT32 dwId);
1772
1773 virtual bool showThresholdSummary();
1774
1775 UINT32 getZoneId() { return m_zoneId; }
1776 UINT32 getAgentProxy() { return m_agentProxy; }
1777 UINT32 getSnmpProxy() { return m_snmpProxy; }
1778 UINT32 getIcmpProxy() { return m_icmpProxy; }
1779
1780 void addSubnet(Subnet *pSubnet) { AddChild(pSubnet); pSubnet->AddParent(this); }
1781
1782 void addToIndex(Subnet *subnet) { m_idxSubnetByAddr->put(subnet->getIpAddress(), subnet); }
1783 void addToIndex(Interface *iface) { m_idxInterfaceByAddr->put(iface->getIpAddressList(), iface); }
1784 void addToIndex(const InetAddress& addr, Interface *iface) { m_idxInterfaceByAddr->put(addr, iface); }
1785 void addToIndex(Node *node) { m_idxNodeByAddr->put(node->getIpAddress(), node); }
1786 void removeFromIndex(Subnet *subnet) { m_idxSubnetByAddr->remove(subnet->getIpAddress()); }
1787 void removeFromIndex(Interface *iface);
1788 void removeFromInterfaceIndex(const InetAddress& addr) { m_idxInterfaceByAddr->remove(addr); }
1789 void removeFromIndex(Node *node) { m_idxNodeByAddr->remove(node->getIpAddress()); }
1790 void updateInterfaceIndex(const InetAddress& oldIp, const InetAddress& newIp, Interface *iface);
1791 Subnet *getSubnetByAddr(const InetAddress& ipAddr) { return (Subnet *)m_idxSubnetByAddr->get(ipAddr); }
1792 Interface *getInterfaceByAddr(const InetAddress& ipAddr) { return (Interface *)m_idxInterfaceByAddr->get(ipAddr); }
1793 Node *getNodeByAddr(const InetAddress& ipAddr) { return (Node *)m_idxNodeByAddr->get(ipAddr); }
1794 Subnet *findSubnet(bool (*comparator)(NetObj *, void *), void *data) { return (Subnet *)m_idxSubnetByAddr->find(comparator, data); }
1795 Interface *findInterface(bool (*comparator)(NetObj *, void *), void *data) { return (Interface *)m_idxInterfaceByAddr->find(comparator, data); }
1796 Node *findNode(bool (*comparator)(NetObj *, void *), void *data) { return (Node *)m_idxNodeByAddr->find(comparator, data); }
1797 void forEachSubnet(void (*callback)(const InetAddress& addr, NetObj *, void *), void *data) { m_idxSubnetByAddr->forEach(callback, data); }
1798 };
1799
1800 /**
1801 * Entire network
1802 */
1803 class NXCORE_EXPORTABLE Network : public NetObj
1804 {
1805 public:
1806 Network();
1807 virtual ~Network();
1808
1809 virtual int getObjectClass() const { return OBJECT_NETWORK; }
1810 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1811
1812 virtual bool showThresholdSummary();
1813
1814 void AddSubnet(Subnet *pSubnet) { AddChild(pSubnet); pSubnet->AddParent(this); }
1815 void AddZone(Zone *pZone) { AddChild(pZone); pZone->AddParent(this); }
1816 void LoadFromDB(void);
1817 };
1818
1819 /**
1820 * Condition
1821 */
1822 class NXCORE_EXPORTABLE Condition : public NetObj
1823 {
1824 protected:
1825 UINT32 m_dciCount;
1826 INPUT_DCI *m_dciList;
1827 TCHAR *m_scriptSource;
1828 NXSL_VM *m_script;
1829 UINT32 m_activationEventCode;
1830 UINT32 m_deactivationEventCode;
1831 UINT32 m_sourceObject;
1832 int m_activeStatus;
1833 int m_inactiveStatus;
1834 bool m_isActive;
1835 time_t m_lastPoll;
1836 bool m_queuedForPolling;
1837
1838 virtual void fillMessageInternal(NXCPMessage *pMsg);
1839 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1840
1841 public:
1842 Condition();
1843 Condition(bool hidden);
1844 virtual ~Condition();
1845
1846 virtual int getObjectClass() const { return OBJECT_CONDITION; }
1847
1848 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1849 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1850 virtual BOOL loadFromDatabase(UINT32 dwId);
1851
1852 void lockForPoll();
1853 void doPoll(PollerInfo *poller);
1854 void check();
1855
1856 bool isReadyForPoll()
1857 {
1858 return ((m_iStatus != STATUS_UNMANAGED) &&
1859 (!m_queuedForPolling) && (!m_isDeleted) &&
1860 ((UINT32)time(NULL) - (UINT32)m_lastPoll > g_dwConditionPollingInterval));
1861 }
1862
1863 int getCacheSizeForDCI(UINT32 itemId, bool noLock);
1864 };
1865
1866 /**
1867 * Generic agent policy object
1868 */
1869 class NXCORE_EXPORTABLE AgentPolicy : public NetObj
1870 {
1871 protected:
1872 UINT32 m_version;
1873 int m_policyType;
1874
1875 BOOL savePolicyCommonProperties(DB_HANDLE hdb);
1876
1877 virtual void fillMessageInternal(NXCPMessage *pMsg);
1878 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1879
1880 public:
1881 AgentPolicy(int type);
1882 AgentPolicy(const TCHAR *name, int type);
1883
1884 virtual int getObjectClass() const { return OBJECT_AGENTPOLICY; }
1885
1886 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1887 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1888 virtual BOOL loadFromDatabase(UINT32 dwId);
1889
1890 virtual bool createDeploymentMessage(NXCPMessage *msg);
1891 virtual bool createUninstallMessage(NXCPMessage *msg);
1892
1893 void linkNode(Node *node) { AddChild(node); node->AddParent(this); }
1894 void unlinkNode(Node *node) { DeleteChild(node); node->DeleteParent(this); }
1895 };
1896
1897 /**
1898 * Agent config policy object
1899 */
1900 class NXCORE_EXPORTABLE AgentPolicyConfig : public AgentPolicy
1901 {
1902 protected:
1903 TCHAR *m_fileContent;
1904
1905 virtual void fillMessageInternal(NXCPMessage *pMsg);
1906 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1907
1908 public:
1909 AgentPolicyConfig();
1910 AgentPolicyConfig(const TCHAR *name);
1911 virtual ~AgentPolicyConfig();
1912
1913 virtual int getObjectClass() const { return OBJECT_AGENTPOLICY_CONFIG; }
1914
1915 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1916 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1917 virtual BOOL loadFromDatabase(UINT32 dwId);
1918
1919 virtual bool createDeploymentMessage(NXCPMessage *msg);
1920 virtual bool createUninstallMessage(NXCPMessage *msg);
1921 };
1922
1923 /**
1924 * Policy group object
1925 */
1926 class NXCORE_EXPORTABLE PolicyGroup : public Container
1927 {
1928 public:
1929 PolicyGroup() : Container() { }
1930 PolicyGroup(const TCHAR *pszName) : Container(pszName, 0) { }
1931 virtual ~PolicyGroup() { }
1932
1933 virtual int getObjectClass() const { return OBJECT_POLICYGROUP; }
1934 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1935
1936 virtual bool showThresholdSummary();
1937 };
1938
1939 /**
1940 * Policy root
1941 */
1942 class NXCORE_EXPORTABLE PolicyRoot : public UniversalRoot
1943 {
1944 public:
1945 PolicyRoot();
1946 virtual ~PolicyRoot();
1947
1948 virtual int getObjectClass() const { return OBJECT_POLICYROOT; }
1949 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1950 };
1951
1952 /**
1953 * Network map root
1954 */
1955 class NXCORE_EXPORTABLE NetworkMapRoot : public UniversalRoot
1956 {
1957 public:
1958 NetworkMapRoot();
1959 virtual ~NetworkMapRoot();
1960
1961 virtual int getObjectClass() const { return OBJECT_NETWORKMAPROOT; }
1962 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1963 };
1964
1965 /**
1966 * Network map group object
1967 */
1968 class NXCORE_EXPORTABLE NetworkMapGroup : public Container
1969 {
1970 public:
1971 NetworkMapGroup() : Container() { }
1972 NetworkMapGroup(const TCHAR *pszName) : Container(pszName, 0) { }
1973 virtual ~NetworkMapGroup() { }
1974
1975 virtual int getObjectClass() const { return OBJECT_NETWORKMAPGROUP; }
1976 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1977
1978 virtual bool showThresholdSummary();
1979 };
1980
1981 /**
1982 * Network map object
1983 */
1984 class NXCORE_EXPORTABLE NetworkMap : public NetObj
1985 {
1986 protected:
1987 int m_mapType;
1988 UINT32 m_seedObject;
1989 int m_discoveryRadius;
1990 int m_layout;
1991 UINT32 m_flags;
1992 int m_backgroundColor;
1993 int m_defaultLinkColor;
1994 int m_defaultLinkRouting;
1995 uuid m_background;
1996 double m_backgroundLatitude;
1997 double m_backgroundLongitude;
1998 int m_backgroundZoom;
1999 UINT32 m_nextElementId;
2000 ObjectArray<NetworkMapElement> *m_elements;
2001 ObjectArray<NetworkMapLink> *m_links;
2002 TCHAR *m_filterSource;
2003 NXSL_VM *m_filter;
2004
2005 virtual void fillMessageInternal(NXCPMessage *pMsg);
2006 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2007
2008 void updateObjects(nxmap_ObjList *objects);
2009 UINT32 objectIdFromElementId(UINT32 eid);
2010 UINT32 elementIdFromObjectId(UINT32 eid);
2011
2012 void setFilter(const TCHAR *filter);
2013
2014 public:
2015 NetworkMap();
2016 NetworkMap(int type, UINT32 seed);
2017 virtual ~NetworkMap();
2018
2019 virtual int getObjectClass() const { return OBJECT_NETWORKMAP; }
2020 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2021
2022 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2023 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2024 virtual BOOL loadFromDatabase(UINT32 dwId);
2025
2026 virtual void onObjectDelete(UINT32 dwObjectId);
2027
2028 void updateContent();
2029
2030 int getBackgroundColor() { return m_backgroundColor; }
2031 void setBackgroundColor(int color) { m_backgroundColor = color; }
2032
2033 bool isAllowedOnMap(NetObj *object);
2034 };
2035
2036 /**
2037 * Dashboard tree root
2038 */
2039 class NXCORE_EXPORTABLE DashboardRoot : public UniversalRoot
2040 {
2041 public:
2042 DashboardRoot();
2043 virtual ~DashboardRoot();
2044
2045 virtual int getObjectClass() const { return OBJECT_DASHBOARDROOT; }
2046 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2047 };
2048
2049 /**
2050 * Dashboard element
2051 */
2052 class DashboardElement
2053 {
2054 public:
2055 int m_type;
2056 TCHAR *m_data;
2057 TCHAR *m_layout;
2058
2059 DashboardElement() { m_data = NULL; m_layout = NULL; }
2060 ~DashboardElement() { safe_free(m_data); safe_free(m_layout); }
2061 };
2062
2063 /**
2064 * Dashboard object
2065 */
2066 class NXCORE_EXPORTABLE Dashboard : public Container
2067 {
2068 protected:
2069 int m_numColumns;
2070 UINT32 m_options;
2071 ObjectArray<DashboardElement> *m_elements;
2072
2073 virtual void fillMessageInternal(NXCPMessage *pMsg);
2074 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2075
2076 public:
2077 Dashboard();
2078 Dashboard(const TCHAR *name);
2079 virtual ~Dashboard();
2080
2081 virtual int getObjectClass() const { return OBJECT_DASHBOARD; }
2082 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2083
2084 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2085 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2086 virtual BOOL loadFromDatabase(UINT32 dwId);
2087
2088 virtual bool showThresholdSummary();
2089 };
2090
2091 /**
2092 * SLM check object
2093 */
2094 class NXCORE_EXPORTABLE SlmCheck : public NetObj
2095 {
2096 protected:
2097 static NXSL_VariableSystem m_nxslConstants;
2098
2099 Threshold *m_threshold;
2100 enum CheckType { check_undefined = 0, check_script = 1, check_threshold = 2 } m_type;
2101 TCHAR *m_script;
2102 NXSL_VM *m_pCompiledScript;
2103 TCHAR m_reason[256];
2104 bool m_isTemplate;
2105 UINT32 m_templateId;
2106 UINT32 m_currentTicketId;
2107
2108 virtual void onObjectDelete(UINT32 objectId);
2109
2110 virtual void fillMessageInternal(NXCPMessage *pMsg);
2111 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2112
2113 void setScript(const TCHAR *script);
2114 UINT32 getOwnerId();
2115 NXSL_Value *getNodeObjectForNXSL();
2116 bool insertTicket();
2117 void closeTicket();
2118 void setReason(const TCHAR *reason) { nx_strncpy(m_reason, CHECK_NULL_EX(reason), 256); }
2119 void compileScript();
2120
2121 public:
2122 SlmCheck();
2123 SlmCheck(const TCHAR *name, bool isTemplate);
2124 SlmCheck(SlmCheck *tmpl);
2125 virtual ~SlmCheck();
2126
2127 static void init();
2128
2129 virtual int getObjectClass() const { return OBJECT_SLMCHECK; }
2130
2131 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2132 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2133 virtual BOOL loadFromDatabase(UINT32 dwId);
2134
2135 virtual void postModify();
2136
2137 void execute();
2138 void updateFromTemplate(SlmCheck *tmpl);
2139
2140 bool isTemplate() { return m_isTemplate; }
2141 UINT32 getTemplateId() { return m_templateId; }
2142 const TCHAR *getReason() { return m_reason; }
2143 };
2144
2145 /**
2146 * Service container - common logic for BusinessService, NodeLink and BusinessServiceRoot
2147 */
2148 class NXCORE_EXPORTABLE ServiceContainer : public Container
2149 {
2150 enum Period { DAY, WEEK, MONTH };
2151
2152 protected:
2153 time_t m_prevUptimeUpdateTime;
2154 int m_prevUptimeUpdateStatus;
2155 double m_uptimeDay;
2156 double m_uptimeWeek;
2157 double m_uptimeMonth;
2158 INT32 m_downtimeDay;
2159 INT32 m_downtimeWeek;
2160 INT32 m_downtimeMonth;
2161 INT32 m_prevDiffDay;
2162 INT32 m_prevDiffWeek;
2163 INT32 m_prevDiffMonth;
2164
2165 static INT32 logRecordId;
2166 static INT32 getSecondsInMonth();
2167 static INT32 getSecondsInPeriod(Period period) { return period == MONTH ? getSecondsInMonth() : (period == WEEK ? (3600 * 24 * 7) : (3600 * 24)); }
2168 static INT32 getSecondsSinceBeginningOf(Period period, time_t *beginTime = NULL);
2169
2170 virtual void fillMessageInternal(NXCPMessage *pMsg);
2171 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2172
2173 void initServiceContainer();
2174 BOOL addHistoryRecord();
2175 double getUptimeFromDBFor(Period period, INT32 *downtime);
2176
2177 public:
2178 ServiceContainer();
2179 ServiceContainer(const TCHAR *pszName);
2180
2181 virtual BOOL loadFromDatabase(UINT32 dwId);
2182 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2183 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2184
2185 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2186 virtual void setStatus(int newStatus);
2187
2188 virtual bool showThresholdSummary();
2189
2190 void initUptimeStats();
2191 void updateUptimeStats(time_t currentTime = 0, BOOL updateChilds = FALSE);
2192 };
2193
2194 /**
2195 * Business service root
2196 */
2197 class NXCORE_EXPORTABLE BusinessServiceRoot : public ServiceContainer
2198 {
2199 public:
2200 BusinessServiceRoot();
2201 virtual ~BusinessServiceRoot();
2202
2203 virtual int getObjectClass() const { return OBJECT_BUSINESSSERVICEROOT; }
2204
2205 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2206 void LoadFromDB();
2207
2208 void LinkChildObjects();
2209 void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
2210 };
2211
2212 /**
2213 * Business service object
2214 */
2215 class NXCORE_EXPORTABLE BusinessService : public ServiceContainer
2216 {
2217 protected:
2218 bool m_busy;
2219 bool m_pollingDisabled;
2220 time_t m_lastPollTime;
2221 int m_lastPollStatus;
2222
2223 virtual void prepareForDeletion();
2224
2225 virtual void fillMessageInternal(NXCPMessage *pMsg);
2226 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2227
2228 public:
2229 BusinessService();
2230 BusinessService(const TCHAR *name);
2231 virtual ~BusinessService();
2232
2233 virtual int getObjectClass() const { return OBJECT_BUSINESSSERVICE; }
2234
2235 virtual BOOL loadFromDatabase(UINT32 dwId);
2236 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2237 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2238
2239 bool isReadyForPolling();
2240 void lockForPolling();
2241 void poll(PollerInfo *poller);
2242 void poll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
2243
2244 void getApplicableTemplates(ServiceContainer *target, ObjectArray<SlmCheck> *templates);
2245 };
2246
2247 /**
2248 * Node link object for business service
2249 */
2250 class NXCORE_EXPORTABLE NodeLink : public ServiceContainer
2251 {
2252 protected:
2253 UINT32 m_nodeId;
2254
2255 virtual void onObjectDelete(UINT32 dwObjectId);
2256
2257 virtual void fillMessageInternal(NXCPMessage *pMsg);
2258 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2259
2260 void applyTemplate(SlmCheck *tmpl);
2261
2262 public:
2263 NodeLink();
2264 NodeLink(const TCHAR *name, UINT32 nodeId);
2265 virtual ~NodeLink();
2266
2267 virtual int getObjectClass() const { return OBJECT_NODELINK; }
2268
2269 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2270 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2271 virtual BOOL loadFromDatabase(UINT32 dwId);
2272
2273 void execute();
2274 void applyTemplates();
2275
2276 UINT32 getNodeId() { return m_nodeId; }
2277 };
2278
2279 /**
2280 * Get IP address for object
2281 */
2282 inline const InetAddress& GetObjectIpAddress(NetObj *object)
2283 {
2284 if (object->getObjectClass() == OBJECT_NODE)
2285 return ((Node *)object)->getIpAddress();
2286 if (object->getObjectClass() == OBJECT_SUBNET)
2287 return ((Subnet *)object)->getIpAddress();
2288 if (object->getObjectClass() == OBJECT_ACCESSPOINT)
2289 return ((AccessPoint *)object)->getIpAddress();
2290 return InetAddress::INVALID;
2291 }
2292
2293 //
2294 // Container category information
2295 //
2296
2297 struct CONTAINER_CATEGORY
2298 {
2299 UINT32 dwCatId;
2300 TCHAR szName[MAX_OBJECT_NAME];
2301 TCHAR *pszDescription;
2302 UINT32 dwImageId;
2303 };
2304
2305
2306 //
2307 // Functions
2308 //
2309
2310 void ObjectsInit();
2311
2312 void NXCORE_EXPORTABLE NetObjInsert(NetObj *pObject, BOOL bNewObject);
2313 void NetObjDeleteFromIndexes(NetObj *pObject);
2314 void NetObjDelete(NetObj *pObject);
2315
2316 void UpdateInterfaceIndex(const InetAddress& oldIpAddr, const InetAddress& newIpAddr, Interface *iface);
2317 ComponentTree *BuildComponentTree(Node *node, SNMP_Transport *snmp);
2318
2319 void NXCORE_EXPORTABLE MacDbAddAccessPoint(AccessPoint *ap);
2320 void NXCORE_EXPORTABLE MacDbAddInterface(Interface *iface);
2321 void NXCORE_EXPORTABLE MacDbAddObject(const BYTE *macAddr, NetObj *object);
2322 void NXCORE_EXPORTABLE MacDbRemove(const BYTE *macAddr);
2323 NetObj NXCORE_EXPORTABLE *MacDbFind(const BYTE *macAddr);
2324
2325 NetObj NXCORE_EXPORTABLE *FindObjectById(UINT32 dwId, int objClass = -1);
2326 NetObj NXCORE_EXPORTABLE *FindObjectByName(const TCHAR *name, int objClass);
2327 NetObj NXCORE_EXPORTABLE *FindObjectByGUID(const uuid& guid, int objClass);
2328 const TCHAR NXCORE_EXPORTABLE *GetObjectName(DWORD id, const TCHAR *defaultName);
2329 Template NXCORE_EXPORTABLE *FindTemplateByName(const TCHAR *pszName);
2330 Node NXCORE_EXPORTABLE *FindNodeByIP(UINT32 zoneId, const InetAddress& ipAddr);
2331 Node NXCORE_EXPORTABLE *FindNodeByIP(UINT32 zoneId, const InetAddressList *ipAddrList);
2332 Node NXCORE_EXPORTABLE *FindNodeByMAC(const BYTE *macAddr);
2333 Node NXCORE_EXPORTABLE *FindNodeByBridgeId(const BYTE *bridgeId);
2334 Node NXCORE_EXPORTABLE *FindNodeByLLDPId(const TCHAR *lldpId);
2335 Interface NXCORE_EXPORTABLE *FindInterfaceByIP(UINT32 zoneId, const InetAddress& ipAddr);
2336 Interface NXCORE_EXPORTABLE *FindInterfaceByMAC(const BYTE *macAddr);
2337 Interface NXCORE_EXPORTABLE *FindInterfaceByDescription(const TCHAR *description);
2338 Subnet NXCORE_EXPORTABLE *FindSubnetByIP(UINT32 zoneId, const InetAddress& ipAddr);
2339 Subnet NXCORE_EXPORTABLE *FindSubnetForNode(UINT32 zoneId, const InetAddress& nodeAddr);
2340 MobileDevice NXCORE_EXPORTABLE *FindMobileDeviceByDeviceID(const TCHAR *deviceId);
2341 AccessPoint NXCORE_EXPORTABLE *FindAccessPointByMAC(const BYTE *macAddr);
2342 UINT32 NXCORE_EXPORTABLE FindLocalMgmtNode();
2343 CONTAINER_CATEGORY NXCORE_EXPORTABLE *FindContainerCategory(UINT32 dwId);
2344 Zone NXCORE_EXPORTABLE *FindZoneByGUID(UINT32 dwZoneGUID);
2345 Cluster NXCORE_EXPORTABLE *FindClusterByResourceIP(UINT32 zone, const InetAddress& ipAddr);
2346 bool NXCORE_EXPORTABLE IsClusterIP(UINT32 zone, const InetAddress& ipAddr);
2347
2348 BOOL LoadObjects();
2349 void DumpObjects(CONSOLE_CTX pCtx, const TCHAR *filter);
2350
2351 void DeleteUserFromAllObjects(UINT32 dwUserId);
2352
2353 bool IsValidParentClass(int iChildClass, int iParentClass);
2354 bool IsAgentPolicyObject(NetObj *object);
2355 bool IsEventSource(int objectClass);
2356
2357 int DefaultPropagatedStatus(int iObjectStatus);
2358 int GetDefaultStatusCalculation(int *pnSingleThreshold, int **ppnThresholds);
2359
2360 PollerInfo *RegisterPoller(PollerType type, NetObj *object);
2361 void ShowPollers(CONSOLE_CTX console);
2362
2363 /**
2364 * Global variables
2365 */
2366 extern Network NXCORE_EXPORTABLE *g_pEntireNet;
2367 extern ServiceRoot NXCORE_EXPORTABLE *g_pServiceRoot;
2368 extern TemplateRoot NXCORE_EXPORTABLE *g_pTemplateRoot;
2369 extern PolicyRoot NXCORE_EXPORTABLE *g_pPolicyRoot;
2370 extern NetworkMapRoot NXCORE_EXPORTABLE *g_pMapRoot;
2371 extern DashboardRoot NXCORE_EXPORTABLE *g_pDashboardRoot;
2372 extern BusinessServiceRoot NXCORE_EXPORTABLE *g_pBusinessServiceRoot;
2373
2374 extern UINT32 NXCORE_EXPORTABLE g_dwMgmtNode;
2375 extern UINT32 g_dwNumCategories;
2376 extern CONTAINER_CATEGORY *g_pContainerCatList;
2377 extern const TCHAR *g_szClassName[];
2378 extern BOOL g_bModificationsLocked;
2379 extern Queue *g_pTemplateUpdateQueue;
2380
2381 extern ObjectIndex NXCORE_EXPORTABLE g_idxObjectById;
2382 extern InetAddressIndex NXCORE_EXPORTABLE g_idxSubnetByAddr;
2383 extern InetAddressIndex NXCORE_EXPORTABLE g_idxInterfaceByAddr;
2384 extern InetAddressIndex NXCORE_EXPORTABLE g_idxNodeByAddr;
2385 extern ObjectIndex NXCORE_EXPORTABLE g_idxZoneByGUID;
2386 extern ObjectIndex NXCORE_EXPORTABLE g_idxNodeById;
2387 extern ObjectIndex NXCORE_EXPORTABLE g_idxClusterById;
2388 extern ObjectIndex NXCORE_EXPORTABLE g_idxMobileDeviceById;
2389 extern ObjectIndex NXCORE_EXPORTABLE g_idxAccessPointById;
2390 extern ObjectIndex NXCORE_EXPORTABLE g_idxConditionById;
2391 extern ObjectIndex NXCORE_EXPORTABLE g_idxServiceCheckById;
2392
2393
2394 #endif /* _nms_objects_h_ */