59e816d245a08569fe13d5ee6b850b854b682513
[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
579 void setId(UINT32 dwId) { m_id = dwId; setModified(); }
580 void generateGuid() { m_guid = uuid::generate(); }
581 void setName(const TCHAR *pszName) { nx_strncpy(m_name, pszName, MAX_OBJECT_NAME); setModified(); }
582 void resetStatus() { m_status = STATUS_UNKNOWN; setModified(); }
583 void setComments(TCHAR *text); /* text must be dynamically allocated */
584
585 bool isInMaintenanceMode() { return m_maintenanceMode; }
586 UINT64 getMaintenanceEventId() { return m_maintenanceEventId; }
587 virtual void enterMaintenanceMode();
588 virtual void leaveMaintenanceMode();
589
590 void fillMessage(NXCPMessage *msg);
591 UINT32 modifyFromMessage(NXCPMessage *msg);
592
593 virtual void postModify();
594
595 void commentsToMessage(NXCPMessage *pMsg);
596
597 virtual void setMgmtStatus(BOOL bIsManaged);
598 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
599
600 UINT32 getUserRights(UINT32 dwUserId);
601 BOOL checkAccessRights(UINT32 dwUserId, UINT32 dwRequiredRights);
602 void dropUserAccess(UINT32 dwUserId);
603
604 void addChildNodesToList(ObjectArray<Node> *nodeList, UINT32 dwUserId);
605 void addChildDCTargetsToList(ObjectArray<DataCollectionTarget> *dctList, UINT32 dwUserId);
606
607 const TCHAR *getCustomAttribute(const TCHAR *name) { return m_customAttributes.get(name); }
608 void setCustomAttribute(const TCHAR *name, const TCHAR *value) { m_customAttributes.set(name, value); setModified(); }
609 void setCustomAttributePV(const TCHAR *name, TCHAR *value) { m_customAttributes.setPreallocated(_tcsdup(name), value); setModified(); }
610 void deleteCustomAttribute(const TCHAR *name) { m_customAttributes.remove(name); setModified(); }
611 NXSL_Value *getCustomAttributesForNXSL() const;
612
613 virtual NXSL_Value *createNXSLObject();
614
615 ModuleData *getModuleData(const TCHAR *module);
616 void setModuleData(const TCHAR *module, ModuleData *data);
617
618 ObjectArray<NetObj> *getParentList(int typeFilter);
619 ObjectArray<NetObj> *getChildList(int typeFilter);
620 ObjectArray<NetObj> *getFullChildList(bool eventSourceOnly, bool updateRefCount);
621
622 NetObj *findChildObject(const TCHAR *name, int typeFilter);
623
624 int getChildCount() { return m_childList->size(); }
625 int getParentCount() { return m_parentList->size(); }
626
627 virtual NXSL_Array *getParentsForNXSL();
628 virtual NXSL_Array *getChildrenForNXSL();
629
630 virtual bool showThresholdSummary();
631 virtual bool isEventSource();
632 virtual bool isDataCollectionTarget();
633
634 void setStatusCalculation(int method, int arg1 = 0, int arg2 = 0, int arg3 = 0, int arg4 = 0);
635 void setStatusPropagation(int method, int arg1 = 0, int arg2 = 0, int arg3 = 0, int arg4 = 0);
636
637 void sendPollerMsg(UINT32 dwRqId, const TCHAR *pszFormat, ...);
638
639 // Debug methods
640 const TCHAR *dbgGetParentList(TCHAR *szBuffer);
641 const TCHAR *dbgGetChildList(TCHAR *szBuffer);
642
643 static const TCHAR *getObjectClassName(int objectClass);
644 };
645
646 /**
647 * Get object's reference count
648 */
649 inline UINT32 NetObj::getRefCount()
650 {
651 UINT32 dwRefCount;
652
653 MutexLock(m_mutexRefCount);
654 dwRefCount = m_dwRefCount;
655 MutexUnlock(m_mutexRefCount);
656 return dwRefCount;
657 }
658
659 /**
660 * Increment object's reference count
661 */
662 inline void NetObj::incRefCount()
663 {
664 MutexLock(m_mutexRefCount);
665 m_dwRefCount++;
666 MutexUnlock(m_mutexRefCount);
667 }
668
669 /**
670 * Decrement object's reference count
671 */
672 inline void NetObj::decRefCount()
673 {
674 MutexLock(m_mutexRefCount);
675 if (m_dwRefCount > 0)
676 m_dwRefCount--;
677 MutexUnlock(m_mutexRefCount);
678 }
679
680 /**
681 * Data collection template class
682 */
683 class NXCORE_EXPORTABLE Template : public NetObj
684 {
685 protected:
686 ObjectArray<DCObject> *m_dcObjects;
687 int m_dciLockStatus;
688 UINT32 m_dwVersion;
689 UINT32 m_flags;
690 bool m_dciListModified;
691 TCHAR m_szCurrDCIOwner[MAX_SESSION_NAME];
692 TCHAR *m_applyFilterSource;
693 NXSL_Program *m_applyFilter;
694 RWLOCK m_dciAccessLock;
695
696 virtual void prepareForDeletion();
697
698 virtual void fillMessageInternal(NXCPMessage *pMsg);
699 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
700
701 virtual void onDataCollectionChange();
702
703 void loadItemsFromDB(DB_HANDLE hdb);
704 void destroyItems();
705 void updateInstanceDiscoveryItems(DCItem *dci);
706
707 void lockDciAccess(bool writeLock) { if (writeLock) { RWLockWriteLock(m_dciAccessLock, INFINITE); } else { RWLockReadLock(m_dciAccessLock, INFINITE); } }
708 void unlockDciAccess() { RWLockUnlock(m_dciAccessLock); }
709
710 void deleteChildDCIs(UINT32 dcObjectId);
711 void destroyItem(DCObject *object, int index);
712
713 public:
714 Template();
715 Template(const TCHAR *pszName);
716 Template(ConfigEntry *config);
717 virtual ~Template();
718
719 virtual int getObjectClass() const { return OBJECT_TEMPLATE; }
720
721 virtual BOOL saveToDatabase(DB_HANDLE hdb);
722 virtual bool deleteFromDatabase(DB_HANDLE hdb);
723 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
724
725 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
726
727 int getVersionMajor() { return m_dwVersion >> 16; }
728 int getVersionMinor() { return m_dwVersion & 0xFFFF; }
729
730 int getItemCount() { return m_dcObjects->size(); }
731 bool addDCObject(DCObject *object, bool alreadyLocked = false);
732 bool updateDCObject(UINT32 dwItemId, NXCPMessage *pMsg, UINT32 *pdwNumMaps, UINT32 **ppdwMapIndex, UINT32 **ppdwMapId);
733 bool deleteDCObject(UINT32 dcObjectId, bool needLock);
734 bool setItemStatus(UINT32 dwNumItems, UINT32 *pdwItemList, int iStatus);
735 int getItemType(UINT32 dwItemId);
736 DCObject *getDCObjectById(UINT32 itemId, bool lock = true);
737 DCObject *getDCObjectByGUID(const uuid& guid, bool lock = true);
738 DCObject *getDCObjectByTemplateId(UINT32 tmplItemId);
739 DCObject *getDCObjectByIndex(int index);
740 DCObject *getDCObjectByName(const TCHAR *name);
741 DCObject *getDCObjectByDescription(const TCHAR *description);
742 NXSL_Value *getAllDCObjectsForNXSL(const TCHAR *name, const TCHAR *description);
743 bool lockDCIList(int sessionId, const TCHAR *pszNewOwner, TCHAR *pszCurrOwner);
744 bool unlockDCIList(int sessionId);
745 void setDCIModificationFlag() { m_dciListModified = true; }
746 void sendItemsToClient(ClientSession *pSession, UINT32 dwRqId);
747 BOOL isLockedBySession(int sessionId) { return m_dciLockStatus == sessionId; }
748 UINT32 *getDCIEventsList(UINT32 *pdwCount);
749 StringSet *getDCIScriptList();
750
751 BOOL applyToTarget(DataCollectionTarget *pNode);
752 AutoBindDecision isApplicable(Node *node);
753 bool isAutoApplyEnabled() { return (m_flags & TF_AUTO_APPLY) ? true : false; }
754 bool isAutoRemoveEnabled() { return ((m_flags & (TF_AUTO_APPLY | TF_AUTO_REMOVE)) == (TF_AUTO_APPLY | TF_AUTO_REMOVE)) ? true : false; }
755 void setAutoApplyFilter(const TCHAR *filter);
756 void queueUpdate();
757 void queueRemoveFromTarget(UINT32 targetId, bool removeDCI);
758
759 void createExportRecord(String &str);
760 void updateFromImport(ConfigEntry *config);
761
762 bool enumDCObjects(bool (* pfCallback)(DCObject *, UINT32, void *), void *pArg);
763 void associateItems();
764
765 UINT32 getLastValues(NXCPMessage *msg, bool objectTooltipOnly, bool overviewOnly, bool includeNoValueObjects);
766 };
767
768 class Cluster;
769
770 /**
771 * Interface class
772 */
773 class NXCORE_EXPORTABLE Interface : public NetObj
774 {
775 protected:
776 UINT32 m_index;
777 BYTE m_macAddr[MAC_ADDR_LENGTH];
778 InetAddressList m_ipAddressList;
779 UINT32 m_flags;
780 TCHAR m_description[MAX_DB_STRING]; // Interface description - value of ifDescr for SNMP, equals to name for NetXMS agent
781 TCHAR m_alias[MAX_DB_STRING]; // Interface alias - value of ifAlias for SNMP, empty for NetXMS agent
782 UINT32 m_type;
783 UINT32 m_mtu;
784 UINT64 m_speed;
785 UINT32 m_bridgePortNumber; // 802.1D port number
786 UINT32 m_slotNumber; // Vendor/device specific slot number
787 UINT32 m_portNumber; // Vendor/device specific port number
788 UINT32 m_peerNodeId; // ID of peer node object, or 0 if unknown
789 UINT32 m_peerInterfaceId; // ID of peer interface object, or 0 if unknown
790 LinkLayerProtocol m_peerDiscoveryProtocol; // Protocol used to discover peer node
791 INT16 m_adminState; // interface administrative state
792 INT16 m_operState; // interface operational state
793 INT16 m_pendingOperState;
794 INT16 m_confirmedOperState;
795 INT16 m_dot1xPaeAuthState; // 802.1x port auth state
796 INT16 m_dot1xBackendAuthState; // 802.1x backend auth state
797 UINT64 m_lastDownEventId;
798 int m_pendingStatus;
799 int m_statusPollCount;
800 int m_operStatePollCount;
801 int m_requiredPollCount;
802 UINT32 m_zoneId;
803 UINT32 m_pingTime;
804 time_t m_pingLastTimeStamp;
805 int m_ifTableSuffixLen;
806 UINT32 *m_ifTableSuffix;
807
808 void icmpStatusPoll(UINT32 rqId, UINT32 nodeIcmpProxy, Cluster *cluster, InterfaceAdminState *adminState, InterfaceOperState *operState);
809 void paeStatusPoll(UINT32 rqId, SNMP_Transport *pTransport, Node *node);
810
811 protected:
812 virtual void onObjectDelete(UINT32 dwObjectId);
813
814 virtual void fillMessageInternal(NXCPMessage *pMsg);
815 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
816
817 public:
818 Interface();
819 Interface(const InetAddressList& addrList, UINT32 zoneId, bool bSyntheticMask);
820 Interface(const TCHAR *name, const TCHAR *descr, UINT32 index, const InetAddressList& addrList, UINT32 ifType, UINT32 zoneId);
821 virtual ~Interface();
822
823 virtual int getObjectClass() const { return OBJECT_INTERFACE; }
824 virtual BOOL saveToDatabase(DB_HANDLE hdb);
825 virtual bool deleteFromDatabase(DB_HANDLE hdb);
826 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
827
828 virtual NXSL_Value *createNXSLObject();
829
830 Node *getParentNode();
831 UINT32 getParentNodeId();
832
833 const InetAddressList *getIpAddressList() { return &m_ipAddressList; }
834 const InetAddress& getFirstIpAddress();
835 UINT32 getZoneId() { return m_zoneId; }
836 UINT32 getIfIndex() { return m_index; }
837 UINT32 getIfType() { return m_type; }
838 UINT32 getMTU() { return m_mtu; }
839 UINT64 getSpeed() { return m_speed; }
840 UINT32 getBridgePortNumber() { return m_bridgePortNumber; }
841 UINT32 getSlotNumber() { return m_slotNumber; }
842 UINT32 getPortNumber() { return m_portNumber; }
843 UINT32 getPeerNodeId() { return m_peerNodeId; }
844 UINT32 getPeerInterfaceId() { return m_peerInterfaceId; }
845 LinkLayerProtocol getPeerDiscoveryProtocol() { return m_peerDiscoveryProtocol; }
846 UINT32 getFlags() { return m_flags; }
847 int getAdminState() { return (int)m_adminState; }
848 int getOperState() { return (int)m_operState; }
849 int getConfirmedOperState() { return (int)m_confirmedOperState; }
850 int getDot1xPaeAuthState() { return (int)m_dot1xPaeAuthState; }
851 int getDot1xBackendAuthState() { return (int)m_dot1xBackendAuthState; }
852 const TCHAR *getDescription() { return m_description; }
853 const TCHAR *getAlias() { return m_alias; }
854 const BYTE *getMacAddr() { return m_macAddr; }
855 int getIfTableSuffixLen() { return m_ifTableSuffixLen; }
856 const UINT32 *getIfTableSuffix() { return m_ifTableSuffix; }
857 UINT32 getPingTime();
858 bool isSyntheticMask() { return (m_flags & IF_SYNTHETIC_MASK) ? true : false; }
859 bool isPhysicalPort() { return (m_flags & IF_PHYSICAL_PORT) ? true : false; }
860 bool isLoopback() { return (m_flags & IF_LOOPBACK) ? true : false; }
861 bool isManuallyCreated() { return (m_flags & IF_CREATED_MANUALLY) ? true : false; }
862 bool isExcludedFromTopology() { return (m_flags & (IF_EXCLUDE_FROM_TOPOLOGY | IF_LOOPBACK)) ? true : false; }
863 bool isFake() { return (m_index == 1) &&
864 (m_type == IFTYPE_OTHER) &&
865 (!_tcscmp(m_name, _T("lan0")) || !_tcscmp(m_name, _T("unknown"))) &&
866 (!memcmp(m_macAddr, "\x00\x00\x00\x00\x00\x00", 6)); }
867
868 UINT64 getLastDownEventId() { return m_lastDownEventId; }
869 void setLastDownEventId(QWORD id) { m_lastDownEventId = id; }
870
871 void setMacAddr(const BYTE *macAddr, bool updateMacDB);
872 void setIpAddress(const InetAddress& addr);
873 void setBridgePortNumber(UINT32 bpn) { m_bridgePortNumber = bpn; setModified(); }
874 void setSlotNumber(UINT32 slot) { m_slotNumber = slot; setModified(); }
875 void setPortNumber(UINT32 port) { m_portNumber = port; setModified(); }
876 void setPhysicalPortFlag(bool isPhysical) { if (isPhysical) m_flags |= IF_PHYSICAL_PORT; else m_flags &= ~IF_PHYSICAL_PORT; setModified(); }
877 void setManualCreationFlag(bool isManual) { if (isManual) m_flags |= IF_CREATED_MANUALLY; else m_flags &= ~IF_CREATED_MANUALLY; setModified(); }
878 void setPeer(Node *node, Interface *iface, LinkLayerProtocol protocol, bool reflection);
879 void clearPeer() { lockProperties(); m_peerNodeId = 0; m_peerInterfaceId = 0; m_peerDiscoveryProtocol = LL_PROTO_UNKNOWN; setModified(); unlockProperties(); }
880 void setDescription(const TCHAR *descr) { lockProperties(); nx_strncpy(m_description, descr, MAX_DB_STRING); setModified(); unlockProperties(); }
881 void setAlias(const TCHAR *alias) { lockProperties(); nx_strncpy(m_alias, alias, MAX_DB_STRING); setModified(); unlockProperties(); }
882 void addIpAddress(const InetAddress& addr);
883 void deleteIpAddress(InetAddress addr);
884 void setNetMask(const InetAddress& addr);
885 void setMTU(int mtu) { m_mtu = mtu; setModified(); }
886 void setSpeed(UINT64 speed) { m_speed = speed; setModified(); }
887 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(); }
888
889 void updateZoneId();
890
891 void statusPoll(ClientSession *session, UINT32 rqId, Queue *eventQueue, Cluster *cluster, SNMP_Transport *snmpTransport, UINT32 nodeIcmpProxy);
892
893 UINT32 wakeUp();
894 void setExpectedState(int state);
895 void setExcludeFromTopology(bool excluded);
896 void updatePingData();
897 };
898
899 /**
900 * Network service class
901 */
902 class NXCORE_EXPORTABLE NetworkService : public NetObj
903 {
904 protected:
905 int m_serviceType; // SSH, POP3, etc.
906 Node *m_hostNode; // Pointer to node object which hosts this service
907 UINT32 m_pollerNode; // ID of node object which is used for polling
908 // If 0, m_pHostNode->m_dwPollerNode will be used
909 UINT16 m_proto; // Protocol (TCP, UDP, etc.)
910 UINT16 m_port; // TCP or UDP port number
911 InetAddress m_ipAddress;
912 TCHAR *m_request; // Service-specific request
913 TCHAR *m_response; // Service-specific expected response
914 int m_pendingStatus;
915 int m_pollCount;
916 int m_requiredPollCount;
917 UINT32 m_responseTime; // Response time from last poll
918
919 virtual void onObjectDelete(UINT32 dwObjectId);
920
921 virtual void fillMessageInternal(NXCPMessage *pMsg);
922 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
923
924 public:
925 NetworkService();
926 NetworkService(int iServiceType, WORD wProto, WORD wPort,
927 TCHAR *pszRequest, TCHAR *pszResponse,
928 Node *pHostNode = NULL, UINT32 dwPollerNode = 0);
929 virtual ~NetworkService();
930
931 virtual int getObjectClass() const { return OBJECT_NETWORKSERVICE; }
932
933 virtual BOOL saveToDatabase(DB_HANDLE hdb);
934 virtual bool deleteFromDatabase(DB_HANDLE hdb);
935 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
936
937 void statusPoll(ClientSession *session, UINT32 rqId, Node *pollerNode, Queue *eventQueue);
938
939 UINT32 getResponseTime() { return m_responseTime; }
940 };
941
942 /**
943 * VPN connector class
944 */
945 class NXCORE_EXPORTABLE VPNConnector : public NetObj
946 {
947 protected:
948 UINT32 m_dwPeerGateway; // Object ID of peer gateway
949 ObjectArray<InetAddress> *m_localNetworks;
950 ObjectArray<InetAddress> *m_remoteNetworks;
951
952 virtual void fillMessageInternal(NXCPMessage *pMsg);
953 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
954
955 Node *getParentNode();
956
957 public:
958 VPNConnector();
959 VPNConnector(bool hidden);
960 virtual ~VPNConnector();
961
962 virtual int getObjectClass() const { return OBJECT_VPNCONNECTOR; }
963
964 virtual BOOL saveToDatabase(DB_HANDLE hdb);
965 virtual bool deleteFromDatabase(DB_HANDLE hdb);
966 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
967
968 bool isLocalAddr(const InetAddress& addr);
969 bool isRemoteAddr(const InetAddress& addr);
970 UINT32 getPeerGatewayId() const { return m_dwPeerGateway; }
971 InetAddress getPeerGatewayAddr();
972 };
973
974 /**
975 * Data collection proxy information structure
976 */
977 struct ProxyInfo
978 {
979 UINT32 proxyId;
980 NXCPMessage *msg;
981 UINT32 fieldId;
982 UINT32 count;
983 UINT32 nodeInfoFieldId;
984 UINT32 nodeInfoCount;
985 };
986
987 /**
988 * Common base class for all objects capable of collecting data
989 */
990 class NXCORE_EXPORTABLE DataCollectionTarget : public Template
991 {
992 protected:
993 UINT32 m_pingTime;
994 time_t m_pingLastTimeStamp;
995
996 virtual void fillMessageInternal(NXCPMessage *pMsg);
997 virtual void fillMessageInternalStage2(NXCPMessage *pMsg);
998 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
999
1000 virtual bool isDataCollectionDisabled();
1001 virtual void updatePingData();
1002
1003 NetObj *objectFromParameter(const TCHAR *param);
1004
1005 void addProxyDataCollectionElement(ProxyInfo *info, const DCObject *dco);
1006 void addProxySnmpTarget(ProxyInfo *info, const Node *node);
1007 virtual void collectProxyInfo(ProxyInfo *info);
1008 static void collectProxyInfoCallback(NetObj *object, void *data);
1009
1010 public:
1011 DataCollectionTarget();
1012 DataCollectionTarget(const TCHAR *name);
1013 virtual ~DataCollectionTarget();
1014
1015 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1016
1017 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1018 virtual bool isDataCollectionTarget();
1019
1020 virtual void enterMaintenanceMode();
1021 virtual void leaveMaintenanceMode();
1022
1023 virtual UINT32 getInternalItem(const TCHAR *param, size_t bufSize, TCHAR *buffer);
1024 virtual UINT32 getScriptItem(const TCHAR *param, size_t bufSize, TCHAR *buffer);
1025
1026 virtual UINT32 getEffectiveSourceNode(DCObject *dco);
1027
1028 UINT32 getListFromScript(const TCHAR *param, StringList **list);
1029
1030 UINT32 getTableLastValues(UINT32 dciId, NXCPMessage *msg);
1031 UINT32 getThresholdSummary(NXCPMessage *msg, UINT32 baseId);
1032 UINT32 getPerfTabDCIList(NXCPMessage *pMsg);
1033 void getDciValuesSummary(SummaryTable *tableDefinition, Table *tableData);
1034
1035 void updateDciCache();
1036 void updateDCItemCacheSize(UINT32 dciId, UINT32 conditionId = 0);
1037 void cleanDCIData(DB_HANDLE hdb);
1038 void queueItemsForPolling(Queue *pPollerQueue);
1039 bool processNewDCValue(DCObject *dco, time_t currTime, const void *value);
1040
1041 bool applyTemplateItem(UINT32 dwTemplateId, DCObject *dcObject);
1042 void cleanDeletedTemplateItems(UINT32 dwTemplateId, UINT32 dwNumItems, UINT32 *pdwItemList);
1043 virtual void unbindFromTemplate(UINT32 dwTemplateId, bool removeDCI);
1044
1045 virtual bool isEventSource();
1046
1047 int getMostCriticalDCIStatus();
1048
1049 UINT32 getPingTime();
1050 };
1051
1052 /**
1053 * Mobile device class
1054 */
1055 class NXCORE_EXPORTABLE MobileDevice : public DataCollectionTarget
1056 {
1057 protected:
1058 time_t m_lastReportTime;
1059 TCHAR *m_deviceId;
1060 TCHAR *m_vendor;
1061 TCHAR *m_model;
1062 TCHAR *m_serialNumber;
1063 TCHAR *m_osName;
1064 TCHAR *m_osVersion;
1065 TCHAR *m_userId;
1066 LONG m_batteryLevel;
1067 InetAddress m_ipAddress;
1068
1069 virtual void fillMessageInternal(NXCPMessage *pMsg);
1070 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1071
1072 public:
1073 MobileDevice();
1074 MobileDevice(const TCHAR *name, const TCHAR *deviceId);
1075 virtual ~MobileDevice();
1076
1077 virtual int getObjectClass() const { return OBJECT_MOBILEDEVICE; }
1078
1079 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
1080 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1081 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1082
1083 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1084
1085 virtual NXSL_Value *createNXSLObject();
1086
1087 void updateSystemInfo(NXCPMessage *msg);
1088 void updateStatus(NXCPMessage *msg);
1089
1090 const TCHAR *getDeviceId() { return CHECK_NULL_EX(m_deviceId); }
1091 const TCHAR *getVendor() { return CHECK_NULL_EX(m_vendor); }
1092 const TCHAR *getModel() { return CHECK_NULL_EX(m_model); }
1093 const TCHAR *getSerialNumber() { return CHECK_NULL_EX(m_serialNumber); }
1094 const TCHAR *getOsName() { return CHECK_NULL_EX(m_osName); }
1095 const TCHAR *getOsVersion() { return CHECK_NULL_EX(m_osVersion); }
1096 const TCHAR *getUserId() { return CHECK_NULL_EX(m_userId); }
1097 const LONG getBatteryLevel() { return m_batteryLevel; }
1098
1099 virtual UINT32 getInternalItem(const TCHAR *param, size_t bufSize, TCHAR *buffer);
1100 };
1101
1102 /**
1103 * Access point class
1104 */
1105 class NXCORE_EXPORTABLE AccessPoint : public DataCollectionTarget
1106 {
1107 protected:
1108 UINT32 m_index;
1109 InetAddress m_ipAddress;
1110 UINT32 m_nodeId;
1111 BYTE m_macAddr[MAC_ADDR_LENGTH];
1112 TCHAR *m_vendor;
1113 TCHAR *m_model;
1114 TCHAR *m_serialNumber;
1115 ObjectArray<RadioInterfaceInfo> *m_radioInterfaces;
1116 AccessPointState m_state;
1117 AccessPointState m_prevState;
1118
1119 virtual void fillMessageInternal(NXCPMessage *pMsg);
1120 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1121
1122 virtual void updatePingData();
1123
1124 public:
1125 AccessPoint();
1126 AccessPoint(const TCHAR *name, UINT32 index, const BYTE *macAddr);
1127 virtual ~AccessPoint();
1128
1129 virtual int getObjectClass() const { return OBJECT_ACCESSPOINT; }
1130
1131 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
1132 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1133 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1134
1135 void statusPoll(ClientSession *session, UINT32 rqId, Queue *eventQueue, Node *controller, SNMP_Transport *snmpTransport);
1136
1137 UINT32 getIndex() { return m_index; }
1138 const BYTE *getMacAddr() { return m_macAddr; }
1139 const InetAddress& getIpAddress() { return m_ipAddress; }
1140 bool isMyRadio(int rfIndex);
1141 bool isMyRadio(const BYTE *macAddr);
1142 void getRadioName(int rfIndex, TCHAR *buffer, size_t bufSize);
1143 AccessPointState getState() { return m_state; }
1144 Node *getParentNode();
1145
1146 void attachToNode(UINT32 nodeId);
1147 void setIpAddress(const InetAddress& addr) { lockProperties(); m_ipAddress = addr; setModified(); unlockProperties(); }
1148 void updateRadioInterfaces(const ObjectArray<RadioInterfaceInfo> *ri);
1149 void updateInfo(const TCHAR *vendor, const TCHAR *model, const TCHAR *serialNumber);
1150 void updateState(AccessPointState state);
1151 };
1152
1153 /**
1154 * Cluster class
1155 */
1156 class NXCORE_EXPORTABLE Cluster : public DataCollectionTarget
1157 {
1158 protected:
1159 UINT32 m_dwClusterType;
1160 ObjectArray<InetAddress> *m_syncNetworks;
1161 UINT32 m_dwNumResources;
1162 CLUSTER_RESOURCE *m_pResourceList;
1163 UINT32 m_dwFlags;
1164 time_t m_tmLastPoll;
1165 UINT32 m_zoneId;
1166
1167 virtual void fillMessageInternal(NXCPMessage *pMsg);
1168 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1169
1170 virtual void onDataCollectionChange();
1171
1172 public:
1173 Cluster();
1174 Cluster(const TCHAR *pszName, UINT32 zoneId);
1175 virtual ~Cluster();
1176
1177 virtual int getObjectClass() const { return OBJECT_CLUSTER; }
1178 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1179 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1180 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
1181 virtual bool showThresholdSummary();
1182
1183 virtual void unbindFromTemplate(UINT32 dwTemplateId, bool removeDCI);
1184
1185 virtual NXSL_Value *createNXSLObject();
1186
1187 bool isSyncAddr(const InetAddress& addr);
1188 bool isVirtualAddr(const InetAddress& addr);
1189 bool isResourceOnNode(UINT32 dwResource, UINT32 dwNode);
1190 UINT32 getZoneId() { return m_zoneId; }
1191
1192 void statusPoll(PollerInfo *poller);
1193 void statusPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
1194 void lockForStatusPoll() { m_dwFlags |= CLF_QUEUED_FOR_STATUS_POLL; }
1195 bool isReadyForStatusPoll()
1196 {
1197 return ((m_status != STATUS_UNMANAGED) && (!m_isDeleted) &&
1198 (!(m_dwFlags & CLF_QUEUED_FOR_STATUS_POLL)) &&
1199 ((UINT32)time(NULL) - (UINT32)m_tmLastPoll > g_dwStatusPollingInterval))
1200 ? true : false;
1201 }
1202
1203 UINT32 collectAggregatedData(DCItem *item, TCHAR *buffer);
1204 UINT32 collectAggregatedData(DCTable *table, Table **result);
1205 };
1206
1207 /**
1208 * Chassis (represents physical chassis)
1209 */
1210 class NXCORE_EXPORTABLE Chassis : public DataCollectionTarget
1211 {
1212 protected:
1213 UINT32 m_controllerId;
1214 INT16 m_rackHeight;
1215 INT16 m_rackPosition;
1216 UINT32 m_rackId;
1217 uuid m_rackImage;
1218
1219 virtual void fillMessageInternal(NXCPMessage *msg);
1220 virtual UINT32 modifyFromMessageInternal(NXCPMessage *request);
1221
1222 virtual void onDataCollectionChange();
1223 virtual void collectProxyInfo(ProxyInfo *info);
1224
1225 void updateRackBinding();
1226
1227 public:
1228 Chassis();
1229 Chassis(const TCHAR *name, UINT32 controllerId);
1230 virtual ~Chassis();
1231
1232 virtual int getObjectClass() const { return OBJECT_CHASSIS; }
1233 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1234 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1235 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
1236 virtual bool showThresholdSummary();
1237 virtual UINT32 getEffectiveSourceNode(DCObject *dco);
1238
1239 virtual NXSL_Value *createNXSLObject();
1240
1241 UINT32 getControllerId() const { return m_controllerId; }
1242 UINT32 getRackId() const { return m_rackId; }
1243 INT16 getRackHeight() const { return m_rackHeight; }
1244 INT16 getRackPosition() const { return m_rackPosition; }
1245 };
1246
1247 class Subnet;
1248 struct ProxyInfo;
1249
1250 /**
1251 * Node subtypes
1252 */
1253 enum NodeType
1254 {
1255 NODE_TYPE_UNKNOWN = 0,
1256 NODE_TYPE_PHYSICAL = 1,
1257 NODE_TYPE_VIRTUAL = 2,
1258 NODE_TYPE_CONTROLLER = 3
1259 };
1260
1261 /**
1262 * Node
1263 */
1264 class NXCORE_EXPORTABLE Node : public DataCollectionTarget
1265 {
1266 friend class Subnet;
1267
1268 private:
1269 /**
1270 * Delete agent connection
1271 */
1272 void deleteAgentConnection()
1273 {
1274 if (m_agentConnection != NULL)
1275 {
1276 m_agentConnection->decRefCount();
1277 m_agentConnection = NULL;
1278 }
1279 }
1280
1281 void onSnmpProxyChange(UINT32 oldProxy);
1282
1283 static void onDataCollectionChangeAsyncCallback(void *arg);
1284
1285 protected:
1286 InetAddress m_ipAddress;
1287 TCHAR m_primaryName[MAX_DNS_NAME];
1288 UINT32 m_dwFlags;
1289 UINT32 m_dwDynamicFlags; // Flags used at runtime by server
1290 NodeType m_type;
1291 TCHAR m_subType[MAX_NODE_SUBTYPE_LENGTH];
1292 int m_iPendingStatus;
1293 int m_iPollCount;
1294 int m_iRequiredPollCount;
1295 UINT32 m_zoneId;
1296 UINT16 m_agentPort;
1297 INT16 m_agentAuthMethod;
1298 INT16 m_agentCacheMode;
1299 TCHAR m_szSharedSecret[MAX_SECRET_LENGTH];
1300 INT16 m_iStatusPollType;
1301 INT16 m_snmpVersion;
1302 UINT16 m_snmpPort;
1303 UINT16 m_nUseIfXTable;
1304 SNMP_SecurityContext *m_snmpSecurity;
1305 TCHAR m_szObjectId[MAX_OID_LEN * 4];
1306 TCHAR m_szAgentVersion[MAX_AGENT_VERSION_LEN];
1307 TCHAR m_szPlatformName[MAX_PLATFORM_NAME_LEN];
1308 TCHAR *m_sysDescription; // Agent's System.Uname or SNMP sysDescr
1309 TCHAR *m_sysName; // SNMP sysName
1310 TCHAR *m_sysLocation; // SNMP sysLocation
1311 TCHAR *m_sysContact; // SNMP sysContact
1312 TCHAR *m_lldpNodeId; // lldpLocChassisId combined with lldpLocChassisIdSubtype, or NULL for non-LLDP nodes
1313 ObjectArray<LLDP_LOCAL_PORT_INFO> *m_lldpLocalPortInfo;
1314 NetworkDeviceDriver *m_driver;
1315 DriverData *m_driverData;
1316 ObjectArray<AgentParameterDefinition> *m_paramList; // List of supported parameters
1317 ObjectArray<AgentTableDefinition> *m_tableList; // List of supported tables
1318 time_t m_lastDiscoveryPoll;
1319 time_t m_lastStatusPoll;
1320 time_t m_lastConfigurationPoll;
1321 time_t m_lastInstancePoll;
1322 time_t m_lastTopologyPoll;
1323 time_t m_lastRTUpdate;
1324 time_t m_failTimeSNMP;
1325 time_t m_failTimeAgent;
1326 time_t m_downSince;
1327 time_t m_bootTime;
1328 time_t m_agentUpTime;
1329 time_t m_lastAgentCommTime;
1330 time_t m_lastAgentConnectAttempt;
1331 MUTEX m_hPollerMutex;
1332 MUTEX m_hAgentAccessMutex;
1333 MUTEX m_hSmclpAccessMutex;
1334 MUTEX m_mutexRTAccess;
1335 MUTEX m_mutexTopoAccess;
1336 MUTEX m_snmpProxyConnectionLock;
1337 AgentConnectionEx *m_agentConnection;
1338 AgentConnectionEx *m_snmpProxyConnection;
1339 SMCLP_Connection *m_smclpConnection;
1340 QWORD m_lastAgentTrapId; // ID of last received agent trap
1341 QWORD m_lastAgentPushRequestId; // ID of last received agent push request
1342 UINT32 m_lastSNMPTrapId;
1343 UINT32 m_pollerNode; // Node used for network service polling
1344 UINT32 m_agentProxy; // Node used as proxy for agent connection
1345 UINT32 m_snmpProxy; // Node used as proxy for SNMP requests
1346 UINT32 m_icmpProxy; // Node used as proxy for ICMP ping
1347 UINT64 m_qwLastEvents[MAX_LAST_EVENTS];
1348 ROUTING_TABLE *m_pRoutingTable;
1349 ForwardingDatabase *m_fdb;
1350 LinkLayerNeighbors *m_linkLayerNeighbors;
1351 VlanList *m_vlans;
1352 VrrpInfo *m_vrrpInfo;
1353 ObjectArray<WirelessStationInfo> *m_wirelessStations;
1354 int m_adoptedApCount;
1355 int m_totalApCount;
1356 BYTE m_baseBridgeAddress[MAC_ADDR_LENGTH]; // Bridge base address (dot1dBaseBridgeAddress in bridge MIB)
1357 nxmap_ObjList *m_pTopology;
1358 time_t m_topologyRebuildTimestamp;
1359 ServerJobQueue *m_jobQueue;
1360 ComponentTree *m_components; // Hardware components
1361 ObjectArray<SoftwarePackage> *m_softwarePackages; // installed software packages
1362 ObjectArray<WinPerfObject> *m_winPerfObjects; // Windows performance objects
1363 AgentConnection *m_fileUpdateConn;
1364 INT16 m_rackHeight;
1365 INT16 m_rackPosition;
1366 UINT32 m_rackId;
1367 uuid m_rackImage;
1368 UINT32 m_chassisId;
1369 INT64 m_syslogMessageCount;
1370 INT64 m_snmpTrapCount;
1371
1372 void pollerLock() { MutexLock(m_hPollerMutex); }
1373 void pollerUnlock() { MutexUnlock(m_hPollerMutex); }
1374
1375 void agentLock() { MutexLock(m_hAgentAccessMutex); }
1376 void agentUnlock() { MutexUnlock(m_hAgentAccessMutex); }
1377
1378 void smclpLock() { MutexLock(m_hSmclpAccessMutex); }
1379 void smclpUnlock() { MutexUnlock(m_hSmclpAccessMutex); }
1380
1381 void routingTableLock() { MutexLock(m_mutexRTAccess); }
1382 void routingTableUnlock() { MutexUnlock(m_mutexRTAccess); }
1383
1384 BOOL checkSNMPIntegerValue(SNMP_Transport *pTransport, const TCHAR *pszOID, int nValue);
1385 void checkOSPFSupport(SNMP_Transport *pTransport);
1386 void addVrrpInterfaces(InterfaceList *ifList);
1387 BOOL resolveName(BOOL useOnlyDNS);
1388 void setAgentProxy(AgentConnection *pConn);
1389 void setPrimaryIPAddress(const InetAddress& addr);
1390
1391 UINT32 getInterfaceCount(Interface **ppInterface);
1392
1393 void checkInterfaceNames(InterfaceList *pIfList);
1394 bool filterInterface(InterfaceInfo *info);
1395 Subnet *createSubnet(InetAddress& baseAddr, bool syntheticMask);
1396 void checkAgentPolicyBinding(AgentConnection *conn);
1397 void updatePrimaryIpAddr();
1398 bool confPollAgent(UINT32 dwRqId);
1399 bool confPollSnmp(UINT32 dwRqId);
1400 NodeType detectNodeType();
1401 bool querySnmpSysProperty(SNMP_Transport *snmp, const TCHAR *oid, const TCHAR *propName, UINT32 pollRqId, TCHAR **value);
1402 void checkBridgeMib(SNMP_Transport *pTransport);
1403 void checkIfXTable(SNMP_Transport *pTransport);
1404 void executeHookScript(const TCHAR *hookName);
1405 bool checkNetworkPath(UINT32 dwRqId);
1406 bool checkNetworkPathElement(UINT32 nodeId, const TCHAR *nodeType, bool isProxy, UINT32 dwRqId);
1407
1408 void applyUserTemplates();
1409 void doInstanceDiscovery(UINT32 requestId);
1410 StringMap *getInstanceList(DCItem *dci);
1411 bool updateInstances(DCItem *root, StringMap *instances, UINT32 requestId);
1412 void syncDataCollectionWithAgent(AgentConnectionEx *conn);
1413
1414 void updateContainerMembership();
1415 bool updateInterfaceConfiguration(UINT32 rqid, int maskBits);
1416 bool deleteDuplicateInterfaces(UINT32 rqid);
1417 void updatePhysicalContainerBinding(int containerClass, UINT32 containerId);
1418
1419 bool connectToAgent(UINT32 *error = NULL, UINT32 *socketError = NULL, bool *newConnection = NULL, bool forceConnect = false);
1420 void setLastAgentCommTime() { time_t now = time(NULL); if (m_lastAgentCommTime < now - 60) { m_lastAgentCommTime = now; setModified(); } }
1421
1422 void buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedObject, bool vpnLink, bool includeEndNodes);
1423
1424 virtual bool isDataCollectionDisabled();
1425 virtual void collectProxyInfo(ProxyInfo *info);
1426
1427 virtual void prepareForDeletion();
1428 virtual void onObjectDelete(UINT32 dwObjectId);
1429
1430 virtual void fillMessageInternal(NXCPMessage *pMsg);
1431 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1432
1433 virtual void updatePingData();
1434
1435 virtual void onDataCollectionChange();
1436
1437 public:
1438 Node();
1439 Node(const InetAddress& addr, UINT32 dwFlags, UINT32 agentProxy, UINT32 snmpProxy, UINT32 dwZone);
1440 virtual ~Node();
1441
1442 virtual int getObjectClass() const { return OBJECT_NODE; }
1443
1444 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1445 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1446 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
1447
1448 virtual NXSL_Value *createNXSLObject();
1449
1450 TCHAR *expandText(const TCHAR *textTemplate, StringMap *inputFields, const TCHAR *userName);
1451
1452 Cluster *getMyCluster();
1453
1454 const InetAddress& getIpAddress() const { return m_ipAddress; }
1455 UINT32 getZoneId() const { return m_zoneId; }
1456 NodeType getType() const { return m_type; }
1457 const TCHAR *getSubType() const { return m_subType; }
1458 UINT32 getFlags() const { return m_dwFlags; }
1459 UINT32 getRuntimeFlags() const { return m_dwDynamicFlags; }
1460
1461 void setFlag(UINT32 flag) { lockProperties(); m_dwFlags |= flag; setModified(); unlockProperties(); }
1462 void clearFlag(UINT32 flag) { lockProperties(); m_dwFlags &= ~flag; setModified(); unlockProperties(); }
1463 void setLocalMgmtFlag() { m_dwFlags |= NF_IS_LOCAL_MGMT; }
1464 void clearLocalMgmtFlag() { m_dwFlags &= ~NF_IS_LOCAL_MGMT; }
1465
1466 void setType(NodeType type, const TCHAR *subType) { lockProperties(); m_type = type; nx_strncpy(m_subType, subType, MAX_NODE_SUBTYPE_LENGTH); unlockProperties(); }
1467
1468 bool isSNMPSupported() const { return m_dwFlags & NF_IS_SNMP ? true : false; }
1469 bool isNativeAgent() const { return m_dwFlags & NF_IS_NATIVE_AGENT ? true : false; }
1470 bool isBridge() const { return m_dwFlags & NF_IS_BRIDGE ? true : false; }
1471 bool isRouter() const { return m_dwFlags & NF_IS_ROUTER ? true : false; }
1472 bool isLocalManagement() const { return m_dwFlags & NF_IS_LOCAL_MGMT ? true : false; }
1473 bool isPerVlanFdbSupported() const { return (m_driver != NULL) ? m_driver->isPerVlanFdbSupported() : false; }
1474 bool isWirelessController() const { return m_dwFlags & NF_IS_WIFI_CONTROLLER ? true : false; }
1475
1476 LONG getSNMPVersion() const { return m_snmpVersion; }
1477 UINT16 getSNMPPort() const { return m_snmpPort; }
1478 const TCHAR *getSNMPObjectId() const { return m_szObjectId; }
1479 const TCHAR *getAgentVersion() const { return m_szAgentVersion; }
1480 const TCHAR *getPlatformName() const { return m_szPlatformName; }
1481 const TCHAR *getObjectId() const { return m_szObjectId; }
1482 const TCHAR *getSysName() const { return CHECK_NULL_EX(m_sysName); }
1483 const TCHAR *getSysDescription() const { return CHECK_NULL_EX(m_sysDescription); }
1484 const TCHAR *getSysContact() const { return CHECK_NULL_EX(m_sysContact); }
1485 const TCHAR *getSysLocation() const { return CHECK_NULL_EX(m_sysLocation); }
1486 time_t getBootTime() const { return m_bootTime; }
1487 const TCHAR *getLLDPNodeId() const { return m_lldpNodeId; }
1488 const BYTE *getBridgeId() const { return m_baseBridgeAddress; }
1489 const TCHAR *getDriverName() const { return (m_driver != NULL) ? m_driver->getName() : _T("GENERIC"); }
1490 UINT16 getAgentPort() const { return m_agentPort; }
1491 INT16 getAgentAuthMethod() const { return m_agentAuthMethod; }
1492 INT16 getAgentCacheMode() const { return (m_dwDynamicFlags & NDF_CACHE_MODE_NOT_SUPPORTED) ? AGENT_CACHE_OFF : ((m_agentCacheMode == AGENT_CACHE_DEFAULT) ? g_defaultAgentCacheMode : m_agentCacheMode); }
1493 const TCHAR *getSharedSecret() const { return m_szSharedSecret; }
1494 UINT32 getRackId() const { return m_rackId; }
1495 INT16 getRackHeight() const { return m_rackHeight; }
1496 INT16 getRackPosition() const { return m_rackPosition; }
1497 bool hasFileUpdateConnection() const { lockProperties(); bool result = (m_fileUpdateConn != NULL); unlockProperties(); return result; }
1498 UINT32 getIcmpProxy() const { return m_icmpProxy; }
1499
1500 bool isDown() { return (m_dwDynamicFlags & NDF_UNREACHABLE) ? true : false; }
1501 time_t getDownTime() const { return m_downSince; }
1502
1503 void addInterface(Interface *pInterface) { addChild(pInterface); pInterface->addParent(this); }
1504 Interface *createNewInterface(InterfaceInfo *ifInfo, bool manuallyCreated);
1505 Interface *createNewInterface(const InetAddress& ipAddr, BYTE *macAddr);
1506 void deleteInterface(Interface *iface);
1507
1508 void setPrimaryName(const TCHAR *name) { nx_strncpy(m_primaryName, name, MAX_DNS_NAME); }
1509 void setAgentPort(WORD port) { m_agentPort = port; }
1510 void setSnmpPort(WORD port) { m_snmpPort = port; }
1511 void changeIPAddress(const InetAddress& ipAddr);
1512 void changeZone(UINT32 newZone);
1513 void setFileUpdateConnection(AgentConnection *conn);
1514 void clearDataCollectionConfigFromAgent(AgentConnectionEx *conn);
1515 void forceSyncDataCollectionConfig();
1516 void relatedNodeDataCollectionChanged() { onDataCollectionChange(); }
1517
1518 ARP_CACHE *getArpCache();
1519 InterfaceList *getInterfaceList();
1520 Interface *findInterfaceByIndex(UINT32 ifIndex);
1521 Interface *findInterfaceByName(const TCHAR *name);
1522 Interface *findInterfaceByMAC(const BYTE *macAddr);
1523 Interface *findInterfaceByIP(const InetAddress& addr);
1524 Interface *findInterfaceBySlotAndPort(UINT32 slot, UINT32 port);
1525 Interface *findBridgePort(UINT32 bridgePortNumber);
1526 AccessPoint *findAccessPointByMAC(const BYTE *macAddr);
1527 AccessPoint *findAccessPointByBSSID(const BYTE *bssid);
1528 AccessPoint *findAccessPointByRadioId(int rfIndex);
1529 ObjectArray<WirelessStationInfo> *getWirelessStations();
1530 bool isMyIP(const InetAddress& addr);
1531 void getInterfaceStatusFromSNMP(SNMP_Transport *pTransport, UINT32 dwIndex, int ifTableSuffixLen, UINT32 *ifTableSuffix, InterfaceAdminState *adminState, InterfaceOperState *operState);
1532 void getInterfaceStatusFromAgent(UINT32 dwIndex, InterfaceAdminState *adminState, InterfaceOperState *operState);
1533 ROUTING_TABLE *getRoutingTable();
1534 ROUTING_TABLE *getCachedRoutingTable() { return m_pRoutingTable; }
1535 LinkLayerNeighbors *getLinkLayerNeighbors();
1536 VlanList *getVlans();
1537 bool getNextHop(const InetAddress& srcAddr, const InetAddress& destAddr, InetAddress *nextHop, UINT32 *ifIndex, bool *isVpn, TCHAR *name);
1538 bool getOutwardInterface(const InetAddress& destAddr, InetAddress *srcAddr, UINT32 *srcIfIndex);
1539 ComponentTree *getComponents();
1540 bool getLldpLocalPortInfo(UINT32 idType, BYTE *id, size_t idLen, LLDP_LOCAL_PORT_INFO *port);
1541 void showLLDPInfo(CONSOLE_CTX console);
1542
1543 void setRecheckCapsFlag() { m_dwDynamicFlags |= NDF_RECHECK_CAPABILITIES; }
1544 void setDiscoveryPollTimeStamp();
1545 void statusPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
1546 void statusPoll(PollerInfo *poller);
1547 void configurationPoll(PollerInfo *poller);
1548 void configurationPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller, int maskBits);
1549 void instanceDiscoveryPoll(PollerInfo *poller);
1550 void instanceDiscoveryPoll(ClientSession *session, UINT32 requestId, PollerInfo *poller);
1551 void topologyPoll(PollerInfo *poller);
1552 void topologyPoll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
1553 void resolveVlanPorts(VlanList *vlanList);
1554 void updateInterfaceNames(ClientSession *pSession, UINT32 dwRqId);
1555 void routingTablePoll(PollerInfo *poller);
1556 void updateRoutingTable();
1557 void checkSubnetBinding();
1558 AccessPointState getAccessPointState(AccessPoint *ap, SNMP_Transport *snmpTransport);
1559
1560 bool isReadyForStatusPoll();
1561 bool isReadyForConfigurationPoll();
1562 bool isReadyForInstancePoll();
1563 bool isReadyForDiscoveryPoll();
1564 bool isReadyForRoutePoll();
1565 bool isReadyForTopologyPoll();
1566
1567 void lockForStatusPoll();
1568 void lockForConfigurationPoll();
1569 void lockForInstancePoll();
1570 void lockForDiscoveryPoll();
1571 void lockForRoutePoll();
1572 void lockForTopologyPoll();
1573 void forceConfigurationPoll() { m_dwDynamicFlags |= NDF_FORCE_CONFIGURATION_POLL; }
1574
1575 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1576
1577 bool checkAgentTrapId(UINT64 id);
1578 bool checkSNMPTrapId(UINT32 id);
1579 bool checkAgentPushRequestId(UINT64 id);
1580
1581 bool connectToSMCLP();
1582
1583 virtual UINT32 getInternalItem(const TCHAR *param, size_t bufSize, TCHAR *buffer);
1584
1585 UINT32 getItemFromSNMP(WORD port, const TCHAR *param, size_t bufSize, TCHAR *buffer, int interpretRawValue);
1586 UINT32 getTableFromSNMP(WORD port, const TCHAR *oid, ObjectArray<DCTableColumn> *columns, Table **table);
1587 UINT32 getListFromSNMP(WORD port, const TCHAR *oid, StringList **list);
1588 UINT32 getOIDSuffixListFromSNMP(WORD port, const TCHAR *oid, StringMap **values);
1589 UINT32 getItemFromCheckPointSNMP(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
1590 UINT32 getItemFromAgent(const TCHAR *szParam, UINT32 dwBufSize, TCHAR *szBuffer);
1591 UINT32 getTableFromAgent(const TCHAR *name, Table **table);
1592 UINT32 getListFromAgent(const TCHAR *name, StringList **list);
1593 UINT32 getItemForClient(int iOrigin, const TCHAR *pszParam, TCHAR *pszBuffer, UINT32 dwBufSize);
1594 UINT32 getTableForClient(const TCHAR *name, Table **table);
1595 UINT32 getItemFromSMCLP(const TCHAR *param, UINT32 bufSize, TCHAR *buffer);
1596
1597 virtual NXSL_Array *getParentsForNXSL();
1598 virtual NXSL_Array *getTemplatesForNXSL();
1599 NXSL_Array *getInterfacesForNXSL();
1600
1601 void openParamList(ObjectArray<AgentParameterDefinition> **paramList);
1602 void closeParamList() { unlockProperties(); }
1603
1604 void openTableList(ObjectArray<AgentTableDefinition> **tableList);
1605 void closeTableList() { unlockProperties(); }
1606
1607 AgentConnectionEx *createAgentConnection(bool sendServerId = false);
1608 AgentConnectionEx *acquireSnmpProxyConnection();
1609 SNMP_Transport *createSnmpTransport(WORD port = 0, const TCHAR *context = NULL);
1610 SNMP_SecurityContext *getSnmpSecurityContext() const;
1611 UINT32 getEffectiveSnmpProxy() const;
1612
1613 void writeParamListToMessage(NXCPMessage *pMsg, WORD flags);
1614 void writeWinPerfObjectsToMessage(NXCPMessage *msg);
1615 void writePackageListToMessage(NXCPMessage *msg);
1616 void writeWsListToMessage(NXCPMessage *msg);
1617
1618 UINT32 wakeUp();
1619
1620 void addService(NetworkService *pNetSrv) { addChild(pNetSrv); pNetSrv->addParent(this); }
1621 UINT32 checkNetworkService(UINT32 *pdwStatus, const InetAddress& ipAddr, int iServiceType, WORD wPort = 0,
1622 WORD wProto = 0, TCHAR *pszRequest = NULL, TCHAR *pszResponse = NULL, UINT32 *responseTime = NULL);
1623
1624 QWORD getLastEventId(int nIndex) { return ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) ? m_qwLastEvents[nIndex] : 0; }
1625 void setLastEventId(int nIndex, QWORD qwId) { if ((nIndex >= 0) && (nIndex < MAX_LAST_EVENTS)) m_qwLastEvents[nIndex] = qwId; }
1626
1627 UINT32 callSnmpEnumerate(const TCHAR *pszRootOid,
1628 UINT32 (* pHandler)(SNMP_Variable *, SNMP_Transport *, void *), void *pArg, const TCHAR *context = NULL);
1629
1630 nxmap_ObjList *getL2Topology();
1631 nxmap_ObjList *buildL2Topology(UINT32 *pdwStatus, int radius, bool includeEndNodes);
1632 ForwardingDatabase *getSwitchForwardingDatabase();
1633 NetObj *findConnectionPoint(UINT32 *localIfId, BYTE *localMacAddr, int *type);
1634 void addHostConnections(LinkLayerNeighbors *nbs);
1635 void addExistingConnections(LinkLayerNeighbors *nbs);
1636
1637 nxmap_ObjList *buildIPTopology(UINT32 *pdwStatus, int radius, bool includeEndNodes);
1638
1639 ServerJobQueue *getJobQueue() { return m_jobQueue; }
1640 int getJobCount(const TCHAR *type = NULL) { return m_jobQueue->getJobCount(type); }
1641
1642 DriverData *getDriverData() { return m_driverData; }
1643 void setDriverData(DriverData *data) { m_driverData = data; }
1644
1645 void incSyslogMessageCount();
1646 void incSnmpTrapCount();
1647
1648 static const TCHAR *typeName(NodeType type);
1649 };
1650
1651 /**
1652 * Set timestamp of last discovery poll to current time
1653 */
1654 inline void Node::setDiscoveryPollTimeStamp()
1655 {
1656 m_lastDiscoveryPoll = time(NULL);
1657 m_dwDynamicFlags &= ~NDF_QUEUED_FOR_DISCOVERY_POLL;
1658 }
1659
1660 inline bool Node::isReadyForStatusPoll()
1661 {
1662 if (m_isDeleted)
1663 return false;
1664 if (m_dwDynamicFlags & NDF_FORCE_STATUS_POLL)
1665 {
1666 m_dwDynamicFlags &= ~NDF_FORCE_STATUS_POLL;
1667 return true;
1668 }
1669 return (m_status != STATUS_UNMANAGED) &&
1670 (!(m_dwFlags & NF_DISABLE_STATUS_POLL)) &&
1671 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_STATUS_POLL)) &&
1672 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1673 (getMyCluster() == NULL) &&
1674 ((UINT32)(time(NULL) - m_lastStatusPoll) > g_dwStatusPollingInterval);
1675 }
1676
1677 inline bool Node::isReadyForConfigurationPoll()
1678 {
1679 if (m_isDeleted)
1680 return false;
1681 if (m_dwDynamicFlags & NDF_FORCE_CONFIGURATION_POLL)
1682 {
1683 m_dwDynamicFlags &= ~NDF_FORCE_CONFIGURATION_POLL;
1684 return true;
1685 }
1686 return (m_status != STATUS_UNMANAGED) &&
1687 (!(m_dwFlags & NF_DISABLE_CONF_POLL)) &&
1688 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_CONFIG_POLL)) &&
1689 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1690 ((UINT32)(time(NULL) - m_lastConfigurationPoll) > g_dwConfigurationPollingInterval);
1691 }
1692
1693 inline bool Node::isReadyForDiscoveryPoll()
1694 {
1695 if (m_isDeleted)
1696 return false;
1697 return (g_flags & AF_ENABLE_NETWORK_DISCOVERY) &&
1698 (m_status != STATUS_UNMANAGED) &&
1699 (!(m_dwFlags & NF_DISABLE_DISCOVERY_POLL)) &&
1700 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_DISCOVERY_POLL)) &&
1701 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1702 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1703 ((UINT32)(time(NULL) - m_lastDiscoveryPoll) > g_dwDiscoveryPollingInterval);
1704 }
1705
1706 inline bool Node::isReadyForRoutePoll()
1707 {
1708 if (m_isDeleted)
1709 return false;
1710 return (m_status != STATUS_UNMANAGED) &&
1711 (!(m_dwFlags & NF_DISABLE_ROUTE_POLL)) &&
1712 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_ROUTE_POLL)) &&
1713 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1714 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1715 ((UINT32)(time(NULL) - m_lastRTUpdate) > g_dwRoutingTableUpdateInterval);
1716 }
1717
1718 inline bool Node::isReadyForTopologyPoll()
1719 {
1720 if (m_isDeleted)
1721 return false;
1722 return (m_status != STATUS_UNMANAGED) &&
1723 (!(m_dwFlags & NF_DISABLE_TOPOLOGY_POLL)) &&
1724 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_TOPOLOGY_POLL)) &&
1725 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1726 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1727 ((UINT32)(time(NULL) - m_lastTopologyPoll) > g_dwTopologyPollingInterval);
1728 }
1729
1730 inline bool Node::isReadyForInstancePoll()
1731 {
1732 if (m_isDeleted)
1733 return false;
1734 return (m_status != STATUS_UNMANAGED) &&
1735 (!(m_dwFlags & NF_DISABLE_CONF_POLL)) &&
1736 (!(m_dwDynamicFlags & NDF_QUEUED_FOR_INSTANCE_POLL)) &&
1737 (!(m_dwDynamicFlags & NDF_POLLING_DISABLED)) &&
1738 (m_dwDynamicFlags & NDF_CONFIGURATION_POLL_PASSED) &&
1739 ((UINT32)(time(NULL) - m_lastInstancePoll) > g_instancePollingInterval);
1740 }
1741
1742 inline void Node::lockForStatusPoll()
1743 {
1744 lockProperties();
1745 m_dwDynamicFlags |= NDF_QUEUED_FOR_STATUS_POLL;
1746 unlockProperties();
1747 }
1748
1749 inline void Node::lockForConfigurationPoll()
1750 {
1751 lockProperties();
1752 m_dwDynamicFlags |= NDF_QUEUED_FOR_CONFIG_POLL;
1753 unlockProperties();
1754 }
1755
1756 inline void Node::lockForInstancePoll()
1757 {
1758 lockProperties();
1759 m_dwDynamicFlags |= NDF_QUEUED_FOR_INSTANCE_POLL;
1760 unlockProperties();
1761 }
1762
1763 inline void Node::lockForDiscoveryPoll()
1764 {
1765 lockProperties();
1766 m_dwDynamicFlags |= NDF_QUEUED_FOR_DISCOVERY_POLL;
1767 unlockProperties();
1768 }
1769
1770 inline void Node::lockForTopologyPoll()
1771 {
1772 lockProperties();
1773 m_dwDynamicFlags |= NDF_QUEUED_FOR_TOPOLOGY_POLL;
1774 unlockProperties();
1775 }
1776
1777 inline void Node::lockForRoutePoll()
1778 {
1779 lockProperties();
1780 m_dwDynamicFlags |= NDF_QUEUED_FOR_ROUTE_POLL;
1781 unlockProperties();
1782 }
1783
1784 /**
1785 * Subnet
1786 */
1787 class NXCORE_EXPORTABLE Subnet : public NetObj
1788 {
1789 friend void Node::buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedSubnet, bool vpnLink, bool includeEndNodes);
1790
1791 protected:
1792 InetAddress m_ipAddress;
1793 UINT32 m_zoneId;
1794 bool m_bSyntheticMask;
1795
1796 virtual void prepareForDeletion();
1797
1798 virtual void fillMessageInternal(NXCPMessage *pMsg);
1799
1800 void buildIPTopologyInternal(nxmap_ObjList &topology, int nDepth, UINT32 seedNode, bool includeEndNodes);
1801
1802 public:
1803 Subnet();
1804 Subnet(const InetAddress& addr, UINT32 dwZone, bool bSyntheticMask);
1805 virtual ~Subnet();
1806
1807 virtual int getObjectClass() const { return OBJECT_SUBNET; }
1808
1809 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1810 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1811 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
1812
1813 void addNode(Node *node) { addChild(node); node->addParent(this); calculateCompoundStatus(TRUE); }
1814
1815 virtual bool showThresholdSummary();
1816
1817 const InetAddress& getIpAddress() { return m_ipAddress; }
1818 UINT32 getZoneId() { return m_zoneId; }
1819 bool isSyntheticMask() { return m_bSyntheticMask; }
1820
1821 void setCorrectMask(const InetAddress& addr);
1822
1823 bool findMacAddress(const InetAddress& ipAddr, BYTE *macAddr);
1824
1825 UINT32 *buildAddressMap(int *length);
1826 };
1827
1828 /**
1829 * Universal root object
1830 */
1831 class NXCORE_EXPORTABLE UniversalRoot : public NetObj
1832 {
1833 using NetObj::loadFromDatabase;
1834
1835 public:
1836 UniversalRoot();
1837 virtual ~UniversalRoot();
1838
1839 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1840 void loadFromDatabase(DB_HANDLE hdb);
1841
1842 void linkChildObjects();
1843 void linkObject(NetObj *pObject) { addChild(pObject); pObject->addParent(this); }
1844 };
1845
1846 /**
1847 * Service root
1848 */
1849 class NXCORE_EXPORTABLE ServiceRoot : public UniversalRoot
1850 {
1851 public:
1852 ServiceRoot();
1853 virtual ~ServiceRoot();
1854
1855 virtual int getObjectClass() const { return OBJECT_SERVICEROOT; }
1856
1857 virtual bool showThresholdSummary();
1858 };
1859
1860 /**
1861 * Template root
1862 */
1863 class NXCORE_EXPORTABLE TemplateRoot : public UniversalRoot
1864 {
1865 public:
1866 TemplateRoot();
1867 virtual ~TemplateRoot();
1868
1869 virtual int getObjectClass() const { return OBJECT_TEMPLATEROOT; }
1870 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1871 };
1872
1873 /**
1874 * Generic container object
1875 */
1876 class NXCORE_EXPORTABLE Container : public NetObj
1877 {
1878 private:
1879 UINT32 *m_pdwChildIdList;
1880 UINT32 m_dwChildIdListSize;
1881
1882 protected:
1883 UINT32 m_flags;
1884 NXSL_Program *m_bindFilter;
1885 TCHAR *m_bindFilterSource;
1886
1887 virtual void fillMessageInternal(NXCPMessage *msg);
1888 virtual UINT32 modifyFromMessageInternal(NXCPMessage *request);
1889
1890 public:
1891 Container();
1892 Container(const TCHAR *pszName, UINT32 dwCategory);
1893 virtual ~Container();
1894
1895 virtual int getObjectClass() const { return OBJECT_CONTAINER; }
1896
1897 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1898 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1899 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
1900
1901 virtual bool showThresholdSummary();
1902
1903 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1904
1905 void linkChildObjects();
1906 void linkObject(NetObj *pObject) { addChild(pObject); pObject->addParent(this); }
1907
1908 AutoBindDecision isSuitableForNode(Node *node);
1909 bool isAutoBindEnabled() { return (m_flags & CF_AUTO_BIND) ? true : false; }
1910 bool isAutoUnbindEnabled() { return ((m_flags & (CF_AUTO_BIND | CF_AUTO_UNBIND)) == (CF_AUTO_BIND | CF_AUTO_UNBIND)) ? true : false; }
1911
1912 void setAutoBindFilter(const TCHAR *script);
1913 };
1914
1915 /**
1916 * Template group object
1917 */
1918 class NXCORE_EXPORTABLE TemplateGroup : public Container
1919 {
1920 public:
1921 TemplateGroup() : Container() { }
1922 TemplateGroup(const TCHAR *pszName) : Container(pszName, 0) { m_status = STATUS_NORMAL; }
1923 virtual ~TemplateGroup() { }
1924
1925 virtual int getObjectClass() const { return OBJECT_TEMPLATEGROUP; }
1926 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
1927
1928 virtual bool showThresholdSummary();
1929 };
1930
1931 /**
1932 * Rack object
1933 */
1934 class NXCORE_EXPORTABLE Rack : public Container
1935 {
1936 protected:
1937 int m_height; // Rack height in units
1938 bool m_topBottomNumbering;
1939
1940 virtual void fillMessageInternal(NXCPMessage *pMsg);
1941 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1942
1943 public:
1944 Rack();
1945 Rack(const TCHAR *name, int height);
1946 virtual ~Rack();
1947
1948 virtual int getObjectClass() const { return OBJECT_RACK; }
1949
1950 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1951 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1952 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
1953 };
1954
1955 /**
1956 * Zone object
1957 */
1958 class Zone : public NetObj
1959 {
1960 protected:
1961 UINT32 m_zoneId;
1962 UINT32 m_agentProxy;
1963 UINT32 m_snmpProxy;
1964 UINT32 m_icmpProxy;
1965 InetAddressIndex *m_idxNodeByAddr;
1966 InetAddressIndex *m_idxInterfaceByAddr;
1967 InetAddressIndex *m_idxSubnetByAddr;
1968
1969 virtual void fillMessageInternal(NXCPMessage *pMsg);
1970 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
1971
1972 public:
1973 Zone();
1974 Zone(UINT32 zoneId, const TCHAR *name);
1975 virtual ~Zone();
1976
1977 virtual int getObjectClass() const { return OBJECT_ZONE; }
1978
1979 virtual BOOL saveToDatabase(DB_HANDLE hdb);
1980 virtual bool deleteFromDatabase(DB_HANDLE hdb);
1981 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
1982
1983 virtual bool showThresholdSummary();
1984
1985 virtual NXSL_Value *createNXSLObject();
1986
1987 UINT32 getZoneId() { return m_zoneId; }
1988 UINT32 getAgentProxy() { return m_agentProxy; }
1989 UINT32 getSnmpProxy() { return m_snmpProxy; }
1990 UINT32 getIcmpProxy() { return m_icmpProxy; }
1991
1992 void addSubnet(Subnet *pSubnet) { addChild(pSubnet); pSubnet->addParent(this); }
1993
1994 void addToIndex(Subnet *subnet) { m_idxSubnetByAddr->put(subnet->getIpAddress(), subnet); }
1995 void addToIndex(Interface *iface) { m_idxInterfaceByAddr->put(iface->getIpAddressList(), iface); }
1996 void addToIndex(const InetAddress& addr, Interface *iface) { m_idxInterfaceByAddr->put(addr, iface); }
1997 void addToIndex(Node *node) { m_idxNodeByAddr->put(node->getIpAddress(), node); }
1998 void removeFromIndex(Subnet *subnet) { m_idxSubnetByAddr->remove(subnet->getIpAddress()); }
1999 void removeFromIndex(Interface *iface);
2000 void removeFromInterfaceIndex(const InetAddress& addr) { m_idxInterfaceByAddr->remove(addr); }
2001 void removeFromIndex(Node *node) { m_idxNodeByAddr->remove(node->getIpAddress()); }
2002 void updateInterfaceIndex(const InetAddress& oldIp, const InetAddress& newIp, Interface *iface);
2003 Subnet *getSubnetByAddr(const InetAddress& ipAddr) { return (Subnet *)m_idxSubnetByAddr->get(ipAddr); }
2004 Interface *getInterfaceByAddr(const InetAddress& ipAddr) { return (Interface *)m_idxInterfaceByAddr->get(ipAddr); }
2005 Node *getNodeByAddr(const InetAddress& ipAddr) { return (Node *)m_idxNodeByAddr->get(ipAddr); }
2006 Subnet *findSubnet(bool (*comparator)(NetObj *, void *), void *data) { return (Subnet *)m_idxSubnetByAddr->find(comparator, data); }
2007 Interface *findInterface(bool (*comparator)(NetObj *, void *), void *data) { return (Interface *)m_idxInterfaceByAddr->find(comparator, data); }
2008 Node *findNode(bool (*comparator)(NetObj *, void *), void *data) { return (Node *)m_idxNodeByAddr->find(comparator, data); }
2009 void forEachSubnet(void (*callback)(const InetAddress& addr, NetObj *, void *), void *data) { m_idxSubnetByAddr->forEach(callback, data); }
2010 ObjectArray<NetObj> *getSubnets(bool updateRefCount) { return m_idxSubnetByAddr->getObjects(updateRefCount); }
2011 };
2012
2013 /**
2014 * Entire network
2015 */
2016 class NXCORE_EXPORTABLE Network : public NetObj
2017 {
2018 using NetObj::loadFromDatabase;
2019
2020 public:
2021 Network();
2022 virtual ~Network();
2023
2024 virtual int getObjectClass() const { return OBJECT_NETWORK; }
2025 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2026
2027 virtual bool showThresholdSummary();
2028
2029 void AddSubnet(Subnet *pSubnet) { addChild(pSubnet); pSubnet->addParent(this); }
2030 void AddZone(Zone *pZone) { addChild(pZone); pZone->addParent(this); }
2031 void loadFromDatabase(DB_HANDLE hdb);
2032 };
2033
2034 /**
2035 * Condition
2036 */
2037 class NXCORE_EXPORTABLE Condition : public NetObj
2038 {
2039 protected:
2040 UINT32 m_dciCount;
2041 INPUT_DCI *m_dciList;
2042 TCHAR *m_scriptSource;
2043 NXSL_VM *m_script;
2044 UINT32 m_activationEventCode;
2045 UINT32 m_deactivationEventCode;
2046 UINT32 m_sourceObject;
2047 int m_activeStatus;
2048 int m_inactiveStatus;
2049 bool m_isActive;
2050 time_t m_lastPoll;
2051 bool m_queuedForPolling;
2052
2053 virtual void fillMessageInternal(NXCPMessage *pMsg);
2054 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2055
2056 public:
2057 Condition();
2058 Condition(bool hidden);
2059 virtual ~Condition();
2060
2061 virtual int getObjectClass() const { return OBJECT_CONDITION; }
2062
2063 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2064 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2065 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2066
2067 void lockForPoll();
2068 void doPoll(PollerInfo *poller);
2069 void check();
2070
2071 bool isReadyForPoll()
2072 {
2073 return ((m_status != STATUS_UNMANAGED) &&
2074 (!m_queuedForPolling) && (!m_isDeleted) &&
2075 ((UINT32)time(NULL) - (UINT32)m_lastPoll > g_dwConditionPollingInterval));
2076 }
2077
2078 int getCacheSizeForDCI(UINT32 itemId, bool noLock);
2079 };
2080
2081 /**
2082 * Generic agent policy object
2083 */
2084 class NXCORE_EXPORTABLE AgentPolicy : public NetObj
2085 {
2086 protected:
2087 UINT32 m_version;
2088 int m_policyType;
2089
2090 BOOL savePolicyCommonProperties(DB_HANDLE hdb);
2091
2092 virtual void fillMessageInternal(NXCPMessage *pMsg);
2093 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2094
2095 public:
2096 AgentPolicy(int type);
2097 AgentPolicy(const TCHAR *name, int type);
2098
2099 virtual int getObjectClass() const { return OBJECT_AGENTPOLICY; }
2100
2101 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2102 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2103 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2104
2105 virtual bool createDeploymentMessage(NXCPMessage *msg);
2106 virtual bool createUninstallMessage(NXCPMessage *msg);
2107
2108 void linkNode(Node *node) { addChild(node); node->addParent(this); }
2109 void unlinkNode(Node *node) { deleteChild(node); node->deleteParent(this); }
2110 };
2111
2112 /**
2113 * Agent config policy object
2114 */
2115 class NXCORE_EXPORTABLE AgentPolicyConfig : public AgentPolicy
2116 {
2117 protected:
2118 TCHAR *m_fileContent;
2119
2120 virtual void fillMessageInternal(NXCPMessage *pMsg);
2121 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2122
2123 public:
2124 AgentPolicyConfig();
2125 AgentPolicyConfig(const TCHAR *name);
2126 virtual ~AgentPolicyConfig();
2127
2128 virtual int getObjectClass() const { return OBJECT_AGENTPOLICY_CONFIG; }
2129
2130 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2131 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2132 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2133
2134 virtual bool createDeploymentMessage(NXCPMessage *msg);
2135 virtual bool createUninstallMessage(NXCPMessage *msg);
2136 };
2137
2138 /**
2139 * Log parser configuration policy object
2140 */
2141 class NXCORE_EXPORTABLE AgentPolicyLogParser : public AgentPolicy
2142 {
2143 protected:
2144 TCHAR *m_fileContent;
2145
2146 virtual void fillMessageInternal(NXCPMessage *pMsg);
2147 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2148 public:
2149 AgentPolicyLogParser();
2150 AgentPolicyLogParser(const TCHAR *name);
2151 virtual ~AgentPolicyLogParser();
2152
2153 virtual int getObjectClass() const { return OBJECT_AGENTPOLICY_LOGPARSER; }
2154
2155 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2156 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2157 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2158
2159 virtual bool createDeploymentMessage(NXCPMessage *msg);
2160 virtual bool createUninstallMessage(NXCPMessage *msg);
2161 };
2162
2163 /**
2164 * Policy group object
2165 */
2166 class NXCORE_EXPORTABLE PolicyGroup : public Container
2167 {
2168 public:
2169 PolicyGroup() : Container() { }
2170 PolicyGroup(const TCHAR *pszName) : Container(pszName, 0) { }
2171 virtual ~PolicyGroup() { }
2172
2173 virtual int getObjectClass() const { return OBJECT_POLICYGROUP; }
2174 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2175
2176 virtual bool showThresholdSummary();
2177 };
2178
2179 /**
2180 * Policy root
2181 */
2182 class NXCORE_EXPORTABLE PolicyRoot : public UniversalRoot
2183 {
2184 public:
2185 PolicyRoot();
2186 virtual ~PolicyRoot();
2187
2188 virtual int getObjectClass() const { return OBJECT_POLICYROOT; }
2189 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2190 };
2191
2192 /**
2193 * Network map root
2194 */
2195 class NXCORE_EXPORTABLE NetworkMapRoot : public UniversalRoot
2196 {
2197 public:
2198 NetworkMapRoot();
2199 virtual ~NetworkMapRoot();
2200
2201 virtual int getObjectClass() const { return OBJECT_NETWORKMAPROOT; }
2202 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2203 };
2204
2205 /**
2206 * Network map group object
2207 */
2208 class NXCORE_EXPORTABLE NetworkMapGroup : public Container
2209 {
2210 public:
2211 NetworkMapGroup() : Container() { }
2212 NetworkMapGroup(const TCHAR *pszName) : Container(pszName, 0) { }
2213 virtual ~NetworkMapGroup() { }
2214
2215 virtual int getObjectClass() const { return OBJECT_NETWORKMAPGROUP; }
2216 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2217
2218 virtual bool showThresholdSummary();
2219 };
2220
2221 /**
2222 * Network map object
2223 */
2224 class NXCORE_EXPORTABLE NetworkMap : public NetObj
2225 {
2226 protected:
2227 int m_mapType;
2228 UINT32 m_seedObject;
2229 int m_discoveryRadius;
2230 int m_layout;
2231 UINT32 m_flags;
2232 int m_backgroundColor;
2233 int m_defaultLinkColor;
2234 int m_defaultLinkRouting;
2235 int m_objectDisplayMode;
2236 uuid m_background;
2237 double m_backgroundLatitude;
2238 double m_backgroundLongitude;
2239 int m_backgroundZoom;
2240 UINT32 m_nextElementId;
2241 ObjectArray<NetworkMapElement> *m_elements;
2242 ObjectArray<NetworkMapLink> *m_links;
2243 TCHAR *m_filterSource;
2244 NXSL_VM *m_filter;
2245
2246 virtual void fillMessageInternal(NXCPMessage *pMsg);
2247 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2248
2249 void updateObjects(nxmap_ObjList *objects);
2250 UINT32 objectIdFromElementId(UINT32 eid);
2251 UINT32 elementIdFromObjectId(UINT32 eid);
2252
2253 void setFilter(const TCHAR *filter);
2254
2255 public:
2256 NetworkMap();
2257 NetworkMap(int type, UINT32 seed);
2258 virtual ~NetworkMap();
2259
2260 virtual int getObjectClass() const { return OBJECT_NETWORKMAP; }
2261 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2262
2263 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2264 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2265 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2266
2267 virtual void onObjectDelete(UINT32 dwObjectId);
2268
2269 void updateContent();
2270
2271 int getBackgroundColor() { return m_backgroundColor; }
2272 void setBackgroundColor(int color) { m_backgroundColor = color; }
2273
2274 bool isAllowedOnMap(NetObj *object);
2275 };
2276
2277 /**
2278 * Dashboard tree root
2279 */
2280 class NXCORE_EXPORTABLE DashboardRoot : public UniversalRoot
2281 {
2282 public:
2283 DashboardRoot();
2284 virtual ~DashboardRoot();
2285
2286 virtual int getObjectClass() const { return OBJECT_DASHBOARDROOT; }
2287 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2288 };
2289
2290 /**
2291 * Dashboard element
2292 */
2293 class DashboardElement
2294 {
2295 public:
2296 int m_type;
2297 TCHAR *m_data;
2298 TCHAR *m_layout;
2299
2300 DashboardElement() { m_data = NULL; m_layout = NULL; }
2301 ~DashboardElement() { safe_free(m_data); safe_free(m_layout); }
2302 };
2303
2304 /**
2305 * Dashboard object
2306 */
2307 class NXCORE_EXPORTABLE Dashboard : public Container
2308 {
2309 protected:
2310 int m_numColumns;
2311 UINT32 m_options;
2312 ObjectArray<DashboardElement> *m_elements;
2313
2314 virtual void fillMessageInternal(NXCPMessage *pMsg);
2315 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2316
2317 public:
2318 Dashboard();
2319 Dashboard(const TCHAR *name);
2320 virtual ~Dashboard();
2321
2322 virtual int getObjectClass() const { return OBJECT_DASHBOARD; }
2323 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2324
2325 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2326 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2327 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2328
2329 virtual bool showThresholdSummary();
2330 };
2331
2332 /**
2333 * SLM check object
2334 */
2335 class NXCORE_EXPORTABLE SlmCheck : public NetObj
2336 {
2337 protected:
2338 static NXSL_VariableSystem m_nxslConstants;
2339
2340 Threshold *m_threshold;
2341 enum CheckType { check_undefined = 0, check_script = 1, check_threshold = 2 } m_type;
2342 TCHAR *m_script;
2343 NXSL_VM *m_pCompiledScript;
2344 TCHAR m_reason[256];
2345 bool m_isTemplate;
2346 UINT32 m_templateId;
2347 UINT32 m_currentTicketId;
2348
2349 virtual void onObjectDelete(UINT32 objectId);
2350
2351 virtual void fillMessageInternal(NXCPMessage *pMsg);
2352 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2353
2354 void setScript(const TCHAR *script);
2355 UINT32 getOwnerId();
2356 NXSL_Value *getNodeObjectForNXSL();
2357 bool insertTicket();
2358 void closeTicket();
2359 void setReason(const TCHAR *reason) { nx_strncpy(m_reason, CHECK_NULL_EX(reason), 256); }
2360 void compileScript();
2361
2362 public:
2363 SlmCheck();
2364 SlmCheck(const TCHAR *name, bool isTemplate);
2365 SlmCheck(SlmCheck *tmpl);
2366 virtual ~SlmCheck();
2367
2368 static void init();
2369
2370 virtual int getObjectClass() const { return OBJECT_SLMCHECK; }
2371
2372 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2373 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2374 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2375
2376 virtual void postModify();
2377
2378 void execute();
2379 void updateFromTemplate(SlmCheck *tmpl);
2380
2381 bool isTemplate() { return m_isTemplate; }
2382 UINT32 getTemplateId() { return m_templateId; }
2383 const TCHAR *getReason() { return m_reason; }
2384 };
2385
2386 /**
2387 * Service container - common logic for BusinessService, NodeLink and BusinessServiceRoot
2388 */
2389 class NXCORE_EXPORTABLE ServiceContainer : public Container
2390 {
2391 enum Period { DAY, WEEK, MONTH };
2392
2393 protected:
2394 time_t m_prevUptimeUpdateTime;
2395 int m_prevUptimeUpdateStatus;
2396 double m_uptimeDay;
2397 double m_uptimeWeek;
2398 double m_uptimeMonth;
2399 INT32 m_downtimeDay;
2400 INT32 m_downtimeWeek;
2401 INT32 m_downtimeMonth;
2402 INT32 m_prevDiffDay;
2403 INT32 m_prevDiffWeek;
2404 INT32 m_prevDiffMonth;
2405
2406 static INT32 logRecordId;
2407 static INT32 getSecondsInMonth();
2408 static INT32 getSecondsInPeriod(Period period) { return period == MONTH ? getSecondsInMonth() : (period == WEEK ? (3600 * 24 * 7) : (3600 * 24)); }
2409 static INT32 getSecondsSinceBeginningOf(Period period, time_t *beginTime = NULL);
2410
2411 virtual void fillMessageInternal(NXCPMessage *pMsg);
2412 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2413
2414 void initServiceContainer();
2415 BOOL addHistoryRecord();
2416 double getUptimeFromDBFor(Period period, INT32 *downtime);
2417
2418 public:
2419 ServiceContainer();
2420 ServiceContainer(const TCHAR *pszName);
2421
2422 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2423 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2424 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2425
2426 virtual void calculateCompoundStatus(BOOL bForcedRecalc = FALSE);
2427 virtual void setStatus(int newStatus);
2428
2429 virtual bool showThresholdSummary();
2430
2431 void initUptimeStats();
2432 void updateUptimeStats(time_t currentTime = 0, BOOL updateChilds = FALSE);
2433 };
2434
2435 /**
2436 * Business service root
2437 */
2438 class NXCORE_EXPORTABLE BusinessServiceRoot : public ServiceContainer
2439 {
2440 using ServiceContainer::loadFromDatabase;
2441
2442 public:
2443 BusinessServiceRoot();
2444 virtual ~BusinessServiceRoot();
2445
2446 virtual int getObjectClass() const { return OBJECT_BUSINESSSERVICEROOT; }
2447
2448 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2449 void loadFromDatabase(DB_HANDLE hdb);
2450
2451 void linkChildObjects();
2452 void linkObject(NetObj *pObject) { addChild(pObject); pObject->addParent(this); }
2453 };
2454
2455 /**
2456 * Business service object
2457 */
2458 class NXCORE_EXPORTABLE BusinessService : public ServiceContainer
2459 {
2460 protected:
2461 bool m_busy;
2462 bool m_pollingDisabled;
2463 time_t m_lastPollTime;
2464 int m_lastPollStatus;
2465
2466 virtual void prepareForDeletion();
2467
2468 virtual void fillMessageInternal(NXCPMessage *pMsg);
2469 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2470
2471 public:
2472 BusinessService();
2473 BusinessService(const TCHAR *name);
2474 virtual ~BusinessService();
2475
2476 virtual int getObjectClass() const { return OBJECT_BUSINESSSERVICE; }
2477
2478 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2479 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2480 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2481
2482 bool isReadyForPolling();
2483 void lockForPolling();
2484 void poll(PollerInfo *poller);
2485 void poll(ClientSession *pSession, UINT32 dwRqId, PollerInfo *poller);
2486
2487 void getApplicableTemplates(ServiceContainer *target, ObjectArray<SlmCheck> *templates);
2488 };
2489
2490 /**
2491 * Node link object for business service
2492 */
2493 class NXCORE_EXPORTABLE NodeLink : public ServiceContainer
2494 {
2495 protected:
2496 UINT32 m_nodeId;
2497
2498 virtual void onObjectDelete(UINT32 dwObjectId);
2499
2500 virtual void fillMessageInternal(NXCPMessage *pMsg);
2501 virtual UINT32 modifyFromMessageInternal(NXCPMessage *pRequest);
2502
2503 void applyTemplate(SlmCheck *tmpl);
2504
2505 public:
2506 NodeLink();
2507 NodeLink(const TCHAR *name, UINT32 nodeId);
2508 virtual ~NodeLink();
2509
2510 virtual int getObjectClass() const { return OBJECT_NODELINK; }
2511
2512 virtual BOOL saveToDatabase(DB_HANDLE hdb);
2513 virtual bool deleteFromDatabase(DB_HANDLE hdb);
2514 virtual bool loadFromDatabase(DB_HANDLE hdb, UINT32 id);
2515
2516 void execute();
2517 void applyTemplates();
2518
2519 UINT32 getNodeId() { return m_nodeId; }
2520 };
2521
2522 /**
2523 * Get IP address for object
2524 */
2525 inline const InetAddress& GetObjectIpAddress(NetObj *object)
2526 {
2527 if (object->getObjectClass() == OBJECT_NODE)
2528 return ((Node *)object)->getIpAddress();
2529 if (object->getObjectClass() == OBJECT_SUBNET)
2530 return ((Subnet *)object)->getIpAddress();
2531 if (object->getObjectClass() == OBJECT_ACCESSPOINT)
2532 return ((AccessPoint *)object)->getIpAddress();
2533 if (object->getObjectClass() == OBJECT_INTERFACE)
2534 return ((Interface *)object)->getIpAddressList()->getFirstUnicastAddress();
2535 return InetAddress::INVALID;
2536 }
2537
2538 /**
2539 * Functions
2540 */
2541 void ObjectsInit();
2542
2543 void NXCORE_EXPORTABLE NetObjInsert(NetObj *object, bool newObject, bool importedObject);
2544 void NetObjDeleteFromIndexes(NetObj *object);
2545 void NetObjDelete(NetObj *object);
2546
2547 void UpdateInterfaceIndex(const InetAddress& oldIpAddr, const InetAddress& newIpAddr, Interface *iface);
2548 ComponentTree *BuildComponentTree(Node *node, SNMP_Transport *snmp);
2549
2550 void NXCORE_EXPORTABLE MacDbAddAccessPoint(AccessPoint *ap);
2551 void NXCORE_EXPORTABLE MacDbAddInterface(Interface *iface);
2552 void NXCORE_EXPORTABLE MacDbAddObject(const BYTE *macAddr, NetObj *object);
2553 void NXCORE_EXPORTABLE MacDbRemove(const BYTE *macAddr);
2554 NetObj NXCORE_EXPORTABLE *MacDbFind(const BYTE *macAddr);
2555
2556 NetObj NXCORE_EXPORTABLE *FindObjectById(UINT32 dwId, int objClass = -1);
2557 NetObj NXCORE_EXPORTABLE *FindObjectByName(const TCHAR *name, int objClass);
2558 NetObj NXCORE_EXPORTABLE *FindObjectByGUID(const uuid& guid, int objClass);
2559 const TCHAR NXCORE_EXPORTABLE *GetObjectName(DWORD id, const TCHAR *defaultName);
2560 Template NXCORE_EXPORTABLE *FindTemplateByName(const TCHAR *pszName);
2561 Node NXCORE_EXPORTABLE *FindNodeByIP(UINT32 zoneId, const InetAddress& ipAddr);
2562 Node NXCORE_EXPORTABLE *FindNodeByIP(UINT32 zoneId, const InetAddressList *ipAddrList);
2563 Node NXCORE_EXPORTABLE *FindNodeByMAC(const BYTE *macAddr);
2564 Node NXCORE_EXPORTABLE *FindNodeByBridgeId(const BYTE *bridgeId);
2565 Node NXCORE_EXPORTABLE *FindNodeByLLDPId(const TCHAR *lldpId);
2566 Node NXCORE_EXPORTABLE *FindNodeBySysName(const TCHAR *sysName);
2567 Interface NXCORE_EXPORTABLE *FindInterfaceByIP(UINT32 zoneId, const InetAddress& ipAddr);
2568 Interface NXCORE_EXPORTABLE *FindInterfaceByMAC(const BYTE *macAddr);
2569 Interface NXCORE_EXPORTABLE *FindInterfaceByDescription(const TCHAR *description);
2570 Subnet NXCORE_EXPORTABLE *FindSubnetByIP(UINT32 zoneId, const InetAddress& ipAddr);
2571 Subnet NXCORE_EXPORTABLE *FindSubnetForNode(UINT32 zoneId, const InetAddress& nodeAddr);
2572 MobileDevice NXCORE_EXPORTABLE *FindMobileDeviceByDeviceID(const TCHAR *deviceId);
2573 AccessPoint NXCORE_EXPORTABLE *FindAccessPointByMAC(const BYTE *macAddr);
2574 UINT32 NXCORE_EXPORTABLE FindLocalMgmtNode();
2575 Zone NXCORE_EXPORTABLE *FindZoneByGUID(UINT32 dwZoneGUID);
2576 Cluster NXCORE_EXPORTABLE *FindClusterByResourceIP(UINT32 zone, const InetAddress& ipAddr);
2577 bool NXCORE_EXPORTABLE IsClusterIP(UINT32 zone, const InetAddress& ipAddr);
2578
2579 BOOL LoadObjects();
2580 void DumpObjects(CONSOLE_CTX pCtx, const TCHAR *filter);
2581
2582 void DeleteUserFromAllObjects(UINT32 dwUserId);
2583
2584 bool IsValidParentClass(int childClass, int parentClass);
2585 bool IsAgentPolicyObject(NetObj *object);
2586 bool IsEventSource(int objectClass);
2587
2588 int DefaultPropagatedStatus(int iObjectStatus);
2589 int GetDefaultStatusCalculation(int *pnSingleThreshold, int **ppnThresholds);
2590
2591 PollerInfo *RegisterPoller(PollerType type, NetObj *object);
2592 void ShowPollers(CONSOLE_CTX console);
2593
2594 /**
2595 * Global variables
2596 */
2597 extern Network NXCORE_EXPORTABLE *g_pEntireNet;
2598 extern ServiceRoot NXCORE_EXPORTABLE *g_pServiceRoot;
2599 extern TemplateRoot NXCORE_EXPORTABLE *g_pTemplateRoot;
2600 extern PolicyRoot NXCORE_EXPORTABLE *g_pPolicyRoot;
2601 extern NetworkMapRoot NXCORE_EXPORTABLE *g_pMapRoot;
2602 extern DashboardRoot NXCORE_EXPORTABLE *g_pDashboardRoot;
2603 extern BusinessServiceRoot NXCORE_EXPORTABLE *g_pBusinessServiceRoot;
2604
2605 extern UINT32 NXCORE_EXPORTABLE g_dwMgmtNode;
2606 extern BOOL g_bModificationsLocked;
2607 extern Queue *g_pTemplateUpdateQueue;
2608
2609 extern ObjectIndex NXCORE_EXPORTABLE g_idxObjectById;
2610 extern InetAddressIndex NXCORE_EXPORTABLE g_idxSubnetByAddr;
2611 extern InetAddressIndex NXCORE_EXPORTABLE g_idxInterfaceByAddr;
2612 extern InetAddressIndex NXCORE_EXPORTABLE g_idxNodeByAddr;
2613 extern ObjectIndex NXCORE_EXPORTABLE g_idxZoneByGUID;
2614 extern ObjectIndex NXCORE_EXPORTABLE g_idxNodeById;
2615 extern ObjectIndex NXCORE_EXPORTABLE g_idxChassisById;
2616 extern ObjectIndex NXCORE_EXPORTABLE g_idxClusterById;
2617 extern ObjectIndex NXCORE_EXPORTABLE g_idxMobileDeviceById;
2618 extern ObjectIndex NXCORE_EXPORTABLE g_idxAccessPointById;
2619 extern ObjectIndex NXCORE_EXPORTABLE g_idxConditionById;
2620 extern ObjectIndex NXCORE_EXPORTABLE g_idxServiceCheckById;
2621
2622 #endif /* _nms_objects_h_ */