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