implemented nxsl class "Interface" and function GetInterfaceObject; manual updated
[public/netxms.git] / src / server / core / nxsl_classes.cpp
CommitLineData
5039dede
AK
1/*
2** NetXMS - Network Management System
d8ca56d5 3** Copyright (C) 2003-2011 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
25
541a3ebc
VK
26//
27// Implementation of "NetXMS object" class
28//
29
30NXSL_NetObjClass::NXSL_NetObjClass()
31 :NXSL_Class()
32{
35f836fe 33 _tcscpy(m_szName, _T("NetObj"));
541a3ebc
VK
34}
35
36NXSL_Value *NXSL_NetObjClass::getAttr(NXSL_Object *pObject, const TCHAR *pszAttr)
37{
38 NetObj *object;
39 NXSL_Value *pValue = NULL;
35f836fe 40 TCHAR szBuffer[256];
541a3ebc
VK
41
42 object = (NetObj *)pObject->getData();
35f836fe 43 if (!_tcscmp(pszAttr, _T("name")))
541a3ebc
VK
44 {
45 pValue = new NXSL_Value(object->Name());
46 }
35f836fe 47 else if (!_tcscmp(pszAttr, _T("id")))
541a3ebc
VK
48 {
49 pValue = new NXSL_Value(object->Id());
50 }
35f836fe 51 else if (!_tcscmp(pszAttr, _T("status")))
541a3ebc
VK
52 {
53 pValue = new NXSL_Value((LONG)object->Status());
54 }
35f836fe 55 else if (!_tcscmp(pszAttr, _T("ipAddr")))
541a3ebc
VK
56 {
57 IpToStr(object->IpAddr(), szBuffer);
58 pValue = new NXSL_Value(szBuffer);
59 }
35f836fe 60 else if (!_tcscmp(pszAttr, _T("type")))
541a3ebc
VK
61 {
62 pValue = new NXSL_Value((LONG)object->Type());
74fde582
VK
63 }
64 else if (!_tcscmp(pszAttr, _T("comments")))
65 {
66 pValue = new NXSL_Value(object->getComments());
541a3ebc
VK
67 }
68 else
69 {
70 const TCHAR *attrValue = object->GetCustomAttribute(pszAttr);
71 if (attrValue != NULL)
72 {
73 pValue = new NXSL_Value(attrValue);
74 }
75 }
76 return pValue;
77}
78
79
5039dede
AK
80//
81// Implementation of "NetXMS node" class
82//
83
84NXSL_NodeClass::NXSL_NodeClass()
85 :NXSL_Class()
86{
35f836fe 87 _tcscpy(m_szName, _T("Node"));
5039dede
AK
88}
89
bb51576f 90NXSL_Value *NXSL_NodeClass::getAttr(NXSL_Object *pObject, const TCHAR *pszAttr)
5039dede
AK
91{
92 Node *pNode;
93 NXSL_Value *pValue = NULL;
35f836fe 94 TCHAR szBuffer[256];
5039dede 95
bb5365ed 96 pNode = (Node *)pObject->getData();
35f836fe 97 if (!_tcscmp(pszAttr, _T("name")))
5039dede
AK
98 {
99 pValue = new NXSL_Value(pNode->Name());
100 }
35f836fe 101 else if (!_tcscmp(pszAttr, _T("id")))
5039dede
AK
102 {
103 pValue = new NXSL_Value(pNode->Id());
104 }
35f836fe 105 else if (!_tcscmp(pszAttr, _T("status")))
5039dede
AK
106 {
107 pValue = new NXSL_Value((LONG)pNode->Status());
108 }
35f836fe 109 else if (!_tcscmp(pszAttr, _T("ipAddr")))
5039dede
AK
110 {
111 IpToStr(pNode->IpAddr(), szBuffer);
112 pValue = new NXSL_Value(szBuffer);
113 }
35f836fe 114 else if (!_tcscmp(pszAttr, _T("isAgent")))
5039dede 115 {
7c521895 116 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_NATIVE_AGENT) ? 1 : 0));
5039dede 117 }
35f836fe 118 else if (!_tcscmp(pszAttr, _T("isSNMP")))
5039dede 119 {
7c521895 120 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_SNMP) ? 1 : 0));
5039dede 121 }
35f836fe 122 else if (!_tcscmp(pszAttr, _T("isBridge")))
5039dede 123 {
7c521895 124 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_BRIDGE) ? 1 : 0));
5039dede 125 }
35f836fe 126 else if (!_tcscmp(pszAttr, _T("isRouter")))
5039dede 127 {
7c521895 128 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_ROUTER) ? 1 : 0));
5039dede 129 }
35f836fe 130 else if (!_tcscmp(pszAttr, _T("isPrinter")))
5039dede 131 {
7c521895 132 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_PRINTER) ? 1 : 0));
5039dede 133 }
35f836fe 134 else if (!_tcscmp(pszAttr, _T("isCDP")))
5039dede 135 {
7c521895 136 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_CDP) ? 1 : 0));
5039dede 137 }
35f836fe 138 else if (!_tcscmp(pszAttr, _T("isSONMP")))
5039dede 139 {
7c521895 140 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_SONMP) ? 1 : 0));
5039dede 141 }
35f836fe 142 else if (!_tcscmp(pszAttr, _T("isLLDP")))
5039dede 143 {
7c521895 144 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_LLDP) ? 1 : 0));
5039dede 145 }
d8ca56d5
VK
146 else if (!_tcscmp(pszAttr, _T("isPAE")) || !_tcscmp(pszAttr, _T("is802_1x")))
147 {
148 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_8021X) ? 1 : 0));
149 }
35f836fe 150 else if (!_tcscmp(pszAttr, _T("snmpVersion")))
5039dede 151 {
7c521895 152 pValue = new NXSL_Value((LONG)pNode->getSNMPVersion());
5039dede 153 }
35f836fe 154 else if (!_tcscmp(pszAttr, _T("snmpOID")))
5039dede 155 {
7c521895 156 pValue = new NXSL_Value(pNode->getSNMPObjectId());
5039dede 157 }
35f836fe 158 else if (!_tcscmp(pszAttr, _T("agentVersion")))
5039dede 159 {
7c521895 160 pValue = new NXSL_Value(pNode->getAgentVersion());
5039dede 161 }
35f836fe 162 else if (!_tcscmp(pszAttr, _T("platformName")))
5039dede 163 {
7c521895 164 pValue = new NXSL_Value(pNode->getPlatformName());
ff0b91fd
VK
165 }
166 else if (!_tcscmp(pszAttr, _T("snmpSysName")))
167 {
168 pValue = new NXSL_Value(pNode->getSysName());
169 }
170 else if (!_tcscmp(pszAttr, _T("sysDescription")))
171 {
172 pValue = new NXSL_Value(pNode->getSysDescription());
74fde582
VK
173 }
174 else if (!_tcscmp(pszAttr, _T("comments")))
175 {
176 pValue = new NXSL_Value(pNode->getComments());
5039dede 177 }
210642a1
VK
178 else
179 {
180 const TCHAR *attrValue = pNode->GetCustomAttribute(pszAttr);
181 if (attrValue != NULL)
182 {
183 pValue = new NXSL_Value(attrValue);
184 }
185 }
5039dede
AK
186 return pValue;
187}
188
189
09e834a1
VK
190//
191// Implementation of "NetXMS interface" class
192//
193
194NXSL_InterfaceClass::NXSL_InterfaceClass() : NXSL_Class()
195{
196 _tcscpy(m_szName, _T("Interface"));
197}
198
199NXSL_Value *NXSL_InterfaceClass::getAttr(NXSL_Object *pObject, const TCHAR *pszAttr)
200{
201 Interface *iface;
202 NXSL_Value *pValue = NULL;
203 TCHAR szBuffer[256];
204
205 iface = (Interface *)pObject->getData();
206 if (!_tcscmp(pszAttr, _T("name")))
207 {
208 pValue = new NXSL_Value(iface->Name());
209 }
210 else if (!_tcscmp(pszAttr, _T("id")))
211 {
212 pValue = new NXSL_Value(iface->Id());
213 }
214 else if (!_tcscmp(pszAttr, _T("status")))
215 {
216 pValue = new NXSL_Value((LONG)iface->Status());
217 }
218 else if (!_tcscmp(pszAttr, _T("ipAddr")))
219 {
220 IpToStr(iface->IpAddr(), szBuffer);
221 pValue = new NXSL_Value(szBuffer);
222 }
223 else if (!_tcscmp(pszAttr, _T("ipNetMask")))
224 {
225 IpToStr(iface->getIpNetMask(), szBuffer);
226 pValue = new NXSL_Value(szBuffer);
227 }
228 else if (!_tcscmp(pszAttr, _T("isLoopback")))
229 {
230 pValue = new NXSL_Value((LONG)(iface->isLoopback() ? 1 : 0));
231 }
232 else if (!_tcscmp(pszAttr, _T("isPhysicalPort")))
233 {
234 pValue = new NXSL_Value((LONG)(iface->isPhysicalPort() ? 1 : 0));
235 }
236 else if (!_tcscmp(pszAttr, _T("isManuallyCreated")))
237 {
238 pValue = new NXSL_Value((LONG)(iface->isManuallyCreated() ? 1 : 0));
239 }
240 else if (!_tcscmp(pszAttr, _T("isExcludedFromTopology")))
241 {
242 pValue = new NXSL_Value((LONG)(iface->isExcludedFromTopology() ? 1 : 0));
243 }
244 else if (!_tcscmp(pszAttr, _T("description")))
245 {
246 pValue = new NXSL_Value(iface->getDescription());
247 }
248 else if (!_tcscmp(pszAttr, _T("comments")))
249 {
250 pValue = new NXSL_Value(iface->getComments());
251 }
252 else if (!_tcscmp(pszAttr, _T("ifIndex")))
253 {
254 pValue = new NXSL_Value(iface->getIfIndex());
255 }
256 else if (!_tcscmp(pszAttr, _T("ifType")))
257 {
258 pValue = new NXSL_Value(iface->getIfType());
259 }
260 else if (!_tcscmp(pszAttr, _T("bridgePortNumber")))
261 {
262 pValue = new NXSL_Value(iface->getBridgePortNumber());
263 }
264 else
265 {
266 const TCHAR *attrValue = iface->GetCustomAttribute(pszAttr);
267 if (attrValue != NULL)
268 {
269 pValue = new NXSL_Value(attrValue);
270 }
271 }
272 return pValue;
273}
274
275
5039dede
AK
276//
277// Implementation of "NetXMS event" class
278//
279
3c050e4c 280NXSL_EventClass::NXSL_EventClass() : NXSL_Class()
5039dede 281{
35f836fe 282 _tcscpy(m_szName, _T("Event"));
5039dede
AK
283}
284
bb51576f 285NXSL_Value *NXSL_EventClass::getAttr(NXSL_Object *pObject, const TCHAR *pszAttr)
5039dede
AK
286{
287 Event *event;
288 NXSL_Value *value = NULL;
289
bb5365ed 290 event = (Event *)pObject->getData();
35f836fe 291 if (!_tcscmp(pszAttr, _T("code")))
5039dede 292 {
210642a1 293 value = new NXSL_Value(event->getCode());
5039dede 294 }
35f836fe 295 else if (!_tcscmp(pszAttr, _T("name")))
86a4796f
VK
296 {
297 value = new NXSL_Value(event->getName());
298 }
35f836fe 299 else if (!_tcscmp(pszAttr, _T("id")))
5039dede 300 {
210642a1 301 value = new NXSL_Value(event->getId());
5039dede 302 }
35f836fe 303 else if (!_tcscmp(pszAttr, _T("severity")))
5039dede 304 {
210642a1 305 value = new NXSL_Value(event->getSeverity());
5039dede 306 }
35f836fe 307 else if (!_tcscmp(pszAttr, _T("timestamp")))
5039dede 308 {
210642a1 309 value = new NXSL_Value((INT64)event->getTimeStamp());
5039dede 310 }
35f836fe 311 else if (!_tcscmp(pszAttr, _T("message")))
5039dede 312 {
210642a1
VK
313 value = new NXSL_Value(event->getMessage());
314 }
35f836fe 315 else if (!_tcscmp(pszAttr, _T("customMessage")))
210642a1
VK
316 {
317 value = new NXSL_Value(event->getCustomMessage());
5039dede 318 }
35f836fe 319 else if (!_tcscmp(pszAttr, _T("userTag")))
5039dede 320 {
210642a1 321 value = new NXSL_Value(event->getUserTag());
5039dede 322 }
35f836fe 323 else if (!_tcscmp(pszAttr, _T("parameters")))
5039dede
AK
324 {
325 NXSL_Array *array = new NXSL_Array;
326 DWORD i;
327
210642a1 328 for(i = 0; i < event->getParametersCount(); i++)
bb5365ed 329 array->set((int)(i + 1), new NXSL_Value(event->getParameter(i)));
5039dede
AK
330 value = new NXSL_Value(array);
331 }
332 return value;
333}
334
335
bb51576f
VK
336//
337// Implementation of "DCI" class
338//
339
340NXSL_DciClass::NXSL_DciClass()
341 :NXSL_Class()
342{
35f836fe 343 _tcscpy(m_szName, _T("DCI"));
bb51576f
VK
344}
345
346NXSL_Value *NXSL_DciClass::getAttr(NXSL_Object *object, const TCHAR *attr)
347{
348 DCItem *dci;
349 NXSL_Value *value = NULL;
350
351 dci = (DCItem *)object->getData();
35f836fe 352 if (!_tcscmp(attr, _T("id")))
bb51576f
VK
353 {
354 value = new NXSL_Value(dci->getId());
355 }
35f836fe 356 else if (!_tcscmp(attr, _T("name")))
bb51576f
VK
357 {
358 value = new NXSL_Value(dci->getName());
359 }
35f836fe 360 else if (!_tcscmp(attr, _T("description")))
bb51576f
VK
361 {
362 value = new NXSL_Value(dci->getDescription());
363 }
35f836fe 364 else if (!_tcscmp(attr, _T("origin")))
bb51576f
VK
365 {
366 value = new NXSL_Value((LONG)dci->getDataSource());
367 }
35f836fe 368 else if (!_tcscmp(attr, _T("dataType")))
bb51576f
VK
369 {
370 value = new NXSL_Value((LONG)dci->getDataType());
371 }
35f836fe 372 else if (!_tcscmp(attr, _T("status")))
bb51576f
VK
373 {
374 value = new NXSL_Value((LONG)dci->getStatus());
375 }
35f836fe 376 else if (!_tcscmp(attr, _T("errorCount")))
d7877de4
VK
377 {
378 value = new NXSL_Value(dci->getErrorCount());
379 }
35f836fe 380 else if (!_tcscmp(attr, _T("lastPollTime")))
bb51576f 381 {
4294323c 382 value = new NXSL_Value((INT64)dci->getLastPollTime());
bb51576f 383 }
35f836fe 384 else if (!_tcscmp(attr, _T("systemTag")))
bb51576f
VK
385 {
386 value = new NXSL_Value(dci->getSystemTag());
387 }
388 return value;
389}
390
391
5039dede
AK
392//
393// Class objects
394//
395
541a3ebc 396NXSL_NetObjClass g_nxslNetObjClass;
5039dede 397NXSL_NodeClass g_nxslNodeClass;
09e834a1 398NXSL_InterfaceClass g_nxslInterfaceClass;
5039dede 399NXSL_EventClass g_nxslEventClass;
bb51576f 400NXSL_DciClass g_nxslDciClass;