summaryrefslogtreecommitdiffstats
path: root/src/libs/zbxsysinfo
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/zbxsysinfo')
-rw-r--r--src/libs/zbxsysinfo/common/common.c8
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/memory.c82
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/pdhmon.c91
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/proc.c35
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/services.c92
-rwxr-xr-xsrc/libs/zbxsysinfo/win32/swap.c71
6 files changed, 282 insertions, 97 deletions
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c
index c106b315..29f4c7ce 100644
--- a/src/libs/zbxsysinfo/common/common.c
+++ b/src/libs/zbxsysinfo/common/common.c
@@ -2086,18 +2086,10 @@ int CHECK_DNS(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *
# define C_IN ns_c_in
#endif /* C_IN */
-#if !defined(ns_c_in)
-# define ns_c_in 1
-#endif /* ns_c_in */
-
#if !defined(T_SOA)
# define T_SOA ns_t_soa
#endif /* T_SOA */
-#if !defined(ns_t_soa)
-# define ns_t_soa 6
-#endif /* ns_t_soa */
-
int res;
char ip[MAX_STRING_LEN];
diff --git a/src/libs/zbxsysinfo/win32/memory.c b/src/libs/zbxsysinfo/win32/memory.c
index f8ab5a3a..40872581 100755
--- a/src/libs/zbxsysinfo/win32/memory.c
+++ b/src/libs/zbxsysinfo/win32/memory.c
@@ -22,18 +22,14 @@
#include "common.h"
#include "sysinfo.h"
+#include "symbols.h"
+
int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-
-#if defined(HAVE_GETPERFORMANCEINFO)
PERFORMANCE_INFORMATION pfi;
-#endif /* HAVE_GETPERFORMANCEINFO */
+ MEMORYSTATUSEX ms_ex;
+ MEMORYSTATUS ms;
-#if defined(HAVE_GLOBALMEMORYSTATUSEX)
- MEMORYSTATUSEX ms;
-#else /* HAVE_GLOBALMEMORYSTATUSEX */
- MEMORYSTATUS ms;
-#endif
char mode[10];
if(num_param(param) > 1)
@@ -51,57 +47,55 @@ int VM_MEMORY_SIZE(const char *cmd, const char *param, unsigned flags, AGENT
zbx_snprintf(mode, sizeof(mode), "total");
}
-#if defined(HAVE_GETPERFORMANCEINFO)
-
if (strcmp(mode,"cached") == 0)
{
+ if(NULL == zbx_GetPerformanceInfo)
+ return SYSINFO_RET_FAIL;
- GetPerformanceInfo(&pfi,sizeof(PERFORMANCE_INFORMATION));
+ zbx_GetPerformanceInfo(&pfi,sizeof(PERFORMANCE_INFORMATION));
SET_UI64_RESULT(result, (zbx_uint64_t)pfi.SystemCache * (zbx_uint64_t)pfi.PageSize);
return SYSINFO_RET_OK;
}
-#endif /* HAVE_GETPERFORMANCEINFO */
-
-#if defined(HAVE_GLOBALMEMORYSTATUSEX)
-
- ms.dwLength = sizeof(MEMORYSTATUSEX);
-
- GlobalMemoryStatusEx(&ms);
-
- if (strcmp(mode, "total") == 0)
+ if(NULL != zbx_GlobalMemoryStatusEx)
{
- SET_UI64_RESULT(result, ms.ullTotalPhys);
- return SYSINFO_RET_OK;
- }
- else if (strcmp(mode, "free") == 0)
- {
- SET_UI64_RESULT(result, ms.ullAvailPhys);
- return SYSINFO_RET_OK;
+ ms_ex.dwLength = sizeof(MEMORYSTATUSEX);
+
+ zbx_GlobalMemoryStatusEx(&ms_ex);
+
+ if (strcmp(mode, "total") == 0)
+ {
+ SET_UI64_RESULT(result, ms_ex.ullTotalPhys);
+ return SYSINFO_RET_OK;
+ }
+ else if (strcmp(mode, "free") == 0)
+ {
+ SET_UI64_RESULT(result, ms_ex.ullAvailPhys);
+ return SYSINFO_RET_OK;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
}
else
{
- return SYSINFO_RET_FAIL;
- }
-
-#else /* not HAVE_GLOBALMEMORYSTATUSEX */
- GlobalMemoryStatus(&ms);
-
- if (strcmp(mode,"total") == 0)
- {
- SET_UI64_RESULT(result, ms.dwTotalPhys);
- return SYSINFO_RET_OK;
+ GlobalMemoryStatus(&ms);
+
+ if (strcmp(mode,"total") == 0)
+ {
+ SET_UI64_RESULT(result, ms.dwTotalPhys);
+ return SYSINFO_RET_OK;
+ }
+ else if (strcmp(mode,"free") == 0)
+ {
+ SET_UI64_RESULT(result, ms.dwAvailPhys);
+ return SYSINFO_RET_OK;
+ }
}
- else if (strcmp(mode,"free") == 0)
- {
- SET_UI64_RESULT(result, ms.dwAvailPhys);
- return SYSINFO_RET_OK;
- }
-
-#endif /* HAVE_GLOBALMEMORYSTATUSEX */
return SYSINFO_RET_FAIL;
diff --git a/src/libs/zbxsysinfo/win32/pdhmon.c b/src/libs/zbxsysinfo/win32/pdhmon.c
new file mode 100755
index 00000000..b6f9038e
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/pdhmon.c
@@ -0,0 +1,91 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+#include "log.h"
+
+
+int PERF_MONITOR(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ HQUERY query;
+ HCOUNTER counter;
+ PDH_STATUS status;
+
+ PDH_RAW_COUNTER rawData;
+ PDH_FMT_COUNTERVALUE counterValue;
+
+ char counter_name[MAX_STRING_LEN];
+
+ int ret = SYSINFO_RET_FAIL;
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, counter_name, sizeof(counter_name)) != 0)
+ {
+ counter_name[0] = '\0';
+ }
+ if(counter_name[0] == '\0')
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if (ERROR_SUCCESS == PdhOpenQuery(NULL,0,&query))
+ {
+ if (ERROR_SUCCESS == (status = PdhAddCounter(query,counter_name,0,&counter)))
+ {
+ if (ERROR_SUCCESS == PdhCollectQueryData(query))
+ {
+ if(ERROR_SUCCESS == PdhGetRawCounterValue(counter, NULL, &rawData))
+ {
+ if( ERROR_SUCCESS == PdhCalculateCounterFromRawValue(
+ counter,
+ PDH_FMT_DOUBLE,
+ &rawData,
+ NULL,
+ &counterValue
+ ) )
+ {
+ SET_DBL_RESULT(result, counterValue.doubleValue);
+ ret = SYSINFO_RET_OK;
+ }
+ else
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "Can't format counter value [%s] [%s]", counter_name, "Rate counter is used.");
+ }
+ }
+ else
+ {
+ zabbix_log(LOG_LEVEL_DEBUG, "Can't get counter value [%s] [%s]", counter_name, strerror_from_system(GetLastError()));
+ }
+ }
+ PdhRemoveCounter(&counter);
+ }
+
+ PdhCloseQuery(query);
+ }
+
+ return ret;
+}
diff --git a/src/libs/zbxsysinfo/win32/proc.c b/src/libs/zbxsysinfo/win32/proc.c
index e529e10c..b071d98e 100755
--- a/src/libs/zbxsysinfo/win32/proc.c
+++ b/src/libs/zbxsysinfo/win32/proc.c
@@ -22,6 +22,8 @@
#include "common.h"
#include "sysinfo.h"
+#include "symbols.h"
+
#define MAX_PROCESSES 4096
#define MAX_MODULES 512
@@ -207,42 +209,59 @@ static double GetProcessAttribute(HANDLE hProcess,int attr,int type,int count,do
case 3: /* ktime */
case 4: /* utime */
GetProcessTimes(hProcess,&ftCreate,&ftExit,&ftKernel,&ftUser);
- value=ConvertProcessTime(attr==3 ? &ftKernel : &ftUser);
+ value = ConvertProcessTime(attr==3 ? &ftKernel : &ftUser);
break;
- case 5: /* gdiobj */
-#if defined(HAVE_GETGUIRESOURCES)
+ case 5: /* gdiobj */
case 6: /* userobj */
- value=(double)GetGuiResources(hProcess,attr==5 ? 0 : 1);
+ if(NULL == zbx_GetGuiResources)
+ return SYSINFO_RET_FAIL;
+
+ value = (double)zbx_GetGuiResources(hProcess,attr==5 ? 0 : 1);
break;
-#endif /* HAVE_GETGUIRESOURCES */
-#if defined(HAVE_GETPROCESSIOCOUNTERS)
case 7: /* io_read_b */
- GetProcessIoCounters(hProcess,&ioCounters);
+ if(NULL == zbx_GetProcessIoCounters)
+ return SYSINFO_RET_FAIL;
+
+ zbx_GetProcessIoCounters(hProcess,&ioCounters);
value=(double)((__int64)ioCounters.ReadTransferCount);
break;
case 8: /* io_read_op */
+ if(NULL == zbx_GetProcessIoCounters)
+ return SYSINFO_RET_FAIL;
+
GetProcessIoCounters(hProcess,&ioCounters);
value=(double)((__int64)ioCounters.ReadOperationCount);
break;
case 9: /* io_write_b */
+ if(NULL == zbx_GetProcessIoCounters)
+ return SYSINFO_RET_FAIL;
+
GetProcessIoCounters(hProcess,&ioCounters);
value=(double)((__int64)ioCounters.WriteTransferCount);
break;
case 10: /* io_write_op */
+ if(NULL == zbx_GetProcessIoCounters)
+ return SYSINFO_RET_FAIL;
+
GetProcessIoCounters(hProcess,&ioCounters);
value=(double)((__int64)ioCounters.WriteOperationCount);
break;
case 11: /* io_other_b */
+ if(NULL == zbx_GetProcessIoCounters)
+ return SYSINFO_RET_FAIL;
+
GetProcessIoCounters(hProcess,&ioCounters);
value=(double)((__int64)ioCounters.OtherTransferCount);
break;
case 12: /* io_other_op */
+ if(NULL == zbx_GetProcessIoCounters)
+ return SYSINFO_RET_FAIL;
+
GetProcessIoCounters(hProcess,&ioCounters);
value=(double)((__int64)ioCounters.OtherOperationCount);
break;
-#endif /* HAVE_GETPROCESSIOCOUNTERS */
default: /* Unknown attribute */
return SYSINFO_RET_FAIL;
diff --git a/src/libs/zbxsysinfo/win32/services.c b/src/libs/zbxsysinfo/win32/services.c
new file mode 100755
index 00000000..39288b63
--- /dev/null
+++ b/src/libs/zbxsysinfo/win32/services.c
@@ -0,0 +1,92 @@
+/*
+** ZABBIX
+** Copyright (C) 2000-2005 SIA Zabbix
+**
+** This program is free software; you can redistribute it and/or modify
+** it under the terms of the GNU General Public License as published by
+** the Free Software Foundation; either version 2 of the License, or
+** (at your option) any later version.
+**
+** This program is distributed in the hope that it will be useful,
+** but WITHOUT ANY WARRANTY; without even the implied warranty of
+** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+** GNU General Public License for more details.
+**
+** You should have received a copy of the GNU General Public License
+** along with this program; if not, write to the Free Software
+** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+**/
+
+#include "config.h"
+
+#include "common.h"
+#include "sysinfo.h"
+
+int SERVICE_STATE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
+{
+ SC_HANDLE
+ mgr,
+ service;
+
+ char service_name[MAX_STRING_LEN];
+
+ int ret = SYSINFO_RET_FAIL;
+ int i;
+
+ if(num_param(param) > 1)
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(get_param(param, 1, service_name, sizeof(service_name)) != 0)
+ {
+ service_name[0] = '\0';
+ }
+ if(service_name[0] == '\0')
+ {
+ return SYSINFO_RET_FAIL;
+ }
+
+ if(NULL == (mgr = OpenSCManager(NULL,NULL,GENERIC_READ)) )
+ {
+ SET_UI64_RESULT(result, 255);
+ return SYSINFO_RET_OK;
+ }
+
+ if(NULL != (service = OpenService(mgr,service_name,SERVICE_QUERY_STATUS)) )
+ {
+ SERVICE_STATUS status;
+
+ if (QueryServiceStatus(service, &status))
+ {
+ static DWORD states[7] =
+ {
+ SERVICE_RUNNING,
+ SERVICE_PAUSED,
+ SERVICE_START_PENDING,
+ SERVICE_PAUSE_PENDING,
+ SERVICE_CONTINUE_PENDING,
+ SERVICE_STOP_PENDING,
+ SERVICE_STOPPED
+ };
+
+ for(i=0; i < 7 && status.dwCurrentState != states[i]; i++);
+
+ SET_UI64_RESULT(result, i);
+ }
+ else
+ {
+ SET_UI64_RESULT(result, 255);
+ }
+
+ CloseServiceHandle(service);
+ }
+ else
+ {
+ SET_UI64_RESULT(result, 255);
+ }
+
+ CloseServiceHandle(mgr);
+
+ return SYSINFO_RET_OK;
+}
diff --git a/src/libs/zbxsysinfo/win32/swap.c b/src/libs/zbxsysinfo/win32/swap.c
index b4f07409..5a72668d 100755
--- a/src/libs/zbxsysinfo/win32/swap.c
+++ b/src/libs/zbxsysinfo/win32/swap.c
@@ -21,17 +21,15 @@
#include "common.h"
#include "sysinfo.h"
+#include "symbols.h"
#include "md5.h"
int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
-#if defined(HAVE_GLOBALMEMORYSTATUSEX)
- MEMORYSTATUSEX ms;
-#else /* HAVE_GLOBALMEMORYSTATUSEX */
- MEMORYSTATUS ms;
-#endif
+ MEMORYSTATUSEX ms_ex;
+ MEMORYSTATUS ms;
char swapdev[10];
char mode[10];
@@ -65,43 +63,42 @@ int SYSTEM_SWAP_SIZE(const char *cmd, const char *param, unsigned flags, AGENT_R
zbx_snprintf(mode, sizeof(mode), "total");
}
-#if defined(HAVE_GLOBALMEMORYSTATUSEX)
-
- ms.dwLength = sizeof(MEMORYSTATUSEX);
-
- GlobalMemoryStatusEx(&ms);
-
- if (strcmp(mode, "total") == 0)
+ if(NULL != zbx_GlobalMemoryStatusEx)
{
- SET_UI64_RESULT(result, ms.ullTotalPageFile);
- return SYSINFO_RET_OK;
- }
- else if (strcmp(mode, "free") == 0)
- {
- SET_UI64_RESULT(result, ms.ullAvailPageFile);
- return SYSINFO_RET_OK;
+ ms_ex.dwLength = sizeof(MEMORYSTATUSEX);
+
+ zbx_GlobalMemoryStatusEx(&ms_ex);
+
+ if (strcmp(mode, "total") == 0)
+ {
+ SET_UI64_RESULT(result, ms_ex.ullTotalPageFile);
+ return SYSINFO_RET_OK;
+ }
+ else if (strcmp(mode, "free") == 0)
+ {
+ SET_UI64_RESULT(result, ms_ex.ullAvailPageFile);
+ return SYSINFO_RET_OK;
+ }
+ else
+ {
+ return SYSINFO_RET_FAIL;
+ }
}
else
{
- return SYSINFO_RET_FAIL;
- }
-
-#else /* not HAVE_GLOBALMEMORYSTATUSEX */
-
- GlobalMemoryStatus(&ms);
-
- if (strcmp(mode,"total") == 0)
- {
- SET_UI64_RESULT(result, ms.dwTotalPageFile);
- return SYSINFO_RET_OK;
+ GlobalMemoryStatus(&ms);
+
+ if (strcmp(mode,"total") == 0)
+ {
+ SET_UI64_RESULT(result, ms.dwTotalPageFile);
+ return SYSINFO_RET_OK;
+ }
+ else if (strcmp(mode,"free") == 0)
+ {
+ SET_UI64_RESULT(result, ms.dwAvailPageFile);
+ return SYSINFO_RET_OK;
+ }
}
- else if (strcmp(mode,"free") == 0)
- {
- SET_UI64_RESULT(result, ms.dwAvailPageFile);
- return SYSINFO_RET_OK;
- }
-
-#endif /* HAVE_GLOBALMEMORYSTATUSEX */
return SYSINFO_RET_OK;
}