dashboard editor improved; added "refresh" menu to dashboard view; added "comments...
[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()
195 :NXSL_Class()
196 {
197 _tcscpy(m_szName, _T("Event"));
198 }
199
200 NXSL_Value *NXSL_EventClass::getAttr(NXSL_Object *pObject, const TCHAR *pszAttr)
201 {
202 Event *event;
203 NXSL_Value *value = NULL;
204
205 event = (Event *)pObject->getData();
206 if (!_tcscmp(pszAttr, _T("code")))
207 {
208 value = new NXSL_Value(event->getCode());
209 }
210 else if (!_tcscmp(pszAttr, _T("name")))
211 {
212 value = new NXSL_Value(event->getName());
213 }
214 else if (!_tcscmp(pszAttr, _T("id")))
215 {
216 value = new NXSL_Value(event->getId());
217 }
218 else if (!_tcscmp(pszAttr, _T("severity")))
219 {
220 value = new NXSL_Value(event->getSeverity());
221 }
222 else if (!_tcscmp(pszAttr, _T("timestamp")))
223 {
224 value = new NXSL_Value((INT64)event->getTimeStamp());
225 }
226 else if (!_tcscmp(pszAttr, _T("message")))
227 {
228 value = new NXSL_Value(event->getMessage());
229 }
230 else if (!_tcscmp(pszAttr, _T("customMessage")))
231 {
232 value = new NXSL_Value(event->getCustomMessage());
233 }
234 else if (!_tcscmp(pszAttr, _T("userTag")))
235 {
236 value = new NXSL_Value(event->getUserTag());
237 }
238 else if (!_tcscmp(pszAttr, _T("parameters")))
239 {
240 NXSL_Array *array = new NXSL_Array;
241 DWORD i;
242
243 for(i = 0; i < event->getParametersCount(); i++)
244 array->set((int)(i + 1), new NXSL_Value(event->getParameter(i)));
245 value = new NXSL_Value(array);
246 }
247 return value;
248 }
249
250
251 //
252 // Implementation of "DCI" class
253 //
254
255 NXSL_DciClass::NXSL_DciClass()
256 :NXSL_Class()
257 {
258 _tcscpy(m_szName, _T("DCI"));
259 }
260
261 NXSL_Value *NXSL_DciClass::getAttr(NXSL_Object *object, const TCHAR *attr)
262 {
263 DCItem *dci;
264 NXSL_Value *value = NULL;
265
266 dci = (DCItem *)object->getData();
267 if (!_tcscmp(attr, _T("id")))
268 {
269 value = new NXSL_Value(dci->getId());
270 }
271 else if (!_tcscmp(attr, _T("name")))
272 {
273 value = new NXSL_Value(dci->getName());
274 }
275 else if (!_tcscmp(attr, _T("description")))
276 {
277 value = new NXSL_Value(dci->getDescription());
278 }
279 else if (!_tcscmp(attr, _T("origin")))
280 {
281 value = new NXSL_Value((LONG)dci->getDataSource());
282 }
283 else if (!_tcscmp(attr, _T("dataType")))
284 {
285 value = new NXSL_Value((LONG)dci->getDataType());
286 }
287 else if (!_tcscmp(attr, _T("status")))
288 {
289 value = new NXSL_Value((LONG)dci->getStatus());
290 }
291 else if (!_tcscmp(attr, _T("errorCount")))
292 {
293 value = new NXSL_Value(dci->getErrorCount());
294 }
295 else if (!_tcscmp(attr, _T("lastPollTime")))
296 {
297 value = new NXSL_Value((INT64)dci->getLastPollTime());
298 }
299 else if (!_tcscmp(attr, _T("systemTag")))
300 {
301 value = new NXSL_Value(dci->getSystemTag());
302 }
303 return value;
304 }
305
306
307 //
308 // Class objects
309 //
310
311 NXSL_NetObjClass g_nxslNetObjClass;
312 NXSL_NodeClass g_nxslNodeClass;
313 NXSL_EventClass g_nxslEventClass;
314 NXSL_DciClass g_nxslDciClass;