2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2016 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
;
54 * setStatusCalculation(type, ...)
56 NXSL_METHOD_DEFINITION(NetObj
, setStatusCalculation
)
59 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
61 if (!argv
[0]->isInteger())
62 return NXSL_ERR_NOT_INTEGER
;
65 int method
= argv
[0]->getValueAsInt32();
66 NetObj
*netobj
= (NetObj
*)object
->getData();
69 case SA_CALCULATE_DEFAULT
:
70 case SA_CALCULATE_MOST_CRITICAL
:
71 netobj
->setStatusCalculation(method
);
73 case SA_CALCULATE_SINGLE_THRESHOLD
:
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());
80 case SA_CALCULATE_MULTIPLE_THRESHOLDS
:
82 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
83 for(int i
= 1; i
<= 4; i
++)
85 if (!argv
[i
]->isInteger())
86 return NXSL_ERR_NOT_INTEGER
;
88 netobj
->setStatusCalculation(method
, argv
[1]->getValueAsInt32(), argv
[2]->getValueAsInt32(), argv
[3]->getValueAsInt32(), argv
[4]->getValueAsInt32());
91 success
= 0; // invalid method
94 *result
= new NXSL_Value(success
);
99 * setStatusPropagation(type, ...)
101 NXSL_METHOD_DEFINITION(NetObj
, setStatusPropagation
)
104 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
106 if (!argv
[0]->isInteger())
107 return NXSL_ERR_NOT_INTEGER
;
110 int method
= argv
[0]->getValueAsInt32();
111 NetObj
*netobj
= (NetObj
*)object
->getData();
114 case SA_PROPAGATE_DEFAULT
:
115 case SA_PROPAGATE_UNCHANGED
:
116 netobj
->setStatusPropagation(method
);
118 case SA_PROPAGATE_FIXED
:
119 case SA_PROPAGATE_RELATIVE
:
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());
126 case SA_PROPAGATE_TRANSLATED
:
128 return NXSL_ERR_INVALID_ARGUMENT_COUNT
;
129 for(int i
= 1; i
<= 4; i
++)
131 if (!argv
[i
]->isInteger())
132 return NXSL_ERR_NOT_INTEGER
;
134 netobj
->setStatusPropagation(method
, argv
[1]->getValueAsInt32(), argv
[2]->getValueAsInt32(), argv
[3]->getValueAsInt32(), argv
[4]->getValueAsInt32());
137 success
= 0; // invalid method
140 *result
= new NXSL_Value(success
);
145 * NXSL class NetObj: constructor
147 NXSL_NetObjClass::NXSL_NetObjClass() : NXSL_Class()
149 _tcscpy(m_name
, _T("NetObj"));
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);
158 * NXSL class NetObj: get attribute
160 NXSL_Value
*NXSL_NetObjClass::getAttr(NXSL_Object
*_object
, const TCHAR
*attr
)
162 NXSL_Value
*value
= NULL
;
163 NetObj
*object
= (NetObj
*)_object
->getData();
164 if (!_tcscmp(attr
, _T("name")))
166 value
= new NXSL_Value(object
->getName());
168 else if (!_tcscmp(attr
, _T("id")))
170 value
= new NXSL_Value(object
->getId());
172 else if (!_tcscmp(attr
, _T("guid")))
175 value
= new NXSL_Value(object
->getGuid().toString(buffer
));
177 else if (!_tcscmp(attr
, _T("status")))
179 value
= new NXSL_Value((LONG
)object
->getStatus());
181 else if (!_tcscmp(attr
, _T("ipAddr")))
184 GetObjectIpAddress(object
).toString(buffer
);
185 value
= new NXSL_Value(buffer
);
187 else if (!_tcscmp(attr
, _T("type")))
189 value
= new NXSL_Value((LONG
)object
->getObjectClass());
191 else if (!_tcscmp(attr
, _T("comments")))
193 value
= new NXSL_Value(object
->getComments());
195 else if (!_tcscmp(attr
, _T("customAttributes")))
197 value
= object
->getCustomAttributesForNXSL();
199 else if (!_tcscmp(attr
, _T("country")))
201 value
= new NXSL_Value(object
->getPostalAddress()->getCountry());
203 else if (!_tcscmp(attr
, _T("city")))
205 value
= new NXSL_Value(object
->getPostalAddress()->getCity());
207 else if (!_tcscmp(attr
, _T("geolocation")))
209 value
= new NXSL_Value(new NXSL_Object(&g_nxslGeoLocationClass
, new GeoLocation(object
->getGeoLocation())));
211 else if (!_tcscmp(attr
, _T("streetAddress")))
213 value
= new NXSL_Value(object
->getPostalAddress()->getStreetAddress());
215 else if (!_tcscmp(attr
, _T("postcode")))
217 value
= new NXSL_Value(object
->getPostalAddress()->getPostCode());
221 const TCHAR
*attrValue
= object
->getCustomAttribute(attr
);
222 if (attrValue
!= NULL
)
224 value
= new NXSL_Value(attrValue
);
231 * NXSL class Zone: constructor
233 NXSL_ZoneClass::NXSL_ZoneClass() : NXSL_NetObjClass()
235 _tcscpy(m_name
, _T("Zone"));
239 * NXSL class Zone: get attribute
241 NXSL_Value
*NXSL_ZoneClass::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
243 NXSL_Value
*value
= NXSL_NetObjClass::getAttr(object
, attr
);
247 Zone
*zone
= (Zone
*)object
->getData();
248 if (!_tcscmp(attr
, _T("proxyNode")))
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();
253 else if (!_tcscmp(attr
, _T("proxyNodeId")))
255 value
= new NXSL_Value(zone
->getProxyNodeId());
257 else if (!_tcscmp(attr
, _T("zoneId")))
259 value
= new NXSL_Value(zone
->getZoneId());
265 * Generic implementation for flag changing methods
267 static int ChangeFlagMethod(NXSL_Object
*object
, NXSL_Value
*arg
, NXSL_Value
**result
, UINT32 flag
)
269 if (!arg
->isInteger())
270 return NXSL_ERR_NOT_INTEGER
;
272 Node
*node
= (Node
*)object
->getData();
273 if (arg
->getValueAsInt32())
274 node
->clearFlag(flag
);
278 *result
= new NXSL_Value
;
283 * enableAgent(enabled) method
285 NXSL_METHOD_DEFINITION(Node
, enableAgent
)
287 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_NXCP
);
291 * enableConfigurationPolling(enabled) method
293 NXSL_METHOD_DEFINITION(Node
, enableConfigurationPolling
)
295 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_CONF_POLL
);
299 * enableDiscoveryPolling(enabled) method
301 NXSL_METHOD_DEFINITION(Node
, enableDiscoveryPolling
)
303 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_DISCOVERY_POLL
);
307 * enableIcmp(enabled) method
309 NXSL_METHOD_DEFINITION(Node
, enableIcmp
)
311 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_ICMP
);
315 * enableSnmp(enabled) method
317 NXSL_METHOD_DEFINITION(Node
, enableSnmp
)
319 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_SNMP
);
323 * enableStatusPolling(enabled) method
325 NXSL_METHOD_DEFINITION(Node
, enableStatusPolling
)
327 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_STATUS_POLL
);
331 * enableTopologyPolling(enabled) method
333 NXSL_METHOD_DEFINITION(Node
, enableTopologyPolling
)
335 return ChangeFlagMethod(object
, argv
[0], result
, NF_DISABLE_TOPOLOGY_POLL
);
339 * NXSL class Node: constructor
341 NXSL_NodeClass::NXSL_NodeClass() : NXSL_NetObjClass()
343 _tcscpy(m_name
, _T("Node"));
345 NXSL_REGISTER_METHOD(Node
, enableAgent
, 1);
346 NXSL_REGISTER_METHOD(Node
, enableConfigurationPolling
, 1);
347 NXSL_REGISTER_METHOD(Node
, enableDiscoveryPolling
, 1);
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);
355 * NXSL class Node: get attribute
357 NXSL_Value
*NXSL_NodeClass::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
359 NXSL_Value
*value
= NXSL_NetObjClass::getAttr(object
, attr
);
363 Node
*node
= (Node
*)object
->getData();
364 if (!_tcscmp(attr
, _T("agentVersion")))
366 value
= new NXSL_Value(node
->getAgentVersion());
368 else if (!_tcscmp(attr
, _T("bootTime")))
370 value
= new NXSL_Value((INT64
)node
->getBootTime());
372 else if (!_tcscmp(attr
, _T("bridgeBaseAddress")))
375 value
= new NXSL_Value(BinToStr(node
->getBridgeId(), MAC_ADDR_LENGTH
, buffer
));
377 else if (!_tcscmp(attr
, _T("driver")))
379 value
= new NXSL_Value(node
->getDriverName());
381 else if (!_tcscmp(attr
, _T("flags")))
383 value
= new NXSL_Value(node
->getFlags());
385 else if (!_tcscmp(attr
, _T("isAgent")))
387 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_NATIVE_AGENT
) ? 1 : 0));
389 else if (!_tcscmp(attr
, _T("isBridge")))
391 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_BRIDGE
) ? 1 : 0));
393 else if (!_tcscmp(attr
, _T("isCDP")))
395 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_CDP
) ? 1 : 0));
397 else if (!_tcscmp(attr
, _T("isLLDP")))
399 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_LLDP
) ? 1 : 0));
401 else if (!_tcscmp(attr
, _T("isLocalMgmt")) || !_tcscmp(attr
, _T("isLocalManagement")))
403 value
= new NXSL_Value((LONG
)((node
->isLocalManagement()) ? 1 : 0));
405 else if (!_tcscmp(attr
, _T("isPAE")) || !_tcscmp(attr
, _T("is802_1x")))
407 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_8021X
) ? 1 : 0));
409 else if (!_tcscmp(attr
, _T("isPrinter")))
411 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_PRINTER
) ? 1 : 0));
413 else if (!_tcscmp(attr
, _T("isRouter")))
415 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_ROUTER
) ? 1 : 0));
417 else if (!_tcscmp(attr
, _T("isSMCLP")))
419 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_SMCLP
) ? 1 : 0));
421 else if (!_tcscmp(attr
, _T("isSNMP")))
423 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_SNMP
) ? 1 : 0));
425 else if (!_tcscmp(attr
, _T("isSONMP")))
427 value
= new NXSL_Value((LONG
)((node
->getFlags() & NF_IS_SONMP
) ? 1 : 0));
429 else if (!_tcscmp(attr
, _T("platformName")))
431 value
= new NXSL_Value(node
->getPlatformName());
433 else if (!_tcscmp(attr
, _T("rack")))
435 Rack
*rack
= (Rack
*)FindObjectById(node
->getRackId(), OBJECT_RACK
);
438 value
= rack
->createNXSLObject();
442 value
= new NXSL_Value
;
445 else if (!_tcscmp(attr
, _T("rackId")))
447 value
= new NXSL_Value(node
->getRackId());
449 else if (!_tcscmp(attr
, _T("rackHeight")))
451 value
= new NXSL_Value(node
->getRackHeight());
453 else if (!_tcscmp(attr
, _T("rackPosition")))
455 value
= new NXSL_Value(node
->getRackPosition());
457 else if (!_tcscmp(attr
, _T("runtimeFlags")))
459 value
= new NXSL_Value(node
->getRuntimeFlags());
461 else if (!_tcscmp(attr
, _T("snmpOID")))
463 value
= new NXSL_Value(node
->getSNMPObjectId());
465 else if (!_tcscmp(attr
, _T("snmpSysContact")))
467 value
= new NXSL_Value(node
->getSysContact());
469 else if (!_tcscmp(attr
, _T("snmpSysLocation")))
471 value
= new NXSL_Value(node
->getSysLocation());
473 else if (!_tcscmp(attr
, _T("snmpSysName")))
475 value
= new NXSL_Value(node
->getSysName());
477 else if (!_tcscmp(attr
, _T("snmpVersion")))
479 value
= new NXSL_Value((LONG
)node
->getSNMPVersion());
481 else if (!_tcscmp(attr
, _T("subType")))
483 value
= new NXSL_Value(node
->getSubType());
485 else if (!_tcscmp(attr
, _T("sysDescription")))
487 value
= new NXSL_Value(node
->getSysDescription());
489 else if (!_tcscmp(attr
, _T("type")))
491 value
= new NXSL_Value((INT32
)node
->getType());
493 else if (!_tcscmp(attr
, _T("zone")))
495 if (g_flags
& AF_ENABLE_ZONING
)
497 Zone
*zone
= FindZoneByGUID(node
->getZoneId());
500 value
= new NXSL_Value(new NXSL_Object(&g_nxslZoneClass
, zone
));
504 value
= new NXSL_Value
;
509 value
= new NXSL_Value
;
512 else if (!_tcscmp(attr
, _T("zoneId")))
514 value
= new NXSL_Value(node
->getZoneId());
520 * Interface::setExcludeFromTopology(enabled) method
522 NXSL_METHOD_DEFINITION(Interface
, setExcludeFromTopology
)
524 if (!argv
[0]->isInteger())
525 return NXSL_ERR_NOT_INTEGER
;
527 Interface
*iface
= (Interface
*)object
->getData();
528 iface
->setExcludeFromTopology(argv
[0]->getValueAsInt32() != 0);
529 *result
= new NXSL_Value
;
534 * Interface::setExpectedState(state) method
536 NXSL_METHOD_DEFINITION(Interface
, setExpectedState
)
539 if (argv
[0]->isInteger())
541 state
= argv
[0]->getValueAsInt32();
543 else if (argv
[0]->isString())
545 static const TCHAR
*stateNames
[] = { _T("UP"), _T("DOWN"), _T("IGNORE"), NULL
};
546 const TCHAR
*name
= argv
[0]->getValueAsCString();
547 for(state
= 0; stateNames
[state
] != NULL
; state
++)
548 if (!_tcsicmp(stateNames
[state
], name
))
553 return NXSL_ERR_NOT_STRING
;
556 if ((state
>= 0) && (state
<= 2))
557 ((Interface
*)object
->getData())->setExpectedState(state
);
559 *result
= new NXSL_Value
;
564 * NXSL class Interface: constructor
566 NXSL_InterfaceClass::NXSL_InterfaceClass() : NXSL_NetObjClass()
568 _tcscpy(m_name
, _T("Interface"));
570 NXSL_REGISTER_METHOD(Interface
, setExcludeFromTopology
, 1);
571 NXSL_REGISTER_METHOD(Interface
, setExpectedState
, 1);
575 * NXSL class Interface: get attribute
577 NXSL_Value
*NXSL_InterfaceClass::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
579 NXSL_Value
*value
= NXSL_NetObjClass::getAttr(object
, attr
);
583 Interface
*iface
= (Interface
*)object
->getData();
584 if (!_tcscmp(attr
, _T("adminState")))
586 value
= new NXSL_Value((LONG
)iface
->getAdminState());
588 else if (!_tcscmp(attr
, _T("alias")))
590 value
= new NXSL_Value(iface
->getAlias());
592 else if (!_tcscmp(attr
, _T("bridgePortNumber")))
594 value
= new NXSL_Value(iface
->getBridgePortNumber());
596 else if (!_tcscmp(attr
, _T("description")))
598 value
= new NXSL_Value(iface
->getDescription());
600 else if (!_tcscmp(attr
, _T("dot1xBackendAuthState")))
602 value
= new NXSL_Value((LONG
)iface
->getDot1xBackendAuthState());
604 else if (!_tcscmp(attr
, _T("dot1xPaeAuthState")))
606 value
= new NXSL_Value((LONG
)iface
->getDot1xPaeAuthState());
608 else if (!_tcscmp(attr
, _T("expectedState")))
610 value
= new NXSL_Value((iface
->getFlags() & IF_EXPECTED_STATE_MASK
) >> 28);
612 else if (!_tcscmp(attr
, _T("flags")))
614 value
= new NXSL_Value(iface
->getFlags());
616 else if (!_tcscmp(attr
, _T("ifIndex")))
618 value
= new NXSL_Value(iface
->getIfIndex());
620 else if (!_tcscmp(attr
, _T("ifType")))
622 value
= new NXSL_Value(iface
->getIfType());
624 else if (!_tcscmp(attr
, _T("ipNetMask")))
626 value
= new NXSL_Value(iface
->getIpAddressList()->getFirstUnicastAddress().getMaskBits());
628 else if (!_tcscmp(attr
, _T("isExcludedFromTopology")))
630 value
= new NXSL_Value((LONG
)(iface
->isExcludedFromTopology() ? 1 : 0));
632 else if (!_tcscmp(attr
, _T("isLoopback")))
634 value
= new NXSL_Value((LONG
)(iface
->isLoopback() ? 1 : 0));
636 else if (!_tcscmp(attr
, _T("isManuallyCreated")))
638 value
= new NXSL_Value((LONG
)(iface
->isManuallyCreated() ? 1 : 0));
640 else if (!_tcscmp(attr
, _T("isPhysicalPort")))
642 value
= new NXSL_Value((LONG
)(iface
->isPhysicalPort() ? 1 : 0));
644 else if (!_tcscmp(attr
, _T("macAddr")))
647 value
= new NXSL_Value(BinToStr(iface
->getMacAddr(), MAC_ADDR_LENGTH
, buffer
));
649 else if (!_tcscmp(attr
, _T("mtu")))
651 value
= new NXSL_Value(iface
->getMTU());
653 else if (!_tcscmp(attr
, _T("node")))
655 Node
*parentNode
= iface
->getParentNode();
656 if (parentNode
!= NULL
)
658 value
= new NXSL_Value(new NXSL_Object(&g_nxslNodeClass
, parentNode
));
662 value
= new NXSL_Value
;
665 else if (!_tcscmp(attr
, _T("operState")))
667 value
= new NXSL_Value((LONG
)iface
->getOperState());
669 else if (!_tcscmp(attr
, _T("peerInterface")))
671 Interface
*peerIface
= (Interface
*)FindObjectById(iface
->getPeerInterfaceId(), OBJECT_INTERFACE
);
672 if (peerIface
!= NULL
)
674 if (g_flags
& AF_CHECK_TRUSTED_NODES
)
676 Node
*parentNode
= iface
->getParentNode();
677 Node
*peerNode
= peerIface
->getParentNode();
678 if ((parentNode
!= NULL
) && (peerNode
!= NULL
))
680 if (peerNode
->isTrustedNode(parentNode
->getId()))
682 value
= new NXSL_Value(new NXSL_Object(&g_nxslInterfaceClass
, peerIface
));
686 // No access, return null
687 value
= new NXSL_Value
;
688 DbgPrintf(4, _T("NXSL::Interface::peerInterface(%s [%d]): access denied for node %s [%d]"),
689 iface
->getName(), iface
->getId(), peerNode
->getName(), peerNode
->getId());
694 value
= new NXSL_Value
;
695 DbgPrintf(4, _T("NXSL::Interface::peerInterface(%s [%d]): parentNode=%p peerNode=%p"), iface
->getName(), iface
->getId(), parentNode
, peerNode
);
700 value
= new NXSL_Value(new NXSL_Object(&g_nxslInterfaceClass
, peerIface
));
705 value
= new NXSL_Value
;
708 else if (!_tcscmp(attr
, _T("peerNode")))
710 Node
*peerNode
= (Node
*)FindObjectById(iface
->getPeerNodeId(), OBJECT_NODE
);
711 if (peerNode
!= NULL
)
713 if (g_flags
& AF_CHECK_TRUSTED_NODES
)
715 Node
*parentNode
= iface
->getParentNode();
716 if ((parentNode
!= NULL
) && (peerNode
->isTrustedNode(parentNode
->getId())))
718 value
= new NXSL_Value(new NXSL_Object(&g_nxslNodeClass
, peerNode
));
722 // No access, return null
723 value
= new NXSL_Value
;
724 DbgPrintf(4, _T("NXSL::Interface::peerNode(%s [%d]): access denied for node %s [%d]"),
725 iface
->getName(), iface
->getId(), peerNode
->getName(), peerNode
->getId());
730 value
= new NXSL_Value(new NXSL_Object(&g_nxslNodeClass
, peerNode
));
735 value
= new NXSL_Value
;
738 else if (!_tcscmp(attr
, _T("port")))
740 value
= new NXSL_Value(iface
->getPortNumber());
742 else if (!_tcscmp(attr
, _T("slot")))
744 value
= new NXSL_Value(iface
->getSlotNumber());
746 else if (!_tcscmp(attr
, _T("speed")))
748 value
= new NXSL_Value(iface
->getSpeed());
750 else if (!_tcscmp(attr
, _T("zone")))
752 if (g_flags
& AF_ENABLE_ZONING
)
754 Zone
*zone
= FindZoneByGUID(iface
->getZoneId());
757 value
= new NXSL_Value(new NXSL_Object(&g_nxslZoneClass
, zone
));
761 value
= new NXSL_Value
;
766 value
= new NXSL_Value
;
769 else if (!_tcscmp(attr
, _T("zoneId")))
771 value
= new NXSL_Value(iface
->getZoneId());
777 * NXSL class Mobile Device: constructor
779 NXSL_MobileDeviceClass::NXSL_MobileDeviceClass() : NXSL_NetObjClass()
781 _tcscpy(m_name
, _T("MobileDevice"));
785 * NXSL class Mobile Device: get attribute
787 NXSL_Value
*NXSL_MobileDeviceClass::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
789 NXSL_Value
*value
= NXSL_NetObjClass::getAttr(object
, attr
);
793 MobileDevice
*mobDevice
= (MobileDevice
*)object
->getData();
794 if (!_tcscmp(attr
, _T("deviceId")))
796 value
= new NXSL_Value(mobDevice
->getDeviceId());
798 else if (!_tcscmp(attr
, _T("vendor")))
800 value
= new NXSL_Value(mobDevice
->getVendor());
802 else if (!_tcscmp(attr
, _T("model")))
804 value
= new NXSL_Value(mobDevice
->getModel());
806 else if (!_tcscmp(attr
, _T("serialNumber")))
808 value
= new NXSL_Value(mobDevice
->getSerialNumber());
810 else if (!_tcscmp(attr
, _T("osName")))
812 value
= new NXSL_Value(mobDevice
->getOsName());
814 else if (!_tcscmp(attr
, _T("osVersion")))
816 value
= new NXSL_Value(mobDevice
->getOsVersion());
818 else if (!_tcscmp(attr
, _T("userId")))
820 value
= new NXSL_Value(mobDevice
->getUserId());
822 else if (!_tcscmp(attr
, _T("batteryLevel")))
824 value
= new NXSL_Value(mobDevice
->getBatteryLevel());
831 * NXSL class "Chassis" constructor
833 NXSL_ChassisClass::NXSL_ChassisClass() : NXSL_NetObjClass()
835 _tcscpy(m_name
, _T("Chassis"));
839 * NXSL class "Cluster" attributes
841 NXSL_Value
*NXSL_ChassisClass::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
843 NXSL_Value
*value
= NXSL_NetObjClass::getAttr(object
, attr
);
847 Chassis
*chassis
= (Chassis
*)object
->getData();
848 if (!_tcscmp(attr
, _T("controller")))
850 Node
*node
= (Node
*)FindObjectById(chassis
->getControllerId(), OBJECT_NODE
);
853 value
= node
->createNXSLObject();
857 value
= new NXSL_Value
;
860 else if (!_tcscmp(attr
, _T("controllerId")))
862 value
= new NXSL_Value(chassis
->getControllerId());
864 else if (!_tcscmp(attr
, _T("flags")))
866 value
= new NXSL_Value(chassis
->getFlags());
868 else if (!_tcscmp(attr
, _T("rack")))
870 Rack
*rack
= (Rack
*)FindObjectById(chassis
->getRackId(), OBJECT_RACK
);
873 value
= rack
->createNXSLObject();
877 value
= new NXSL_Value
;
880 else if (!_tcscmp(attr
, _T("rackId")))
882 value
= new NXSL_Value(chassis
->getRackId());
884 else if (!_tcscmp(attr
, _T("rackHeight")))
886 value
= new NXSL_Value(chassis
->getRackHeight());
888 else if (!_tcscmp(attr
, _T("rackPosition")))
890 value
= new NXSL_Value(chassis
->getRackPosition());
896 * NXSL class "Cluster" constructor
898 NXSL_ClusterClass::NXSL_ClusterClass() : NXSL_NetObjClass()
900 _tcscpy(m_name
, _T("Cluster"));
904 * NXSL class "Cluster" attributes
906 NXSL_Value
*NXSL_ClusterClass::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
908 NXSL_Value
*value
= NXSL_NetObjClass::getAttr(object
, attr
);
912 Cluster
*cluster
= (Cluster
*)object
->getData();
913 if (!_tcscmp(attr
, _T("zone")))
915 if (g_flags
& AF_ENABLE_ZONING
)
917 Zone
*zone
= FindZoneByGUID(cluster
->getZoneId());
920 value
= zone
->createNXSLObject();
924 value
= new NXSL_Value
;
929 value
= new NXSL_Value
;
932 else if (!_tcscmp(attr
, _T("zoneId")))
934 value
= new NXSL_Value(cluster
->getZoneId());
940 * Event::setMessage() method
942 NXSL_METHOD_DEFINITION(Event
, setMessage
)
944 if (!argv
[0]->isString())
945 return NXSL_ERR_NOT_STRING
;
947 Event
*event
= (Event
*)object
->getData();
948 event
->setMessage(argv
[0]->getValueAsCString());
949 *result
= new NXSL_Value();
954 * Event::setSeverity() method
956 NXSL_METHOD_DEFINITION(Event
, setSeverity
)
958 if (!argv
[0]->isInteger())
959 return NXSL_ERR_NOT_STRING
;
961 int s
= argv
[0]->getValueAsInt32();
962 if ((s
>= SEVERITY_NORMAL
) && (s
<= SEVERITY_CRITICAL
))
964 Event
*event
= (Event
*)object
->getData();
965 event
->setSeverity(s
);
967 *result
= new NXSL_Value();
972 * Event::setUserTag() method
974 NXSL_METHOD_DEFINITION(Event
, setUserTag
)
976 if (!argv
[0]->isString())
977 return NXSL_ERR_NOT_STRING
;
979 Event
*event
= (Event
*)object
->getData();
980 event
->setUserTag(argv
[0]->getValueAsCString());
981 *result
= new NXSL_Value();
986 * Event::toJson() method
988 NXSL_METHOD_DEFINITION(Event
, toJson
)
990 Event
*event
= (Event
*)object
->getData();
991 *result
= new NXSL_Value(event
->createJson());
996 * NXSL class Event: constructor
998 NXSL_EventClass::NXSL_EventClass() : NXSL_Class()
1000 _tcscpy(m_name
, _T("Event"));
1002 NXSL_REGISTER_METHOD(Event
, setMessage
, 1);
1003 NXSL_REGISTER_METHOD(Event
, setSeverity
, 1);
1004 NXSL_REGISTER_METHOD(Event
, setUserTag
, 1);
1005 NXSL_REGISTER_METHOD(Event
, toJson
, 0);
1009 * NXSL class Event: get attribute
1011 NXSL_Value
*NXSL_EventClass::getAttr(NXSL_Object
*pObject
, const TCHAR
*attr
)
1013 NXSL_Value
*value
= NULL
;
1015 Event
*event
= (Event
*)pObject
->getData();
1016 if (!_tcscmp(attr
, _T("code")))
1018 value
= new NXSL_Value(event
->getCode());
1020 else if (!_tcscmp(attr
, _T("customMessage")))
1022 value
= new NXSL_Value(event
->getCustomMessage());
1024 else if (!_tcscmp(attr
, _T("id")))
1026 value
= new NXSL_Value(event
->getId());
1028 else if (!_tcscmp(attr
, _T("message")))
1030 value
= new NXSL_Value(event
->getMessage());
1032 else if (!_tcscmp(attr
, _T("name")))
1034 value
= new NXSL_Value(event
->getName());
1036 else if (!_tcscmp(attr
, _T("parameters")))
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
);
1043 else if (!_tcscmp(attr
, _T("severity")))
1045 value
= new NXSL_Value(event
->getSeverity());
1047 else if (!_tcscmp(attr
, _T("source")))
1049 NetObj
*object
= FindObjectById(event
->getSourceId());
1050 value
= (object
!= NULL
) ? object
->createNXSLObject() : new NXSL_Value();
1052 else if (!_tcscmp(attr
, _T("sourceId")))
1054 value
= new NXSL_Value(event
->getSourceId());
1056 else if (!_tcscmp(attr
, _T("timestamp")))
1058 value
= new NXSL_Value((INT64
)event
->getTimeStamp());
1060 else if (!_tcscmp(attr
, _T("userTag")))
1062 value
= new NXSL_Value(event
->getUserTag());
1066 if (attr
[0] == _T('$'))
1068 // Try to find parameter with given index
1070 int index
= _tcstol(&attr
[1], &eptr
, 10);
1071 if ((index
> 0) && (*eptr
== 0))
1073 const TCHAR
*s
= event
->getParameter(index
- 1);
1076 value
= new NXSL_Value(s
);
1081 // Try to find named parameter with given name
1084 const TCHAR
*s
= event
->getNamedParameter(attr
);
1087 value
= new NXSL_Value(s
);
1095 * Alarm::acknowledge() method
1097 NXSL_METHOD_DEFINITION(Alarm
, acknowledge
)
1099 Alarm
*alarm
= (Alarm
*)object
->getData();
1100 *result
= new NXSL_Value(AckAlarmById(alarm
->getAlarmId(), NULL
, false, 0));
1105 * Alarm::resolve() method
1107 NXSL_METHOD_DEFINITION(Alarm
, resolve
)
1109 Alarm
*alarm
= (Alarm
*)object
->getData();
1110 *result
= new NXSL_Value(ResolveAlarmById(alarm
->getAlarmId(), NULL
, false));
1115 * Alarm::terminate() method
1117 NXSL_METHOD_DEFINITION(Alarm
, terminate
)
1119 Alarm
*alarm
= (Alarm
*)object
->getData();
1120 *result
= new NXSL_Value(ResolveAlarmById(alarm
->getAlarmId(), NULL
, true));
1125 * NXSL class Alarm: constructor
1127 NXSL_AlarmClass::NXSL_AlarmClass() : NXSL_Class()
1129 _tcscpy(m_name
, _T("Alarm"));
1131 NXSL_REGISTER_METHOD(Alarm
, acknowledge
, 0);
1132 NXSL_REGISTER_METHOD(Alarm
, resolve
, 0);
1133 NXSL_REGISTER_METHOD(Alarm
, terminate
, 0);
1137 * NXSL object destructor
1139 void NXSL_AlarmClass::onObjectDelete(NXSL_Object
*object
)
1141 delete (Alarm
*)object
->getData();
1145 * NXSL class Alarm: get attribute
1147 NXSL_Value
*NXSL_AlarmClass::getAttr(NXSL_Object
*pObject
, const TCHAR
*attr
)
1149 NXSL_Value
*value
= NULL
;
1150 Alarm
*alarm
= (Alarm
*)pObject
->getData();
1152 if (!_tcscmp(attr
, _T("ackBy")))
1154 value
= new NXSL_Value(alarm
->getAckByUser());
1156 else if (!_tcscmp(attr
, _T("creationTime")))
1158 value
= new NXSL_Value((INT64
)alarm
->getCreationTime());
1160 else if (!_tcscmp(attr
, _T("dciId")))
1162 value
= new NXSL_Value(alarm
->getDciId());
1164 else if (!_tcscmp(attr
, _T("eventCode")))
1166 value
= new NXSL_Value(alarm
->getSourceEventCode());
1168 else if (!_tcscmp(attr
, _T("eventId")))
1170 value
= new NXSL_Value(alarm
->getSourceEventId());
1172 else if (!_tcscmp(attr
, _T("helpdeskReference")))
1174 value
= new NXSL_Value(alarm
->getHelpDeskRef());
1176 else if (!_tcscmp(attr
, _T("helpdeskState")))
1178 value
= new NXSL_Value(alarm
->getHelpDeskState());
1180 else if (!_tcscmp(attr
, _T("id")))
1182 value
= new NXSL_Value(alarm
->getAlarmId());
1184 else if (!_tcscmp(attr
, _T("key")))
1186 value
= new NXSL_Value(alarm
->getKey());
1188 else if (!_tcscmp(attr
, _T("lastChangeTime")))
1190 value
= new NXSL_Value((INT64
)alarm
->getLastChangeTime());
1192 else if (!_tcscmp(attr
, _T("message")))
1194 value
= new NXSL_Value(alarm
->getMessage());
1196 else if (!_tcscmp(attr
, _T("originalSeverity")))
1198 value
= new NXSL_Value(alarm
->getOriginalSeverity());
1200 else if (!_tcscmp(attr
, _T("repeatCount")))
1202 value
= new NXSL_Value(alarm
->getRepeatCount());
1204 else if (!_tcscmp(attr
, _T("resolvedBy")))
1206 value
= new NXSL_Value(alarm
->getResolvedByUser());
1208 else if (!_tcscmp(attr
, _T("severity")))
1210 value
= new NXSL_Value(alarm
->getCurrentSeverity());
1212 else if (!_tcscmp(attr
, _T("sourceObject")))
1214 value
= new NXSL_Value(alarm
->getSourceObject());
1216 else if (!_tcscmp(attr
, _T("state")))
1218 value
= new NXSL_Value(alarm
->getState());
1224 * Implementation of "DCI" class: constructor
1226 NXSL_DciClass::NXSL_DciClass() : NXSL_Class()
1228 _tcscpy(m_name
, _T("DCI"));
1234 void NXSL_DciClass::onObjectDelete(NXSL_Object
*object
)
1236 delete (DCObjectInfo
*)object
->getData();
1240 * Implementation of "DCI" class: get attribute
1242 NXSL_Value
*NXSL_DciClass::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1245 NXSL_Value
*value
= NULL
;
1247 dci
= (DCObjectInfo
*)object
->getData();
1248 if (!_tcscmp(attr
, _T("comments")))
1250 value
= new NXSL_Value(dci
->getComments());
1252 else if (!_tcscmp(attr
, _T("dataType")) && (dci
->getType() == DCO_TYPE_ITEM
))
1254 value
= new NXSL_Value(dci
->getDataType());
1256 else if (!_tcscmp(attr
, _T("description")))
1258 value
= new NXSL_Value(dci
->getDescription());
1260 else if (!_tcscmp(attr
, _T("errorCount")))
1262 value
= new NXSL_Value(dci
->getErrorCount());
1264 else if (!_tcscmp(attr
, _T("id")))
1266 value
= new NXSL_Value(dci
->getId());
1268 else if ((dci
->getType() == DCO_TYPE_ITEM
) && !_tcscmp(attr
, _T("instance")))
1270 value
= new NXSL_Value(dci
->getInstance());
1272 else if (!_tcscmp(attr
, _T("lastPollTime")))
1274 value
= new NXSL_Value((INT64
)dci
->getLastPollTime());
1276 else if (!_tcscmp(attr
, _T("name")))
1278 value
= new NXSL_Value(dci
->getName());
1280 else if (!_tcscmp(attr
, _T("origin")))
1282 value
= new NXSL_Value((LONG
)dci
->getOrigin());
1284 else if (!_tcscmp(attr
, _T("status")))
1286 value
= new NXSL_Value((LONG
)dci
->getStatus());
1288 else if (!_tcscmp(attr
, _T("systemTag")))
1290 value
= new NXSL_Value(dci
->getSystemTag());
1292 else if (!_tcscmp(attr
, _T("type")))
1294 value
= new NXSL_Value((LONG
)dci
->getType());
1300 * Implementation of "SNMP_Transport" class: constructor
1302 NXSL_SNMPTransportClass::NXSL_SNMPTransportClass() : NXSL_Class()
1304 _tcscpy(m_name
, _T("SNMP_Transport"));
1308 * Implementation of "SNMP_Transport" class: get attribute
1310 NXSL_Value
*NXSL_SNMPTransportClass::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1312 NXSL_Value
*value
= NULL
;
1315 t
= (SNMP_Transport
*)object
->getData();
1316 if (!_tcscmp(attr
, _T("snmpVersion")))
1318 const TCHAR
*versions
[] = { _T("1"), _T("2c"), _T("3") };
1319 value
= new NXSL_Value((const TCHAR
*)versions
[t
->getSnmpVersion()]);
1326 * Implementation of "SNMP_Transport" class: NXSL object destructor
1328 void NXSL_SNMPTransportClass::onObjectDelete(NXSL_Object
*object
)
1330 delete (SNMP_Transport
*)object
->getData();
1334 * NXSL class SNMP_VarBind: constructor
1336 NXSL_SNMPVarBindClass::NXSL_SNMPVarBindClass() : NXSL_Class()
1338 _tcscpy(m_name
, _T("SNMP_VarBind"));
1342 * NXSL class SNMP_VarBind: get attribute
1344 NXSL_Value
*NXSL_SNMPVarBindClass::getAttr(NXSL_Object
*object
, const TCHAR
*attr
)
1346 NXSL_Value
*value
= NULL
;
1347 SNMP_Variable
*t
= (SNMP_Variable
*)object
->getData();
1348 if (!_tcscmp(attr
, _T("type")))
1350 value
= new NXSL_Value((UINT32
)t
->getType());
1352 else if (!_tcscmp(attr
, _T("name")))
1354 value
= new NXSL_Value(t
->getName().toString());
1356 else if (!_tcscmp(attr
, _T("value")))
1358 TCHAR strValue
[1024];
1359 value
= new NXSL_Value(t
->getValueAsString(strValue
, 1024));
1361 else if (!_tcscmp(attr
, _T("printableValue")))
1363 TCHAR strValue
[1024];
1364 bool convToHex
= true;
1365 t
->getValueAsPrintableString(strValue
, 1024, &convToHex
);
1366 value
= new NXSL_Value(strValue
);
1368 else if (!_tcscmp(attr
, _T("valueAsIp")))
1370 TCHAR strValue
[128];
1371 t
->getValueAsIPAddr(strValue
);
1372 value
= new NXSL_Value(strValue
);
1374 else if (!_tcscmp(attr
, _T("valueAsMac")))
1376 TCHAR strValue
[128];
1377 t
->getValueAsMACAddr(strValue
);
1378 value
= new NXSL_Value(strValue
);
1385 * NXSL class SNMP_VarBind: NXSL object desctructor
1387 void NXSL_SNMPVarBindClass::onObjectDelete(NXSL_Object
*object
)
1389 delete (SNMP_Variable
*)object
->getData();
1395 NXSL_AlarmClass g_nxslAlarmClass
;
1396 NXSL_ChassisClass g_nxslChassisClass
;
1397 NXSL_ClusterClass g_nxslClusterClass
;
1398 NXSL_DciClass g_nxslDciClass
;
1399 NXSL_EventClass g_nxslEventClass
;
1400 NXSL_InterfaceClass g_nxslInterfaceClass
;
1401 NXSL_MobileDeviceClass g_nxslMobileDeviceClass
;
1402 NXSL_NetObjClass g_nxslNetObjClass
;
1403 NXSL_NodeClass g_nxslNodeClass
;
1404 NXSL_SNMPTransportClass g_nxslSnmpTransportClass
;
1405 NXSL_SNMPVarBindClass g_nxslSnmpVarBindClass
;
1406 NXSL_ZoneClass g_nxslZoneClass
;