~ubuntu-dev/ubuntu/lucid/zabbix/lucid-201002110857

« back to all changes in this revision

Viewing changes to src/zabbix_server/poller/checks_aggregate.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Ablassmeier
  • Date: 2007-07-02 09:06:51 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070702090651-8l6fl3fjw9rh6l2u
Tags: 1:1.4.1-2
Add patch from SVN in order to fix Incorrect processing of character '%'
in user parameters and remote commands.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
static  int     evaluate_one(double *result, int *num, char *grpfunc, char const *value_str, int valuetype)
24
24
{
25
25
        int     ret = SUCCEED;
26
 
        double  value;
 
26
        double  value = 0;
27
27
 
28
28
        if(valuetype == ITEM_VALUE_TYPE_FLOAT)
29
29
        {
30
 
                value = atof(value_str);
 
30
                value = zbx_atod(value_str);
31
31
        }
32
32
        else if(valuetype == ITEM_VALUE_TYPE_UINT64)
33
33
        {
34
 
#ifdef HAVE_ATOLL
35
 
                        value = (double)atoll(value_str);
36
 
#else
37
 
                        value = (double)atol(value_str);
38
 
#endif
 
34
                value = (double)zbx_atoui64(value_str);
39
35
        }
40
36
 
41
37
        if(strcmp(grpfunc,"grpsum") == 0)
74
70
        }
75
71
        else
76
72
        {
77
 
                zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",grpfunc);
 
73
                zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",
 
74
                        grpfunc);
78
75
                ret = FAIL;
79
76
        }
80
77
 
103
100
 
104
101
        now=time(NULL);
105
102
 
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')",
 
104
                grpfunc,
 
105
                hostgroup,
 
106
                itemkey,
 
107
                itemfunc,
 
108
                param);
 
109
 
107
110
        init_result(res);
108
111
 
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,
 
117
                hostgroup_esc,
 
118
                itemkey_esc,
 
119
                ITEM_STATUS_ACTIVE,
 
120
                HOST_STATUS_MONITORED,
 
121
                LOCAL_NODE("h.hostid"));
115
122
 
116
123
        while((row=DBfetch(result)))
117
124
        {
118
 
                snprintf(items2,sizeof(items2)-1,"%s,%s",items, row[0]);
 
125
                zbx_snprintf(items2,sizeof(items2),"%s,%s",
 
126
                        items,
 
127
                        row[0]);
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);*/
124
133
 
125
134
        if(strcmp(itemfunc,"last") == 0)
126
135
        {
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)",
 
137
                        items);
 
138
                zbx_snprintf(sql2,sizeof(sql2),"select itemid,value_type,lastvalue from items where 0=1");
129
139
        }
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)
137
147
        )
138
148
        {
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",
 
150
                        itemfunc,
 
151
                        items,
 
152
                        now - atoi(param));
 
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",
 
154
                        itemfunc,
 
155
                        items,
 
156
                        now - atoi(param));
141
157
        }
142
158
        else
143
159
        {
144
 
                zabbix_log( LOG_LEVEL_WARNING, "Unsupported item function [%s])",itemfunc);
 
160
                zabbix_log( LOG_LEVEL_WARNING, "Unsupported item function [%s])",
 
161
                        itemfunc);
145
162
                return FAIL;
146
163
        }
147
164
        zabbix_log( LOG_LEVEL_DEBUG, "SQL [%s]",sql);
154
171
                value = row[2];
155
172
                if(FAIL == evaluate_one(&d, &num, grpfunc, value, valuetype))
156
173
                {
157
 
                        zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",grpfunc);
 
174
                        zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",
 
175
                                grpfunc);
158
176
                        DBfree_result(result);
159
177
                        return FAIL;
160
178
                }
168
186
                value = row[2];
169
187
                if(FAIL == evaluate_one(&d, &num, grpfunc, value, valuetype))
170
188
                {
171
 
                        zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",grpfunc);
 
189
                        zabbix_log( LOG_LEVEL_WARNING, "Unsupported group function [%s])",
 
190
                                grpfunc);
172
191
                        DBfree_result(result);
173
192
                        return FAIL;
174
193
                }
175
194
        }
 
195
        DBfree_result(result);
176
196
 
177
197
        if(num==0)
178
198
        {
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])",
 
200
                        hostgroup,
 
201
                        itemkey);
180
202
                return FAIL;
181
203
        }
182
204
 
189
211
                SET_DBL_RESULT(res, d);
190
212
        }
191
213
 
192
 
        zabbix_log( LOG_LEVEL_DEBUG, "Result([%f])",d);
 
214
        zabbix_log( LOG_LEVEL_DEBUG, "End evaluate_aggregate(result:" ZBX_FS_DBL ")",
 
215
                d);
193
216
        return SUCCEED;
194
217
}
195
218
 
223
246
        int     ret = SUCCEED;
224
247
 
225
248
 
226
 
        zabbix_log( LOG_LEVEL_DEBUG, "In get_value_aggregate([%s])",item->key);
 
249
        zabbix_log( LOG_LEVEL_DEBUG, "In get_value_aggregate([%s])",
 
250
                item->key);
227
251
 
228
252
        init_result(result);
229
253
 
316
340
                else    ret = NOTSUPPORTED;
317
341
        }
318
342
 
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]",
 
344
                item->key,
 
345
                function_grp,
 
346
                group,
 
347
                itemkey,
 
348
                function_item,
 
349
                parameter);
320
350
 
321
351
        if( (ret == SUCCEED) &&
322
352
                (evaluate_aggregate(result,function_grp, group, itemkey, function_item, parameter) != SUCCEED)