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