ICMP ping timeout made configurable; code refactoring
[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_pollRequestor;
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_lastDownEventId;
605 int m_pendingStatus;
606 int m_pollCount;
607 int m_requiredPollCount;
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_lastDownEventId; }
655 void setLastDownEventId(QWORD id) { m_lastDownEventId = id; }
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 *session, UINT32 rqId, Queue *eventQueue, bool clusterSync, SNMP_Transport *snmpTransport);
671
672 virtual void CreateMessage(CSCPMessage *pMsg);
673 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
674
675 UINT32 wakeUp();
676 void setExpectedState(int state);
677 };
678
679 /**
680 * Network service class
681 */
682 class NetworkService : public NetObj
683 {
684 protected:
685 int m_serviceType; // SSH, POP3, etc.
686 Node *m_hostNode; // Pointer to node object which hosts this service
687 UINT32 m_pollerNode; // ID of node object which is used for polling
688 // If 0, m_pHostNode->m_dwPollerNode will be used
689 WORD m_proto; // Protocol (TCP, UDP, etc.)
690 WORD m_port; // TCP or UDP port number
691 TCHAR *m_request; // Service-specific request
692 TCHAR *m_response; // Service-specific expected response
693 int m_pendingStatus;
694 int m_pollCount;
695 int m_requiredPollCount;
696
697 virtual void onObjectDelete(UINT32 dwObjectId);
698
699 public:
700 NetworkService();
701 NetworkService(int iServiceType, WORD wProto, WORD wPort,
702 TCHAR *pszRequest, TCHAR *pszResponse,
703 Node *pHostNode = NULL, UINT32 dwPollerNode = 0);
704 virtual ~NetworkService();
705
706 virtual int Type() { return OBJECT_NETWORKSERVICE; }
707
708 virtual BOOL SaveToDB(DB_HANDLE hdb);
709 virtual bool deleteFromDB(DB_HANDLE hdb);
710 virtual BOOL CreateFromDB(UINT32 dwId);
711
712 void statusPoll(ClientSession *session, UINT32 rqId, Node *pollerNode, Queue *eventQueue);
713
714 virtual void CreateMessage(CSCPMessage *pMsg);
715 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
716 };
717
718 /**
719 * VPN connector class
720 */
721 class VPNConnector : public NetObj
722 {
723 protected:
724 UINT32 m_dwPeerGateway; // Object ID of peer gateway
725 UINT32 m_dwNumLocalNets;
726 IP_NETWORK *m_pLocalNetList;
727 UINT32 m_dwNumRemoteNets;
728 IP_NETWORK *m_pRemoteNetList;
729
730 Node *GetParentNode();
731
732 public:
733 VPNConnector();
734 VPNConnector(bool hidden);
735 virtual ~VPNConnector();
736
737 virtual int Type() { return OBJECT_VPNCONNECTOR; }
738
739 virtual BOOL SaveToDB(DB_HANDLE hdb);
740 virtual bool deleteFromDB(DB_HANDLE hdb);
741 virtual BOOL CreateFromDB(UINT32 dwId);
742
743 virtual void CreateMessage(CSCPMessage *pMsg);
744 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
745
746 BOOL IsLocalAddr(UINT32 dwIpAddr);
747 BOOL IsRemoteAddr(UINT32 dwIpAddr);
748 UINT32 GetPeerGatewayAddr();
749 };
750
751 /**
752 * Common base class for all objects capable of collecting data
753 */
754 class NXCORE_EXPORTABLE DataCollectionTarget : public Template
755 {
756 protected:
757 virtual bool isDataCollectionDisabled();
758
759 public:
760 DataCollectionTarget();
761 DataCollectionTarget(const TCHAR *name);
762 virtual ~DataCollectionTarget();
763
764 virtual bool deleteFromDB(DB_HANDLE hdb);
765
766 virtual void CreateMessage(CSCPMessage *pMsg);
767 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
768
769 virtual UINT32 getInternalItem(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
770
771 UINT32 getTableLastValues(UINT32 dciId, CSCPMessage *msg);
772 UINT32 getThresholdSummary(CSCPMessage *msg, UINT32 baseId);
773 UINT32 getPerfTabDCIList(CSCPMessage *pMsg);
774 void getLastValuesSummary(SummaryTable *tableDefinition, Table *tableData);
775
776 void updateDciCache();
777 void cleanDCIData();
778 void queueItemsForPolling(Queue *pPollerQueue);
779 void processNewDCValue(DCObject *dco, time_t currTime, void *value);
780
781 bool applyTemplateItem(UINT32 dwTemplateId, DCObject *dcObject);
782 void cleanDeletedTemplateItems(UINT32 dwTemplateId, UINT32 dwNumItems, UINT32 *pdwItemList);
783 virtual void unbindFromTemplate(UINT32 dwTemplateId, BOOL bRemoveDCI);
784 };
785
786 /**
787 * Mobile device class
788 */
789 class NXCORE_EXPORTABLE MobileDevice : public DataCollectionTarget
790 {
791 protected:
792 time_t m_lastReportTime;
793 TCHAR *m_deviceId;
794 TCHAR *m_vendor;
795 TCHAR *m_model;
796 TCHAR *m_serialNumber;
797 TCHAR *m_osName;
798 TCHAR *m_osVersion;
799 TCHAR *m_userId;
800 LONG m_batteryLevel;
801
802 public:
803 MobileDevice();
804 MobileDevice(const TCHAR *name, const TCHAR *deviceId);
805 virtual ~MobileDevice();
806
807 virtual int Type() { return OBJECT_MOBILEDEVICE; }
808
809 virtual BOOL CreateFromDB(UINT32 dwId);
810 virtual BOOL SaveToDB(DB_HANDLE hdb);
811 virtual bool deleteFromDB(DB_HANDLE hdb);
812
813 virtual void CreateMessage(CSCPMessage *pMsg);
814 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
815
816 void updateSystemInfo(CSCPMessage *msg);
817 void updateStatus(CSCPMessage *msg);
818
819 const TCHAR *getDeviceId() { return CHECK_NULL_EX(m_deviceId); }
820
821 virtual UINT32 getInternalItem(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
822 };
823
824 /**
825 * Access point class
826 */
827 class NXCORE_EXPORTABLE AccessPoint : public DataCollectionTarget
828 {
829 protected:
830 UINT32 m_nodeId;
831 BYTE m_macAddr[MAC_ADDR_LENGTH];
832 TCHAR *m_vendor;
833 TCHAR *m_model;
834 TCHAR *m_serialNumber;
835 ObjectArray<RadioInterfaceInfo> *m_radioInterfaces;
836
837 public:
838 AccessPoint();
839 AccessPoint(const TCHAR *name, BYTE *macAddr);
840 virtual ~AccessPoint();
841
842 virtual int Type() { return OBJECT_ACCESSPOINT; }
843
844 virtual BOOL CreateFromDB(UINT32 dwId);
845 virtual BOOL SaveToDB(DB_HANDLE hdb);
846 virtual bool deleteFromDB(DB_HANDLE hdb);
847
848 virtual void CreateMessage(CSCPMessage *pMsg);
849 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
850
851 BYTE *getMacAddr() { return m_macAddr; }
852 bool isMyRadio(int rfIndex);
853 void getRadioName(int rfIndex, TCHAR *buffer, size_t bufSize);
854
855 void attachToNode(UINT32 nodeId);
856 void updateRadioInterfaces(ObjectArray<RadioInterfaceInfo> *ri);
857 void updateInfo(const TCHAR *vendor, const TCHAR *model, const TCHAR *serialNumber);
858 };
859
860 /**
861 * Cluster class
862 */
863 class NXCORE_EXPORTABLE Cluster : public DataCollectionTarget
864 {
865 protected:
866 UINT32 m_dwClusterType;
867 UINT32 m_dwNumSyncNets;
868 IP_NETWORK *m_pSyncNetList;
869 UINT32 m_dwNumResources;
870 CLUSTER_RESOURCE *m_pResourceList;
871 UINT32 m_dwFlags;
872 time_t m_tmLastPoll;
873 UINT32 m_zoneId;
874
875 public:
876 Cluster();
877 Cluster(const TCHAR *pszName, UINT32 zoneId);
878 virtual ~Cluster();
879
880 virtual int Type() { return OBJECT_CLUSTER; }
881 virtual BOOL SaveToDB(DB_HANDLE hdb);
882 virtual bool deleteFromDB(DB_HANDLE hdb);
883 virtual BOOL CreateFromDB(UINT32 dwId);
884
885 virtual void CreateMessage(CSCPMessage *pMsg);
886 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
887
888 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
889
890 virtual void unbindFromTemplate(UINT32 dwTemplateId, BOOL bRemoveDCI);
891
892 bool isSyncAddr(UINT32 dwAddr);
893 bool isVirtualAddr(UINT32 dwAddr);
894 bool isResourceOnNode(UINT32 dwResource, UINT32 dwNode);
895 UINT32 getZoneId() { return m_zoneId; }
896
897 void statusPoll(ClientSession *pSession, UINT32 dwRqId, int nPoller);
898 void lockForStatusPoll() { m_dwFlags |= CLF_QUEUED_FOR_STATUS_POLL; }
899 bool isReadyForStatusPoll()
900 {
901 return ((m_iStatus != STATUS_UNMANAGED) && (!m_isDeleted) &&
902 (!(m_dwFlags & CLF_QUEUED_FOR_STATUS_POLL)) &&
903 ((UINT32)time(NULL) - (UINT32)m_tmLastPoll > g_dwStatusPollingInterval))
904 ? true : false;
905 }
906
907 UINT32 collectAggregatedData(DCItem *item, TCHAR *buffer);
908 UINT32 collectAggregatedData(DCTable *table, Table **result);
909 };
910
911 class Subnet;
912
913 /**
914 * Node
915 */
916 class NXCORE_EXPORTABLE Node : public DataCollectionTarget
917 {
918 friend class Subnet;
919
920 protected:
921 TCHAR m_primaryName[MAX_DNS_NAME];
922 UINT32 m_dwFlags;
923 UINT32 m_dwDynamicFlags; // Flags used at runtime by server
924 int m_iPendingStatus;
925 int m_iPollCount;
926 int m_iRequiredPollCount;
927 UINT32 m_zoneId;
928 WORD m_wAgentPort;
929 WORD m_wAuthMethod;
930 TCHAR m_szSharedSecret[MAX_SECRET_LENGTH];
931 int m_iStatusPollType;
932 int m_snmpVersion;
933 WORD m_wSNMPPort;
934 WORD m_nUseIfXTable;
935 SNMP_SecurityContext *m_snmpSecurity;
936 TCHAR m_szObjectId[MAX_OID_LEN * 4];
937 TCHAR m_szAgentVersion[MAX_AGENT_VERSION_LEN];
938 TCHAR m_szPlatformName[MAX_PLATFORM_NAME_LEN];
939 TCHAR *m_sysDescription; // Agent's System.Uname or SNMP sysDescr
940 TCHAR *m_sysName; // SNMP sysName
941 TCHAR *m_lldpNodeId; // lldpLocChassisId combined with lldpLocChassisIdSubtype, or NULL for non-LLDP nodes
942 ObjectArray<LLDP_LOCAL_PORT_INFO> *m_lldpLocalPortInfo;
943 NetworkDeviceDriver *m_driver;
944 void *m_driverData;
945 ObjectArray<AgentParameterDefinition> *m_paramList; // List of supported parameters
946 ObjectArray<AgentTableDefinition> *m_tableList; // List of supported tables
947 time_t m_tLastDiscoveryPoll;
948 time_t m_tLastStatusPoll;
949 time_t m_tLastConfigurationPoll;
950 time_t m_tLastTopologyPoll;
951 time_t m_tLastRTUpdate;
952 time_t m_tFailTimeSNMP;
953 time_t m_tFailTimeAgent;
954 time_t m_tDownSince;
955 MUTEX m_hPollerMutex;
956 MUTEX m_hAgentAccessMutex;
957 MUTEX m_hSmclpAccessMutex;
958 MUTEX m_mutexRTAccess;
959 MUTEX m_mutexTopoAccess;
960 AgentConnectionEx *m_pAgentConnection;
961 SMCLP_Connection *m_smclpConnection;
962 QWORD m_lastAgentTrapId; // ID of last received agent trap
963 UINT32 m_dwPollerNode; // Node used for network service polling
964 UINT32 m_dwProxyNode; // Node used as proxy for agent connection
965 UINT32 m_dwSNMPProxy; // Node used as proxy for SNMP requests
966 QWORD m_qwLastEvents[MAX_LAST_EVENTS];
967 ROUTING_TABLE *m_pRoutingTable;
968 ForwardingDatabase *m_fdb;
969 LinkLayerNeighbors *m_linkLayerNeighbors;
970 VlanList *m_vlans;
971 VrrpInfo *m_vrrpInfo;
972 ObjectArray<WirelessStationInfo> *m_wirelessStations;
973 int m_adoptedApCount;
974 int m_totalApCount;
975 BYTE m_baseBridgeAddress[MAC_ADDR_LENGTH]; // Bridge base address (dot1dBaseBridgeAddress in bridge MIB)
976 nxmap_ObjList *m_pTopology;
977 time_t m_topologyRebuildTimestamp;
978 ServerJobQueue *m_jobQueue;
979 ComponentTree *m_components; // Hardware components
980 ObjectArray<SoftwarePackage> *m_softwarePackages; // installed software packages
981 ObjectArray<WinPerfObject> *m_winPerfObjects; // Windows performance objects
982
983 void pollerLock() { MutexLock(m_hPollerMutex); }
984 void pollerUnlock() { MutexUnlock(m_hPollerMutex); }
985
986 void agentLock() { MutexLock(m_hAgentAccessMutex); }
987 void agentUnlock() { MutexUnlock(m_hAgentAccessMutex); }
988
989 void smclpLock() { MutexLock(m_hSmclpAccessMutex); }
990 void smclpUnlock() { MutexUnlock(m_hSmclpAccessMutex); }
991
992 void routingTableLock() { MutexLock(m_mutexRTAccess); }
993 void routingTableUnlock() { MutexUnlock(m_mutexRTAccess); }
994
995 BOOL checkSNMPIntegerValue(SNMP_Transport *pTransport, const TCHAR *pszOID, int nValue);
996 void checkOSPFSupport(SNMP_Transport *pTransport);
997 void addVrrpInterfaces(InterfaceList *ifList);
998 BOOL resolveName(BOOL useOnlyDNS);
999 void setAgentProxy(AgentConnection *pConn);
1000 void setPrimaryIPAddress(UINT32 addr);
1001
1002 UINT32 getInterfaceCount(Interface **ppInterface);
1003
1004 void checkInterfaceNames(InterfaceList *pIfList);
1005 void checkSubnetBinding(InterfaceList *pIfList);
1006 Subnet *createSubnet(DWORD ipAddr, DWORD netMask, bool syntheticMask);
1007 void checkAgentPolicyBinding(AgentConnection *conn);
1008 void updatePrimaryIpAddr();
1009 bool confPollAgent(UINT32 dwRqId);
1010 bool confPollSnmp(UINT32 dwRqId);
1011 void checkBridgeMib(SNMP_Transport *pTransport);
1012 void checkIfXTable(SNMP_Transport *pTransport);
1013 void executeHookScript(const TCHAR *hookName);
1014 bool checkNetworkPath(UINT32 dwRqId);
1015 bool checkNetworkPathElement(UINT32 nodeId, const TCHAR *nodeType, bool isProxy, UINT32 dwRqId);
1016
1017 void applyUserTemplates();
1018 void doInstanceDiscovery();
1019 StringList *getInstanceList(DCItem *dci);
1020 void updateInstances(DCItem *root, StringList *instances);
1021
1022 void updateContainerMembership();
1023 BOOL updateInterfaceConfiguration(UINT32 dwRqId, UINT32 dwNetMask);
1024
1025 void buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedSubnet, bool includeEndNodes);
1026
1027 virtual bool isDataCollectionDisabled();
1028
1029 virtual void prepareForDeletion();
1030 virtual void onObjectDelete(UINT32 dwObjectId);
1031
1032 public:
1033 Node();
1034 Node(UINT32 dwAddr, UINT32 dwFlags, UINT32 dwProxyNode, UINT32 dwSNMPProxy, UINT32 dwZone);
1035 virtual ~Node();
1036
1037 virtual int Type() { return OBJECT_NODE; }
1038
1039 virtual BOOL SaveToDB(DB_HANDLE hdb);
1040 virtual bool deleteFromDB(DB_HANDLE hdb);
1041 virtual BOOL CreateFromDB(UINT32 dwId);
1042
1043 TCHAR *expandText(const TCHAR *pszTemplate);
1044
1045 Cluster *getMyCluster();
1046
1047 UINT32 getFlags() { return m_dwFlags; }
1048 UINT32 getRuntimeFlags() { return m_dwDynamicFlags; }
1049 UINT32 getZoneId() { return m_zoneId; }
1050 void setLocalMgmtFlag() { m_dwFlags |= NF_IS_LOCAL_MGMT; }
1051 void clearLocalMgmtFlag() { m_dwFlags &= ~NF_IS_LOCAL_MGMT; }
1052
1053 bool isSNMPSupported() { return m_dwFlags & NF_IS_SNMP ? true : false; }
1054 bool isNativeAgent() { return m_dwFlags & NF_IS_NATIVE_AGENT ? true : false; }
1055 bool isBridge() { return m_dwFlags & NF_IS_BRIDGE ? true : false; }
1056 bool isRouter() { return m_dwFlags & NF_IS_ROUTER ? true : false; }
1057 bool isLocalManagement() { return m_dwFlags & NF_IS_LOCAL_MGMT ? true : false; }
1058 bool isPerVlanFdbSupported() { return (m_driver != NULL) ? m_driver->isPerVlanFdbSupported() : false; }
1059 bool isWirelessController() { return m_dwFlags & NF_IS_WIFI_CONTROLLER ? true : false; }
1060
1061 LONG getSNMPVersion() { return m_snmpVersion; }
1062 const TCHAR *getSNMPObjectId() { return m_szObjectId; }
1063 const TCHAR *getAgentVersion() { return m_szAgentVersion; }
1064 const TCHAR *getPlatformName() { return m_szPlatformName; }
1065 const TCHAR *getObjectId() { return m_szObjectId; }
1066 const TCHAR *getSysName() { return CHECK_NULL_EX(m_sysName); }
1067 const TCHAR *getSysDescription() { return CHECK_NULL_EX(m_sysDescription); }
1068 const TCHAR *getLLDPNodeId() { return m_lldpNodeId; }
1069 const TCHAR *getDriverName() { return (m_driver != NULL) ? m_driver->getName() : _T("GENERIC"); }
1070 WORD getAgentPort() { return m_wAgentPort; }
1071 WORD getAuthMethod() { return m_wAuthMethod; }
1072 const TCHAR *getSharedSecret() { return m_szSharedSecret; }
1073
1074 BOOL isDown() { return m_dwDynamicFlags & NDF_UNREACHABLE ? TRUE : FALSE; }
1075 time_t getDownTime() const { return m_tDownSince; }
1076
1077 void addInterface(Interface *pInterface) { AddChild(pInterface); pInterface->AddParent(this); }
1078 Interface *createNewInterface(UINT32 dwAddr, UINT32 dwNetMask, const TCHAR *name = NULL, const TCHAR *descr = NULL,
1079 UINT32 dwIndex = 0, UINT32 dwType = 0, BYTE *pbMacAddr = NULL, UINT32 bridgePort = 0,
1080 UINT32 slot = 0, UINT32 port = 0, bool physPort = false, bool manuallyCreated = false,
1081 bool system = false);
1082 void deleteInterface(Interface *pInterface);
1083
1084 void setPrimaryName(const TCHAR *name) { nx_strncpy(m_primaryName, name, MAX_DNS_NAME); }
1085 void setAgentPort(WORD port) { m_wAgentPort = port; }
1086 void setSnmpPort(WORD port) { m_wSNMPPort = port; }
1087 void changeIPAddress(UINT32 dwIpAddr);
1088 void changeZone(UINT32 newZone);
1089
1090 ARP_CACHE *getArpCache();
1091 InterfaceList *getInterfaceList();
1092 Interface *findInterface(UINT32 dwIndex, UINT32 dwHostAddr);
1093 Interface *findInterface(const TCHAR *name);
1094 Interface *findInterfaceByMAC(const BYTE *macAddr);
1095 Interface *findInterfaceByIP(UINT32 ipAddr);
1096 Interface *findInterfaceBySlotAndPort(UINT32 slot, UINT32 port);
1097 Interface *findBridgePort(UINT32 bridgePortNumber);
1098 BOOL isMyIP(UINT32 dwIpAddr);
1099 void getInterfaceStatusFromSNMP(SNMP_Transport *pTransport, UINT32 dwIndex, int *adminState, int *operState);
1100 void getInterfaceStatusFromAgent(UINT32 dwIndex, int *adminState, int *operState);
1101 ROUTING_TABLE *getRoutingTable();
1102 ROUTING_TABLE *getCachedRoutingTable() { return m_pRoutingTable; }
1103 LinkLayerNeighbors *getLinkLayerNeighbors();
1104 VlanList *getVlans();
1105 BOOL getNextHop(UINT32 dwSrcAddr, UINT32 dwDestAddr, UINT32 *pdwNextHop,
1106 UINT32 *pdwIfIndex, BOOL *pbIsVPN);
1107 ComponentTree *getComponents();
1108 bool ifDescrFromLldpLocalId(BYTE *id, size_t idLen, TCHAR *ifName);
1109
1110 void setRecheckCapsFlag() { m_dwDynamicFlags |= NDF_RECHECK_CAPABILITIES; }
1111 void setDiscoveryPollTimeStamp();
1112 void statusPoll(ClientSession *pSession, UINT32 dwRqId, int nPoller);
1113 void configurationPoll(ClientSession *pSession, UINT32 dwRqId, int nPoller, UINT32 dwNetMask);
1114 void topologyPoll(ClientSession *pSession, UINT32 dwRqId, int nPoller);
1115 void resolveVlanPorts(VlanList *vlanList);
1116 void updateInterfaceNames(ClientSession *pSession, UINT32 dwRqId);
1117 void updateRoutingTable();
1118 bool isReadyForStatusPoll();
1119 bool isReadyForConfigurationPoll();
1120 bool isReadyForDiscoveryPoll();
1121 bool isReadyForRoutePoll();
1122 bool isReadyForTopologyPoll();
1123 void lockForStatusPoll();
1124 void lockForConfigurationPoll();
1125 void lockForDiscoveryPoll();
1126 void lockForRoutePoll();
1127 void lockForTopologyPoll();
1128 void forceConfigurationPoll() { m_dwDynamicFlags |= NDF_FORCE_CONFIGURATION_POLL; }
1129
1130 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1131
1132 BOOL connectToAgent(UINT32 *error = NULL, UINT32 *socketError = NULL);
1133 bool checkAgentTrapId(QWORD id);
1134
1135 bool connectToSMCLP();
1136
1137 virtual UINT32 getInternalItem(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
1138 UINT32 getItemFromSNMP(WORD port, const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer, int interpretRawValue);
1139 UINT32 getTableFromSNMP(WORD port, const TCHAR *oid, ObjectArray<DCTableColumn> *columns, Table **table);
1140 UINT32 getListFromSNMP(WORD port, const TCHAR *oid, StringList **list);
1141 UINT32 getOIDSuffixListFromSNMP(WORD port, const TCHAR *oid, StringList **list);
1142 UINT32 getItemFromCheckPointSNMP(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
1143 UINT32 getItemFromAgent(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
1144 UINT32 getTableFromAgent(const TCHAR *name, Table **table);
1145 UINT32 getListFromAgent(const TCHAR *name, StringList **list);
1146 UINT32 getItemForClient(int iOrigin, const TCHAR *pszParam, TCHAR *pszBuffer, UINT32 dwBufSize);
1147 UINT32 getTableForClient(const TCHAR *name, Table **table);
1148 UINT32 getItemFromSMCLP(const TCHAR *param, UINT32 bufSize, TCHAR *buffer);
1149
1150 virtual NXSL_Array *getParentsForNXSL();
1151 NXSL_Array *getInterfacesForNXSL();
1152
1153 void openParamList(ObjectArray<AgentParameterDefinition> **paramList);
1154 void closeParamList() { UnlockData(); }
1155
1156 void openTableList(ObjectArray<AgentTableDefinition> **tableList);
1157 void closeTableList() { UnlockData(); }
1158
1159 AgentConnectionEx *createAgentConnection();
1160 SNMP_Transport *createSnmpTransport(WORD port = 0, const TCHAR *context = NULL);
1161 SNMP_SecurityContext *getSnmpSecurityContext();
1162
1163 virtual void CreateMessage(CSCPMessage *pMsg);
1164 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1165 void writeParamListToMessage(CSCPMessage *pMsg, WORD flags);
1166 void writeWinPerfObjectsToMessage(CSCPMessage *msg);
1167 void writePackageListToMessage(CSCPMessage *msg);
1168 void writeWsListToMessage(CSCPMessage *msg);
1169
1170 UINT32 wakeUp();
1171
1172 void addService(NetworkService *pNetSrv) { AddChild(pNetSrv); pNetSrv->AddParent(this); }
1173 UINT32 checkNetworkService(UINT32 *pdwStatus, UINT32 dwIpAddr, int iServiceType, WORD wPort = 0,
1174 WORD wProto = 0, TCHAR *pszRequest = NULL, TCHAR *pszResponse = NULL);
1175
1176 QWORD getLastEventId(int nIndex) { return ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) ? m_qwLastEvents[nIndex] : 0; }
1177 void setLastEventId(int nIndex, QWORD qwId) { if ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) m_qwLastEvents[nIndex] = qwId; }
1178
1179 UINT32 callSnmpEnumerate(const TCHAR *pszRootOid,
1180 UINT32 (* pHandler)(UINT32, SNMP_Variable *, SNMP_Transport *, void *), void *pArg, const TCHAR *context = NULL);
1181
1182 nxmap_ObjList *getL2Topology();
1183 nxmap_ObjList *buildL2Topology(UINT32 *pdwStatus, int radius, bool includeEndNodes);
1184 ForwardingDatabase *getSwitchForwardingDatabase();
1185 Interface *findConnectionPoint(UINT32 *localIfId, BYTE *localMacAddr, bool *exactMatch);
1186 void addHostConnections(LinkLayerNeighbors *nbs);
1187 void addExistingConnections(LinkLayerNeighbors *nbs);
1188
1189 nxmap_ObjList *buildIPTopology(UINT32 *pdwStatus, int radius, bool includeEndNodes);
1190
1191 ServerJobQueue *getJobQueue() { return m_jobQueue; }
1192 int getJobCount(const TCHAR *type = NULL) { return m_jobQueue->getJobCount(type); }
1193
1194 void *getDriverData() { return m_driverData; }
1195 void setDriverData(void *data) { m_driverData = data; }
1196 };
1197
1198 /**
1199 * Set timestamp of last discovery poll to current time
1200 */
1201 inline void Node::setDiscoveryPollTimeStamp()
1202 {
1203 m_tLastDiscoveryPoll = time(NULL);
1204 m_dwDynamicFlags &= ~NDF_QUEUED_FOR_DISCOVERY_POLL;
1205 }
1206
1207 inline bool Node::isReadyForStatusPoll()
1208 {
1209 if (m_isDeleted)
1210 return false;
1211 //if (GetMyCluster() != NULL)
1212 // return FALSE; // Cluster nodes should be polled from cluster status poll
1213 if (m_dwDynamicFlags & NDF_FORCE_STATUS_POLL)
1214 {
1215 m_dwDynamicFlags &= ~NDF_FORCE_STATUS_POLL;
1216 return true;
1217 }
1218 return (m_iStatus != STATUS_UNMANAGED) &&
1219 (!(m_dwFlags & NF_DISABLE_STATUS_POLL)) &&
1220 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_STATUS_POLL)) &&
1221 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1222 (getMyCluster() == NULL) &&
1223 ((UINT32)time(NULL) - (UINT32)m_tLastStatusPoll > g_dwStatusPollingInterval);
1224 }
1225
1226 inline bool Node::isReadyForConfigurationPoll()
1227 {
1228 if (m_isDeleted)
1229 return false;
1230 if (m_dwDynamicFlags & NDF_FORCE_CONFIGURATION_POLL)
1231 {
1232 m_dwDynamicFlags &= ~NDF_FORCE_CONFIGURATION_POLL;
1233 return true;
1234 }
1235 return (m_iStatus != STATUS_UNMANAGED) &&
1236 (!(m_dwFlags & NF_DISABLE_CONF_POLL)) &&
1237 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_CONFIG_POLL)) &&
1238 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1239 ((UINT32)time(NULL) - (UINT32)m_tLastConfigurationPoll > g_dwConfigurationPollingInterval);
1240 }
1241
1242 inline bool Node::isReadyForDiscoveryPoll()
1243 {
1244 if (m_isDeleted)
1245 return false;
1246 return (g_dwFlags & AF_ENABLE_NETWORK_DISCOVERY) &&
1247 (m_iStatus != STATUS_UNMANAGED) &&
1248 (!(m_dwFlags & NF_DISABLE_DISCOVERY_POLL)) &&
1249 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_DISCOVERY_POLL)) &&
1250 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1251 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1252 ((UINT32)time(NULL) - (UINT32)m_tLastDiscoveryPoll > g_dwDiscoveryPollingInterval);
1253 }
1254
1255 inline bool Node::isReadyForRoutePoll()
1256 {
1257 if (m_isDeleted)
1258 return false;
1259 return (m_iStatus != STATUS_UNMANAGED) &&
1260 (!(m_dwFlags & NF_DISABLE_ROUTE_POLL)) &&
1261 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_ROUTE_POLL)) &&
1262 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1263 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1264 ((UINT32)time(NULL) - (UINT32)m_tLastRTUpdate > g_dwRoutingTableUpdateInterval);
1265 }
1266
1267 inline bool Node::isReadyForTopologyPoll()
1268 {
1269 if (m_isDeleted)
1270 return false;
1271 return (m_iStatus != STATUS_UNMANAGED) &&
1272 (!(m_dwFlags & NF_DISABLE_TOPOLOGY_POLL)) &&
1273 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_TOPOLOGY_POLL)) &&
1274 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1275 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1276 ((UINT32)time(NULL) - (UINT32)m_tLastTopologyPoll > g_dwTopologyPollingInterval);
1277 }
1278
1279 inline void Node::lockForStatusPoll()
1280 {
1281 LockData();
1282 m_dwDynamicFlags |= NDF_QUEUED_FOR_STATUS_POLL;
1283 UnlockData();
1284 }
1285
1286 inline void Node::lockForConfigurationPoll()
1287 {
1288 LockData();
1289 m_dwDynamicFlags |= NDF_QUEUED_FOR_CONFIG_POLL;
1290 UnlockData();
1291 }
1292
1293 inline void Node::lockForDiscoveryPoll()
1294 {
1295 LockData();
1296 m_dwDynamicFlags |= NDF_QUEUED_FOR_DISCOVERY_POLL;
1297 UnlockData();
1298 }
1299
1300 inline void Node::lockForTopologyPoll()
1301 {
1302 LockData();
1303 m_dwDynamicFlags |= NDF_QUEUED_FOR_TOPOLOGY_POLL;
1304 UnlockData();
1305 }
1306
1307 inline void Node::lockForRoutePoll()
1308 {
1309 LockData();
1310 m_dwDynamicFlags |= NDF_QUEUED_FOR_ROUTE_POLL;
1311 UnlockData();
1312 }
1313
1314 /**
1315 * Subnet
1316 */
1317 class NXCORE_EXPORTABLE Subnet : public NetObj
1318 {
1319 friend void Node::buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedSubnet, bool includeEndNodes);
1320
1321 protected:
1322 UINT32 m_dwIpNetMask;
1323 UINT32 m_zoneId;
1324 bool m_bSyntheticMask;
1325
1326 void buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedNode, bool includeEndNodes);
1327
1328 public:
1329 Subnet();
1330 Subnet(UINT32 dwAddr, UINT32 dwNetMask, UINT32 dwZone, bool bSyntheticMask);
1331 virtual ~Subnet();
1332
1333 virtual int Type() { return OBJECT_SUBNET; }
1334
1335 virtual BOOL SaveToDB(DB_HANDLE hdb);
1336 virtual bool deleteFromDB(DB_HANDLE hdb);
1337 virtual BOOL CreateFromDB(UINT32 dwId);
1338
1339 void AddNode(Node *pNode) { AddChild(pNode); pNode->AddParent(this); }
1340 virtual void CreateMessage(CSCPMessage *pMsg);
1341
1342 virtual bool showThresholdSummary();
1343
1344 UINT32 getIpNetMask() { return m_dwIpNetMask; }
1345 UINT32 getZoneId() { return m_zoneId; }
1346 bool isSyntheticMask() { return m_bSyntheticMask; }
1347
1348 void setCorrectMask(UINT32 dwAddr, UINT32 dwMask);
1349
1350 bool findMacAddress(UINT32 ipAddr, BYTE *macAddr);
1351 };
1352
1353 /**
1354 * Universal root object
1355 */
1356 class NXCORE_EXPORTABLE UniversalRoot : public NetObj
1357 {
1358 public:
1359 UniversalRoot();
1360 virtual ~UniversalRoot();
1361
1362 virtual BOOL SaveToDB(DB_HANDLE hdb);
1363 virtual void LoadFromDB();
1364
1365 void LinkChildObjects();
1366 void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
1367 };
1368
1369 /**
1370 * Service root
1371 */
1372 class NXCORE_EXPORTABLE ServiceRoot : public UniversalRoot
1373 {
1374 public:
1375 ServiceRoot();
1376 virtual ~ServiceRoot();
1377
1378 virtual int Type() { return OBJECT_SERVICEROOT; }
1379
1380 virtual bool showThresholdSummary();
1381 };
1382
1383 /**
1384 * Template root
1385 */
1386 class NXCORE_EXPORTABLE TemplateRoot : public UniversalRoot
1387 {
1388 public:
1389 TemplateRoot();
1390 virtual ~TemplateRoot();
1391
1392 virtual int Type() { return OBJECT_TEMPLATEROOT; }
1393 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1394 };
1395
1396 /**
1397 * Generic container object
1398 */
1399 class NXCORE_EXPORTABLE Container : public NetObj
1400 {
1401 private:
1402 UINT32 *m_pdwChildIdList;
1403 UINT32 m_dwChildIdListSize;
1404
1405 protected:
1406 UINT32 m_flags;
1407 UINT32 m_dwCategory;
1408 NXSL_Program *m_bindFilter;
1409 TCHAR *m_bindFilterSource;
1410
1411 public:
1412 Container();
1413 Container(const TCHAR *pszName, UINT32 dwCategory);
1414 virtual ~Container();
1415
1416 virtual int Type(void) { return OBJECT_CONTAINER; }
1417
1418 virtual BOOL SaveToDB(DB_HANDLE hdb);
1419 virtual bool deleteFromDB(DB_HANDLE hdb);
1420 virtual BOOL CreateFromDB(UINT32 dwId);
1421
1422 virtual void CreateMessage(CSCPMessage *pMsg);
1423 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1424
1425 virtual bool showThresholdSummary();
1426
1427 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1428
1429 UINT32 getCategory() { return m_dwCategory; }
1430
1431 void linkChildObjects();
1432 void linkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
1433
1434 bool isSuitableForNode(Node *node);
1435 bool isAutoBindEnabled() { return (m_flags & CF_AUTO_BIND) ? true : false; }
1436 bool isAutoUnbindEnabled() { return ((m_flags & (CF_AUTO_UNBIND | CF_AUTO_UNBIND)) == (CF_AUTO_UNBIND | CF_AUTO_UNBIND)) ? true : false; }
1437
1438 void setAutoBindFilter(const TCHAR *script);
1439 };
1440
1441 /**
1442 * Template group object
1443 */
1444 class NXCORE_EXPORTABLE TemplateGroup : public Container
1445 {
1446 public:
1447 TemplateGroup() : Container() { }
1448 TemplateGroup(const TCHAR *pszName) : Container(pszName, 0) { }
1449 virtual ~TemplateGroup() { }
1450
1451 virtual int Type() { return OBJECT_TEMPLATEGROUP; }
1452 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1453
1454 virtual bool showThresholdSummary();
1455 };
1456
1457 /**
1458 * Rack object
1459 */
1460 class NXCORE_EXPORTABLE Rack : public Container
1461 {
1462 protected:
1463 int m_height; // Rack height in units
1464
1465 public:
1466 Rack();
1467 Rack(const TCHAR *name, int height);
1468 virtual ~Rack();
1469
1470 virtual int Type() { return OBJECT_RACK; }
1471
1472 virtual BOOL SaveToDB(DB_HANDLE hdb);
1473 virtual bool deleteFromDB(DB_HANDLE hdb);
1474 virtual BOOL CreateFromDB(UINT32 dwId);
1475
1476 virtual void CreateMessage(CSCPMessage *pMsg);
1477 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1478 };
1479
1480 /**
1481 * Zone object
1482 */
1483 class Zone : public NetObj
1484 {
1485 protected:
1486 UINT32 m_zoneId;
1487 UINT32 m_agentProxy;
1488 UINT32 m_snmpProxy;
1489 UINT32 m_icmpProxy;
1490 ObjectIndex *m_idxNodeByAddr;
1491 ObjectIndex *m_idxInterfaceByAddr;
1492 ObjectIndex *m_idxSubnetByAddr;
1493
1494 public:
1495 Zone();
1496 Zone(UINT32 zoneId, const TCHAR *name);
1497 virtual ~Zone();
1498
1499 virtual int Type() { return OBJECT_ZONE; }
1500
1501 virtual BOOL SaveToDB(DB_HANDLE hdb);
1502 virtual bool deleteFromDB(DB_HANDLE hdb);
1503 virtual BOOL CreateFromDB(UINT32 dwId);
1504
1505 virtual void CreateMessage(CSCPMessage *pMsg);
1506 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1507
1508 virtual bool showThresholdSummary();
1509
1510 UINT32 getZoneId() { return m_zoneId; }
1511 UINT32 getAgentProxy() { return m_agentProxy; }
1512 UINT32 getSnmpProxy() { return m_snmpProxy; }
1513 UINT32 getIcmpProxy() { return m_icmpProxy; }
1514
1515 void addSubnet(Subnet *pSubnet) { AddChild(pSubnet); pSubnet->AddParent(this); }
1516
1517 void addToIndex(Subnet *subnet) { m_idxSubnetByAddr->put(subnet->IpAddr(), subnet); }
1518 void addToIndex(Interface *iface) { m_idxInterfaceByAddr->put(iface->IpAddr(), iface); }
1519 void addToIndex(Node *node) { m_idxNodeByAddr->put(node->IpAddr(), node); }
1520 void removeFromIndex(Subnet *subnet) { m_idxSubnetByAddr->remove(subnet->IpAddr()); }
1521 void removeFromIndex(Interface *iface) { m_idxInterfaceByAddr->remove(iface->IpAddr()); }
1522 void removeFromIndex(Node *node) { m_idxNodeByAddr->remove(node->IpAddr()); }
1523 void updateInterfaceIndex(UINT32 oldIp, UINT32 newIp, Interface *iface);
1524 Subnet *getSubnetByAddr(UINT32 ipAddr) { return (Subnet *)m_idxSubnetByAddr->get(ipAddr); }
1525 Interface *getInterfaceByAddr(UINT32 ipAddr) { return (Interface *)m_idxInterfaceByAddr->get(ipAddr); }
1526 Node *getNodeByAddr(UINT32 ipAddr) { return (Node *)m_idxNodeByAddr->get(ipAddr); }
1527 Subnet *findSubnet(bool (*comparator)(NetObj *, void *), void *data) { return (Subnet *)m_idxSubnetByAddr->find(comparator, data); }
1528 Interface *findInterface(bool (*comparator)(NetObj *, void *), void *data) { return (Interface *)m_idxInterfaceByAddr->find(comparator, data); }
1529 Node *findNode(bool (*comparator)(NetObj *, void *), void *data) { return (Node *)m_idxNodeByAddr->find(comparator, data); }
1530 void forEachSubnet(void (*callback)(NetObj *, void *), void *data) { m_idxSubnetByAddr->forEach(callback, data); }
1531 };
1532
1533 /**
1534 * Entire network
1535 */
1536 class NXCORE_EXPORTABLE Network : public NetObj
1537 {
1538 public:
1539 Network();
1540 virtual ~Network();
1541
1542 virtual int Type(void) { return OBJECT_NETWORK; }
1543 virtual BOOL SaveToDB(DB_HANDLE hdb);
1544
1545 virtual bool showThresholdSummary();
1546
1547 void AddSubnet(Subnet *pSubnet) { AddChild(pSubnet); pSubnet->AddParent(this); }
1548 void AddZone(Zone *pZone) { AddChild(pZone); pZone->AddParent(this); }
1549 void LoadFromDB(void);
1550 };
1551
1552 /**
1553 * Condition
1554 */
1555 class NXCORE_EXPORTABLE Condition : public NetObj
1556 {
1557 protected:
1558 UINT32 m_dwDCICount;
1559 INPUT_DCI *m_pDCIList;
1560 TCHAR *m_pszScript;
1561 NXSL_Program *m_pCompiledScript;
1562 UINT32 m_dwActivationEventCode;
1563 UINT32 m_dwDeactivationEventCode;
1564 UINT32 m_dwSourceObject;
1565 int m_nActiveStatus;
1566 int m_nInactiveStatus;
1567 BOOL m_bIsActive;
1568 time_t m_tmLastPoll;
1569 BOOL m_bQueuedForPolling;
1570
1571 public:
1572 Condition();
1573 Condition(bool hidden);
1574 virtual ~Condition();
1575
1576 virtual int Type() { return OBJECT_CONDITION; }
1577
1578 virtual BOOL SaveToDB(DB_HANDLE hdb);
1579 virtual bool deleteFromDB(DB_HANDLE hdb);
1580 virtual BOOL CreateFromDB(UINT32 dwId);
1581
1582 virtual void CreateMessage(CSCPMessage *pMsg);
1583 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1584
1585 void check();
1586
1587 void LockForPoll(void);
1588 void EndPoll(void);
1589
1590 BOOL ReadyForPoll(void)
1591 {
1592 return ((m_iStatus != STATUS_UNMANAGED) &&
1593 (!m_bQueuedForPolling) && (!m_isDeleted) &&
1594 ((UINT32)time(NULL) - (UINT32)m_tmLastPoll > g_dwConditionPollingInterval))
1595 ? TRUE : FALSE;
1596 }
1597
1598 int getCacheSizeForDCI(UINT32 dwItemId, BOOL bNoLock);
1599 };
1600
1601 /**
1602 * Generic agent policy object
1603 */
1604 class NXCORE_EXPORTABLE AgentPolicy : public NetObj
1605 {
1606 protected:
1607 UINT32 m_version;
1608 int m_policyType;
1609 TCHAR *m_description;
1610
1611 BOOL savePolicyCommonProperties(DB_HANDLE hdb);
1612
1613 public:
1614 AgentPolicy(int type);
1615 AgentPolicy(const TCHAR *name, int type);
1616 virtual ~AgentPolicy();
1617
1618 virtual int Type() { return OBJECT_AGENTPOLICY; }
1619
1620 virtual BOOL SaveToDB(DB_HANDLE hdb);
1621 virtual bool deleteFromDB(DB_HANDLE hdb);
1622 virtual BOOL CreateFromDB(UINT32 dwId);
1623
1624 virtual void CreateMessage(CSCPMessage *pMsg);
1625 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1626
1627 virtual bool createDeploymentMessage(CSCPMessage *msg);
1628 virtual bool createUninstallMessage(CSCPMessage *msg);
1629
1630 void linkNode(Node *node) { AddChild(node); node->AddParent(this); }
1631 void unlinkNode(Node *node) { DeleteChild(node); node->DeleteParent(this); }
1632 };
1633
1634 /**
1635 * Agent config policy object
1636 */
1637 class NXCORE_EXPORTABLE AgentPolicyConfig : public AgentPolicy
1638 {
1639 protected:
1640 TCHAR *m_fileContent;
1641
1642 public:
1643 AgentPolicyConfig();
1644 AgentPolicyConfig(const TCHAR *name);
1645 virtual ~AgentPolicyConfig();
1646
1647 virtual int Type() { return OBJECT_AGENTPOLICY_CONFIG; }
1648
1649 virtual BOOL SaveToDB(DB_HANDLE hdb);
1650 virtual bool deleteFromDB(DB_HANDLE hdb);
1651 virtual BOOL CreateFromDB(UINT32 dwId);
1652
1653 virtual void CreateMessage(CSCPMessage *pMsg);
1654 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1655
1656 virtual bool createDeploymentMessage(CSCPMessage *msg);
1657 virtual bool createUninstallMessage(CSCPMessage *msg);
1658 };
1659
1660 /**
1661 * Policy group object
1662 */
1663 class NXCORE_EXPORTABLE PolicyGroup : public Container
1664 {
1665 public:
1666 PolicyGroup() : Container() { }
1667 PolicyGroup(const TCHAR *pszName) : Container(pszName, 0) { }
1668 virtual ~PolicyGroup() { }
1669
1670 virtual int Type() { return OBJECT_POLICYGROUP; }
1671 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1672
1673 virtual bool showThresholdSummary();
1674 };
1675
1676 /**
1677 * Policy root
1678 */
1679 class NXCORE_EXPORTABLE PolicyRoot : public UniversalRoot
1680 {
1681 public:
1682 PolicyRoot();
1683 virtual ~PolicyRoot();
1684
1685 virtual int Type() { return OBJECT_POLICYROOT; }
1686 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1687 };
1688
1689 /**
1690 * Network map root
1691 */
1692 class NXCORE_EXPORTABLE NetworkMapRoot : public UniversalRoot
1693 {
1694 public:
1695 NetworkMapRoot();
1696 virtual ~NetworkMapRoot();
1697
1698 virtual int Type() { return OBJECT_NETWORKMAPROOT; }
1699 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1700 };
1701
1702 /**
1703 * Network map group object
1704 */
1705 class NXCORE_EXPORTABLE NetworkMapGroup : public Container
1706 {
1707 public:
1708 NetworkMapGroup() : Container() { }
1709 NetworkMapGroup(const TCHAR *pszName) : Container(pszName, 0) { }
1710 virtual ~NetworkMapGroup() { }
1711
1712 virtual int Type() { return OBJECT_NETWORKMAPGROUP; }
1713 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1714
1715 virtual bool showThresholdSummary();
1716 };
1717
1718 /**
1719 * Network map object
1720 */
1721 class NXCORE_EXPORTABLE NetworkMap : public NetObj
1722 {
1723 protected:
1724 int m_mapType;
1725 UINT32 m_seedObject;
1726 int m_discoveryRadius;
1727 int m_layout;
1728 UINT32 m_flags;
1729 int m_backgroundColor;
1730 int m_defaultLinkColor;
1731 int m_defaultLinkRouting;
1732 uuid_t m_background;
1733 double m_backgroundLatitude;
1734 double m_backgroundLongitude;
1735 int m_backgroundZoom;
1736 UINT32 m_nextElementId;
1737 ObjectArray<NetworkMapElement> *m_elements;
1738 ObjectArray<NetworkMapLink> *m_links;
1739 TCHAR *m_filterSource;
1740 NXSL_Program *m_filter;
1741
1742 void updateObjects(nxmap_ObjList *objects);
1743 UINT32 objectIdFromElementId(UINT32 eid);
1744 UINT32 elementIdFromObjectId(UINT32 eid);
1745
1746 public:
1747 NetworkMap();
1748 NetworkMap(int type, UINT32 seed);
1749 virtual ~NetworkMap();
1750
1751 virtual int Type() { return OBJECT_NETWORKMAP; }
1752 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1753
1754 virtual BOOL SaveToDB(DB_HANDLE hdb);
1755 virtual bool deleteFromDB(DB_HANDLE hdb);
1756 virtual BOOL CreateFromDB(UINT32 dwId);
1757
1758 virtual void CreateMessage(CSCPMessage *pMsg);
1759 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1760
1761 virtual void onObjectDelete(UINT32 dwObjectId);
1762
1763 void updateContent();
1764
1765 int getBackgroundColor() { return m_backgroundColor; }
1766 void setBackgroundColor(int color) { m_backgroundColor = color; }
1767
1768 void setFilter(const TCHAR *filter);
1769 bool isAllowedOnMap(NetObj *object);
1770 };
1771
1772 /**
1773 * Dashboard tree root
1774 */
1775 class NXCORE_EXPORTABLE DashboardRoot : public UniversalRoot
1776 {
1777 public:
1778 DashboardRoot();
1779 virtual ~DashboardRoot();
1780
1781 virtual int Type() { return OBJECT_DASHBOARDROOT; }
1782 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1783 };
1784
1785 /**
1786 * Dashboard element
1787 */
1788 class DashboardElement
1789 {
1790 public:
1791 int m_type;
1792 TCHAR *m_data;
1793 TCHAR *m_layout;
1794
1795 DashboardElement() { m_data = NULL; m_layout = NULL; }
1796 ~DashboardElement() { safe_free(m_data); safe_free(m_layout); }
1797 };
1798
1799 /**
1800 * Dashboard object
1801 */
1802 class NXCORE_EXPORTABLE Dashboard : public Container
1803 {
1804 protected:
1805 int m_numColumns;
1806 UINT32 m_options;
1807 ObjectArray<DashboardElement> *m_elements;
1808
1809 public:
1810 Dashboard();
1811 Dashboard(const TCHAR *name);
1812 virtual ~Dashboard();
1813
1814 virtual int Type() { return OBJECT_DASHBOARD; }
1815 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1816
1817 virtual BOOL SaveToDB(DB_HANDLE hdb);
1818 virtual bool deleteFromDB(DB_HANDLE hdb);
1819 virtual BOOL CreateFromDB(UINT32 dwId);
1820
1821 virtual void CreateMessage(CSCPMessage *pMsg);
1822 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1823
1824 virtual bool showThresholdSummary();
1825 };
1826
1827 /**
1828 * Report root
1829 */
1830 class NXCORE_EXPORTABLE ReportRoot : public UniversalRoot
1831 {
1832 public:
1833 ReportRoot();
1834 virtual ~ReportRoot();
1835
1836 virtual int Type() { return OBJECT_REPORTROOT; }
1837 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1838 };
1839
1840 /**
1841 * Report group object
1842 */
1843 class NXCORE_EXPORTABLE ReportGroup : public Container
1844 {
1845 public:
1846 ReportGroup() : Container() { }
1847 ReportGroup(const TCHAR *pszName) : Container(pszName, 0) { }
1848 virtual ~ReportGroup() { }
1849
1850 virtual int Type() { return OBJECT_REPORTGROUP; }
1851 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1852
1853 virtual bool showThresholdSummary();
1854 };
1855
1856 /**
1857 * Report object
1858 */
1859 class NXCORE_EXPORTABLE Report : public NetObj
1860 {
1861 protected:
1862 TCHAR *m_definition;
1863
1864 public:
1865 Report();
1866 Report(const TCHAR *name);
1867 virtual ~Report();
1868
1869 virtual int Type() { return OBJECT_REPORT; }
1870 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1871
1872 virtual BOOL SaveToDB(DB_HANDLE hdb);
1873 virtual bool deleteFromDB(DB_HANDLE hdb);
1874 virtual BOOL CreateFromDB(UINT32 dwId);
1875
1876 virtual void CreateMessage(CSCPMessage *pMsg);
1877 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1878
1879 const TCHAR *getDefinition() { return CHECK_NULL_EX(m_definition); }
1880
1881 UINT32 execute(StringMap *parameters, UINT32 userId);
1882 };
1883
1884 /**
1885 * SLM check object
1886 */
1887 class NXCORE_EXPORTABLE SlmCheck : public NetObj
1888 {
1889 protected:
1890 static NXSL_VariableSystem m_nxslConstants;
1891
1892 Threshold *m_threshold;
1893 enum CheckType { check_undefined = 0, check_script = 1, check_threshold = 2 } m_type;
1894 TCHAR *m_script;
1895 NXSL_Program *m_pCompiledScript;
1896 TCHAR m_reason[256];
1897 bool m_isTemplate;
1898 UINT32 m_templateId;
1899 UINT32 m_currentTicketId;
1900
1901 virtual void onObjectDelete(UINT32 objectId);
1902
1903 void setScript(const TCHAR *script);
1904 UINT32 getOwnerId();
1905 NXSL_Value *getNodeObjectForNXSL();
1906 bool insertTicket();
1907 void closeTicket();
1908 void setReason(const TCHAR *reason) { nx_strncpy(m_reason, CHECK_NULL_EX(reason), 256); }
1909 void compileScript();
1910
1911 public:
1912 SlmCheck();
1913 SlmCheck(const TCHAR *name, bool isTemplate);
1914 SlmCheck(SlmCheck *tmpl);
1915 virtual ~SlmCheck();
1916
1917 static void init();
1918
1919 virtual int Type() { return OBJECT_SLMCHECK; }
1920
1921 virtual BOOL SaveToDB(DB_HANDLE hdb);
1922 virtual bool deleteFromDB(DB_HANDLE hdb);
1923 virtual BOOL CreateFromDB(UINT32 dwId);
1924
1925 virtual void CreateMessage(CSCPMessage *pMsg);
1926 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1927 virtual void postModify();
1928
1929 void execute();
1930 void updateFromTemplate(SlmCheck *tmpl);
1931
1932 bool isTemplate() { return m_isTemplate; }
1933 UINT32 getTemplateId() { return m_templateId; }
1934 const TCHAR *getReason() { return m_reason; }
1935 };
1936
1937 /**
1938 * Service container - common logic for BusinessService, NodeLink and BusinessServiceRoot
1939 */
1940 class NXCORE_EXPORTABLE ServiceContainer : public Container
1941 {
1942 enum Period { DAY, WEEK, MONTH };
1943
1944 protected:
1945 time_t m_prevUptimeUpdateTime;
1946 int m_prevUptimeUpdateStatus;
1947 double m_uptimeDay;
1948 double m_uptimeWeek;
1949 double m_uptimeMonth;
1950 LONG m_downtimeDay;
1951 LONG m_downtimeWeek;
1952 LONG m_downtimeMonth;
1953 LONG m_prevDiffDay;
1954 LONG m_prevDiffWeek;
1955 LONG m_prevDiffMonth;
1956
1957 static LONG logRecordId;
1958 static LONG getSecondsInMonth();
1959 static LONG getSecondsInPeriod(Period period) { return period == MONTH ? getSecondsInMonth() : (period == WEEK ? (3600 * 24 * 7) : (3600 * 24)); }
1960 static LONG getSecondsSinceBeginningOf(Period period, time_t *beginTime = NULL);
1961
1962 void initServiceContainer();
1963 BOOL addHistoryRecord();
1964 double getUptimeFromDBFor(Period period, LONG *downtime);
1965
1966 public:
1967 ServiceContainer();
1968 ServiceContainer(const TCHAR *pszName);
1969
1970 virtual BOOL CreateFromDB(UINT32 dwId);
1971 virtual BOOL SaveToDB(DB_HANDLE hdb);
1972 virtual bool deleteFromDB(DB_HANDLE hdb);
1973
1974 virtual void CreateMessage(CSCPMessage *pMsg);
1975 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1976
1977 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1978 virtual void setStatus(int newStatus);
1979
1980 virtual bool showThresholdSummary();
1981
1982 void initUptimeStats();
1983 void updateUptimeStats(time_t currentTime = 0, BOOL updateChilds = FALSE);
1984 };
1985
1986
1987 //
1988 // Business service root
1989 //
1990
1991 class NXCORE_EXPORTABLE BusinessServiceRoot : public ServiceContainer
1992 {
1993 public:
1994 BusinessServiceRoot();
1995 virtual ~BusinessServiceRoot();
1996
1997 virtual int Type() { return OBJECT_BUSINESSSERVICEROOT; }
1998
1999 virtual BOOL SaveToDB(DB_HANDLE hdb);
2000 void LoadFromDB();
2001
2002 void LinkChildObjects();
2003 void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
2004 };
2005
2006
2007 //
2008 // Business service object
2009 //
2010
2011 class NXCORE_EXPORTABLE BusinessService : public ServiceContainer
2012 {
2013 protected:
2014 bool m_busy;
2015 time_t m_lastPollTime;
2016 int m_lastPollStatus;
2017
2018 public:
2019 BusinessService();
2020 BusinessService(const TCHAR *name);
2021 virtual ~BusinessService();
2022
2023 virtual int Type() { return OBJECT_BUSINESSSERVICE; }
2024
2025 virtual BOOL CreateFromDB(UINT32 dwId);
2026 virtual BOOL SaveToDB(DB_HANDLE hdb);
2027 virtual bool deleteFromDB(DB_HANDLE hdb);
2028
2029 virtual void CreateMessage(CSCPMessage *pMsg);
2030 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
2031
2032 bool isReadyForPolling();
2033 void lockForPolling();
2034 void poll(ClientSession *pSession, UINT32 dwRqId, int nPoller);
2035
2036 void getApplicableTemplates(ServiceContainer *target, ObjectArray<SlmCheck> *templates);
2037 };
2038
2039 /**
2040 * Node link object for business service
2041 */
2042 class NXCORE_EXPORTABLE NodeLink : public ServiceContainer
2043 {
2044 protected:
2045 UINT32 m_nodeId;
2046
2047 virtual void onObjectDelete(UINT32 dwObjectId);
2048
2049 void applyTemplate(SlmCheck *tmpl);
2050
2051 public:
2052 NodeLink();
2053 NodeLink(const TCHAR *name, UINT32 nodeId);
2054 virtual ~NodeLink();
2055
2056 virtual int Type() { return OBJECT_NODELINK; }
2057
2058 virtual BOOL SaveToDB(DB_HANDLE hdb);
2059 virtual bool deleteFromDB(DB_HANDLE hdb);
2060 virtual BOOL CreateFromDB(UINT32 dwId);
2061
2062 virtual void CreateMessage(CSCPMessage *pMsg);
2063 virtual UINT32 ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
2064
2065 void execute();
2066 void applyTemplates();
2067
2068 UINT32 getNodeId() { return m_nodeId; }
2069 };
2070
2071
2072 //
2073 // Container category information
2074 //
2075
2076 struct CONTAINER_CATEGORY
2077 {
2078 UINT32 dwCatId;
2079 TCHAR szName[MAX_OBJECT_NAME];
2080 TCHAR *pszDescription;
2081 UINT32 dwImageId;
2082 };
2083
2084
2085 //
2086 // Functions
2087 //
2088
2089 void ObjectsInit();
2090
2091 void NXCORE_EXPORTABLE NetObjInsert(NetObj *pObject, BOOL bNewObject);
2092 void NetObjDeleteFromIndexes(NetObj *pObject);
2093 void NetObjDelete(NetObj *pObject);
2094
2095 void UpdateInterfaceIndex(UINT32 dwOldIpAddr, UINT32 dwNewIpAddr, Interface *pObject);
2096 ComponentTree *BuildComponentTree(Node *node, SNMP_Transport *snmp);
2097
2098 NetObj NXCORE_EXPORTABLE *FindObjectById(UINT32 dwId, int objClass = -1);
2099 NetObj NXCORE_EXPORTABLE *FindObjectByName(const TCHAR *name, int objClass);
2100 NetObj NXCORE_EXPORTABLE *FindObjectByGUID(uuid_t guid, int objClass);
2101 Template NXCORE_EXPORTABLE *FindTemplateByName(const TCHAR *pszName);
2102 Node NXCORE_EXPORTABLE *FindNodeByIP(UINT32 zoneId, UINT32 ipAddr);
2103 Node NXCORE_EXPORTABLE *FindNodeByMAC(const BYTE *macAddr);
2104 Node NXCORE_EXPORTABLE *FindNodeByLLDPId(const TCHAR *lldpId);
2105 Interface NXCORE_EXPORTABLE *FindInterfaceByIP(UINT32 zoneId, UINT32 ipAddr);
2106 Interface NXCORE_EXPORTABLE *FindInterfaceByMAC(const BYTE *macAddr);
2107 Interface NXCORE_EXPORTABLE *FindInterfaceByDescription(const TCHAR *description);
2108 Subnet NXCORE_EXPORTABLE *FindSubnetByIP(UINT32 zoneId, UINT32 ipAddr);
2109 Subnet NXCORE_EXPORTABLE *FindSubnetForNode(UINT32 zoneId, UINT32 dwNodeAddr);
2110 MobileDevice NXCORE_EXPORTABLE *FindMobileDeviceByDeviceID(const TCHAR *deviceId);
2111 AccessPoint NXCORE_EXPORTABLE *FindAccessPointByMAC(const BYTE *macAddr);
2112 AccessPoint NXCORE_EXPORTABLE *FindAccessPointByRadioId(int rfIndex);
2113 UINT32 NXCORE_EXPORTABLE FindLocalMgmtNode();
2114 CONTAINER_CATEGORY NXCORE_EXPORTABLE *FindContainerCategory(UINT32 dwId);
2115 Zone NXCORE_EXPORTABLE *FindZoneByGUID(UINT32 dwZoneGUID);
2116 Cluster NXCORE_EXPORTABLE *FindClusterByResourceIP(UINT32 zone, UINT32 ipAddr);
2117 bool NXCORE_EXPORTABLE IsClusterIP(UINT32 zone, UINT32 ipAddr);
2118
2119 BOOL LoadObjects();
2120 void DumpObjects(CONSOLE_CTX pCtx);
2121
2122 void DeleteUserFromAllObjects(UINT32 dwUserId);
2123
2124 bool IsValidParentClass(int iChildClass, int iParentClass);
2125 bool IsAgentPolicyObject(NetObj *object);
2126 bool IsEventSource(int objectClass);
2127
2128 int DefaultPropagatedStatus(int iObjectStatus);
2129 int GetDefaultStatusCalculation(int *pnSingleThreshold, int **ppnThresholds);
2130
2131 /**
2132 * Global variables
2133 */
2134 extern Network NXCORE_EXPORTABLE *g_pEntireNet;
2135 extern ServiceRoot NXCORE_EXPORTABLE *g_pServiceRoot;
2136 extern TemplateRoot NXCORE_EXPORTABLE *g_pTemplateRoot;
2137 extern PolicyRoot NXCORE_EXPORTABLE *g_pPolicyRoot;
2138 extern NetworkMapRoot NXCORE_EXPORTABLE *g_pMapRoot;
2139 extern DashboardRoot NXCORE_EXPORTABLE *g_pDashboardRoot;
2140 extern ReportRoot NXCORE_EXPORTABLE *g_pReportRoot;
2141 extern BusinessServiceRoot NXCORE_EXPORTABLE *g_pBusinessServiceRoot;
2142
2143 extern UINT32 NXCORE_EXPORTABLE g_dwMgmtNode;
2144 extern UINT32 g_dwNumCategories;
2145 extern CONTAINER_CATEGORY *g_pContainerCatList;
2146 extern const TCHAR *g_szClassName[];
2147 extern BOOL g_bModificationsLocked;
2148 extern Queue *g_pTemplateUpdateQueue;
2149
2150 extern ObjectIndex NXCORE_EXPORTABLE g_idxObjectById;
2151 extern ObjectIndex NXCORE_EXPORTABLE g_idxSubnetByAddr;
2152 extern ObjectIndex NXCORE_EXPORTABLE g_idxInterfaceByAddr;
2153 extern ObjectIndex NXCORE_EXPORTABLE g_idxNodeByAddr;
2154 extern ObjectIndex NXCORE_EXPORTABLE g_idxZoneByGUID;
2155 extern ObjectIndex NXCORE_EXPORTABLE g_idxNodeById;
2156 extern ObjectIndex NXCORE_EXPORTABLE g_idxClusterById;
2157 extern ObjectIndex NXCORE_EXPORTABLE g_idxMobileDeviceById;
2158 extern ObjectIndex NXCORE_EXPORTABLE g_idxAccessPointById;
2159 extern ObjectIndex NXCORE_EXPORTABLE g_idxConditionById;
2160 extern ObjectIndex NXCORE_EXPORTABLE g_idxServiceCheckById;
2161
2162
2163 #endif /* _nms_objects_h_ */