Index: src/zabbix_server/poller/checks_aggregate.c =================================================================== --- src/zabbix_server/poller/checks_aggregate.c (revision 8819) +++ src/zabbix_server/poller/checks_aggregate.c (working copy) @@ -86,6 +86,7 @@ { char sql[MAX_STRING_LEN]; char sql2[MAX_STRING_LEN]; + char items_sub_select[MAX_STRING_LEN]; char hostgroup_esc[MAX_STRING_LEN],itemkey_esc[MAX_STRING_LEN]; DB_RESULT result; @@ -96,7 +97,6 @@ const char *value; int num = 0; int now; - char items[MAX_STRING_LEN],items2[MAX_STRING_LEN]; now=time(NULL); @@ -112,31 +112,19 @@ 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 i.itemid from items i,hosts_groups hg,hosts h,groups g" + zbx_snprintf(items_sub_select,sizeof(items_sub_select), "select i.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" DB_NODE, + " and g.name='%s' and i.key_='%s' and i.status=%d and h.status=%d", hostgroup_esc, itemkey_esc, ITEM_STATUS_ACTIVE, - HOST_STATUS_MONITORED, - DBnode_local("h.hostid")); + HOST_STATUS_MONITORED); - 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); + items_sub_select); 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. */ @@ -150,11 +138,11 @@ { 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, + items_sub_select, 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, + items_sub_select, now - atoi(param)); } else