Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 411 lines (309 sloc) 8.489 kb
bed7682 useful XML support, first commit of uwsgiconfig.py
roberto@sirius authored
1 #ifdef UWSGI_SNMP
e0882ed big update: hooks and plugins
roberto@sirius authored
2
3 #include "uwsgi.h"
4
5 extern struct uwsgi_server uwsgi;
6
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
7 #define SNMP_SEQUENCE 0x30
8 #define SNMP_INTEGER 0x02
9 #define SNMP_STRING 0x04
10 #define SNMP_NULL 0x05
11 #define SNMP_GET 0xA0
12 #define SNMP_RES 0xA2
13 #define SNMP_OID 0x06
e0882ed big update: hooks and plugins
roberto@sirius authored
14
e05edd9 almost ready SNMP support
roberto@sirius authored
15 #define SNMP_WATERMARK (127-8)
16
e0882ed big update: hooks and plugins
roberto@sirius authored
17 /* 1.3.6.1.4.1.35156.17.X.X */
18 #define SNMP_UWSGI_BASE "\x2B\x06\x01\x04\x01\x82\x92\x54\x11"
19
20 static int get_snmp_integer(uint8_t *, uint64_t *);
21
e05edd9 almost ready SNMP support
roberto@sirius authored
22 static uint64_t get_uwsgi_snmp_value(uint64_t, uint8_t *);
23 static uint64_t get_uwsgi_custom_snmp_value(uint64_t, uint8_t *);
e0882ed big update: hooks and plugins
roberto@sirius authored
24
e05edd9 almost ready SNMP support
roberto@sirius authored
25 static uint8_t snmp_int_to_snmp(uint64_t, uint8_t, uint8_t *);
e0882ed big update: hooks and plugins
roberto@sirius authored
26
e05edd9 almost ready SNMP support
roberto@sirius authored
27 static ssize_t build_snmp_response(uint8_t, uint8_t, uint8_t *, int, uint8_t *, uint8_t *, uint8_t *);
e0882ed big update: hooks and plugins
roberto@sirius authored
28
aa9c533 re-indent all the code
roberto@sirius authored
29 void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_addr) {
e05edd9 almost ready SNMP support
roberto@sirius authored
30
e0882ed big update: hooks and plugins
roberto@sirius authored
31 uint16_t asnlen;
32 uint16_t oidlen;
e05edd9 almost ready SNMP support
roberto@sirius authored
33
34 uint8_t oid_part[2];
35
aa9c533 re-indent all the code
roberto@sirius authored
36 int ptrdelta;
e0882ed big update: hooks and plugins
roberto@sirius authored
37
e05edd9 almost ready SNMP support
roberto@sirius authored
38 uint8_t *ptr = buffer, *seq1, *seq2, *seq3;
39
40 uint8_t community_len;
e0882ed big update: hooks and plugins
roberto@sirius authored
41
b245307 stricter compiler flags
riccardo@montag authored
42 uint64_t snmp_int = 0;
43 uint64_t request_id = 0;
44 uint64_t version = 0;
aa9c533 re-indent all the code
roberto@sirius authored
45
b9cc3b6 snmp fix
roberto@sirius authored
46
aa9c533 re-indent all the code
roberto@sirius authored
47 // KISS for memory management
e05edd9 almost ready SNMP support
roberto@sirius authored
48 if (size > SNMP_WATERMARK)
aa9c533 re-indent all the code
roberto@sirius authored
49 return;
e0882ed big update: hooks and plugins
roberto@sirius authored
50 ptr++;
51
b9cc3b6 snmp fix
roberto@sirius authored
52
e0882ed big update: hooks and plugins
roberto@sirius authored
53 // check total sequence size
e05edd9 almost ready SNMP support
roberto@sirius authored
54 if (*ptr > SNMP_WATERMARK || *ptr < 13)
e0882ed big update: hooks and plugins
roberto@sirius authored
55 return;
e05edd9 almost ready SNMP support
roberto@sirius authored
56 ptr++;
e0882ed big update: hooks and plugins
roberto@sirius authored
57
9285b40 SNMP test
roberto authored
58 #ifdef UWSGI_DEBUG
59 uwsgi_debug("SNMP packet size: %d\n", size);
60 #endif
e0882ed big update: hooks and plugins
roberto@sirius authored
61
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
62 // check snmp version
e0882ed big update: hooks and plugins
roberto@sirius authored
63 if (*ptr != SNMP_INTEGER)
64 return;
65 ptr++;
66
e05edd9 almost ready SNMP support
roberto@sirius authored
67 ptrdelta = get_snmp_integer(ptr, &version);
68 if (version > 2)
e0882ed big update: hooks and plugins
roberto@sirius authored
69 return;
e05edd9 almost ready SNMP support
roberto@sirius authored
70 ptr += ptrdelta;
e0882ed big update: hooks and plugins
roberto@sirius authored
71
9285b40 SNMP test
roberto authored
72 #ifdef UWSGI_DEBUG
73 uwsgi_debug("SNMP version: %d\n", version);
74 #endif
e0882ed big update: hooks and plugins
roberto@sirius authored
75
09bc058 goodbye to ROCK_SOLID
roberto@sirius authored
76 // check for community string (this must be set from the python vm using uwsgi.snmp_community or with --snmp-community arg)
e0882ed big update: hooks and plugins
roberto@sirius authored
77 if (*ptr != SNMP_STRING)
aa9c533 re-indent all the code
roberto@sirius authored
78 return;
79 ptr++;
e0882ed big update: hooks and plugins
roberto@sirius authored
80
e05edd9 almost ready SNMP support
roberto@sirius authored
81 community_len = *ptr;
e0882ed big update: hooks and plugins
roberto@sirius authored
82
e05edd9 almost ready SNMP support
roberto@sirius authored
83 if (community_len > 72 || community_len < 1)
e0882ed big update: hooks and plugins
roberto@sirius authored
84 return;
e05edd9 almost ready SNMP support
roberto@sirius authored
85 ptr++;
09bc058 goodbye to ROCK_SOLID
roberto@sirius authored
86
87 // check for community string
88 if (strlen(uwsgi.shared->snmp_community) != community_len)
89 return;
90 if (memcmp(ptr, uwsgi.shared->snmp_community, community_len))
91 return;
e0882ed big update: hooks and plugins
roberto@sirius authored
92
9285b40 SNMP test
roberto authored
93 #ifdef UWSGI_DEBUG
94 uwsgi_debug("SNMP community: %.*s\n", community_len, ptr);
95 #endif
96
e05edd9 almost ready SNMP support
roberto@sirius authored
97 ptr += community_len;
aa9c533 re-indent all the code
roberto@sirius authored
98
e0882ed big update: hooks and plugins
roberto@sirius authored
99 // check for get request
100 if (*ptr != SNMP_GET)
aa9c533 re-indent all the code
roberto@sirius authored
101 return;
9285b40 SNMP test
roberto authored
102
e05edd9 almost ready SNMP support
roberto@sirius authored
103 *ptr = SNMP_RES;
e0882ed big update: hooks and plugins
roberto@sirius authored
104 ptr++;
e05edd9 almost ready SNMP support
roberto@sirius authored
105 seq1 = ptr;
e0882ed big update: hooks and plugins
roberto@sirius authored
106
107
e05edd9 almost ready SNMP support
roberto@sirius authored
108 if (*ptr != ((size - community_len) - 9))
aa9c533 re-indent all the code
roberto@sirius authored
109 return;
e05edd9 almost ready SNMP support
roberto@sirius authored
110 ptr++;
aa9c533 re-indent all the code
roberto@sirius authored
111
e0882ed big update: hooks and plugins
roberto@sirius authored
112 // get request_id
113 if (*ptr != SNMP_INTEGER)
aa9c533 re-indent all the code
roberto@sirius authored
114 return;
115 ptr++;
9285b40 SNMP test
roberto authored
116
aa9c533 re-indent all the code
roberto@sirius authored
117 ptrdelta = get_snmp_integer(ptr, &request_id);
e05edd9 almost ready SNMP support
roberto@sirius authored
118
e0882ed big update: hooks and plugins
roberto@sirius authored
119 if (ptrdelta <= 0)
aa9c533 re-indent all the code
roberto@sirius authored
120 return;
e05edd9 almost ready SNMP support
roberto@sirius authored
121
9285b40 SNMP test
roberto authored
122 #ifdef UWSGI_DEBUG
123 uwsgi_debug("SNMP request id: %d %p\n", request_id, ptr);
124 #endif
125
e05edd9 almost ready SNMP support
roberto@sirius authored
126 // check here
aa9c533 re-indent all the code
roberto@sirius authored
127 if (ptr + ptrdelta >= buffer + size)
128 return;
129 ptr += ptrdelta;
e0882ed big update: hooks and plugins
roberto@sirius authored
130
9285b40 SNMP test
roberto authored
131
e0882ed big update: hooks and plugins
roberto@sirius authored
132 // get error
133 if (*ptr != SNMP_INTEGER)
aa9c533 re-indent all the code
roberto@sirius authored
134 return;
9285b40 SNMP test
roberto authored
135
aa9c533 re-indent all the code
roberto@sirius authored
136 ptr++;
b245307 stricter compiler flags
riccardo@montag authored
137 snmp_int = 0;
aa9c533 re-indent all the code
roberto@sirius authored
138 ptrdelta = get_snmp_integer(ptr, &snmp_int);
b245307 stricter compiler flags
riccardo@montag authored
139
e0882ed big update: hooks and plugins
roberto@sirius authored
140 if (ptrdelta <= 0)
aa9c533 re-indent all the code
roberto@sirius authored
141 return;
142 if (ptr + ptrdelta >= buffer + size)
143 return;
e0882ed big update: hooks and plugins
roberto@sirius authored
144 if (snmp_int != 0)
145 return;
9285b40 SNMP test
roberto authored
146
aa9c533 re-indent all the code
roberto@sirius authored
147 ptr += ptrdelta;
e0882ed big update: hooks and plugins
roberto@sirius authored
148
149 // get index
150 if (*ptr != SNMP_INTEGER)
aa9c533 re-indent all the code
roberto@sirius authored
151 return;
152 ptr++;
b245307 stricter compiler flags
riccardo@montag authored
153 snmp_int = 0;
aa9c533 re-indent all the code
roberto@sirius authored
154 ptrdelta = get_snmp_integer(ptr, &snmp_int);
e0882ed big update: hooks and plugins
roberto@sirius authored
155 if (ptrdelta <= 0)
aa9c533 re-indent all the code
roberto@sirius authored
156 return;
157 if (ptr + ptrdelta >= buffer + size)
158 return;
e05edd9 almost ready SNMP support
roberto@sirius authored
159
e0882ed big update: hooks and plugins
roberto@sirius authored
160 if (snmp_int != 0)
161 return;
aa9c533 re-indent all the code
roberto@sirius authored
162 ptr += ptrdelta;
e0882ed big update: hooks and plugins
roberto@sirius authored
163
9285b40 SNMP test
roberto authored
164 #ifdef UWSGI_DEBUG
165 uwsgi_debug("SNMP int [1]: %d\n", snmp_int);
166 #endif
167
e0882ed big update: hooks and plugins
roberto@sirius authored
168 // check for sequence
169 if (*ptr != SNMP_SEQUENCE)
aa9c533 re-indent all the code
roberto@sirius authored
170 return;
e0882ed big update: hooks and plugins
roberto@sirius authored
171 ptr++;
172
e05edd9 almost ready SNMP support
roberto@sirius authored
173
174 if (*ptr > SNMP_WATERMARK)
aa9c533 re-indent all the code
roberto@sirius authored
175 return;
e05edd9 almost ready SNMP support
roberto@sirius authored
176 seq2 = ptr;
177 ptr++;
e0882ed big update: hooks and plugins
roberto@sirius authored
178
e05edd9 almost ready SNMP support
roberto@sirius authored
179 // now the interesting stuff: OID management
180 if (*ptr != SNMP_SEQUENCE)
e0882ed big update: hooks and plugins
roberto@sirius authored
181 return;
e05edd9 almost ready SNMP support
roberto@sirius authored
182 ptr++;
aa9c533 re-indent all the code
roberto@sirius authored
183
e05edd9 almost ready SNMP support
roberto@sirius authored
184 // check for normal OID uWSGI size: |1.3|.6|.1|.4|.1.|35156|.17|.1/2|.x| + OID_NULL
185 asnlen = *ptr;
186 if (asnlen < 15)
aa9c533 re-indent all the code
roberto@sirius authored
187 return;
e05edd9 almost ready SNMP support
roberto@sirius authored
188 seq3 = ptr;
189 ptr++;
aa9c533 re-indent all the code
roberto@sirius authored
190
9285b40 SNMP test
roberto authored
191 #ifdef UWSGI_DEBUG
192 uwsgi_debug("SNMP ASN len: %d\n", asnlen);
193 #endif
194
e05edd9 almost ready SNMP support
roberto@sirius authored
195 // is it an OID ?
196 if (*ptr != SNMP_OID)
197 return;
198 ptr++;
aa9c533 re-indent all the code
roberto@sirius authored
199
e05edd9 almost ready SNMP support
roberto@sirius authored
200 oidlen = *ptr;
201 if (oidlen != 11)
202 return;
203 ptr++;
e0882ed big update: hooks and plugins
roberto@sirius authored
204
e05edd9 almost ready SNMP support
roberto@sirius authored
205 // and now parse the OID !!!
206 if (memcmp(ptr, SNMP_UWSGI_BASE, 9))
207 return;
e0882ed big update: hooks and plugins
roberto@sirius authored
208
e05edd9 almost ready SNMP support
roberto@sirius authored
209 ptr += 9;
e0882ed big update: hooks and plugins
roberto@sirius authored
210
e05edd9 almost ready SNMP support
roberto@sirius authored
211 oid_part[0] = *ptr;
e0882ed big update: hooks and plugins
roberto@sirius authored
212
e05edd9 almost ready SNMP support
roberto@sirius authored
213 if (oid_part[0] != 1 && oid_part[0] != 2)
214 return;
215 ptr++;
e0882ed big update: hooks and plugins
roberto@sirius authored
216
e05edd9 almost ready SNMP support
roberto@sirius authored
217 oid_part[1] = *ptr;
218 if (oid_part[1] < 1 || oid_part[1] > 100)
219 return;
220 ptr++;
e0882ed big update: hooks and plugins
roberto@sirius authored
221
e05edd9 almost ready SNMP support
roberto@sirius authored
222 // check for null
223 if (memcmp((char *) ptr, "\x05\x00", 2))
224 return;
225 ptr += 2;
aa9c533 re-indent all the code
roberto@sirius authored
226
e05edd9 almost ready SNMP support
roberto@sirius authored
227 size = build_snmp_response(oid_part[0], oid_part[1], buffer, size, seq1, seq2, seq3);
e0882ed big update: hooks and plugins
roberto@sirius authored
228
229 if (size > 0) {
aa9c533 re-indent all the code
roberto@sirius authored
230 if (sendto(fd, buffer, size, 0, (struct sockaddr *) client_addr, sizeof(struct sockaddr_in)) < 0) {
02a1847 async memory fixes
roberto@sirius authored
231 uwsgi_error("sendto()");
e0882ed big update: hooks and plugins
roberto@sirius authored
232 }
233 }
234 }
235
e05edd9 almost ready SNMP support
roberto@sirius authored
236 static uint64_t get_uwsgi_snmp_value(uint64_t val, uint8_t * oid_t) {
e0882ed big update: hooks and plugins
roberto@sirius authored
237
e05edd9 almost ready SNMP support
roberto@sirius authored
238 val--;
e0882ed big update: hooks and plugins
roberto@sirius authored
239
e05edd9 almost ready SNMP support
roberto@sirius authored
240 if (uwsgi.shared->snmp_gvalue[val].type) {
241 *oid_t = uwsgi.shared->snmp_gvalue[val].type;
242 return *uwsgi.shared->snmp_gvalue[val].val;
243 }
244
245 *oid_t = SNMP_NULL;
246 return 0;
247 }
e0882ed big update: hooks and plugins
roberto@sirius authored
248
e05edd9 almost ready SNMP support
roberto@sirius authored
249 static uint64_t get_uwsgi_custom_snmp_value(uint64_t val, uint8_t * oid_t) {
e0882ed big update: hooks and plugins
roberto@sirius authored
250
e05edd9 almost ready SNMP support
roberto@sirius authored
251 val--;
252 if (uwsgi.shared->snmp_value[val].type) {
253 *oid_t = uwsgi.shared->snmp_value[val].type;
254 return uwsgi.shared->snmp_value[val].val;
aa9c533 re-indent all the code
roberto@sirius authored
255 }
e0882ed big update: hooks and plugins
roberto@sirius authored
256
e05edd9 almost ready SNMP support
roberto@sirius authored
257 *oid_t = SNMP_NULL;
258 return 0;
e0882ed big update: hooks and plugins
roberto@sirius authored
259 }
260
aa9c533 re-indent all the code
roberto@sirius authored
261 static int get_snmp_integer(uint8_t * ptr, uint64_t * val) {
e05edd9 almost ready SNMP support
roberto@sirius authored
262
aa9c533 re-indent all the code
roberto@sirius authored
263 uint16_t tlen;
e05edd9 almost ready SNMP support
roberto@sirius authored
264 int i, j;
265
b245307 stricter compiler flags
riccardo@montag authored
266 uint8_t *cval = (uint8_t *) val;
267
e05edd9 almost ready SNMP support
roberto@sirius authored
268 tlen = *ptr;
e0882ed big update: hooks and plugins
roberto@sirius authored
269
e05edd9 almost ready SNMP support
roberto@sirius authored
270 if (tlen > 4)
271 return -1;
e0882ed big update: hooks and plugins
roberto@sirius authored
272
9285b40 SNMP test
roberto authored
273 #ifdef UWSGI_DEBUG
b245307 stricter compiler flags
riccardo@montag authored
274 uwsgi_debug("SNMP get integer TLEN %d %p\n", tlen, ptr);
9285b40 SNMP test
roberto authored
275 #endif
e0882ed big update: hooks and plugins
roberto@sirius authored
276
e05edd9 almost ready SNMP support
roberto@sirius authored
277 j = 0;
e0882ed big update: hooks and plugins
roberto@sirius authored
278 #ifdef __BIG_ENDIAN__
e05edd9 almost ready SNMP support
roberto@sirius authored
279 for (i = 0; i < tlen; i++) {
e0882ed big update: hooks and plugins
roberto@sirius authored
280 #else
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
281 for (i = tlen - 1; i >= 0; i--) {
e0882ed big update: hooks and plugins
roberto@sirius authored
282 #endif
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
283 cval[j] = ptr[1 + i];
284 j++;
285 }
e0882ed big update: hooks and plugins
roberto@sirius authored
286
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
287 return tlen + 1;
288 }
e0882ed big update: hooks and plugins
roberto@sirius authored
289
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
290 static uint8_t snmp_int_to_snmp(uint64_t snmp_val, uint8_t oid_type, uint8_t * buffer) {
291 uint8_t tlen;
292 int i, j;
293 uint8_t *ptr = (uint8_t *) &snmp_val;
e0882ed big update: hooks and plugins
roberto@sirius authored
294
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
295 // check for counter, counter64 or gauge
e0882ed big update: hooks and plugins
roberto@sirius authored
296
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
297 if (oid_type == SNMP_COUNTER64) {
298 tlen = 8;
299 }
300 else if (oid_type == SNMP_NULL || oid_type == 0) {
301 tlen = 0;
302 }
303 else {
304 tlen = 4;
305 }
e0882ed big update: hooks and plugins
roberto@sirius authored
306
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
307 buffer[0] = tlen;
e0882ed big update: hooks and plugins
roberto@sirius authored
308
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
309 j = 1;
e0882ed big update: hooks and plugins
roberto@sirius authored
310 #ifdef __BIG_ENDIAN__
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
311 for (i = 0; i < tlen; i++) {
e0882ed big update: hooks and plugins
roberto@sirius authored
312 #else
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
313 for (i = tlen - 1; i >= 0; i--) {
e0882ed big update: hooks and plugins
roberto@sirius authored
314 #endif
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
315 buffer[j] = ptr[i];
316 j++;
317 }
e0882ed big update: hooks and plugins
roberto@sirius authored
318
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
319 return tlen + 1;
320 }
e05edd9 almost ready SNMP support
roberto@sirius authored
321
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
322 static ssize_t build_snmp_response(uint8_t oid1, uint8_t oid2, uint8_t * buffer, int size, uint8_t * seq1, uint8_t * seq2, uint8_t * seq3) {
323 uint64_t snmp_val;
324 uint8_t oid_sz;
325 uint8_t oid_type;
e05edd9 almost ready SNMP support
roberto@sirius authored
326
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
327 if (oid1 == 1) {
328 snmp_val = get_uwsgi_snmp_value(oid2, &oid_type);
329 }
330 else if (oid1 == 2) {
331 snmp_val = get_uwsgi_custom_snmp_value(oid2, &oid_type);
332 }
333 else {
334 return -1;
335 }
e05edd9 almost ready SNMP support
roberto@sirius authored
336
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
337 buffer[size - 2] = oid_type;
338 oid_sz = snmp_int_to_snmp(snmp_val, oid_type, buffer + (size - 1));
e0882ed big update: hooks and plugins
roberto@sirius authored
339
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
340 if (oid_sz < 1)
341 return -1;
e05edd9 almost ready SNMP support
roberto@sirius authored
342
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
343 oid_sz--;
e05edd9 almost ready SNMP support
roberto@sirius authored
344
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
345 buffer[1] += oid_sz;
346 *seq1 += oid_sz;
347 *seq2 += oid_sz;
348 *seq3 += oid_sz;
e05edd9 almost ready SNMP support
roberto@sirius authored
349
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
350 return size + oid_sz;
e05edd9 almost ready SNMP support
roberto@sirius authored
351
8668b9a applied Dan Loewenherz stylish patch
roberto@sirius authored
352 }
d46a8db ported snmp to new options api
roberto@oneiric64 authored
353
354 void uwsgi_opt_snmp(char *opt, char *value, void *foobar) {
355 uwsgi.snmp = 1;
356 if (value) {
2043127 fixed snmp support
roberto@precise64 authored
357 uwsgi.snmp_addr = value;
358 uwsgi.master_process = 1;
d46a8db ported snmp to new options api
roberto@oneiric64 authored
359 }
360
361 }
362
363 void uwsgi_opt_snmp_community(char *opt, char *value, void *foobar) {
364 uwsgi.snmp = 1;
365 uwsgi.snmp_community = value;
366 }
d8d2923 refactored snmp
roberto@precise64 authored
367
368 int uwsgi_setup_snmp(void) {
369 int snmp_fd = -1;
370 int i;
371 if (uwsgi.snmp) {
372 if (uwsgi.snmp_community) {
373 if (strlen(uwsgi.snmp_community) > 72) {
374 uwsgi_log("*** warning the supplied SNMP community string will be truncated to 72 chars ***\n");
375 memcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, 72);
376 }
377 else {
378 memcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, strlen(uwsgi.snmp_community) + 1);
379 }
380 }
381
382 uwsgi.shared->snmp_gvalue[0].type = SNMP_COUNTER64;
383 uwsgi.shared->snmp_gvalue[0].val = &uwsgi.workers[0].requests;
384
385 for (i = 0; i < uwsgi.numproc; i++) {
386 uwsgi.shared->snmp_gvalue[30 + i].type = SNMP_COUNTER64;
387 uwsgi.shared->snmp_gvalue[30 + i].val = &uwsgi.workers[i + 1].requests;
388 }
389
390 if (uwsgi.snmp_addr) {
391 snmp_fd = bind_to_udp(uwsgi.snmp_addr, 0, 0);
392 if (snmp_fd < 0) {
393 uwsgi_log("unable to bind to udp socket. SNMP service will be disabled.\n");
394 }
395 else {
396 uwsgi_log("SNMP server enabled on %s\n", uwsgi.snmp_addr);
397 event_queue_add_fd_read(uwsgi.master_queue, snmp_fd);
398 }
399 }
400 else {
401 uwsgi_log("SNMP agent enabled.\n");
402 }
403
404 }
405
406 return snmp_fd;
407 }
bed7682 useful XML support, first commit of uwsgiconfig.py
roberto@sirius authored
408 #else
409 #warning "*** SNMP support is disabled ***"
e0882ed big update: hooks and plugins
roberto@sirius authored
410 #endif
Something went wrong with that request. Please try again.