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