summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2002-04-07 18:22:26 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2002-04-07 18:22:26 +0000
commitf137ecdab820e8b918c488145fc75a009f7d050d (patch)
tree49c391c81e042c5eb44de7188fac37872366f82e
parent793cc2e085dc67097d1521d58052033cfdcbfef3 (diff)
downloadzabbix-f137ecdab820e8b918c488145fc75a009f7d050d.tar.gz
zabbix-f137ecdab820e8b918c488145fc75a009f7d050d.tar.xz
zabbix-f137ecdab820e8b918c488145fc75a009f7d050d.zip
- improved update_triggers() (Alexei)
- fixed get_lastvalue() (Alexei) - getting rid of malloc() and free() (Alexei) git-svn-id: svn://svn.zabbix.com/trunk@347 97f52cf1-0a1b-0410-bd0e-c28be96e8082
-rw-r--r--ChangeLog15
-rw-r--r--create/data/data.sql7
-rw-r--r--include/cfg.c1
-rw-r--r--include/expression.c44
-rw-r--r--include/functions.c80
-rw-r--r--src/zabbix_agent/sysinfo.c32
-rw-r--r--src/zabbix_agent/sysinfo.h2
-rw-r--r--src/zabbix_agent/zabbix_agent.c17
-rw-r--r--src/zabbix_agent/zabbix_agentd.c26
-rw-r--r--src/zabbix_sucker/zabbix_sucker.c14
-rw-r--r--src/zabbix_trapper/zabbix_trapperd.c6
11 files changed, 131 insertions, 113 deletions
diff --git a/ChangeLog b/ChangeLog
index a6188025..763e9400 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,24 +1,27 @@
Not ready yet:
[ Fix DebugLevel ]
-[ Update task status on SF ]
+[ Support for automake ]
[ Support for Service Tree ]
[ Support for flexible permissions ]
[ Make Zabbix compile by cc ]
-[ Show diff instead of real values ]
-[ Show triggers by userid ]
+[ PHP. Change algorithm for audible notification ]
+[ PHP. Show time legend for graphs ]
+[ PHP. Show diff instead of real values ]
+[ PHP. Show triggers by userid ]
+[ PHP. Support for template-based new hosts ]
+
[ Add support for new trigger statuses: MODIFIED/NOTSUPORTED ]
[ All parameters should contain section "How can be used" in the Manual ]
-[ PHP to support non-numeric values ]
-[ Change algorithm for audible notification ]
Changes for 1.0beta3:
+ - improved update_triggers() (Alexei)
+ - fixed get_lastvalue() (Alexei)
- minor changes in include/cfg.c (Alexei)
-
- column functions.lastvalue changed to varchar(255) (Alexei)
- column items.lastvalue changed to varchar(255) (Alexei)
- column items.prevvalue changed to varchar(255) (Alexei)
diff --git a/create/data/data.sql b/create/data/data.sql
index 29414653..21aed8ec 100644
--- a/create/data/data.sql
+++ b/create/data/data.sql
@@ -244,4 +244,9 @@ insert into triggers_template (triggertemplateid,itemtemplateid,description,expr
values (63,63,'Configured max number of processes is too low on %s','{:.last(0)}<256');
insert into triggers_template (triggertemplateid,itemtemplateid,description,expression)
values (64,64,'Configured max number of opened files is too low on %s','{:.last(0)}<512');
-
+insert into triggers_template (triggertemplateid,itemtemplateid,description,expression)
+ values (65,65,'Hostname was changed on %s','{:.diff(0)}>0');
+insert into triggers_template (triggertemplateid,itemtemplateid,description,expression)
+ values (66,66,'Host information was changed on %s','{:.diff(0)}>0');
+insert into triggers_template (triggertemplateid,itemtemplateid,description,expression)
+ values (67,67,'Version of zabbix_agent(d) was changed on %s','{:.diff(0)}>0');
diff --git a/include/cfg.c b/include/cfg.c
index 4849f11e..63e376f0 100644
--- a/include/cfg.c
+++ b/include/cfg.c
@@ -31,7 +31,6 @@ int parse_cfg_file(char *cfg_file,struct cfg_line *cfg)
char *value;
int lineno;
int i,var;
- int *pointer;
char **c;
int (*func)();
diff --git a/include/expression.c b/include/expression.c
index a87becff..b7ec09db 100644
--- a/include/expression.c
+++ b/include/expression.c
@@ -29,7 +29,7 @@ int is_float(char *c)
int i;
int dot=-1;
- zabbix_log(LOG_LEVEL_DEBUG, "Starting is_float:%s", c );
+ zabbix_log(LOG_LEVEL_DEBUG, "Starting is_float:[%s]", c );
for(i=0;i<strlen(c);i++)
{
if((c[i]>='0')&&(c[i]<='9'))
@@ -316,7 +316,7 @@ int evaluate(int *result,char *exp)
}
if( r == -1 )
{
- zabbix_log(LOG_LEVEL_WARNING, "Cannot find left bracket [(]. Expression:%s", exp );
+ zabbix_log(LOG_LEVEL_WARNING, "Cannot find left bracket [(]. Expression:[%s]", exp );
return FAIL;
}
for(i=l+1;i<r;i++)
@@ -327,30 +327,30 @@ int evaluate(int *result,char *exp)
if( evaluate_simple( &value, simple ) != SUCCEED )
{
- zabbix_log( LOG_LEVEL_WARNING, "Unable to evaluate simple expression [%s]", simple );
+ zabbix_log( LOG_LEVEL_WARNING, "Unable to evaluate simple expression1 [%s]", simple );
return FAIL;
}
- zabbix_log(LOG_LEVEL_DEBUG, "Expression1:%s", exp );
+ zabbix_log(LOG_LEVEL_DEBUG, "Expression1:[%s]", exp );
exp[l]='%';
exp[l+1]='f';
exp[l+2]=' ';
- zabbix_log(LOG_LEVEL_DEBUG, "Expression2:%s", exp );
+ zabbix_log(LOG_LEVEL_DEBUG, "Expression2:[%s]", exp );
for(i=l+3;i<=r;i++) exp[i]=' ';
- zabbix_log(LOG_LEVEL_DEBUG, "Expression3:%s", exp );
+ zabbix_log(LOG_LEVEL_DEBUG, "Expression3:[%s]", exp );
sprintf(res,exp,value);
strncpy(exp,res, MAX_STRING_LEN);
delete_spaces(res);
- zabbix_log(LOG_LEVEL_DEBUG, "Expression4:%s", res );
+ zabbix_log(LOG_LEVEL_DEBUG, "Expression4:[%s]", res );
}
if( evaluate_simple( &value, res ) != SUCCEED )
{
- zabbix_log(LOG_LEVEL_WARNING, "Unable to evaluate simple expression [%s]", simple );
+ zabbix_log(LOG_LEVEL_WARNING, "Unable to evaluate simple expression2 [%s]", simple );
return FAIL;
}
zabbix_log( LOG_LEVEL_DEBUG, "Evaluate end:[%f]", value );
@@ -369,14 +369,14 @@ int substitute_macros(char *exp)
char key[MAX_STRING_LEN+1];
char function[MAX_STRING_LEN+1];
char parameter[MAX_STRING_LEN+1];
- char value[MAX_STRING_LEN+1];
+ static char value[MAX_STRING_LEN+1];
int i,j;
int r,l;
int r1,l1;
zabbix_log(LOG_LEVEL_DEBUG, "BEGIN substitute_macros" );
- zabbix_log( LOG_LEVEL_DEBUG, "Expression1:%s", exp );
+ zabbix_log( LOG_LEVEL_DEBUG, "Expression1:[%s]", exp );
while( find_char(exp,'{') != FAIL )
{
@@ -385,13 +385,13 @@ int substitute_macros(char *exp)
if( r == FAIL )
{
- zabbix_log( LOG_LEVEL_WARNING, "Cannot find right bracket. Expression:%s", exp );
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot find right bracket. Expression:[%s]", exp );
return FAIL;
}
if( r < l )
{
- zabbix_log( LOG_LEVEL_WARNING, "Right bracket is before left one. Expression:%s", exp );
+ zabbix_log( LOG_LEVEL_WARNING, "Right bracket is before left one. Expression:[%s]", exp );
return FAIL;
}
@@ -456,7 +456,7 @@ int substitute_macros(char *exp)
exp[l+1]='s';
exp[l+2]=' ';
- zabbix_log( LOG_LEVEL_DEBUG, "Expression2:%s", exp );
+ zabbix_log( LOG_LEVEL_DEBUG, "Expression2:[%s]", exp );
for(i=l+3;i<=r;i++) exp[i]=' ';
@@ -474,12 +474,12 @@ int substitute_macros(char *exp)
}
exp[j]=0;
- zabbix_log( LOG_LEVEL_DEBUG, "Expression3:%s", exp );
+ zabbix_log( LOG_LEVEL_DEBUG, "Expression3:[%s]", exp );
sprintf(res,exp,value);
strncpy(exp,res, MAX_STRING_LEN);
/* delete_spaces(exp); */
- zabbix_log( LOG_LEVEL_DEBUG, "Expression4:%s", exp );
+ zabbix_log( LOG_LEVEL_DEBUG, "Expression4:[%s]", exp );
}
zabbix_log( LOG_LEVEL_DEBUG, "Result expression:%s", exp );
@@ -505,12 +505,12 @@ int substitute_functions(char *exp)
r=find_char(exp,'}');
if( r == FAIL )
{
- zabbix_log( LOG_LEVEL_WARNING, "Cannot find right bracket. Expression:%s", exp );
+ zabbix_log( LOG_LEVEL_WARNING, "Cannot find right bracket. Expression:[%s]", exp );
return FAIL;
}
if( r < l )
{
- zabbix_log( LOG_LEVEL_WARNING, "Right bracket is before left one. Expression:%s", exp );
+ zabbix_log( LOG_LEVEL_WARNING, "Right bracket is before left one. Expression:[%s]", exp );
return FAIL;
}
@@ -527,24 +527,24 @@ int substitute_functions(char *exp)
}
- zabbix_log( LOG_LEVEL_DEBUG, "Expression1:%s", exp );
+ zabbix_log( LOG_LEVEL_DEBUG, "Expression1:[%s]", exp );
exp[l]='%';
exp[l+1]='f';
exp[l+2]=' ';
- zabbix_log( LOG_LEVEL_DEBUG, "Expression2:%s", exp );
+ zabbix_log( LOG_LEVEL_DEBUG, "Expression2:[%s]", exp );
for(i=l+3;i<=r;i++) exp[i]=' ';
- zabbix_log( LOG_LEVEL_DEBUG, "Expression3:%s", exp );
+ zabbix_log( LOG_LEVEL_DEBUG, "Expression3:[%s]", exp );
sprintf(res,exp,value);
strncpy(exp,res, MAX_STRING_LEN);
delete_spaces(exp);
- zabbix_log( LOG_LEVEL_DEBUG, "Expression4:%s", exp );
+ zabbix_log( LOG_LEVEL_DEBUG, "Expression4:[%s]", exp );
}
- zabbix_log( LOG_LEVEL_DEBUG, "Expression:%s", exp );
+ zabbix_log( LOG_LEVEL_DEBUG, "Expression:[%s]", exp );
zabbix_log( LOG_LEVEL_DEBUG, "END substitute_functions" );
return SUCCEED;
}
diff --git a/include/functions.c b/include/functions.c
index 943aa62e..370de58e 100644
--- a/include/functions.c
+++ b/include/functions.c
@@ -131,7 +131,6 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,int parameter)
{
if(item->value_type==0)
{
-/* *value=(char *)malloc(MAX_STRING_LEN+1);*/
zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 1");
sprintf(value,"%f",item->lastvalue);
zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 2");
@@ -139,7 +138,7 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,int parameter)
else
{
/* *value=strdup(item->lastvalue_str);*/
- zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 3");
+ zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 3 [%s] [%s]",value,item->lastvalue_str);
strncpy(value,item->lastvalue_str,MAX_STRING_LEN);
zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_FUNCTION() 4");
}
@@ -155,13 +154,11 @@ int evaluate_FUNCTION(char *value,DB_ITEM *item,char *function,int parameter)
{
if(item->value_type==0)
{
-/* *value=(char *)malloc(MAX_STRING_LEN+1);*/
sprintf(value,"%f",item->prevvalue);
}
else
{
-/* *value=strdup(item->prevvalue_str);*/
- strncpy(value,item->lastvalue_str,MAX_STRING_LEN);
+ strncpy(value,item->prevvalue_str,MAX_STRING_LEN);
}
}
}
@@ -249,6 +246,8 @@ void update_functions(DB_ITEM *item)
function.itemid=atoi(DBget_field(result,i,2));
zabbix_log( LOG_LEVEL_DEBUG, "ItemId:%d Evaluating %s(%d)\n",function.itemid,function.function,function.parameter);
+ zabbix_log( LOG_LEVEL_DEBUG, "ZZZ (%l)\n",value);
+
ret = evaluate_FUNCTION(value,item,function.function,function.parameter);
if( FAIL == ret)
@@ -316,7 +315,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error sending HELO to mailserver.");
close(s);
- free(c);
return FAIL;
}
@@ -326,7 +324,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error receiving answer on HELO request.");
close(s);
- free(c);
return FAIL;
}
@@ -336,7 +333,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error sending MAIL FROM to mailserver.");
close(s);
- free(c);
return FAIL;
}
i=sizeof(struct sockaddr_in);
@@ -345,7 +341,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error receiving answer on MAIL FROM request.");
close(s);
- free(c);
return FAIL;
}
@@ -355,7 +350,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error sending RCPT TO to mailserver.");
close(s);
- free(c);
return FAIL;
}
i=sizeof(struct sockaddr_in);
@@ -364,7 +358,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error receiving answer on RCPT TO request.");
close(s);
- free(c);
return FAIL;
}
@@ -374,7 +367,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error sending DATA to mailserver.");
close(s);
- free(c);
return FAIL;
}
i=sizeof(struct sockaddr_in);
@@ -383,7 +375,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error receivng answer on DATA request.");
close(s);
- free(c);
return FAIL;
}
sprintf(c,"%s\n",mailbody);
@@ -392,7 +383,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error sending mail body to mailserver.");
close(s);
- free(c);
return FAIL;
}
sprintf(c,".\n");
@@ -401,7 +391,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error sending . to mailserver.");
close(s);
- free(c);
return FAIL;
}
i=sizeof(struct sockaddr_in);
@@ -410,7 +399,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error receivng answer on . request.");
close(s);
- free(c);
return FAIL;
}
@@ -420,7 +408,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error sending \\n to mailserver.");
close(s);
- free(c);
return FAIL;
}
i=sizeof(struct sockaddr_in);
@@ -429,7 +416,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error receiving answer on \\n request.");
close(s);
- free(c);
return FAIL;
}
@@ -439,7 +425,6 @@ int send_mail(char *smtp_server,char *smtp_helo,char *smtp_email,char *mailto,ch
{
zabbix_log(LOG_LEVEL_ERR, "Error sending QUIT to mailserver.");
close(s);
- free(c);
return FAIL;
}
@@ -614,7 +599,9 @@ void update_triggers( int suckers, int flag, int sucker_num, int lastclock )
if(flag == 0)
{
- sprintf(sql,"select t.triggerid,t.expression,t.istrue,t.dep_level from triggers t,functions f,items i where i.status<>3 and i.itemid=f.itemid and i.lastclock<=%d and t.istrue!=2 and f.triggerid=t.triggerid and f.itemid%%%d=%d group by t.triggerid,t.expression,t.istrue,t.dep_level",lastclock,suckers-1,sucker_num-1);
+ now=time(NULL);
+/* Added table hosts to eliminate unnecessary update of triggers */
+ sprintf(sql,"select t.triggerid,t.expression,t.istrue,t.dep_level from triggers t,functions f,items i,hosts h where i.hostid=h.hostid and i.status<>3 and i.itemid=f.itemid and i.lastclock<=%d and t.istrue!=2 and f.triggerid=t.triggerid and f.itemid%%%d=%d and (h.status=0 or (h.status=2 and h.disable_until<%d)) group by t.triggerid,t.expression,t.istrue,t.dep_level",lastclock,suckers-1,sucker_num-1,now);
}
else
{
@@ -640,7 +627,7 @@ void update_triggers( int suckers, int flag, int sucker_num, int lastclock )
strncpy(exp, trigger.expression, MAX_STRING_LEN);
if( evaluate_expression(&b, exp) != 0 )
{
- zabbix_log( LOG_LEVEL_WARNING, "Expression %s - SUX.",trigger.expression);
+ zabbix_log( LOG_LEVEL_WARNING, "Expression [%s] - SUX.",trigger.expression);
continue;
}
@@ -683,6 +670,9 @@ void update_triggers( int suckers, int flag, int sucker_num, int lastclock )
DBfree_result(result);
}
+/*
+ The fuction is used to evaluate macros for email notifications
+*/
int get_lastvalue(char *value,char *host,char *key,char *function,char *parameter)
{
DB_ITEM item;
@@ -691,28 +681,54 @@ int get_lastvalue(char *value,char *host,char *key,char *function,char *paramete
char sql[MAX_STRING_LEN+1];
int rows;
int parm;
+ char *s;
- sprintf(sql, "select i.itemid from items i,hosts h where h.host='%s' and h.hostid=i.hostid and i.key_='%s'", host, key );
+ zabbix_log(LOG_LEVEL_DEBUG, "In get_lastvalue()" );
+
+ sprintf(sql, "select i.itemid,i.prevvalue,i.lastvalue from items i,hosts h where h.host='%s' and h.hostid=i.hostid and i.key_='%s'", host, key );
result = DBselect(sql);
rows = DBnum_rows(result);
if((result == NULL)||(rows==0))
{
DBfree_result(result);
- zabbix_log(LOG_LEVEL_WARNING, "Query failed" );
+ zabbix_log(LOG_LEVEL_WARNING, "Query [%s] returned empty result" );
return FAIL;
}
item.itemid=atoi(DBget_field(result,0,0));
+ s=DBget_field(result,0,1);
+ if(s==NULL)
+ {
+ item.prevvalue_null=1;
+ }
+ else
+ {
+ item.prevvalue_null=0;
+ item.prevvalue_str=s;
+ item.prevvalue=atof(s);
+ }
+ s=DBget_field(result,0,2);
+ if(s==NULL)
+ {
+ item.lastvalue_null=1;
+ }
+ else
+ {
+ item.lastvalue_null=0;
+ item.lastvalue_str=s;
+ item.lastvalue=atof(s);
+ }
+
+
+
zabbix_log(LOG_LEVEL_DEBUG, "Itemid:%d", item.itemid );
DBfree_result(result);
parm=atoi(parameter);
zabbix_log(LOG_LEVEL_DEBUG, "Before evaluate_FUNCTION()" );
- evaluate_FUNCTION(value,&item,function,parm);
- zabbix_log(LOG_LEVEL_DEBUG, "After evaluate_FUNCTION()" );
- return SUCCEED;
+ return evaluate_FUNCTION(value,&item,function,parm);
}
/* For zabbix_trapper(d) */
@@ -766,8 +782,8 @@ int process_data(char *server,char *key,char *value)
else
{
item.lastvalue_null=0;
- item.lastvalue=atof(s);
item.lastvalue_str=s;
+ item.lastvalue=atof(s);
}
s=DBget_field(result,0,14);
if(s==NULL)
@@ -777,8 +793,8 @@ int process_data(char *server,char *key,char *value)
else
{
item.prevvalue_null=0;
- item.prevvalue=atof(s);
item.prevvalue_str=s;
+ item.prevvalue=atof(s);
}
item.value_type=atoi(DBget_field(result,0,15));
@@ -813,11 +829,15 @@ void process_new_value(DB_ITEM *item,char *value)
DBexecute(sql);
}
- if((item->prevvalue_null == 1) || (cmp_double(value_double,item->lastvalue) != 0) || (cmp_double(item->prevvalue,item->lastvalue) != 0) )
+// if((item->prevvalue_null == 1) || (cmp_double(value_double,item->lastvalue) != 0) || (cmp_double(item->prevvalue,item->lastvalue) != 0) )
+ if((item->prevvalue_null == 1) || (strcmp(value,item->lastvalue_str) != 0) || (strcmp(item->prevvalue_str,item->lastvalue_str) != 0) )
{
- sprintf(sql,"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue=%f,lastclock=%d where itemid=%d",now+item->delay,value_double,now,item->itemid);
+ sprintf(sql,"update items set nextcheck=%d,prevvalue=lastvalue,lastvalue='%s',lastclock=%d where itemid=%d",now+item->delay,value,now,item->itemid);
item->prevvalue=item->lastvalue;
item->lastvalue=value_double;
+ item->prevvalue_str=item->lastvalue_str;
+/* Risky !!!*/
+ item->lastvalue_str=value;
item->prevvalue_null=item->lastvalue_null;
item->lastvalue_null=0;
}
diff --git a/src/zabbix_agent/sysinfo.c b/src/zabbix_agent/sysinfo.c
index 28ddead7..a149d0da 100644
--- a/src/zabbix_agent/sysinfo.c
+++ b/src/zabbix_agent/sysinfo.c
@@ -183,21 +183,20 @@ void test_parameters(void)
{
int i;
- char *c;
+ char c[MAX_STRING_LEN+1];
i=0;
while(0 != commands[i].key)
{
- c=process(commands[i].key);
+ process(commands[i].key,c);
printf("Key: [%s]\tResult: [%s]\n",commands[i].key,c);
fflush(stdout);
- free(c);
i++;
}
}
/* This messy function must be rewritten! */
-char *process(char *command)
+void process(char *command,char *value)
{
char *p;
double result=0;
@@ -209,7 +208,7 @@ char *process(char *command)
char key[MAX_STRING_LEN+1];
char param[1024];
char cmd[1024];
- char *res,*res2;
+ char *res2;
int ret_str=0;
for( p=command+strlen(command)-1; p>command && ( *p=='\r' || *p =='\n' || *p == ' ' ); --p );
@@ -299,30 +298,31 @@ char *process(char *command)
}
}
- res=(char *)malloc(MAX_STRING_LEN+1);
- if(res == NULL)
- {
+// if(res == NULL)
+// {
/* Not exactly ... */
- result=NOTSUPPORTED;
- }
+// result=NOTSUPPORTED;
+// }
if(ret_str==0)
{
- sprintf(res,"%f",result);
+ sprintf(value,"%f",result);
}
else
{
if(result==NOTSUPPORTED)
{
- sprintf(res,"%f",result);
+ sprintf(value,"%f",result);
}
else
{
- sprintf(res,"%s",res2);
+ sprintf(value,"%s",res2);
+ if(res2!=NULL)
+ {
+ free(res2);
+ }
}
}
-
- return res;
}
/* Code for cksum is based on code from cksum.c */
@@ -1226,7 +1226,7 @@ float DISK_WBLK(void)
char *VERSION(void)
{
- static char *version="1.0beta3\n";
+ static char version[]="1.0beta3\n";
return version;
}
diff --git a/src/zabbix_agent/sysinfo.h b/src/zabbix_agent/sysinfo.h
index 64cec9d1..bbdd3a7a 100644
--- a/src/zabbix_agent/sysinfo.h
+++ b/src/zabbix_agent/sysinfo.h
@@ -1,7 +1,7 @@
#ifndef MON_SYSINFO_H
#define MON_SYSINFO_H
-char *process(char *command);
+void process(char *command, char *value);
void add_user_parameter(char *key,char *command);
void test_parameters(void);
diff --git a/src/zabbix_agent/zabbix_agent.c b/src/zabbix_agent/zabbix_agent.c
index cc135b48..1f9dfcc3 100644
--- a/src/zabbix_agent/zabbix_agent.c
+++ b/src/zabbix_agent/zabbix_agent.c
@@ -107,18 +107,10 @@ int check_security(void)
return FAIL;
}
-char *process_input()
-{
- char s[1024];
-
- fgets(s,1024,stdin);
-
- return process(s);
-}
-
int main()
{
- char *res;
+ char s[MAX_STRING_LEN+1];
+ char value[MAX_STRING_LEN+1];
#ifdef TEST_PARAMETERS
init_config();
@@ -140,9 +132,10 @@ int main()
exit(FAIL);
}
- res=process_input();
+ fgets(s,MAX_STRING_LEN,stdin);
+ process(s,value);
- printf("%s\n",res);
+ printf("%s\n",value);
fflush(stdout);
diff --git a/src/zabbix_agent/zabbix_agentd.c b/src/zabbix_agent/zabbix_agentd.c
index d659c3a2..ecc35498 100644
--- a/src/zabbix_agent/zabbix_agentd.c
+++ b/src/zabbix_agent/zabbix_agentd.c
@@ -243,7 +243,7 @@ int check_security(int sockfd)
int i;
char *s;
- char *tmp;
+ char tmp[MAX_STRING_LEN+1];
i=sizeof(name);
@@ -255,7 +255,7 @@ int check_security(int sockfd)
zabbix_log( LOG_LEVEL_DEBUG, "Connection from [%s]. Allowed servers [%s] ",sname, CONFIG_HOSTS_ALLOWED);
- tmp=strdup(CONFIG_HOSTS_ALLOWED);
+ strncpy(tmp,CONFIG_HOSTS_ALLOWED,MAX_STRING_LEN);
s=(char *)strtok(tmp,",");
while(s!=NULL)
{
@@ -279,9 +279,8 @@ int check_security(int sockfd)
void process_child(int sockfd)
{
ssize_t nread;
- char line[1024];
- char result[1024];
- char *res;
+ char line[MAX_STRING_LEN+1];
+ char result[MAX_STRING_LEN+1];
static struct sigaction phan;
@@ -293,7 +292,7 @@ void process_child(int sockfd)
alarm(CONFIG_TIMEOUT);
zabbix_log( LOG_LEVEL_DEBUG, "Before read()");
- if( (nread = read(sockfd, line, 1024)) < 0)
+ if( (nread = read(sockfd, line, MAX_STRING_LEN)) < 0)
{
if(errno == EINTR)
{
@@ -313,13 +312,8 @@ void process_child(int sockfd)
zabbix_log( LOG_LEVEL_DEBUG, "Got line:%s", line);
- res=process(line);
+ process(line,result);
- sprintf(result,"%s",res);
- if(res!=NULL)
- {
- free(res);
- }
zabbix_log( LOG_LEVEL_DEBUG, "Sending back:%s", result);
write(sockfd,result,strlen(result));
@@ -376,9 +370,10 @@ void child_main(int i,int listenfd, int addrlen)
{
int connfd;
socklen_t clilen;
- struct sockaddr *cliaddr;
+// struct sockaddr *cliaddr;
+ struct sockaddr cliaddr;
- cliaddr=malloc(addrlen);
+// cliaddr=malloc(addrlen);
zabbix_log( LOG_LEVEL_WARNING, "zabbix_agentd %ld started",(long)getpid());
@@ -388,7 +383,8 @@ void child_main(int i,int listenfd, int addrlen)
#ifdef HAVE_FUNCTION_SETPROCTITLE
setproctitle("waiting for connection. Requests [%d]", stats_request++);
#endif
- connfd=accept(listenfd,cliaddr, &clilen);
+// connfd=accept(listenfd,cliaddr, &clilen);
+ connfd=accept(listenfd,&cliaddr, &clilen);
#ifdef HAVE_FUNCTION_SETPROCTITLE
setproctitle("processing request");
#endif
diff --git a/src/zabbix_sucker/zabbix_sucker.c b/src/zabbix_sucker/zabbix_sucker.c
index 2251c116..ba3952b8 100644
--- a/src/zabbix_sucker/zabbix_sucker.c
+++ b/src/zabbix_sucker/zabbix_sucker.c
@@ -353,7 +353,7 @@ int get_value_SNMPv1(double *result,DB_ITEM *item)
}
#endif
-int get_value_zabbix(double *result,char **result_str,DB_ITEM *item)
+int get_value_zabbix(double *result,char *result_str,DB_ITEM *item)
{
int s;
int i;
@@ -490,14 +490,14 @@ int get_value_zabbix(double *result,char **result_str,DB_ITEM *item)
}
}
- *result_str=strdup(c);
+ strncpy(result_str,c,MAX_STRING_LEN);
zabbix_log(LOG_LEVEL_DEBUG, "RESULT_STR [%s]", c );
return SUCCEED;
}
-int get_value(double *result,char **result_str,DB_ITEM *item)
+int get_value(double *result,char *result_str,DB_ITEM *item)
{
int res;
@@ -566,7 +566,7 @@ int get_minnextcheck(int now)
int get_values(void)
{
double value;
- char *value_str;
+ char value_str[MAX_STRING_LEN+1];
char sql[MAX_STRING_LEN+1];
DB_RESULT *result;
@@ -627,7 +627,9 @@ int get_values(void)
else
{
item.lastvalue_null=0;
+ item.lastvalue_str=s;
item.lastvalue=atof(s);
+// item.lastvalue_str=DBget_field(result,i,13);
}
s=DBget_field(result,i,14);
if(s==NULL)
@@ -637,13 +639,15 @@ int get_values(void)
else
{
item.prevvalue_null=0;
+ item.prevvalue_str=s;
item.prevvalue=atof(s);
+// item.prevvalue_str=DBget_field(result,i,14);
}
item.hostid=atoi(DBget_field(result,i,15));
host_status=atoi(DBget_field(result,i,16));
item.value_type=atoi(DBget_field(result,i,17));
- res = get_value(&value,&value_str,&item);
+ res = get_value(&value,value_str,&item);
zabbix_log( LOG_LEVEL_DEBUG, "GOT VALUE [%s]", value_str );
if(res == SUCCEED )
diff --git a/src/zabbix_trapper/zabbix_trapperd.c b/src/zabbix_trapper/zabbix_trapperd.c
index 09784aaa..1ea5ec3c 100644
--- a/src/zabbix_trapper/zabbix_trapperd.c
+++ b/src/zabbix_trapper/zabbix_trapperd.c
@@ -348,9 +348,7 @@ void child_main(int i,int listenfd, int addrlen)
{
int connfd;
socklen_t clilen;
- struct sockaddr *cliaddr;
-
- cliaddr=malloc(addrlen);
+ struct sockaddr cliaddr;
zabbix_log( LOG_LEVEL_WARNING, "zabbix_trapperd %ld started",(long)getpid());
@@ -362,7 +360,7 @@ void child_main(int i,int listenfd, int addrlen)
#ifdef HAVE_FUNCTION_SETPROCTITLE
setproctitle("waiting for connection");
#endif
- connfd=accept(listenfd,cliaddr, &clilen);
+ connfd=accept(listenfd,&cliaddr, &clilen);
#ifdef HAVE_FUNCTION_SETPROCTITLE
setproctitle("processing data");
#endif