Commit | Line | Data |
---|---|---|
23015e41 | 1 | /* |
5039dede | 2 | ** NetXMS - Network Management System |
7638efb1 | 3 | ** Copyright (C) 2003-2016 Victor Kirhenshtein |
5039dede AK |
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: nxsl_classes.cpp | |
20 | ** | |
21 | **/ | |
22 | ||
23 | #include "nxcore.h" | |
24 | ||
63e99e56 VK |
25 | /** |
26 | * clearGeoLocation() | |
27 | */ | |
28 | NXSL_METHOD_DEFINITION(NetObj, clearGeoLocation) | |
29 | { | |
30 | ((NetObj *)object->getData())->setGeoLocation(GeoLocation()); | |
31 | *result = new NXSL_Value; | |
32 | return 0; | |
33 | } | |
34 | ||
35 | /** | |
36 | * setGeoLocation(loc) | |
37 | */ | |
38 | NXSL_METHOD_DEFINITION(NetObj, setGeoLocation) | |
39 | { | |
40 | if (!argv[0]->isObject()) | |
41 | return NXSL_ERR_NOT_OBJECT; | |
42 | ||
43 | NXSL_Object *o = argv[0]->getValueAsObject(); | |
44 | if (_tcscmp(o->getClass()->getName(), g_nxslGeoLocationClass.getName())) | |
45 | return NXSL_ERR_BAD_CLASS; | |
46 | ||
47 | GeoLocation *gl = (GeoLocation *)o->getData(); | |
48 | ((NetObj *)object->getData())->setGeoLocation(*gl); | |
49 | *result = new NXSL_Value; | |
50 | return 0; | |
51 | } | |
52 | ||
d67faad5 VK |
53 | /** |
54 | * setStatusCalculation(type, ...) | |
55 | */ | |
63e99e56 | 56 | NXSL_METHOD_DEFINITION(NetObj, setStatusCalculation) |
d67faad5 VK |
57 | { |
58 | if (argc < 1) | |
59 | return NXSL_ERR_INVALID_ARGUMENT_COUNT; | |
60 | ||
61 | if (!argv[0]->isInteger()) | |
62 | return NXSL_ERR_NOT_INTEGER; | |
63 | ||
64 | INT32 success = 1; | |
65 | int method = argv[0]->getValueAsInt32(); | |
66 | NetObj *netobj = (NetObj *)object->getData(); | |
67 | switch(method) | |
68 | { | |
69 | case SA_CALCULATE_DEFAULT: | |
70 | case SA_CALCULATE_MOST_CRITICAL: | |
71 | netobj->setStatusCalculation(method); | |
72 | break; | |
73 | case SA_CALCULATE_SINGLE_THRESHOLD: | |
74 | if (argc < 2) | |
75 | return NXSL_ERR_INVALID_ARGUMENT_COUNT; | |
76 | if (!argv[1]->isInteger()) | |
77 | return NXSL_ERR_NOT_INTEGER; | |
78 | netobj->setStatusCalculation(method, argv[1]->getValueAsInt32()); | |
79 | break; | |
80 | case SA_CALCULATE_MULTIPLE_THRESHOLDS: | |
81 | if (argc < 5) | |
82 | return NXSL_ERR_INVALID_ARGUMENT_COUNT; | |
83 | for(int i = 1; i <= 4; i++) | |
84 | { | |
85 | if (!argv[i]->isInteger()) | |
86 | return NXSL_ERR_NOT_INTEGER; | |
87 | } | |
88 | netobj->setStatusCalculation(method, argv[1]->getValueAsInt32(), argv[2]->getValueAsInt32(), argv[3]->getValueAsInt32(), argv[4]->getValueAsInt32()); | |
89 | break; | |
90 | default: | |
91 | success = 0; // invalid method | |
92 | break; | |
93 | } | |
94 | *result = new NXSL_Value(success); | |
95 | return 0; | |
96 | } | |
97 | ||
98 | /** | |
99 | * setStatusPropagation(type, ...) | |
100 | */ | |
63e99e56 | 101 | NXSL_METHOD_DEFINITION(NetObj, setStatusPropagation) |
d67faad5 VK |
102 | { |
103 | if (argc < 1) | |
104 | return NXSL_ERR_INVALID_ARGUMENT_COUNT; | |
105 | ||
106 | if (!argv[0]->isInteger()) | |
107 | return NXSL_ERR_NOT_INTEGER; | |
108 | ||
109 | INT32 success = 1; | |
110 | int method = argv[0]->getValueAsInt32(); | |
111 | NetObj *netobj = (NetObj *)object->getData(); | |
112 | switch(method) | |
113 | { | |
114 | case SA_PROPAGATE_DEFAULT: | |
115 | case SA_PROPAGATE_UNCHANGED: | |
116 | netobj->setStatusPropagation(method); | |
117 | break; | |
118 | case SA_PROPAGATE_FIXED: | |
119 | case SA_PROPAGATE_RELATIVE: | |
120 | if (argc < 2) | |
121 | return NXSL_ERR_INVALID_ARGUMENT_COUNT; | |
122 | if (!argv[1]->isInteger()) | |
123 | return NXSL_ERR_NOT_INTEGER; | |
124 | netobj->setStatusPropagation(method, argv[1]->getValueAsInt32()); | |
125 | break; | |
126 | case SA_PROPAGATE_TRANSLATED: | |
127 | if (argc < 5) | |
128 | return NXSL_ERR_INVALID_ARGUMENT_COUNT; | |
129 | for(int i = 1; i <= 4; i++) | |
130 | { | |
131 | if (!argv[i]->isInteger()) | |
132 | return NXSL_ERR_NOT_INTEGER; | |
133 | } | |
134 | netobj->setStatusPropagation(method, argv[1]->getValueAsInt32(), argv[2]->getValueAsInt32(), argv[3]->getValueAsInt32(), argv[4]->getValueAsInt32()); | |
135 | break; | |
136 | default: | |
137 | success = 0; // invalid method | |
138 | break; | |
139 | } | |
140 | *result = new NXSL_Value(success); | |
141 | return 0; | |
142 | } | |
143 | ||
21c9acce | 144 | /** |
484e609d | 145 | * NXSL class NetObj: constructor |
21c9acce VK |
146 | */ |
147 | NXSL_NetObjClass::NXSL_NetObjClass() : NXSL_Class() | |
541a3ebc | 148 | { |
c42b4551 | 149 | _tcscpy(m_name, _T("NetObj")); |
d67faad5 | 150 | |
63e99e56 VK |
151 | NXSL_REGISTER_METHOD(NetObj, clearGeoLocation, 0); |
152 | NXSL_REGISTER_METHOD(NetObj, setGeoLocation, 1); | |
153 | NXSL_REGISTER_METHOD(NetObj, setStatusCalculation, -1); | |
154 | NXSL_REGISTER_METHOD(NetObj, setStatusPropagation, -1); | |
541a3ebc VK |
155 | } |
156 | ||
484e609d VK |
157 | /** |
158 | * NXSL class NetObj: get attribute | |
159 | */ | |
ca594353 | 160 | NXSL_Value *NXSL_NetObjClass::getAttr(NXSL_Object *_object, const TCHAR *attr) |
541a3ebc | 161 | { |
ca594353 VK |
162 | NXSL_Value *value = NULL; |
163 | NetObj *object = (NetObj *)_object->getData(); | |
164 | if (!_tcscmp(attr, _T("name"))) | |
541a3ebc | 165 | { |
ca594353 | 166 | value = new NXSL_Value(object->getName()); |
541a3ebc | 167 | } |
ca594353 | 168 | else if (!_tcscmp(attr, _T("id"))) |
541a3ebc | 169 | { |
ca594353 | 170 | value = new NXSL_Value(object->getId()); |
541a3ebc | 171 | } |
ca594353 | 172 | else if (!_tcscmp(attr, _T("guid"))) |
9b3015b8 | 173 | { |
de4af576 | 174 | TCHAR buffer[64]; |
ca594353 | 175 | value = new NXSL_Value(object->getGuid().toString(buffer)); |
9b3015b8 | 176 | } |
ca594353 | 177 | else if (!_tcscmp(attr, _T("status"))) |
541a3ebc | 178 | { |
db091a1f | 179 | value = new NXSL_Value((LONG)object->getStatus()); |
541a3ebc | 180 | } |
ca594353 | 181 | else if (!_tcscmp(attr, _T("ipAddr"))) |
541a3ebc | 182 | { |
c75e9ee4 | 183 | TCHAR buffer[64]; |
c30c0c0f | 184 | GetObjectIpAddress(object).toString(buffer); |
ca594353 VK |
185 | value = new NXSL_Value(buffer); |
186 | } | |
187 | else if (!_tcscmp(attr, _T("type"))) | |
188 | { | |
189 | value = new NXSL_Value((LONG)object->getObjectClass()); | |
541a3ebc | 190 | } |
ca594353 | 191 | else if (!_tcscmp(attr, _T("comments"))) |
541a3ebc | 192 | { |
ca594353 | 193 | value = new NXSL_Value(object->getComments()); |
74fde582 | 194 | } |
ca594353 | 195 | else if (!_tcscmp(attr, _T("customAttributes"))) |
74fde582 | 196 | { |
ca594353 | 197 | value = object->getCustomAttributesForNXSL(); |
56fa1092 | 198 | } |
ca594353 | 199 | else if (!_tcscmp(attr, _T("country"))) |
56fa1092 | 200 | { |
ca594353 | 201 | value = new NXSL_Value(object->getPostalAddress()->getCountry()); |
56fa1092 | 202 | } |
ca594353 | 203 | else if (!_tcscmp(attr, _T("city"))) |
56fa1092 | 204 | { |
ca594353 | 205 | value = new NXSL_Value(object->getPostalAddress()->getCity()); |
56fa1092 | 206 | } |
ca594353 | 207 | else if (!_tcscmp(attr, _T("geolocation"))) |
63e99e56 | 208 | { |
ca594353 | 209 | value = new NXSL_Value(new NXSL_Object(&g_nxslGeoLocationClass, new GeoLocation(object->getGeoLocation()))); |
63e99e56 | 210 | } |
ca594353 | 211 | else if (!_tcscmp(attr, _T("streetAddress"))) |
56fa1092 | 212 | { |
ca594353 | 213 | value = new NXSL_Value(object->getPostalAddress()->getStreetAddress()); |
56fa1092 | 214 | } |
ca594353 | 215 | else if (!_tcscmp(attr, _T("postcode"))) |
56fa1092 | 216 | { |
ca594353 | 217 | value = new NXSL_Value(object->getPostalAddress()->getPostCode()); |
541a3ebc VK |
218 | } |
219 | else | |
220 | { | |
ca594353 | 221 | const TCHAR *attrValue = object->getCustomAttribute(attr); |
541a3ebc VK |
222 | if (attrValue != NULL) |
223 | { | |
ca594353 | 224 | value = new NXSL_Value(attrValue); |
541a3ebc VK |
225 | } |
226 | } | |
ca594353 | 227 | return value; |
541a3ebc VK |
228 | } |
229 | ||
fe400f32 VK |
230 | /** |
231 | * NXSL class Zone: constructor | |
232 | */ | |
ca594353 | 233 | NXSL_ZoneClass::NXSL_ZoneClass() : NXSL_NetObjClass() |
fe400f32 | 234 | { |
c42b4551 | 235 | _tcscpy(m_name, _T("Zone")); |
fe400f32 VK |
236 | } |
237 | ||
238 | /** | |
239 | * NXSL class Zone: get attribute | |
240 | */ | |
ca594353 | 241 | NXSL_Value *NXSL_ZoneClass::getAttr(NXSL_Object *object, const TCHAR *attr) |
fe400f32 | 242 | { |
ca594353 VK |
243 | NXSL_Value *value = NXSL_NetObjClass::getAttr(object, attr); |
244 | if (value != NULL) | |
245 | return value; | |
246 | ||
247 | Zone *zone = (Zone *)object->getData(); | |
43b62436 | 248 | if (!_tcscmp(attr, _T("proxyNode"))) |
fe400f32 | 249 | { |
43b62436 VK |
250 | Node *node = (Node *)FindObjectById(zone->getProxyNodeId(), OBJECT_NODE); |
251 | value = (node != NULL) ? new NXSL_Value(new NXSL_Object(&g_nxslNodeClass, node)) : new NXSL_Value(); | |
fe400f32 | 252 | } |
43b62436 | 253 | else if (!_tcscmp(attr, _T("proxyNodeId"))) |
fe400f32 | 254 | { |
43b62436 | 255 | value = new NXSL_Value(zone->getProxyNodeId()); |
56fa1092 | 256 | } |
ca594353 | 257 | else if (!_tcscmp(attr, _T("zoneId"))) |
fe400f32 | 258 | { |
ca594353 | 259 | value = new NXSL_Value(zone->getZoneId()); |
fe400f32 | 260 | } |
ca594353 | 261 | return value; |
fe400f32 VK |
262 | } |
263 | ||
484e609d VK |
264 | /** |
265 | * Generic implementation for flag changing methods | |
266 | */ | |
267 | static int ChangeFlagMethod(NXSL_Object *object, NXSL_Value *arg, NXSL_Value **result, UINT32 flag) | |
268 | { | |
269 | if (!arg->isInteger()) | |
270 | return NXSL_ERR_NOT_INTEGER; | |
271 | ||
272 | Node *node = (Node *)object->getData(); | |
273 | if (arg->getValueAsInt32()) | |
274 | node->clearFlag(flag); | |
275 | else | |
276 | node->setFlag(flag); | |
277 | ||
278 | *result = new NXSL_Value; | |
279 | return 0; | |
280 | } | |
281 | ||
282 | /** | |
283 | * enableAgent(enabled) method | |
284 | */ | |
63e99e56 | 285 | NXSL_METHOD_DEFINITION(Node, enableAgent) |
484e609d VK |
286 | { |
287 | return ChangeFlagMethod(object, argv[0], result, NF_DISABLE_NXCP); | |
288 | } | |
289 | ||
290 | /** | |
291 | * enableConfigurationPolling(enabled) method | |
292 | */ | |
63e99e56 | 293 | NXSL_METHOD_DEFINITION(Node, enableConfigurationPolling) |
484e609d VK |
294 | { |
295 | return ChangeFlagMethod(object, argv[0], result, NF_DISABLE_CONF_POLL); | |
296 | } | |
297 | ||
3f419209 VK |
298 | /** |
299 | * enableDiscoveryPolling(enabled) method | |
300 | */ | |
301 | NXSL_METHOD_DEFINITION(Node, enableDiscoveryPolling) | |
302 | { | |
303 | return ChangeFlagMethod(object, argv[0], result, NF_DISABLE_DISCOVERY_POLL); | |
304 | } | |
305 | ||
484e609d VK |
306 | /** |
307 | * enableIcmp(enabled) method | |
308 | */ | |
63e99e56 | 309 | NXSL_METHOD_DEFINITION(Node, enableIcmp) |
484e609d VK |
310 | { |
311 | return ChangeFlagMethod(object, argv[0], result, NF_DISABLE_ICMP); | |
312 | } | |
313 | ||
314 | /** | |
315 | * enableSnmp(enabled) method | |
316 | */ | |
63e99e56 | 317 | NXSL_METHOD_DEFINITION(Node, enableSnmp) |
484e609d VK |
318 | { |
319 | return ChangeFlagMethod(object, argv[0], result, NF_DISABLE_SNMP); | |
320 | } | |
321 | ||
322 | /** | |
323 | * enableStatusPolling(enabled) method | |
324 | */ | |
63e99e56 | 325 | NXSL_METHOD_DEFINITION(Node, enableStatusPolling) |
484e609d VK |
326 | { |
327 | return ChangeFlagMethod(object, argv[0], result, NF_DISABLE_STATUS_POLL); | |
328 | } | |
541a3ebc | 329 | |
484e609d VK |
330 | /** |
331 | * enableTopologyPolling(enabled) method | |
332 | */ | |
63e99e56 | 333 | NXSL_METHOD_DEFINITION(Node, enableTopologyPolling) |
484e609d VK |
334 | { |
335 | return ChangeFlagMethod(object, argv[0], result, NF_DISABLE_TOPOLOGY_POLL); | |
336 | } | |
5039dede | 337 | |
484e609d VK |
338 | /** |
339 | * NXSL class Node: constructor | |
340 | */ | |
ca594353 | 341 | NXSL_NodeClass::NXSL_NodeClass() : NXSL_NetObjClass() |
5039dede | 342 | { |
c42b4551 | 343 | _tcscpy(m_name, _T("Node")); |
484e609d | 344 | |
63e99e56 VK |
345 | NXSL_REGISTER_METHOD(Node, enableAgent, 1); |
346 | NXSL_REGISTER_METHOD(Node, enableConfigurationPolling, 1); | |
3f419209 | 347 | NXSL_REGISTER_METHOD(Node, enableDiscoveryPolling, 1); |
63e99e56 VK |
348 | NXSL_REGISTER_METHOD(Node, enableIcmp, 1); |
349 | NXSL_REGISTER_METHOD(Node, enableSnmp, 1); | |
350 | NXSL_REGISTER_METHOD(Node, enableStatusPolling, 1); | |
351 | NXSL_REGISTER_METHOD(Node, enableTopologyPolling, 1); | |
5039dede AK |
352 | } |
353 | ||
484e609d VK |
354 | /** |
355 | * NXSL class Node: get attribute | |
356 | */ | |
ca594353 | 357 | NXSL_Value *NXSL_NodeClass::getAttr(NXSL_Object *object, const TCHAR *attr) |
5039dede | 358 | { |
ca594353 VK |
359 | NXSL_Value *value = NXSL_NetObjClass::getAttr(object, attr); |
360 | if (value != NULL) | |
361 | return value; | |
5039dede | 362 | |
ca594353 VK |
363 | Node *node = (Node *)object->getData(); |
364 | if (!_tcscmp(attr, _T("agentVersion"))) | |
5039dede | 365 | { |
ca594353 | 366 | value = new NXSL_Value(node->getAgentVersion()); |
5039dede | 367 | } |
ca594353 | 368 | else if (!_tcscmp(attr, _T("bootTime"))) |
71e4ed3a | 369 | { |
ca594353 | 370 | value = new NXSL_Value((INT64)node->getBootTime()); |
71e4ed3a | 371 | } |
ca594353 | 372 | else if (!_tcscmp(attr, _T("bridgeBaseAddress"))) |
64909a13 VK |
373 | { |
374 | TCHAR buffer[64]; | |
ca594353 | 375 | value = new NXSL_Value(BinToStr(node->getBridgeId(), MAC_ADDR_LENGTH, buffer)); |
64909a13 | 376 | } |
ca594353 | 377 | else if (!_tcscmp(attr, _T("driver"))) |
56fa1092 | 378 | { |
ca594353 | 379 | value = new NXSL_Value(node->getDriverName()); |
56fa1092 | 380 | } |
ca594353 | 381 | else if (!_tcscmp(attr, _T("flags"))) |
5039dede | 382 | { |
ca594353 | 383 | value = new NXSL_Value(node->getFlags()); |
707b18df | 384 | } |
ca594353 | 385 | else if (!_tcscmp(attr, _T("isAgent"))) |
56fa1092 | 386 | { |
ca594353 | 387 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_NATIVE_AGENT) ? 1 : 0)); |
56fa1092 | 388 | } |
ca594353 | 389 | else if (!_tcscmp(attr, _T("isBridge"))) |
9c170b20 | 390 | { |
ca594353 | 391 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_BRIDGE) ? 1 : 0)); |
9c170b20 | 392 | } |
ca594353 | 393 | else if (!_tcscmp(attr, _T("isCDP"))) |
707b18df | 394 | { |
ca594353 | 395 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_CDP) ? 1 : 0)); |
5039dede | 396 | } |
ca594353 | 397 | else if (!_tcscmp(attr, _T("isLLDP"))) |
63e99e56 | 398 | { |
ca594353 | 399 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_LLDP) ? 1 : 0)); |
63e99e56 | 400 | } |
ca594353 | 401 | else if (!_tcscmp(attr, _T("isLocalMgmt")) || !_tcscmp(attr, _T("isLocalManagement"))) |
6a7bf4f6 | 402 | { |
ca594353 | 403 | value = new NXSL_Value((LONG)((node->isLocalManagement()) ? 1 : 0)); |
6a7bf4f6 | 404 | } |
ca594353 | 405 | else if (!_tcscmp(attr, _T("isPAE")) || !_tcscmp(attr, _T("is802_1x"))) |
6a7bf4f6 | 406 | { |
ca594353 | 407 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_8021X) ? 1 : 0)); |
5039dede | 408 | } |
ca594353 | 409 | else if (!_tcscmp(attr, _T("isPrinter"))) |
5039dede | 410 | { |
ca594353 | 411 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_PRINTER) ? 1 : 0)); |
5039dede | 412 | } |
ca594353 | 413 | else if (!_tcscmp(attr, _T("isRouter"))) |
5039dede | 414 | { |
ca594353 | 415 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_ROUTER) ? 1 : 0)); |
5039dede | 416 | } |
ca594353 | 417 | else if (!_tcscmp(attr, _T("isSMCLP"))) |
5039dede | 418 | { |
ca594353 | 419 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_SMCLP) ? 1 : 0)); |
5039dede | 420 | } |
ca594353 | 421 | else if (!_tcscmp(attr, _T("isSNMP"))) |
5039dede | 422 | { |
ca594353 | 423 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_SNMP) ? 1 : 0)); |
5039dede | 424 | } |
ca594353 | 425 | else if (!_tcscmp(attr, _T("isSONMP"))) |
d8ca56d5 | 426 | { |
ca594353 | 427 | value = new NXSL_Value((LONG)((node->getFlags() & NF_IS_SONMP) ? 1 : 0)); |
d8ca56d5 | 428 | } |
ca594353 | 429 | else if (!_tcscmp(attr, _T("platformName"))) |
5039dede | 430 | { |
ca594353 | 431 | value = new NXSL_Value(node->getPlatformName()); |
707b18df | 432 | } |
e4926628 VK |
433 | else if (!_tcscmp(attr, _T("rack"))) |
434 | { | |
435 | Rack *rack = (Rack *)FindObjectById(node->getRackId(), OBJECT_RACK); | |
436 | if (rack != NULL) | |
437 | { | |
438 | value = rack->createNXSLObject(); | |
439 | } | |
440 | else | |
441 | { | |
442 | value = new NXSL_Value; | |
443 | } | |
444 | } | |
445 | else if (!_tcscmp(attr, _T("rackId"))) | |
446 | { | |
447 | value = new NXSL_Value(node->getRackId()); | |
448 | } | |
449 | else if (!_tcscmp(attr, _T("rackHeight"))) | |
450 | { | |
451 | value = new NXSL_Value(node->getRackHeight()); | |
452 | } | |
453 | else if (!_tcscmp(attr, _T("rackPosition"))) | |
454 | { | |
455 | value = new NXSL_Value(node->getRackPosition()); | |
456 | } | |
ca594353 | 457 | else if (!_tcscmp(attr, _T("runtimeFlags"))) |
707b18df | 458 | { |
ca594353 | 459 | value = new NXSL_Value(node->getRuntimeFlags()); |
5039dede | 460 | } |
ca594353 | 461 | else if (!_tcscmp(attr, _T("snmpOID"))) |
56fa1092 | 462 | { |
ca594353 | 463 | value = new NXSL_Value(node->getSNMPObjectId()); |
56fa1092 | 464 | } |
ca594353 | 465 | else if (!_tcscmp(attr, _T("snmpSysContact"))) |
dc679178 | 466 | { |
ca594353 | 467 | value = new NXSL_Value(node->getSysContact()); |
dc679178 | 468 | } |
ca594353 | 469 | else if (!_tcscmp(attr, _T("snmpSysLocation"))) |
5039dede | 470 | { |
ca594353 | 471 | value = new NXSL_Value(node->getSysLocation()); |
5039dede | 472 | } |
ca594353 | 473 | else if (!_tcscmp(attr, _T("snmpSysName"))) |
cf38357f | 474 | { |
ca594353 | 475 | value = new NXSL_Value(node->getSysName()); |
cf38357f | 476 | } |
ca594353 | 477 | else if (!_tcscmp(attr, _T("snmpVersion"))) |
cf38357f | 478 | { |
ca594353 | 479 | value = new NXSL_Value((LONG)node->getSNMPVersion()); |
cf38357f | 480 | } |
e980db40 VK |
481 | else if (!_tcscmp(attr, _T("subType"))) |
482 | { | |
483 | value = new NXSL_Value(node->getSubType()); | |
484 | } | |
ca594353 | 485 | else if (!_tcscmp(attr, _T("sysDescription"))) |
5039dede | 486 | { |
ca594353 | 487 | value = new NXSL_Value(node->getSysDescription()); |
5039dede | 488 | } |
e980db40 VK |
489 | else if (!_tcscmp(attr, _T("type"))) |
490 | { | |
491 | value = new NXSL_Value((INT32)node->getType()); | |
492 | } | |
ca594353 | 493 | else if (!_tcscmp(attr, _T("zone"))) |
fe400f32 VK |
494 | { |
495 | if (g_flags & AF_ENABLE_ZONING) | |
496 | { | |
ca594353 | 497 | Zone *zone = FindZoneByGUID(node->getZoneId()); |
fe400f32 VK |
498 | if (zone != NULL) |
499 | { | |
ca594353 | 500 | value = new NXSL_Value(new NXSL_Object(&g_nxslZoneClass, zone)); |
fe400f32 VK |
501 | } |
502 | else | |
503 | { | |
ca594353 | 504 | value = new NXSL_Value; |
fe400f32 VK |
505 | } |
506 | } | |
507 | else | |
508 | { | |
ca594353 | 509 | value = new NXSL_Value; |
fe400f32 VK |
510 | } |
511 | } | |
ca594353 | 512 | else if (!_tcscmp(attr, _T("zoneId"))) |
fe400f32 | 513 | { |
ca594353 | 514 | value = new NXSL_Value(node->getZoneId()); |
5039dede | 515 | } |
ca594353 | 516 | return value; |
5039dede AK |
517 | } |
518 | ||
7638efb1 VK |
519 | /** |
520 | * Interface::setExcludeFromTopology(enabled) method | |
521 | */ | |
522 | NXSL_METHOD_DEFINITION(Interface, setExcludeFromTopology) | |
523 | { | |
524 | if (!argv[0]->isInteger()) | |
525 | return NXSL_ERR_NOT_INTEGER; | |
526 | ||
527 | Interface *iface = (Interface *)object->getData(); | |
528 | iface->setExcludeFromTopology(argv[0]->getValueAsInt32() != 0); | |
529 | *result = new NXSL_Value; | |
530 | return 0; | |
531 | } | |
532 | ||
533 | /** | |
534 | * Interface::setExpectedState(state) method | |
535 | */ | |
536 | NXSL_METHOD_DEFINITION(Interface, setExpectedState) | |
537 | { | |
538 | int state; | |
99561450 | 539 | if (argv[0]->isInteger()) |
7638efb1 | 540 | { |
99561450 | 541 | state = argv[0]->getValueAsInt32(); |
7638efb1 | 542 | } |
99561450 | 543 | else if (argv[0]->isString()) |
7638efb1 VK |
544 | { |
545 | static const TCHAR *stateNames[] = { _T("UP"), _T("DOWN"), _T("IGNORE"), NULL }; | |
99561450 | 546 | const TCHAR *name = argv[0]->getValueAsCString(); |
7638efb1 VK |
547 | for(state = 0; stateNames[state] != NULL; state++) |
548 | if (!_tcsicmp(stateNames[state], name)) | |
549 | break; | |
550 | } | |
551 | else | |
552 | { | |
553 | return NXSL_ERR_NOT_STRING; | |
554 | } | |
555 | ||
7638efb1 VK |
556 | if ((state >= 0) && (state <= 2)) |
557 | ((Interface *)object->getData())->setExpectedState(state); | |
558 | ||
559 | *result = new NXSL_Value; | |
560 | return 0; | |
561 | } | |
562 | ||
5956e68b | 563 | /** |
484e609d | 564 | * NXSL class Interface: constructor |
5956e68b | 565 | */ |
ca594353 | 566 | NXSL_InterfaceClass::NXSL_InterfaceClass() : NXSL_NetObjClass() |
09e834a1 | 567 | { |
c42b4551 | 568 | _tcscpy(m_name, _T("Interface")); |
7638efb1 VK |
569 | |
570 | NXSL_REGISTER_METHOD(Interface, setExcludeFromTopology, 1); | |
571 | NXSL_REGISTER_METHOD(Interface, setExpectedState, 1); | |
09e834a1 VK |
572 | } |
573 | ||
484e609d VK |
574 | /** |
575 | * NXSL class Interface: get attribute | |
576 | */ | |
ca594353 | 577 | NXSL_Value *NXSL_InterfaceClass::getAttr(NXSL_Object *object, const TCHAR *attr) |
09e834a1 | 578 | { |
ca594353 VK |
579 | NXSL_Value *value = NXSL_NetObjClass::getAttr(object, attr); |
580 | if (value != NULL) | |
581 | return value; | |
09e834a1 | 582 | |
ca594353 VK |
583 | Interface *iface = (Interface *)object->getData(); |
584 | if (!_tcscmp(attr, _T("adminState"))) | |
707b18df | 585 | { |
ca594353 | 586 | value = new NXSL_Value((LONG)iface->getAdminState()); |
707b18df | 587 | } |
ca594353 | 588 | else if (!_tcscmp(attr, _T("alias"))) |
707b18df | 589 | { |
ca594353 | 590 | value = new NXSL_Value(iface->getAlias()); |
707b18df | 591 | } |
ca594353 | 592 | else if (!_tcscmp(attr, _T("bridgePortNumber"))) |
707b18df | 593 | { |
ca594353 | 594 | value = new NXSL_Value(iface->getBridgePortNumber()); |
707b18df | 595 | } |
ca594353 | 596 | else if (!_tcscmp(attr, _T("description"))) |
707b18df | 597 | { |
ca594353 | 598 | value = new NXSL_Value(iface->getDescription()); |
707b18df | 599 | } |
ca594353 | 600 | else if (!_tcscmp(attr, _T("dot1xBackendAuthState"))) |
707b18df | 601 | { |
ca594353 | 602 | value = new NXSL_Value((LONG)iface->getDot1xBackendAuthState()); |
707b18df | 603 | } |
ca594353 | 604 | else if (!_tcscmp(attr, _T("dot1xPaeAuthState"))) |
707b18df | 605 | { |
ca594353 | 606 | value = new NXSL_Value((LONG)iface->getDot1xPaeAuthState()); |
9b3015b8 | 607 | } |
ca594353 | 608 | else if (!_tcscmp(attr, _T("expectedState"))) |
09e834a1 | 609 | { |
ca594353 | 610 | value = new NXSL_Value((iface->getFlags() & IF_EXPECTED_STATE_MASK) >> 28); |
09e834a1 | 611 | } |
ca594353 | 612 | else if (!_tcscmp(attr, _T("flags"))) |
6adc4a1a | 613 | { |
ca594353 | 614 | value = new NXSL_Value(iface->getFlags()); |
707b18df | 615 | } |
ca594353 | 616 | else if (!_tcscmp(attr, _T("ifIndex"))) |
707b18df | 617 | { |
ca594353 | 618 | value = new NXSL_Value(iface->getIfIndex()); |
6adc4a1a | 619 | } |
ca594353 | 620 | else if (!_tcscmp(attr, _T("ifType"))) |
09e834a1 | 621 | { |
ca594353 | 622 | value = new NXSL_Value(iface->getIfType()); |
09e834a1 | 623 | } |
ca594353 | 624 | else if (!_tcscmp(attr, _T("ipNetMask"))) |
09e834a1 | 625 | { |
ca594353 | 626 | value = new NXSL_Value(iface->getIpAddressList()->getFirstUnicastAddress().getMaskBits()); |
09e834a1 | 627 | } |
ca594353 | 628 | else if (!_tcscmp(attr, _T("isExcludedFromTopology"))) |
09e834a1 | 629 | { |
ca594353 | 630 | value = new NXSL_Value((LONG)(iface->isExcludedFromTopology() ? 1 : 0)); |
09e834a1 | 631 | } |
ca594353 | 632 | else if (!_tcscmp(attr, _T("isLoopback"))) |
09e834a1 | 633 | { |
ca594353 | 634 | value = new NXSL_Value((LONG)(iface->isLoopback() ? 1 : 0)); |
6adc4a1a | 635 | } |
ca594353 | 636 | else if (!_tcscmp(attr, _T("isManuallyCreated"))) |
1e6b68a6 | 637 | { |
ca594353 | 638 | value = new NXSL_Value((LONG)(iface->isManuallyCreated() ? 1 : 0)); |
1e6b68a6 | 639 | } |
ca594353 | 640 | else if (!_tcscmp(attr, _T("isPhysicalPort"))) |
1e6b68a6 | 641 | { |
ca594353 | 642 | value = new NXSL_Value((LONG)(iface->isPhysicalPort() ? 1 : 0)); |
1e6b68a6 | 643 | } |
ca594353 | 644 | else if (!_tcscmp(attr, _T("macAddr"))) |
1e6b68a6 | 645 | { |
707b18df | 646 | TCHAR buffer[256]; |
ca594353 | 647 | value = new NXSL_Value(BinToStr(iface->getMacAddr(), MAC_ADDR_LENGTH, buffer)); |
e95680e5 | 648 | } |
ca594353 | 649 | else if (!_tcscmp(attr, _T("mtu"))) |
1e6b68a6 | 650 | { |
ca594353 | 651 | value = new NXSL_Value(iface->getMTU()); |
1e6b68a6 | 652 | } |
ca594353 | 653 | else if (!_tcscmp(attr, _T("node"))) |
6adc4a1a VK |
654 | { |
655 | Node *parentNode = iface->getParentNode(); | |
656 | if (parentNode != NULL) | |
657 | { | |
ca594353 | 658 | value = new NXSL_Value(new NXSL_Object(&g_nxslNodeClass, parentNode)); |
6adc4a1a VK |
659 | } |
660 | else | |
661 | { | |
ca594353 | 662 | value = new NXSL_Value; |
6adc4a1a VK |
663 | } |
664 | } | |
ca594353 | 665 | else if (!_tcscmp(attr, _T("operState"))) |
6adc4a1a | 666 | { |
ca594353 | 667 | value = new NXSL_Value((LONG)iface->getOperState()); |
707b18df | 668 | } |
ca594353 | 669 | else if (!_tcscmp(attr, _T("peerInterface"))) |
707b18df VK |
670 | { |
671 | Interface *peerIface = (Interface *)FindObjectById(iface->getPeerInterfaceId(), OBJECT_INTERFACE); | |
672 | if (peerIface != NULL) | |
6adc4a1a | 673 | { |
c8076b19 | 674 | if (g_flags & AF_CHECK_TRUSTED_NODES) |
6adc4a1a VK |
675 | { |
676 | Node *parentNode = iface->getParentNode(); | |
707b18df VK |
677 | Node *peerNode = peerIface->getParentNode(); |
678 | if ((parentNode != NULL) && (peerNode != NULL)) | |
6adc4a1a | 679 | { |
c42b4551 | 680 | if (peerNode->isTrustedNode(parentNode->getId())) |
707b18df | 681 | { |
ca594353 | 682 | value = new NXSL_Value(new NXSL_Object(&g_nxslInterfaceClass, peerIface)); |
707b18df VK |
683 | } |
684 | else | |
685 | { | |
686 | // No access, return null | |
ca594353 | 687 | value = new NXSL_Value; |
707b18df | 688 | DbgPrintf(4, _T("NXSL::Interface::peerInterface(%s [%d]): access denied for node %s [%d]"), |
c42b4551 | 689 | iface->getName(), iface->getId(), peerNode->getName(), peerNode->getId()); |
707b18df | 690 | } |
6adc4a1a VK |
691 | } |
692 | else | |
693 | { | |
ca594353 | 694 | value = new NXSL_Value; |
c42b4551 | 695 | DbgPrintf(4, _T("NXSL::Interface::peerInterface(%s [%d]): parentNode=%p peerNode=%p"), iface->getName(), iface->getId(), parentNode, peerNode); |
6adc4a1a VK |
696 | } |
697 | } | |
698 | else | |
699 | { | |
ca594353 | 700 | value = new NXSL_Value(new NXSL_Object(&g_nxslInterfaceClass, peerIface)); |
6adc4a1a VK |
701 | } |
702 | } | |
703 | else | |
704 | { | |
ca594353 | 705 | value = new NXSL_Value; |
6adc4a1a VK |
706 | } |
707 | } | |
ca594353 | 708 | else if (!_tcscmp(attr, _T("peerNode"))) |
6adc4a1a | 709 | { |
707b18df VK |
710 | Node *peerNode = (Node *)FindObjectById(iface->getPeerNodeId(), OBJECT_NODE); |
711 | if (peerNode != NULL) | |
6adc4a1a | 712 | { |
c8076b19 | 713 | if (g_flags & AF_CHECK_TRUSTED_NODES) |
6adc4a1a VK |
714 | { |
715 | Node *parentNode = iface->getParentNode(); | |
c42b4551 | 716 | if ((parentNode != NULL) && (peerNode->isTrustedNode(parentNode->getId()))) |
6adc4a1a | 717 | { |
ca594353 | 718 | value = new NXSL_Value(new NXSL_Object(&g_nxslNodeClass, peerNode)); |
6adc4a1a VK |
719 | } |
720 | else | |
721 | { | |
707b18df | 722 | // No access, return null |
ca594353 | 723 | value = new NXSL_Value; |
707b18df | 724 | DbgPrintf(4, _T("NXSL::Interface::peerNode(%s [%d]): access denied for node %s [%d]"), |
c42b4551 | 725 | iface->getName(), iface->getId(), peerNode->getName(), peerNode->getId()); |
6adc4a1a VK |
726 | } |
727 | } | |
728 | else | |
729 | { | |
ca594353 | 730 | value = new NXSL_Value(new NXSL_Object(&g_nxslNodeClass, peerNode)); |
6adc4a1a VK |
731 | } |
732 | } | |
733 | else | |
734 | { | |
ca594353 | 735 | value = new NXSL_Value; |
6adc4a1a | 736 | } |
707b18df | 737 | } |
ca594353 | 738 | else if (!_tcscmp(attr, _T("port"))) |
ee9e3506 | 739 | { |
ca594353 | 740 | value = new NXSL_Value(iface->getPortNumber()); |
ee9e3506 | 741 | } |
ca594353 | 742 | else if (!_tcscmp(attr, _T("slot"))) |
ee9e3506 | 743 | { |
ca594353 | 744 | value = new NXSL_Value(iface->getSlotNumber()); |
ee9e3506 | 745 | } |
ca594353 | 746 | else if (!_tcscmp(attr, _T("speed"))) |
3d37f7bf | 747 | { |
ca594353 | 748 | value = new NXSL_Value(iface->getSpeed()); |
3d37f7bf | 749 | } |
ca594353 | 750 | else if (!_tcscmp(attr, _T("zone"))) |
fe400f32 VK |
751 | { |
752 | if (g_flags & AF_ENABLE_ZONING) | |
753 | { | |
754 | Zone *zone = FindZoneByGUID(iface->getZoneId()); | |
755 | if (zone != NULL) | |
756 | { | |
ca594353 | 757 | value = new NXSL_Value(new NXSL_Object(&g_nxslZoneClass, zone)); |
fe400f32 VK |
758 | } |
759 | else | |
760 | { | |
ca594353 | 761 | value = new NXSL_Value; |
fe400f32 VK |
762 | } |
763 | } | |
764 | else | |
765 | { | |
ca594353 | 766 | value = new NXSL_Value; |
fe400f32 VK |
767 | } |
768 | } | |
ca594353 | 769 | else if (!_tcscmp(attr, _T("zoneId"))) |
fe400f32 | 770 | { |
ca594353 | 771 | value = new NXSL_Value(iface->getZoneId()); |
09e834a1 | 772 | } |
ca594353 | 773 | return value; |
09e834a1 VK |
774 | } |
775 | ||
23015e41 Z |
776 | /** |
777 | * NXSL class Mobile Device: constructor | |
778 | */ | |
779 | NXSL_MobileDeviceClass::NXSL_MobileDeviceClass() : NXSL_NetObjClass() | |
780 | { | |
781 | _tcscpy(m_name, _T("MobileDevice")); | |
782 | } | |
783 | ||
784 | /** | |
785 | * NXSL class Mobile Device: get attribute | |
786 | */ | |
787 | NXSL_Value *NXSL_MobileDeviceClass::getAttr(NXSL_Object *object, const TCHAR *attr) | |
788 | { | |
789 | NXSL_Value *value = NXSL_NetObjClass::getAttr(object, attr); | |
790 | if (value != NULL) | |
791 | return value; | |
792 | ||
34f32920 Z |
793 | MobileDevice *mobDevice = (MobileDevice *)object->getData(); |
794 | if (!_tcscmp(attr, _T("deviceId"))) | |
795 | { | |
796 | value = new NXSL_Value(mobDevice->getDeviceId()); | |
797 | } | |
798 | else if (!_tcscmp(attr, _T("vendor"))) | |
799 | { | |
800 | value = new NXSL_Value(mobDevice->getVendor()); | |
801 | } | |
802 | else if (!_tcscmp(attr, _T("model"))) | |
803 | { | |
804 | value = new NXSL_Value(mobDevice->getModel()); | |
805 | } | |
806 | else if (!_tcscmp(attr, _T("serialNumber"))) | |
807 | { | |
808 | value = new NXSL_Value(mobDevice->getSerialNumber()); | |
809 | } | |
810 | else if (!_tcscmp(attr, _T("osName"))) | |
811 | { | |
812 | value = new NXSL_Value(mobDevice->getOsName()); | |
813 | } | |
814 | else if (!_tcscmp(attr, _T("osVersion"))) | |
815 | { | |
816 | value = new NXSL_Value(mobDevice->getOsVersion()); | |
817 | } | |
818 | else if (!_tcscmp(attr, _T("userId"))) | |
819 | { | |
820 | value = new NXSL_Value(mobDevice->getUserId()); | |
821 | } | |
822 | else if (!_tcscmp(attr, _T("batteryLevel"))) | |
823 | { | |
824 | value = new NXSL_Value(mobDevice->getBatteryLevel()); | |
825 | } | |
826 | ||
23015e41 Z |
827 | return value; |
828 | } | |
829 | ||
e4926628 VK |
830 | /** |
831 | * NXSL class "Chassis" constructor | |
832 | */ | |
833 | NXSL_ChassisClass::NXSL_ChassisClass() : NXSL_NetObjClass() | |
834 | { | |
835 | _tcscpy(m_name, _T("Chassis")); | |
836 | } | |
837 | ||
838 | /** | |
839 | * NXSL class "Cluster" attributes | |
840 | */ | |
841 | NXSL_Value *NXSL_ChassisClass::getAttr(NXSL_Object *object, const TCHAR *attr) | |
842 | { | |
843 | NXSL_Value *value = NXSL_NetObjClass::getAttr(object, attr); | |
844 | if (value != NULL) | |
845 | return value; | |
846 | ||
847 | Chassis *chassis = (Chassis *)object->getData(); | |
848 | if (!_tcscmp(attr, _T("controller"))) | |
849 | { | |
850 | Node *node = (Node *)FindObjectById(chassis->getControllerId(), OBJECT_NODE); | |
851 | if (node != NULL) | |
852 | { | |
853 | value = node->createNXSLObject(); | |
854 | } | |
855 | else | |
856 | { | |
857 | value = new NXSL_Value; | |
858 | } | |
859 | } | |
860 | else if (!_tcscmp(attr, _T("controllerId"))) | |
861 | { | |
862 | value = new NXSL_Value(chassis->getControllerId()); | |
863 | } | |
487cde95 VK |
864 | else if (!_tcscmp(attr, _T("flags"))) |
865 | { | |
866 | value = new NXSL_Value(chassis->getFlags()); | |
867 | } | |
e4926628 VK |
868 | else if (!_tcscmp(attr, _T("rack"))) |
869 | { | |
870 | Rack *rack = (Rack *)FindObjectById(chassis->getRackId(), OBJECT_RACK); | |
871 | if (rack != NULL) | |
872 | { | |
873 | value = rack->createNXSLObject(); | |
874 | } | |
875 | else | |
876 | { | |
877 | value = new NXSL_Value; | |
878 | } | |
879 | } | |
880 | else if (!_tcscmp(attr, _T("rackId"))) | |
881 | { | |
882 | value = new NXSL_Value(chassis->getRackId()); | |
883 | } | |
884 | else if (!_tcscmp(attr, _T("rackHeight"))) | |
885 | { | |
886 | value = new NXSL_Value(chassis->getRackHeight()); | |
887 | } | |
888 | else if (!_tcscmp(attr, _T("rackPosition"))) | |
889 | { | |
890 | value = new NXSL_Value(chassis->getRackPosition()); | |
891 | } | |
892 | return value; | |
893 | } | |
894 | ||
23015e41 | 895 | /** |
7833a69f | 896 | * NXSL class "Cluster" constructor |
23015e41 | 897 | */ |
7833a69f | 898 | NXSL_ClusterClass::NXSL_ClusterClass() : NXSL_NetObjClass() |
23015e41 Z |
899 | { |
900 | _tcscpy(m_name, _T("Cluster")); | |
901 | } | |
902 | ||
903 | /** | |
7833a69f | 904 | * NXSL class "Cluster" attributes |
23015e41 | 905 | */ |
7833a69f | 906 | NXSL_Value *NXSL_ClusterClass::getAttr(NXSL_Object *object, const TCHAR *attr) |
23015e41 Z |
907 | { |
908 | NXSL_Value *value = NXSL_NetObjClass::getAttr(object, attr); | |
909 | if (value != NULL) | |
910 | return value; | |
911 | ||
912 | Cluster *cluster = (Cluster *)object->getData(); | |
7833a69f VK |
913 | if (!_tcscmp(attr, _T("zone"))) |
914 | { | |
915 | if (g_flags & AF_ENABLE_ZONING) | |
916 | { | |
917 | Zone *zone = FindZoneByGUID(cluster->getZoneId()); | |
918 | if (zone != NULL) | |
919 | { | |
e4926628 | 920 | value = zone->createNXSLObject(); |
7833a69f VK |
921 | } |
922 | else | |
923 | { | |
924 | value = new NXSL_Value; | |
925 | } | |
926 | } | |
927 | else | |
928 | { | |
929 | value = new NXSL_Value; | |
930 | } | |
931 | } | |
932 | else if (!_tcscmp(attr, _T("zoneId"))) | |
933 | { | |
934 | value = new NXSL_Value(cluster->getZoneId()); | |
935 | } | |
23015e41 Z |
936 | return value; |
937 | } | |
938 | ||
ad13c0e2 VK |
939 | /** |
940 | * Event::setMessage() method | |
941 | */ | |
63e99e56 | 942 | NXSL_METHOD_DEFINITION(Event, setMessage) |
ad13c0e2 VK |
943 | { |
944 | if (!argv[0]->isString()) | |
945 | return NXSL_ERR_NOT_STRING; | |
946 | ||
947 | Event *event = (Event *)object->getData(); | |
948 | event->setMessage(argv[0]->getValueAsCString()); | |
949 | *result = new NXSL_Value(); | |
950 | return 0; | |
951 | } | |
952 | ||
953 | /** | |
954 | * Event::setSeverity() method | |
955 | */ | |
63e99e56 | 956 | NXSL_METHOD_DEFINITION(Event, setSeverity) |
ad13c0e2 VK |
957 | { |
958 | if (!argv[0]->isInteger()) | |
959 | return NXSL_ERR_NOT_STRING; | |
960 | ||
961 | int s = argv[0]->getValueAsInt32(); | |
962 | if ((s >= SEVERITY_NORMAL) && (s <= SEVERITY_CRITICAL)) | |
963 | { | |
964 | Event *event = (Event *)object->getData(); | |
965 | event->setSeverity(s); | |
966 | } | |
967 | *result = new NXSL_Value(); | |
968 | return 0; | |
969 | } | |
970 | ||
971 | /** | |
972 | * Event::setUserTag() method | |
973 | */ | |
63e99e56 | 974 | NXSL_METHOD_DEFINITION(Event, setUserTag) |
ad13c0e2 VK |
975 | { |
976 | if (!argv[0]->isString()) | |
977 | return NXSL_ERR_NOT_STRING; | |
978 | ||
979 | Event *event = (Event *)object->getData(); | |
980 | event->setUserTag(argv[0]->getValueAsCString()); | |
981 | *result = new NXSL_Value(); | |
982 | return 0; | |
983 | } | |
984 | ||
0356b995 VK |
985 | /** |
986 | * Event::toJson() method | |
987 | */ | |
988 | NXSL_METHOD_DEFINITION(Event, toJson) | |
989 | { | |
990 | Event *event = (Event *)object->getData(); | |
991 | *result = new NXSL_Value(event->createJson()); | |
992 | return 0; | |
993 | } | |
994 | ||
49fbe41f | 995 | /** |
484e609d | 996 | * NXSL class Event: constructor |
49fbe41f | 997 | */ |
3c050e4c | 998 | NXSL_EventClass::NXSL_EventClass() : NXSL_Class() |
5039dede | 999 | { |
c42b4551 | 1000 | _tcscpy(m_name, _T("Event")); |
ad13c0e2 | 1001 | |
63e99e56 VK |
1002 | NXSL_REGISTER_METHOD(Event, setMessage, 1); |
1003 | NXSL_REGISTER_METHOD(Event, setSeverity, 1); | |
1004 | NXSL_REGISTER_METHOD(Event, setUserTag, 1); | |
0356b995 | 1005 | NXSL_REGISTER_METHOD(Event, toJson, 0); |
5039dede AK |
1006 | } |
1007 | ||
484e609d VK |
1008 | /** |
1009 | * NXSL class Event: get attribute | |
1010 | */ | |
ca594353 | 1011 | NXSL_Value *NXSL_EventClass::getAttr(NXSL_Object *pObject, const TCHAR *attr) |
5039dede | 1012 | { |
5039dede AK |
1013 | NXSL_Value *value = NULL; |
1014 | ||
ad13c0e2 | 1015 | Event *event = (Event *)pObject->getData(); |
ca594353 | 1016 | if (!_tcscmp(attr, _T("code"))) |
5039dede | 1017 | { |
210642a1 | 1018 | value = new NXSL_Value(event->getCode()); |
5039dede | 1019 | } |
e0a7a7f5 | 1020 | else if (!_tcscmp(attr, _T("customMessage"))) |
86a4796f | 1021 | { |
e0a7a7f5 | 1022 | value = new NXSL_Value(event->getCustomMessage()); |
86a4796f | 1023 | } |
ca594353 | 1024 | else if (!_tcscmp(attr, _T("id"))) |
5039dede | 1025 | { |
210642a1 | 1026 | value = new NXSL_Value(event->getId()); |
5039dede | 1027 | } |
e0a7a7f5 VK |
1028 | else if (!_tcscmp(attr, _T("message"))) |
1029 | { | |
1030 | value = new NXSL_Value(event->getMessage()); | |
1031 | } | |
1032 | else if (!_tcscmp(attr, _T("name"))) | |
1033 | { | |
1034 | value = new NXSL_Value(event->getName()); | |
1035 | } | |
1036 | else if (!_tcscmp(attr, _T("parameters"))) | |
1037 | { | |
1038 | NXSL_Array *array = new NXSL_Array; | |
1039 | for(int i = 0; i < event->getParametersCount(); i++) | |
1040 | array->set(i + 1, new NXSL_Value(event->getParameter(i))); | |
1041 | value = new NXSL_Value(array); | |
1042 | } | |
ca594353 | 1043 | else if (!_tcscmp(attr, _T("severity"))) |
5039dede | 1044 | { |
210642a1 | 1045 | value = new NXSL_Value(event->getSeverity()); |
5039dede | 1046 | } |
e0a7a7f5 | 1047 | else if (!_tcscmp(attr, _T("source"))) |
5039dede | 1048 | { |
e0a7a7f5 VK |
1049 | NetObj *object = FindObjectById(event->getSourceId()); |
1050 | value = (object != NULL) ? object->createNXSLObject() : new NXSL_Value(); | |
5039dede | 1051 | } |
e0a7a7f5 | 1052 | else if (!_tcscmp(attr, _T("sourceId"))) |
5039dede | 1053 | { |
e0a7a7f5 | 1054 | value = new NXSL_Value(event->getSourceId()); |
210642a1 | 1055 | } |
e0a7a7f5 | 1056 | else if (!_tcscmp(attr, _T("timestamp"))) |
210642a1 | 1057 | { |
e0a7a7f5 | 1058 | value = new NXSL_Value((INT64)event->getTimeStamp()); |
5039dede | 1059 | } |
ca594353 | 1060 | else if (!_tcscmp(attr, _T("userTag"))) |
5039dede | 1061 | { |
210642a1 | 1062 | value = new NXSL_Value(event->getUserTag()); |
5039dede | 1063 | } |
4058f716 VK |
1064 | else |
1065 | { | |
1066 | if (attr[0] == _T('$')) | |
1067 | { | |
1068 | // Try to find parameter with given index | |
1069 | TCHAR *eptr; | |
1070 | int index = _tcstol(&attr[1], &eptr, 10); | |
1071 | if ((index > 0) && (*eptr == 0)) | |
1072 | { | |
1073 | const TCHAR *s = event->getParameter(index - 1); | |
1074 | if (s != NULL) | |
1075 | { | |
1076 | value = new NXSL_Value(s); | |
1077 | } | |
1078 | } | |
1079 | } | |
1080 | ||
1081 | // Try to find named parameter with given name | |
1082 | if (value == NULL) | |
1083 | { | |
1084 | const TCHAR *s = event->getNamedParameter(attr); | |
1085 | if (s != NULL) | |
1086 | { | |
1087 | value = new NXSL_Value(s); | |
1088 | } | |
1089 | } | |
1090 | } | |
5039dede AK |
1091 | return value; |
1092 | } | |
1093 | ||
459f4057 VK |
1094 | /** |
1095 | * Alarm::acknowledge() method | |
1096 | */ | |
63e99e56 | 1097 | NXSL_METHOD_DEFINITION(Alarm, acknowledge) |
459f4057 | 1098 | { |
d727efe6 VK |
1099 | Alarm *alarm = (Alarm *)object->getData(); |
1100 | *result = new NXSL_Value(AckAlarmById(alarm->getAlarmId(), NULL, false, 0)); | |
459f4057 VK |
1101 | return 0; |
1102 | } | |
1103 | ||
1104 | /** | |
1105 | * Alarm::resolve() method | |
1106 | */ | |
63e99e56 | 1107 | NXSL_METHOD_DEFINITION(Alarm, resolve) |
459f4057 | 1108 | { |
d727efe6 VK |
1109 | Alarm *alarm = (Alarm *)object->getData(); |
1110 | *result = new NXSL_Value(ResolveAlarmById(alarm->getAlarmId(), NULL, false)); | |
459f4057 VK |
1111 | return 0; |
1112 | } | |
1113 | ||
1114 | /** | |
1115 | * Alarm::terminate() method | |
1116 | */ | |
63e99e56 | 1117 | NXSL_METHOD_DEFINITION(Alarm, terminate) |
459f4057 | 1118 | { |
d727efe6 VK |
1119 | Alarm *alarm = (Alarm *)object->getData(); |
1120 | *result = new NXSL_Value(ResolveAlarmById(alarm->getAlarmId(), NULL, true)); | |
459f4057 VK |
1121 | return 0; |
1122 | } | |
1123 | ||
1124 | /** | |
1125 | * NXSL class Alarm: constructor | |
1126 | */ | |
1127 | NXSL_AlarmClass::NXSL_AlarmClass() : NXSL_Class() | |
1128 | { | |
1129 | _tcscpy(m_name, _T("Alarm")); | |
1130 | ||
63e99e56 VK |
1131 | NXSL_REGISTER_METHOD(Alarm, acknowledge, 0); |
1132 | NXSL_REGISTER_METHOD(Alarm, resolve, 0); | |
1133 | NXSL_REGISTER_METHOD(Alarm, terminate, 0); | |
459f4057 VK |
1134 | } |
1135 | ||
1136 | /** | |
1137 | * NXSL object destructor | |
1138 | */ | |
1139 | void NXSL_AlarmClass::onObjectDelete(NXSL_Object *object) | |
1140 | { | |
d727efe6 | 1141 | delete (Alarm *)object->getData(); |
459f4057 VK |
1142 | } |
1143 | ||
1144 | /** | |
1145 | * NXSL class Alarm: get attribute | |
1146 | */ | |
ca594353 | 1147 | NXSL_Value *NXSL_AlarmClass::getAttr(NXSL_Object *pObject, const TCHAR *attr) |
459f4057 VK |
1148 | { |
1149 | NXSL_Value *value = NULL; | |
d727efe6 | 1150 | Alarm *alarm = (Alarm *)pObject->getData(); |
459f4057 | 1151 | |
ca594353 | 1152 | if (!_tcscmp(attr, _T("ackBy"))) |
459f4057 | 1153 | { |
d727efe6 | 1154 | value = new NXSL_Value(alarm->getAckByUser()); |
459f4057 | 1155 | } |
ca594353 | 1156 | else if (!_tcscmp(attr, _T("creationTime"))) |
459f4057 | 1157 | { |
d727efe6 | 1158 | value = new NXSL_Value((INT64)alarm->getCreationTime()); |
65ce7452 | 1159 | } |
ca594353 | 1160 | else if (!_tcscmp(attr, _T("dciId"))) |
65ce7452 | 1161 | { |
d727efe6 | 1162 | value = new NXSL_Value(alarm->getDciId()); |
459f4057 | 1163 | } |
ca594353 | 1164 | else if (!_tcscmp(attr, _T("eventCode"))) |
459f4057 | 1165 | { |
d727efe6 | 1166 | value = new NXSL_Value(alarm->getSourceEventCode()); |
459f4057 | 1167 | } |
ca594353 | 1168 | else if (!_tcscmp(attr, _T("eventId"))) |
459f4057 | 1169 | { |
d727efe6 | 1170 | value = new NXSL_Value(alarm->getSourceEventId()); |
459f4057 | 1171 | } |
ca594353 | 1172 | else if (!_tcscmp(attr, _T("helpdeskReference"))) |
459f4057 | 1173 | { |
d727efe6 | 1174 | value = new NXSL_Value(alarm->getHelpDeskRef()); |
459f4057 | 1175 | } |
ca594353 | 1176 | else if (!_tcscmp(attr, _T("helpdeskState"))) |
459f4057 | 1177 | { |
d727efe6 | 1178 | value = new NXSL_Value(alarm->getHelpDeskState()); |
459f4057 | 1179 | } |
ca594353 | 1180 | else if (!_tcscmp(attr, _T("id"))) |
459f4057 | 1181 | { |
d727efe6 | 1182 | value = new NXSL_Value(alarm->getAlarmId()); |
459f4057 | 1183 | } |
ca594353 | 1184 | else if (!_tcscmp(attr, _T("key"))) |
459f4057 | 1185 | { |
d727efe6 | 1186 | value = new NXSL_Value(alarm->getKey()); |
459f4057 | 1187 | } |
ca594353 | 1188 | else if (!_tcscmp(attr, _T("lastChangeTime"))) |
459f4057 | 1189 | { |
d727efe6 | 1190 | value = new NXSL_Value((INT64)alarm->getLastChangeTime()); |
459f4057 | 1191 | } |
ca594353 | 1192 | else if (!_tcscmp(attr, _T("message"))) |
459f4057 | 1193 | { |
d727efe6 | 1194 | value = new NXSL_Value(alarm->getMessage()); |
459f4057 | 1195 | } |
ca594353 | 1196 | else if (!_tcscmp(attr, _T("originalSeverity"))) |
459f4057 | 1197 | { |
d727efe6 | 1198 | value = new NXSL_Value(alarm->getOriginalSeverity()); |
459f4057 | 1199 | } |
ca594353 | 1200 | else if (!_tcscmp(attr, _T("repeatCount"))) |
459f4057 | 1201 | { |
d727efe6 | 1202 | value = new NXSL_Value(alarm->getRepeatCount()); |
459f4057 | 1203 | } |
ca594353 | 1204 | else if (!_tcscmp(attr, _T("resolvedBy"))) |
459f4057 | 1205 | { |
d727efe6 | 1206 | value = new NXSL_Value(alarm->getResolvedByUser()); |
459f4057 | 1207 | } |
ca594353 | 1208 | else if (!_tcscmp(attr, _T("severity"))) |
459f4057 | 1209 | { |
d727efe6 | 1210 | value = new NXSL_Value(alarm->getCurrentSeverity()); |
459f4057 | 1211 | } |
ca594353 | 1212 | else if (!_tcscmp(attr, _T("sourceObject"))) |
459f4057 | 1213 | { |
d727efe6 | 1214 | value = new NXSL_Value(alarm->getSourceObject()); |
459f4057 | 1215 | } |
ca594353 | 1216 | else if (!_tcscmp(attr, _T("state"))) |
459f4057 | 1217 | { |
d727efe6 | 1218 | value = new NXSL_Value(alarm->getState()); |
459f4057 VK |
1219 | } |
1220 | return value; | |
1221 | } | |
1222 | ||
0688e29b | 1223 | /** |
7de1151b | 1224 | * Implementation of "DCI" class: constructor |
0688e29b VK |
1225 | */ |
1226 | NXSL_DciClass::NXSL_DciClass() : NXSL_Class() | |
bb51576f | 1227 | { |
c42b4551 | 1228 | _tcscpy(m_name, _T("DCI")); |
bb51576f VK |
1229 | } |
1230 | ||
4804be4e VK |
1231 | /** |
1232 | * Object destructor | |
1233 | */ | |
1234 | void NXSL_DciClass::onObjectDelete(NXSL_Object *object) | |
1235 | { | |
1236 | delete (DCObjectInfo *)object->getData(); | |
1237 | } | |
1238 | ||
7de1151b VK |
1239 | /** |
1240 | * Implementation of "DCI" class: get attribute | |
1241 | */ | |
bb51576f VK |
1242 | NXSL_Value *NXSL_DciClass::getAttr(NXSL_Object *object, const TCHAR *attr) |
1243 | { | |
4804be4e | 1244 | DCObjectInfo *dci; |
bb51576f VK |
1245 | NXSL_Value *value = NULL; |
1246 | ||
4804be4e | 1247 | dci = (DCObjectInfo *)object->getData(); |
7f16667f VK |
1248 | if (!_tcscmp(attr, _T("comments"))) |
1249 | { | |
1250 | value = new NXSL_Value(dci->getComments()); | |
1251 | } | |
1252 | else if (!_tcscmp(attr, _T("dataType")) && (dci->getType() == DCO_TYPE_ITEM)) | |
bb51576f | 1253 | { |
31704fa2 | 1254 | value = new NXSL_Value(dci->getDataType()); |
bb51576f | 1255 | } |
35f836fe | 1256 | else if (!_tcscmp(attr, _T("description"))) |
bb51576f VK |
1257 | { |
1258 | value = new NXSL_Value(dci->getDescription()); | |
1259 | } | |
7de1151b | 1260 | else if (!_tcscmp(attr, _T("errorCount"))) |
bb51576f | 1261 | { |
7de1151b | 1262 | value = new NXSL_Value(dci->getErrorCount()); |
bb51576f | 1263 | } |
7de1151b | 1264 | else if (!_tcscmp(attr, _T("id"))) |
bb51576f | 1265 | { |
7de1151b | 1266 | value = new NXSL_Value(dci->getId()); |
bb51576f | 1267 | } |
ba39fc61 VK |
1268 | else if ((dci->getType() == DCO_TYPE_ITEM) && !_tcscmp(attr, _T("instance"))) |
1269 | { | |
31704fa2 | 1270 | value = new NXSL_Value(dci->getInstance()); |
ba39fc61 | 1271 | } |
7de1151b | 1272 | else if (!_tcscmp(attr, _T("lastPollTime"))) |
bb51576f | 1273 | { |
7de1151b | 1274 | value = new NXSL_Value((INT64)dci->getLastPollTime()); |
bb51576f | 1275 | } |
7de1151b | 1276 | else if (!_tcscmp(attr, _T("name"))) |
d7877de4 | 1277 | { |
7de1151b | 1278 | value = new NXSL_Value(dci->getName()); |
d7877de4 | 1279 | } |
7de1151b | 1280 | else if (!_tcscmp(attr, _T("origin"))) |
bb51576f | 1281 | { |
4804be4e | 1282 | value = new NXSL_Value((LONG)dci->getOrigin()); |
7de1151b VK |
1283 | } |
1284 | else if (!_tcscmp(attr, _T("status"))) | |
1285 | { | |
1286 | value = new NXSL_Value((LONG)dci->getStatus()); | |
bb51576f | 1287 | } |
35f836fe | 1288 | else if (!_tcscmp(attr, _T("systemTag"))) |
bb51576f VK |
1289 | { |
1290 | value = new NXSL_Value(dci->getSystemTag()); | |
1291 | } | |
7de1151b VK |
1292 | else if (!_tcscmp(attr, _T("type"))) |
1293 | { | |
1294 | value = new NXSL_Value((LONG)dci->getType()); | |
1295 | } | |
bb51576f VK |
1296 | return value; |
1297 | } | |
1298 | ||
7de1151b VK |
1299 | /** |
1300 | * Implementation of "SNMP_Transport" class: constructor | |
1301 | */ | |
bdd1560b | 1302 | NXSL_SNMPTransportClass::NXSL_SNMPTransportClass() : NXSL_Class() |
e7c4e97b | 1303 | { |
c42b4551 | 1304 | _tcscpy(m_name, _T("SNMP_Transport")); |
e7c4e97b AK |
1305 | } |
1306 | ||
7de1151b VK |
1307 | /** |
1308 | * Implementation of "SNMP_Transport" class: get attribute | |
1309 | */ | |
e7c4e97b AK |
1310 | NXSL_Value *NXSL_SNMPTransportClass::getAttr(NXSL_Object *object, const TCHAR *attr) |
1311 | { | |
1312 | NXSL_Value *value = NULL; | |
1313 | SNMP_Transport *t; | |
1314 | ||
1315 | t = (SNMP_Transport*)object->getData(); | |
1316 | if (!_tcscmp(attr, _T("snmpVersion"))) | |
1317 | { | |
515c9d67 AK |
1318 | const TCHAR *versions[] = { _T("1"), _T("2c"), _T("3") }; |
1319 | value = new NXSL_Value((const TCHAR*)versions[t->getSnmpVersion()]); | |
e7c4e97b AK |
1320 | } |
1321 | ||
1322 | return value; | |
1323 | } | |
1324 | ||
7de1151b | 1325 | /** |
484e609d | 1326 | * Implementation of "SNMP_Transport" class: NXSL object destructor |
7de1151b | 1327 | */ |
bdd1560b VK |
1328 | void NXSL_SNMPTransportClass::onObjectDelete(NXSL_Object *object) |
1329 | { | |
1330 | delete (SNMP_Transport *)object->getData(); | |
1331 | } | |
1332 | ||
7de1151b | 1333 | /** |
484e609d | 1334 | * NXSL class SNMP_VarBind: constructor |
7de1151b | 1335 | */ |
bdd1560b | 1336 | NXSL_SNMPVarBindClass::NXSL_SNMPVarBindClass() : NXSL_Class() |
e7c4e97b | 1337 | { |
c42b4551 | 1338 | _tcscpy(m_name, _T("SNMP_VarBind")); |
e7c4e97b AK |
1339 | } |
1340 | ||
484e609d VK |
1341 | /** |
1342 | * NXSL class SNMP_VarBind: get attribute | |
1343 | */ | |
e7c4e97b AK |
1344 | NXSL_Value *NXSL_SNMPVarBindClass::getAttr(NXSL_Object *object, const TCHAR *attr) |
1345 | { | |
1346 | NXSL_Value *value = NULL; | |
f3d71512 | 1347 | SNMP_Variable *t = (SNMP_Variable *)object->getData(); |
e7c4e97b AK |
1348 | if (!_tcscmp(attr, _T("type"))) |
1349 | { | |
e0471fad | 1350 | value = new NXSL_Value((UINT32)t->getType()); |
e7c4e97b AK |
1351 | } |
1352 | else if (!_tcscmp(attr, _T("name"))) | |
1353 | { | |
9ceab287 | 1354 | value = new NXSL_Value(t->getName().toString()); |
e7c4e97b AK |
1355 | } |
1356 | else if (!_tcscmp(attr, _T("value"))) | |
1357 | { | |
f3d71512 | 1358 | TCHAR strValue[1024]; |
817dce5b | 1359 | value = new NXSL_Value(t->getValueAsString(strValue, 1024)); |
e7c4e97b | 1360 | } |
bdd1560b VK |
1361 | else if (!_tcscmp(attr, _T("printableValue"))) |
1362 | { | |
f3d71512 | 1363 | TCHAR strValue[1024]; |
bdd1560b VK |
1364 | bool convToHex = true; |
1365 | t->getValueAsPrintableString(strValue, 1024, &convToHex); | |
817dce5b | 1366 | value = new NXSL_Value(strValue); |
bdd1560b VK |
1367 | } |
1368 | else if (!_tcscmp(attr, _T("valueAsIp"))) | |
e7c4e97b | 1369 | { |
f3d71512 | 1370 | TCHAR strValue[128]; |
e0471fad | 1371 | t->getValueAsIPAddr(strValue); |
e7c4e97b AK |
1372 | value = new NXSL_Value(strValue); |
1373 | } | |
bdd1560b | 1374 | else if (!_tcscmp(attr, _T("valueAsMac"))) |
e7c4e97b | 1375 | { |
f3d71512 | 1376 | TCHAR strValue[128]; |
e0471fad | 1377 | t->getValueAsMACAddr(strValue); |
e7c4e97b AK |
1378 | value = new NXSL_Value(strValue); |
1379 | } | |
1380 | ||
1381 | return value; | |
1382 | } | |
bb51576f | 1383 | |
484e609d VK |
1384 | /** |
1385 | * NXSL class SNMP_VarBind: NXSL object desctructor | |
1386 | */ | |
bdd1560b VK |
1387 | void NXSL_SNMPVarBindClass::onObjectDelete(NXSL_Object *object) |
1388 | { | |
1389 | delete (SNMP_Variable *)object->getData(); | |
1390 | } | |
1391 | ||
49fbe41f VK |
1392 | /** |
1393 | * Class objects | |
1394 | */ | |
459f4057 | 1395 | NXSL_AlarmClass g_nxslAlarmClass; |
e4926628 VK |
1396 | NXSL_ChassisClass g_nxslChassisClass; |
1397 | NXSL_ClusterClass g_nxslClusterClass; | |
fe400f32 VK |
1398 | NXSL_DciClass g_nxslDciClass; |
1399 | NXSL_EventClass g_nxslEventClass; | |
1400 | NXSL_InterfaceClass g_nxslInterfaceClass; | |
23015e41 | 1401 | NXSL_MobileDeviceClass g_nxslMobileDeviceClass; |
541a3ebc | 1402 | NXSL_NetObjClass g_nxslNetObjClass; |
5039dede | 1403 | NXSL_NodeClass g_nxslNodeClass; |
e7c4e97b | 1404 | NXSL_SNMPTransportClass g_nxslSnmpTransportClass; |
fe400f32 VK |
1405 | NXSL_SNMPVarBindClass g_nxslSnmpVarBindClass; |
1406 | NXSL_ZoneClass g_nxslZoneClass; |