9ff5784fa254f6b928b1a47c55d8d2972355fef5
[public/netxms.git] / src / server / include / nms_objects.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2011 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: nms_objects.h
20 **
21 **/
22
23 #ifndef _nms_objects_h_
24 #define _nms_objects_h_
25
26 #include <nms_agent.h>
27 #include <netxms_maps.h>
28 #include <geolocation.h>
29 #include "nxcore_jobs.h"
30 #include "nms_topo.h"
31
32
33 //
34 // Forward declarations of classes
35 //
36
37 class AgentConnection;
38 class AgentConnectionEx;
39 class ClientSession;
40 class Queue;
41
42
43 //
44 // Global variables used by inline functions
45 //
46
47 extern DWORD g_dwDiscoveryPollingInterval;
48 extern DWORD g_dwStatusPollingInterval;
49 extern DWORD g_dwConfigurationPollingInterval;
50 extern DWORD g_dwRoutingTableUpdateInterval;
51 extern DWORD g_dwTopologyPollingInterval;
52 extern DWORD g_dwConditionPollingInterval;
53
54
55 //
56 // Constants
57 //
58
59 #define MAX_INTERFACES 4096
60 #define MAX_ATTR_NAME_LEN 128
61 #define INVALID_INDEX 0xFFFFFFFF
62
63
64 //
65 // Last events
66 //
67
68 #define MAX_LAST_EVENTS 8
69
70 #define LAST_EVENT_NODE_DOWN 0
71
72
73 //
74 // Built-in object IDs
75 //
76
77 #define BUILTIN_OID_NETWORK 1
78 #define BUILTIN_OID_SERVICEROOT 2
79 #define BUILTIN_OID_TEMPLATEROOT 3
80 #define BUILTIN_OID_ZONE0 4
81 #define BUILTIN_OID_POLICYROOT 5
82 #define BUILTIN_OID_NETWORKMAPROOT 6
83
84
85 //
86 // Node runtime (dynamic) flags
87 //
88
89 #define NDF_QUEUED_FOR_STATUS_POLL 0x0001
90 #define NDF_QUEUED_FOR_CONFIG_POLL 0x0002
91 #define NDF_UNREACHABLE 0x0004
92 #define NDF_AGENT_UNREACHABLE 0x0008
93 #define NDF_SNMP_UNREACHABLE 0x0010
94 #define NDF_QUEUED_FOR_DISCOVERY_POLL 0x0020
95 #define NDF_FORCE_STATUS_POLL 0x0040
96 #define NDF_FORCE_CONFIGURATION_POLL 0x0080
97 #define NDF_QUEUED_FOR_ROUTE_POLL 0x0100
98 #define NDF_CPSNMP_UNREACHABLE 0x0200
99 #define NDF_RECHECK_CAPABILITIES 0x0400
100 #define NDF_POLLING_DISABLED 0x0800
101 #define NDF_CONFIGURATION_POLL_PASSED 0x1000
102 #define NDF_QUEUED_FOR_TOPOLOGY_POLL 0x2000
103
104 #define __NDF_FLAGS_DEFINED
105
106
107 //
108 // Cluster runtime flags
109 //
110
111 #define CLF_QUEUED_FOR_STATUS_POLL 0x0001
112 #define CLF_DOWN 0x0002
113
114
115 //
116 // Status poll types
117 //
118
119 #define POLL_ICMP_PING 0
120 #define POLL_SNMP 1
121 #define POLL_NATIVE_AGENT 2
122
123
124 //
125 // Zone types
126 //
127
128 #define ZONE_TYPE_PASSIVE 0
129 #define ZONE_TYPE_ACTIVE 1
130
131
132 //
133 // Template update types
134 //
135
136 #define APPLY_TEMPLATE 0
137 #define REMOVE_TEMPLATE 1
138
139
140 //
141 // Queued template update information
142 //
143
144 struct TEMPLATE_UPDATE_INFO
145 {
146 int iUpdateType;
147 Template *pTemplate;
148 DWORD dwNodeId;
149 BOOL bRemoveDCI;
150 };
151
152
153 //
154 // DCI configuration for system templates
155 //
156
157 typedef struct
158 {
159 const TCHAR *pszName;
160 const TCHAR *pszParam;
161 int nInterval;
162 int nRetention;
163 int nDataType;
164 int nOrigin;
165 int nFound;
166 } DCI_CFG;
167
168
169 //
170 // Base class for network objects
171 //
172
173 class NXCORE_EXPORTABLE NetObj
174 {
175 protected:
176 DWORD m_dwId;
177 uuid_t m_guid;
178 DWORD m_dwTimeStamp; // Last change time stamp
179 DWORD m_dwRefCount; // Number of references. Object can be destroyed only when this counter is zero
180 TCHAR m_szName[MAX_OBJECT_NAME];
181 TCHAR *m_pszComments; // User comments
182 int m_iStatus;
183 int m_iStatusCalcAlg; // Status calculation algorithm
184 int m_iStatusPropAlg; // Status propagation algorithm
185 int m_iFixedStatus; // Status if propagation is "Fixed"
186 int m_iStatusShift; // Shift value for "shifted" status propagation
187 int m_iStatusTranslation[4];
188 int m_iStatusSingleThreshold;
189 int m_iStatusThresholds[4];
190 BOOL m_bIsModified;
191 BOOL m_bIsDeleted;
192 BOOL m_bIsHidden;
193 BOOL m_bIsSystem;
194 uuid_t m_image;
195 MUTEX m_mutexData; // Object data access mutex
196 MUTEX m_mutexRefCount; // Reference counter access mutex
197 RWLOCK m_rwlockParentList; // Lock for parent list
198 RWLOCK m_rwlockChildList; // Lock for child list
199 DWORD m_dwIpAddr; // Every object should have an IP address
200 GeoLocation m_geoLocation;
201 ClientSession *m_pPollRequestor;
202
203 DWORD m_dwChildCount; // Number of child objects
204 NetObj **m_pChildList; // Array of pointers to child objects
205
206 DWORD m_dwParentCount; // Number of parent objects
207 NetObj **m_pParentList; // Array of pointers to parent objects
208
209 AccessList *m_pAccessList;
210 BOOL m_bInheritAccessRights;
211 MUTEX m_mutexACL;
212
213 DWORD m_dwNumTrustedNodes; // Trusted nodes
214 DWORD *m_pdwTrustedNodes;
215
216 StringMap m_customAttributes;
217
218 void LockData() { MutexLock(m_mutexData, INFINITE); }
219 void UnlockData() { MutexUnlock(m_mutexData); }
220 void LockACL() { MutexLock(m_mutexACL, INFINITE); }
221 void UnlockACL() { MutexUnlock(m_mutexACL); }
222 void LockParentList(BOOL bWrite)
223 {
224 if (bWrite)
225 RWLockWriteLock(m_rwlockParentList, INFINITE);
226 else
227 RWLockReadLock(m_rwlockParentList, INFINITE);
228 }
229 void UnlockParentList() { RWLockUnlock(m_rwlockParentList); }
230 void LockChildList(BOOL bWrite)
231 {
232 if (bWrite)
233 RWLockWriteLock(m_rwlockChildList, INFINITE);
234 else
235 RWLockReadLock(m_rwlockChildList, INFINITE);
236 }
237 void UnlockChildList() { RWLockUnlock(m_rwlockChildList); }
238
239 void Modify(); // Used to mark object as modified
240
241 BOOL LoadACLFromDB();
242 BOOL SaveACLToDB(DB_HANDLE hdb);
243 BOOL LoadCommonProperties();
244 BOOL SaveCommonProperties(DB_HANDLE hdb);
245 BOOL LoadTrustedNodes();
246 BOOL SaveTrustedNodes(DB_HANDLE hdb);
247
248 void SendPollerMsg(DWORD dwRqId, const TCHAR *pszFormat, ...);
249
250 virtual void PrepareForDeletion();
251 virtual void OnObjectDelete(DWORD dwObjectId);
252
253 public:
254 NetObj();
255 virtual ~NetObj();
256
257 virtual int Type() { return OBJECT_GENERIC; }
258
259 DWORD IpAddr() { return m_dwIpAddr; }
260 DWORD Id() { return m_dwId; }
261 const TCHAR *Name() { return m_szName; }
262 int Status() { return m_iStatus; }
263 int PropagatedStatus(void);
264 DWORD TimeStamp() { return m_dwTimeStamp; }
265 void getGuid(uuid_t out) { memcpy(out, m_guid, UUID_LENGTH); }
266
267 BOOL IsModified(void) { return m_bIsModified; }
268 BOOL IsDeleted(void) { return m_bIsDeleted; }
269 BOOL IsOrphaned(void) { return m_dwParentCount == 0 ? TRUE : FALSE; }
270 BOOL IsEmpty(void) { return m_dwChildCount == 0 ? TRUE : FALSE; }
271
272 BOOL IsSystem() { return m_bIsSystem; }
273 void SetSystemFlag(BOOL bFlag) { m_bIsSystem = bFlag; }
274
275 DWORD RefCount();
276 void IncRefCount();
277 void DecRefCount();
278
279 BOOL IsChild(DWORD dwObjectId);
280 BOOL IsTrustedNode(DWORD id);
281
282 void AddChild(NetObj *pObject); // Add reference to child object
283 void AddParent(NetObj *pObject); // Add reference to parent object
284
285 void DeleteChild(NetObj *pObject); // Delete reference to child object
286 void DeleteParent(NetObj *pObject); // Delete reference to parent object
287
288 void Delete(BOOL bIndexLocked); // Prepare object for deletion
289
290 BOOL IsHidden(void) { return m_bIsHidden; }
291 void Hide(void);
292 void Unhide(void);
293
294 virtual BOOL SaveToDB(DB_HANDLE hdb);
295 virtual BOOL DeleteFromDB(void);
296 virtual BOOL CreateFromDB(DWORD dwId);
297
298 void setId(DWORD dwId) { m_dwId = dwId; Modify(); }
299 void generateGuid() { uuid_generate(m_guid); }
300 void setMgmtStatus(BOOL bIsManaged);
301 void setName(const TCHAR *pszName) { nx_strncpy(m_szName, pszName, MAX_OBJECT_NAME); Modify(); }
302 void resetStatus() { m_iStatus = STATUS_UNKNOWN; Modify(); }
303 void setComments(TCHAR *pszText); /* pszText must be dynamically allocated */
304
305 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
306
307 virtual void CreateMessage(CSCPMessage *pMsg);
308 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
309
310 void CommentsToMessage(CSCPMessage *pMsg);
311
312 DWORD GetUserRights(DWORD dwUserId);
313 BOOL CheckAccessRights(DWORD dwUserId, DWORD dwRequiredRights);
314 void DropUserAccess(DWORD dwUserId);
315
316 void AddChildNodesToList(DWORD *pdwNumNodes, Node ***pppNodeList, DWORD dwUserId);
317
318 const TCHAR *GetCustomAttribute(const TCHAR *name) { return m_customAttributes.get(name); }
319 void SetCustomAttribute(const TCHAR *name, const TCHAR *value) { m_customAttributes.set(name, value); Modify(); }
320 void SetCustomAttributePV(const TCHAR *name, TCHAR *value) { m_customAttributes.setPreallocated(_tcsdup(name), value); Modify(); }
321 void DeleteCustomAttribute(const TCHAR *name) { m_customAttributes.remove(name); Modify(); }
322
323 // Debug methods
324 const TCHAR *ParentList(TCHAR *szBuffer);
325 const TCHAR *ChildList(TCHAR *szBuffer);
326 };
327
328
329 //
330 // Inline functions of NetObj class
331 //
332
333 inline DWORD NetObj::RefCount()
334 {
335 DWORD dwRefCount;
336
337 MutexLock(m_mutexRefCount, INFINITE);
338 dwRefCount = m_dwRefCount;
339 MutexUnlock(m_mutexRefCount);
340 return dwRefCount;
341 }
342
343 inline void NetObj::IncRefCount()
344 {
345 MutexLock(m_mutexRefCount, INFINITE);
346 m_dwRefCount++;
347 MutexUnlock(m_mutexRefCount);
348 }
349
350 inline void NetObj::DecRefCount()
351 {
352 MutexLock(m_mutexRefCount, INFINITE);
353 if (m_dwRefCount > 0)
354 m_dwRefCount--;
355 MutexUnlock(m_mutexRefCount);
356 }
357
358
359 //
360 // Node template class
361 //
362
363 class NXCORE_EXPORTABLE Template : public NetObj
364 {
365 protected:
366 DWORD m_dwNumItems; // Number of data collection items
367 DCItem **m_ppItems; // Data collection items
368 DWORD m_dwDCILockStatus;
369 DWORD m_dwVersion;
370 BOOL m_bDCIListModified;
371 TCHAR m_szCurrDCIOwner[MAX_SESSION_NAME];
372 TCHAR *m_applyFilterSource;
373 NXSL_Program *m_applyFilter;
374 MUTEX m_mutexDciAccess;
375
376 virtual void PrepareForDeletion();
377
378 void loadItemsFromDB();
379 void destroyItems();
380
381 void lockDciAccess() { MutexLock(m_mutexDciAccess, INFINITE); }
382 void unlockDciAccess() { MutexUnlock(m_mutexDciAccess); }
383
384 public:
385 Template();
386 Template(const TCHAR *pszName);
387 Template(ConfigEntry *config);
388 virtual ~Template();
389
390 virtual int Type(void) { return OBJECT_TEMPLATE; }
391
392 virtual BOOL SaveToDB(DB_HANDLE hdb);
393 virtual BOOL DeleteFromDB(void);
394 virtual BOOL CreateFromDB(DWORD dwId);
395
396 virtual void CreateMessage(CSCPMessage *pMsg);
397 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
398
399 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
400
401 int getVersionMajor() { return m_dwVersion >> 16; }
402 int getVersionMinor() { return m_dwVersion & 0xFFFF; }
403
404 DWORD getItemCount() { return m_dwNumItems; }
405 bool addItem(DCItem *pItem, bool alreadyLocked = false);
406 bool updateItem(DWORD dwItemId, CSCPMessage *pMsg, DWORD *pdwNumMaps,
407 DWORD **ppdwMapIndex, DWORD **ppdwMapId);
408 bool deleteItem(DWORD dwItemId, bool needLock);
409 bool setItemStatus(DWORD dwNumItems, DWORD *pdwItemList, int iStatus);
410 int getItemType(DWORD dwItemId);
411 DCItem *getItemById(DWORD dwItemId);
412 DCItem *getItemByIndex(DWORD dwIndex);
413 DCItem *getItemByName(const TCHAR *pszName);
414 DCItem *getItemByDescription(const TCHAR *pszDescription);
415 BOOL LockDCIList(DWORD dwSessionId, const TCHAR *pszNewOwner, TCHAR *pszCurrOwner);
416 BOOL UnlockDCIList(DWORD dwSessionId);
417 void SetDCIModificationFlag(void) { m_bDCIListModified = TRUE; }
418 void SendItemsToClient(ClientSession *pSession, DWORD dwRqId);
419 BOOL IsLockedBySession(DWORD dwSessionId) { return m_dwDCILockStatus == dwSessionId; }
420 DWORD *getDCIEventsList(DWORD *pdwCount);
421 void ValidateSystemTemplate(void);
422 void ValidateDCIList(DCI_CFG *cfg);
423
424 BOOL ApplyToNode(Node *pNode);
425 BOOL isApplicable(Node *node);
426 BOOL isAutoApplyEnabled() { return m_applyFilter != NULL; }
427 void setAutoApplyFilter(const TCHAR *filter);
428 void queueUpdate();
429 void queueRemoveFromNode(DWORD dwNodeId, BOOL bRemoveDCI);
430
431 void CreateNXMPRecord(String &str);
432
433 BOOL EnumDCI(BOOL (* pfCallback)(DCItem *, DWORD, void *), void *pArg);
434 void associateItems();
435 };
436
437
438 //
439 // Cluster class
440 //
441
442 class NXCORE_EXPORTABLE Cluster : public Template
443 {
444 protected:
445 DWORD m_dwClusterType;
446 DWORD m_dwNumSyncNets;
447 IP_NETWORK *m_pSyncNetList;
448 DWORD m_dwNumResources;
449 CLUSTER_RESOURCE *m_pResourceList;
450 DWORD m_dwFlags;
451 time_t m_tmLastPoll;
452
453 public:
454 Cluster();
455 Cluster(const TCHAR *pszName);
456 virtual ~Cluster();
457
458 virtual int Type(void) { return OBJECT_CLUSTER; }
459 virtual BOOL SaveToDB(DB_HANDLE hdb);
460 virtual BOOL DeleteFromDB(void);
461 virtual BOOL CreateFromDB(DWORD dwId);
462
463 virtual void CreateMessage(CSCPMessage *pMsg);
464 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
465
466 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
467
468 BOOL isSyncAddr(DWORD dwAddr);
469 BOOL isVirtualAddr(DWORD dwAddr);
470 BOOL isResourceOnNode(DWORD dwResource, DWORD dwNode);
471
472 void statusPoll(ClientSession *pSession, DWORD dwRqId, int nPoller);
473 void lockForStatusPoll() { m_dwFlags |= CLF_QUEUED_FOR_STATUS_POLL; }
474 BOOL isReadyForStatusPoll()
475 {
476 return ((m_iStatus != STATUS_UNMANAGED) && (!m_bIsDeleted) &&
477 (!(m_dwFlags & CLF_QUEUED_FOR_STATUS_POLL)) &&
478 ((DWORD)time(NULL) - (DWORD)m_tmLastPoll > g_dwStatusPollingInterval))
479 ? TRUE : FALSE;
480 }
481 };
482
483
484 //
485 // Interface class
486 //
487
488 class NXCORE_EXPORTABLE Interface : public NetObj
489 {
490 protected:
491 DWORD m_dwIfIndex;
492 DWORD m_dwIfType;
493 DWORD m_dwIpNetMask;
494 BYTE m_bMacAddr[MAC_ADDR_LENGTH];
495 DWORD m_bridgePortNumber; // 802.1D port number
496 DWORD m_slotNumber; // Vendor/device specific slot number
497 DWORD m_portNumber; // Vendor/device specific port number
498 DWORD m_peerNodeId; // ID of peer node object, or 0 if unknown
499 DWORD m_peerInterfaceId; // ID of peer interface object, or 0 if unknown
500 QWORD m_qwLastDownEventId;
501 bool m_bSyntheticMask;
502 int m_iPendingStatus;
503 int m_iPollCount;
504 int m_iRequiredPollCount;
505
506 public:
507 Interface();
508 Interface(DWORD dwAddr, DWORD dwNetMask, bool bSyntheticMask);
509 Interface(const TCHAR *szName, DWORD dwIndex, DWORD dwAddr, DWORD dwNetMask, DWORD dwType);
510 virtual ~Interface();
511
512 virtual int Type() { return OBJECT_INTERFACE; }
513 virtual BOOL SaveToDB(DB_HANDLE hdb);
514 virtual BOOL DeleteFromDB();
515 virtual BOOL CreateFromDB(DWORD dwId);
516
517 Node *getParentNode();
518
519 DWORD getIpNetMask() { return m_dwIpNetMask; }
520 DWORD getIfIndex() { return m_dwIfIndex; }
521 DWORD getIfType() { return m_dwIfType; }
522 DWORD getBridgePortNumber() { return m_bridgePortNumber; }
523 DWORD getSlotNumber() { return m_slotNumber; }
524 DWORD getPortNumber() { return m_portNumber; }
525 DWORD getPeerNodeId() { return m_peerNodeId; }
526 DWORD getPeerInterfaceId() { return m_peerInterfaceId; }
527 const BYTE *getMacAddr() { return m_bMacAddr; }
528 bool isSyntheticMask() { return m_bSyntheticMask; }
529 bool isFake() { return (m_dwIfIndex == 1) &&
530 (m_dwIfType == IFTYPE_OTHER) &&
531 (!_tcscmp(m_szName, _T("lan0")) || !_tcscmp(m_szName, _T("unknown"))) &&
532 (!memcmp(m_bMacAddr, "\x00\x00\x00\x00\x00\x00", 6)); }
533
534 QWORD getLastDownEventId() { return m_qwLastDownEventId; }
535 void setLastDownEventId(QWORD qwId) { m_qwLastDownEventId = qwId; }
536
537 void setMacAddr(const BYTE *pbNewMac) { memcpy(m_bMacAddr, pbNewMac, MAC_ADDR_LENGTH); Modify(); }
538 void setIpAddr(DWORD dwNewAddr);
539 void setIpNetMask(DWORD dwNewMask);
540 void setBridgePortNumber(DWORD bpn) { m_bridgePortNumber = bpn; Modify(); }
541 void setSlotNumber(DWORD slot) { m_slotNumber = slot; Modify(); }
542 void setPortNumber(DWORD port) { m_portNumber = port; Modify(); }
543 void setPeer(DWORD nodeId, DWORD ifId) { m_peerNodeId = nodeId; m_peerInterfaceId = ifId; Modify(); }
544
545 void StatusPoll(ClientSession *pSession, DWORD dwRqId, Queue *pEventQueue,
546 BOOL bClusterSync, SNMP_Transport *pTransport);
547
548 virtual void CreateMessage(CSCPMessage *pMsg);
549 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
550
551 DWORD wakeUp();
552 };
553
554
555 //
556 // Network service class
557 //
558
559 class NetworkService : public NetObj
560 {
561 protected:
562 int m_iServiceType; // SSH, POP3, etc.
563 Node *m_pHostNode; // Pointer to node object which hosts this service
564 DWORD m_dwPollerNode; // ID of node object which is used for polling
565 // If 0, m_pHostNode->m_dwPollerNode will be used
566 WORD m_wProto; // Protocol (TCP, UDP, etc.)
567 WORD m_wPort; // TCP or UDP port number
568 TCHAR *m_pszRequest; // Service-specific request
569 TCHAR *m_pszResponse; // Service-specific expected response
570 int m_iPendingStatus;
571 int m_iPollCount;
572 int m_iRequiredPollCount;
573
574 virtual void OnObjectDelete(DWORD dwObjectId);
575
576 public:
577 NetworkService();
578 NetworkService(int iServiceType, WORD wProto, WORD wPort,
579 TCHAR *pszRequest, TCHAR *pszResponse,
580 Node *pHostNode = NULL, DWORD dwPollerNode = 0);
581 virtual ~NetworkService();
582
583 virtual int Type() { return OBJECT_NETWORKSERVICE; }
584
585 virtual BOOL SaveToDB(DB_HANDLE hdb);
586 virtual BOOL DeleteFromDB();
587 virtual BOOL CreateFromDB(DWORD dwId);
588
589 void StatusPoll(ClientSession *pSession, DWORD dwRqId, Node *pPollerNode, Queue *pEventQueue);
590
591 virtual void CreateMessage(CSCPMessage *pMsg);
592 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
593 };
594
595
596 //
597 // VPN connector class
598 //
599
600 class VPNConnector : public NetObj
601 {
602 protected:
603 DWORD m_dwPeerGateway; // Object ID of peer gateway
604 DWORD m_dwNumLocalNets;
605 IP_NETWORK *m_pLocalNetList;
606 DWORD m_dwNumRemoteNets;
607 IP_NETWORK *m_pRemoteNetList;
608
609 Node *GetParentNode();
610
611 public:
612 VPNConnector();
613 VPNConnector(BOOL bIsHidden);
614 virtual ~VPNConnector();
615
616 virtual int Type() { return OBJECT_VPNCONNECTOR; }
617
618 virtual BOOL SaveToDB(DB_HANDLE hdb);
619 virtual BOOL DeleteFromDB();
620 virtual BOOL CreateFromDB(DWORD dwId);
621
622 virtual void CreateMessage(CSCPMessage *pMsg);
623 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
624
625 BOOL IsLocalAddr(DWORD dwIpAddr);
626 BOOL IsRemoteAddr(DWORD dwIpAddr);
627 DWORD GetPeerGatewayAddr();
628 };
629
630
631 //
632 // Node
633 //
634
635 class NXCORE_EXPORTABLE Node : public Template
636 {
637 protected:
638 TCHAR m_primaryName[MAX_DNS_NAME];
639 DWORD m_dwFlags;
640 DWORD m_dwDynamicFlags; // Flags used at runtime by server
641 int m_iPendingStatus;
642 int m_iPollCount;
643 int m_iRequiredPollCount;
644 DWORD m_dwZoneGUID;
645 WORD m_wAgentPort;
646 WORD m_wAuthMethod;
647 TCHAR m_szSharedSecret[MAX_SECRET_LENGTH];
648 int m_iStatusPollType;
649 int m_snmpVersion;
650 WORD m_wSNMPPort;
651 WORD m_nUseIfXTable;
652 SNMP_SecurityContext *m_snmpSecurity;
653 TCHAR m_szObjectId[MAX_OID_LEN * 4];
654 TCHAR m_szAgentVersion[MAX_AGENT_VERSION_LEN];
655 TCHAR m_szPlatformName[MAX_PLATFORM_NAME_LEN];
656 TCHAR *m_sysDescription; // Agent's System.Uname or SNMP sysDescr
657 TCHAR *m_sysName; // SNMP sysName
658 TCHAR *m_lldpNodeId; // lldpLocChassisId combined with lldpLocChassisIdSubtype, or NULL for non-LLDP nodes
659 NetworkDeviceDriver *m_driver;
660 DWORD m_dwNumParams; // Number of elements in supported parameters list
661 NXC_AGENT_PARAM *m_pParamList; // List of supported parameters
662 time_t m_tLastDiscoveryPoll;
663 time_t m_tLastStatusPoll;
664 time_t m_tLastConfigurationPoll;
665 time_t m_tLastTopologyPoll;
666 time_t m_tLastRTUpdate;
667 time_t m_tFailTimeSNMP;
668 time_t m_tFailTimeAgent;
669 MUTEX m_hPollerMutex;
670 MUTEX m_hAgentAccessMutex;
671 MUTEX m_mutexRTAccess;
672 MUTEX m_mutexTopoAccess;
673 AgentConnectionEx *m_pAgentConnection;
674 DWORD m_dwPollerNode; // Node used for network service polling
675 DWORD m_dwProxyNode; // Node used as proxy for agent connection
676 DWORD m_dwSNMPProxy; // Node used as proxy for SNMP requests
677 QWORD m_qwLastEvents[MAX_LAST_EVENTS];
678 ROUTING_TABLE *m_pRoutingTable;
679 ForwardingDatabase *m_fdb;
680 LinkLayerNeighbors *m_linkLayerNeighbors;
681 VrrpInfo *m_vrrpInfo;
682 nxmap_ObjList *m_pTopology; // For compatibility, to be removed in 1.1.x
683 time_t m_topologyRebuildTimestamp;
684 ServerJobQueue *m_jobQueue;
685
686 void pollerLock() { MutexLock(m_hPollerMutex, INFINITE); }
687 void pollerUnlock() { MutexUnlock(m_hPollerMutex); }
688
689 void agentLock() { MutexLock(m_hAgentAccessMutex, INFINITE); }
690 void agentUnlock() { MutexUnlock(m_hAgentAccessMutex); }
691
692 void routingTableLock() { MutexLock(m_mutexRTAccess, INFINITE); }
693 void routingTableUnlock() { MutexUnlock(m_mutexRTAccess); }
694
695 BOOL CheckSNMPIntegerValue(SNMP_Transport *pTransport, const TCHAR *pszOID, int nValue);
696 void CheckOSPFSupport(SNMP_Transport *pTransport);
697 void addVrrpInterfaces(InterfaceList *ifList);
698 BOOL ResolveName(BOOL useOnlyDNS);
699 void setAgentProxy(AgentConnection *pConn);
700
701 DWORD getInterfaceCount(Interface **ppInterface);
702
703 void CheckInterfaceNames(InterfaceList *pIfList);
704 void CheckSubnetBinding(InterfaceList *pIfList);
705 void checkAgentPolicyBinding(AgentConnection *conn);
706
707 void ApplySystemTemplates();
708 void ApplyUserTemplates();
709
710 void updateContainerMembership();
711 BOOL updateInterfaceConfiguration(DWORD dwRqId, DWORD dwNetMask);
712
713 virtual void PrepareForDeletion();
714 virtual void OnObjectDelete(DWORD dwObjectId);
715
716 public:
717 Node();
718 Node(DWORD dwAddr, DWORD dwFlags, DWORD dwProxyNode, DWORD dwSNMPProxy, DWORD dwZone);
719 virtual ~Node();
720
721 virtual int Type(void) { return OBJECT_NODE; }
722
723 virtual BOOL SaveToDB(DB_HANDLE hdb);
724 virtual BOOL DeleteFromDB();
725 virtual BOOL CreateFromDB(DWORD dwId);
726
727 TCHAR *expandText(const TCHAR *pszTemplate);
728
729 Cluster *getMyCluster();
730
731 DWORD getFlags() { return m_dwFlags; }
732 DWORD getRuntimeFlags() { return m_dwDynamicFlags; }
733 DWORD getZoneGUID() { return m_dwZoneGUID; }
734 void setLocalMgmtFlag() { m_dwFlags |= NF_IS_LOCAL_MGMT; }
735 void clearLocalMgmtFlag() { m_dwFlags &= ~NF_IS_LOCAL_MGMT; }
736
737 bool isSNMPSupported() { return m_dwFlags & NF_IS_SNMP ? true : false; }
738 bool isNativeAgent() { return m_dwFlags & NF_IS_NATIVE_AGENT ? true : false; }
739 bool isBridge() { return m_dwFlags & NF_IS_BRIDGE ? true : false; }
740 bool isRouter() { return m_dwFlags & NF_IS_ROUTER ? true : false; }
741 bool isLocalManagement() { return m_dwFlags & NF_IS_LOCAL_MGMT ? true : false; }
742
743 LONG getSNMPVersion() { return m_snmpVersion; }
744 const TCHAR *getSNMPObjectId() { return m_szObjectId; }
745 const TCHAR *getAgentVersion() { return m_szAgentVersion; }
746 const TCHAR *getPlatformName() { return m_szPlatformName; }
747 const TCHAR *getObjectId() { return m_szObjectId; }
748 const TCHAR *getSysName() { return CHECK_NULL_EX(m_sysName); }
749 const TCHAR *getLLDPNodeId() { return m_lldpNodeId; }
750
751 BOOL isDown() { return m_dwDynamicFlags & NDF_UNREACHABLE ? TRUE : FALSE; }
752
753 void addInterface(Interface *pInterface) { AddChild(pInterface); pInterface->AddParent(this); }
754 void createNewInterface(DWORD dwAddr, DWORD dwNetMask, const TCHAR *name = NULL,
755 DWORD dwIndex = 0, DWORD dwType = 0, BYTE *pbMacAddr = NULL, DWORD bridgePort = 0,
756 DWORD slot = 0, DWORD port = 0);
757 void deleteInterface(Interface *pInterface);
758
759 void changeIPAddress(DWORD dwIpAddr);
760
761 ARP_CACHE *getArpCache();
762 InterfaceList *getInterfaceList();
763 Interface *findInterface(DWORD dwIndex, DWORD dwHostAddr);
764 Interface *findInterface(const TCHAR *name);
765 Interface *findInterfaceByMAC(const BYTE *macAddr);
766 Interface *findInterfaceByIP(DWORD ipAddr);
767 Interface *findInterfaceBySlotAndPort(DWORD slot, DWORD port);
768 Interface *findBridgePort(DWORD bridgePortNumber);
769 BOOL isMyIP(DWORD dwIpAddr);
770 int getInterfaceStatusFromSNMP(SNMP_Transport *pTransport, DWORD dwIndex);
771 int getInterfaceStatusFromAgent(DWORD dwIndex);
772 ROUTING_TABLE *getRoutingTable();
773 ROUTING_TABLE *getCachedRoutingTable() { return m_pRoutingTable; }
774 LinkLayerNeighbors *getLinkLayerNeighbors();
775 BOOL getNextHop(DWORD dwSrcAddr, DWORD dwDestAddr, DWORD *pdwNextHop,
776 DWORD *pdwIfIndex, BOOL *pbIsVPN);
777
778 void setRecheckCapsFlag() { m_dwDynamicFlags |= NDF_RECHECK_CAPABILITIES; }
779 void setDiscoveryPollTimeStamp();
780 void statusPoll(ClientSession *pSession, DWORD dwRqId, int nPoller);
781 void configurationPoll(ClientSession *pSession, DWORD dwRqId, int nPoller, DWORD dwNetMask);
782 void topologyPoll(int nPoller);
783 void updateInterfaceNames(ClientSession *pSession, DWORD dwRqId);
784 void updateRoutingTable();
785 bool isReadyForStatusPoll();
786 bool isReadyForConfigurationPoll();
787 bool isReadyForDiscoveryPoll();
788 bool isReadyForRoutePoll();
789 bool isReadyForTopologyPoll();
790 void lockForStatusPoll();
791 void lockForConfigurationPoll();
792 void lockForDiscoveryPoll();
793 void lockForRoutePoll();
794 void lockForTopologyPoll();
795 void forceConfigurationPoll() { m_dwDynamicFlags |= NDF_FORCE_CONFIGURATION_POLL; }
796
797 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
798
799 BOOL connectToAgent(DWORD *error = NULL, DWORD *socketError = NULL);
800 DWORD GetItemFromSNMP(WORD port, const TCHAR *szParam, DWORD dwBufSize, TCHAR *szBuffer);
801 DWORD GetItemFromCheckPointSNMP(const TCHAR *szParam, DWORD dwBufSize, TCHAR *szBuffer);
802 DWORD GetItemFromAgent(const TCHAR *szParam, DWORD dwBufSize, TCHAR *szBuffer);
803 DWORD GetInternalItem(const TCHAR *szParam, DWORD dwBufSize, TCHAR *szBuffer);
804 DWORD getTableFromAgent(const TCHAR *name, Table **table);
805 void queueItemsForPolling(Queue *pPollerQueue);
806 DWORD getItemForClient(int iOrigin, const TCHAR *pszParam, TCHAR *pszBuffer, DWORD dwBufSize);
807 DWORD getTableForClient(const TCHAR *name, Table **table);
808 DWORD getLastValues(CSCPMessage *pMsg);
809 void processNewDciValue(DCItem *item, time_t currTime, const TCHAR *value);
810 void cleanDCIData();
811 BOOL applyTemplateItem(DWORD dwTemplateId, DCItem *pItem);
812 void cleanDeletedTemplateItems(DWORD dwTemplateId, DWORD dwNumItems, DWORD *pdwItemList);
813 void unbindFromTemplate(DWORD dwTemplateId, BOOL bRemoveDCI);
814 void updateDciCache();
815 DWORD getPerfTabDCIList(CSCPMessage *pMsg);
816 NXSL_Array *getParentsForNXSL();
817
818 void OpenParamList(DWORD *pdwNumParams, NXC_AGENT_PARAM **ppParamList);
819 void CloseParamList(void) { UnlockData(); }
820
821 AgentConnectionEx *createAgentConnection();
822 SNMP_Transport *createSnmpTransport(WORD port = 0);
823 SNMP_SecurityContext *getSnmpSecurityContext();
824
825 virtual void CreateMessage(CSCPMessage *pMsg);
826 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
827 void WriteParamListToMessage(CSCPMessage *pMsg);
828
829 DWORD wakeUp();
830
831 void AddService(NetworkService *pNetSrv) { AddChild(pNetSrv); pNetSrv->AddParent(this); }
832 DWORD CheckNetworkService(DWORD *pdwStatus, DWORD dwIpAddr, int iServiceType, WORD wPort = 0,
833 WORD wProto = 0, TCHAR *pszRequest = NULL, TCHAR *pszResponse = NULL);
834
835 QWORD GetLastEventId(int nIndex) { return ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) ? m_qwLastEvents[nIndex] : 0; }
836 void SetLastEventId(int nIndex, QWORD qwId) { if ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) m_qwLastEvents[nIndex] = qwId; }
837
838 DWORD CallSnmpEnumerate(const TCHAR *pszRootOid,
839 DWORD (* pHandler)(DWORD, SNMP_Variable *, SNMP_Transport *, void *), void *pArg);
840
841 nxmap_ObjList *GetL2Topology();
842 nxmap_ObjList *BuildL2Topology(DWORD *pdwStatus);
843 ForwardingDatabase *getSwitchForwardingDatabase();
844 Interface *findConnectionPoint(DWORD *localIfId, BYTE *localMacAddr);
845
846 ServerJobQueue *getJobQueue() { return m_jobQueue; }
847 };
848
849
850 //
851 // Inline functions for Node class
852 //
853
854 inline void Node::setDiscoveryPollTimeStamp()
855 {
856 m_tLastDiscoveryPoll = time(NULL);
857 m_dwDynamicFlags &= ~NDF_QUEUED_FOR_DISCOVERY_POLL;
858 }
859
860 inline bool Node::isReadyForStatusPoll()
861 {
862 if (m_bIsDeleted)
863 return false;
864 //if (GetMyCluster() != NULL)
865 // return FALSE; // Cluster nodes should be polled from cluster status poll
866 if (m_dwDynamicFlags & NDF_FORCE_STATUS_POLL)
867 {
868 m_dwDynamicFlags &= ~NDF_FORCE_STATUS_POLL;
869 return true;
870 }
871 return (m_iStatus != STATUS_UNMANAGED) &&
872 (!(m_dwFlags & NF_DISABLE_STATUS_POLL)) &&
873 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_STATUS_POLL)) &&
874 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
875 (getMyCluster() == NULL) &&
876 ((DWORD)time(NULL) - (DWORD)m_tLastStatusPoll > g_dwStatusPollingInterval);
877 }
878
879 inline bool Node::isReadyForConfigurationPoll()
880 {
881 if (m_bIsDeleted)
882 return false;
883 if (m_dwDynamicFlags & NDF_FORCE_CONFIGURATION_POLL)
884 {
885 m_dwDynamicFlags &= ~NDF_FORCE_CONFIGURATION_POLL;
886 return true;
887 }
888 return (m_iStatus != STATUS_UNMANAGED) &&
889 (!(m_dwFlags & NF_DISABLE_CONF_POLL)) &&
890 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_CONFIG_POLL)) &&
891 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
892 ((DWORD)time(NULL) - (DWORD)m_tLastConfigurationPoll > g_dwConfigurationPollingInterval);
893 }
894
895 inline bool Node::isReadyForDiscoveryPoll()
896 {
897 if (m_bIsDeleted)
898 return false;
899 return (g_dwFlags & AF_ENABLE_NETWORK_DISCOVERY) &&
900 (m_iStatus != STATUS_UNMANAGED) &&
901 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_DISCOVERY_POLL)) &&
902 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
903 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
904 ((DWORD)time(NULL) - (DWORD)m_tLastDiscoveryPoll > g_dwDiscoveryPollingInterval);
905 }
906
907 inline bool Node::isReadyForRoutePoll()
908 {
909 if (m_bIsDeleted)
910 return false;
911 return (m_iStatus != STATUS_UNMANAGED) &&
912 (!(m_dwFlags & NF_DISABLE_ROUTE_POLL)) &&
913 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_ROUTE_POLL)) &&
914 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
915 ((DWORD)time(NULL) - (DWORD)m_tLastRTUpdate > g_dwRoutingTableUpdateInterval);
916 }
917
918 inline bool Node::isReadyForTopologyPoll()
919 {
920 if (m_bIsDeleted)
921 return false;
922 return (m_iStatus != STATUS_UNMANAGED) &&
923 (!(m_dwFlags & NF_DISABLE_TOPOLOGY_POLL)) &&
924 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_TOPOLOGY_POLL)) &&
925 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
926 ((DWORD)time(NULL) - (DWORD)m_tLastTopologyPoll > g_dwTopologyPollingInterval);
927 }
928
929 inline void Node::lockForStatusPoll()
930 {
931 LockData();
932 m_dwDynamicFlags |= NDF_QUEUED_FOR_STATUS_POLL;
933 UnlockData();
934 }
935
936 inline void Node::lockForConfigurationPoll()
937 {
938 LockData();
939 m_dwDynamicFlags |= NDF_QUEUED_FOR_CONFIG_POLL;
940 UnlockData();
941 }
942
943 inline void Node::lockForDiscoveryPoll()
944 {
945 LockData();
946 m_dwDynamicFlags |= NDF_QUEUED_FOR_DISCOVERY_POLL;
947 UnlockData();
948 }
949
950 inline void Node::lockForTopologyPoll()
951 {
952 LockData();
953 m_dwDynamicFlags |= NDF_QUEUED_FOR_TOPOLOGY_POLL;
954 UnlockData();
955 }
956
957 inline void Node::lockForRoutePoll()
958 {
959 LockData();
960 m_dwDynamicFlags |= NDF_QUEUED_FOR_ROUTE_POLL;
961 UnlockData();
962 }
963
964
965 //
966 // Subnet
967 //
968
969 class NXCORE_EXPORTABLE Subnet : public NetObj
970 {
971 protected:
972 DWORD m_dwIpNetMask;
973 DWORD m_dwZoneGUID;
974 bool m_bSyntheticMask;
975
976 public:
977 Subnet();
978 Subnet(DWORD dwAddr, DWORD dwNetMask, DWORD dwZone, bool bSyntheticMask);
979 virtual ~Subnet();
980
981 virtual int Type() { return OBJECT_SUBNET; }
982
983 virtual BOOL SaveToDB(DB_HANDLE hdb);
984 virtual BOOL DeleteFromDB(void);
985 virtual BOOL CreateFromDB(DWORD dwId);
986
987 void AddNode(Node *pNode) { AddChild(pNode); pNode->AddParent(this); }
988 virtual void CreateMessage(CSCPMessage *pMsg);
989
990 DWORD getIpNetMask() { return m_dwIpNetMask; }
991 DWORD getZoneGUID() { return m_dwZoneGUID; }
992 bool isSyntheticMask() { return m_bSyntheticMask; }
993
994 void setCorrectMask(DWORD dwAddr, DWORD dwMask);
995 };
996
997
998 //
999 // Universal root object
1000 //
1001
1002 class NXCORE_EXPORTABLE UniversalRoot : public NetObj
1003 {
1004 public:
1005 UniversalRoot();
1006 virtual ~UniversalRoot();
1007
1008 virtual BOOL SaveToDB(DB_HANDLE hdb);
1009 virtual void LoadFromDB(void);
1010 virtual const char *DefaultName(void) { return "Root Object"; }
1011
1012 void LinkChildObjects(void);
1013 void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
1014 };
1015
1016
1017 //
1018 // Service root
1019 //
1020
1021 class NXCORE_EXPORTABLE ServiceRoot : public UniversalRoot
1022 {
1023 public:
1024 ServiceRoot();
1025 virtual ~ServiceRoot();
1026
1027 virtual int Type(void) { return OBJECT_SERVICEROOT; }
1028 virtual const char *DefaultName(void) { return "All Services"; }
1029 };
1030
1031
1032 //
1033 // Template root
1034 //
1035
1036 class NXCORE_EXPORTABLE TemplateRoot : public UniversalRoot
1037 {
1038 public:
1039 TemplateRoot();
1040 virtual ~TemplateRoot();
1041
1042 virtual int Type(void) { return OBJECT_TEMPLATEROOT; }
1043 virtual const char *DefaultName(void) { return "Templates"; }
1044 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1045 };
1046
1047
1048 //
1049 // Generic container object
1050 //
1051
1052 class NXCORE_EXPORTABLE Container : public NetObj
1053 {
1054 private:
1055 DWORD *m_pdwChildIdList;
1056 DWORD m_dwChildIdListSize;
1057
1058 protected:
1059 DWORD m_dwCategory;
1060 NXSL_Program *m_bindFilter;
1061 TCHAR *m_bindFilterSource;
1062
1063 public:
1064 Container();
1065 Container(TCHAR *pszName, DWORD dwCategory);
1066 virtual ~Container();
1067
1068 virtual int Type(void) { return OBJECT_CONTAINER; }
1069
1070 virtual BOOL SaveToDB(DB_HANDLE hdb);
1071 virtual BOOL DeleteFromDB(void);
1072 virtual BOOL CreateFromDB(DWORD dwId);
1073
1074 virtual void CreateMessage(CSCPMessage *pMsg);
1075 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1076
1077 DWORD Category(void) { return m_dwCategory; }
1078
1079 void LinkChildObjects(void);
1080 void LinkObject(NetObj *pObject) { AddChild(pObject); pObject->AddParent(this); }
1081
1082 BOOL IsSuitableForNode(Node *node);
1083 BOOL IsAutoBindEnabled() { return m_bindFilter != NULL; }
1084
1085 void setAutoBindFilter(const TCHAR *script);
1086 };
1087
1088
1089 //
1090 // Template group object
1091 //
1092
1093 class NXCORE_EXPORTABLE TemplateGroup : public Container
1094 {
1095 public:
1096 TemplateGroup() : Container() { }
1097 TemplateGroup(TCHAR *pszName) : Container(pszName, 0) { }
1098 virtual ~TemplateGroup() { }
1099
1100 virtual int Type(void) { return OBJECT_TEMPLATEGROUP; }
1101 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1102 };
1103
1104
1105 //
1106 // Zone object
1107 //
1108
1109 class Zone : public NetObj
1110 {
1111 protected:
1112 DWORD m_dwZoneGUID;
1113 int m_iZoneType;
1114 DWORD m_dwControllerIpAddr;
1115 DWORD m_dwAddrListSize;
1116 DWORD *m_pdwIpAddrList;
1117
1118 public:
1119 Zone();
1120 virtual ~Zone();
1121
1122 virtual int Type(void) { return OBJECT_ZONE; }
1123
1124 virtual BOOL SaveToDB(DB_HANDLE hdb);
1125 virtual BOOL DeleteFromDB(void);
1126 virtual BOOL CreateFromDB(DWORD dwId);
1127
1128 virtual void CreateMessage(CSCPMessage *pMsg);
1129 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1130
1131 DWORD GUID(void) { return m_dwZoneGUID; }
1132
1133 void AddSubnet(Subnet *pSubnet) { AddChild(pSubnet); pSubnet->AddParent(this); }
1134 };
1135
1136
1137 //
1138 // Entire network
1139 //
1140
1141 class NXCORE_EXPORTABLE Network : public NetObj
1142 {
1143 public:
1144 Network();
1145 virtual ~Network();
1146
1147 virtual int Type(void) { return OBJECT_NETWORK; }
1148 virtual BOOL SaveToDB(DB_HANDLE hdb);
1149
1150 void AddSubnet(Subnet *pSubnet) { AddChild(pSubnet); pSubnet->AddParent(this); }
1151 void AddZone(Zone *pZone) { AddChild(pZone); pZone->AddParent(this); }
1152 void LoadFromDB(void);
1153 };
1154
1155
1156 //
1157 // Condition
1158 //
1159
1160 class NXCORE_EXPORTABLE Condition : public NetObj
1161 {
1162 protected:
1163 DWORD m_dwDCICount;
1164 INPUT_DCI *m_pDCIList;
1165 TCHAR *m_pszScript;
1166 NXSL_Program *m_pCompiledScript;
1167 DWORD m_dwActivationEventCode;
1168 DWORD m_dwDeactivationEventCode;
1169 DWORD m_dwSourceObject;
1170 int m_nActiveStatus;
1171 int m_nInactiveStatus;
1172 BOOL m_bIsActive;
1173 time_t m_tmLastPoll;
1174 BOOL m_bQueuedForPolling;
1175
1176 public:
1177 Condition();
1178 Condition(BOOL bHidden);
1179 virtual ~Condition();
1180
1181 virtual int Type() { return OBJECT_CONDITION; }
1182
1183 virtual BOOL SaveToDB(DB_HANDLE hdb);
1184 virtual BOOL DeleteFromDB(void);
1185 virtual BOOL CreateFromDB(DWORD dwId);
1186
1187 virtual void CreateMessage(CSCPMessage *pMsg);
1188 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1189
1190 void check();
1191
1192 void LockForPoll(void);
1193 void EndPoll(void);
1194
1195 BOOL ReadyForPoll(void)
1196 {
1197 return ((m_iStatus != STATUS_UNMANAGED) &&
1198 (!m_bQueuedForPolling) && (!m_bIsDeleted) &&
1199 ((DWORD)time(NULL) - (DWORD)m_tmLastPoll > g_dwConditionPollingInterval))
1200 ? TRUE : FALSE;
1201 }
1202
1203 int getCacheSizeForDCI(DWORD dwItemId, BOOL bNoLock);
1204 };
1205
1206
1207 //
1208 // Generic agent policy object
1209 //
1210
1211 class NXCORE_EXPORTABLE AgentPolicy : public NetObj
1212 {
1213 protected:
1214 DWORD m_version;
1215 int m_policyType;
1216 TCHAR *m_description;
1217
1218 BOOL savePolicyCommonProperties(DB_HANDLE hdb);
1219
1220 public:
1221 AgentPolicy(int type);
1222 AgentPolicy(const TCHAR *name, int type);
1223 virtual ~AgentPolicy();
1224
1225 virtual int Type() { return OBJECT_AGENTPOLICY; }
1226
1227 virtual BOOL SaveToDB(DB_HANDLE hdb);
1228 virtual BOOL DeleteFromDB();
1229 virtual BOOL CreateFromDB(DWORD dwId);
1230
1231 virtual void CreateMessage(CSCPMessage *pMsg);
1232 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1233
1234 virtual bool createDeploymentMessage(CSCPMessage *msg);
1235 virtual bool createUninstallMessage(CSCPMessage *msg);
1236
1237 void linkNode(Node *node) { AddChild(node); node->AddParent(this); }
1238 void unlinkNode(Node *node) { DeleteChild(node); node->DeleteParent(this); }
1239 };
1240
1241
1242 //
1243 // Agent config policy object
1244 //
1245
1246 class NXCORE_EXPORTABLE AgentPolicyConfig : public AgentPolicy
1247 {
1248 protected:
1249 TCHAR *m_fileContent;
1250
1251 public:
1252 AgentPolicyConfig();
1253 AgentPolicyConfig(const TCHAR *name);
1254 virtual ~AgentPolicyConfig();
1255
1256 virtual int Type() { return OBJECT_AGENTPOLICY_CONFIG; }
1257
1258 virtual BOOL SaveToDB(DB_HANDLE hdb);
1259 virtual BOOL DeleteFromDB();
1260 virtual BOOL CreateFromDB(DWORD dwId);
1261
1262 virtual void CreateMessage(CSCPMessage *pMsg);
1263 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1264
1265 virtual bool createDeploymentMessage(CSCPMessage *msg);
1266 virtual bool createUninstallMessage(CSCPMessage *msg);
1267 };
1268
1269
1270 //
1271 // Policy group object
1272 //
1273
1274 class NXCORE_EXPORTABLE PolicyGroup : public Container
1275 {
1276 public:
1277 PolicyGroup() : Container() { }
1278 PolicyGroup(TCHAR *pszName) : Container(pszName, 0) { }
1279 virtual ~PolicyGroup() { }
1280
1281 virtual int Type() { return OBJECT_POLICYGROUP; }
1282 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1283 };
1284
1285
1286 //
1287 // Policy root
1288 //
1289
1290 class NXCORE_EXPORTABLE PolicyRoot : public UniversalRoot
1291 {
1292 public:
1293 PolicyRoot();
1294 virtual ~PolicyRoot();
1295
1296 virtual int Type() { return OBJECT_POLICYROOT; }
1297 virtual const char *DefaultName(void) { return "Policies"; }
1298 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1299 };
1300
1301
1302 //
1303 // Network map root
1304 //
1305
1306 class NXCORE_EXPORTABLE NetworkMapRoot : public UniversalRoot
1307 {
1308 public:
1309 NetworkMapRoot();
1310 virtual ~NetworkMapRoot();
1311
1312 virtual int Type() { return OBJECT_NETWORKMAPROOT; }
1313 virtual const char *DefaultName() { return "Network Maps"; }
1314 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1315 };
1316
1317
1318 //
1319 // Network map group object
1320 //
1321
1322 class NXCORE_EXPORTABLE NetworkMapGroup : public Container
1323 {
1324 public:
1325 NetworkMapGroup() : Container() { }
1326 NetworkMapGroup(TCHAR *pszName) : Container(pszName, 0) { }
1327 virtual ~NetworkMapGroup() { }
1328
1329 virtual int Type() { return OBJECT_NETWORKMAPGROUP; }
1330 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1331 };
1332
1333
1334 //
1335 // Network map object
1336 //
1337
1338 class NXCORE_EXPORTABLE NetworkMap : public NetObj
1339 {
1340 protected:
1341 int m_mapType;
1342 DWORD m_seedObject;
1343 int m_layout;
1344 uuid_t m_background;
1345 int m_numElements;
1346 NetworkMapElement **m_elements;
1347 int m_numLinks;
1348 NetworkMapLink **m_links;
1349
1350 public:
1351 NetworkMap();
1352 NetworkMap(int type, DWORD seed);
1353 virtual ~NetworkMap();
1354
1355 virtual int Type() { return OBJECT_NETWORKMAP; }
1356 virtual void CalculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1357
1358 virtual BOOL SaveToDB(DB_HANDLE hdb);
1359 virtual BOOL DeleteFromDB();
1360 virtual BOOL CreateFromDB(DWORD dwId);
1361
1362 virtual void CreateMessage(CSCPMessage *pMsg);
1363 virtual DWORD ModifyFromMessage(CSCPMessage *pRequest, BOOL bAlreadyLocked = FALSE);
1364 };
1365
1366
1367 //
1368 // Object index structure
1369 //
1370
1371 struct INDEX
1372 {
1373 DWORD dwKey;
1374 void *pObject;
1375 };
1376
1377
1378 //
1379 // Container category information
1380 //
1381
1382 struct CONTAINER_CATEGORY
1383 {
1384 DWORD dwCatId;
1385 TCHAR szName[MAX_OBJECT_NAME];
1386 TCHAR *pszDescription;
1387 DWORD dwImageId;
1388 };
1389
1390
1391 //
1392 // Functions
1393 //
1394
1395 void ObjectsInit();
1396
1397 void NXCORE_EXPORTABLE NetObjInsert(NetObj *pObject, BOOL bNewObject);
1398 void NetObjDeleteFromIndexes(NetObj *pObject);
1399 void NetObjDelete(NetObj *pObject);
1400
1401 void UpdateNodeIndex(DWORD dwOldIpAddr, DWORD dwNewIpAddr, NetObj *pObject);
1402 void UpdateInterfaceIndex(DWORD dwOldIpAddr, DWORD dwNewIpAddr, NetObj *pObject);
1403
1404 NetObj NXCORE_EXPORTABLE *FindObjectById(DWORD dwId);
1405 NetObj NXCORE_EXPORTABLE *FindObjectByName(const TCHAR *name, int objClass);
1406 NetObj NXCORE_EXPORTABLE *FindObjectByGUID(uuid_t guid, int objClass);
1407 Template NXCORE_EXPORTABLE *FindTemplateByName(const TCHAR *pszName);
1408 Node NXCORE_EXPORTABLE *FindNodeByIP(DWORD dwAddr);
1409 Node NXCORE_EXPORTABLE *FindNodeByMAC(const BYTE *macAddr);
1410 Node NXCORE_EXPORTABLE *FindNodeByLLDPId(const TCHAR *lldpId);
1411 Interface NXCORE_EXPORTABLE *FindInterfaceByMAC(const BYTE *macAddr);
1412 Subnet NXCORE_EXPORTABLE *FindSubnetByIP(DWORD dwAddr);
1413 Subnet NXCORE_EXPORTABLE *FindSubnetForNode(DWORD dwNodeAddr);
1414 DWORD NXCORE_EXPORTABLE FindLocalMgmtNode(void);
1415 CONTAINER_CATEGORY NXCORE_EXPORTABLE *FindContainerCategory(DWORD dwId);
1416 Zone NXCORE_EXPORTABLE *FindZoneByGUID(DWORD dwZoneGUID);
1417 Cluster NXCORE_EXPORTABLE *FindClusterByResourceIP(DWORD ipAddr);
1418 bool NXCORE_EXPORTABLE IsClusterIP(DWORD ipAddr);
1419
1420 BOOL LoadObjects();
1421 void DumpObjects(CONSOLE_CTX pCtx);
1422
1423 void DeleteUserFromAllObjects(DWORD dwUserId);
1424
1425 BOOL IsValidParentClass(int iChildClass, int iParentClass);
1426 bool IsAgentPolicyObject(NetObj *object);
1427
1428 int DefaultPropagatedStatus(int iObjectStatus);
1429 int GetDefaultStatusCalculation(int *pnSingleThreshold, int **ppnThresholds);
1430
1431
1432 //
1433 // Global variables
1434 //
1435
1436 extern Network NXCORE_EXPORTABLE *g_pEntireNet;
1437 extern ServiceRoot NXCORE_EXPORTABLE *g_pServiceRoot;
1438 extern TemplateRoot NXCORE_EXPORTABLE *g_pTemplateRoot;
1439 extern PolicyRoot NXCORE_EXPORTABLE *g_pPolicyRoot;
1440
1441 extern DWORD NXCORE_EXPORTABLE g_dwMgmtNode;
1442 extern INDEX NXCORE_EXPORTABLE *g_pIndexById;
1443 extern DWORD NXCORE_EXPORTABLE g_dwIdIndexSize;
1444 extern INDEX NXCORE_EXPORTABLE *g_pSubnetIndexByAddr;
1445 extern DWORD NXCORE_EXPORTABLE g_dwSubnetAddrIndexSize;
1446 extern INDEX NXCORE_EXPORTABLE *g_pNodeIndexByAddr;
1447 extern DWORD NXCORE_EXPORTABLE g_dwNodeAddrIndexSize;
1448 extern INDEX NXCORE_EXPORTABLE *g_pInterfaceIndexByAddr;
1449 extern DWORD NXCORE_EXPORTABLE g_dwInterfaceAddrIndexSize;
1450 extern INDEX NXCORE_EXPORTABLE *g_pZoneIndexByGUID;
1451 extern DWORD NXCORE_EXPORTABLE g_dwZoneGUIDIndexSize;
1452 extern INDEX NXCORE_EXPORTABLE *g_pConditionIndex;
1453 extern DWORD NXCORE_EXPORTABLE g_dwConditionIndexSize;
1454 extern RWLOCK NXCORE_EXPORTABLE g_rwlockIdIndex;
1455 extern RWLOCK NXCORE_EXPORTABLE g_rwlockNodeIndex;
1456 extern RWLOCK NXCORE_EXPORTABLE g_rwlockSubnetIndex;
1457 extern RWLOCK NXCORE_EXPORTABLE g_rwlockInterfaceIndex;
1458 extern RWLOCK NXCORE_EXPORTABLE g_rwlockZoneIndex;
1459 extern RWLOCK NXCORE_EXPORTABLE g_rwlockConditionIndex;
1460 extern DWORD g_dwNumCategories;
1461 extern CONTAINER_CATEGORY *g_pContainerCatList;
1462 extern const TCHAR *g_szClassName[];
1463 extern BOOL g_bModificationsLocked;
1464 extern Queue *g_pTemplateUpdateQueue;
1465
1466
1467 #endif /* _nms_objects_h_ */