summaryrefslogtreecommitdiffstats
path: root/src/zabbix_proxy
diff options
context:
space:
mode:
authorsasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-15 18:42:39 +0000
committersasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2008-02-15 18:42:39 +0000
commit0a495e2d44b51021b95bef2b273c4c2fd59af389 (patch)
treed1a3b29353ff33c223d98d96d6aa84ebc38c9dea /src/zabbix_proxy
parenta108856b0ce83183ef5a13429f377ea0caf5e6fe (diff)
downloadzabbix-0a495e2d44b51021b95bef2b273c4c2fd59af389.tar.gz
zabbix-0a495e2d44b51021b95bef2b273c4c2fd59af389.tar.xz
zabbix-0a495e2d44b51021b95bef2b273c4c2fd59af389.zip
- [DEV-110] Proxy changes
git-svn-id: svn://svn.zabbix.com/trunk@5357 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_proxy')
-rw-r--r--src/zabbix_proxy/Makefile.am4
-rw-r--r--src/zabbix_proxy/httppoller/Makefile.am8
-rw-r--r--src/zabbix_proxy/httppoller/httpmacro.c133
-rw-r--r--src/zabbix_proxy/httppoller/httpmacro.h25
-rw-r--r--src/zabbix_proxy/httppoller/httppoller.c165
-rw-r--r--src/zabbix_proxy/httppoller/httppoller.h30
-rw-r--r--src/zabbix_proxy/httppoller/httptest.c544
-rw-r--r--src/zabbix_proxy/httppoller/httptest.h51
-rw-r--r--src/zabbix_proxy/proxy.c26
9 files changed, 12 insertions, 974 deletions
diff --git a/src/zabbix_proxy/Makefile.am b/src/zabbix_proxy/Makefile.am
index d624e038..bcbca23a 100644
--- a/src/zabbix_proxy/Makefile.am
+++ b/src/zabbix_proxy/Makefile.am
@@ -4,7 +4,7 @@ SUBDIRS = \
../zabbix_server/dbsyncer \
../zabbix_server/discoverer \
housekeeper \
- httppoller \
+ ../zabbix_server/httppoller \
proxyconfig \
../zabbix_server/pinger \
poller \
@@ -25,7 +25,7 @@ zabbix_proxy_LDADD = \
$(top_srcdir)/src/zabbix_server/dbsyncer/libzbxdbsyncer.a \
$(top_srcdir)/src/zabbix_server/discoverer/libzbxdiscoverer.a \
housekeeper/libzbxhousekeeper.a \
- httppoller/libzbxhttppoller.a \
+ $(top_srcdir)/src/zabbix_server/httppoller/libzbxhttppoller.a \
proxyconfig/libzbxproxyconfig.a \
$(top_srcdir)/src/zabbix_server/pinger/libzbxpinger.a \
poller/libzbxpoller.a \
diff --git a/src/zabbix_proxy/httppoller/Makefile.am b/src/zabbix_proxy/httppoller/Makefile.am
deleted file mode 100644
index 07706687..00000000
--- a/src/zabbix_proxy/httppoller/Makefile.am
+++ /dev/null
@@ -1,8 +0,0 @@
-## Process this file with automake to produce Makefile.in
-
-noinst_LIBRARIES = libzbxhttppoller.a
-
-libzbxhttppoller_a_SOURCES = \
- httpmacro.c httpmacro.h \
- httptest.c httptest.h \
- httppoller.c httppoller.h
diff --git a/src/zabbix_proxy/httppoller/httpmacro.c b/src/zabbix_proxy/httppoller/httpmacro.c
deleted file mode 100644
index 4e14fe9b..00000000
--- a/src/zabbix_proxy/httppoller/httpmacro.c
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
-** 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 "common.h"
-
-#include "cfg.h"
-#include "pid.h"
-#include "db.h"
-#include "log.h"
-#include "zlog.h"
-
-#include "httpmacro.h"
-
-/******************************************************************************
- * *
- * Function: http_substitute_macros *
- * *
- * Purpose: substitute macros in input string by value from http test config *
- * *
- * Parameters: httptest - http test data, data - string to substitute macros *
- * *
- * Return value: - *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: *
- * *
- ******************************************************************************/
-void http_substitute_macros(DB_HTTPTEST *httptest, char *data, int data_max_len)
-{
- char
- *pl = NULL,
- *pr = NULL,
- str_out[MAX_STRING_LEN],
- replace_to[MAX_STRING_LEN],
- *c,*c2, save,*replacement,save2;
- int
- outlen,
- var_len;
-
- zabbix_log(LOG_LEVEL_DEBUG, "In http_substitute_macros(httptestid:" ZBX_FS_UI64 ", data:%s)",
- httptest->httptestid,
- data);
-
- assert(data);
-
- *str_out = '\0';
- outlen = sizeof(str_out) - 1;
- pl = data;
- while((pr = strchr(pl, '{')) && outlen > 0)
- {
- pr[0] = '\0';
- zbx_strlcat(str_out, pl, outlen);
- outlen -= MIN(strlen(pl), outlen);
- pr[0] = '{';
-
- zbx_snprintf(replace_to, sizeof(replace_to), "{");
- var_len = 1;
-
-
- if(NULL!=(c=strchr(pr,'}')))
- {
- /* Macro in pr */
- save = c[1]; c[1]=0;
-
- if(NULL != (c2 = strstr(httptest->macros,pr)))
- {
- if(NULL != (replacement = strchr(c2,'=')))
- {
- replacement++;
- if(NULL != (c2 = strchr(replacement,'\r')))
- {
- save2 = c2[0]; c2[0]=0;
- var_len = strlen(pr);
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", replacement);
- c2[0] = save2;
- }
- else
- {
- var_len = strlen(pr);
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", replacement);
- }
- }
-
- }
-/* result = DBselect("select value from httpmacro where macro='%s' and httptestid=" ZBX_FS_UI64,
- pr, httptest->httptestid);
- row = DBfetch(result);
- if(row)
- {
- var_len = strlen(pr);
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", row[0]);
- }
- DBfree_result(result);*/
- /* Restore pr */
- c[1]=save;
- }
-
-/* if(strncmp(pr, "TRIGGER.NAME", strlen("TRIGGER.NAME")) == 0)
- {
- var_len = strlen("TRIGGER.NAME");
-
- zbx_snprintf(replace_to, sizeof(replace_to), "%s", event->trigger_description);
- substitute_simple_macros(event, action, replace_to, sizeof(replace_to), MACRO_TYPE_TRIGGER_DESCRIPTION);
- }*/
- zbx_strlcat(str_out, replace_to, outlen);
- outlen -= MIN(strlen(replace_to), outlen);
- pl = pr + var_len;
- }
- zbx_strlcat(str_out, pl, outlen);
- outlen -= MIN(strlen(pl), outlen);
-
- zbx_snprintf(data, data_max_len, "%s", str_out);
-
- zabbix_log( LOG_LEVEL_DEBUG, "Result expression [%s]",
- data);
-}
diff --git a/src/zabbix_proxy/httppoller/httpmacro.h b/src/zabbix_proxy/httppoller/httpmacro.h
deleted file mode 100644
index 3a3a2abf..00000000
--- a/src/zabbix_proxy/httppoller/httpmacro.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
-** 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_HTTPMACRO_H
-#define ZABBIX_HTTPMACRO_H
-
-void http_substitute_macros(DB_HTTPTEST *httptest, char *data, int data_max_len);
-
-#endif
diff --git a/src/zabbix_proxy/httppoller/httppoller.c b/src/zabbix_proxy/httppoller/httppoller.c
deleted file mode 100644
index ef07fa05..00000000
--- a/src/zabbix_proxy/httppoller/httppoller.c
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
-** 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 "common.h"
-
-#include "cfg.h"
-#include "pid.h"
-#include "db.h"
-#include "log.h"
-#include "zlog.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;
- DB_ROW row;
-
- int res;
-
- 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 httptests to process in get_minnextcheck.");
- res = FAIL;
- }
- else
- {
- if( atoi(row[0]) == 0)
- {
- res = FAIL;
- }
- else
- {
- res = atoi(row[1]);
- }
- }
- DBfree_result(result);
-
- return res;
-}
-
-/******************************************************************************
- * *
- * 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_DEBUG, "In main_httppoller_loop(num:%d)",
- num);
-
- httppoller_num = num;
-
- DBconnect(ZBX_DB_CONNECT_NORMAL);
-
- for(;;)
- {
- zbx_setproctitle("http poller [getting values]");
-
- now=time(NULL);
- process_httptests(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_DEBUG, "Nextcheck:%d Time:%d",
- nextcheck,
- (int)time(NULL));
-
- if( FAIL == nextcheck)
- {
- sleeptime=POLLER_DELAY;
- }
- else
- {
- sleeptime=nextcheck-time(NULL);
- if(sleeptime<0)
- {
- sleeptime=0;
- }
- }
- if(sleeptime>0)
- {
- if(sleeptime > POLLER_DELAY)
- {
- sleeptime = POLLER_DELAY;
- }
- zabbix_log( LOG_LEVEL_DEBUG, "Sleeping for %d seconds",
- sleeptime );
-
- zbx_setproctitle("http poller [sleeping for %d seconds]",
- sleeptime);
-
- sleep( sleeptime );
- }
- else
- {
- zabbix_log( LOG_LEVEL_DEBUG, "No sleeping" );
- }
-
-#ifdef ZABBIX_TEST
- break;
-#endif /* ZABBIX_TEST */
- }
-}
diff --git a/src/zabbix_proxy/httppoller/httppoller.h b/src/zabbix_proxy/httppoller/httppoller.h
deleted file mode 100644
index eb0d63e0..00000000
--- a/src/zabbix_proxy/httppoller/httppoller.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
-** 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_HTTPPOLLER_H
-#define ZABBIX_HTTPPOLLER_H
-
-extern void signal_handler(int);
-extern int server_num;
-
-extern int CONFIG_HTTPPOLLER_FORKS;
-
-void main_httppoller_loop(int num);
-
-#endif
diff --git a/src/zabbix_proxy/httppoller/httptest.c b/src/zabbix_proxy/httppoller/httptest.c
deleted file mode 100644
index cc7fefc4..00000000
--- a/src/zabbix_proxy/httppoller/httptest.c
+++ /dev/null
@@ -1,544 +0,0 @@
-/*
-** 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 "common.h"
-
-#include "cfg.h"
-#include "pid.h"
-#include "db.h"
-#include "log.h"
-#include "zlog.h"
-
-#include "../functions.h"
-#include "httpmacro.h"
-#include "httptest.h"
-
-#ifdef HAVE_LIBCURL
-
-static S_ZBX_HTTPPAGE page;
-
-/******************************************************************************
- * *
- * Function: process_value *
- * *
- * Purpose: process new item value *
- * *
- * Parameters: key - item key *
- * host - host name *
- * value - new value of the item *
- * *
- * Return value: SUCCEED - new value sucesfully processed *
- * FAIL - otherwise *
- * *
- * Author: Alexei Vladishev *
- * *
- * Comments: can be done in process_data() *
- * *
- ******************************************************************************/
-static int process_value(zbx_uint64_t itemid, AGENT_RESULT *value)
-{
- DB_RESULT result;
- DB_ROW row;
- DB_ITEM item;
-
- INIT_CHECK_MEMORY();
-
- zabbix_log( LOG_LEVEL_DEBUG, "In process_value(itemid:" ZBX_FS_UI64 ")",
- itemid);
-
- result = DBselect("select %s where h.status=%d and h.hostid=i.hostid and i.status=%d and i.type=%d and i.itemid=" ZBX_FS_UI64 " and " ZBX_COND_NODEID,
- ZBX_SQL_ITEM_SELECT,
- HOST_STATUS_MONITORED,
- ITEM_STATUS_ACTIVE,
- ITEM_TYPE_HTTPTEST,
- itemid,
- LOCAL_NODE("h.hostid"));
- row=DBfetch(result);
-
- if(!row)
- {
- DBfree_result(result);
- zabbix_log( LOG_LEVEL_DEBUG, "End process_value(result:FAIL)");
- return FAIL;
- }
-
- DBget_item_from_db(&item,row);
-
- DBbegin();
- process_new_value(&item,value);
- update_triggers(item.itemid);
- DBcommit();
-
- DBfree_result(result);
-
- zabbix_log( LOG_LEVEL_DEBUG, "End process_value()");
-
- CHECK_MEMORY("process_value", "end");
-
- return SUCCEED;
-}
-
-static size_t WRITEFUNCTION2( void *ptr, size_t size, size_t nmemb, void *stream)
-{
- size_t r_size = size*nmemb;
-
- /* First piece of data */
- if(page.data == NULL)
- {
- page.allocated=MAX(8096, r_size);
- page.offset=0;
- page.data=malloc(page.allocated);
- }
-
- zbx_snprintf_alloc(&page.data, &page.allocated, &page.offset, MAX(8096, r_size), "%s", ptr);
-
- return r_size;
-}
-
-static size_t HEADERFUNCTION2( void *ptr, size_t size, size_t nmemb, void *stream)
-{
-/*
- ZBX_LIM_PRINT("HEADERFUNCTION", size*nmemb, ptr, 300);
- zabbix_log(LOG_LEVEL_WARNING, "In HEADERFUNCTION");
-*/
-
- return size*nmemb;
-}
-
-static void process_test_data(DB_HTTPTEST *httptest, S_ZBX_HTTPSTAT *stat)
-{
- DB_RESULT result;
- DB_ROW row;
- DB_HTTPTESTITEM httptestitem;
-
- AGENT_RESULT value;
-
- INIT_CHECK_MEMORY();
-
- zabbix_log(LOG_LEVEL_DEBUG, "In process_test_data(test:%s,time:" ZBX_FS_DBL ",last step:%d)",
- httptest->name,
- stat->test_total_time,
- stat->test_last_step);
-
- result = DBselect("select httptestitemid,httptestid,itemid,type from httptestitem where httptestid=" ZBX_FS_UI64,
- httptest->httptestid);
-
- while((row=DBfetch(result)))
- {
- ZBX_STR2UINT64(httptestitem.httptestitemid, row[0]);
- ZBX_STR2UINT64(httptestitem.httptestid, row[1]);
- ZBX_STR2UINT64(httptestitem.itemid, row[2]);
- httptestitem.type=atoi(row[3]);
-
- init_result(&value);
-
- switch (httptestitem.type) {
- case ZBX_HTTPITEM_TYPE_TIME:
- SET_DBL_RESULT(&value, stat->test_total_time);
- process_value(httptestitem.itemid,&value);
- break;
- case ZBX_HTTPITEM_TYPE_LASTSTEP:
- SET_UI64_RESULT(&value, stat->test_last_step);
- process_value(httptestitem.itemid,&value);
- break;
- default:
- break;
- }
-
- free_result(&value);
- }
-
- DBfree_result(result);
- zabbix_log(LOG_LEVEL_DEBUG, "End process_test_data()");
-
- CHECK_MEMORY("process_test_data", "end");
-}
-
-
-static void process_step_data(DB_HTTPTEST *httptest, DB_HTTPSTEP *httpstep, S_ZBX_HTTPSTAT *stat)
-{
- DB_RESULT result;
- DB_ROW row;
- DB_HTTPSTEPITEM httpstepitem;
-
- AGENT_RESULT value;
-
- INIT_CHECK_MEMORY();
-
- zabbix_log(LOG_LEVEL_DEBUG, "In process_step_data(step:%s,url:%s,rsp:%d,time:" ZBX_FS_DBL ",speed:" ZBX_FS_DBL ")",
- httpstep->name,
- httpstep->url,
- stat->rspcode,
- stat->total_time,
- stat->speed_download);
-
- result = DBselect("select httpstepitemid,httpstepid,itemid,type from httpstepitem where httpstepid=" ZBX_FS_UI64,
- httpstep->httpstepid);
-
- while((row=DBfetch(result)))
- {
- ZBX_STR2UINT64(httpstepitem.httpstepitemid, row[0]);
- ZBX_STR2UINT64(httpstepitem.httpstepid, row[1]);
- ZBX_STR2UINT64(httpstepitem.itemid, row[2]);
- httpstepitem.type=atoi(row[3]);
-
- init_result(&value);
-
- switch (httpstepitem.type) {
- case ZBX_HTTPITEM_TYPE_RSPCODE:
- SET_UI64_RESULT(&value, stat->rspcode);
- process_value(httpstepitem.itemid,&value);
- break;
- case ZBX_HTTPITEM_TYPE_TIME:
- SET_DBL_RESULT(&value, stat->total_time);
- process_value(httpstepitem.itemid,&value);
- break;
- case ZBX_HTTPITEM_TYPE_SPEED:
- SET_DBL_RESULT(&value, stat->speed_download);
- process_value(httpstepitem.itemid,&value);
- break;
- default:
- break;
- }
-
- free_result(&value);
- }
-
- DBfree_result(result);
- zabbix_log(LOG_LEVEL_DEBUG, "End process_step_data()");
-
- CHECK_MEMORY("process_step_data", "end");
-}
-
-/******************************************************************************
- * *
- * 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 *
- * *
- ******************************************************************************/
-static void process_httptest(DB_HTTPTEST *httptest)
-{
- DB_RESULT result;
- DB_ROW row;
- DB_HTTPSTEP httpstep;
- int err;
- char *err_str = NULL, *esc_err_str = NULL;
- int now;
- int lastfailedstep;
-
- S_ZBX_HTTPSTAT stat;
-
- CURL *easyhandle = NULL;
-
- INIT_CHECK_MEMORY();
-
- zabbix_log(LOG_LEVEL_DEBUG, "In process_httptest(httptestid:" ZBX_FS_UI64 ",name:%s)",
- httptest->httptestid,
- httptest->name);
-
- now = time(NULL);
-
- DBexecute("update httptest set lastcheck=%d where httptestid=" ZBX_FS_UI64,
- now,
- httptest->httptestid);
-
- easyhandle = curl_easy_init();
- if(easyhandle == NULL)
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot init CURL");
-
- return;
- }
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_COOKIEFILE, "")))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_COOKIEFILE [%s]",
- curl_easy_strerror(err));
- (void)curl_easy_cleanup(easyhandle);
- return;
- }
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_USERAGENT, httptest->agent)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_USERAGENT [%s]",
- curl_easy_strerror(err));
- (void)curl_easy_cleanup(easyhandle);
- return;
- }
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_FOLLOWLOCATION, 1)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_FOLLOWLOCATION [%s]",
- curl_easy_strerror(err));
- (void)curl_easy_cleanup(easyhandle);
- return;
- }
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_WRITEFUNCTION ,WRITEFUNCTION2)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_WRITEFUNCTION [%s]",
- curl_easy_strerror(err));
- (void)curl_easy_cleanup(easyhandle);
- return;
- }
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_HEADERFUNCTION ,HEADERFUNCTION2)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_WRITEFUNCTION [%s]",
- curl_easy_strerror(err));
- (void)curl_easy_cleanup(easyhandle);
- return;
- }
- /* Process self-signed certificates. Do not verify certificate. */
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_SSL_VERIFYPEER , 0)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_SSL_VERIFYPEER [%s]",
- curl_easy_strerror(err));
- (void)curl_easy_cleanup(easyhandle);
- return;
- }
-
- /* Process certs whose hostnames do not match the queried hostname. */
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle,CURLOPT_SSL_VERIFYHOST , 0)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set CURLOPT_SSL_VERIFYHOST [%s]",
- curl_easy_strerror(err));
- (void)curl_easy_cleanup(easyhandle);
- return;
- }
-
- lastfailedstep=0;
- httptest->time = 0;
- result = DBselect("select httpstepid,httptestid,no,name,url,timeout,posts,required,status_codes from httpstep where httptestid=" ZBX_FS_UI64 " order by no",
- httptest->httptestid);
- now=time(NULL);
- while((row=DBfetch(result)) && !err_str)
- {
- /* NOTE: do not use break or return for this block!
- * process_step_data calling required!
- */
- ZBX_STR2UINT64(httpstep.httpstepid, row[0]);
- ZBX_STR2UINT64(httpstep.httptestid, row[1]);
- httpstep.no=atoi(row[2]);
- httpstep.name=row[3];
- strscpy(httpstep.url,row[4]);
- httpstep.timeout=atoi(row[5]);
- strscpy(httpstep.posts,row[6]);
- strscpy(httpstep.required,row[7]);
- strscpy(httpstep.status_codes,row[8]);
-
- DBexecute("update httptest set curstep=%d,curstate=%d where httptestid=" ZBX_FS_UI64,
- httpstep.no,
- HTTPTEST_STATE_BUSY,
- httptest->httptestid);
-
- memset(&stat,0,sizeof(stat));
-
- /* Substitute macros */
- http_substitute_macros(httptest,httpstep.url, sizeof(httpstep.url));
-
- http_substitute_macros(httptest,httpstep.posts, sizeof(httpstep.posts));
- /* zabbix_log(LOG_LEVEL_WARNING, "POSTS [%s]", httpstep.posts); */
- if(httpstep.posts[0] != 0)
- {
- zabbix_log(LOG_LEVEL_DEBUG, "WEBMonitor: use post [%s]", httpstep.posts);
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_POSTFIELDS, httpstep.posts)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set POST vars [%s]",
- curl_easy_strerror(err));
- err_str = strdup(curl_easy_strerror(err));
- lastfailedstep = httpstep.no;
- }
- }
- if( !err_str )
- {
- zabbix_log(LOG_LEVEL_DEBUG, "WEBMonitor: Go to URL [%s]", httpstep.url);
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_URL, httpstep.url)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set URL [%s]",
- curl_easy_strerror(err));
- err_str = strdup(curl_easy_strerror(err));
- lastfailedstep = httpstep.no;
- }
- }
- if( !err_str )
- {
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_TIMEOUT, httpstep.timeout)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set TIMEOUT [%s]",
- curl_easy_strerror(err));
- err_str = strdup(curl_easy_strerror(err));
- lastfailedstep = httpstep.no;
- }
- }
- if( !err_str )
- {
- if(CURLE_OK != (err = curl_easy_setopt(easyhandle, CURLOPT_CONNECTTIMEOUT, httpstep.timeout)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Cannot set CONNECTTIMEOUT [%s]",
- curl_easy_strerror(err));
- err_str = strdup(curl_easy_strerror(err));
- lastfailedstep = httpstep.no;
- }
- }
-
- if( !err_str )
- {
- memset(&page, 0, sizeof(page));
- if(CURLE_OK != (err = curl_easy_perform(easyhandle)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Error doing curl_easy_perform [%s]",
- curl_easy_strerror(err));
- err_str = strdup(curl_easy_strerror(err));
- lastfailedstep = httpstep.no;
- }
- else
- {
- if(httpstep.required[0]!='\0' && zbx_regexp_match(page.data,httpstep.required,NULL) == NULL)
- {
- zabbix_log(LOG_LEVEL_DEBUG, "Page didn't match [%s]", httpstep.required);
- err_str = strdup("Page didn't match");
- lastfailedstep = httpstep.no;
- }
- }
- free(page.data);
-
- if( !err_str )
- {
- if(CURLE_OK != (err = curl_easy_getinfo(easyhandle,CURLINFO_RESPONSE_CODE ,&stat.rspcode)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Error getting CURLINFO_RESPONSE_CODE [%s]",
- curl_easy_strerror(err));
- err_str = strdup(curl_easy_strerror(err));
- lastfailedstep = httpstep.no;
- }
- else if(httpstep.status_codes[0]!='\0' && (int_in_list(httpstep.status_codes,stat.rspcode) == FAIL))
- {
- zabbix_log(LOG_LEVEL_DEBUG, "Status code didn't match [%s]", httpstep.status_codes);
- err_str = strdup("Status code didn't match");
- lastfailedstep = httpstep.no;
- }
- }
-
- if( !err_str && CURLE_OK != (err = curl_easy_getinfo(easyhandle,CURLINFO_TOTAL_TIME ,&stat.total_time)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Error getting CURLINFO_TOTAL_TIME [%s]",
- curl_easy_strerror(err));
- err_str = strdup(curl_easy_strerror(err));
- lastfailedstep = httpstep.no;
- }
-
- if( !err_str && CURLE_OK != (err = curl_easy_getinfo(easyhandle,CURLINFO_SPEED_DOWNLOAD ,&stat.speed_download)))
- {
- zabbix_log(LOG_LEVEL_ERR, "Error getting CURLINFO_SPEED_DOWNLOAD [%s]",
- curl_easy_strerror(err));
- err_str = strdup(curl_easy_strerror(err));
- lastfailedstep = httpstep.no;
- }
- }
-
- httptest->time+=stat.total_time;
- process_step_data(httptest, &httpstep, &stat);
- }
- DBfree_result(result);
-
- esc_err_str = DBdyn_escape_string(err_str);
- zbx_free(err_str);
-
- (void)curl_easy_cleanup(easyhandle);
-
- DBexecute("update httptest set curstep=0,curstate=%d,lastcheck=%d,nextcheck=%d+delay,lastfailedstep=%d,"
- "time=" ZBX_FS_DBL ",error='%s' where httptestid=" ZBX_FS_UI64,
- HTTPTEST_STATE_IDLE,
- now,
- now,
- lastfailedstep,
- httptest->time,
- esc_err_str,
- httptest->httptestid);
-
- zbx_free(esc_err_str);
-
- stat.test_total_time = httptest->time;
- stat.test_last_step = lastfailedstep;
-
- process_test_data(httptest, &stat);
-
- zabbix_log(LOG_LEVEL_DEBUG, "End process_httptest(total time:" ZBX_FS_DBL ")",
- httptest->time);
-
- CHECK_MEMORY("process_httptest", "end");
-}
-
-/******************************************************************************
- * *
- * 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;
-
- DB_HTTPTEST httptest;
-
- INIT_CHECK_MEMORY();
-
- zabbix_log(LOG_LEVEL_DEBUG, "In process_httptests()");
-
- result = DBselect("select httptestid,name,applicationid,nextcheck,status,delay,macros,agent from httptest where status=%d and nextcheck<=%d and " ZBX_SQL_MOD(httptestid,%d) "=%d and " ZBX_COND_NODEID,
- HTTPTEST_STATUS_MONITORED,
- now,
- CONFIG_HTTPPOLLER_FORKS,
- httppoller_num-1,
- LOCAL_NODE("httptestid"));
- while((row=DBfetch(result)))
- {
- ZBX_STR2UINT64(httptest.httptestid, row[0]);
- httptest.name=row[1];
- ZBX_STR2UINT64(httptest.applicationid, row[2]);
- httptest.nextcheck=atoi(row[3]);
- httptest.status=atoi(row[4]);
- httptest.delay=atoi(row[5]);
- httptest.macros=row[6];
- httptest.agent=row[7];
-
- process_httptest(&httptest);
- }
- DBfree_result(result);
- zabbix_log(LOG_LEVEL_DEBUG, "End process_httptests()");
-
- CHECK_MEMORY("process_httptests", "end");
-}
-
-#endif /* HAVE_LIBCURL */
diff --git a/src/zabbix_proxy/httppoller/httptest.h b/src/zabbix_proxy/httppoller/httptest.h
deleted file mode 100644
index fef92849..00000000
--- a/src/zabbix_proxy/httppoller/httptest.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
-** 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
-
-#define S_ZBX_HTTPPAGE struct s_zbx_httppage_t
-S_ZBX_HTTPPAGE
-{
- char *data;
- int allocated;
- int offset;
-};
-
-#define S_ZBX_HTTPSTAT struct s_zbx_httpstat_t
-S_ZBX_HTTPSTAT
-{
- long rspcode;
- double total_time;
- double speed_download;
- double test_total_time;
- int test_last_step;
-};
-
-#ifdef HAVE_LIBCURL
- void process_httptests(int now);
-#else
-# define process_httptests(now)
-#endif /* HAVE_LIBCURL */
-
-extern int httppoller_num;
-
-extern int CONFIG_HTTPPOLLER_FORKS;
-
-#endif
diff --git a/src/zabbix_proxy/proxy.c b/src/zabbix_proxy/proxy.c
index c029db19..ddae1db0 100644
--- a/src/zabbix_proxy/proxy.c
+++ b/src/zabbix_proxy/proxy.c
@@ -42,7 +42,7 @@
#include "../zabbix_server/dbsyncer/dbsyncer.h"
#include "../zabbix_server/discoverer/discoverer.h"
-#include "httppoller/httppoller.h"
+#include "../zabbix_server/httppoller/httppoller.h"
#include "housekeeper/housekeeper.h"
#include "../zabbix_server/pinger/pinger.h"
#include "poller/poller.h"
@@ -518,24 +518,18 @@ int MAIN_ZABBIX_ENTRY(void)
zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller for unreachable hosts. SNMP:%s]",
server_num,
SNMP_FEATURE_STATUS);
- main_poller_loop(ZBX_POLLER_TYPE_UNREACHABLE,
- server_num - (CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS));
-/* } else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS
- + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS
- + CONFIG_NODEWATCHER_FORKS)
- {
-zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Node watcher. Node ID:]",
- server_num);
- main_nodewatcher_loop();*/
- } else if(server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS
- + CONFIG_HOUSEKEEPER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS
- + /*CONFIG_NODEWATCHER_FORKS + */CONFIG_HTTPPOLLER_FORKS)
+
+ main_poller_loop(ZBX_POLLER_TYPE_UNREACHABLE, server_num - (CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS
+ + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS));
+ }
+ else if (server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS
+ + CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_HTTPPOLLER_FORKS)
{
zabbix_log( LOG_LEVEL_WARNING, "server #%d started [HTTP Poller]",
server_num);
- main_httppoller_loop(server_num - CONFIG_POLLER_FORKS - CONFIG_TRAPPERD_FORKS -CONFIG_PINGER_FORKS
- - CONFIG_HOUSEKEEPER_FORKS
- - CONFIG_UNREACHABLE_POLLER_FORKS/* - CONFIG_NODEWATCHER_FORKS*/);
+
+ main_httppoller_loop(server_num - CONFIG_POLLER_FORKS - CONFIG_TRAPPERD_FORKS - CONFIG_PINGER_FORKS
+ - CONFIG_HOUSEKEEPER_FORKS - CONFIG_UNREACHABLE_POLLER_FORKS);
}
else if (server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS
+ CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS)