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