diff options
author | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-02-15 19:16:03 +0000 |
---|---|---|
committer | sasha <sasha@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2008-02-15 19:16:03 +0000 |
commit | 7f3c4b75b989aa9218908862db0af4233d1c009b (patch) | |
tree | 2ce72219f38a3068c19189921eeeb8620d375de5 /src/zabbix_proxy | |
parent | 0a495e2d44b51021b95bef2b273c4c2fd59af389 (diff) | |
download | zabbix-7f3c4b75b989aa9218908862db0af4233d1c009b.tar.gz zabbix-7f3c4b75b989aa9218908862db0af4233d1c009b.tar.xz zabbix-7f3c4b75b989aa9218908862db0af4233d1c009b.zip |
- [DEV-110] Proxy changes
git-svn-id: svn://svn.zabbix.com/trunk@5358 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src/zabbix_proxy')
-rw-r--r-- | src/zabbix_proxy/Makefile.am | 4 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/Makefile.am | 13 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_agent.c | 133 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_agent.h | 32 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_aggregate.c | 369 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_aggregate.h | 30 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_db.c | 201 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_db.h | 28 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_external.c | 134 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_external.h | 36 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_internal.c | 93 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_internal.h | 30 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_simple.c | 221 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_simple.h | 30 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_snmp.c | 493 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/checks_snmp.h | 30 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/poller.c | 579 | ||||
-rw-r--r-- | src/zabbix_proxy/poller/poller.h | 40 | ||||
-rw-r--r-- | src/zabbix_proxy/proxy.c | 23 |
19 files changed, 14 insertions, 2505 deletions
diff --git a/src/zabbix_proxy/Makefile.am b/src/zabbix_proxy/Makefile.am index bcbca23a..b33438c0 100644 --- a/src/zabbix_proxy/Makefile.am +++ b/src/zabbix_proxy/Makefile.am @@ -7,7 +7,7 @@ SUBDIRS = \ ../zabbix_server/httppoller \ proxyconfig \ ../zabbix_server/pinger \ - poller \ + ../zabbix_server/poller \ ../zabbix_server/trapper sbin_PROGRAMS = zabbix_proxy @@ -28,7 +28,7 @@ zabbix_proxy_LDADD = \ $(top_srcdir)/src/zabbix_server/httppoller/libzbxhttppoller.a \ proxyconfig/libzbxproxyconfig.a \ $(top_srcdir)/src/zabbix_server/pinger/libzbxpinger.a \ - poller/libzbxpoller.a \ + $(top_srcdir)/src/zabbix_server/poller/libzbxpoller.a \ $(top_srcdir)/src/zabbix_server/trapper/libzbxtrapper.a \ $(top_srcdir)/src/libs/zbxsysinfo/libzbxserversysinfo.a \ $(top_srcdir)/src/libs/zbxsysinfo/$(ARCH)/libspecsysinfo.a \ diff --git a/src/zabbix_proxy/poller/Makefile.am b/src/zabbix_proxy/poller/Makefile.am deleted file mode 100644 index 5d6ebe0a..00000000 --- a/src/zabbix_proxy/poller/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -## Process this file with automake to produce Makefile.in - -noinst_LIBRARIES = libzbxpoller.a - -libzbxpoller_a_SOURCES = \ - checks_agent.c checks_agent.h \ - checks_internal.c checks_internal.h \ - checks_simple.c checks_simple.h \ - checks_snmp.c checks_snmp.h \ - checks_db.c checks_db.h \ - checks_aggregate.c checks_aggregate.h \ - checks_external.c checks_external.h \ - poller.c poller.h diff --git a/src/zabbix_proxy/poller/checks_agent.c b/src/zabbix_proxy/poller/checks_agent.c deleted file mode 100644 index a9a5fe80..00000000 --- a/src/zabbix_proxy/poller/checks_agent.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 "comms.h" - -#include "checks_agent.h" - -/****************************************************************************** - * * - * Function: get_value_agent * - * * - * Purpose: retrieve data from ZABBIX agent * - * * - * Parameters: item - item we are interested in * - * * - * Return value: SUCCEED - data succesfully retrieved and stored in result * - * and result_str (as string) * - * NETWORK_ERROR - network related error occured * - * NOTSUPPORTED - item not supported by the agent * - * AGENT_ERROR - uncritical error on agent side occured * - * FAIL - otherwise * - * * - * Author: Alexei Vladishev * - * * - * Comments: error will contain error message * - * * - ******************************************************************************/ -int get_value_agent(DB_ITEM *item, AGENT_RESULT *result) -{ - zbx_sock_t s; - - char - *buf, - packet[MAX_STRING_LEN], - error[MAX_STRING_LEN]; - - int ret = SUCCEED; - - init_result(result); - - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_agent(host:%s,ip:%s,key:%s", - item->host_name, - item->host_ip, - item->key ); - - if (SUCCEED == (ret = zbx_tcp_connect(&s, item->useip==1 ? item->host_ip : item->host_dns, item->port, 0))) { - zbx_snprintf(packet, sizeof(packet), "%s\n",item->key); - zabbix_log(LOG_LEVEL_DEBUG, "Sending [%s]", packet); - - /* Send requests using old protocol */ - if( SUCCEED == (ret = zbx_tcp_send_raw(&s, packet)) ) - { - zabbix_log(LOG_LEVEL_DEBUG, "Before read"); - - ret = zbx_tcp_recv_ext(&s, &buf, ZBX_TCP_READ_UNTIL_CLOSE); - } - } - - if( SUCCEED == ret ) - { - zbx_rtrim(buf, " \r\n\0"); - zbx_ltrim(buf, " "); - - if( strcmp(buf,"ZBX_NOTSUPPORTED") == 0) - { - zbx_snprintf(error,sizeof(error),"Not supported by ZABBIX agent"); - SET_MSG_RESULT(result, strdup(error)); - ret = NOTSUPPORTED; - } - else if( strcmp(buf,"ZBX_ERROR") == 0) - { - zbx_snprintf(error,sizeof(error),"ZABBIX agent non-critical error"); - SET_MSG_RESULT(result, strdup(error)); - ret = AGENT_ERROR; - } - /* The section should be improved */ - else if(buf[0]==0) - { - zbx_snprintf(error,sizeof(error),"Got empty string from [%s] IP [%s] Parameter [%s]", - item->host_name, - item->host_ip, - item->key); - zabbix_log( LOG_LEVEL_WARNING, "%s", - error); - zabbix_log( LOG_LEVEL_WARNING, "Assuming that agent dropped connection because of access permissions"); - SET_MSG_RESULT(result, strdup(error)); - ret = NETWORK_ERROR; - } - else if(set_result_type(result, item->value_type, buf) == FAIL) - { - zbx_snprintf(error,sizeof(error), "Type of received value [%s] is not sutable for [%s@%s] having type [%d]", - buf, - item->key, - item->host_name, - item->value_type); - zabbix_log( LOG_LEVEL_WARNING, "%s", - error); - zabbix_log( LOG_LEVEL_WARNING, "Returning NOTSUPPORTED"); - result->msg=strdup(error); - ret = NOTSUPPORTED; - } - - zabbix_log( LOG_LEVEL_DEBUG, "End get_value_agent(result:%s)", - buf); - - } - else - { - zabbix_log(LOG_LEVEL_WARNING, "Get value from agent failed. Error: %s", zbx_tcp_strerror()); - SET_MSG_RESULT(result, strdup(zbx_tcp_strerror())); - ret = NETWORK_ERROR; - - } - zbx_tcp_close(&s); - - return ret; -} diff --git a/src/zabbix_proxy/poller/checks_agent.h b/src/zabbix_proxy/poller/checks_agent.h deleted file mode 100644 index f890eee7..00000000 --- a/src/zabbix_proxy/poller/checks_agent.h +++ /dev/null @@ -1,32 +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_CHECKS_AGENT_H -#define ZABBIX_CHECKS_AGENT_H - -#include "common.h" -#include "db.h" -#include "log.h" -#include "sysinfo.h" - -extern int CONFIG_NOTIMEWAIT; - -extern int get_value_agent(DB_ITEM *item, AGENT_RESULT *result); - -#endif diff --git a/src/zabbix_proxy/poller/checks_aggregate.c b/src/zabbix_proxy/poller/checks_aggregate.c deleted file mode 100644 index 29e56cb7..00000000 --- a/src/zabbix_proxy/poller/checks_aggregate.c +++ /dev/null @@ -1,369 +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 "checks_aggregate.h" - -static int evaluate_one(double *result, int *num, char *grpfunc, char const *value_str, int valuetype) -{ - int ret = SUCCEED; - double value = 0; - - if(valuetype == ITEM_VALUE_TYPE_FLOAT) - { - value = zbx_atod(value_str); - } - else if(valuetype == ITEM_VALUE_TYPE_UINT64) - { - value = (double)zbx_atoui64(value_str); - } - - if(strcmp(grpfunc,"grpsum") == 0) - { - *result+=value; - *num+=1; - } - else if(strcmp(grpfunc,"grpavg") == 0) - { - *result+=value; - *num+=1; - } - else if(strcmp(grpfunc,"grpmin") == 0) - { - if(*num==0) - { - *result=value; - } - else if(value<*result) - { - *result=value; - } - *num+=1; - } - else if(strcmp(grpfunc,"grpmax") == 0) - { - if(*num==0) - { - *result=value; - } - else if(value>*result) - { - *result=value; - } - *num+=1; - } - else - { - ret = FAIL; - } - - return ret; -} - -/* - * grpfunc: grpmax, grpmin, grpsum, grpavg - * itemfunc: last, min, max, avg, sum,count - */ -static int evaluate_aggregate(AGENT_RESULT *res,char *grpfunc, char *hostgroup, char *itemkey, char *itemfunc, char *param) -{ - char sql[MAX_STRING_LEN]; - char sql2[MAX_STRING_LEN]; - char hostgroup_esc[MAX_STRING_LEN],itemkey_esc[MAX_STRING_LEN]; - - DB_RESULT result; - DB_ROW row; - - int valuetype; - double d = 0; - const char *value; - int num = 0; - int now; - char items[MAX_STRING_LEN],items2[MAX_STRING_LEN]; - - now=time(NULL); - - zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_aggregate('%s','%s','%s','%s','%s')", - grpfunc, - hostgroup, - itemkey, - itemfunc, - param); - - init_result(res); - - DBescape_string(itemkey,itemkey_esc,MAX_STRING_LEN); - DBescape_string(hostgroup,hostgroup_esc,MAX_STRING_LEN); -/* Get list of affected item IDs */ - strscpy(items,"0"); - result = DBselect("select itemid from items i,hosts_groups hg,hosts h,groups g where hg.groupid=g.groupid and i.hostid=h.hostid and hg.hostid=h.hostid and g.name='%s' and i.key_='%s' and i.status=%d and h.status=%d and" ZBX_COND_NODEID, - hostgroup_esc, - itemkey_esc, - ITEM_STATUS_ACTIVE, - HOST_STATUS_MONITORED, - LOCAL_NODE("h.hostid")); - - while((row=DBfetch(result))) - { - zbx_snprintf(items2,sizeof(items2),"%s,%s", - items, - row[0]); -/* zabbix_log( LOG_LEVEL_WARNING, "ItemIDs items2[%s])",items2);*/ - strscpy(items,items2); -/* zabbix_log( LOG_LEVEL_WARNING, "ItemIDs items[%s])",items2);*/ - } - DBfree_result(result); - - if(strcmp(itemfunc,"last") == 0) - { - zbx_snprintf(sql,sizeof(sql),"select itemid,value_type,lastvalue from items where lastvalue is not NULL and items.itemid in (%s)", - items); - zbx_snprintf(sql2,sizeof(sql2),"select itemid,value_type,lastvalue from items where 0=1"); - } - /* The SQL works very very slow on MySQL 4.0. That's why it has been split into two. */ -/* zbx_snprintf(sql,sizeof(sql),"select items.itemid,items.value_type,min(history.value) from items,hosts_groups,hosts,groups,history where history.itemid=items.itemid and hosts_groups.groupid=groups.groupid and items.hostid=hosts.hostid and hosts_groups.hostid=hosts.hostid and groups.name='%s' and items.key_='%s' and history.clock>%d group by 1,2",hostgroup_esc, itemkey_esc, now - atoi(param));*/ - else if( (strcmp(itemfunc,"min") == 0) || - (strcmp(itemfunc,"max") == 0) || - (strcmp(itemfunc,"avg") == 0) || - (strcmp(itemfunc,"count") == 0) || - (strcmp(itemfunc,"sum") == 0) - ) - { - zbx_snprintf(sql,sizeof(sql),"select h.itemid,i.value_type,%s(h.value) from items i,history h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by h.itemid,i.value_type", - itemfunc, - items, - now - atoi(param)); - zbx_snprintf(sql2,sizeof(sql),"select h.itemid,i.value_type,%s(h.value) from items i,history_uint h where h.itemid=i.itemid and h.itemid in (%s) and h.clock>%d group by h.itemid,i.value_type", - itemfunc, - items, - now - atoi(param)); - } - else - { - SET_MSG_RESULT(res, strdup("Unsupported item function")); - zabbix_log( LOG_LEVEL_WARNING, "Unsupported item function [%s])", - itemfunc); - return FAIL; - } - zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]",sql); - zabbix_log( LOG_LEVEL_DEBUG, "SQL2 [%s]",sql2); - - result = DBselect("%s",sql); - while((row=DBfetch(result))) - { - valuetype = atoi(row[1]); - value = row[2]; - if(FAIL == evaluate_one(&d, &num, grpfunc, value, valuetype)) - { - SET_MSG_RESULT(res, strdup("Unsupported group function")); - zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])", - grpfunc); - DBfree_result(result); - return FAIL; - } - } - DBfree_result(result); - - result = DBselect("%s",sql2); - while((row=DBfetch(result))) - { - valuetype = atoi(row[1]); - value = row[2]; - if(FAIL == evaluate_one(&d, &num, grpfunc, value, valuetype)) - { - SET_MSG_RESULT(res, strdup("Unsupported group function")); - zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])", - grpfunc); - DBfree_result(result); - return FAIL; - } - } - DBfree_result(result); - - if(num==0) - { - SET_MSG_RESULT(res, strdup("No values")); - zabbix_log( LOG_LEVEL_WARNING, "No values for group[%s] key[%s])", - hostgroup, - itemkey); - return FAIL; - } - - if(strcmp(grpfunc,"grpavg") == 0) - { - SET_DBL_RESULT(res, d/num); - } - else - { - SET_DBL_RESULT(res, d); - } - - zabbix_log( LOG_LEVEL_DEBUG, "End evaluate_aggregate(result:" ZBX_FS_DBL ")", - d); - return SUCCEED; -} - -/****************************************************************************** - * * - * Function: get_value_aggregate * - * * - * Purpose: retrieve data from ZABBIX server (aggregate items) * - * * - * Parameters: item - item we are interested in * - * * - * Return value: SUCCEED - data succesfully retrieved and stored in result * - * and result_str (as string) * - * NOTSUPPORTED - requested item is not supported * - * * - * Author: Alexei Vladishev * - * * - * Comments: * - * * - ******************************************************************************/ -int get_value_aggregate(DB_ITEM *item, AGENT_RESULT *result) -{ - char function_grp[MAX_STRING_LEN]; - char key[MAX_STRING_LEN]; - char group[MAX_STRING_LEN]; - char itemkey[MAX_STRING_LEN]; - char function_item[MAX_STRING_LEN]; - char parameter[MAX_STRING_LEN]; - char *p,*p2; - - int ret = SUCCEED; - - - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_aggregate([%s])", - item->key); - - init_result(result); - - strscpy(key, item->key); - if((p=strchr(key,'[')) != NULL) - { - *p=0; - strscpy(function_grp,key); - *p='['; - p++; - } - else ret = NOTSUPPORTED; - - if(ret == SUCCEED) - { - if((p2=strchr(p,'"')) != NULL) - { - p2++; - } - else ret = NOTSUPPORTED; - - if((ret == SUCCEED) && (p=strchr(p2,'"')) != NULL) - { - *p=0; - strscpy(group,p2); - *p='"'; - p++; - } - else ret = NOTSUPPORTED; - } - - if(ret == SUCCEED) - { - if(*p != ',') ret = NOTSUPPORTED; - } - - if(ret == SUCCEED) - { - if((p2=strchr(p,'"')) != NULL) - { - p2++; - } - else ret = NOTSUPPORTED; - - if((ret == SUCCEED) && (p=strchr(p2,'"')) != NULL) - { - *p=0; - strscpy(itemkey,p2); - *p='"'; - p++; - } - else ret = NOTSUPPORTED; - } - - if(ret == SUCCEED) - { - if(*p != ',') ret = NOTSUPPORTED; - } - - if(ret == SUCCEED) - { - if((p2=strchr(p,'"')) != NULL) - { - p2++; - } - else ret = NOTSUPPORTED; - - if((ret == SUCCEED) && (p=strchr(p2,'"')) != NULL) - { - *p=0; - strscpy(function_item,p2); - *p='"'; - p++; - } - else ret = NOTSUPPORTED; - } - - if(ret == SUCCEED) - { - if(*p != ',') ret = NOTSUPPORTED; - } - - if(ret == SUCCEED) - { - if((p2=strchr(p,'"')) != NULL) - { - p2++; - } - else ret = NOTSUPPORTED; - - if((ret == SUCCEED) && (p=strchr(p2,'"')) != NULL) - { - *p=0; - strscpy(parameter,p2); - *p='"'; - p++; - } - else ret = NOTSUPPORTED; - } - - zabbix_log( LOG_LEVEL_DEBUG, "Evaluating aggregate[%s] grpfunc[%s] group[%s] itemkey[%s] itemfunc [%s] parameter [%s]", - item->key, - function_grp, - group, - itemkey, - function_item, - parameter); - - if( (ret == SUCCEED) && - (evaluate_aggregate(result,function_grp, group, itemkey, function_item, parameter) != SUCCEED) - ) - { - ret = NOTSUPPORTED; - } - - return ret; -} diff --git a/src/zabbix_proxy/poller/checks_aggregate.h b/src/zabbix_proxy/poller/checks_aggregate.h deleted file mode 100644 index 0d42b2bd..00000000 --- a/src/zabbix_proxy/poller/checks_aggregate.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_CHECKS_AGGREGATE_H -#define ZABBIX_CHECKS_AGGREGATE_H - -#include "common.h" -#include "db.h" -#include "log.h" -#include "sysinfo.h" - -extern int get_value_aggregate(DB_ITEM *item, AGENT_RESULT *result); - -#endif diff --git a/src/zabbix_proxy/poller/checks_db.c b/src/zabbix_proxy/poller/checks_db.c deleted file mode 100644 index bd3b9cf7..00000000 --- a/src/zabbix_proxy/poller/checks_db.c +++ /dev/null @@ -1,201 +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" - -#ifdef HAVE_ODBC -# include "zbxodbc.h" -#endif /* HAVE_ODBC */ - -#include "checks_db.h" -#include "log.h" - -#ifdef HAVE_ODBC -/****************************************************************************** - * * - * Function: get_param_value * - * * - * Purpose: retrieve parameter value by name * - * * - * Parameters: params - list of params * - * param_name - name of requested parameter * - * * - * Return value: NULL - if parameter missedparam_name, * - * else return value in new allocated memory * - * * - * Author: Eugene Grigorjev * - * * - * Comments: this function allocate memory, required zbx_free for result!!! * - * one parameter format: param1_name=param1_value * - * parameters splited by '\n' * - * * - ******************************************************************************/ -static char* get_param_value(char* params, const char* param_name) -{ - char - *p = NULL, - *l = NULL, - *n = NULL, - *r = NULL, - *buf = NULL; - - for(p = params; p && *p; p++) - { - r = NULL; - - /* trim left spaces */ - for(; *p == ' '; p++); - - /* find '=' symbol */ - for(n = p; *n && *n != '\n'; n++) - { - if(*n == '=') - { - /* trim right spaces */ - for(l = n - 1; *l == ' '; l--); - l++; - - /* compare parameter name */ - if(l - p != strlen(param_name)) break; - if(strncmp(p, param_name, l - p)) break; - - r = n+1; - break; - } - } - - /* find EOL */ - for(p = n; *p && *p != '\n'; p++); - - /* allocate result */ - if(r) - { - /* trim right EOL symbols */ - while(*p == '\r' || *p == '\n' || *p == '\0') p--; - p++; - - /* allocate result */ - buf = zbx_malloc(buf, p - r + 1); - memmove(buf, r, p - r); - buf[p - r] = '\0'; - - break; - } - } - - if(buf == NULL) - { - /* allocate result */ - buf = zbx_malloc(buf, 1); - *buf = '\0'; - } - return buf; -} -#endif /* HAVE_ODBC */ - -/****************************************************************************** - * * - * Function: get_value_db * - * * - * Purpose: retrieve data from database * - * * - * Parameters: item - item we are interested in * - * * - * Return value: SUCCEED - data succesfully retrieved and stored in result * - * NOTSUPPORTED - requested item is not supported * - * * - * Author: Eugene Grigorjev * - * * - * Comments: * - * * - ******************************************************************************/ -int get_value_db(DB_ITEM *item, AGENT_RESULT *result) -{ -#ifdef HAVE_ODBC - ZBX_ODBC_DBH dbh; - ZBX_ODBC_ROW row; - - char - *db_dsn = NULL, - *db_user = NULL, - *db_pass = NULL, - *db_sql = NULL; -#endif /* HAVE_ODBC */ - - int ret = NOTSUPPORTED; - - init_result(result); - - zabbix_log(LOG_LEVEL_DEBUG, "In database monitor: %s", item->key); - -#ifdef HAVE_ODBC - - #define DB_ODBC_SELECT_KEY "db.odbc.select[" - - if(strncmp(item->key, DB_ODBC_SELECT_KEY, strlen(DB_ODBC_SELECT_KEY)) == 0) - { - db_dsn = get_param_value(item->params,"DSN"); - db_user = get_param_value(item->params,"user"); - db_pass = get_param_value(item->params,"password"); - db_sql = get_param_value(item->params,"sql"); - - if( SUCCEED == odbc_DBconnect(&dbh, db_dsn, db_user, db_pass) ) - { - if( NULL != (row = odbc_DBfetch(odbc_DBselect(&dbh, db_sql))) ) - { - if( SUCCEED == set_result_type(result, item->value_type, row[0]) ) - { - zabbix_log(LOG_LEVEL_DEBUG, "Result accepted with type 0x%02X [%s]", item->value_type, row[0]); - ret = SUCCEED; - } - else - { - zabbix_log(LOG_LEVEL_DEBUG, "Cant determine result type [%s]", row[0]); - } - } - else - { - SET_MSG_RESULT(result, strdup(get_last_odbc_strerror())); - } - odbc_DBclose(&dbh); - } - else - { - SET_MSG_RESULT(result, strdup(get_last_odbc_strerror())); - } - - zbx_free(db_dsn); - zbx_free(db_user); - zbx_free(db_pass); - zbx_free(db_sql); - } - -#endif /* HAVE_ODBC */ - - /* - * TODO: - * - * db.*.select[] - * db.*.ping - * ... - * - */ - - return ret; -} diff --git a/src/zabbix_proxy/poller/checks_db.h b/src/zabbix_proxy/poller/checks_db.h deleted file mode 100644 index e3b07d21..00000000 --- a/src/zabbix_proxy/poller/checks_db.h +++ /dev/null @@ -1,28 +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_CHECKS_DB_H -#define ZABBIX_CHECKS_DB_H - -#include "db.h" -#include "sysinfo.h" - -int get_value_db(DB_ITEM *item, AGENT_RESULT *result); - -#endif /* ZABBIX_CHECKS_DB_H */ diff --git a/src/zabbix_proxy/poller/checks_external.c b/src/zabbix_proxy/poller/checks_external.c deleted file mode 100644 index a4a164b7..00000000 --- a/src/zabbix_proxy/poller/checks_external.c +++ /dev/null @@ -1,134 +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 "checks_external.h" - -/****************************************************************************** - * * - * Function: get_value_external * - * * - * Purpose: retrieve data from script executed on ZABBIX server * - * * - * Parameters: item - item we are interested in * - * * - * Return value: SUCCEED - data succesfully retrieved and stored in result * - * and result_str (as string) * - * NOTSUPPORTED - requested item is not supported * - * * - * Author: Mike Nestor * - * * - * Comments: * - * * - ************************************************** ****************************/ -int get_value_external(DB_ITEM *item, AGENT_RESULT *result) -{ - FILE* fp; - char scriptname[MAX_STRING_LEN]; - char key[MAX_STRING_LEN]; - char params[MAX_STRING_LEN]; - char error[MAX_STRING_LEN]; - char cmd[MAX_STRING_LEN]; - char msg[MAX_STRING_LEN]; - char *p,*p2; - int i; - - int ret = SUCCEED; - - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_external([%s])",item->key); - - init_result(result); - - strscpy(key, item->key); - if((p2=strchr(key,'[')) != NULL) - { - *p2=0; - strscpy(scriptname,key); - zabbix_log( LOG_LEVEL_DEBUG, "scriptname [%s]",scriptname); - *p2='['; - p2++; - } - else ret = NOTSUPPORTED; - - if(ret == SUCCEED) - { - if((ret == SUCCEED) && (p=strchr(p2,']')) != NULL) - { - *p=0; - strscpy(params,p2); - zabbix_log( LOG_LEVEL_DEBUG, "params [%s]",params); - *p=']'; - p++; - } - else ret = NOTSUPPORTED; - } - else - { - zbx_snprintf(error,MAX_STRING_LEN-1,"External check [%s] is not supported", item->key); - zabbix_log( LOG_LEVEL_DEBUG, "%s", error); - SET_STR_RESULT(result, strdup(error)); - return NOTSUPPORTED; - } - - zbx_snprintf(cmd, MAX_STRING_LEN-1, "%s/%s %s %s", - CONFIG_EXTERNALSCRIPTS, - scriptname, -/* item->host_name,*/ - item->useip == 1 ? item->host_ip : item->host_dns, - params); - zabbix_log( LOG_LEVEL_DEBUG, "%s", cmd ); - if (NULL == (fp = popen(cmd, "r"))) - { - zbx_snprintf(error,MAX_STRING_LEN-1,"External check [%s] is not supported, failed execution", item->key); - zabbix_log( LOG_LEVEL_DEBUG, "%s", error); - SET_STR_RESULT(result, strdup(error)); - return NOTSUPPORTED; - } - - /* we only care about the first line */ - memset(msg,0,sizeof(msg)); - if(NULL != fgets(msg, sizeof(msg)-1, fp)) - { - for (i = 0; i < MAX_STRING_LEN && msg[i] != 0; ++i) - { - if (msg[i] == '\n') - { - msg[i] = 0; - break; - } - } - zabbix_log( LOG_LEVEL_DEBUG, "Result [%s]", msg); - - set_result_type(result,item->value_type,strdup(msg)); - } - else - { - zbx_snprintf(error,MAX_STRING_LEN-1,"Script %s/%s returned nothing.", - CONFIG_EXTERNALSCRIPTS, - scriptname); - zabbix_log( LOG_LEVEL_WARNING, "%s", error); - SET_STR_RESULT(result, strdup(error)); - ret = NOTSUPPORTED; - } - - /* cleanup */ - pclose(fp); - - return ret; -} diff --git a/src/zabbix_proxy/poller/checks_external.h b/src/zabbix_proxy/poller/checks_external.h deleted file mode 100644 index cdabbaab..00000000 --- a/src/zabbix_proxy/poller/checks_external.h +++ /dev/null @@ -1,36 +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_CHECKS_EXTERNAL_H -#define ZABBIX_CHECKS_EXTERNAL_H - -#include <string.h> -#include <stdio.h> -#include <stdlib.h> - -#include "common.h" -#include "db.h" -#include "log.h" -#include "sysinfo.h" - -extern char *CONFIG_EXTERNALSCRIPTS; - -extern int get_value_external(DB_ITEM *item, AGENT_RESULT *result); - -#endif diff --git a/src/zabbix_proxy/poller/checks_internal.c b/src/zabbix_proxy/poller/checks_internal.c deleted file mode 100644 index ed53c36e..00000000 --- a/src/zabbix_proxy/poller/checks_internal.c +++ /dev/null @@ -1,93 +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 "checks_internal.h" - -/****************************************************************************** - * * - * Function: get_value_internal * - * * - * Purpose: retrieve data from ZABBIX server (internally supported intems) * - * * - * Parameters: item - item we are interested in * - * * - * Return value: SUCCEED - data succesfully retrieved and stored in result * - * and result_str (as string) * - * NOTSUPPORTED - requested item is not supported * - * * - * Author: Alexei Vladishev * - * * - * Comments: * - * * - ******************************************************************************/ -int get_value_internal(DB_ITEM *item, AGENT_RESULT *result) -{ - zbx_uint64_t i; - char error[MAX_STRING_LEN]; - - init_result(result); - - if(strcmp(item->key,"zabbix[triggers]")==0) - { - i = (zbx_uint64_t)DBget_triggers_count(); - SET_UI64_RESULT(result, i); - } - else if(strcmp(item->key,"zabbix[items]")==0) - { - i = (zbx_uint64_t)DBget_items_count(); - SET_UI64_RESULT(result, i); - } - else if(strcmp(item->key,"zabbix[items_unsupported]")==0) - { - i=DBget_items_unsupported_count(); - SET_UI64_RESULT(result, i); - } - else if(strcmp(item->key,"zabbix[history]")==0) - { - i=DBget_history_count(); - SET_UI64_RESULT(result, i); - } - else if(strcmp(item->key,"zabbix[history_str]")==0) - { - i=DBget_history_str_count(); - SET_UI64_RESULT(result, i); - } - else if(strcmp(item->key,"zabbix[trends]")==0) - { - i=DBget_trends_count(); - SET_UI64_RESULT(result, i); - } - else if(strcmp(item->key,"zabbix[queue]")==0) - { - i=DBget_queue_count(); - SET_UI64_RESULT(result, i); - } - else - { - zbx_snprintf(error,sizeof(error),"Internal check [%s] is not supported", - item->key); - zabbix_log( LOG_LEVEL_WARNING, "%s", - error); - SET_STR_RESULT(result, strdup(error)); - return NOTSUPPORTED; - } - - return SUCCEED; -} diff --git a/src/zabbix_proxy/poller/checks_internal.h b/src/zabbix_proxy/poller/checks_internal.h deleted file mode 100644 index da2bdf75..00000000 --- a/src/zabbix_proxy/poller/checks_internal.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_CHECKS_INTERNAL_H -#define ZABBIX_CHECKS_INTERNAL_H - -#include "common.h" -#include "db.h" -#include "log.h" -#include "sysinfo.h" - -extern int get_value_internal(DB_ITEM *item, AGENT_RESULT *result); - -#endif diff --git a/src/zabbix_proxy/poller/checks_simple.c b/src/zabbix_proxy/poller/checks_simple.c deleted file mode 100644 index bce26b2f..00000000 --- a/src/zabbix_proxy/poller/checks_simple.c +++ /dev/null @@ -1,221 +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 "checks_simple.h" - -int get_value_simple(DB_ITEM *item, AGENT_RESULT *result) -{ - char *t; - char c[MAX_STRING_LEN]; - char param[MAX_STRING_LEN]; - char error[MAX_STRING_LEN]; - char service[MAX_STRING_LEN]; - char service_sysinfo[MAX_STRING_LEN]; - char ip[MAX_STRING_LEN]; - char port[MAX_STRING_LEN]; - int port_int=0; - int ret = SUCCEED; - char *l,*r; - /* Assumption: host name does not contain '_perf' */ - - init_result(result); - - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_simple([%s]", - item->key); - - if(0 == strncmp(item->key,"service.ntp",11)) - { - l=strchr(item->key,'['); - r=strrchr(item->key,']'); - if(l==NULL || r==NULL) - zbx_snprintf(c,sizeof(c),"net.tcp.service[%s]", - item->key); - else - { - zbx_strlcpy( param,l+1, r-l-1); - if(item->useip==1) - { - zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]", - item->key, - item->host_ip); - } - else - { - zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]", - item->key, - item->host_ip); - } - } - } - else if(0 == strncmp(item->key,"dns",3)) - { - if(item->useip==1) - { - l=strchr(item->key,'['); - r=strrchr(item->key,']'); - if(l==NULL || r==NULL) - zbx_snprintf(c,sizeof(c),"%s", - item->key); - else - { - zbx_strlcpy( param,l+1, r-l-1); -/* zbx_snprintf(c,sizeof(c),"dns[%s,%s]",item->ip,param);*/ - zbx_snprintf(c,sizeof(c),"dns[%s]", - param); - } - } - else - { - zbx_snprintf(error,sizeof(error),"You must use IP address in Host %s definition", - item->host_name); - zabbix_log( LOG_LEVEL_WARNING, "%s", - error); - result->str=strdup(error); - return NOTSUPPORTED; - } - } - else - { - ip[0]=0; - port[0]=0; - service[0]=0; - if(num_param(item->key) == 1) - { - if(get_param(item->key, 1, service, MAX_STRING_LEN) != 0) - { - ret = NOTSUPPORTED; - } - } - else if(num_param(item->key) == 2) - { - if(get_param(item->key, 1, service, MAX_STRING_LEN) != 0) - { - ret = NOTSUPPORTED; - } - if(get_param(item->key, 2, port, MAX_STRING_LEN) != 0) - { - ret = NOTSUPPORTED; - } - else if(is_uint(port)==SUCCEED) - { - port_int=atoi(port); - } - else - { - zbx_snprintf(error,sizeof(error),"Port number must be numeric in [%s]", - item->key); - zabbix_log( LOG_LEVEL_WARNING, "%s", - error); - result->str=strdup(error); - ret = NOTSUPPORTED; - } - } - else - { - zbx_snprintf(error,sizeof(error),"Too many parameters in [%s]", - item->key); - zabbix_log( LOG_LEVEL_WARNING, "%s", - error); - result->str=strdup(error); - ret = NOTSUPPORTED; - } - - if(ret == SUCCEED) - { - if(item->useip==1) - { - strscpy(ip,item->host_ip); - } - else - { - strscpy(ip,item->host_dns); - } - - t = strstr(service,"_perf"); - if(t != NULL) - { - t[0]=0; - strscpy(service_sysinfo,"net.tcp.service.perf"); - } - else strscpy(service_sysinfo,"net.tcp.service"); - - if(port_int == 0) - { - zbx_snprintf(c,sizeof(c),"%s[%s,%s]", - service_sysinfo, - service, - ip); - } - else - { - zbx_snprintf(c,sizeof(c),"%s[%s,%s,%d]", - service_sysinfo, - service, - ip, - port_int); - } - zabbix_log( LOG_LEVEL_DEBUG, "Sysinfo [%s]", - c); - } - else - { - return ret; - } - } -/* - else if(NULL == strstr(item->key,"_perf")) - { - if(item->useip==1) - { - zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->ip); - } - else - { - zbx_snprintf(c,sizeof(c),"net.tcp.service[%s,%s]",item->key,item->host); - } - } - else - { - strscpy(s,item->key); - t=strstr(s,"_perf"); - t[0]=0; - - if(item->useip==1) - { - zbx_snprintf(c,sizeof(c),"net.tcp.service.perf[%s,%s]",s,item->ip); - } - else - { - zbx_snprintf(c,sizeof(c),"net.tcp.service.perf[%s,%s]",s,item->host); - } - } -*/ - - if(process(c, 0, result) == NOTSUPPORTED) - { - zbx_snprintf(error,sizeof(error),"Simple check [%s] is not supported", - c); - zabbix_log( LOG_LEVEL_WARNING, "%s", - error); - result->str=strdup(error); - ret = NOTSUPPORTED; - } - - return ret; -} diff --git a/src/zabbix_proxy/poller/checks_simple.h b/src/zabbix_proxy/poller/checks_simple.h deleted file mode 100644 index 3b327214..00000000 --- a/src/zabbix_proxy/poller/checks_simple.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_CHECKS_SIMPLE_H -#define ZABBIX_CHECKS_SIMPLE_H - -#include "common.h" -#include "db.h" -#include "log.h" -#include "sysinfo.h" - -extern int get_value_simple(DB_ITEM *item, AGENT_RESULT *result); - -#endif diff --git a/src/zabbix_proxy/poller/checks_snmp.c b/src/zabbix_proxy/poller/checks_snmp.c deleted file mode 100644 index b289a1bc..00000000 --- a/src/zabbix_proxy/poller/checks_snmp.c +++ /dev/null @@ -1,493 +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 "checks_snmp.h" - -#ifdef HAVE_SNMP -int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value) -{ - - #define NEW_APPROACH - - struct snmp_session session, *ss; - struct snmp_pdu *pdu; - struct snmp_pdu *response; - -#ifdef NEW_APPROACH - char temp[MAX_STRING_LEN]; -#endif - - oid anOID[MAX_OID_LEN]; - size_t anOID_len = MAX_OID_LEN; - - struct variable_list *vars; - int status; - - char *p, *c; - - unsigned char *ip; - - char error[MAX_STRING_LEN]; - - int ret=SUCCEED; - - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP()"); - - init_result(value); - -/* assert((item->type == ITEM_TYPE_SNMPv1)||(item->type == ITEM_TYPE_SNMPv2c)); */ - assert((item->type == ITEM_TYPE_SNMPv1)||(item->type == ITEM_TYPE_SNMPv2c)||(item->type == ITEM_TYPE_SNMPv3)); - - snmp_sess_init( &session ); -/* session.version = version;*/ - if(item->type == ITEM_TYPE_SNMPv1) - { - session.version = SNMP_VERSION_1; - } - else if(item->type == ITEM_TYPE_SNMPv2c) - { - session.version = SNMP_VERSION_2c; - } - else if(item->type == ITEM_TYPE_SNMPv3) - { - session.version = SNMP_VERSION_3; - } - else - { - zbx_snprintf(error,sizeof(error),"Error in get_value_SNMP. Wrong item type [%d]. Must be SNMP.", - item->type); - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - - return NOTSUPPORTED; - } - - - if(item->useip == 1) - { - #ifdef NEW_APPROACH - zbx_snprintf(temp,sizeof(temp),"%s:%d", - item->host_ip, - item->snmp_port); - session.peername = temp; - session.remote_port = item->snmp_port; - #else - session.peername = item->host_ip; - session.remote_port = item->snmp_port; - #endif - } - else - { - #ifdef NEW_APPROACH - zbx_snprintf(temp, sizeof(temp), "%s:%d", - item->host_dns, - item->snmp_port); - session.peername = temp; - session.remote_port = item->snmp_port; - #else - session.peername = item->host_dns; - session.remote_port = item->snmp_port; - #endif - } - - if( (session.version == SNMP_VERSION_1) || (item->type == ITEM_TYPE_SNMPv2c)) - { - session.community = (u_char *)item->snmp_community; - session.community_len = strlen((void *)session.community); - zabbix_log( LOG_LEVEL_DEBUG, "SNMP [%s@%s:%d]", - session.community, - session.peername, - session.remote_port); - } - else if(session.version == SNMP_VERSION_3) - { - /* set the SNMPv3 user name */ - session.securityName = item->snmpv3_securityname; - session.securityNameLen = strlen(session.securityName); - - /* set the security level to authenticated, but not encrypted */ - - if(item->snmpv3_securitylevel == ITEM_SNMPV3_SECURITYLEVEL_NOAUTHNOPRIV) - { - session.securityLevel = SNMP_SEC_LEVEL_NOAUTH; - } - else if(item->snmpv3_securitylevel == ITEM_SNMPV3_SECURITYLEVEL_AUTHNOPRIV) - { - session.securityLevel = SNMP_SEC_LEVEL_AUTHNOPRIV; - - /* set the authentication method to MD5 */ - session.securityAuthProto = usmHMACMD5AuthProtocol; - session.securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN; - session.securityAuthKeyLen = USM_AUTH_KU_LEN; - - if (generate_Ku(session.securityAuthProto, - session.securityAuthProtoLen, - (u_char *) item->snmpv3_authpassphrase, strlen(item->snmpv3_authpassphrase), - session.securityAuthKey, - &session.securityAuthKeyLen) != SNMPERR_SUCCESS) - { - zbx_snprintf(error,sizeof(error),"Error generating Ku from authentication pass phrase."); - - zabbix_log( LOG_LEVEL_ERR, "%s", error); - SET_MSG_RESULT(value, strdup(error)); - - return NOTSUPPORTED; - } - } - else if(item->snmpv3_securitylevel == ITEM_SNMPV3_SECURITYLEVEL_AUTHPRIV) - { - session.securityLevel = SNMP_SEC_LEVEL_AUTHPRIV; - - /* set the authentication method to MD5 */ - session.securityAuthProto = usmHMACMD5AuthProtocol; - session.securityAuthProtoLen = USM_AUTH_PROTO_MD5_LEN; - session.securityAuthKeyLen = USM_AUTH_KU_LEN; - - if (generate_Ku(session.securityAuthProto, - session.securityAuthProtoLen, - (u_char *) item->snmpv3_authpassphrase, strlen(item->snmpv3_authpassphrase), - session.securityAuthKey, - &session.securityAuthKeyLen) != SNMPERR_SUCCESS) - { - zbx_snprintf(error,sizeof(error),"Error generating Ku from authentication pass phrase."); - - zabbix_log( LOG_LEVEL_ERR, "%s", error); - SET_MSG_RESULT(value, strdup(error)); - - return NOTSUPPORTED; - } - - /* set the private method to DES */ - session.securityPrivProto = usmDESPrivProtocol; - session.securityPrivProtoLen = USM_PRIV_PROTO_DES_LEN; - session.securityPrivKeyLen = USM_PRIV_KU_LEN; - - if (generate_Ku(session.securityAuthProto, - session.securityAuthProtoLen, - (u_char *) item->snmpv3_privpassphrase, strlen(item->snmpv3_privpassphrase), - session.securityPrivKey, - &session.securityPrivKeyLen) != SNMPERR_SUCCESS) - { - zbx_snprintf(error,sizeof(error),"Error generating Ku from priv pass phrase."); - - zabbix_log( LOG_LEVEL_ERR, "%s", error); - SET_MSG_RESULT(value, strdup(error)); - - return NOTSUPPORTED; - } - } - zabbix_log( LOG_LEVEL_DEBUG, "SNMPv3 [%s@%s:%d]", - session.securityName, - session.peername, - session.remote_port); - } - else - { - zbx_snprintf(error,sizeof(error),"Error in get_value_SNMP. Unsupported session.version [%d]", - (int)session.version); - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - - return NOTSUPPORTED; - } - - zabbix_log( LOG_LEVEL_DEBUG, "OID [%s]", - item->snmp_oid); - - SOCK_STARTUP; - ss = snmp_open(&session); - - if(ss == NULL) - { - SOCK_CLEANUP; - - zbx_snprintf(error,sizeof(error),"Error doing snmp_open()"); - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - - return NOTSUPPORTED; - } - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP() 0.2"); - - pdu = snmp_pdu_create(SNMP_MSG_GET); -/* Changed to snmp_parse_oid */ -/* read_objid(item->snmp_oid, anOID, &anOID_len);*/ - snmp_parse_oid(item->snmp_oid, anOID, &anOID_len); - -#if OTHER_METHODS - get_node("sysDescr.0", anOID, &anOID_len); - read_objid(".1.3.6.1.2.1.1.1.0", anOID, &anOID_len); - read_objid("system.sysDescr.0", anOID, &anOID_len); -#endif - - snmp_add_null_var(pdu, anOID, anOID_len); - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP() 0.3"); - - status = snmp_synch_response(ss, pdu, &response); - zabbix_log( LOG_LEVEL_DEBUG, "Status send [%d]", status); - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP() 0.4"); - - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP() 1"); - - if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) - { - - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP() 2"); -/* for(vars = response->variables; vars; vars = vars->next_variable) - { - print_variable(vars->name, vars->name_length, vars); - }*/ - - for(vars = response->variables; vars; vars = vars->next_variable) - { - int count=1; - zabbix_log( LOG_LEVEL_DEBUG, "AV loop(%d)", vars->type); - -/* if( (vars->type == ASN_INTEGER) ||*/ - if( (vars->type == ASN_UINTEGER)|| - (vars->type == ASN_COUNTER) || -#ifdef OPAQUE_SPECIAL_TYPES - (vars->type == ASN_UNSIGNED64) || -#endif - (vars->type == ASN_TIMETICKS) || - (vars->type == ASN_GAUGE) - ) - { -/* *result=(long)*vars->val.integer;*/ - /* - * This solves situation when large numbers are stored as negative values - * http://sourceforge.net/tracker/index.php?func=detail&aid=700145&group_id=23494&atid=378683 - */ - /*zbx_snprintf(result_str,sizeof(result_str),"%ld",(long)*vars->val.integer);*/ -/* zbx_snprintf(result_str,sizeof(result_str),"%lu",(long)*vars->val.integer);*/ - - /* Not correct. Returns huge values. */ -/* SET_UI64_RESULT(value, (zbx_uint64_t)*vars->val.integer);*/ - SET_UI64_RESULT(value, (unsigned long)*vars->val.integer); - zabbix_log( LOG_LEVEL_DEBUG, "OID [%s] Type [%d] UI64[" ZBX_FS_UI64 "]", - item->snmp_oid, - vars->type, - (zbx_uint64_t)*vars->val.integer); - zabbix_log( LOG_LEVEL_DEBUG, "OID [%s] Type [%d] ULONG[%lu]", - item->snmp_oid, - vars->type, - (zbx_uint64_t)(unsigned long)*vars->val.integer); - } - else if(vars->type == ASN_COUNTER64) - { - /* Incorrect code for 32 bit platforms */ -/* SET_UI64_RESULT(value, ((vars->val.counter64->high)<<32)+(vars->val.counter64->low));*/ - SET_UI64_RESULT(value, (((zbx_uint64_t)vars->val.counter64->high)<<32)+((zbx_uint64_t)vars->val.counter64->low)); - } - else if(vars->type == ASN_INTEGER -#define ASN_FLOAT (ASN_APPLICATION | 8) -#define ASN_DOUBLE (ASN_APPLICATION | 9) - -#ifdef OPAQUE_SPECIAL_TYPES - || (vars->type == ASN_INTEGER64) -#endif - ) - { - /* Negative integer values are converted to double */ - if(*vars->val.integer<0) - { - SET_DBL_RESULT(value, (double)*vars->val.integer); - } - else - { - SET_UI64_RESULT(value, (zbx_uint64_t)*vars->val.integer); - } - } -#ifdef OPAQUE_SPECIAL_TYPES - else if(vars->type == ASN_FLOAT) - { - SET_DBL_RESULT(value, *vars->val.floatVal); - } - else if(vars->type == ASN_DOUBLE) - { - SET_DBL_RESULT(value, *vars->val.doubleVal); - } -#endif - else if(vars->type == ASN_OCTET_STR) - { - if(item->value_type == ITEM_VALUE_TYPE_FLOAT) - { - SET_DBL_RESULT(value, strtod((char*)vars->val.string,0)); - } - else if(item->value_type != ITEM_VALUE_TYPE_STR) - { - zbx_snprintf(error,sizeof(error),"Cannot store SNMP string value (ASN_OCTET_STR) in item having numeric type"); - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - - ret = NOTSUPPORTED; - } - else - { - zabbix_log( LOG_LEVEL_DEBUG, "ASN_OCTET_STR [%s]", vars->val.string); - zabbix_log( LOG_LEVEL_DEBUG, "ASN_OCTET_STR [%d]", vars->val_len); - - p = malloc(1024); - if(p) - { - memset(p,0,1024); - snprint_value(p, 1023, vars->name, vars->name_length, vars); - /* Skip STRING: and STRING_HEX: */ - c=strchr(p,':'); - if(c==NULL) - { - SET_STR_RESULT(value, strdup(p)); - } - else - { - SET_STR_RESULT(value, strdup(c+1)); - } - zabbix_log( LOG_LEVEL_DEBUG, "ASN_OCTET_STR [%s]", p); - free(p); - } - else - { - zbx_snprintf(error,MAX_STRING_LEN-1,"Cannot allocate required memory"); - zabbix_log( LOG_LEVEL_ERR, "%s", error); - SET_MSG_RESULT(value, strdup(error)); - } - -/* p = malloc(vars->val_len+1); - if(p) - { - zabbix_log( LOG_LEVEL_WARNING, "Result [%s] len [%d]",vars->val.string,vars->val_len); - memcpy(p, vars->val.string, vars->val_len); - p[vars->val_len] = '\0'; - - SET_STR_RESULT(value, p); - } - else - { - zbx_snprintf(error,sizeof(error),"Cannot allocate required memory"); - zabbix_log( LOG_LEVEL_ERR, "%s", error); - SET_MSG_RESULT(value, strdup(error)); - }*/ - } - } - else if(vars->type == ASN_IPADDRESS) - { - if(item->value_type != ITEM_VALUE_TYPE_STR) - { - zbx_snprintf(error,sizeof(error),"Cannot store SNMP string value (ASN_IPADDRESS) in item having numeric type"); - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - ret = NOTSUPPORTED; - } - else - { - ip = vars->val.string; - SET_STR_RESULT(value, zbx_dsprintf(NULL, "%d.%d.%d.%d", - ip[0], - ip[1], - ip[2], - ip[3])); - } - } - else - { -/* count is not really used. Has to be removed */ - count++; - - zbx_snprintf(error,sizeof(error),"OID [%s] value #%d has unknow type [%X]", - item->snmp_oid, - count, - vars->type); - - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - - ret = NOTSUPPORTED; - } - } - } - else - { - if (status == STAT_SUCCESS) - { - zabbix_log( LOG_LEVEL_WARNING, "SNMP error in packet. Reason: %s\n", - snmp_errstring(response->errstat)); - if(response->errstat == SNMP_ERR_NOSUCHNAME) - { - zbx_snprintf(error,sizeof(error),"SNMP error [%s]", - snmp_errstring(response->errstat)); - - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - - ret=NOTSUPPORTED; - } - else - { - zbx_snprintf(error,sizeof(error),"SNMP error [%s]", - snmp_errstring(response->errstat)); - - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - - ret=NOTSUPPORTED; - } - } - else if(status == STAT_TIMEOUT) - { - zbx_snprintf(error,sizeof(error),"Timeout while connecting to [%s]", - session.peername); - -/* snmp_sess_perror("snmpget", ss);*/ - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - - ret = NETWORK_ERROR; - } - else - { - zbx_snprintf(error,sizeof(error),"SNMP error [%d]", - status); - - zabbix_log( LOG_LEVEL_ERR, "%s", - error); - SET_MSG_RESULT(value, strdup(error)); - - ret=NOTSUPPORTED; - } - } - - if (response) - { - snmp_free_pdu(response); - } - snmp_close(ss); - - SOCK_CLEANUP; - return ret; -} -#endif diff --git a/src/zabbix_proxy/poller/checks_snmp.h b/src/zabbix_proxy/poller/checks_snmp.h deleted file mode 100644 index c574c874..00000000 --- a/src/zabbix_proxy/poller/checks_snmp.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_CHECKS_SNMP_H -#define ZABBIX_CHECKS_SNMP_H - -#include "common.h" -#include "log.h" -#include "db.h" -#include "sysinfo.h" - -int get_value_snmp(DB_ITEM *item, AGENT_RESULT *value); - -#endif diff --git a/src/zabbix_proxy/poller/poller.c b/src/zabbix_proxy/poller/poller.c deleted file mode 100644 index 8435d15e..00000000 --- a/src/zabbix_proxy/poller/poller.c +++ /dev/null @@ -1,579 +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 "zlog.h" - -#include "../functions.h" -#include "../expression.h" -#include "poller.h" - -#include "db.h" -#include "sysinfo.h" - -#include "checks_agent.h" -#include "checks_aggregate.h" -#include "checks_external.h" -#include "checks_internal.h" -#include "checks_simple.h" -#include "checks_snmp.h" -#include "checks_db.h" - -#include "daemon.h" - -AGENT_RESULT result; - -int poller_type; -int poller_num; - -int get_value(DB_ITEM *item, AGENT_RESULT *result) -{ - int res=FAIL; - - struct sigaction phan; - - zabbix_log(LOG_LEVEL_DEBUG, "In get_value(key:%s)", - item->key); - - phan.sa_handler = &child_signal_handler; - sigemptyset(&phan.sa_mask); - phan.sa_flags = 0; - sigaction(SIGALRM, &phan, NULL); - - alarm(CONFIG_TIMEOUT); - - if(item->type == ITEM_TYPE_ZABBIX) - { - res=get_value_agent(item, result); - } - else if( (item->type == ITEM_TYPE_SNMPv1) || (item->type == ITEM_TYPE_SNMPv2c) || (item->type == ITEM_TYPE_SNMPv3)) - { -#ifdef HAVE_SNMP - res=get_value_snmp(item, result); -#else - zabbix_log(LOG_LEVEL_WARNING, "Support of SNMP parameters was not compiled in"); - zabbix_syslog("Support of SNMP parameters was not compiled in. Cannot process [%s:%s]", - item->host_name, - item->key); - res=NOTSUPPORTED; -#endif - } - else if(item->type == ITEM_TYPE_SIMPLE) - { - res=get_value_simple(item, result); - } - else if(item->type == ITEM_TYPE_INTERNAL) - { - res=get_value_internal(item, result); - } - else if(item->type == ITEM_TYPE_DB_MONITOR) - { - res=get_value_db(item, result); - } - else if(item->type == ITEM_TYPE_AGGREGATE) - { - res=get_value_aggregate(item, result); - } - else if(item->type == ITEM_TYPE_EXTERNAL) - { - res=get_value_external(item, result); - } - else - { - zabbix_log(LOG_LEVEL_WARNING, "Not supported item type:%d", - item->type); - zabbix_syslog("Not supported item type:%d", - item->type); - res=NOTSUPPORTED; - } - alarm(0); - - zabbix_log(LOG_LEVEL_DEBUG, "End get_value()"); - return res; -} - -static int get_minnextcheck(int now) -{ - DB_RESULT result; - DB_ROW row; - - int res; - -/* Host status 0 == MONITORED - 1 == NOT MONITORED - 2 == UNREACHABLE */ - if(poller_type == ZBX_POLLER_TYPE_UNREACHABLE) - { - result = DBselect("select count(*),min(nextcheck) as nextcheck from items i,hosts h where " ZBX_SQL_MOD(h.hostid,%d) "=%d and i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') and " ZBX_COND_NODEID "order by nextcheck", - CONFIG_UNREACHABLE_POLLER_FORKS, - poller_num-1, - now, - ITEM_STATUS_ACTIVE, - ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_HTTPTEST, - HOST_STATUS_MONITORED, - now, - SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, - LOCAL_NODE("h.hostid")); - } - else - { - if(CONFIG_REFRESH_UNSUPPORTED != 0) - { - result = DBselect("select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d,%d) and i.type not in (%d,%d,%d) and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s') and" ZBX_COND_NODEID, - HOST_STATUS_MONITORED, - now, - ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, - ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_HTTPTEST, - CONFIG_POLLER_FORKS, - poller_num-1, - SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, - LOCAL_NODE("h.hostid")); - } - else - { - result = DBselect("select count(*),min(nextcheck) from items i,hosts h where h.status=%d and h.disable_until<%d and h.errors_from=0 and h.hostid=i.hostid and i.status in (%d) and i.type not in (%d,%d,%d) and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s') and" ZBX_COND_NODEID, - HOST_STATUS_MONITORED, - now, - ITEM_STATUS_ACTIVE, - ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_HTTPTEST, - CONFIG_POLLER_FORKS, - poller_num-1, - SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, - LOCAL_NODE("h.hostid")); - } - } - - 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."); - res = FAIL; - } - else - { - if( atoi(row[0]) == 0) - { - res = FAIL; - } - else - { - res = atoi(row[1]); - } - } - DBfree_result(result); - - return res; -} - -/* Update special host's item - "status" */ -static void update_key_status(zbx_uint64_t hostid,int host_status) -{ -/* char value_str[MAX_STRING_LEN];*/ - AGENT_RESULT agent; - - DB_ITEM item; - DB_RESULT result; - DB_ROW row; - - int update; - - zabbix_log(LOG_LEVEL_DEBUG, "In update_key_status(" ZBX_FS_UI64 ",%d)", - hostid, - host_status); - - result = DBselect("select %s where h.hostid=i.hostid and h.hostid=" ZBX_FS_UI64 " and i.key_='%s'", - ZBX_SQL_ITEM_SELECT, - hostid, - SERVER_STATUS_KEY); - - row = DBfetch(result); - - if(row) - { - DBget_item_from_db(&item,row); - -/* Do not process new value for status, if previous status is the same */ - update = (item.lastvalue_null==1); - update = update || ((item.value_type == ITEM_VALUE_TYPE_FLOAT) &&(cmp_double(item.lastvalue_dbl, (double)host_status) == 1)); - update = update || ((item.value_type == ITEM_VALUE_TYPE_UINT64) &&(item.lastvalue_uint64 != host_status)); - - if(update) - { - init_result(&agent); - SET_UI64_RESULT(&agent, host_status); - process_new_value(&item,&agent); - free_result(&agent); - - update_triggers(item.itemid); - } - } - else - { - zabbix_log( LOG_LEVEL_DEBUG, "No items to update."); - } - - DBfree_result(result); -} - -/****************************************************************************** - * * - * Function: get_values * - * * - * Purpose: retrieve values of metrics from monitored hosts * - * * - * Parameters: * - * * - * Return value: * - * * - * Author: Alexei Vladishev * - * * - * Comments: always SUCCEED * - * * - ******************************************************************************/ -int get_values(void) -{ - DB_RESULT result; - DB_RESULT result2; - DB_ROW row; - DB_ROW row2; - - int now; - int delay; - int res; - DB_ITEM item; - AGENT_RESULT agent; - int stop=0; - - char *unreachable_hosts = NULL; - char tmp[MAX_STRING_LEN]; - - zabbix_log( LOG_LEVEL_DEBUG, "In get_values()"); - - now = time(NULL); - - zbx_snprintf(tmp,sizeof(tmp)-1,ZBX_FS_UI64,0); - unreachable_hosts=zbx_strdcat(unreachable_hosts,tmp); - - /* Poller for unreachable hosts */ - if(poller_type == ZBX_POLLER_TYPE_UNREACHABLE) - { - result = DBselect("select h.hostid,min(i.itemid) from hosts h,items i where " ZBX_SQL_MOD(h.hostid,%d) "=%d and i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from!=0 and h.hostid=i.hostid and i.key_ not in ('%s','%s','%s','%s') and " ZBX_COND_NODEID " group by h.hostid", - CONFIG_UNREACHABLE_POLLER_FORKS, - poller_num-1, - now, - ITEM_STATUS_ACTIVE, - ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_HTTPTEST, - HOST_STATUS_MONITORED, - now, - SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, - LOCAL_NODE("h.hostid")); - } - else - { - if(CONFIG_REFRESH_UNSUPPORTED != 0) - { - result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d,%d) and i.type not in (%d,%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s') and " ZBX_COND_NODEID " order by i.nextcheck", - ZBX_SQL_ITEM_SELECT, - now, - ITEM_STATUS_ACTIVE, ITEM_STATUS_NOTSUPPORTED, - ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_HTTPTEST, - HOST_STATUS_MONITORED, - now, - CONFIG_POLLER_FORKS, - poller_num-1, - SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, - LOCAL_NODE("h.hostid")); - } - else - { - result = DBselect("select %s where i.nextcheck<=%d and i.status in (%d) and i.type not in (%d,%d,%d) and h.status=%d and h.disable_until<=%d and h.errors_from=0 and h.hostid=i.hostid and " ZBX_SQL_MOD(i.itemid,%d) "=%d and i.key_ not in ('%s','%s','%s','%s') and " ZBX_COND_NODEID " order by i.nextcheck", - ZBX_SQL_ITEM_SELECT, - now, - ITEM_STATUS_ACTIVE, - ITEM_TYPE_TRAPPER, ITEM_TYPE_ZABBIX_ACTIVE, ITEM_TYPE_HTTPTEST, - HOST_STATUS_MONITORED, - now, - CONFIG_POLLER_FORKS, - poller_num-1, - SERVER_STATUS_KEY, SERVER_ICMPPING_KEY, SERVER_ICMPPINGSEC_KEY,SERVER_ZABBIXLOG_KEY, - LOCAL_NODE("h.hostid")); - } - } - - /* Do not stop when select is made by poller for unreachable hosts */ - while((row=DBfetch(result))&&(stop==0 || poller_type == ZBX_POLLER_TYPE_UNREACHABLE)) - { - /* This code is just to avoid compilation warining about use of uninitialized result2 */ - result2 = result; - /* */ - - /* Poller for unreachable hosts */ - if(poller_type == ZBX_POLLER_TYPE_UNREACHABLE) - { - result2 = DBselect("select %s where h.hostid=i.hostid and i.itemid=%s and" ZBX_COND_NODEID, - ZBX_SQL_ITEM_SELECT, - row[1], - LOCAL_NODE("h.hostid")); - - row2 = DBfetch(result2); - - if(!row2) - { - DBfree_result(result2); - continue; - } - DBget_item_from_db(&item,row2); - } - else - { - DBget_item_from_db(&item,row); - /* Skip unreachable hosts but do not break the loop. */ - if(uint64_in_list(unreachable_hosts,item.hostid) == SUCCEED) - { - zabbix_log( LOG_LEVEL_DEBUG, "Host " ZBX_FS_UI64 " is unreachable. Skipping [%s]", - item.hostid,item.key); - continue; - } - } - - init_result(&agent); - res = get_value(&item, &agent); - - DBbegin(); - - if(res == SUCCEED ) - { - - process_new_value(&item,&agent); - - if(HOST_AVAILABLE_TRUE != item.host_available) - { - zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", - item.host_name); - zabbix_syslog("Enabling host [%s]", - item.host_name); - - now = time(NULL); - DBupdate_host_availability(item.hostid,HOST_AVAILABLE_TRUE,now,agent.msg); - - update_key_status(item.hostid, HOST_STATUS_MONITORED); /* 0 */ - item.host_available=HOST_AVAILABLE_TRUE; - - stop=1; - } - if(item.host_errors_from!=0) - { - DBexecute("update hosts set errors_from=0 where hostid=" ZBX_FS_UI64, - item.hostid); - - stop=1; - } - update_triggers(item.itemid); - } - else if(res == NOTSUPPORTED || res == AGENT_ERROR) - { - now = time(NULL); - if(item.status == ITEM_STATUS_NOTSUPPORTED) - { - /* It is not correct */ -/* snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d, lastclock=%d where itemid=%d",calculate_item_nextcheck(item.itemid, CONFIG_REFRESH_UNSUPPORTED,now), now, item.itemid);*/ - DBexecute("update items set nextcheck=%d, lastclock=%d where itemid=" ZBX_FS_UI64, - CONFIG_REFRESH_UNSUPPORTED+now, - now, - item.itemid); - } - else - { - zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] is not supported by agent on host [%s] Old status [%d]", - item.key, - item.host_name, - item.status); - zabbix_syslog("Parameter [%s] is not supported by agent on host [%s]", - item.key, - item.host_name); - DBupdate_item_status_to_notsupported(item.itemid, agent.msg); - /* if(HOST_STATUS_UNREACHABLE == item.host_status)*/ - if(HOST_AVAILABLE_TRUE != item.host_available) - { - zabbix_log( LOG_LEVEL_WARNING, "Enabling host [%s]", - item.host_name); - zabbix_syslog("Enabling host [%s]", - item.host_name); - DBupdate_host_availability(item.hostid,HOST_AVAILABLE_TRUE,now,agent.msg); - update_key_status(item.hostid, HOST_STATUS_MONITORED); /* 0 */ - item.host_available=HOST_AVAILABLE_TRUE; - - stop=1; - } - } - } - else if(res == NETWORK_ERROR) - { - now = time(NULL); - - /* First error */ - if(item.host_errors_from==0) - { - zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: first network error, wait for %d seconds", - item.host_name, - CONFIG_UNREACHABLE_DELAY); - zabbix_syslog("Host [%s]: first network error, wait for %d seconds", - item.host_name, - CONFIG_UNREACHABLE_DELAY); - - item.host_errors_from=now; - DBexecute("update hosts set errors_from=%d,disable_until=%d where hostid=" ZBX_FS_UI64, - now, - now+CONFIG_UNREACHABLE_DELAY, - item.hostid); - - delay = MIN(4*item.delay, 300); - zabbix_log( LOG_LEVEL_WARNING, "Parameter [%s] will be checked after %d seconds on host [%s]", - item.key, - delay, - item.host_name); - DBexecute("update items set nextcheck=%d where itemid=" ZBX_FS_UI64, - now + delay, - item.itemid); - } - else - { - if(now-item.host_errors_from>CONFIG_UNREACHABLE_PERIOD) - { - zabbix_log( LOG_LEVEL_WARNING, "Host [%s] will be checked after %d seconds", - item.host_name, - CONFIG_UNAVAILABLE_DELAY); - zabbix_syslog("Host [%s] will be checked after %d seconds", - item.host_name, - CONFIG_UNAVAILABLE_DELAY); - - DBupdate_host_availability(item.hostid,HOST_AVAILABLE_FALSE,now,agent.msg); - update_key_status(item.hostid,HOST_AVAILABLE_FALSE); /* 2 */ - item.host_available=HOST_AVAILABLE_FALSE; - - DBexecute("update hosts set disable_until=%d where hostid=" ZBX_FS_UI64, - now+CONFIG_UNAVAILABLE_DELAY, - item.hostid); - } - /* Still unavailable, but won't change status to UNAVAILABLE yet */ - else - { - zabbix_log( LOG_LEVEL_WARNING, "Host [%s]: another network error, wait for %d seconds", - item.host_name, - CONFIG_UNREACHABLE_DELAY); - zabbix_syslog("Host [%s]: another network error, wait for %d seconds", - item.host_name, - CONFIG_UNREACHABLE_DELAY); - - DBexecute("update hosts set disable_until=%d where hostid=" ZBX_FS_UI64, - now+CONFIG_UNREACHABLE_DELAY, - item.hostid); - } - } - - zbx_snprintf(tmp,sizeof(tmp)-1,"," ZBX_FS_UI64,item.hostid); - unreachable_hosts=zbx_strdcat(unreachable_hosts,tmp); - -/* stop=1;*/ - } - else - { - zabbix_log( LOG_LEVEL_CRIT, "Unknown response code returned."); - assert(0==1); - } - /* Poller for unreachable hosts */ - if(poller_type == ZBX_POLLER_TYPE_UNREACHABLE) - { - /* We cannot freeit earlier because items has references to the structure */ - DBfree_result(result2); - } - free_result(&agent); - DBcommit(); - } - - zbx_free(unreachable_hosts); - - DBfree_result(result); - zabbix_log( LOG_LEVEL_DEBUG, "End get_values()"); - return SUCCEED; -} - -void main_poller_loop(int type, int num) -{ - int now; - int nextcheck,sleeptime; - - zabbix_log( LOG_LEVEL_DEBUG, "In main_poller_loop(type:%d,num:%d)", - type, - num); - - poller_type = type; - poller_num = num; - - DBconnect(ZBX_DB_CONNECT_NORMAL); - - for(;;) - { - zbx_setproctitle("poller [getting values]"); - - now=time(NULL); - get_values(); - - zabbix_log( LOG_LEVEL_DEBUG, "Spent %d seconds while updating values", - (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("poller [sleeping for %d seconds]", - sleeptime); - - sleep( sleeptime ); - } - else - { - zabbix_log( LOG_LEVEL_DEBUG, "No sleeping" ); - } - } -} diff --git a/src/zabbix_proxy/poller/poller.h b/src/zabbix_proxy/poller/poller.h deleted file mode 100644 index 6f08111c..00000000 --- a/src/zabbix_proxy/poller/poller.h +++ /dev/null @@ -1,40 +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_POLLER_H -#define ZABBIX_POLLER_H - -extern void signal_handler(int); -extern int server_num; - -extern int CONFIG_TIMEOUT; -extern int CONFIG_POLLER_FORKS; -extern int CONFIG_UNREACHABLE_POLLER_FORKS; -extern int CONFIG_UNAVAILABLE_DELAY; -extern int CONFIG_UNREACHABLE_PERIOD; -extern int CONFIG_UNREACHABLE_DELAY; - -void main_poller_loop(int type, int num); - -#include "db.h" -#include "sysinfo.h" - -int get_value(DB_ITEM *item, AGENT_RESULT *result); - -#endif diff --git a/src/zabbix_proxy/proxy.c b/src/zabbix_proxy/proxy.c index ddae1db0..e5b032fd 100644 --- a/src/zabbix_proxy/proxy.c +++ b/src/zabbix_proxy/proxy.c @@ -45,8 +45,7 @@ #include "../zabbix_server/httppoller/httppoller.h" #include "housekeeper/housekeeper.h" #include "../zabbix_server/pinger/pinger.h" -#include "poller/poller.h" -#include "poller/checks_snmp.h" +#include "../zabbix_server/poller/poller.h" #include "../zabbix_server/trapper/trapper.h" #include "proxyconfig/proxyconfig.h" @@ -483,10 +482,11 @@ int MAIN_ZABBIX_ENTRY(void) #ifdef HAVE_SNMP init_snmp("zabbix_server"); #endif /* HAVE_SNMP */ - zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Poller. SNMP:%s]", - server_num, - SNMP_FEATURE_STATUS); - main_poller_loop(ZBX_POLLER_TYPE_NORMAL, server_num); + + zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Poller. SNMP:"SNMP_FEATURE_STATUS"]", + server_num); + + main_poller_loop(ZBX_PROCESS_PROXY, ZBX_POLLER_TYPE_NORMAL, server_num); } else if (server_num <= CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS) { @@ -509,15 +509,16 @@ int MAIN_ZABBIX_ENTRY(void) zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Housekeeper]", server_num); main_housekeeper_loop(); - } else if(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) { #ifdef HAVE_SNMP init_snmp("zabbix_server"); #endif /* HAVE_SNMP */ - zabbix_log( LOG_LEVEL_WARNING, "server #%d started [Poller for unreachable hosts. SNMP:%s]", - server_num, - SNMP_FEATURE_STATUS); + + zabbix_log(LOG_LEVEL_WARNING, "server #%d started [Poller for unreachable hosts. SNMP:"SNMP_FEATURE_STATUS"]", + server_num); main_poller_loop(ZBX_POLLER_TYPE_UNREACHABLE, server_num - (CONFIG_POLLER_FORKS + CONFIG_TRAPPERD_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS)); |