diff options
| author | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2004-08-08 15:13:06 +0000 |
|---|---|---|
| committer | hugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082> | 2004-08-08 15:13:06 +0000 |
| commit | 3da79e6d41d7feb6eb2f6e61a1712fdeca4fb46c (patch) | |
| tree | 4474956ae190044aa59bf8c4be23d3131427ade2 | |
| parent | 37568f78334d10a6b9b68e9c96f0694fce3ae6b0 (diff) | |
| download | zabbix-3da79e6d41d7feb6eb2f6e61a1712fdeca4fb46c.tar.gz zabbix-3da79e6d41d7feb6eb2f6e61a1712fdeca4fb46c.tar.xz zabbix-3da79e6d41d7feb6eb2f6e61a1712fdeca4fb46c.zip | |
- added housekeeping of trends (Alexei)
- added column items.trends (Alexei)
- added escaping of SQL statements where needed (Alexei)
- added src/zabbix_sucker/checks_agent.[h,c] (Alexei)
- added src/zabbix_sucker/checks_internal.[h,c] (Alexei)
- added src/zabbix_sucker/checks_snmp.[h,c] (Alexei)
- added src/zabbix_sucker/checks_simple.[h,c] (Alexei)
git-svn-id: svn://svn.zabbix.com/trunk@1378 97f52cf1-0a1b-0410-bd0e-c28be96e8082
24 files changed, 770 insertions, 497 deletions
@@ -1,5 +1,12 @@ Changes for 1.1alpha1: + - added housekeeping of trends (Alexei) + - added column items.trends (Alexei) + - added escaping of SQL statements where needed (Alexei) + - added src/zabbix_sucker/checks_agent.[h,c] (Alexei) + - added src/zabbix_sucker/checks_internal.[h,c] (Alexei) + - added src/zabbix_sucker/checks_snmp.[h,c] (Alexei) + - added src/zabbix_sucker/checks_simple.[h,c] (Alexei) - send alert when trigger changes its value to TRUE for the first time (Alexei) - added support of zabbix[history_str] (Alexei) - use $_GET, $_POST, $_COOKIE to be PHP5-compatible. Thanks to Martin MOHNHAUP. (Alexei) @@ -34,6 +34,7 @@ TKOM: OTHER: + - use assert() for critical functions - check if simple checks (FTP, SMTP!) works correctly when host name (not IP) is used - add icons to a map by clicking mouse - implement fixed range for graphs (Y axis) @@ -55,21 +56,8 @@ Most of the signal handlers all need to delay or block signals to avoid signal r - check snprintf() from http://www.ijs.si/software/snprintf/. Better implementation of sprintf? -support of Oracle -I think that i found a bug in zabbix_suckerd. -I get the value :" The system's global status is normal. " from snmp. -but the log say me : - -023889:20040630:131408 Query::update items set -nextcheck=1088594108,prevvalue=lastvalue,lastvalue='The system's global status -is normal. ',lastclock=1088594048 where itemid=24893 -023889:20040630:131408 Query failed:You have an error in your SQL syntax near -'s global status is normal. ',lastclock=1088594048 where itemid=24893' at line -1 [1064] -(there is 3 ' on the update) - - in user administration, add many resources from a list (not by one ID) - availability report for day/week/month/etc - - add housekeeping for trends - check if items delay works - change location of Zabbix Manual in about.php - apply Igor patches for chart.php (calculation of MIN, MAX) diff --git a/create/mysql/schema.sql b/create/mysql/schema.sql index 121a0e38..5457249b 100644 --- a/create/mysql/schema.sql +++ b/create/mysql/schema.sql @@ -285,7 +285,8 @@ CREATE TABLE items ( description varchar(255) DEFAULT '' NOT NULL, key_ varchar(64) DEFAULT '' NOT NULL, delay int(4) DEFAULT '0' NOT NULL, - history int(4) DEFAULT '0' NOT NULL, + history int(4) DEFAULT '90' NOT NULL, + trends int(4) DEFAULT '365' NOT NULL, lastdelete int(4) DEFAULT '0' NOT NULL, nextcheck int(4) DEFAULT '0' NOT NULL, lastvalue varchar(255) DEFAULT NULL, diff --git a/create/postgresql/schema.sql b/create/postgresql/schema.sql index 0b7216c7..646f25a9 100644 --- a/create/postgresql/schema.sql +++ b/create/postgresql/schema.sql @@ -52,7 +52,8 @@ CREATE TABLE items ( description varchar(255) DEFAULT '' NOT NULL, key_ varchar(64) DEFAULT '' NOT NULL, delay int4 DEFAULT '0' NOT NULL, - history int4 DEFAULT '0' NOT NULL, + history int4 DEFAULT '90' NOT NULL, + trends int4 DEFAULT '365' NOT NULL, lastdelete int4 DEFAULT '0' NOT NULL, nextcheck int4 DEFAULT '0' NOT NULL, lastvalue varchar(255) DEFAULT NULL, diff --git a/frontends/php/about.php b/frontends/php/about.php index 739250d4..9a4e3038 100644 --- a/frontends/php/about.php +++ b/frontends/php/about.php @@ -40,7 +40,7 @@ </TR> <TR BGCOLOR=#DDDDDD> <TD ALIGN=LEFT> - <font face="Helvetica"><a href="http://www.zabbix.com/manual.php>"<?php echo S_LATEST_ZABBIX_MANUAL; ?></a></font><br> + <font face="Helvetica"><a href="http://www.zabbix.com/manual.php"><?php echo S_LATEST_ZABBIX_MANUAL; ?></a></font><br> </TD> <TD> <?php echo S_LATEST_ZABBIX_MANUAL_DETAILS; ?> diff --git a/frontends/php/include/forms.inc.php b/frontends/php/include/forms.inc.php index 19189f79..675de396 100644 --- a/frontends/php/include/forms.inc.php +++ b/frontends/php/include/forms.inc.php @@ -104,7 +104,8 @@ $host=@iif(isset($_GET["host"]),$_GET["host"],""); $port=@iif(isset($_GET["port"]),$_GET["port"],10000); $delay=@iif(isset($_GET["delay"]),$_GET["delay"],30); - $history=@iif(isset($_GET["history"]),$_GET["history"],365); + $history=@iif(isset($_GET["history"]),$_GET["history"],90); + $trends=@iif(isset($_GET["trends"]),$_GET["trends"],365); $status=@iif(isset($_GET["status"]),$_GET["status"],0); $type=@iif(isset($_GET["type"]),$_GET["type"],0); $snmp_community=@iif(isset($_GET["snmp_community"]),$_GET["snmp_community"],"public"); @@ -119,7 +120,7 @@ if(isset($_GET["register"])&&($_GET["register"] == "change")) { - $result=DBselect("select i.description, i.key_, h.host, h.port, i.delay, i.history, i.status, i.type, i.snmp_community,i.snmp_oid,i.value_type,i.trapper_hosts,i.snmp_port,i.units,i.multiplier,h.hostid,i.delta from items i,hosts h where i.itemid=".$_GET["itemid"]." and h.hostid=i.hostid"); + $result=DBselect("select i.description, i.key_, h.host, h.port, i.delay, i.history, i.status, i.type, i.snmp_community,i.snmp_oid,i.value_type,i.trapper_hosts,i.snmp_port,i.units,i.multiplier,h.hostid,i.delta,i.trends from items i,hosts h where i.itemid=".$_GET["itemid"]." and h.hostid=i.hostid"); $description=DBget_field($result,0,0); $key=DBget_field($result,0,1); @@ -138,6 +139,7 @@ $multiplier=DBget_field($result,0,14); $hostid=DBget_field($result,0,15); $delta=DBget_field($result,0,16); + $trends=DBget_field($result,0,17); } echo "<br>"; @@ -269,6 +271,11 @@ echo "<input class=\"biginput\" name=\"history\" value=\"$history\" size=8>"; show_table2_v_delimiter(); + echo nbsp("Keep trends (in days)"); + show_table2_h_delimiter(); + echo "<input class=\"biginput\" name=\"trends\" value=\"$trends\" size=8>"; + + show_table2_v_delimiter(); echo "Status"; show_table2_h_delimiter(); echo "<SELECT class=\"biginput\" NAME=\"status\" value=\"$status\" size=\"1\">"; diff --git a/frontends/php/include/local_en.inc.php b/frontends/php/include/local_en.inc.php index 90800db9..6a4b6a51 100644 --- a/frontends/php/include/local_en.inc.php +++ b/frontends/php/include/local_en.inc.php @@ -240,7 +240,7 @@ define("S_USE_THE_HOST_AS_A_TEMPLATE", "Use the host as a template"); define("S_DELETE_SELECTED_HOST_Q", "Delete selected host?"); -// config.php +// items.php define("S_CONFIGURATION_OF_ITEMS", "Configuration of items"); define("S_CONFIGURATION_OF_ITEMS_BIG", "CONFIGURATION OF ITEMS"); define("S_CANNOT_UPDATE_ITEM", "Cannot update item"); @@ -258,6 +258,7 @@ define("S_DESCRIPTION", "Description"); define("S_UPDATE_INTERVAL", "Update interval"); define("S_HISTORY", "History"); + define("S_TRENDS", "Trends"); define("S_SHORT_NAME", "Short name"); define("S_ZABBIX_AGENT", "Zabbix agent"); define("S_SNMPV1_AGENT", "SNMPv1 agent"); diff --git a/frontends/php/items.php b/frontends/php/items.php index fa515d58..91b6a41f 100644 --- a/frontends/php/items.php +++ b/frontends/php/items.php @@ -192,7 +192,7 @@ $lasthost=""; if(isset($_GET["hostid"])&&!isset($_GET["type"])) { - $result=DBselect("select h.host,i.key_,i.itemid,i.description,h.port,i.delay,i.history,i.lastvalue,i.lastclock,i.status,i.lastdelete,i.nextcheck,h.hostid,i.type from hosts h,items i where h.hostid=i.hostid and h.hostid=".$_GET["hostid"]." order by h.host,i.key_,i.description"); + $result=DBselect("select h.host,i.key_,i.itemid,i.description,h.port,i.delay,i.history,i.lastvalue,i.lastclock,i.status,i.lastdelete,i.nextcheck,h.hostid,i.type,i.trends from hosts h,items i where h.hostid=i.hostid and h.hostid=".$_GET["hostid"]." order by h.host,i.key_,i.description"); $col=0; while($row=DBfetch($result)) { @@ -219,6 +219,7 @@ echo "<TD WIDTH=10% NOSAVE><B>".S_DESCRIPTION."</B></TD>"; echo "<TD WIDTH=5% NOSAVE><B>".S_UPDATE_INTERVAL."</B></TD>"; echo "<TD WIDTH=5% NOSAVE><B>".S_HISTORY."</B></TD>"; + echo "<TD WIDTH=5% NOSAVE><B>".S_TRENDS."</B></TD>"; echo "<TD><B>".S_SHORT_NAME."</B></TD>"; echo "<TD WIDTH=5% NOSAVE><B>".S_TYPE."</B></TD>"; echo "<TD WIDTH=5% NOSAVE><B>".S_STATUS."</B></TD>"; @@ -237,6 +238,7 @@ echo "<TD>".$row["description"]."</TD>"; echo "<TD>".$row["delay"]."</TD>"; echo "<TD>".$row["history"]."</TD>"; + echo "<TD>".$row["trends"]."</TD>"; echo "<TD>".$row["host"].":".$row["key_"]."</TD>"; echo "<td align=center>"; diff --git a/frontends/php/maps.php b/frontends/php/maps.php index d6a56e0b..040fa7b2 100644 --- a/frontends/php/maps.php +++ b/frontends/php/maps.php @@ -75,6 +75,11 @@ show_table3_h_delimiter(); echo "<form name=\"form2\" method=\"get\" action=\"maps.php\">"; + if(isset($_GET["fullscreen"])) + { + echo "<input name=\"fullscreen\" type=\"hidden\" value=".$_GET["fullscreen"].">"; + } + if(isset($_GET["sysmapid"])&&($_GET["sysmapid"]==0)) { unset($_GET["sysmapid"]); diff --git a/include/db.h b/include/db.h index a43de0e9..c0544c0f 100644 --- a/include/db.h +++ b/include/db.h @@ -71,22 +71,23 @@ DB_HOST DB_ITEM { - int itemid; - int hostid; - int type; - char *description; - char *key; - char *host; - int useip; - char *ip; - char *shortname; - char *snmp_community; - char *snmp_oid; - int snmp_port; + int itemid; + int hostid; + int type; + char *description; + char *key; + char *host; + int useip; + char *ip; + char *shortname; + char *snmp_community; + char *snmp_oid; + int snmp_port; char *trapper_hosts; int port; int delay; int history; + int trends; double prevorgvalue; int prevorgvalue_null; double lastvalue; diff --git a/include/functions.c b/include/functions.c index 0412373c..f2ccde94 100644 --- a/include/functions.c +++ b/include/functions.c @@ -555,6 +555,7 @@ void update_functions(DB_ITEM *item) DB_RESULT *result; char sql[MAX_STRING_LEN]; char value[MAX_STRING_LEN]; + char value_esc[MAX_STRING_LEN]; int ret=SUCCEED; int i; @@ -583,7 +584,8 @@ void update_functions(DB_ITEM *item) zabbix_log( LOG_LEVEL_DEBUG, "Result:%f\n",value); if (ret == SUCCEED) { - snprintf(sql,sizeof(sql)-1,"update functions set lastvalue='%s' where itemid=%d and function='%s' and parameter='%s'", value, function.itemid, function.function, function.parameter ); + DBescape_string(value,value_esc,MAX_STRING_LEN); + snprintf(sql,sizeof(sql)-1,"update functions set lastvalue='%s' where itemid=%d and function='%s' and parameter='%s'", value_esc, function.itemid, function.function, function.parameter ); DBexecute(sql); } } @@ -1173,6 +1175,7 @@ void process_new_value(DB_ITEM *item,char *value) { int now; char sql[MAX_STRING_LEN]; + char value_esc[MAX_STRING_LEN]; double value_double; char *e; @@ -1225,7 +1228,8 @@ void process_new_value(DB_ITEM *item,char *value) { if((item->prevvalue_null == 1) || (strcmp(value,item->lastvalue_str) != 0) || (strcmp(item->prevvalue_str,item->lastvalue_str) != 0) ) { - snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",now+item->delay,value,now,item->itemid); + DBescape_string(value,value_esc,MAX_STRING_LEN); + snprintf(sql,sizeof(sql)-1,"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",now+item->delay,value_esc,now,item->itemid); item->prevvalue=item->lastvalue; item->lastvalue=value_double; item->prevvalue_str=item->lastvalue_str; diff --git a/src/zabbix_sucker/Makefile.in b/src/zabbix_sucker/Makefile.in index 35c71668..4b79f15c 100644 --- a/src/zabbix_sucker/Makefile.in +++ b/src/zabbix_sucker/Makefile.in @@ -5,7 +5,7 @@ LIBS = @LIBS@ @MYSQL_LFLAGS@ @PGSQL_LFLAGS@ @SNMP_LFLAGS@ all: - @CC@ -o ../../bin/zabbix_suckerd @CFLAGS@ -I../../include $(INCLUDE) zabbix_sucker.c ../../include/db.c ../../include/functions.c ../../include/expression.c ../../include/cfg.c ../../include/log.c ../../include/security.c ../../include/pid.c ../../include/email.c ../../include/snprintf.c ../zabbix_agent/sysinfo.c alerter.c pinger.c housekeeper.c -Wall $(LIBS) + @CC@ -o ../../bin/zabbix_suckerd @CFLAGS@ -I../../include $(INCLUDE) zabbix_sucker.c ../../include/db.c ../../include/functions.c ../../include/expression.c ../../include/cfg.c ../../include/log.c ../../include/security.c ../../include/pid.c ../../include/email.c ../../include/snprintf.c ../zabbix_agent/sysinfo.c alerter.c pinger.c housekeeper.c checks_simple.c checks_snmp.c checks_agent.c checks_internal.c -Wall $(LIBS) clean: rm -f *.o diff --git a/src/zabbix_sucker/checks_agent.c b/src/zabbix_sucker/checks_agent.c new file mode 100644 index 00000000..a654b25c --- /dev/null +++ b/src/zabbix_sucker/checks_agent.c @@ -0,0 +1,170 @@ +/* +** Zabbix +** Copyright (C) 2000,2001,2002,2003,2004 Alexei Vladishev +** +** 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_agent.h" + +int get_value_agent(double *result,char *result_str,DB_ITEM *item) +{ + int s; + int len; + static char c[MAX_STRING_LEN]; + char *e; + + struct hostent *hp; + + struct sockaddr_in servaddr_in; + + struct linger ling; + + zabbix_log( LOG_LEVEL_DEBUG, "%10s%25s", item->host, item->key ); + + servaddr_in.sin_family=AF_INET; + if(item->useip==1) + { + hp=gethostbyname(item->ip); + } + else + { + hp=gethostbyname(item->host); + } + + if(hp==NULL) + { + zabbix_log( LOG_LEVEL_WARNING, "gethostbyname() failed" ); + return NETWORK_ERROR; + } + + servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr; + + servaddr_in.sin_port=htons(item->port); + + s=socket(AF_INET,SOCK_STREAM,0); + + if(CONFIG_NOTIMEWAIT == 1) + { + ling.l_onoff=1; + ling.l_linger=0; + if(setsockopt(s,SOL_SOCKET,SO_LINGER,&ling,sizeof(ling))==-1) + { + zabbix_log(LOG_LEVEL_WARNING, "Cannot setsockopt SO_LINGER [%s]", strerror(errno)); + } + } + if(s == -1) + { + zabbix_log(LOG_LEVEL_WARNING, "Cannot create socket [%s]", + strerror(errno)); + return FAIL; + } + + if( connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 ) + { + switch (errno) + { + case EINTR: + zabbix_log( LOG_LEVEL_WARNING, "Timeout while connecting to [%s]",item->host ); + break; + case EHOSTUNREACH: + zabbix_log( LOG_LEVEL_WARNING, "No route to host [%s]",item->host ); + break; + default: + zabbix_log( LOG_LEVEL_WARNING, "Cannot connect to [%s] [%s]",item->host, strerror(errno)); + } + close(s); + return NETWORK_ERROR; + } + + snprintf(c,sizeof(c)-1,"%s\n",item->key); + zabbix_log(LOG_LEVEL_DEBUG, "Sending [%s]", c); + if( write(s,c,strlen(c)) == -1 ) + { + switch (errno) + { + case EINTR: + zabbix_log( LOG_LEVEL_WARNING, "Timeout while sending data to [%s]",item->host ); + break; + default: + zabbix_log( LOG_LEVEL_WARNING, "Error while sending data to [%s] [%s]",item->host, strerror(errno)); + } + close(s); + return FAIL; + } + + memset(c,0,MAX_STRING_LEN); + len=read(s,c,MAX_STRING_LEN); + if(len == -1) + { + switch (errno) + { + case EINTR: + zabbix_log( LOG_LEVEL_WARNING, "Timeout while receiving data from [%s]",item->host ); + break; + case ECONNRESET: + zabbix_log( LOG_LEVEL_WARNING, "Connection reset by peer. Host [%s] Parameter [%s]",item->host, item->key ); + close(s); + return NETWORK_ERROR; + default: + zabbix_log( LOG_LEVEL_WARNING, "Error while receiving data from [%s] [%s]",item->host, strerror(errno)); + } + close(s); + return FAIL; + } + + if( close(s)!=0 ) + { + zabbix_log(LOG_LEVEL_WARNING, "Problem with close [%s]", strerror(errno)); + } + zabbix_log(LOG_LEVEL_DEBUG, "Got string:[%d] [%s]", len, c); + if(len>0) + { + c[len-1]=0; + } + + *result=strtod(c,&e); + + /* The section should be improved */ + if( (*result==0) && (c==e) && (item->value_type==0) && (strcmp(c,"ZBX_NOTSUPPORTED") != 0) && (strcmp(c,"ZBX_ERROR") != 0) ) + { + zabbix_log( LOG_LEVEL_WARNING, "Got empty string from [%s]. Parameter [%s]", item->host, item->key); + zabbix_log( LOG_LEVEL_WARNING, "Assuming that agent dropped connection because of access permissions"); + return NETWORK_ERROR; + } + + /* Should be deleted in Zabbix 1.0 stable */ + if( cmp_double(*result,NOTSUPPORTED) == 0) + { + zabbix_log(LOG_LEVEL_DEBUG, "NOTSUPPORTED1 [%s]", c ); + return NOTSUPPORTED; + } + if( strcmp(c,"ZBX_NOTSUPPORTED") == 0) + { + zabbix_log(LOG_LEVEL_DEBUG, "NOTSUPPORTED2 [%s]", c ); + return NOTSUPPORTED; + } + if( strcmp(c,"ZBX_ERROR") == 0) + { + zabbix_log(LOG_LEVEL_DEBUG, "AGENT_ERROR [%s]", c ); + return AGENT_ERROR; + } + + strcpy(result_str,c); + + zabbix_log(LOG_LEVEL_DEBUG, "RESULT_STR [%s]", c ); + + return SUCCEED; +} diff --git a/src/zabbix_sucker/checks_agent.h b/src/zabbix_sucker/checks_agent.h new file mode 100644 index 00000000..c5e68c8d --- /dev/null +++ b/src/zabbix_sucker/checks_agent.h @@ -0,0 +1,47 @@ +/* +** Zabbix +** Copyright (C) 2000,2001,2002,2003,2004 Alexei Vladishev +** +** 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 <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <errno.h> + +#include "config.h" + +#ifdef HAVE_NETDB_H + #include <netdb.h> +#endif +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> + +#include "common.h" +#include "db.h" +#include "log.h" +#include "expression.h" + +extern int CONFIG_NOTIMEWAIT; + +extern int get_value_agent(double *result,char *result_str,DB_ITEM *item); + +#endif diff --git a/src/zabbix_sucker/checks_internal.c b/src/zabbix_sucker/checks_internal.c new file mode 100644 index 00000000..64512d17 --- /dev/null +++ b/src/zabbix_sucker/checks_internal.c @@ -0,0 +1,61 @@ +/* +** Zabbix +** Copyright (C) 2000,2001,2002,2003,2004 Alexei Vladishev +** +** 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_internal.h" + +int get_value_internal(double *result,char *result_str,DB_ITEM *item) +{ + if(strcmp(item->key,"zabbix[triggers]")==0) + { + *result=DBget_triggers_count(); + } + else if(strcmp(item->key,"zabbix[items]")==0) + { + *result=DBget_items_count(); + } + else if(strcmp(item->key,"zabbix[items_unsupported]")==0) + { + *result=DBget_items_unsupported_count(); + } + else if(strcmp(item->key,"zabbix[history]")==0) + { + *result=DBget_history_count(); + } + else if(strcmp(item->key,"zabbix[history_str]")==0) + { + *result=DBget_history_str_count(); + } + else if(strcmp(item->key,"zabbix[trends]")==0) + { + *result=DBget_trends_count(); + } + else if(strcmp(item->key,"zabbix[queue]")==0) + { + *result=DBget_queue_count(); + } + else + { + return NOTSUPPORTED; + } + + snprintf(result_str,MAX_STRING_LEN-1,"%f",*result); + + zabbix_log( LOG_LEVEL_DEBUG, "INTERNAL [%s] [%f]", result_str, *result); + return SUCCEED; +} diff --git a/src/zabbix_sucker/checks_internal.h b/src/zabbix_sucker/checks_internal.h new file mode 100644 index 00000000..ad32949e --- /dev/null +++ b/src/zabbix_sucker/checks_internal.h @@ -0,0 +1,34 @@ +/* +** Zabbix +** Copyright (C) 2000,2001,2002,2003,2004 Alexei Vladishev +** +** 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 <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "common.h" +#include "config.h" +#include "db.h" +#include "log.h" + +extern int get_value_internal(double *result,char *result_str,DB_ITEM *item); + +#endif diff --git a/src/zabbix_sucker/checks_simple.c b/src/zabbix_sucker/checks_simple.c new file mode 100644 index 00000000..0ae7bb1d --- /dev/null +++ b/src/zabbix_sucker/checks_simple.c @@ -0,0 +1,73 @@ +/* +** Zabbix +** Copyright (C) 2000,2001,2002,2003,2004 Alexei Vladishev +** +** 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(double *result,char *result_str,DB_ITEM *item) +{ + char *e,*t; + char c[MAX_STRING_LEN]; + char s[MAX_STRING_LEN]; + int ret = SUCCEED; + + /* The code is ugly. I would rewrite it. Alexei. */ + /* Assumption: host name does not contain '_perf' */ + if(NULL == strstr(item->key,"_perf")) + { + if(item->useip==1) + { + snprintf(c,sizeof(c)-1,"check_service[%s,%s]",item->key,item->ip); + } + else + { + snprintf(c,sizeof(c)-1,"check_service[%s,%s]",item->key,item->host); + } + } + else + { + strscpy(s,item->key); + t=strstr(s,"_perf"); + t[0]=0; + + if(item->useip==1) + { + snprintf(c,sizeof(c)-1,"check_service_perf[%s,%s]",s,item->ip); + } + else + { + snprintf(c,sizeof(c)-1,"check_service_perf[%s,%s]",s,item->host); + } + } + + + process(c,result_str); + + if(strcmp(result_str,"ZBX_NOTSUPPORTED\n") == 0) + { + zabbix_log( LOG_LEVEL_WARNING, "Simple check [%s] is not supported", c); + ret = NOTSUPPORTED; + } + else + { + *result=strtod(result_str,&e); + } + + zabbix_log( LOG_LEVEL_DEBUG, "SIMPLE [%s] [%s] [%f] RET [%d]", c, result_str, *result, ret); + return ret; +} diff --git a/src/zabbix_sucker/checks_simple.h b/src/zabbix_sucker/checks_simple.h new file mode 100644 index 00000000..243a2b6c --- /dev/null +++ b/src/zabbix_sucker/checks_simple.h @@ -0,0 +1,36 @@ +/* +** Zabbix +** Copyright (C) 2000,2001,2002,2003,2004 Alexei Vladishev +** +** 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 <string.h> +#include <stdio.h> +#include <stdlib.h> + +#include "common.h" +#include "config.h" +#include "db.h" +#include "log.h" + +#include "../zabbix_agent/sysinfo.h" + +extern int get_value_simple(double *result,char *result_str,DB_ITEM *item); + +#endif diff --git a/src/zabbix_sucker/checks_snmp.c b/src/zabbix_sucker/checks_snmp.c new file mode 100644 index 00000000..509e7cf9 --- /dev/null +++ b/src/zabbix_sucker/checks_snmp.c @@ -0,0 +1,215 @@ +/* +** Zabbix +** Copyright (C) 2000,2001,2002,2003,2004 Alexei Vladishev +** +** 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(int version,double *result,char *result_str,DB_ITEM *item)*/ +int get_value_snmp(double *result,char *result_str,DB_ITEM *item) +{ + + #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; + + unsigned char *ip; + + int ret=SUCCEED; + + zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP()"); + + assert((item->type == ITEM_TYPE_SNMPv1)||(item->type == ITEM_TYPE_SNMPv2c)); + + 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 + { + zabbix_log( LOG_LEVEL_ERR, "Error in get_value_SNMP. Wrong item type [%d]. Must be SNMP.", item->type); + return FAIL; + } + + + if(item->useip == 1) + { + #ifdef NEW_APPROACH + snprintf(temp,sizeof(temp)-1,"%s:%d", item->ip, item->snmp_port); + session.peername = temp; + #else + session.peername = item->ip; + #endif + } + else + { + #ifdef NEW_APPROACH + snprintf(temp, sizeof(temp)-1, "%s:%d", item->host, item->snmp_port); + session.peername = temp; + #else + session.peername = item->host; + #endif + } + session.community = item->snmp_community; + session.community_len = strlen(session.community); + + zabbix_log( LOG_LEVEL_DEBUG, "SNMP [%s@%s:%d]",session.community, session.peername, session.remote_port); + zabbix_log( LOG_LEVEL_DEBUG, "OID [%s]", item->snmp_oid); + + SOCK_STARTUP; + ss = snmp_open(&session); + + if(ss == NULL) + { + SOCK_CLEANUP; + zabbix_log( LOG_LEVEL_WARNING, "Error: snmp_open()"); + return FAIL; + } + zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP() 0.2"); + + pdu = snmp_pdu_create(SNMP_MSG_GET); + read_objid(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()"); + + if( (vars->type == ASN_INTEGER) || + (vars->type == ASN_UINTEGER)|| + (vars->type == ASN_COUNTER) || + (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 + */ + /*sprintf(result_str,"%ld",(long)*vars->val.integer);*/ + snprintf(result_str,MAX_STRING_LEN-1,"%lu",(long)*vars->val.integer); + } + else if(vars->type == ASN_OCTET_STR) + { + memcpy(result_str,vars->val.string,vars->val_len); + result_str[vars->val_len] = '\0'; + if(item->type == 0) + { + ret = NOTSUPPORTED; + } + } + else if(vars->type == ASN_IPADDRESS) + { + ip = vars->val.string; + snprintf(result_str,MAX_STRING_LEN-1,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); + if(item->type == 0) + { + ret = NOTSUPPORTED; + } + } + else + { + zabbix_log( LOG_LEVEL_WARNING,"value #%d has unknow type", count++); + ret = NOTSUPPORTED; + } + } + } + else + { + if (status == STAT_SUCCESS) + { + zabbix_log( LOG_LEVEL_WARNING, "Error in packet\nReason: %s\n", + snmp_errstring(response->errstat)); + if(response->errstat == SNMP_ERR_NOSUCHNAME) + { + ret=NOTSUPPORTED; + } + else + { + ret=FAIL; + } + } + else if(status == STAT_TIMEOUT) + { + zabbix_log( LOG_LEVEL_WARNING, "Timeout while connecting to [%s]", + session.peername); + snmp_sess_perror("snmpget", ss); + ret = NETWORK_ERROR; + } + else + { + zabbix_log( LOG_LEVEL_WARNING, "Error [%d]", + status); + snmp_sess_perror("snmpget", ss); + ret=FAIL; + } + } + + if (response) + { + snmp_free_pdu(response); + } + snmp_close(ss); + + SOCK_CLEANUP; + return ret; +} +#endif diff --git a/src/zabbix_sucker/checks_snmp.h b/src/zabbix_sucker/checks_snmp.h new file mode 100644 index 00000000..aabfdb57 --- /dev/null +++ b/src/zabbix_sucker/checks_snmp.h @@ -0,0 +1,50 @@ +/* +** Zabbix +** Copyright (C) 2000,2001,2002,2003,2004 Alexei Vladishev +** +** 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 <string.h> +#include <stdio.h> +#include <stdlib.h> +#include <assert.h> + +#include "common.h" +#include "config.h" +#include "log.h" +#include "db.h" + +/* NET-SNMP is used */ +#ifdef HAVE_NETSNMP + #include <net-snmp/net-snmp-config.h> + #include <net-snmp/net-snmp-includes.h> +#endif + +/* Required for SNMP support*/ +#ifdef HAVE_UCDSNMP + #include <ucd-snmp/ucd-snmp-config.h> + #include <ucd-snmp/ucd-snmp-includes.h> + #include <ucd-snmp/system.h> +#endif + + +/*int get_value_SNMP(int version,double *result,char *result_str,DB_ITEM *item);*/ +int get_value_snmp(double *result,char *result_str,DB_ITEM *item); + +#endif diff --git a/src/zabbix_sucker/housekeeper.c b/src/zabbix_sucker/housekeeper.c index 0d92f785..eba04c60 100644 --- a/src/zabbix_sucker/housekeeper.c +++ b/src/zabbix_sucker/housekeeper.c @@ -86,7 +86,7 @@ int housekeeping_hosts(void) return SUCCEED; } -int housekeeping_history(int now) +int housekeeping_history_and_trends(int now) { char sql[MAX_STRING_LEN]; DB_ITEM item; @@ -96,7 +96,7 @@ int housekeeping_history(int now) int i; /* How lastdelete is used ??? */ - snprintf(sql,sizeof(sql)-1,"select itemid,lastdelete,history,delay from items where lastdelete<=%d", now); + snprintf(sql,sizeof(sql)-1,"select itemid,lastdelete,history,delay,trends from items where lastdelete<=%d", now); result = DBselect(sql); for(i=0;i<DBnum_rows(result);i++) @@ -105,24 +105,36 @@ int housekeeping_history(int now) item.lastdelete=atoi(DBget_field(result,i,1)); item.history=atoi(DBget_field(result,i,2)); item.delay=atoi(DBget_field(result,i,3)); + item.trends=atoi(DBget_field(result,i,4)); if(item.delay==0) { item.delay=1; } +/* Delete HISTORY */ #ifdef HAVE_MYSQL snprintf(sql,sizeof(sql)-1,"delete from history where itemid=%d and clock<%d limit %d",item.itemid,now-24*3600*item.history,2*CONFIG_HOUSEKEEPING_FREQUENCY*3600/item.delay); #else snprintf(sql,sizeof(sql)-1,"delete from history where itemid=%d and clock<%d",item.itemid,now-24*3600*item.history); #endif DBexecute(sql); + +/* Delete HISTORY_STR */ #ifdef HAVE_MYSQL snprintf(sql,sizeof(sql)-1,"delete from history_str where itemid=%d and clock<%d limit %d",item.itemid,now-24*3600*item.history,2*CONFIG_HOUSEKEEPING_FREQUENCY*3600/item.delay); #else snprintf(sql,sizeof(sql)-1,"delete from history_str where itemid=%d and clock<%d",item.itemid,now-24*3600*item.history); #endif DBexecute(sql); + +/* Delete HISTORY_TRENDS */ +#ifdef HAVE_MYSQL + snprintf(sql,sizeof(sql)-1,"delete from trends where itemid=%d and clock<%d limit %d",item.itemid,now-24*3600*item.trends,2*CONFIG_HOUSEKEEPING_FREQUENCY*3600/item.delay); +#else + snprintf(sql,sizeof(sql)-1,"delete from trends where itemid=%d and clock<%d",item.itemid,now-24*3600*item.trends); +#endif + DBexecute(sql); snprintf(sql,sizeof(sql)-1,"update items set lastdelete=%d where itemid=%d",now,item.itemid); DBexecute(sql); @@ -231,7 +243,7 @@ int main_housekeeper_loop() #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("housekeeper [removing old values]"); #endif - housekeeping_history(now); + housekeeping_history_and_trends(now); #ifdef HAVE_FUNCTION_SETPROCTITLE setproctitle("housekeeper [removing old alarms]"); diff --git a/src/zabbix_sucker/zabbix_sucker.c b/src/zabbix_sucker/zabbix_sucker.c index 8b7e72f6..e5d95913 100644 --- a/src/zabbix_sucker/zabbix_sucker.c +++ b/src/zabbix_sucker/zabbix_sucker.c @@ -21,17 +21,10 @@ #include <stdio.h> #include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> #include <sys/stat.h> -#include <sys/socket.h> -#include <netinet/in.h> #include <string.h> -#ifdef HAVE_NETDB_H - #include <netdb.h> -#endif /* Required for getpwuid */ #include <pwd.h> @@ -41,19 +34,6 @@ #include <time.h> -/* NET-SNMP is used */ -#ifdef HAVE_NETSNMP - #include <net-snmp/net-snmp-config.h> - #include <net-snmp/net-snmp-includes.h> -#endif - -/* Required for SNMP support*/ -#ifdef HAVE_UCDSNMP - #include <ucd-snmp/ucd-snmp-config.h> - #include <ucd-snmp/ucd-snmp-includes.h> - #include <ucd-snmp/system.h> -#endif - #include "cfg.h" #include "pid.h" #include "db.h" @@ -62,11 +42,16 @@ #include "common.h" #include "functions.h" #include "expression.h" + #include "alerter.h" #include "pinger.h" #include "housekeeper.h" +#include "housekeeper.h" -#include "../zabbix_agent/sysinfo.h" +#include "checks_agent.h" +#include "checks_internal.h" +#include "checks_simple.h" +#include "checks_snmp.h" static pid_t *pids=NULL; @@ -260,430 +245,6 @@ void init_config(void) } } -#ifdef HAVE_SNMP -int get_value_SNMP(int version,double *result,char *result_str,DB_ITEM *item) -{ - - #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; - - unsigned char *ip; - - int ret=SUCCEED; - - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP()"); - - snmp_sess_init( &session ); - session.version = version; - session.remote_port = item->snmp_port; - - - if(item->useip == 1) - { - #ifdef NEW_APPROACH - snprintf(temp,sizeof(temp)-1,"%s:%d", item->ip, item->snmp_port); - session.peername = temp; - #else - session.peername = item->ip; - #endif - } - else - { - #ifdef NEW_APPROACH - snprintf(temp, sizeof(temp)-1, "%s:%d", item->host, item->snmp_port); - session.peername = temp; - #else - session.peername = item->host; - #endif - } - session.community = item->snmp_community; - session.community_len = strlen(session.community); - - zabbix_log( LOG_LEVEL_DEBUG, "SNMP [%s@%s:%d]",session.community, session.peername, session.remote_port); - zabbix_log( LOG_LEVEL_DEBUG, "OID [%s]", item->snmp_oid); - - SOCK_STARTUP; - ss = snmp_open(&session); - - if(ss == NULL) - { - SOCK_CLEANUP; - zabbix_log( LOG_LEVEL_WARNING, "Error: snmp_open()"); - return FAIL; - } - zabbix_log( LOG_LEVEL_DEBUG, "In get_value_SNMP() 0.2"); - - pdu = snmp_pdu_create(SNMP_MSG_GET); - read_objid(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()"); - - if( (vars->type == ASN_INTEGER) || - (vars->type == ASN_UINTEGER)|| - (vars->type == ASN_COUNTER) || - (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 - */ - /*sprintf(result_str,"%ld",(long)*vars->val.integer);*/ - snprintf(result_str,MAX_STRING_LEN-1,"%lu",(long)*vars->val.integer); - } - else if(vars->type == ASN_OCTET_STR) - { - memcpy(result_str,vars->val.string,vars->val_len); - result_str[vars->val_len] = '\0'; - if(item->type == 0) - { - ret = NOTSUPPORTED; - } - } - else if(vars->type == ASN_IPADDRESS) - { - ip = vars->val.string; - snprintf(result_str,MAX_STRING_LEN-1,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]); - if(item->type == 0) - { - ret = NOTSUPPORTED; - } - } - else - { - zabbix_log( LOG_LEVEL_WARNING,"value #%d has unknow type", count++); - ret = NOTSUPPORTED; - } - } - } - else - { - if (status == STAT_SUCCESS) - { - zabbix_log( LOG_LEVEL_WARNING, "Error in packet\nReason: %s\n", - snmp_errstring(response->errstat)); - if(response->errstat == SNMP_ERR_NOSUCHNAME) - { - ret=NOTSUPPORTED; - } - else - { - ret=FAIL; - } - } - else if(status == STAT_TIMEOUT) - { - zabbix_log( LOG_LEVEL_WARNING, "Timeout while connecting to [%s]", - session.peername); - snmp_sess_perror("snmpget", ss); - ret = NETWORK_ERROR; - } - else - { - zabbix_log( LOG_LEVEL_WARNING, "Error [%d]", - status); - snmp_sess_perror("snmpget", ss); - ret=FAIL; - } - } - - if (response) - { - snmp_free_pdu(response); - } - snmp_close(ss); - - SOCK_CLEANUP; - return ret; -} -#endif - -int get_value_SIMPLE(double *result,char *result_str,DB_ITEM *item) -{ - char *e,*t; - char c[MAX_STRING_LEN]; - char s[MAX_STRING_LEN]; - int ret = SUCCEED; - - /* The code is ugly. I would rewrite it. Alexei. */ - /* Assumption: host name does not contain '_perf' */ - if(NULL == strstr(item->key,"_perf")) - { - if(item->useip==1) - { - snprintf(c,sizeof(c)-1,"check_service[%s,%s]",item->key,item->ip); - } - else - { - snprintf(c,sizeof(c)-1,"check_service[%s,%s]",item->key,item->host); - } - } - else - { - strscpy(s,item->key); - t=strstr(s,"_perf"); - t[0]=0; - - if(item->useip==1) - { - snprintf(c,sizeof(c)-1,"check_service_perf[%s,%s]",s,item->ip); - } - else - { - snprintf(c,sizeof(c)-1,"check_service_perf[%s,%s]",s,item->host); - } - } - - - process(c,result_str); - - if(strcmp(result_str,"ZBX_NOTSUPPORTED\n") == 0) - { - zabbix_log( LOG_LEVEL_WARNING, "Simple check [%s] is not supported", c); - ret = NOTSUPPORTED; - } - else - { - *result=strtod(result_str,&e); - } - - zabbix_log( LOG_LEVEL_DEBUG, "SIMPLE [%s] [%s] [%f] RET [%d]", c, result_str, *result, ret); - return ret; -} - -int get_value_INTERNAL(double *result,char *result_str,DB_ITEM *item) -{ - if(strcmp(item->key,"zabbix[triggers]")==0) - { - *result=DBget_triggers_count(); - } - else if(strcmp(item->key,"zabbix[items]")==0) - { - *result=DBget_items_count(); - } - else if(strcmp(item->key,"zabbix[items_unsupported]")==0) - { - *result=DBget_items_unsupported_count(); - } - else if(strcmp(item->key,"zabbix[history]")==0) - { - *result=DBget_history_count(); - } - else if(strcmp(item->key,"zabbix[history_str]")==0) - { - *result=DBget_history_str_count(); - } - else if(strcmp(item->key,"zabbix[trends]")==0) - { - *result=DBget_trends_count(); - } - else if(strcmp(item->key,"zabbix[queue]")==0) - { - *result=DBget_queue_count(); - } - else - { - return NOTSUPPORTED; - } - - snprintf(result_str,MAX_STRING_LEN-1,"%f",*result); - - zabbix_log( LOG_LEVEL_DEBUG, "INTERNAL [%s] [%f]", result_str, *result); - return SUCCEED; -} - -int get_value_zabbix(double *result,char *result_str,DB_ITEM *item) -{ - int s; - int len; - static char c[MAX_STRING_LEN]; - char *e; - - struct hostent *hp; - - struct sockaddr_in servaddr_in; - - struct linger ling; - - zabbix_log( LOG_LEVEL_DEBUG, "%10s%25s", item->host, item->key ); - - servaddr_in.sin_family=AF_INET; - if(item->useip==1) - { - hp=gethostbyname(item->ip); - } - else - { - hp=gethostbyname(item->host); - } - - if(hp==NULL) - { - zabbix_log( LOG_LEVEL_WARNING, "gethostbyname() failed" ); - return NETWORK_ERROR; - } - - servaddr_in.sin_addr.s_addr=((struct in_addr *)(hp->h_addr))->s_addr; - - servaddr_in.sin_port=htons(item->port); - - s=socket(AF_INET,SOCK_STREAM,0); - - if(CONFIG_NOTIMEWAIT == 1) - { - ling.l_onoff=1; - ling.l_linger=0; - if(setsockopt(s,SOL_SOCKET,SO_LINGER,&ling,sizeof(ling))==-1) - { - zabbix_log(LOG_LEVEL_WARNING, "Cannot setsockopt SO_LINGER [%s]", strerror(errno)); - } - } - if(s == -1) - { - zabbix_log(LOG_LEVEL_WARNING, "Cannot create socket [%s]", - strerror(errno)); - return FAIL; - } - - if( connect(s,(struct sockaddr *)&servaddr_in,sizeof(struct sockaddr_in)) == -1 ) - { - switch (errno) - { - case EINTR: - zabbix_log( LOG_LEVEL_WARNING, "Timeout while connecting to [%s]",item->host ); - break; - case EHOSTUNREACH: - zabbix_log( LOG_LEVEL_WARNING, "No route to host [%s]",item->host ); - break; - default: - zabbix_log( LOG_LEVEL_WARNING, "Cannot connect to [%s] [%s]",item->host, strerror(errno)); - } - close(s); - return NETWORK_ERROR; - } - - snprintf(c,sizeof(c)-1,"%s\n",item->key); - zabbix_log(LOG_LEVEL_DEBUG, "Sending [%s]", c); - if( write(s,c,strlen(c)) == -1 ) - { - switch (errno) - { - case EINTR: - zabbix_log( LOG_LEVEL_WARNING, "Timeout while sending data to [%s]",item->host ); - break; - default: - zabbix_log( LOG_LEVEL_WARNING, "Error while sending data to [%s] [%s]",item->host, strerror(errno)); - } - close(s); - return FAIL; - } - - memset(c,0,MAX_STRING_LEN); - len=read(s,c,MAX_STRING_LEN); - if(len == -1) - { - switch (errno) - { - case EINTR: - zabbix_log( LOG_LEVEL_WARNING, "Timeout while receiving data from [%s]",item->host ); - break; - case ECONNRESET: - zabbix_log( LOG_LEVEL_WARNING, "Connection reset by peer. Host [%s] Parameter [%s]",item->host, item->key ); - close(s); - return NETWORK_ERROR; - default: - zabbix_log( LOG_LEVEL_WARNING, "Error while receiving data from [%s] [%s]",item->host, strerror(errno)); - } - close(s); - return FAIL; - } - - if( close(s)!=0 ) - { - zabbix_log(LOG_LEVEL_WARNING, "Problem with close [%s]", strerror(errno)); - } - zabbix_log(LOG_LEVEL_DEBUG, "Got string:[%d] [%s]", len, c); - if(len>0) - { - c[len-1]=0; - } - - *result=strtod(c,&e); - - /* The section should be improved */ - if( (*result==0) && (c==e) && (item->value_type==0) && (strcmp(c,"ZBX_NOTSUPPORTED") != 0) && (strcmp(c,"ZBX_ERROR") != 0) ) - { - zabbix_log( LOG_LEVEL_WARNING, "Got empty string from [%s]. Parameter [%s]", item->host, item->key); - zabbix_log( LOG_LEVEL_WARNING, "Assuming that agent dropped connection because of access permissions"); - return NETWORK_ERROR; - } - - /* Should be deleted in Zabbix 1.0 stable */ - if( cmp_double(*result,NOTSUPPORTED) == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "NOTSUPPORTED1 [%s]", c ); - return NOTSUPPORTED; - } - if( strcmp(c,"ZBX_NOTSUPPORTED") == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "NOTSUPPORTED2 [%s]", c ); - return NOTSUPPORTED; - } - if( strcmp(c,"ZBX_ERROR") == 0) - { - zabbix_log(LOG_LEVEL_DEBUG, "AGENT_ERROR [%s]", c ); - return AGENT_ERROR; - } - - strcpy(result_str,c); - - zabbix_log(LOG_LEVEL_DEBUG, "RESULT_STR [%s]", c ); - - return SUCCEED; -} - int get_value(double *result,char *result_str,DB_ITEM *item) { int res=FAIL; @@ -699,21 +260,12 @@ int get_value(double *result,char *result_str,DB_ITEM *item) if(item->type == ITEM_TYPE_ZABBIX) { - res=get_value_zabbix(result,result_str,item); - } - else if(item->type == ITEM_TYPE_SNMPv1) - { -#ifdef HAVE_SNMP - res=get_value_SNMP(SNMP_VERSION_1,result,result_str,item); -#else - zabbix_log(LOG_LEVEL_WARNING, "Support of SNMP parameters was no compiled in"); - res=NOTSUPPORTED; -#endif + res=get_value_agent(result,result_str,item); } - else if(item->type == ITEM_TYPE_SNMPv2c) + else if( (item->type == ITEM_TYPE_SNMPv1) || (item->type == ITEM_TYPE_SNMPv2c)) { #ifdef HAVE_SNMP - res=get_value_SNMP(SNMP_VERSION_2c,result,result_str,item); + res=get_value_snmp(result,result_str,item); #else zabbix_log(LOG_LEVEL_WARNING, "Support of SNMP parameters was no compiled in"); res=NOTSUPPORTED; @@ -721,11 +273,11 @@ int get_value(double *result,char *result_str,DB_ITEM *item) } else if(item->type == ITEM_TYPE_SIMPLE) { - res=get_value_SIMPLE(result,result_str,item); + res=get_value_simple(result,result_str,item); } else if(item->type == ITEM_TYPE_INTERNAL) { - res=get_value_INTERNAL(result,result_str,item); + res=get_value_internal(result,result_str,item); } else { diff --git a/upgrades/dbpatches/1.0_to_1.1alpha1/mysql/patch.sql b/upgrades/dbpatches/1.0_to_1.1alpha1/mysql/patch.sql index c44a8b65..bce92c94 100644 --- a/upgrades/dbpatches/1.0_to_1.1alpha1/mysql/patch.sql +++ b/upgrades/dbpatches/1.0_to_1.1alpha1/mysql/patch.sql @@ -1,3 +1,5 @@ alter table users add url varchar(255) DEFAULT '' NOT NULL; alter table sysmaps add use_background int(4) DEFAULT 0 NOT NULL; alter table sysmaps add background longblob DEFAULT '' NOT NULL; + +alter table items add trends int(4) DEFAULT '365' NOT NULL; diff --git a/upgrades/dbpatches/1.0_to_1.1alpha1/postgresql/patch.sql b/upgrades/dbpatches/1.0_to_1.1alpha1/postgresql/patch.sql index 15b41af3..b25a4ba6 100644 --- a/upgrades/dbpatches/1.0_to_1.1alpha1/postgresql/patch.sql +++ b/upgrades/dbpatches/1.0_to_1.1alpha1/postgresql/patch.sql @@ -1 +1,5 @@ alter table users add url varchar(255) DEFAULT '' NOT NULL; +alter table sysmaps add use_background int4 DEFAULT 0 NOT NULL; +alter table sysmaps add background blob DEFAULT '' NOT NULL; + +alter table items add trends int4 DEFAULT '365' NOT NULL; |
