b5b46250587ac1c4e800e35581aadb9c9234bd57
[public/netxms.git] / src / agent / subagents / sunos / main.cpp
1 /*
2 ** NetXMS subagent for SunOS/Solaris
3 ** Copyright (C) 2004, 2005 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 ** $module: main.cpp
20 **
21 **/
22
23 #include "sunos_subagent.h"
24
25
26 //
27 // Hanlder functions
28 //
29
30 LONG H_CPUCount(char *pszParam, char *pArg, char *pValue);
31 LONG H_CPUUsage(char *pszParam, char *pArg, char *pValue);
32 LONG H_DiskInfo(char *pszParam, char *pArg, char *pValue);
33 LONG H_Hostname(char *pszParam, char *pArg, char *pValue);
34 LONG H_KStat(char *pszParam, char *pArg, char *pValue);
35 LONG H_LoadAvg(char *pszParam, char *pArg, char *pValue);
36 LONG H_MemoryInfo(char *pszParam, char *pArg, char *pValue);
37 LONG H_NetIfList(char *pszParam, char *pArg, NETXMS_VALUES_LIST *pValue);
38 LONG H_NetIfAdminStatus(char *pszParam, char *pArg, char *pValue);
39 LONG H_NetIfDescription(char *pszParam, char *pArg, char *pValue);
40 LONG H_NetInterfaceStats(char *pszParam, char *pArg, char *pValue);
41 LONG H_ProcessCount(char *pszParam, char *pArg, char *pValue);
42 LONG H_ProcessInfo(char *pszParam, char *pArg, char *pValue);
43 LONG H_ProcessList(char *pszParam, char *pArg, NETXMS_VALUES_LIST *pValue);
44 LONG H_SysProcCount(char *pszParam, char *pArg, char *pValue);
45 LONG H_Uname(char *pszParam, char *pArg, char *pValue);
46 LONG H_Uptime(char *pszParam, char *pArg, char *pValue);
47
48
49 //
50 // Global variables
51 //
52
53 BOOL g_bShutdown = FALSE;
54
55
56 //
57 // Static data
58 //
59
60 static THREAD m_hCPUStatThread = INVALID_THREAD_HANDLE;
61
62
63 //
64 // Detect support for source packages
65 //
66
67 static LONG H_SourcePkg(char *pszParam, char *pArg, char *pValue)
68 {
69 ret_int(pValue, 1);
70 return SYSINFO_RC_SUCCESS;
71 }
72
73
74 //
75 // Called by master agent at unload
76 //
77
78 static void UnloadHandler(void)
79 {
80 g_bShutdown = TRUE;
81 ThreadJoin(m_hCPUStatThread);
82 }
83
84
85 //
86 // Subagent information
87 //
88
89 static NETXMS_SUBAGENT_PARAM m_parameters[] =
90 {
91 { "Agent.SourcePackageSupport", H_SourcePkg, NULL, DCI_DT_INT, "" },
92 { "Disk.Free(*)", H_DiskInfo, (char *)DISK_FREE, DCI_DT_UINT64, "Free disk space on *" },
93 { "Disk.Total(*)", H_DiskInfo, (char *)DISK_TOTAL, DCI_DT_UINT64, "Total disk space on *" },
94 { "Disk.Used(*)", H_DiskInfo, (char *)DISK_USED, DCI_DT_UINT64, "Used disk space on *" },
95 { "Net.Interface.AdminStatus(*)", H_NetIfAdminStatus, NULL, DCI_DT_INT, "Administrative status of interface {instance}" },
96 { "Net.Interface.BytesIn(*)", H_NetInterfaceStats, "rbytes", DCI_DT_UINT, "Number of input bytes on interface {instance}" },
97 { "Net.Interface.BytesOut(*)", H_NetInterfaceStats, "obytes", DCI_DT_UINT, "Number of output bytes on interface {instance}" },
98 { "Net.Interface.Description(*)", H_NetIfDescription, NULL, DCI_DT_STRING, "" },
99 { "Net.Interface.InErrors(*)", H_NetInterfaceStats, "ierrors", DCI_DT_UINT, "Number of input errors on interface {instance}" },
100 { "Net.Interface.Link(*)", H_NetInterfaceStats, "link_up", DCI_DT_INT, "Link status for interface {instance}" },
101 { "Net.Interface.OutErrors(*)", H_NetInterfaceStats, "oerrors", DCI_DT_UINT, "Number of output errors on interface {instance}" },
102 { "Net.Interface.PacketsIn(*)", H_NetInterfaceStats, "ipackets", DCI_DT_UINT, "Number of input packets on interface {instance}" },
103 { "Net.Interface.PacketsOut(*)", H_NetInterfaceStats, "opackets", DCI_DT_UINT, "Number of output packets on interface {instance}" },
104 { "Net.Interface.Speed(*)", H_NetInterfaceStats, "ifspeed", DCI_DT_UINT, "Speed of interface {instance}" },
105 { "Process.Count(*)", H_ProcessCount, NULL, DCI_DT_UINT, "Number of proceses {instance}" },
106 { "Process.KernelTime(*)", H_ProcessInfo, (char *)PROCINFO_KTIME, DCI_DT_UINT64, "" },
107 { "Process.PageFaults(*)", H_ProcessInfo, (char *)PROCINFO_PF, DCI_DT_UINT64, "" },
108 { "Process.UserTime(*)", H_ProcessInfo, (char *)PROCINFO_UTIME, DCI_DT_UINT64, "" },
109 { "System.CPU.Count", H_CPUCount, NULL, DCI_DT_UINT, "Number of CPU in the system" },
110 { "System.CPU.LoadAvg", H_LoadAvg, (char *)0, DCI_DT_FLOAT, "Average CPU load for last minute" },
111 { "System.CPU.LoadAvg5", H_LoadAvg, (char *)1, DCI_DT_FLOAT, "Average CPU load for last 5 minutes" },
112 { "System.CPU.LoadAvg15", H_LoadAvg, (char *)2, DCI_DT_FLOAT, "Average CPU load for last 15 minutes" },
113 { "System.CPU.Usage", H_CPUUsage, "T0", DCI_DT_FLOAT, "Average CPU(s) utilization for last minute" },
114 { "System.CPU.Usage5", H_CPUUsage, "T1", DCI_DT_FLOAT, "Average CPU(s) utilization for last 5 minutes" },
115 { "System.CPU.Usage15", H_CPUUsage, "T2", DCI_DT_FLOAT, "Average CPU(s) utilization for last 15 minutes" },
116 { "System.CPU.Usage(*)", H_CPUUsage, "C0", DCI_DT_FLOAT, "Average CPU {instance} utilization for last minute" },
117 { "System.CPU.Usage5(*)", H_CPUUsage, "C1", DCI_DT_FLOAT, "Average CPU {instance} utilization for last 5 minutes" },
118 { "System.CPU.Usage15(*)", H_CPUUsage, "C2", DCI_DT_FLOAT, "Average CPU {instance} utilization for last 15 minutes" },
119 { "System.Hostname", H_Hostname, NULL, DCI_DT_STRING, "Host name" },
120 { "System.KStat(*)", H_KStat, NULL, DCI_DT_STRING, "" },
121 { "System.Memory.Physical.Free", H_MemoryInfo, (char *)MEMINFO_PHYSICAL_FREE, DCI_DT_UINT64, "Available physical memory" },
122 { "System.Memory.Physical.Total", H_MemoryInfo, (char *)MEMINFO_PHYSICAL_TOTAL, DCI_DT_UINT64, "Total amount of physical memory" },
123 { "System.Memory.Physical.Used", H_MemoryInfo, (char *)MEMINFO_PHYSICAL_FREE, DCI_DT_UINT64, "Used physical memory" },
124 { "System.Memory.Swap.Free", H_MemoryInfo, (char *)MEMINFO_SWAP_FREE, DCI_DT_UINT64, "Free swap space" },
125 { "System.Memory.Swap.Total", H_MemoryInfo, (char *)MEMINFO_SWAP_TOTAL, DCI_DT_UINT64, "Total amount of swap space" },
126 { "System.Memory.Swap.Used", H_MemoryInfo, (char *)MEMINFO_SWAP_USED, DCI_DT_UINT64, "Used swap space" },
127 { "System.ProcessCount", H_SysProcCount, NULL, DCI_DT_INT, "Total number of processes" },
128 { "System.Uname", H_Uname, NULL, DCI_DT_STRING, "System uname" },
129 { "System.Uptime", H_Uptime, NULL, DCI_DT_UINT, "System uptime" }
130 };
131 static NETXMS_SUBAGENT_ENUM m_enums[] =
132 {
133 { "Net.InterfaceList", H_NetIfList, NULL },
134 { "System.ProcessList", H_ProcessList, NULL }
135 };
136
137 static NETXMS_SUBAGENT_INFO m_info =
138 {
139 NETXMS_SUBAGENT_INFO_MAGIC,
140 _T("SUNOS"), NETXMS_VERSION_STRING,
141 UnloadHandler, NULL,
142 sizeof(m_parameters) / sizeof(NETXMS_SUBAGENT_PARAM),
143 m_parameters,
144 sizeof(m_enums) / sizeof(NETXMS_SUBAGENT_ENUM),
145 m_enums
146 };
147
148
149 //
150 // Entry point for NetXMS agent
151 //
152
153 extern "C" BOOL NxSubAgentInit(NETXMS_SUBAGENT_INFO **ppInfo, TCHAR *pszConfigFile)
154 {
155 m_hCPUStatThread = ThreadCreateEx(CPUStatCollector, 0, NULL);
156
157 *ppInfo = &m_info;
158 return TRUE;
159 }