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