ef51376a8810832f541f6b685ee70666bd69a499
[public/netxms.git] / src / server / core / nxsl_classes.cpp
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2011 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: nxsl_classes.cpp
20 **
21 **/
22
23 #include "nxcore.h"
24
25
26 //
27 // Implementation of "NetXMS object" class
28 //
29
30 NXSL_NetObjClass::NXSL_NetObjClass()
31 :NXSL_Class()
32 {
33 _tcscpy(m_szName, _T("NetObj"));
34 }
35
36 NXSL_Value *NXSL_NetObjClass::getAttr(NXSL_Object *pObject, const TCHAR *pszAttr)
37 {
38 NetObj *object;
39 NXSL_Value *pValue = NULL;
40 TCHAR szBuffer[256];
41
42 object = (NetObj *)pObject->getData();
43 if (!_tcscmp(pszAttr, _T("name")))
44 {
45 pValue = new NXSL_Value(object->Name());
46 }
47 else if (!_tcscmp(pszAttr, _T("id")))
48 {
49 pValue = new NXSL_Value(object->Id());
50 }
51 else if (!_tcscmp(pszAttr, _T("status")))
52 {
53 pValue = new NXSL_Value((LONG)object->Status());
54 }
55 else if (!_tcscmp(pszAttr, _T("ipAddr")))
56 {
57 IpToStr(object->IpAddr(), szBuffer);
58 pValue = new NXSL_Value(szBuffer);
59 }
60 else if (!_tcscmp(pszAttr, _T("type")))
61 {
62 pValue = new NXSL_Value((LONG)object->Type());
63 }
64 else if (!_tcscmp(pszAttr, _T("comments")))
65 {
66 pValue = new NXSL_Value(object->getComments());
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
80 //
81 // Implementation of "NetXMS node" class
82 //
83
84 NXSL_NodeClass::NXSL_NodeClass()
85 :NXSL_Class()
86 {
87 _tcscpy(m_szName, _T("Node"));
88 }
89
90 NXSL_Value *NXSL_NodeClass::getAttr(NXSL_Object *pObject, const TCHAR *pszAttr)
91 {
92 Node *pNode;
93 NXSL_Value *pValue = NULL;
94 TCHAR szBuffer[256];
95
96 pNode = (Node *)pObject->getData();
97 if (!_tcscmp(pszAttr, _T("name")))
98 {
99 pValue = new NXSL_Value(pNode->Name());
100 }
101 else if (!_tcscmp(pszAttr, _T("id")))
102 {
103 pValue = new NXSL_Value(pNode->Id());
104 }
105 else if (!_tcscmp(pszAttr, _T("status")))
106 {
107 pValue = new NXSL_Value((LONG)pNode->Status());
108 }
109 else if (!_tcscmp(pszAttr, _T("ipAddr")))
110 {
111 IpToStr(pNode->IpAddr(), szBuffer);
112 pValue = new NXSL_Value(szBuffer);
113 }
114 else if (!_tcscmp(pszAttr, _T("isAgent")))
115 {
116 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_NATIVE_AGENT) ? 1 : 0));
117 }
118 else if (!_tcscmp(pszAttr, _T("isSNMP")))
119 {
120 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_SNMP) ? 1 : 0));
121 }
122 else if (!_tcscmp(pszAttr, _T("isBridge")))
123 {
124 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_BRIDGE) ? 1 : 0));
125 }
126 else if (!_tcscmp(pszAttr, _T("isRouter")))
127 {
128 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_ROUTER) ? 1 : 0));
129 }
130 else if (!_tcscmp(pszAttr, _T("isPrinter")))
131 {
132 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_PRINTER) ? 1 : 0));
133 }
134 else if (!_tcscmp(pszAttr, _T("isCDP")))
135 {
136 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_CDP) ? 1 : 0));
137 }
138 else if (!_tcscmp(pszAttr, _T("isSONMP")))
139 {
140 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_SONMP) ? 1 : 0));
141 }
142 else if (!_tcscmp(pszAttr, _T("isLLDP")))
143 {
144 pValue = new NXSL_Value((LONG)((pNode->getFlags() & NF_IS_LLDP) ? 1 : 0));
145 }
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 }
150 else if (!_tcscmp(pszAttr, _T("snmpVersion")))
151 {
152 pValue = new NXSL_Value((LONG)pNode->getSNMPVersion());
153 }
154 else if (!_tcscmp(pszAttr, _T("snmpOID")))
155 {
156 pValue = new NXSL_Value(pNode->getSNMPObjectId());
157 }
158 else if (!_tcscmp(pszAttr, _T("agentVersion")))
159 {
160 pValue = new NXSL_Value(pNode->getAgentVersion());
161 }
162 else if (!_tcscmp(pszAttr, _T("platformName")))
163 {
164 pValue = new NXSL_Value(pNode->getPlatformName());
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());
173 }
174 else if (!_tcscmp(pszAttr, _T("comments")))
175 {
176 pValue = new NXSL_Value(pNode->getComments());
177 }
178 else
179 {
180 const TCHAR *attrValue = pNode->GetCustomAttribute(pszAttr);
181 if (attrValue != NULL)
182 {
183 pValue = new NXSL_Value(attrValue);
184 }
185 }
186 return pValue;
187 }
188
189
190 //
191 // Implementation of "NetXMS event" class
192 //
193
194 NXSL_EventClass::NXSL_EventClass() : NXSL_Class()
195 {
196 _tcscpy(m_szName, _T("Event"));
197 }
198
199 NXSL_Value *NXSL_EventClass::getAttr(NXSL_Object *pObject, const TCHAR *pszAttr)
200 {
201 Event *event;
202 NXSL_Value *value = NULL;
203
204 event = (Event *)pObject->getData();
205 if (!_tcscmp(pszAttr, _T("code")))
206 {
207 value = new NXSL_Value(event->getCode());
208 }
209 else if (!_tcscmp(pszAttr, _T("name")))
210 {
211 value = new NXSL_Value(event->getName());
212 }
213 else if (!_tcscmp(pszAttr, _T("id")))
214 {
215 value = new NXSL_Value(event->getId());
216 }
217 else if (!_tcscmp(pszAttr, _T("severity")))
218 {
219 value = new NXSL_Value(event->getSeverity());
220 }
221 else if (!_tcscmp(pszAttr, _T("timestamp")))
222 {
223 value = new NXSL_Value((INT64)event->getTimeStamp());
224 }
225 else if (!_tcscmp(pszAttr, _T("message")))
226 {
227 value = new NXSL_Value(event->getMessage());
228 }
229 else if (!_tcscmp(pszAttr, _T("customMessage")))
230 {
231 value = new NXSL_Value(event->getCustomMessage());
232 }
233 else if (!_tcscmp(pszAttr, _T("userTag")))
234 {
235 value = new NXSL_Value(event->getUserTag());
236 }
237 else if (!_tcscmp(pszAttr, _T("parameters")))
238 {
239 NXSL_Array *array = new NXSL_Array;
240 DWORD i;
241
242 for(i = 0; i < event->getParametersCount(); i++)
243 array->set((int)(i + 1), new NXSL_Value(event->getParameter(i)));
244 value = new NXSL_Value(array);
245 }
246 return value;
247 }
248
249
250 //
251 // Implementation of "DCI" class
252 //
253
254 NXSL_DciClass::NXSL_DciClass()
255 :NXSL_Class()
256 {
257 _tcscpy(m_szName, _T("DCI"));
258 }
259
260 NXSL_Value *NXSL_DciClass::getAttr(NXSL_Object *object, const TCHAR *attr)
261 {
262 DCItem *dci;
263 NXSL_Value *value = NULL;
264
265 dci = (DCItem *)object->getData();
266 if (!_tcscmp(attr, _T("id")))
267 {
268 value = new NXSL_Value(dci->getId());
269 }
270 else if (!_tcscmp(attr, _T("name")))
271 {
272 value = new NXSL_Value(dci->getName());
273 }
274 else if (!_tcscmp(attr, _T("description")))
275 {
276 value = new NXSL_Value(dci->getDescription());
277 }
278 else if (!_tcscmp(attr, _T("origin")))
279 {
280 value = new NXSL_Value((LONG)dci->getDataSource());
281 }
282 else if (!_tcscmp(attr, _T("dataType")))
283 {
284 value = new NXSL_Value((LONG)dci->getDataType());
285 }
286 else if (!_tcscmp(attr, _T("status")))
287 {
288 value = new NXSL_Value((LONG)dci->getStatus());
289 }
290 else if (!_tcscmp(attr, _T("errorCount")))
291 {
292 value = new NXSL_Value(dci->getErrorCount());
293 }
294 else if (!_tcscmp(attr, _T("lastPollTime")))
295 {
296 value = new NXSL_Value((INT64)dci->getLastPollTime());
297 }
298 else if (!_tcscmp(attr, _T("systemTag")))
299 {
300 value = new NXSL_Value(dci->getSystemTag());
301 }
302 return value;
303 }
304
305
306 //
307 // Class objects
308 //
309
310 NXSL_NetObjClass g_nxslNetObjClass;
311 NXSL_NodeClass g_nxslNodeClass;
312 NXSL_EventClass g_nxslEventClass;
313 NXSL_DciClass g_nxslDciClass;