summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-06 23:55:23 +0000
committerhugetoad <hugetoad@97f52cf1-0a1b-0410-bd0e-c28be96e8082>2006-05-06 23:55:23 +0000
commitd3df28b936d259b8d3e91deeeba2104e87dffc8c (patch)
treef80e86dbe44d37c015bb5c58d5ed08fc859f57be /src
parentdf815285d27dc77733398d14db0bfbc27a7a3c3e (diff)
downloadzabbix-d3df28b936d259b8d3e91deeeba2104e87dffc8c.tar.gz
zabbix-d3df28b936d259b8d3e91deeeba2104e87dffc8c.tar.xz
zabbix-d3df28b936d259b8d3e91deeeba2104e87dffc8c.zip
Minor changes.
git-svn-id: svn://svn.zabbix.com/trunk@2813 97f52cf1-0a1b-0410-bd0e-c28be96e8082
Diffstat (limited to 'src')
-rw-r--r--src/libs/zbxdbhigh/db.c72
-rw-r--r--src/zabbix_server/evalfunc.c7
-rw-r--r--src/zabbix_server/functions.c10
-rw-r--r--src/zabbix_server/poller/poller.c23
-rw-r--r--src/zabbix_server/server.c2
-rw-r--r--src/zabbix_server/timer/timer.c7
-rw-r--r--src/zabbix_server/zlog.c33
7 files changed, 79 insertions, 75 deletions
diff --git a/src/libs/zbxdbhigh/db.c b/src/libs/zbxdbhigh/db.c
index 5545deb5..552b5189 100644
--- a/src/libs/zbxdbhigh/db.c
+++ b/src/libs/zbxdbhigh/db.c
@@ -1419,27 +1419,27 @@ void DBescape_string(char *from, char *to, int maxlen)
to[ptr]=0;
}
-void DBget_item_from_db(DB_ITEM *item,DB_RESULT result, int row)
+void DBget_item_from_db(DB_ITEM *item,DB_ROW row)
{
char *s;
int i;
i=row;
- item->itemid=atoi(DBget_field(result,i,0));
- strscpy(item->key,DBget_field(result,i,1));
- item->host=DBget_field(result,i,2);
- item->port=atoi(DBget_field(result,i,3));
- item->delay=atoi(DBget_field(result,i,4));
- item->description=DBget_field(result,i,5);
- item->nextcheck=atoi(DBget_field(result,i,6));
- item->type=atoi(DBget_field(result,i,7));
- item->snmp_community=DBget_field(result,i,8);
- item->snmp_oid=DBget_field(result,i,9);
- item->useip=atoi(DBget_field(result,i,10));
- item->ip=DBget_field(result,i,11);
- item->history=atoi(DBget_field(result,i,12));
- s=DBget_field(result,i,13);
+ item->itemid=atoi(row[0]);
+ strscpy(item->key,row[1]);
+ item->host=row[2];
+ item->port=atoi(row[3]);
+ item->delay=atoi(row[4]);
+ item->description=row[5];
+ item->nextcheck=atoi(row[6]);
+ item->type=atoi(row[7]);
+ item->snmp_community=row[8];
+ item->snmp_oid=row[9];
+ item->useip=atoi(row[10]);
+ item->ip=row[11];
+ item->history=atoi(row[12]);
+ s=row[13];
if(s==NULL)
{
item->lastvalue_null=1;
@@ -1450,7 +1450,7 @@ void DBget_item_from_db(DB_ITEM *item,DB_RESULT result, int row)
item->lastvalue_str=s;
item->lastvalue=atof(s);
}
- s=DBget_field(result,i,14);
+ s=row[14];
if(s==NULL)
{
item->prevvalue_null=1;
@@ -1461,15 +1461,15 @@ void DBget_item_from_db(DB_ITEM *item,DB_RESULT result, int row)
item->prevvalue_str=s;
item->prevvalue=atof(s);
}
- item->hostid=atoi(DBget_field(result,i,15));
- item->host_status=atoi(DBget_field(result,i,16));
- item->value_type=atoi(DBget_field(result,i,17));
+ item->hostid=atoi(row[15]);
+ item->host_status=atoi(row[16]);
+ item->value_type=atoi(row[17]);
- item->host_errors_from=atoi(DBget_field(result,i,18));
- item->snmp_port=atoi(DBget_field(result,i,19));
- item->delta=atoi(DBget_field(result,i,20));
+ item->host_errors_from=atoi(row[18]);
+ item->snmp_port=atoi(row[19]);
+ item->delta=atoi(row[20]);
- s=DBget_field(result,i,21);
+ s=row[21];
if(s==NULL)
{
item->prevorgvalue_null=1;
@@ -1479,7 +1479,7 @@ void DBget_item_from_db(DB_ITEM *item,DB_RESULT result, int row)
item->prevorgvalue_null=0;
item->prevorgvalue=atof(s);
}
- s=DBget_field(result,i,22);
+ s=row[22];
if(s==NULL)
{
item->lastclock=0;
@@ -1489,19 +1489,19 @@ void DBget_item_from_db(DB_ITEM *item,DB_RESULT result, int row)
item->lastclock=atoi(s);
}
- item->units=DBget_field(result,i,23);
- item->multiplier=atoi(DBget_field(result,i,24));
+ item->units=row[23];
+ item->multiplier=atoi(row[24]);
- item->snmpv3_securityname = DBget_field(result,i,25);
- item->snmpv3_securitylevel = atoi(DBget_field(result,i,26));
- item->snmpv3_authpassphrase = DBget_field(result,i,27);
- item->snmpv3_privpassphrase = DBget_field(result,i,28);
- item->formula = DBget_field(result,i,29);
- item->host_available=atoi(DBget_field(result,i,30));
- item->status=atoi(DBget_field(result,i,31));
- item->trapper_hosts=DBget_field(result,i,32);
- item->logtimefmt=DBget_field(result,i,33);
- item->valuemapid=atoi(DBget_field(result,i,34));
+ item->snmpv3_securityname = row[25];
+ item->snmpv3_securitylevel = atoi(row[26]);
+ item->snmpv3_authpassphrase = row[27];
+ item->snmpv3_privpassphrase = row[28];
+ item->formula = row[29];
+ item->host_available=atoi(row[30]);
+ item->status=atoi(row[31]);
+ item->trapper_hosts=row[32];
+ item->logtimefmt=row[33];
+ item->valuemapid=atoi(row[34]);
}
int DBget_default_escalation_id()
diff --git a/src/zabbix_server/evalfunc.c b/src/zabbix_server/evalfunc.c
index e062d5da..88a2d6f5 100644
--- a/src/zabbix_server/evalfunc.c
+++ b/src/zabbix_server/evalfunc.c
@@ -1109,6 +1109,7 @@ int evaluate_FUNCTION2(char *value,char *host,char *key,char *function,char *par
{
DB_ITEM item;
DB_RESULT result;
+ DB_ROW row;
char sql[MAX_STRING_LEN];
int res;
@@ -1118,7 +1119,9 @@ int evaluate_FUNCTION2(char *value,char *host,char *key,char *function,char *par
snprintf(sql,sizeof(sql)-1,"select %s where h.host='%s' and h.hostid=i.hostid and i.key_='%s'", ZBX_SQL_ITEM_SELECT, host, key );
result = DBselect(sql);
- if(DBnum_rows(result) == 0)
+ row = DBfetch(result);
+
+ if(!row)
{
DBfree_result(result);
zabbix_log(LOG_LEVEL_WARNING, "Query [%s] returned empty result", sql );
@@ -1126,7 +1129,7 @@ int evaluate_FUNCTION2(char *value,char *host,char *key,char *function,char *par
return FAIL;
}
- DBget_item_from_db(&item,result, 0);
+ DBget_item_from_db(&item,row);
zabbix_log(LOG_LEVEL_DEBUG, "Itemid:%d", item.itemid );
diff --git a/src/zabbix_server/functions.c b/src/zabbix_server/functions.c
index 70dc7444..2825592a 100644
--- a/src/zabbix_server/functions.c
+++ b/src/zabbix_server/functions.c
@@ -405,6 +405,7 @@ int process_data(int sockfd,char *server,char *key,char *value,char *lastlogsize
AGENT_RESULT agent;
DB_RESULT result;
+ DB_ROW row;
DB_ITEM item;
char *s;
@@ -424,7 +425,9 @@ int process_data(int sockfd,char *server,char *key,char *value,char *lastlogsize
result = DBselect(sql);
- if(DBnum_rows(result) == 0)
+ row=DBfetch(result);
+
+ if(!row)
{
zabbix_log( LOG_LEVEL_DEBUG, "Before checking autoregistration for [%s]",server);
@@ -433,7 +436,8 @@ int process_data(int sockfd,char *server,char *key,char *value,char *lastlogsize
DBfree_result(result);
result = DBselect(sql);
- if(DBnum_rows(result) == 0)
+ row = DBfetch(result);
+ if(!row)
{
DBfree_result(result);
return FAIL;
@@ -446,7 +450,7 @@ int process_data(int sockfd,char *server,char *key,char *value,char *lastlogsize
}
}
- DBget_item_from_db(&item,result,0);
+ DBget_item_from_db(&item,row);
/* item.itemid=atoi(DBget_field(result,0,0));
strscpy(item.key,DBget_field(result,0,1));
diff --git a/src/zabbix_server/poller/poller.c b/src/zabbix_server/poller/poller.c
index d1bfc8c3..03e43fdd 100644
--- a/src/zabbix_server/poller/poller.c
+++ b/src/zabbix_server/poller/poller.c
@@ -164,6 +164,7 @@ static void update_key_status(int hostid,int host_status)
DB_ITEM item;
DB_RESULT result;
+ DB_ROW row;
zabbix_log(LOG_LEVEL_DEBUG, "In update_key_status(%d,%d)",hostid,host_status);
@@ -171,13 +172,11 @@ static void update_key_status(int hostid,int host_status)
zabbix_log(LOG_LEVEL_DEBUG, "SQL [%s]", sql);
result = DBselect(sql);
- if( DBnum_rows(result) == 0)
- {
- zabbix_log( LOG_LEVEL_DEBUG, "No items to update.");
- }
- else
+ row = DBfetch(result);
+
+ if(row)
{
- DBget_item_from_db(&item,result,0);
+ DBget_item_from_db(&item,row);
/* Do not process new value for status, if previous status is the same */
zabbix_log( LOG_LEVEL_DEBUG, "item.lastvalue[%f] new host status[%d]",item.lastvalue,host_status);
@@ -191,6 +190,10 @@ static void update_key_status(int hostid,int host_status)
update_triggers(item.itemid);
}
}
+ else
+ {
+ zabbix_log( LOG_LEVEL_DEBUG, "No items to update.");
+ }
DBfree_result(result);
}
@@ -215,13 +218,13 @@ int get_values(void)
char sql[MAX_STRING_LEN];
DB_RESULT result;
+ DB_ROW row;
- int i;
int now;
int res;
DB_ITEM item;
AGENT_RESULT agent;
- int stop;
+ int stop=0;
now = time(NULL);
@@ -243,9 +246,9 @@ int get_values(void)
}
result = DBselect(sql);
- for(stop=i=0;i<DBnum_rows(result)&&stop==0;i++)
+ while((row=DBfetch(result))&&(stop==0))
{
- DBget_item_from_db(&item,result, i);
+ DBget_item_from_db(&item,row);
init_result(&agent);
zabbix_log( LOG_LEVEL_DEBUG, "GOT VALUE TYPE [0x%X]", agent.type);
diff --git a/src/zabbix_server/server.c b/src/zabbix_server/server.c
index ae166175..d927ce32 100644
--- a/src/zabbix_server/server.c
+++ b/src/zabbix_server/server.c
@@ -490,7 +490,7 @@ void test()
int main(int argc, char **argv)
{
int ch;
- int i,j;
+ int i;
pid_t pid;
struct sigaction phan;
diff --git a/src/zabbix_server/timer/timer.c b/src/zabbix_server/timer/timer.c
index d3cd271e..5dcc27c2 100644
--- a/src/zabbix_server/timer/timer.c
+++ b/src/zabbix_server/timer/timer.c
@@ -64,7 +64,7 @@ extern void update_functions(DB_ITEM *item);
void main_timer_loop()
{
char sql[MAX_STRING_LEN];
- int i,now;
+ int now;
/* int itemid,functionid;
char *function;
@@ -73,6 +73,7 @@ void main_timer_loop()
DB_ITEM item;
DB_RESULT result;
+ DB_ROW row;
for(;;)
{
@@ -95,9 +96,9 @@ void main_timer_loop()
result = DBselect(sql);
- for(i=0;i<DBnum_rows(result);i++)
+ while((row=DBfetch(result)))
{
- DBget_item_from_db(&item,result, i);
+ DBget_item_from_db(&item,row);
/* Update triggers will update value for NODATA */
/* snprintf(sql,sizeof(sql)-1,"update functions set lastvalue='1' where itemid=%d and function='%s' and parameter='%s'" , itemid, function, parameter );
diff --git a/src/zabbix_server/zlog.c b/src/zabbix_server/zlog.c
index 99ef20cc..5a9d36d4 100644
--- a/src/zabbix_server/zlog.c
+++ b/src/zabbix_server/zlog.c
@@ -51,13 +51,13 @@
******************************************************************************/
void zabbix_syslog(const char *fmt, ...)
{
- int i;
va_list ap;
char sql[MAX_STRING_LEN];
char value_str[MAX_STRING_LEN];
DB_ITEM item;
DB_RESULT result;
+ DB_ROW row;
AGENT_RESULT agent;
@@ -66,28 +66,21 @@ void zabbix_syslog(const char *fmt, ...)
snprintf(sql,sizeof(sql)-1,"select %s where h.hostid=i.hostid and i.key_='%s' and i.value_type=%d", ZBX_SQL_ITEM_SELECT, SERVER_ZABBIXLOG_KEY, ITEM_VALUE_TYPE_STR);
result = DBselect(sql);
- if( DBnum_rows(result) == 0)
+ while((row=DBfetch(result)))
{
- zabbix_log( LOG_LEVEL_DEBUG, "No zabbix[log] to update.");
- }
- else
- {
- for(i=0;i<DBnum_rows(result);i++)
- {
- DBget_item_from_db(&item,result, i);
-
- va_start(ap,fmt);
- vsprintf(value_str,fmt,ap);
- value_str[MAX_STRING_LEN-1]=0;
- va_end(ap);
+ DBget_item_from_db(&item,row);
+
+ va_start(ap,fmt);
+ vsprintf(value_str,fmt,ap);
+ value_str[MAX_STRING_LEN-1]=0;
+ va_end(ap);
- init_result(&agent);
- SET_STR_RESULT(&agent, strdup(value_str));
- process_new_value(&item,&agent);
- free_result(&agent);
+ init_result(&agent);
+ SET_STR_RESULT(&agent, strdup(value_str));
+ process_new_value(&item,&agent);
+ free_result(&agent);
- update_triggers(item.itemid);
- }
+ update_triggers(item.itemid);
}
DBfree_result(result);