all pollers converted to single thread pool
[public/netxms.git] / src / server / include / nms_dcoll.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2013 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_dcoll.h
20 **
21 **/
22
23 #ifndef _nms_dcoll_h_
24 #define _nms_dcoll_h_
25
26
27 //
28 // Data collection errors
29 //
30
31 #define DCE_SUCCESS 0
32 #define DCE_COMM_ERROR 1
33 #define DCE_NOT_SUPPORTED 2
34 #define DCE_IGNORE 3
35
36 /**
37 * Threshold check results
38 */
39 enum ThresholdCheckResult
40 {
41 ACTIVATED = 0,
42 DEACTIVATED = 1,
43 ALREADY_ACTIVE = 2,
44 ALREADY_INACTIVE = 3
45 };
46
47 /**
48 * DCI value
49 */
50 class NXCORE_EXPORTABLE ItemValue
51 {
52 private:
53 double m_dFloat;
54 INT32 m_iInt32;
55 INT64 m_iInt64;
56 UINT32 m_dwInt32;
57 UINT64 m_qwInt64;
58 TCHAR m_szString[MAX_DB_STRING];
59 UINT32 m_dwTimeStamp;
60
61 public:
62 ItemValue();
63 ItemValue(const TCHAR *pszValue, UINT32 dwTimeStamp);
64 ItemValue(const ItemValue *pValue);
65 ~ItemValue();
66
67 void setTimeStamp(UINT32 dwTime) { m_dwTimeStamp = dwTime; }
68 UINT32 getTimeStamp() { return m_dwTimeStamp; }
69
70 const TCHAR *getString() { return m_szString; }
71
72 operator double() { return m_dFloat; }
73 operator UINT32() { return m_dwInt32; }
74 operator UINT64() { return m_qwInt64; }
75 operator INT32() { return m_iInt32; }
76 operator INT64() { return m_iInt64; }
77 operator const TCHAR*() const { return m_szString; }
78
79 const ItemValue& operator=(const ItemValue &src);
80 const ItemValue& operator=(const TCHAR *pszStr);
81 const ItemValue& operator=(double dFloat);
82 const ItemValue& operator=(INT32 iInt32);
83 const ItemValue& operator=(INT64 iInt64);
84 const ItemValue& operator=(UINT32 dwInt32);
85 const ItemValue& operator=(UINT64 qwInt64);
86 };
87
88
89 class DCItem;
90 class DataCollectionTarget;
91
92 /**
93 * Threshold definition class
94 */
95 class NXCORE_EXPORTABLE Threshold
96 {
97 private:
98 UINT32 m_id; // Unique threshold id
99 UINT32 m_itemId; // Parent item id
100 UINT32 m_targetId; // Parent data collection target ID
101 UINT32 m_eventCode; // Event code to be generated
102 UINT32 m_rearmEventCode;
103 ItemValue m_value;
104 BYTE m_function; // Function code
105 BYTE m_operation; // Comparision operation code
106 BYTE m_dataType; // Related item data type
107 BYTE m_currentSeverity; // Current everity (NORMAL if threshold is inactive)
108 int m_sampleCount; // Number of samples to calculate function on
109 TCHAR *m_scriptSource;
110 NXSL_VM *m_script;
111 BOOL m_isReached;
112 int m_numMatches; // Number of consecutive matches
113 int m_repeatInterval; // -1 = default, 0 = off, >0 = seconds between repeats
114 time_t m_lastEventTimestamp;
115
116 const ItemValue& value() { return m_value; }
117 void calculateAverageValue(ItemValue *pResult, ItemValue &lastValue, ItemValue **ppPrevValues);
118 void calculateSumValue(ItemValue *pResult, ItemValue &lastValue, ItemValue **ppPrevValues);
119 void calculateMDValue(ItemValue *pResult, ItemValue &lastValue, ItemValue **ppPrevValues);
120 void calculateDiff(ItemValue *pResult, ItemValue &lastValue, ItemValue **ppPrevValues);
121 void setScript(TCHAR *script);
122
123 public:
124 Threshold();
125 Threshold(DCItem *pRelatedItem);
126 Threshold(Threshold *pSrc);
127 Threshold(DB_RESULT hResult, int iRow, DCItem *pRelatedItem);
128 Threshold(ConfigEntry *config, DCItem *parentItem);
129 ~Threshold();
130
131 void bindToItem(UINT32 itemId, UINT32 targetId) { m_itemId = itemId; m_targetId = targetId; }
132
133 UINT32 getId() { return m_id; }
134 UINT32 getEventCode() { return m_eventCode; }
135 UINT32 getRearmEventCode() { return m_rearmEventCode; }
136 int getFunction() { return m_function; }
137 int getOperation() { return m_operation; }
138 int getSampleCount() { return m_sampleCount; }
139 const TCHAR *getStringValue() { return m_value.getString(); }
140 BOOL isReached() { return m_isReached; }
141
142 int getRepeatInterval() { return m_repeatInterval; }
143 time_t getLastEventTimestamp() { return m_lastEventTimestamp; }
144 int getCurrentSeverity() { return m_currentSeverity; }
145 void markLastEvent(int severity);
146
147 BOOL saveToDB(DB_HANDLE hdb, UINT32 dwIndex);
148 ThresholdCheckResult check(ItemValue &value, ItemValue **ppPrevValues, ItemValue &fvalue, NetObj *target, DCItem *dci);
149 ThresholdCheckResult checkError(UINT32 dwErrorCount);
150
151 void createMessage(NXCPMessage *msg, UINT32 baseId);
152 void updateFromMessage(NXCPMessage *msg, UINT32 baseId);
153
154 void createId();
155 UINT32 getRequiredCacheSize() { return ((m_function == F_LAST) || (m_function == F_ERROR)) ? 0 : m_sampleCount; }
156
157 BOOL compare(Threshold *pThr);
158
159 void createNXMPRecord(String &str, int index);
160
161 void associate(DCItem *pItem);
162 void setFunction(int nFunc) { m_function = nFunc; }
163 void setOperation(int nOp) { m_operation = nOp; }
164 void setEvent(UINT32 dwEvent) { m_eventCode = dwEvent; }
165 void setRearmEvent(UINT32 dwEvent) { m_rearmEventCode = dwEvent; }
166 void setSampleCount(int nVal) { m_sampleCount = nVal; }
167 void setValue(const TCHAR *value) { m_value = value; }
168 };
169
170 class Template;
171
172 /**
173 * Generic data collection object
174 */
175 class NXCORE_EXPORTABLE DCObject
176 {
177 protected:
178 UINT32 m_id;
179 TCHAR m_name[MAX_ITEM_NAME];
180 TCHAR m_szDescription[MAX_DB_STRING];
181 TCHAR m_systemTag[MAX_DB_STRING];
182 time_t m_tLastPoll; // Last poll time
183 int m_iPollingInterval; // Polling interval in seconds
184 int m_iRetentionTime; // Retention time in days
185 BYTE m_source; // origin: SNMP, agent, etc.
186 BYTE m_status; // Item status: active, disabled or not supported
187 BYTE m_busy; // 1 when item is queued for polling, 0 if not
188 BYTE m_scheduledForDeletion; // 1 when item is scheduled for deletion, 0 if not
189 UINT16 m_flags;
190 UINT32 m_dwTemplateId; // Related template's id
191 UINT32 m_dwTemplateItemId; // Related template item's id
192 Template *m_pNode; // Pointer to node or template object this item related to
193 MUTEX m_hMutex;
194 UINT32 m_dwNumSchedules;
195 TCHAR **m_ppScheduleList;
196 time_t m_tLastCheck; // Last schedule checking time
197 UINT32 m_dwErrorCount; // Consequtive collection error count
198 UINT32 m_dwResourceId; // Associated cluster resource ID
199 UINT32 m_dwProxyNode; // Proxy node ID or 0 to disable
200 WORD m_snmpPort; // Custom SNMP port or 0 for node default
201 TCHAR *m_pszPerfTabSettings;
202 TCHAR *m_transformationScriptSource; // Transformation script (source code)
203 NXSL_VM *m_transformationScript; // Compiled transformation script
204 TCHAR *m_comments;
205
206 void lock() { MutexLock(m_hMutex); }
207 void unlock() { MutexUnlock(m_hMutex); }
208
209 BOOL loadCustomSchedules();
210 bool matchSchedule(struct tm *pCurrTime, TCHAR *pszSchedule, BOOL *bWithSeconds, time_t currTimestamp);
211
212 void expandMacros(const TCHAR *src, TCHAR *dst, size_t dstLen);
213
214 virtual bool isCacheLoaded();
215
216 // --- constructors ---
217 DCObject();
218 DCObject(const DCObject *src);
219 DCObject(UINT32 dwId, const TCHAR *szName, int iSource, int iPollingInterval, int iRetentionTime, Template *pNode,
220 const TCHAR *pszDescription = NULL, const TCHAR *systemTag = NULL);
221 DCObject(ConfigEntry *config, Template *owner);
222
223 public:
224 virtual ~DCObject();
225
226 virtual int getType() const { return DCO_TYPE_GENERIC; }
227
228 virtual void updateFromTemplate(DCObject *dcObject);
229
230 virtual BOOL saveToDB(DB_HANDLE hdb);
231 virtual void deleteFromDatabase();
232 virtual bool loadThresholdsFromDB();
233
234 virtual bool processNewValue(time_t nTimeStamp, const void *value, bool *updateStatus);
235 virtual void processNewError();
236
237 virtual bool hasValue();
238
239 UINT32 getId() { return m_id; }
240 int getDataSource() { return m_source; }
241 int getStatus() { return m_status; }
242 const TCHAR *getName() { return m_name; }
243 const TCHAR *getDescription() { return m_szDescription; }
244 const TCHAR *getSystemTag() { return m_systemTag; }
245 const TCHAR *getPerfTabSettings() { return m_pszPerfTabSettings; }
246 int getPollingInterval() { return m_iPollingInterval; }
247 Template *getTarget() { return m_pNode; }
248 UINT32 getTemplateId() { return m_dwTemplateId; }
249 UINT32 getTemplateItemId() { return m_dwTemplateItemId; }
250 UINT32 getResourceId() { return m_dwResourceId; }
251 UINT32 getProxyNode() { return m_dwProxyNode; }
252 time_t getLastPollTime() { return m_tLastPoll; }
253 UINT32 getErrorCount() { return m_dwErrorCount; }
254 WORD getSnmpPort() { return m_snmpPort; }
255 bool isShowOnObjectTooltip() { return (m_flags & DCF_SHOW_ON_OBJECT_TOOLTIP) ? true : false; }
256 bool isShowInObjectOverview() { return (m_flags & DCF_SHOW_IN_OBJECT_OVERVIEW) ? true : false; }
257 bool isAggregateOnCluster() { return (m_flags & DCF_AGGREGATE_ON_CLUSTER) ? true : false; }
258 bool isStatusDCO() {return (m_flags & DCF_CALCULATE_NODE_STATUS) ? true : false; }
259 int getAggregationFunction() { return DCF_GET_AGGREGATION_FUNCTION(m_flags); }
260 Template *getNode() { return m_pNode; }
261 int getRetentionTime() { return m_iRetentionTime; }
262 const TCHAR *getComments() { return m_comments; }
263 INT16 getAgentCacheMode();
264
265 bool matchClusterResource();
266 bool isReadyForPolling(time_t currTime);
267 bool isScheduledForDeletion() { return m_scheduledForDeletion ? true : false; }
268 void setLastPollTime(time_t tLastPoll) { m_tLastPoll = tLastPoll; }
269 void setStatus(int status, bool generateEvent);
270 void setBusyFlag(BOOL busy) { m_busy = (BYTE)busy; }
271 void setTemplateId(UINT32 dwTemplateId, UINT32 dwItemId)
272 { m_dwTemplateId = dwTemplateId; m_dwTemplateItemId = dwItemId; }
273
274 virtual void createMessage(NXCPMessage *pMsg);
275 virtual void updateFromMessage(NXCPMessage *pMsg);
276
277 virtual void changeBinding(UINT32 dwNewId, Template *pNode, BOOL doMacroExpansion);
278
279 virtual void deleteExpiredData();
280 virtual bool deleteAllData();
281
282 virtual void getEventList(UINT32 **ppdwList, UINT32 *pdwSize);
283 virtual void createNXMPRecord(String &str);
284
285 void setName(const TCHAR *pszName) { nx_strncpy(m_name, pszName, MAX_ITEM_NAME); }
286 void setDescription(const TCHAR *pszDescr) { nx_strncpy(m_szDescription, pszDescr, MAX_DB_STRING); }
287 void setOrigin(int origin) { m_source = origin; }
288 void setRetentionTime(int nTime) { m_iRetentionTime = nTime; }
289 void setInterval(int nInt) { m_iPollingInterval = nInt; }
290 void setAdvScheduleFlag(BOOL bFlag) { if (bFlag) m_flags |= DCF_ADVANCED_SCHEDULE; else m_flags &= ~DCF_ADVANCED_SCHEDULE; }
291 void addSchedule(const TCHAR *pszSchedule);
292 void setTransformationScript(const TCHAR *pszScript);
293
294 bool prepareForDeletion();
295 };
296
297 /**
298 * Data collection item class
299 */
300 class NXCORE_EXPORTABLE DCItem : public DCObject
301 {
302 protected:
303 TCHAR m_instance[MAX_DB_STRING];
304 BYTE m_deltaCalculation; // Delta calculation method
305 BYTE m_dataType;
306 int m_sampleCount; // Number of samples required to calculate value
307 ObjectArray<Threshold> *m_thresholds;
308 UINT32 m_cacheSize; // Number of items in cache
309 UINT32 m_requiredCacheSize;
310 ItemValue **m_ppValueCache;
311 ItemValue m_prevRawValue; // Previous raw value (used for delta calculation)
312 time_t m_tPrevValueTimeStamp;
313 bool m_bCacheLoaded;
314 int m_nBaseUnits;
315 int m_nMultiplier;
316 TCHAR *m_customUnitName;
317 WORD m_snmpRawValueType; // Actual SNMP raw value type for input transformation
318 WORD m_instanceDiscoveryMethod;
319 TCHAR *m_instanceDiscoveryData;
320 TCHAR *m_instanceFilterSource;
321 NXSL_VM *m_instanceFilter;
322
323 bool transform(ItemValue &value, time_t nElapsedTime);
324 void checkThresholds(ItemValue &value);
325 void clearCache();
326
327 virtual bool isCacheLoaded();
328
329 public:
330 DCItem();
331 DCItem(const DCItem *pItem);
332 DCItem(DB_RESULT hResult, int iRow, Template *pNode);
333 DCItem(UINT32 dwId, const TCHAR *szName, int iSource, int iDataType,
334 int iPollingInterval, int iRetentionTime, Template *pNode,
335 const TCHAR *pszDescription = NULL, const TCHAR *systemTag = NULL);
336 DCItem(ConfigEntry *config, Template *owner);
337 virtual ~DCItem();
338
339 virtual int getType() const { return DCO_TYPE_ITEM; }
340
341 virtual void updateFromTemplate(DCObject *dcObject);
342
343 virtual BOOL saveToDB(DB_HANDLE hdb);
344 virtual void deleteFromDatabase();
345 virtual bool loadThresholdsFromDB();
346
347 void updateCacheSize(UINT32 dwCondId = 0);
348 void reloadCache();
349
350 int getDataType() { return m_dataType; }
351 bool isInterpretSnmpRawValue() { return (m_flags & DCF_RAW_VALUE_OCTET_STRING) ? true : false; }
352 WORD getSnmpRawValueType() { return m_snmpRawValueType; }
353 bool hasActiveThreshold();
354 int getThresholdSeverity();
355 WORD getInstanceDiscoveryMethod() { return m_instanceDiscoveryMethod; }
356 const TCHAR *getInstanceDiscoveryData() { return m_instanceDiscoveryData; }
357 NXSL_VM *getInstanceFilter() { return m_instanceFilter; }
358 const TCHAR *getInstance() { return m_instance; }
359 int getSampleCount() { return m_sampleCount; }
360
361 void filterInstanceList(StringMap *instances);
362 void expandInstance();
363
364 virtual bool processNewValue(time_t nTimeStamp, const void *value, bool *updateStatus);
365 virtual void processNewError();
366
367 virtual bool hasValue();
368
369 void fillLastValueMessage(NXCPMessage *pMsg, UINT32 dwId);
370 NXSL_Value *getValueForNXSL(int nFunction, int nPolls);
371 NXSL_Value *getRawValueForNXSL();
372 const TCHAR *getLastValue();
373 ItemValue *getInternalLastValue();
374 TCHAR *getAggregateValue(AggregationFunction func, time_t periodStart, time_t periodEnd);
375
376 virtual void createMessage(NXCPMessage *pMsg);
377 #if defined(__SUNPRO_CC) || defined(__HP_aCC)
378 using DCObject::updateFromMessage;
379 #endif
380 void updateFromMessage(NXCPMessage *pMsg, UINT32 *pdwNumMaps, UINT32 **ppdwMapIndex, UINT32 **ppdwMapId);
381 void fillMessageWithThresholds(NXCPMessage *msg);
382
383 virtual void changeBinding(UINT32 dwNewId, Template *pNode, BOOL doMacroExpansion);
384
385 virtual void deleteExpiredData();
386 virtual bool deleteAllData();
387
388 virtual void getEventList(UINT32 **ppdwList, UINT32 *pdwSize);
389 virtual void createNXMPRecord(String &str);
390
391 int getThresholdCount() const { return (m_thresholds != NULL) ? m_thresholds->size() : 0; }
392 BOOL enumThresholds(BOOL (* pfCallback)(Threshold *, UINT32, void *), void *pArg);
393
394 void setInstance(const TCHAR *instance) { nx_strncpy(m_instance, instance, MAX_DB_STRING); }
395 void setDataType(int dataType) { m_dataType = dataType; }
396 void setDeltaCalcMethod(int method) { m_deltaCalculation = method; }
397 void setAllThresholdsFlag(BOOL bFlag) { if (bFlag) m_flags |= DCF_ALL_THRESHOLDS; else m_flags &= ~DCF_ALL_THRESHOLDS; }
398 void addThreshold(Threshold *pThreshold);
399 void deleteAllThresholds();
400 void setInstanceDiscoveryMethod(WORD method) { m_instanceDiscoveryMethod = method; }
401 void setInstanceDiscoveryData(const TCHAR *data) { safe_free(m_instanceDiscoveryData); m_instanceDiscoveryData = _tcsdup_ex(data); }
402 void setInstanceFilter(const TCHAR *pszScript);
403
404 static bool testTransformation(DataCollectionTarget *object, const TCHAR *script, const TCHAR *value, TCHAR *buffer, size_t bufSize);
405 };
406
407 /**
408 * Table column definition
409 */
410 class NXCORE_EXPORTABLE DCTableColumn
411 {
412 private:
413 TCHAR m_name[MAX_COLUMN_NAME];
414 TCHAR *m_displayName;
415 SNMP_ObjectId *m_snmpOid;
416 UINT16 m_flags;
417
418 public:
419 DCTableColumn(const DCTableColumn *src);
420 DCTableColumn(NXCPMessage *msg, UINT32 baseId);
421 DCTableColumn(DB_RESULT hResult, int row);
422 DCTableColumn(ConfigEntry *e);
423 ~DCTableColumn();
424
425 const TCHAR *getName() { return m_name; }
426 const TCHAR *getDisplayName() { return (m_displayName != NULL) ? m_displayName : m_name; }
427 UINT16 getFlags() { return m_flags; }
428 int getDataType() { return TCF_GET_DATA_TYPE(m_flags); }
429 int getAggregationFunction() { return TCF_GET_AGGREGATION_FUNCTION(m_flags); }
430 SNMP_ObjectId *getSnmpOid() { return m_snmpOid; }
431 bool isInstanceColumn() { return (m_flags & TCF_INSTANCE_COLUMN) != 0; }
432
433 void createNXMPRecord(String &str, int id);
434 };
435
436 /**
437 * Table column ID hash entry
438 */
439 struct TC_ID_MAP_ENTRY
440 {
441 INT32 id;
442 TCHAR name[MAX_COLUMN_NAME];
443 };
444
445 /**
446 * Condition for table DCI threshold
447 */
448 class NXCORE_EXPORTABLE DCTableCondition
449 {
450 private:
451 TCHAR *m_column;
452 int m_operation;
453 ItemValue m_value;
454
455 public:
456 DCTableCondition(const TCHAR *column, int operation, const TCHAR *value);
457 DCTableCondition(DCTableCondition *src);
458 ~DCTableCondition();
459
460 bool check(Table *value, int row);
461
462 const TCHAR *getColumn() { return m_column; }
463 int getOperation() { return m_operation; }
464 const TCHAR *getValue() { return m_value.getString(); }
465 };
466
467 /**
468 * Condition group for table DCI threshold
469 */
470 class NXCORE_EXPORTABLE DCTableConditionGroup
471 {
472 private:
473 ObjectArray<DCTableCondition> *m_conditions;
474
475 public:
476 DCTableConditionGroup();
477 DCTableConditionGroup(NXCPMessage *msg, UINT32 *baseId);
478 DCTableConditionGroup(DCTableConditionGroup *src);
479 DCTableConditionGroup(ConfigEntry *e);
480 ~DCTableConditionGroup();
481
482 bool check(Table *value, int row);
483
484 UINT32 fillMessage(NXCPMessage *msg, UINT32 baseId);
485
486 ObjectArray<DCTableCondition> *getConditions() { return m_conditions; }
487 };
488
489 /**
490 * Threshold definition for tabe DCI
491 */
492 class NXCORE_EXPORTABLE DCTableThreshold
493 {
494 private:
495 UINT32 m_id;
496 ObjectArray<DCTableConditionGroup> *m_groups;
497 UINT32 m_activationEvent;
498 UINT32 m_deactivationEvent;
499 StringSet *m_activeKeys;
500
501 void loadConditions();
502
503 public:
504 DCTableThreshold();
505 DCTableThreshold(DB_RESULT hResult, int row);
506 DCTableThreshold(NXCPMessage *msg, UINT32 *baseId);
507 DCTableThreshold(DCTableThreshold *src);
508 DCTableThreshold(ConfigEntry *e);
509 ~DCTableThreshold();
510
511 void copyState(DCTableThreshold *src);
512
513 ThresholdCheckResult check(Table *value, int row, const TCHAR *instance);
514
515 bool saveToDatabase(DB_HANDLE hdb, UINT32 tableId, int seq);
516 UINT32 fillMessage(NXCPMessage *msg, UINT32 baseId);
517 void createNXMPRecord(String &str, int id);
518
519 UINT32 getId() { return m_id; }
520 UINT32 getActivationEvent() { return m_activationEvent; }
521 UINT32 getDeactivationEvent() { return m_deactivationEvent; }
522 };
523
524 /**
525 * Tabular data collection object
526 */
527 class NXCORE_EXPORTABLE DCTable : public DCObject
528 {
529 protected:
530 ObjectArray<DCTableColumn> *m_columns;
531 ObjectArray<DCTableThreshold> *m_thresholds;
532 Table *m_lastValue;
533
534 static TC_ID_MAP_ENTRY *m_cache;
535 static int m_cacheSize;
536 static int m_cacheAllocated;
537 static MUTEX m_cacheMutex;
538
539 bool transform(Table *value);
540 void checkThresholds(Table *value);
541
542 bool loadThresholds();
543 bool saveThresholds(DB_HANDLE hdb);
544
545 public:
546 DCTable();
547 DCTable(const DCTable *src);
548 DCTable(UINT32 id, const TCHAR *name, int source, int pollingInterval, int retentionTime,
549 Template *node, const TCHAR *description = NULL, const TCHAR *systemTag = NULL);
550 DCTable(DB_RESULT hResult, int iRow, Template *pNode);
551 DCTable(ConfigEntry *config, Template *owner);
552 virtual ~DCTable();
553
554 virtual int getType() const { return DCO_TYPE_TABLE; }
555
556 virtual void updateFromTemplate(DCObject *dcObject);
557
558 virtual BOOL saveToDB(DB_HANDLE hdb);
559 virtual void deleteFromDatabase();
560
561 virtual bool processNewValue(time_t nTimeStamp, const void *value, bool *updateStatus);
562 virtual void processNewError();
563
564 virtual void createMessage(NXCPMessage *pMsg);
565 virtual void updateFromMessage(NXCPMessage *pMsg);
566
567 virtual void deleteExpiredData();
568 virtual bool deleteAllData();
569
570 virtual void createNXMPRecord(String &str);
571
572 void fillLastValueMessage(NXCPMessage *msg);
573 void fillLastValueSummaryMessage(NXCPMessage *pMsg, UINT32 dwId);
574
575 int getColumnDataType(const TCHAR *name);
576 ObjectArray<DCTableColumn> *getColumns() { return m_columns; }
577 Table *getLastValue();
578
579 void mergeValues(Table *dest, Table *src, int count);
580
581 void updateResultColumns(Table *t);
582
583 static INT32 columnIdFromName(const TCHAR *name);
584 };
585
586 /**
587 * Functions
588 */
589 BOOL InitDataCollector();
590 void DeleteAllItemsForNode(UINT32 dwNodeId);
591 void WriteFullParamListToMessage(NXCPMessage *pMsg, WORD flags);
592 int GetDCObjectType(UINT32 nodeId, UINT32 dciId);
593
594 void CalculateItemValueDiff(ItemValue &result, int nDataType, ItemValue &value1, ItemValue &value2);
595 void CalculateItemValueAverage(ItemValue &result, int nDataType, int nNumValues, ItemValue **ppValueList);
596 void CalculateItemValueMD(ItemValue &result, int nDataType, int nNumValues, ItemValue **ppValueList);
597 void CalculateItemValueTotal(ItemValue &result, int nDataType, int nNumValues, ItemValue **ppValueList);
598 void CalculateItemValueMin(ItemValue &result, int nDataType, int nNumValues, ItemValue **ppValueList);
599 void CalculateItemValueMax(ItemValue &result, int nDataType, int nNumValues, ItemValue **ppValueList);
600
601 /**
602 * Global variables
603 */
604 extern double g_dAvgPollerQueueSize;
605 extern double g_dAvgDBWriterQueueSize;
606 extern double g_dAvgIDataWriterQueueSize;
607 extern double g_dAvgRawDataWriterQueueSize;
608 extern double g_dAvgDBAndIDataWriterQueueSize;
609 extern double g_dAvgSyslogProcessingQueueSize;
610 extern double g_dAvgSyslogWriterQueueSize;
611 extern UINT32 g_dwAvgDCIQueuingTime;
612
613
614 #endif /* _nms_dcoll_h_ */