diff options
| author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-05-30 08:03:18 +0000 |
|---|---|---|
| committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2006-05-30 08:03:18 +0000 |
| commit | fcce006f76f5e93e675b9673bf3aec465e323d12 (patch) | |
| tree | 5e279124810d6fd1166feeba7076f9cd0d780dcf /src/libs | |
| parent | 46cb0895806a666c03ed44a6f682eedd5d55d222 (diff) | |
- support of web.getpage[] (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@2919 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/libs')
| -rw-r--r-- | src/libs/zbxsysinfo/common/common.c | 1 | ||||
| -rw-r--r-- | src/libs/zbxsysinfo/common/http.c | 63 |
2 files changed, 58 insertions, 6 deletions
diff --git a/src/libs/zbxsysinfo/common/common.c b/src/libs/zbxsysinfo/common/common.c index 783dea2c..d9911cd7 100644 --- a/src/libs/zbxsysinfo/common/common.c +++ b/src/libs/zbxsysinfo/common/common.c @@ -40,6 +40,7 @@ ZBX_METRIC parameters_common[]= {"vfs.file.regexp", CF_USEUPARAM, VFS_FILE_REGEXP, 0, "/etc/passwd,root"}, {"vfs.file.regmatch", CF_USEUPARAM, VFS_FILE_REGMATCH, 0, "/etc/passwd,root"}, {"system.run", CF_USEUPARAM, RUN_COMMAND, 0, "echo test"}, + {"web.getpage", CF_USEUPARAM, WEB_GETPAGE, 0, "www.zabbix.com,,80"}, {0} }; diff --git a/src/libs/zbxsysinfo/common/http.c b/src/libs/zbxsysinfo/common/http.c index 017d78c5..5273176c 100644 --- a/src/libs/zbxsysinfo/common/http.c +++ b/src/libs/zbxsysinfo/common/http.c @@ -26,7 +26,7 @@ int get_http_page(char *hostname, char *param, int port, char *buffer, int max_buf_len) { char *haddr; - char c[1024]; + char c[MAX_STRING_LEN]; int s; struct sockaddr_in addr; @@ -53,23 +53,23 @@ int get_http_page(char *hostname, char *param, int port, char *buffer, int max_b if (s == -1) { close(s); - return SYSINFO_RET_OK; + return SYSINFO_RET_FAIL; } if (connect(s, (struct sockaddr *) &addr, addrlen) == -1) { close(s); - return SYSINFO_RET_OK; + return SYSINFO_RET_FAIL; } - snprintf(c,1024-1,"GET /%s HTTP/1.1\nHost: %s\nConnection: close\n\n", param, hostname); + snprintf(c,MAX_STRING_LEN-1,"GET /%s HTTP/1.1\nHost: %s\nConnection: close\n\n", param, hostname); write(s,c,strlen(c)); memset(buffer, 0, max_buf_len); total=0; - while((n=read(s, buffer+total, max_buf_len-1))>0) + while((n=read(s, buffer+total, max_buf_len-1-total))>0) { total+=n; printf("Read %d bytes\n", total); @@ -78,7 +78,58 @@ int get_http_page(char *hostname, char *param, int port, char *buffer, int max_b close(s); return SYSINFO_RET_OK; } -#define ZABBIX_TEST + +int WEB_GETPAGE(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result) +{ +#define ZABBIX_MAX_WEBPAGE_SIZE 100*1024 + char hostname[MAX_STRING_LEN]; + char path[MAX_STRING_LEN]; + char port_str[MAX_STRING_LEN]; + + char *buffer; + + int ret; + + assert(result); + + init_result(result); + + if(num_param(param) > 3) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 1, hostname, MAX_STRING_LEN) != 0) + { + return SYSINFO_RET_FAIL; + } + + if(get_param(param, 2, path, MAX_STRING_LEN) != 0) + { + path[0]='\0'; + } + + if(get_param(param, 3, port_str, MAX_STRING_LEN) != 0) + { + strscpy(port_str, "80"); + } + + buffer=malloc(100*1024); + if(get_http_page(hostname, path, atoi(port_str), buffer, ZABBIX_MAX_WEBPAGE_SIZE) == SYSINFO_RET_OK) + { + SET_TEXT_RESULT(result, buffer); + ret = SYSINFO_RET_OK; + } + else + { + ret = SYSINFO_RET_FAIL; + } + free(buffer); + + return ret; +} + +/*#define ZABBIX_TEST*/ #ifdef ZABBIX_TEST int main() |
