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