39e2743e270544464021c0db5278e93c4a733586
[public/netxms.git] / src / agent / subagents / rpi / rpi.cpp
1 /*
2 ** Raspberry Pi subagent
3 ** Copyright (C) 2013 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 **/
20
21 #include <nms_common.h>
22 #include <nms_agent.h>
23
24 /**
25 * Sensor data
26 */
27 extern float g_sensorData[];
28 extern time_t g_sensorUpdateTime;
29
30 /**
31 * Sensor reading
32 */
33 static LONG H_Sensors(const TCHAR *param, const TCHAR *arg, TCHAR *value)
34 {
35 LONG ret;
36 if (time(NULL) - g_sensorUpdateTime <= 60)
37 {
38 ret_int(value, (int)g_sensorData[(int)arg]);
39 ret = SYSINFO_RC_SUCCESS;
40 }
41 else
42 {
43 ret = SYSINFO_RC_ERROR;
44 }
45
46 return ret;
47 }
48
49 /**
50 * Parameters
51 */
52 static NETXMS_SUBAGENT_PARAM m_parameters[] =
53 {
54 { _T("Sensors.Humidity"), H_Sensors, (TCHAR *)0, DCI_DT_INT, _T("Humidity") },
55 { _T("Sensors.Temperature"), H_Sensors, (TCHAR *)1, DCI_DT_INT, _T("Temperature") }
56 };
57
58 /**
59 * Subagent information
60 */
61 static NETXMS_SUBAGENT_INFO m_info =
62 {
63 NETXMS_SUBAGENT_INFO_MAGIC,
64 _T("RPI"), NETXMS_VERSION_STRING,
65 NULL, NULL, NULL,
66 sizeof(m_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
67 m_parameters,
68 0, NULL, // lists
69 0, NULL, // tables
70 0, NULL, // actions
71 0, NULL // push parameters
72 };
73
74 /**
75 * Entry point for NetXMS agent
76 */
77 DECLARE_SUBAGENT_ENTRY_POINT(RPI)
78 {
79 *ppInfo = &m_info;
80 return TRUE;
81 }