-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.c
86 lines (72 loc) · 2.05 KB
/
demo.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "kflow.h"
int main(int argc, char **argv) {
char *err;
int r;
kflowConfig cfg = {
.URL = "http://127.0.0.1:8999/chf",
.API = {
.email = "[email protected]",
.token = "token",
.URL = "http://127.0.0.1:8999/api/internal",
},
.metrics = {
.interval = 1,
.URL = "http://127.0.0.1:8999/tsdb",
},
.device_id = 1,
.verbose = 1,
.program = "demo",
.version = "0.0.1",
};
kflowDevice device;
kflowCustom *customs;
uint32_t numCustoms;
if ((r = kflowInit(&cfg, &device)) != 0) {
printf("error initializing libkflow: %d\n", r);
goto error;
};
customs = device.customs;
numCustoms = device.num_customs;
char *url = "http://foo.com";
for (uint32_t i = 0; i < numCustoms; i++) {
if (!strcmp(customs[i].name, KFLOWCUSTOM_HTTP_URL)) {
customs[i].value.str = url;
} else if (!strcmp(customs[i].name, KFLOWCUSTOM_HTTP_STATUS)) {
customs[i].value.u32 = 200;
} else {
free(customs[i].name);
memmove(&customs[i], &customs[i+1], sizeof(kflowCustom)*(numCustoms-i-1));
numCustoms--; i--;
}
}
kflow flow = {
.deviceId = cfg.device_id,
.ipv4SrcAddr = 167772161,
.ipv4DstAddr = 167772162,
.srcAs = 1234,
.inPkts = 20,
.inBytes = 40,
.srcEthMac = 1250999896491,
.dstEthMac = 226426397786884,
.customs = customs,
.numCustoms = numCustoms,
};
if ((r = kflowSend(&flow)) != 0) {
printf("error sending flow: %d\n", r);
goto error;
}
if ((r = kflowStop(10*1000)) != 0) {
printf("error stopping libkflow: %d\n", r);
goto error;
}
return 0;
error:
while ((err = kflowError()) != NULL) {
printf("libkflow error: %s\n", err);
free(err);
}
exit(1);
}