e44de6b9bdbdd044a215357b74bcba2bec3e765a
[public/netxms.git] / src / java / netxms-client / src / main / java / org / netxms / client / datacollection / DataCollectionItem.java
1 /**
2 * NetXMS - open source network management system
3 * Copyright (C) 2003-2012 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 package org.netxms.client.datacollection;
20
21 import java.util.ArrayList;
22
23 import org.netxms.base.NXCPCodes;
24 import org.netxms.base.NXCPMessage;
25
26 /**
27 * Data Collection Item representation
28 */
29 public class DataCollectionItem extends DataCollectionObject
30 {
31 // DCI specific flags
32 public static final int DCF_ALL_THRESHOLDS = 0x0002;
33 public static final int DCF_RAW_VALUE_OCTET_STRING = 0x0004;
34
35 // Delta calculation
36 public static final int DELTA_NONE = 0;
37 public static final int DELTA_SIMPLE = 1;
38 public static final int DELTA_AVERAGE_PER_SECOND = 2;
39 public static final int DELTA_AVERAGE_PER_MINUTE = 3;
40
41 // SNMP raw types for input transformation
42 public static final int SNMP_RAWTYPE_NONE = 0;
43 public static final int SNMP_RAWTYPE_INT32 = 1;
44 public static final int SNMP_RAWTYPE_UINT32 = 2;
45 public static final int SNMP_RAWTYPE_INT64 = 3;
46 public static final int SNMP_RAWTYPE_UINT64 = 4;
47 public static final int SNMP_RAWTYPE_DOUBLE = 5;
48 public static final int SNMP_RAWTYPE_IP_ADDR = 6;
49 public static final int SNMP_RAWTYPE_MAC_ADDR = 7;
50
51 // Instance discovery methods
52 public static final int IDM_NONE = 0;
53 public static final int IDM_AGENT_LIST = 1;
54 public static final int IDM_AGENT_TABLE = 2;
55 public static final int IDM_SNMP_WALK_VALUES = 3;
56 public static final int IDM_SNMP_WALK_OIDS = 4;
57
58 private int dataType;
59 private int deltaCalculation;
60 private String transformationScript;
61 private String instance;
62 private int baseUnits;
63 private int multiplier;
64 private String customUnitName;
65 private int snmpRawValueType;
66 private ArrayList<Threshold> thresholds;
67 private int instanceDiscoveryMethod;
68 private String instanceDiscoveryData;
69 private String instanceDiscoveryFilter;
70
71 /**
72 * Create data collection item object from NXCP message
73 *
74 * @param owner Owning configuration object
75 * @param msg NXCP message
76 */
77 protected DataCollectionItem(final DataCollectionConfiguration owner, final NXCPMessage msg)
78 {
79 super(owner, msg);
80
81 dataType = msg.getVariableAsInteger(NXCPCodes.VID_DCI_DATA_TYPE);
82 deltaCalculation = msg.getVariableAsInteger(NXCPCodes.VID_DCI_DELTA_CALCULATION);
83 transformationScript = msg.getVariableAsString(NXCPCodes.VID_TRANSFORMATION_SCRIPT);
84 instance = msg.getVariableAsString(NXCPCodes.VID_INSTANCE);
85 baseUnits = msg.getVariableAsInteger(NXCPCodes.VID_BASE_UNITS);
86 multiplier = msg.getVariableAsInteger(NXCPCodes.VID_MULTIPLIER);
87 customUnitName = msg.getVariableAsString(NXCPCodes.VID_CUSTOM_UNITS_NAME);
88 snmpRawValueType = msg.getVariableAsInteger(NXCPCodes.VID_SNMP_RAW_VALUE_TYPE);
89 instanceDiscoveryMethod = msg.getVariableAsInteger(NXCPCodes.VID_INSTD_METHOD);
90 instanceDiscoveryData = msg.getVariableAsString(NXCPCodes.VID_INSTD_DATA);
91 instanceDiscoveryFilter = msg.getVariableAsString(NXCPCodes.VID_INSTD_FILTER);
92
93 int count = msg.getVariableAsInteger(NXCPCodes.VID_NUM_THRESHOLDS);
94 thresholds = new ArrayList<Threshold>(count);
95 long varId = NXCPCodes.VID_DCI_THRESHOLD_BASE;
96 for(int i = 0; i < count; i++, varId += 20)
97 {
98 thresholds.add(new Threshold(msg, varId));
99 }
100 }
101
102 /**
103 * Constructor for new data collection items.
104 *
105 * @param owner Owning configuration object
106 * @param id Identifier assigned to new item
107 */
108 protected DataCollectionItem(final DataCollectionConfiguration owner, long id)
109 {
110 super(owner, id);
111
112 dataType = DT_INT;
113 deltaCalculation = DELTA_NONE;
114 transformationScript = null;
115 instance = "";
116 baseUnits = 0;
117 multiplier = 0;
118 customUnitName = null;
119 snmpRawValueType = SNMP_RAWTYPE_NONE;
120 thresholds = new ArrayList<Threshold>(0);
121 }
122
123 /**
124 * Fill NXCP message with item's data.
125 *
126 * @param msg NXCP message
127 */
128 public void fillMessage(final NXCPMessage msg)
129 {
130 super.fillMessage(msg);
131
132 msg.setVariableInt16(NXCPCodes.VID_DCOBJECT_TYPE, DCO_TYPE_ITEM);
133 msg.setVariableInt16(NXCPCodes.VID_DCI_DATA_TYPE, dataType);
134 msg.setVariableInt16(NXCPCodes.VID_DCI_DELTA_CALCULATION, deltaCalculation);
135 msg.setVariable(NXCPCodes.VID_INSTANCE, instance);
136 msg.setVariable(NXCPCodes.VID_TRANSFORMATION_SCRIPT, transformationScript);
137 msg.setVariableInt16(NXCPCodes.VID_SNMP_RAW_VALUE_TYPE, snmpRawValueType);
138 msg.setVariableInt16(NXCPCodes.VID_BASE_UNITS, baseUnits);
139 msg.setVariableInt32(NXCPCodes.VID_MULTIPLIER, multiplier);
140 if (customUnitName != null)
141 msg.setVariable(NXCPCodes.VID_CUSTOM_UNITS_NAME, customUnitName);
142
143 msg.setVariableInt16(NXCPCodes.VID_INSTD_METHOD, instanceDiscoveryMethod);
144 if (instanceDiscoveryData != null)
145 msg.setVariable(NXCPCodes.VID_INSTD_DATA, instanceDiscoveryData);
146 if (instanceDiscoveryFilter != null)
147 msg.setVariable(NXCPCodes.VID_INSTD_FILTER, instanceDiscoveryFilter);
148
149 msg.setVariableInt32(NXCPCodes.VID_NUM_THRESHOLDS, thresholds.size());
150 long varId = NXCPCodes.VID_DCI_THRESHOLD_BASE;
151 for(int i = 0; i < thresholds.size(); i++, varId +=10)
152 {
153 thresholds.get(i).fillMessage(msg, varId);
154 }
155 }
156
157 /**
158 * @return the dataType
159 */
160 public int getDataType()
161 {
162 return dataType;
163 }
164
165 /**
166 * @param dataType the dataType to set
167 */
168 public void setDataType(int dataType)
169 {
170 this.dataType = dataType;
171 }
172
173 /**
174 * @return the deltaCalculation
175 */
176 public int getDeltaCalculation()
177 {
178 return deltaCalculation;
179 }
180
181 /**
182 * @param deltaCalculation the deltaCalculation to set
183 */
184 public void setDeltaCalculation(int deltaCalculation)
185 {
186 this.deltaCalculation = deltaCalculation;
187 }
188
189 /**
190 * @return the processAllThresholds
191 */
192 public boolean isProcessAllThresholds()
193 {
194 return (flags & DCF_ALL_THRESHOLDS) != 0;
195 }
196
197 /**
198 * @param processAllThresholds the processAllThresholds to set
199 */
200 public void setProcessAllThresholds(boolean processAllThresholds)
201 {
202 if (processAllThresholds)
203 flags |= DCF_ALL_THRESHOLDS;
204 else
205 flags &= ~DCF_ALL_THRESHOLDS;
206 }
207
208 /**
209 * @return State of DCF_RAW_VALUE_OCTET_STRING flag
210 */
211 public boolean isSnmpRawValueInOctetString()
212 {
213 return (flags & DCF_RAW_VALUE_OCTET_STRING) != 0;
214 }
215
216 /**
217 * Set state of DCF_RAW_VALUE_OCTET_STRING flag
218 *
219 * @param enable
220 */
221 public void setSnmpRawValueInOctetString(boolean enable)
222 {
223 if (enable)
224 flags |= DCF_RAW_VALUE_OCTET_STRING;
225 else
226 flags &= ~DCF_RAW_VALUE_OCTET_STRING;
227 }
228
229 /**
230 * @return the transformationScript
231 */
232 public String getTransformationScript()
233 {
234 return transformationScript;
235 }
236
237 /**
238 * @param transformationScript the transformationScript to set
239 */
240 public void setTransformationScript(String transformationScript)
241 {
242 this.transformationScript = transformationScript;
243 }
244
245 /**
246 * @return the instance
247 */
248 public String getInstance()
249 {
250 return instance;
251 }
252
253 /**
254 * @param instance the instance to set
255 */
256 public void setInstance(String instance)
257 {
258 this.instance = instance;
259 }
260
261 /**
262 * @return the baseUnits
263 */
264 public int getBaseUnits()
265 {
266 return baseUnits;
267 }
268
269 /**
270 * @param baseUnits the baseUnits to set
271 */
272 public void setBaseUnits(int baseUnits)
273 {
274 this.baseUnits = baseUnits;
275 }
276
277 /**
278 * @return the multiplier
279 */
280 public int getMultiplier()
281 {
282 return multiplier;
283 }
284
285 /**
286 * @param multiplier the multiplier to set
287 */
288 public void setMultiplier(int multiplier)
289 {
290 this.multiplier = multiplier;
291 }
292
293 /**
294 * @return the customUnitName
295 */
296 public String getCustomUnitName()
297 {
298 return customUnitName;
299 }
300
301 /**
302 * @param customUnitName the customUnitName to set
303 */
304 public void setCustomUnitName(String customUnitName)
305 {
306 this.customUnitName = customUnitName;
307 }
308
309 /**
310 * @return the thresholds
311 */
312 public ArrayList<Threshold> getThresholds()
313 {
314 return thresholds;
315 }
316
317 /**
318 * @return the snmpRawValueType
319 */
320 public int getSnmpRawValueType()
321 {
322 return snmpRawValueType;
323 }
324
325 /**
326 * @param snmpRawValueType the snmpRawValueType to set
327 */
328 public void setSnmpRawValueType(int snmpRawValueType)
329 {
330 this.snmpRawValueType = snmpRawValueType;
331 }
332
333 /**
334 * @return the instanceDiscoveryMethod
335 */
336 public final int getInstanceDiscoveryMethod()
337 {
338 return instanceDiscoveryMethod;
339 }
340
341 /**
342 * @param instanceDiscoveryMethod the instanceDiscoveryMethod to set
343 */
344 public final void setInstanceDiscoveryMethod(int instanceDiscoveryMethod)
345 {
346 this.instanceDiscoveryMethod = instanceDiscoveryMethod;
347 }
348
349 /**
350 * @return the instanceDiscoveryData
351 */
352 public final String getInstanceDiscoveryData()
353 {
354 return instanceDiscoveryData;
355 }
356
357 /**
358 * @param instanceDiscoveryData the instanceDiscoveryData to set
359 */
360 public final void setInstanceDiscoveryData(String instanceDiscoveryData)
361 {
362 this.instanceDiscoveryData = instanceDiscoveryData;
363 }
364
365 /**
366 * @return the instanceDiscoveryFilter
367 */
368 public final String getInstanceDiscoveryFilter()
369 {
370 return instanceDiscoveryFilter;
371 }
372
373 /**
374 * @param instanceDiscoveryFilter the instanceDiscoveryFilter to set
375 */
376 public final void setInstanceDiscoveryFilter(String instanceDiscoveryFilter)
377 {
378 this.instanceDiscoveryFilter = instanceDiscoveryFilter;
379 }
380 }