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