- Initial DCI transformation support on server side
[public/netxms.git] / src / server / core / nms_dcoll.h
CommitLineData
1275c750 1/*
07a45e04
VK
2** NetXMS - Network Management System
3** Copyright (C) 2003, 2004 Victor Kirhenshtein
1275c750
VK
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** $module: 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
35
3ea35b38
VK
36//
37// Threshold check results
38//
39
40#define THRESHOLD_REACHED 0
41#define THRESHOLD_REARMED 1
42#define NO_ACTION 2
43
44
333ece94
VK
45//
46// DCI value
47//
48
49class ItemValue
50{
51private:
52 double m_dFloat;
53 long m_iInt32;
54 INT64 m_iInt64;
55 DWORD m_dwInt32;
56 QWORD m_qwInt64;
57 char m_szString[MAX_DB_STRING];
58
59public:
60 ItemValue();
61 ItemValue(const char *pszValue);
62 ItemValue(const ItemValue *pValue);
63 ~ItemValue();
64
65 const char *String(void) { return m_szString; }
66
67 operator double() { return m_dFloat; }
68 operator DWORD() { return m_dwInt32; }
69 operator QWORD() { return m_qwInt64; }
70 operator long() { return m_iInt32; }
71 operator INT64() { return m_iInt64; }
72 operator const char*() const { return m_szString; }
73
74 const ItemValue& operator=(ItemValue &src);
75 const ItemValue& operator=(double dFloat);
76 const ItemValue& operator=(long iInt32);
77 const ItemValue& operator=(INT64 iInt64);
78 const ItemValue& operator=(DWORD dwInt32);
79 const ItemValue& operator=(QWORD qwInt64);
80};
81
82
3ea35b38
VK
83//
84// Threshold definition class
85//
86
87class DCItem;
88
89class Threshold
90{
91private:
92 DWORD m_dwId; // Unique threshold id
93 DWORD m_dwItemId; // Related item id
94 DWORD m_dwEventCode; // Event code to be generated
95 char *m_pszValueStr;
96 union
97 {
98 long iInteger;
521d90e7 99 INT64 qwInt64;
3ea35b38
VK
100 double dFloat;
101 } m_value;
102 BYTE m_iFunction; // Function code
103 BYTE m_iOperation; // Comparision operation code
104 BYTE m_iDataType; // Related item data type
105 int m_iParam1; // Function's parameter #1
106 int m_iParam2; // Function's parameter #2
107 BOOL m_bIsReached;
108
109public:
110 Threshold(DCItem *pRelatedItem);
111 Threshold(DB_RESULT hResult, int iRow, DCItem *pRelatedItem);
112 ~Threshold();
113
07a45e04 114 DWORD Id(void) { return m_dwId; }
3ea35b38
VK
115 DWORD EventCode(void) { return m_dwEventCode; }
116 const char *Value(void) { return m_pszValueStr; }
117 BOOL IsReached(void) { return m_bIsReached; }
118
06e7be2f 119 BOOL SaveToDB(DWORD dwIndex);
333ece94 120 int Check(ItemValue &value);
07a45e04
VK
121
122 void CreateMessage(DCI_THRESHOLD *pData);
123 void UpdateFromMessage(DCI_THRESHOLD *pData);
124
125 void CreateId(void);
3ea35b38
VK
126};
127
128
129//
130// Data collection item class
131//
132
133class Node;
134
135class DCItem
136{
137private:
138 DWORD m_dwId;
139 char m_szName[MAX_ITEM_NAME];
333ece94
VK
140 time_t m_tLastPoll; // Last poll time
141 int m_iPollingInterval; // Polling interval in seconds
142 int m_iRetentionTime; // Retention time in seconds
143 BYTE m_iDeltaCalculation; // Delta calculation method
144 BYTE m_iSource; // SNMP or native agent?
3ea35b38 145 BYTE m_iDataType;
333ece94
VK
146 BYTE m_iStatus; // Item status: active, disabled or not supported
147 BYTE m_iBusy; // 1 when item is queued for polling, 0 if not
148 DWORD m_dwTemplateId; // Related template's id
3ea35b38
VK
149 DWORD m_dwNumThresholds;
150 Threshold **m_ppThresholdList;
151 Node *m_pNode; // Pointer to node object this item related to
333ece94 152 char *m_pszFormula; // Transformation formula
07a45e04 153 MUTEX m_hMutex;
333ece94
VK
154 DWORD m_dwCacheSize; // Number of items in cache
155 ItemValue **m_ppValueCache;
156 ItemValue m_prevRawValue; // Previous raw value (used for delta calculation)
07a45e04
VK
157
158 void Lock(void) { MutexLock(m_hMutex, INFINITE); }
159 void Unlock(void) { MutexUnlock(m_hMutex); }
3ea35b38 160
333ece94
VK
161 void Transform(ItemValue &value);
162 void CheckThresholds(ItemValue &value);
163
3ea35b38
VK
164public:
165 DCItem();
166 DCItem(DB_RESULT hResult, int iRow, Node *pNode);
167 DCItem(DWORD dwId, char *szName, int iSource, int iDataType,
168 int iPollingInterval, int iRetentionTime, Node *pNode);
169 ~DCItem();
170
171 BOOL SaveToDB(void);
172 BOOL LoadThresholdsFromDB(void);
9ed4eaff 173 void DeleteFromDB(void);
3ea35b38
VK
174
175 DWORD Id(void) { return m_dwId; }
176 int DataSource(void) { return m_iSource; }
177 int DataType(void) { return m_iDataType; }
178 const char *Name(void) { return m_szName; }
5add75d8 179 Node *RelatedNode(void) { return m_pNode; }
3ea35b38
VK
180
181 BOOL ReadyForPolling(time_t currTime)
182 {
183 return ((m_iStatus == ITEM_STATUS_ACTIVE) && (!m_iBusy) &&
184 (m_tLastPoll + m_iPollingInterval < currTime));
185 }
186
5add75d8 187 void SetLastPollTime(time_t tLastPoll) { m_tLastPoll = tLastPoll; }
3ea35b38
VK
188 void SetStatus(int iStatus) { m_iStatus = (BYTE)iStatus; }
189 void SetBusyFlag(BOOL bIsBusy) { m_iBusy = (BYTE)bIsBusy; }
190
333ece94 191 void NewValue(DWORD dwTimeStamp, const char *pszValue);
7257eb7d
VK
192
193 void CreateMessage(CSCPMessage *pMsg);
07a45e04 194 void UpdateFromMessage(CSCPMessage *pMsg, DWORD *pdwNumMaps, DWORD **ppdwMapIndex, DWORD **ppdwMapId);
3ea35b38
VK
195};
196
197
1275c750
VK
198//
199// Functions
200//
201
202BOOL InitDataCollector(void);
203void DeleteAllItemsForNode(DWORD dwNodeId);
204
205
206#endif /* _nms_dcoll_h_ */