23
23
static int evaluate_one(double *result, int *num, char *grpfunc, char const *value_str, int valuetype)
28
28
if(valuetype == ITEM_VALUE_TYPE_FLOAT)
30
value = atof(value_str);
30
value = zbx_atod(value_str);
32
32
else if(valuetype == ITEM_VALUE_TYPE_UINT64)
35
value = (double)atoll(value_str);
37
value = (double)atol(value_str);
34
value = (double)zbx_atoui64(value_str);
41
37
if(strcmp(grpfunc,"grpsum") == 0)
106
zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_aggregate('%s','%s','%s','%s','%s')",grpfunc,hostgroup,itemkey,itemfunc,param);
103
zabbix_log( LOG_LEVEL_DEBUG, "In evaluate_aggregate('%s','%s','%s','%s','%s')",
107
110
init_result(res);
109
112
DBescape_string(itemkey,itemkey_esc,MAX_STRING_LEN);
110
113
DBescape_string(hostgroup,hostgroup_esc,MAX_STRING_LEN);
111
114
/* Get list of affected item IDs */
112
115
strscpy(items,"0");
113
snprintf(sql,sizeof(sql)-1,"select itemid from items,hosts_groups,hosts,groups where 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 items.status=%d and hosts.status=%d",hostgroup_esc, itemkey_esc, ITEM_STATUS_ACTIVE, HOST_STATUS_MONITORED);
114
result = DBselect(sql);
116
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,
120
HOST_STATUS_MONITORED,
121
LOCAL_NODE("h.hostid"));
116
123
while((row=DBfetch(result)))
118
snprintf(items2,sizeof(items2)-1,"%s,%s",items, row[0]);
125
zbx_snprintf(items2,sizeof(items2),"%s,%s",
119
128
/* zabbix_log( LOG_LEVEL_WARNING, "ItemIDs items2[%s])",items2);*/
120
129
strscpy(items,items2);
121
130
/* zabbix_log( LOG_LEVEL_WARNING, "ItemIDs items[%s])",items2);*/
125
134
if(strcmp(itemfunc,"last") == 0)
127
snprintf(sql,sizeof(sql)-1,"select itemid,value_type,lastvalue from items where lastvalue is not NULL and items.itemid in (%s)",items);
128
snprintf(sql2,sizeof(sql2)-1,"select itemid,value_type,lastvalue from items where 0=1");
136
zbx_snprintf(sql,sizeof(sql),"select itemid,value_type,lastvalue from items where lastvalue is not NULL and items.itemid in (%s)",
138
zbx_snprintf(sql2,sizeof(sql2),"select itemid,value_type,lastvalue from items where 0=1");
130
140
/* The SQL works very very slow on MySQL 4.0. That's why it has been split into two. */
131
/* snprintf(sql,sizeof(sql)-1,"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));*/
141
/* 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));*/
132
142
else if( (strcmp(itemfunc,"min") == 0) ||
133
143
(strcmp(itemfunc,"max") == 0) ||
134
144
(strcmp(itemfunc,"avg") == 0) ||
136
146
(strcmp(itemfunc,"sum") == 0)
139
snprintf(sql,sizeof(sql)-1,"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));
140
snprintf(sql2,sizeof(sql)-1,"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));
149
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",
153
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",
144
zabbix_log( LOG_LEVEL_WARNING, "Unsupported item function [%s])",itemfunc);
160
zabbix_log( LOG_LEVEL_WARNING, "Unsupported item function [%s])",
147
164
zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]",sql);
155
172
if(FAIL == evaluate_one(&d, &num, grpfunc, value, valuetype))
157
zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",grpfunc);
174
zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",
158
176
DBfree_result(result);
169
187
if(FAIL == evaluate_one(&d, &num, grpfunc, value, valuetype))
171
zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",grpfunc);
189
zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",
172
191
DBfree_result(result);
195
DBfree_result(result);
179
zabbix_log( LOG_LEVEL_WARNING, "No values for group[%s] key[%s])",hostgroup,itemkey);
199
zabbix_log( LOG_LEVEL_WARNING, "No values for group[%s] key[%s])",
316
340
else ret = NOTSUPPORTED;
319
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);
343
zabbix_log( LOG_LEVEL_DEBUG, "Evaluating aggregate[%s] grpfunc[%s] group[%s] itemkey[%s] itemfunc [%s] parameter [%s]",
321
351
if( (ret == SUCCEED) &&
322
352
(evaluate_aggregate(result,function_grp, group, itemkey, function_item, parameter) != SUCCEED)