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