diff options
| author | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-01-06 13:35:58 +0000 |
|---|---|---|
| committer | alex <alex@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2007-01-06 13:35:58 +0000 |
| commit | 5c4b1872d5a5a878fdb6f6d8a0c5880741134ec6 (patch) | |
| tree | afe63b6d5feef0fa3406c55e23965f460dd88f59 /src/zabbix_server/httppoller | |
| parent | 940150b550ffff2d462f81515f6022ed0a712bd2 (diff) | |
| download | zabbix-5c4b1872d5a5a878fdb6f6d8a0c5880741134ec6.tar.gz zabbix-5c4b1872d5a5a878fdb6f6d8a0c5880741134ec6.tar.xz zabbix-5c4b1872d5a5a878fdb6f6d8a0c5880741134ec6.zip | |
More support of WEB monitoring.
git-svn-id: svn://svn.zabbix.com/trunk@3660 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_server/httppoller')
| -rw-r--r-- | src/zabbix_server/httppoller/Makefile.am | 2 | ||||
| -rw-r--r-- | src/zabbix_server/httppoller/httppoller.c | 48 | ||||
| -rw-r--r-- | src/zabbix_server/httppoller/httptest.c | 142 | ||||
| -rw-r--r-- | src/zabbix_server/httppoller/httptest.h | 36 |
4 files changed, 216 insertions, 12 deletions
diff --git a/src/zabbix_server/httppoller/Makefile.am b/src/zabbix_server/httppoller/Makefile.am index d12e1092..19d1a9bc 100644 --- a/src/zabbix_server/httppoller/Makefile.am +++ b/src/zabbix_server/httppoller/Makefile.am @@ -1,4 +1,4 @@ SUBDIRS= INCLUDES=-I@top_srcdir@/include @MYSQL_INCLUDE@ @ORACLE_INCLUDE@ @PGSQL_INCLUDE@ @SNMP_INCLUDE@ lib_LIBRARIES=libzbxhttppoller.a -libzbxhttppoller_a_SOURCES=httppoller.c +libzbxhttppoller_a_SOURCES=httptest.c httppoller.c diff --git a/src/zabbix_server/httppoller/httppoller.c b/src/zabbix_server/httppoller/httppoller.c index 385cc2da..d06f9112 100644 --- a/src/zabbix_server/httppoller/httppoller.c +++ b/src/zabbix_server/httppoller/httppoller.c @@ -45,12 +45,28 @@ #include "common.h" #include "../functions.h" #include "../expression.h" +#include "httptest.h" #include "httppoller.h" #include "daemon.h" int httppoller_num; +/****************************************************************************** + * * + * Function: get_minnextcheck * + * * + * Purpose: calculate when we have to process earliest httptest * + * * + * Parameters: now - current timestamp * + * * + * Return value: timestamp of earliest check or -1 if not found * + * * + * Author: Alexei Vladishev * + * * + * Comments: never returns * + * * + ******************************************************************************/ static int get_minnextcheck(int now) { DB_RESULT result; @@ -58,13 +74,13 @@ static int get_minnextcheck(int now) int res; - result = DBselect("select count(*),min(nextcheck) from httptest h where h.status=%d and " ZBX_SQL_MOD(h.httptestid,%d) "=%d and " ZBX_COND_NODEID, HTTPTEST_STATUS_MONITORED, CONFIG_HTTPPOLLER_FORKS, httppoller_num-1, LOCAL_NODE("h.hostid")); + result = DBselect("select count(*),min(nextcheck) from httptest t where t.status=%d and " ZBX_SQL_MOD(t.httptestid,%d) "=%d and " ZBX_COND_NODEID, HTTPTEST_STATUS_MONITORED, CONFIG_HTTPPOLLER_FORKS, httppoller_num-1, LOCAL_NODE("t.httptestid")); row=DBfetch(result); if(!row || DBis_null(row[0])==SUCCEED || DBis_null(row[1])==SUCCEED) { - zabbix_log(LOG_LEVEL_DEBUG, "No items to update for minnextcheck."); + zabbix_log(LOG_LEVEL_DEBUG, "No httptests to process in get_minnextcheck."); res = FAIL; } else @@ -83,17 +99,27 @@ static int get_minnextcheck(int now) return res; } -void process_httptests() -{ - sleep(1); -} - +/****************************************************************************** + * * + * Function: main_httppoller_loop * + * * + * Purpose: main loop of processing of httptests * + * * + * Parameters: * + * * + * Return value: * + * * + * Author: Alexei Vladishev * + * * + * Comments: never returns * + * * + ******************************************************************************/ void main_httppoller_loop(int num) { int now; int nextcheck,sleeptime; - zabbix_log( LOG_LEVEL_WARNING, "In main_httppoller_loop(num:%d)", num); + zabbix_log( LOG_LEVEL_DEBUG, "In main_httppoller_loop(num:%d)", num); httppoller_num = num; @@ -104,12 +130,12 @@ void main_httppoller_loop(int num) zbx_setproctitle("http poller [getting values]"); now=time(NULL); - process_httptests(); + process_httptests(now); - zabbix_log( LOG_LEVEL_WARNING, "Spent %d seconds while processing HTTP tests", (int)time(NULL)-now ); + zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds while processing HTTP tests", (int)time(NULL)-now ); nextcheck=get_minnextcheck(now); - zabbix_log( LOG_LEVEL_WARNING, "Nextcheck:%d Time:%d", nextcheck, (int)time(NULL) ); + zabbix_log( LOG_LEVEL_DEBUG, "Nextcheck:%d Time:%d", nextcheck, (int)time(NULL) ); if( FAIL == nextcheck) { diff --git a/src/zabbix_server/httppoller/httptest.c b/src/zabbix_server/httppoller/httptest.c new file mode 100644 index 00000000..93c4aa3b --- /dev/null +++ b/src/zabbix_server/httppoller/httptest.c @@ -0,0 +1,142 @@ +/* +** 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 "cfg.h" +#include "pid.h" +#include "db.h" +#include "log.h" +#include "zlog.h" + +#include "common.h" +#include "httptest.h" + +/****************************************************************************** + * * + * Function: process_httptest * + * * + * Purpose: process single scenario of http test * + * * + * Parameters: httptestid - ID of http test * + * * + * Return value: * + * * + * Author: Alexei Vladishev * + * * + * Comments: SUCCEED or FAIL * + * * + ******************************************************************************/ +int process_httptest(zbx_uint64_t httptestid) +{ + DB_RESULT result; + DB_ROW row; + int ret = SUCCEED; + int err; + + long rspcode; + + CURL *easyhandle = NULL; + + zabbix_log(LOG_LEVEL_WARNING, "In process_httptest(httptestid:" ZBX_FS_UI64 ")", httptestid); + + easyhandle = curl_easy_init(); + if(easyhandle == NULL) + { + zabbix_log(LOG_LEVEL_ERR, "Cannot init CURL"); + + return FAIL; + } + + result = DBselect("select httpstepid,no,name,url,timeout,posts from httpstep where httptestid=" ZBX_FS_UI64 " order by no", + httptestid); + + while((row=DBfetch(result))) + { + zabbix_log(LOG_LEVEL_WARNING, "Processing step %d [%s]", row[1], row[3]); + if(row[5][0] != 0) + { + if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, row[5]))) + { + zabbix_log(LOG_LEVEL_ERR, "Cannot set POST vars [%s]", curl_easy_strerror(err)); + ret = FAIL; + break; + } + } + if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_URL, row[3]))) + { + zabbix_log(LOG_LEVEL_ERR, "Cannot set URL [%s]", curl_easy_strerror(err)); + ret = FAIL; + break; + } + if(CURLE_OK != (err = curl_easy_perform(easyhandle))) + { + zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", curl_easy_strerror(err)); + ret = FAIL; + break; + } + if(CURLE_OK != (err = curl_easy_getinfo(easyhandle,CURLINFO_RESPONSE_CODE ,&rspcode))) + { + zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]", curl_easy_strerror(err)); + ret = FAIL; + break; + } + zabbix_log(LOG_LEVEL_WARNING, "RSPCODE [%d]", rspcode); + } + DBfree_result(result); + + (void)curl_easy_cleanup(easyhandle); + + return ret; +} + +/****************************************************************************** + * * + * Function: process_httptests * + * * + * Purpose: process httptests * + * * + * Parameters: now - current timestamp * + * * + * Return value: * + * * + * Author: Alexei Vladishev * + * * + * Comments: always SUCCEED * + * * + ******************************************************************************/ +void process_httptests(int now) +{ + DB_RESULT result; + DB_ROW row; + + zbx_uint64_t httptestid; + + zabbix_log(LOG_LEVEL_DEBUG, "In process_httptests"); + + result = DBselect("select t.httptestid from httptest t where t.status=%d and t.nextcheck<=%d and " ZBX_SQL_MOD(t.httptestid,%d) "=%d and " ZBX_COND_NODEID, HTTPTEST_STATUS_MONITORED, now, CONFIG_HTTPPOLLER_FORKS, httppoller_num-1, LOCAL_NODE("t.httptestid")); + while((row=DBfetch(result))) + { + ZBX_STR2UINT64(httptestid, row[0]); + process_httptest(httptestid); + + DBexecute("update httptest set nextcheck=%d+delay where httptestid=" ZBX_FS_UI64, now, httptestid); + } + DBfree_result(result); +} diff --git a/src/zabbix_server/httppoller/httptest.h b/src/zabbix_server/httppoller/httptest.h new file mode 100644 index 00000000..29482d49 --- /dev/null +++ b/src/zabbix_server/httppoller/httptest.h @@ -0,0 +1,36 @@ +/* +** 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. +**/ + +#ifndef ZABBIX_HTTPTEST_H +#define ZABBIX_HTTPTEST_H + +typedef struct s_zbx_step +{ + char *url; + char *post; +} zbx_step; + +void process_httptests(int now); + +extern int httppoller_num; + +extern int CONFIG_NODEID; +extern int CONFIG_HTTPPOLLER_FORKS; + +#endif |
