2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2017 Victor Kirhenshtein
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.
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.
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.
19 ** File: nxsl_classes.cpp
28 NXSL_METHOD_DEFINITION(NetObj
, clearGeoLocation
)
30 ((NetObj
*)object
->getData())->setGeoLocation(GeoLocation());
31 *result
= new NXSL_Value
;
38 NXSL_METHOD_DEFINITION(NetObj
, setGeoLocation
)
40 if (!argv
[0]->isObject())
41 return NXSL_ERR_NOT_OBJECT
;
43 NXSL_Object
*o
= argv
[0]->getValueAsObject();
44 if (_tcscmp(o
->getClass()->getName(), g_nxslGeoLocationClass
.getName()))
45 return NXSL_ERR_BAD_CLASS
;
47 GeoLocation
*gl
= (GeoLocation
*)o
->getData();
48 ((NetObj
*)object
->getData())->setGeoLocation(*gl
);
49 *result
= new NXSL_Value
;
56 NXSL_METHOD_DEFINITION(NetObj
, setMapImage
)
58 if (!argv
[0]->isString())
59 return NXSL_ERR_NOT_STRING
;
62 DB_HANDLE hdb
= DBConnectionPoolAcquireConnection();
63 DB_STATEMENT hStmt
= DBPrepare(hdb
, _T("SELECT guid FROM images WHERE upper(guid)=upper(?) OR upper(name)=upper(?)"));
66 DBBind(hStmt
, 1, DB_SQLTYPE_VARCHAR
, argv
[0]->getValueAsCString(), DB_BIND_STATIC
);
67 DBBind(hStmt
, 2, DB_SQLTYPE_VARCHAR
, argv
[0]->getValueAsCString(), DB_BIND_STATIC
);
68 DB_RESULT hResult
= DBSelectPrepared(hStmt
);
71 if (DBGetNumRows(hResult
) > 0)
73 uuid guid
= DBGetFieldGUID(hResult
, 0, 0);
74 ((NetObj
*)object
->getData())->setMapImage(guid
);
76 DBFreeResult(hResult
);
78 DBFreeStatement(hStmt
);
80 DBConnectionPoolReleaseConnection(hdb
);
81 *result
= new NXSL_Value(success ?
1 : 0);
86 * setStatusCalculation(type, ...)
88 NXSL_METHOD_DEFINITION(NetObj
, setStatusCalculation
)
91 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
93 if (!argv
[0]->isInteger())
94 return NXSL_ERR_NOT_INTEGER
;
97 int method
= argv
[0]->getValueAsInt32();
98 NetObj
*netobj
= (NetObj
*)object
->getData();
101 case SA_CALCULATE_DEFAULT
:
102 case SA_CALCULATE_MOST_CRITICAL
:
103 netobj
->setStatusCalculation(method
);
105 case SA_CALCULATE_SINGLE_THRESHOLD
:
107 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
108 if (!argv
[1]->isInteger())
109 return NXSL_ERR_NOT_INTEGER
;
110 netobj
->setStatusCalculation(method
, argv
[1]->getValueAsInt32());
112 case SA_CALCULATE_MULTIPLE_THRESHOLDS
:
114 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
115 for(int i
= 1; i
<= 4; i
++)
117 if (!argv
[i
]->isInteger())
118 return NXSL_ERR_NOT_INTEGER
;
120 netobj
->setStatusCalculation(method
, argv
[1]->getValueAsInt32(), argv
[2]->getValueAsInt32(), argv
[3]->getValueAsInt32(), argv
[4]->getValueAsInt32());
123 success
= 0; // invalid method
126 *result
= new NXSL_Value(success
);
131 * setStatusPropagation(type, ...)
133 NXSL_METHOD_DEFINITION(NetObj
, setStatusPropagation
)
136 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
138 if (!argv
[0]->isInteger())
139 return NXSL_ERR_NOT_INTEGER
;
142 int method
= argv
[0]->getValueAsInt32();
143 NetObj
*netobj
= (NetObj
*)object
->getData();
146 case SA_PROPAGATE_DEFAULT
:
147 case SA_PROPAGATE_UNCHANGED
:
148 netobj
->setStatusPropagation(method
);
150 case SA_PROPAGATE_FIXED
:
151 case SA_PROPAGATE_RELATIVE
:
153 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
154 if (!argv
[1]->isInteger())
155 return NXSL_ERR_NOT_INTEGER
;
156 netobj
->setStatusPropagation(method
, argv
[1]->getValueAsInt32());
158 case SA_PROPAGATE_TRANSLATED
:
160 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
161 for(int i
= 1; i
<= 4; i
++)
163 if (!argv
[i
]->isInteger())
164 return NXSL_ERR_NOT_INTEGER
;
166 netobj
->setStatusPropagation(method
, argv
[1]->getValueAsInt32(), argv
[2]->getValueAsInt32(), argv
[3]->getValueAsInt32(), argv
[4]->getValueAsInt32());
169 success
= 0; // invalid method
172 *result
= new NXSL_Value(success
);
177 * NXSL class NetObj: constructor
179 NXSL_NetObjClass
::NXSL_NetObjClass() : NXSL_Class()
181 setName(_T("NetObj"));
183 NXSL_REGISTER_METHOD(NetObj
, clearGeoLocation
, 0);
184 NXSL_REGISTER_METHOD(NetObj
, setGeoLocation
, 1);
185 NXSL_REGISTER_METHOD(NetObj
, setMapImage
, 1);
186 NXSL_REGISTER_METHOD(NetObj
, setStatusCalculation
, -1);
187 NXSL_REGISTER_METHOD(NetObj
, setStatusPropagation
, -1);
191 * Object creation handler
193 void NXSL_NetObjClass
::onObjectCreate(NXSL_Object
*object
)
195 ((NetObj
*)object
->getData())->incRefCount();
199 * Object destruction handler
201 void NXSL_NetObjClass
::onObjectDelete(NXSL_Object
*object
)
203 ((NetObj
*)object
->getData())->decRefCount();
207 * NXSL class NetObj: get attribute
209 NXSL_Value
*NXSL_NetObjClass
::getAttr(NXSL_Object
*_object
, const TCHAR
*attr
)
211 NXSL_Value
*value
= NULL
;
212 NetObj
*object
= (NetObj
*)_object
->getData();
213 if (!_tcscmp(attr
, _T("alarms")))
215 ObjectArray
<Alarm
> *alarms
= GetAlarms(object
->getId(), true);
216 alarms
->setOwner(false);
217 NXSL_Array
*array
= new NXSL_Array
;
218 for(int i
= 0; i
< alarms
->size(); i
++)
219 array
->append(new NXSL_Value(new NXSL_Object(&g_nxslAlarmClass
, alarms
->get(i
))));
220 value
= new NXSL_Value(array
);
223 else if (!_tcscmp(attr
, _T("city")))
225 value
= new NXSL_Value(object
->getPostalAddress()->getCity());
227 else if (!_tcscmp(attr
, _T("comments")))
229 value
= new NXSL_Value(object
->getComments());
231 else if (!_tcscmp(attr
, _T("country")))
233 value
= new NXSL_Value(object
->getPostalAddress()->getCountry());
235 else if (!_tcscmp(attr
, _T("customAttributes")))
237 value
= object
->getCustomAttributesForNXSL();
239 else if (!_tcscmp(attr
, _T("geolocation")))
241 value
= NXSL_GeoLocationClass
::createObject(object
->getGeoLocation());
243 else if (!_tcscmp(attr
, _T("guid")))
246 value
= new NXSL_Value(object
->getGuid().toString(buffer
));
248 else if (!_tcscmp(attr
, _T("id")))
250 value
= new NXSL_Value(object
->getId());
252 else if (!_tcscmp(attr
, _T("ipAddr")))
255 GetObjectIpAddress(object
).toString(buffer
);
256 value
= new NXSL_Value(buffer
);
258 else if (!_tcscmp(attr
, _T("mapImage")))
261 value
= new NXSL_Value(object
->getMapImage().toString(buffer
));
263 else if (!_tcscmp(attr
, _T("name")))
265 value
= new NXSL_Value(object
->getName());
267 else if (!_tcscmp(attr
, _T("postcode")))
269 value
= new NXSL_Value(object
->getPostalAddress()->getPostCode());
271 else if (!_tcscmp(attr
, _T("status")))
273 value
= new NXSL_Value((LONG
)object
->getStatus());
275 else if (!_tcscmp(attr
, _T("streetAddress")))
277 value
= new NXSL_Value(object
->getPostalAddress()->getStreetAddress());
279 else if (!_tcscmp(attr
, _T("type")))
281 value
= new NXSL_Value((LONG
)object
->getObjectClass());
285 value
= object
->getCustomAttributeForNXSL(attr
);
291 * NXSL class Zone: constructor
293 NXSL_ZoneClass
::NXSL_ZoneClass() : NXSL_NetObjClass()
299 * NXSL class Zone: get attribute
301 NXSL_Value
*NXSL_ZoneClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
303 NXSL_Value
*value
= NXSL_NetObjClass
::getAttr(object
, attr
);
307 Zone
*zone
= (Zone
*)object
->getData();
308 if (!_tcscmp(attr
, _T("proxyNode")))
310 Node
*node
= (Node
*)FindObjectById(zone
->getProxyNodeId(), OBJECT_NODE
);
311 value
= (node
!= NULL
) ?
new NXSL_Value(new NXSL_Object(&g_nxslNodeClass
, node
)) : new NXSL_Value();
313 else if (!_tcscmp(attr
, _T("proxyNodeId")))
315 value
= new NXSL_Value(zone
->getProxyNodeId());
317 else if (!_tcscmp(attr
, _T("uin")))
319 value
= new NXSL_Value(zone
->getUIN());
325 * Generic implementation for flag changing methods
327 static int ChangeFlagMethod(NXSL_Object
*object
, NXSL_Value
*arg
, NXSL_Value
**result
, UINT32 flag
)
329 if (!arg
->isInteger())
330 return NXSL_ERR_NOT_INTEGER
;
332 Node
*node
= (Node
*)object
->getData();
333 if (arg
->getValueAsInt32())
334 node
->clearFlag(flag
);
338 *result
= new NXSL_Value
;
343 * enableAgent(enabled) method
345 NXSL_METHOD_DEFINITION(Node
, enableAgent
)
347 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_NXCP
);
351 * enableConfigurationPolling(enabled) method
353 NXSL_METHOD_DEFINITION(Node
, enableConfigurationPolling
)
355 return ChangeFlagMethod(object
, argv
[0], result
, DCF_DISABLE_CONF_POLL
);
359 * enableDiscoveryPolling(enabled) method
361 NXSL_METHOD_DEFINITION(Node
, enableDiscoveryPolling
)
363 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_DISCOVERY_POLL
);
367 * enableIcmp(enabled) method
369 NXSL_METHOD_DEFINITION(Node
, enableIcmp
)
371 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_ICMP
);
375 * enableRoutingTablePolling(enabled) method
377 NXSL_METHOD_DEFINITION(Node
, enableRoutingTablePolling
)
379 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_ROUTE_POLL
);
383 * enableSnmp(enabled) method
385 NXSL_METHOD_DEFINITION(Node
, enableSnmp
)
387 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_SNMP
);
391 * enableStatusPolling(enabled) method
393 NXSL_METHOD_DEFINITION(Node
, enableStatusPolling
)
395 return ChangeFlagMethod(object
, argv
[0], result
, DCF_DISABLE_STATUS_POLL
);
399 * enableTopologyPolling(enabled) method
401 NXSL_METHOD_DEFINITION(Node
, enableTopologyPolling
)
403 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_TOPOLOGY_POLL
);
407 * NXSL class Node: constructor
409 NXSL_NodeClass
::NXSL_NodeClass() : NXSL_NetObjClass()
413 NXSL_REGISTER_METHOD(Node
, enableAgent
, 1);
414 NXSL_REGISTER_METHOD(Node
, enableConfigurationPolling
, 1);
415 NXSL_REGISTER_METHOD(Node
, enableDiscoveryPolling
, 1);
416 NXSL_REGISTER_METHOD(Node
, enableIcmp
, 1);
417 NXSL_REGISTER_METHOD(Node
, enableRoutingTablePolling
, 1);
418 NXSL_REGISTER_METHOD(Node
, enableSnmp
, 1);
419 NXSL_REGISTER_METHOD(Node
, enableStatusPolling
, 1);
420 NXSL_REGISTER_METHOD(Node
, enableTopologyPolling
, 1);
424 * NXSL class Node: get attribute
426 NXSL_Value
*NXSL_NodeClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
428 NXSL_Value
*value
= NXSL_NetObjClass
::getAttr(object
, attr
);
432 Node
*node
= (Node
*)object
->getData();
433 if (!_tcscmp(attr
, _T("agentVersion")))
435 value
= new NXSL_Value(node
->getAgentVersion());
437 else if (!_tcscmp(attr
, _T("bootTime")))
439 value
= new NXSL_Value((INT64
)node
->getBootTime());
441 else if (!_tcscmp(attr
, _T("bridgeBaseAddress")))
444 value
= new NXSL_Value(BinToStr(node
->getBridgeId(), MAC_ADDR_LENGTH
, buffer
));
446 else if (!_tcscmp(attr
, _T("components")))
448 value
= new NXSL_Value(new NXSL_Object(&g_nxslComponentClass
, node
->getComponents()->getRoot()));
450 else if (!_tcscmp(attr
, _T("driver")))
452 value
= new NXSL_Value(node
->getDriverName());
454 else if (!_tcscmp(attr
, _T("flags")))
456 value
= new NXSL_Value(node
->getFlags());
458 else if (!_tcscmp(attr
, _T("isAgent")))
460 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_NATIVE_AGENT
) ?
1 : 0));
462 else if (!_tcscmp(attr
, _T("isBridge")))
464 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_BRIDGE
) ?
1 : 0));
466 else if (!_tcscmp(attr
, _T("isCDP")))
468 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_CDP
) ?
1 : 0));
470 else if (!_tcscmp(attr
, _T("isInMaintenanceMode")))
472 value
= new NXSL_Value((LONG
)(node
->isInMaintenanceMode() ?
1 : 0));
474 else if (!_tcscmp(attr
, _T("isLLDP")))
476 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_LLDP
) ?
1 : 0));
478 else if (!_tcscmp(attr
, _T("isLocalMgmt")) || !_tcscmp(attr
, _T("isLocalManagement")))
480 value
= new NXSL_Value((LONG
)((node
->isLocalManagement()) ?
1 : 0));
482 else if (!_tcscmp(attr
, _T("isPAE")) || !_tcscmp(attr
, _T("is802_1x")))
484 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_8021X
) ?
1 : 0));
486 else if (!_tcscmp(attr
, _T("isPrinter")))
488 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_PRINTER
) ?
1 : 0));
490 else if (!_tcscmp(attr
, _T("isRouter")))
492 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_ROUTER
) ?
1 : 0));
494 else if (!_tcscmp(attr
, _T("isSMCLP")))
496 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_SMCLP
) ?
1 : 0));
498 else if (!_tcscmp(attr
, _T("isSNMP")))
500 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_SNMP
) ?
1 : 0));
502 else if (!_tcscmp(attr
, _T("isSONMP")))
504 value
= new NXSL_Value((LONG
)((node
->getCapabilities() & NC_IS_NDP
) ?
1 : 0));
506 else if (!_tcscmp(attr
, _T("lastAgentCommTime")))
508 value
= new NXSL_Value((INT64
)node
->getLastAgentCommTime());
510 else if (!_tcscmp(attr
, _T("platformName")))
512 value
= new NXSL_Value(node
->getPlatformName());
514 else if (!_tcscmp(attr
, _T("rack")))
516 Rack
*rack
= (Rack
*)FindObjectById(node
->getRackId(), OBJECT_RACK
);
519 value
= rack
->createNXSLObject();
523 value
= new NXSL_Value
;
526 else if (!_tcscmp(attr
, _T("rackId")))
528 value
= new NXSL_Value(node
->getRackId());
530 else if (!_tcscmp(attr
, _T("rackHeight")))
532 value
= new NXSL_Value(node
->getRackHeight());
534 else if (!_tcscmp(attr
, _T("rackPosition")))
536 value
= new NXSL_Value(node
->getRackPosition());
538 else if (!_tcscmp(attr
, _T("runtimeFlags")))
540 value
= new NXSL_Value(node
->getRuntimeFlags());
542 else if (!_tcscmp(attr
, _T("snmpOID")))
544 value
= new NXSL_Value(node
->getSNMPObjectId());
546 else if (!_tcscmp(attr
, _T("snmpSysContact")))
548 value
= new NXSL_Value(node
->getSysContact());
550 else if (!_tcscmp(attr
, _T("snmpSysLocation")))
552 value
= new NXSL_Value(node
->getSysLocation());
554 else if (!_tcscmp(attr
, _T("snmpSysName")))
556 value
= new NXSL_Value(node
->getSysName());
558 else if (!_tcscmp(attr
, _T("snmpVersion")))
560 value
= new NXSL_Value((LONG
)node
->getSNMPVersion());
562 else if (!_tcscmp(attr
, _T("subType")))
564 value
= new NXSL_Value(node
->getSubType());
566 else if (!_tcscmp(attr
, _T("sysDescription")))
568 value
= new NXSL_Value(node
->getSysDescription());
570 else if (!_tcscmp(attr
, _T("type")))
572 value
= new NXSL_Value((INT32
)node
->getType());
574 else if (!_tcscmp(attr
, _T("zone")))
576 if (g_flags
& AF_ENABLE_ZONING
)
578 Zone
*zone
= FindZoneByUIN(node
->getZoneUIN());
581 value
= new NXSL_Value(new NXSL_Object(&g_nxslZoneClass
, zone
));
585 value
= new NXSL_Value
;
590 value
= new NXSL_Value
;
593 else if (!_tcscmp(attr
, _T("zoneUIN")))
595 value
= new NXSL_Value(node
->getZoneUIN());
601 * Interface::setExcludeFromTopology(enabled) method
603 NXSL_METHOD_DEFINITION(Interface
, setExcludeFromTopology
)
605 if (!argv
[0]->isInteger())
606 return NXSL_ERR_NOT_INTEGER
;
608 Interface
*iface
= (Interface
*)object
->getData();
609 iface
->setExcludeFromTopology(argv
[0]->getValueAsInt32() != 0);
610 *result
= new NXSL_Value
;
615 * Interface::setExpectedState(state) method
617 NXSL_METHOD_DEFINITION(Interface
, setExpectedState
)
620 if (argv
[0]->isInteger())
622 state
= argv
[0]->getValueAsInt32();
624 else if (argv
[0]->isString())
626 static const TCHAR
*stateNames
[] = { _T("UP"), _T("DOWN"), _T("IGNORE"), NULL
};
627 const TCHAR
*name
= argv
[0]->getValueAsCString();
628 for(state
= 0; stateNames
[state
] != NULL
; state
++)
629 if (!_tcsicmp(stateNames
[state
], name
))
634 return NXSL_ERR_NOT_STRING
;
637 if ((state
>= 0) && (state
<= 2))
638 ((Interface
*)object
->getData())->setExpectedState(state
);
640 *result
= new NXSL_Value
;
645 * NXSL class Interface: constructor
647 NXSL_InterfaceClass
::NXSL_InterfaceClass() : NXSL_NetObjClass()
649 setName(_T("Interface"));
651 NXSL_REGISTER_METHOD(Interface
, setExcludeFromTopology
, 1);
652 NXSL_REGISTER_METHOD(Interface
, setExpectedState
, 1);
656 * NXSL class Interface: get attribute
658 NXSL_Value
*NXSL_InterfaceClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
660 NXSL_Value
*value
= NXSL_NetObjClass
::getAttr(object
, attr
);
664 Interface
*iface
= (Interface
*)object
->getData();
665 if (!_tcscmp(attr
, _T("adminState")))
667 value
= new NXSL_Value((LONG
)iface
->getAdminState());
669 else if (!_tcscmp(attr
, _T("alias")))
671 value
= new NXSL_Value(iface
->getAlias());
673 else if (!_tcscmp(attr
, _T("bridgePortNumber")))
675 value
= new NXSL_Value(iface
->getBridgePortNumber());
677 else if (!_tcscmp(attr
, _T("description")))
679 value
= new NXSL_Value(iface
->getDescription());
681 else if (!_tcscmp(attr
, _T("dot1xBackendAuthState")))
683 value
= new NXSL_Value((LONG
)iface
->getDot1xBackendAuthState());
685 else if (!_tcscmp(attr
, _T("dot1xPaeAuthState")))
687 value
= new NXSL_Value((LONG
)iface
->getDot1xPaeAuthState());
689 else if (!_tcscmp(attr
, _T("expectedState")))
691 value
= new NXSL_Value((iface
->getFlags() & IF_EXPECTED_STATE_MASK
) >> 28);
693 else if (!_tcscmp(attr
, _T("flags")))
695 value
= new NXSL_Value(iface
->getFlags());
697 else if (!_tcscmp(attr
, _T("ifIndex")))
699 value
= new NXSL_Value(iface
->getIfIndex());
701 else if (!_tcscmp(attr
, _T("ifType")))
703 value
= new NXSL_Value(iface
->getIfType());
705 else if (!_tcscmp(attr
, _T("ipAddressList")))
707 const InetAddressList
*addrList
= iface
->getIpAddressList();
708 NXSL_Array
*a
= new NXSL_Array();
709 for(int i
= 0; i
< addrList
->size(); i
++)
711 a
->append(new NXSL_Value(NXSL_InetAddressClass
::createObject(addrList
->get(i
))));
713 value
= new NXSL_Value(a
);
715 else if (!_tcscmp(attr
, _T("ipNetMask")))
717 value
= new NXSL_Value(iface
->getIpAddressList()->getFirstUnicastAddress().getMaskBits());
719 else if (!_tcscmp(attr
, _T("isExcludedFromTopology")))
721 value
= new NXSL_Value((LONG
)(iface
->isExcludedFromTopology() ?
1 : 0));
723 else if (!_tcscmp(attr
, _T("isLoopback")))
725 value
= new NXSL_Value((LONG
)(iface
->isLoopback() ?
1 : 0));
727 else if (!_tcscmp(attr
, _T("isManuallyCreated")))
729 value
= new NXSL_Value((LONG
)(iface
->isManuallyCreated() ?
1 : 0));
731 else if (!_tcscmp(attr
, _T("isPhysicalPort")))
733 value
= new NXSL_Value((LONG
)(iface
->isPhysicalPort() ?
1 : 0));
735 else if (!_tcscmp(attr
, _T("macAddr")))
738 value
= new NXSL_Value(BinToStr(iface
->getMacAddr(), MAC_ADDR_LENGTH
, buffer
));
740 else if (!_tcscmp(attr
, _T("mtu")))
742 value
= new NXSL_Value(iface
->getMTU());
744 else if (!_tcscmp(attr
, _T("node")))
746 Node
*parentNode
= iface
->getParentNode();
747 if (parentNode
!= NULL
)
749 value
= new NXSL_Value(new NXSL_Object(&g_nxslNodeClass
, parentNode
));
753 value
= new NXSL_Value
;
756 else if (!_tcscmp(attr
, _T("operState")))
758 value
= new NXSL_Value((LONG
)iface
->getOperState());
760 else if (!_tcscmp(attr
, _T("peerInterface")))
762 Interface
*peerIface
= (Interface
*)FindObjectById(iface
->getPeerInterfaceId(), OBJECT_INTERFACE
);
763 if (peerIface
!= NULL
)
765 if (g_flags
& AF_CHECK_TRUSTED_NODES
)
767 Node
*parentNode
= iface
->getParentNode();
768 Node
*peerNode
= peerIface
->getParentNode();
769 if ((parentNode
!= NULL
) && (peerNode
!= NULL
))
771 if (peerNode
->isTrustedNode(parentNode
->getId()))
773 value
= new NXSL_Value(new NXSL_Object(&g_nxslInterfaceClass
, peerIface
));
777 // No access, return null
778 value
= new NXSL_Value
;
779 DbgPrintf(4, _T("NXSL::Interface::peerInterface(%s [%d]): access denied for node %s [%d]"),
780 iface
->getName(), iface
->getId(), peerNode
->getName(), peerNode
->getId());
785 value
= new NXSL_Value
;
786 DbgPrintf(4, _T("NXSL::Interface::peerInterface(%s [%d]): parentNode=%p peerNode=%p"), iface
->getName(), iface
->getId(), parentNode
, peerNode
);
791 value
= new NXSL_Value(new NXSL_Object(&g_nxslInterfaceClass
, peerIface
));
796 value
= new NXSL_Value
;
799 else if (!_tcscmp(attr
, _T("peerNode")))
801 Node
*peerNode
= (Node
*)FindObjectById(iface
->getPeerNodeId(), OBJECT_NODE
);
802 if (peerNode
!= NULL
)
804 if (g_flags
& AF_CHECK_TRUSTED_NODES
)
806 Node
*parentNode
= iface
->getParentNode();
807 if ((parentNode
!= NULL
) && (peerNode
->isTrustedNode(parentNode
->getId())))
809 value
= new NXSL_Value(new NXSL_Object(&g_nxslNodeClass
, peerNode
));
813 // No access, return null
814 value
= new NXSL_Value
;
815 DbgPrintf(4, _T("NXSL::Interface::peerNode(%s [%d]): access denied for node %s [%d]"),
816 iface
->getName(), iface
->getId(), peerNode
->getName(), peerNode
->getId());
821 value
= new NXSL_Value(new NXSL_Object(&g_nxslNodeClass
, peerNode
));
826 value
= new NXSL_Value
;
829 else if (!_tcscmp(attr
, _T("port")))
831 value
= new NXSL_Value(iface
->getPortNumber());
833 else if (!_tcscmp(attr
, _T("slot")))
835 value
= new NXSL_Value(iface
->getSlotNumber());
837 else if (!_tcscmp(attr
, _T("speed")))
839 value
= new NXSL_Value(iface
->getSpeed());
841 else if (!_tcscmp(attr
, _T("zone")))
843 if (g_flags
& AF_ENABLE_ZONING
)
845 Zone
*zone
= FindZoneByUIN(iface
->getZoneUIN());
848 value
= new NXSL_Value(new NXSL_Object(&g_nxslZoneClass
, zone
));
852 value
= new NXSL_Value
;
857 value
= new NXSL_Value
;
860 else if (!_tcscmp(attr
, _T("zoneUIN")))
862 value
= new NXSL_Value(iface
->getZoneUIN());
868 * NXSL class Mobile Device: constructor
870 NXSL_MobileDeviceClass
::NXSL_MobileDeviceClass() : NXSL_NetObjClass()
872 setName(_T("MobileDevice"));
876 * NXSL class Mobile Device: get attribute
878 NXSL_Value
*NXSL_MobileDeviceClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
880 NXSL_Value
*value
= NXSL_NetObjClass
::getAttr(object
, attr
);
884 MobileDevice
*mobDevice
= (MobileDevice
*)object
->getData();
885 if (!_tcscmp(attr
, _T("deviceId")))
887 value
= new NXSL_Value(mobDevice
->getDeviceId());
889 else if (!_tcscmp(attr
, _T("vendor")))
891 value
= new NXSL_Value(mobDevice
->getVendor());
893 else if (!_tcscmp(attr
, _T("model")))
895 value
= new NXSL_Value(mobDevice
->getModel());
897 else if (!_tcscmp(attr
, _T("serialNumber")))
899 value
= new NXSL_Value(mobDevice
->getSerialNumber());
901 else if (!_tcscmp(attr
, _T("osName")))
903 value
= new NXSL_Value(mobDevice
->getOsName());
905 else if (!_tcscmp(attr
, _T("osVersion")))
907 value
= new NXSL_Value(mobDevice
->getOsVersion());
909 else if (!_tcscmp(attr
, _T("userId")))
911 value
= new NXSL_Value(mobDevice
->getUserId());
913 else if (!_tcscmp(attr
, _T("batteryLevel")))
915 value
= new NXSL_Value(mobDevice
->getBatteryLevel());
922 * NXSL class "Chassis" constructor
924 NXSL_ChassisClass
::NXSL_ChassisClass() : NXSL_NetObjClass()
926 setName(_T("Chassis"));
930 * NXSL class "Chassis" attributes
932 NXSL_Value
*NXSL_ChassisClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
934 NXSL_Value
*value
= NXSL_NetObjClass
::getAttr(object
, attr
);
938 Chassis
*chassis
= (Chassis
*)object
->getData();
939 if (!_tcscmp(attr
, _T("controller")))
941 Node
*node
= (Node
*)FindObjectById(chassis
->getControllerId(), OBJECT_NODE
);
944 value
= node
->createNXSLObject();
948 value
= new NXSL_Value
;
951 else if (!_tcscmp(attr
, _T("controllerId")))
953 value
= new NXSL_Value(chassis
->getControllerId());
955 else if (!_tcscmp(attr
, _T("flags")))
957 value
= new NXSL_Value(chassis
->getFlags());
959 else if (!_tcscmp(attr
, _T("rack")))
961 Rack
*rack
= (Rack
*)FindObjectById(chassis
->getRackId(), OBJECT_RACK
);
964 value
= rack
->createNXSLObject();
968 value
= new NXSL_Value
;
971 else if (!_tcscmp(attr
, _T("rackId")))
973 value
= new NXSL_Value(chassis
->getRackId());
975 else if (!_tcscmp(attr
, _T("rackHeight")))
977 value
= new NXSL_Value(chassis
->getRackHeight());
979 else if (!_tcscmp(attr
, _T("rackPosition")))
981 value
= new NXSL_Value(chassis
->getRackPosition());
987 * Cluster::getResourceOwner() method
989 NXSL_METHOD_DEFINITION(Cluster
, getResourceOwner
)
991 if (!argv
[0]->isString())
992 return NXSL_ERR_NOT_STRING
;
994 UINT32 ownerId
= ((Cluster
*)object
->getData())->getResourceOwner(argv
[0]->getValueAsCString());
997 NetObj
*object
= FindObjectById(ownerId
);
998 *result
= (object
!= NULL
) ? object
->createNXSLObject() : new NXSL_Value();
1002 *result
= new NXSL_Value();
1008 * NXSL class "Cluster" constructor
1010 NXSL_ClusterClass
::NXSL_ClusterClass() : NXSL_NetObjClass()
1012 setName(_T("Cluster"));
1014 NXSL_REGISTER_METHOD(Cluster
, getResourceOwner
, 1);
1018 * NXSL class "Cluster" attributes
1020 NXSL_Value
*NXSL_ClusterClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1022 NXSL_Value
*value
= NXSL_NetObjClass
::getAttr(object
, attr
);
1026 Cluster
*cluster
= (Cluster
*)object
->getData();
1027 if (!_tcscmp(attr
, _T("nodes")))
1029 value
= new NXSL_Value(cluster
->getNodesForNXSL());
1031 else if (!_tcscmp(attr
, _T("zone")))
1033 if (g_flags
& AF_ENABLE_ZONING
)
1035 Zone
*zone
= FindZoneByUIN(cluster
->getZoneUIN());
1038 value
= zone
->createNXSLObject();
1042 value
= new NXSL_Value
;
1047 value
= new NXSL_Value
;
1050 else if (!_tcscmp(attr
, _T("zoneUIN")))
1052 value
= new NXSL_Value(cluster
->getZoneUIN());
1058 * Container::setAutoBindMode() method
1060 NXSL_METHOD_DEFINITION(Container
, setAutoBindMode
)
1062 if (!argv
[0]->isInteger() || !argv
[1]->isInteger())
1063 return NXSL_ERR_NOT_INTEGER
;
1065 ((Container
*)object
->getData())->setAutoBindMode(argv
[0]->getValueAsBoolean(), argv
[1]->getValueAsBoolean());
1066 *result
= new NXSL_Value();
1071 * Container::setAutoBindScript() method
1073 NXSL_METHOD_DEFINITION(Container
, setAutoBindScript
)
1075 if (!argv
[0]->isString())
1076 return NXSL_ERR_NOT_STRING
;
1078 ((Container
*)object
->getData())->setAutoBindFilter(argv
[0]->getValueAsCString());
1079 *result
= new NXSL_Value();
1084 * NXSL class "Container" constructor
1086 NXSL_ContainerClass
::NXSL_ContainerClass() : NXSL_NetObjClass()
1088 setName(_T("Container"));
1090 NXSL_REGISTER_METHOD(Container
, setAutoBindMode
, 2);
1091 NXSL_REGISTER_METHOD(Container
, setAutoBindScript
, 1);
1095 * NXSL class "Cluster" attributes
1097 NXSL_Value
*NXSL_ContainerClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1099 NXSL_Value
*value
= NXSL_NetObjClass
::getAttr(object
, attr
);
1103 Container
*container
= (Container
*)object
->getData();
1104 if (!_tcscmp(attr
, _T("autoBindScript")))
1106 const TCHAR
*script
= container
->getAutoBindScriptSource();
1107 value
= new NXSL_Value(CHECK_NULL_EX(script
));
1109 else if (!_tcscmp(attr
, _T("isAutoBindEnabled")))
1111 value
= new NXSL_Value(container
->isAutoBindEnabled() ?
1 : 0);
1113 else if (!_tcscmp(attr
, _T("isAutoUnbindEnabled")))
1115 value
= new NXSL_Value(container
->isAutoUnbindEnabled() ?
1 : 0);
1121 * Event::setMessage() method
1123 NXSL_METHOD_DEFINITION(Event
, setMessage
)
1125 if (!argv
[0]->isString())
1126 return NXSL_ERR_NOT_STRING
;
1128 Event
*event
= (Event
*)object
->getData();
1129 event
->setMessage(argv
[0]->getValueAsCString());
1130 *result
= new NXSL_Value();
1135 * Event::setSeverity() method
1137 NXSL_METHOD_DEFINITION(Event
, setSeverity
)
1139 if (!argv
[0]->isInteger())
1140 return NXSL_ERR_NOT_STRING
;
1142 int s
= argv
[0]->getValueAsInt32();
1143 if ((s
>= SEVERITY_NORMAL
) && (s
<= SEVERITY_CRITICAL
))
1145 Event
*event
= (Event
*)object
->getData();
1146 event
->setSeverity(s
);
1148 *result
= new NXSL_Value();
1153 * Event::setUserTag() method
1155 NXSL_METHOD_DEFINITION(Event
, setUserTag
)
1157 if (!argv
[0]->isString())
1158 return NXSL_ERR_NOT_STRING
;
1160 Event
*event
= (Event
*)object
->getData();
1161 event
->setUserTag(argv
[0]->getValueAsCString());
1162 *result
= new NXSL_Value();
1167 * Event::toJson() method
1169 NXSL_METHOD_DEFINITION(Event
, toJson
)
1171 Event
*event
= (Event
*)object
->getData();
1172 *result
= new NXSL_Value(event
->createJson());
1177 * NXSL class Event: constructor
1179 NXSL_EventClass
::NXSL_EventClass() : NXSL_Class()
1181 setName(_T("Event"));
1183 NXSL_REGISTER_METHOD(Event
, setMessage
, 1);
1184 NXSL_REGISTER_METHOD(Event
, setSeverity
, 1);
1185 NXSL_REGISTER_METHOD(Event
, setUserTag
, 1);
1186 NXSL_REGISTER_METHOD(Event
, toJson
, 0);
1190 * NXSL class Event: get attribute
1192 NXSL_Value
*NXSL_EventClass
::getAttr(NXSL_Object
*pObject
, const TCHAR
*attr
)
1194 NXSL_Value
*value
= NULL
;
1196 Event
*event
= (Event
*)pObject
->getData();
1197 if (!_tcscmp(attr
, _T("code")))
1199 value
= new NXSL_Value(event
->getCode());
1201 else if (!_tcscmp(attr
, _T("customMessage")))
1203 value
= new NXSL_Value(event
->getCustomMessage());
1205 else if (!_tcscmp(attr
, _T("id")))
1207 value
= new NXSL_Value(event
->getId());
1209 else if (!_tcscmp(attr
, _T("message")))
1211 value
= new NXSL_Value(event
->getMessage());
1213 else if (!_tcscmp(attr
, _T("name")))
1215 value
= new NXSL_Value(event
->getName());
1217 else if (!_tcscmp(attr
, _T("parameters")))
1219 NXSL_Array
*array
= new NXSL_Array
;
1220 for(int i
= 0; i
< event
->getParametersCount(); i
++)
1221 array
->set(i
+ 1, new NXSL_Value(event
->getParameter(i
)));
1222 value
= new NXSL_Value(array
);
1224 else if (!_tcscmp(attr
, _T("severity")))
1226 value
= new NXSL_Value(event
->getSeverity());
1228 else if (!_tcscmp(attr
, _T("source")))
1230 NetObj
*object
= FindObjectById(event
->getSourceId());
1231 value
= (object
!= NULL
) ? object
->createNXSLObject() : new NXSL_Value();
1233 else if (!_tcscmp(attr
, _T("sourceId")))
1235 value
= new NXSL_Value(event
->getSourceId());
1237 else if (!_tcscmp(attr
, _T("timestamp")))
1239 value
= new NXSL_Value((INT64
)event
->getTimeStamp());
1241 else if (!_tcscmp(attr
, _T("userTag")))
1243 value
= new NXSL_Value(event
->getUserTag());
1247 if (attr
[0] == _T('$'))
1249 // Try to find parameter with given index
1251 int index
= _tcstol(&attr
[1], &eptr
, 10);
1252 if ((index
> 0) && (*eptr
== 0))
1254 const TCHAR
*s
= event
->getParameter(index
- 1);
1257 value
= new NXSL_Value(s
);
1262 // Try to find named parameter with given name
1265 const TCHAR
*s
= event
->getNamedParameter(attr
);
1268 value
= new NXSL_Value(s
);
1276 * Alarm::acknowledge() method
1278 NXSL_METHOD_DEFINITION(Alarm
, acknowledge
)
1280 Alarm
*alarm
= (Alarm
*)object
->getData();
1281 *result
= new NXSL_Value(AckAlarmById(alarm
->getAlarmId(), NULL
, false, 0));
1286 * Alarm::resolve() method
1288 NXSL_METHOD_DEFINITION(Alarm
, resolve
)
1290 Alarm
*alarm
= (Alarm
*)object
->getData();
1291 *result
= new NXSL_Value(ResolveAlarmById(alarm
->getAlarmId(), NULL
, false));
1296 * Alarm::terminate() method
1298 NXSL_METHOD_DEFINITION(Alarm
, terminate
)
1300 Alarm
*alarm
= (Alarm
*)object
->getData();
1301 *result
= new NXSL_Value(ResolveAlarmById(alarm
->getAlarmId(), NULL
, true));
1306 * NXSL class Alarm: constructor
1308 NXSL_AlarmClass
::NXSL_AlarmClass() : NXSL_Class()
1310 setName(_T("Alarm"));
1312 NXSL_REGISTER_METHOD(Alarm
, acknowledge
, 0);
1313 NXSL_REGISTER_METHOD(Alarm
, resolve
, 0);
1314 NXSL_REGISTER_METHOD(Alarm
, terminate
, 0);
1318 * NXSL object destructor
1320 void NXSL_AlarmClass
::onObjectDelete(NXSL_Object
*object
)
1322 delete (Alarm
*)object
->getData();
1326 * NXSL class Alarm: get attribute
1328 NXSL_Value
*NXSL_AlarmClass
::getAttr(NXSL_Object
*pObject
, const TCHAR
*attr
)
1330 NXSL_Value
*value
= NULL
;
1331 Alarm
*alarm
= (Alarm
*)pObject
->getData();
1333 if (!_tcscmp(attr
, _T("ackBy")))
1335 value
= new NXSL_Value(alarm
->getAckByUser());
1337 else if (!_tcscmp(attr
, _T("creationTime")))
1339 value
= new NXSL_Value((INT64
)alarm
->getCreationTime());
1341 else if (!_tcscmp(attr
, _T("dciId")))
1343 value
= new NXSL_Value(alarm
->getDciId());
1345 else if (!_tcscmp(attr
, _T("eventCode")))
1347 value
= new NXSL_Value(alarm
->getSourceEventCode());
1349 else if (!_tcscmp(attr
, _T("eventId")))
1351 value
= new NXSL_Value(alarm
->getSourceEventId());
1353 else if (!_tcscmp(attr
, _T("helpdeskReference")))
1355 value
= new NXSL_Value(alarm
->getHelpDeskRef());
1357 else if (!_tcscmp(attr
, _T("helpdeskState")))
1359 value
= new NXSL_Value(alarm
->getHelpDeskState());
1361 else if (!_tcscmp(attr
, _T("id")))
1363 value
= new NXSL_Value(alarm
->getAlarmId());
1365 else if (!_tcscmp(attr
, _T("key")))
1367 value
= new NXSL_Value(alarm
->getKey());
1369 else if (!_tcscmp(attr
, _T("lastChangeTime")))
1371 value
= new NXSL_Value((INT64
)alarm
->getLastChangeTime());
1373 else if (!_tcscmp(attr
, _T("message")))
1375 value
= new NXSL_Value(alarm
->getMessage());
1377 else if (!_tcscmp(attr
, _T("originalSeverity")))
1379 value
= new NXSL_Value(alarm
->getOriginalSeverity());
1381 else if (!_tcscmp(attr
, _T("repeatCount")))
1383 value
= new NXSL_Value(alarm
->getRepeatCount());
1385 else if (!_tcscmp(attr
, _T("resolvedBy")))
1387 value
= new NXSL_Value(alarm
->getResolvedByUser());
1389 else if (!_tcscmp(attr
, _T("severity")))
1391 value
= new NXSL_Value(alarm
->getCurrentSeverity());
1393 else if (!_tcscmp(attr
, _T("sourceObject")))
1395 value
= new NXSL_Value(alarm
->getSourceObject());
1397 else if (!_tcscmp(attr
, _T("state")))
1399 value
= new NXSL_Value(alarm
->getState());
1405 * Implementation of "DCI" class: constructor
1407 NXSL_DciClass
::NXSL_DciClass() : NXSL_Class()
1415 void NXSL_DciClass
::onObjectDelete(NXSL_Object
*object
)
1417 delete (DCObjectInfo
*)object
->getData();
1421 * Implementation of "DCI" class: get attribute
1423 NXSL_Value
*NXSL_DciClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1426 NXSL_Value
*value
= NULL
;
1428 dci
= (DCObjectInfo
*)object
->getData();
1429 if (!_tcscmp(attr
, _T("comments")))
1431 value
= new NXSL_Value(dci
->getComments());
1433 else if (!_tcscmp(attr
, _T("dataType")) && (dci
->getType() == DCO_TYPE_ITEM
))
1435 value
= new NXSL_Value(dci
->getDataType());
1437 else if (!_tcscmp(attr
, _T("description")))
1439 value
= new NXSL_Value(dci
->getDescription());
1441 else if (!_tcscmp(attr
, _T("errorCount")))
1443 value
= new NXSL_Value(dci
->getErrorCount());
1445 else if (!_tcscmp(attr
, _T("id")))
1447 value
= new NXSL_Value(dci
->getId());
1449 else if ((dci
->getType() == DCO_TYPE_ITEM
) && !_tcscmp(attr
, _T("instance")))
1451 value
= new NXSL_Value(dci
->getInstance());
1453 else if (!_tcscmp(attr
, _T("lastPollTime")))
1455 value
= new NXSL_Value((INT64
)dci
->getLastPollTime());
1457 else if (!_tcscmp(attr
, _T("name")))
1459 value
= new NXSL_Value(dci
->getName());
1461 else if (!_tcscmp(attr
, _T("origin")))
1463 value
= new NXSL_Value((LONG
)dci
->getOrigin());
1465 else if (!_tcscmp(attr
, _T("status")))
1467 value
= new NXSL_Value((LONG
)dci
->getStatus());
1469 else if (!_tcscmp(attr
, _T("systemTag")))
1471 value
= new NXSL_Value(dci
->getSystemTag());
1473 else if (!_tcscmp(attr
, _T("type")))
1475 value
= new NXSL_Value((LONG
)dci
->getType());
1481 * Implementation of "Sensor" class: constructor
1483 NXSL_SensorClass
::NXSL_SensorClass() : NXSL_NetObjClass()
1485 setName(_T("Sensor"));
1489 * Implementation of "Sensor" class: get attribute
1491 NXSL_Value
*NXSL_SensorClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1493 NXSL_Value
*value
= NXSL_NetObjClass
::getAttr(object
, attr
);
1499 s
= (Sensor
*)object
->getData();
1500 if (!_tcscmp(attr
, _T("description")))
1502 value
= new NXSL_Value(s
->getDescription());
1504 else if (!_tcscmp(attr
, _T("frameCount")))
1506 value
= new NXSL_Value(s
->getFrameCount());
1508 else if (!_tcscmp(attr
, _T("lastContact")))
1510 value
= new NXSL_Value((UINT32
)s
->getLastContact());
1512 else if (!_tcscmp(attr
, _T("metaType")))
1514 value
= new NXSL_Value(s
->getMetaType());
1516 else if (!_tcscmp(attr
, _T("protocol")))
1518 value
= new NXSL_Value(s
->getCommProtocol());
1520 else if (!_tcscmp(attr
, _T("serial")))
1522 value
= new NXSL_Value(s
->getSerialNumber());
1524 else if (!_tcscmp(attr
, _T("type")))
1526 value
= new NXSL_Value(s
->getSensorClass());
1528 else if (!_tcscmp(attr
, _T("vendor")))
1530 value
= new NXSL_Value(s
->getVendor());
1537 * Implementation of "SNMP_Transport" class: constructor
1539 NXSL_SNMPTransportClass
::NXSL_SNMPTransportClass() : NXSL_Class()
1541 setName(_T("SNMP_Transport"));
1545 * Implementation of "SNMP_Transport" class: get attribute
1547 NXSL_Value
*NXSL_SNMPTransportClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1549 NXSL_Value
*value
= NULL
;
1552 t
= (SNMP_Transport
*)object
->getData();
1553 if (!_tcscmp(attr
, _T("snmpVersion")))
1555 const TCHAR
*versions
[] = { _T("1"), _T("2c"), _T("3") };
1556 value
= new NXSL_Value((const TCHAR
*)versions
[t
->getSnmpVersion()]);
1563 * Implementation of "SNMP_Transport" class: NXSL object destructor
1565 void NXSL_SNMPTransportClass
::onObjectDelete(NXSL_Object
*object
)
1567 delete (SNMP_Transport
*)object
->getData();
1571 * NXSL class SNMP_VarBind: constructor
1573 NXSL_SNMPVarBindClass
::NXSL_SNMPVarBindClass() : NXSL_Class()
1575 setName(_T("SNMP_VarBind"));
1579 * NXSL class SNMP_VarBind: get attribute
1581 NXSL_Value
*NXSL_SNMPVarBindClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1583 NXSL_Value
*value
= NULL
;
1584 SNMP_Variable
*t
= (SNMP_Variable
*)object
->getData();
1585 if (!_tcscmp(attr
, _T("type")))
1587 value
= new NXSL_Value((UINT32
)t
->getType());
1589 else if (!_tcscmp(attr
, _T("name")))
1591 value
= new NXSL_Value(t
->getName().toString());
1593 else if (!_tcscmp(attr
, _T("value")))
1595 TCHAR strValue
[1024];
1596 value
= new NXSL_Value(t
->getValueAsString(strValue
, 1024));
1598 else if (!_tcscmp(attr
, _T("printableValue")))
1600 TCHAR strValue
[1024];
1601 bool convToHex
= true;
1602 t
->getValueAsPrintableString(strValue
, 1024, &convToHex
);
1603 value
= new NXSL_Value(strValue
);
1605 else if (!_tcscmp(attr
, _T("valueAsIp")))
1607 TCHAR strValue
[128];
1608 t
->getValueAsIPAddr(strValue
);
1609 value
= new NXSL_Value(strValue
);
1611 else if (!_tcscmp(attr
, _T("valueAsMac")))
1613 TCHAR strValue
[128];
1614 t
->getValueAsMACAddr(strValue
);
1615 value
= new NXSL_Value(strValue
);
1622 * NXSL class SNMP_VarBind: NXSL object desctructor
1624 void NXSL_SNMPVarBindClass
::onObjectDelete(NXSL_Object
*object
)
1626 delete (SNMP_Variable
*)object
->getData();
1630 * NXSL class ComponentClass: constructor
1632 NXSL_ComponentClass
::NXSL_ComponentClass() : NXSL_Class()
1634 setName(_T("Component"));
1638 * NXSL class ComponentClass: get attribute
1640 NXSL_Value
*NXSL_ComponentClass
::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1642 const UINT32 classCount
= 12;
1643 static const TCHAR
*className
[classCount
] = { _T(""), _T("other"), _T("unknown"), _T("chassis"), _T("backplane"),
1644 _T("container"), _T("power supply"), _T("fan"), _T("sensor"),
1645 _T("module"), _T("port"), _T("stack") };
1646 NXSL_Value
*value
= NULL
;
1647 Component
*component
= (Component
*)object
->getData();
1648 if (!_tcscmp(attr
, _T("class")))
1650 if (component
->getClass() >= classCount
)
1651 value
= new NXSL_Value(className
[2]); // Unknown class
1653 value
= new NXSL_Value(className
[component
->getClass()]);
1655 else if (!_tcscmp(attr
, _T("children")))
1657 value
= new NXSL_Value(component
->getChildrenForNXSL());
1659 else if (!_tcscmp(attr
, _T("firmware")))
1661 value
= new NXSL_Value(component
->getFirmware());
1663 else if (!_tcscmp(attr
, _T("model")))
1665 value
= new NXSL_Value(component
->getModel());
1667 else if (!_tcscmp(attr
, _T("name")))
1669 value
= new NXSL_Value(component
->getName());
1671 else if (!_tcscmp(attr
, _T("serial")))
1673 value
= new NXSL_Value(component
->getSerial());
1675 else if (!_tcscmp(attr
, _T("vendor")))
1677 value
= new NXSL_Value(component
->getVendor());
1685 NXSL_AlarmClass g_nxslAlarmClass
;
1686 NXSL_ChassisClass g_nxslChassisClass
;
1687 NXSL_ClusterClass g_nxslClusterClass
;
1688 NXSL_ComponentClass g_nxslComponentClass
;
1689 NXSL_ContainerClass g_nxslContainerClass
;
1690 NXSL_DciClass g_nxslDciClass
;
1691 NXSL_EventClass g_nxslEventClass
;
1692 NXSL_InterfaceClass g_nxslInterfaceClass
;
1693 NXSL_MobileDeviceClass g_nxslMobileDeviceClass
;
1694 NXSL_NetObjClass g_nxslNetObjClass
;
1695 NXSL_NodeClass g_nxslNodeClass
;
1696 NXSL_SensorClass g_nxslSensorClass
;
1697 NXSL_SNMPTransportClass g_nxslSnmpTransportClass
;
1698 NXSL_SNMPVarBindClass g_nxslSnmpVarBindClass
;
1699 NXSL_ZoneClass g_nxslZoneClass
;