summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Friloux <guillaume.friloux@gmail.com>2013-12-26 15:36:45 +0100
committerGuillaume Friloux <guillaume.friloux@gmail.com>2013-12-26 15:36:45 +0100
commit7648d81d7cab7a537c3c7f6a660e394bb097f765 (patch)
treedebe4c2a55c1ca7f95b6a46adeddfe47ade06b86
parentf428b4124d46bef42940f31a04945db762fe8d70 (diff)
Smman can now insert logs into ES.
-rw-r--r--src/bin/config.c9
-rw-r--r--src/bin/log.c44
-rw-r--r--src/bin/main.c3
-rw-r--r--src/lib/store/store_event.c2
4 files changed, 39 insertions, 19 deletions
diff --git a/src/bin/config.c b/src/bin/config.c
index 4c29e34..192feb0 100644
--- a/src/bin/config.c
+++ b/src/bin/config.c
@@ -6,6 +6,7 @@ config_done(void *data,
6{ 6{
7 Smman *smman; 7 Smman *smman;
8 Eina_Iterator *it; 8 Eina_Iterator *it;
9 char *s;
9 10
10 smman = data; 11 smman = data;
11 12
@@ -29,7 +30,13 @@ config_done(void *data,
29 DBG("Host = %s", smman->cfg.host); 30 DBG("Host = %s", smman->cfg.host);
30 eina_iterator_free(it); 31 eina_iterator_free(it);
31 32
32 smman->store = store_new(smman->cfg.server); 33 s = sdupf("%s%s%s",
34 smman->cfg.server,
35 (smman->cfg.server[strlen(smman->cfg.server)-1] == '/') ?
36 "" : "/",
37 "logs/");
38 smman->store = store_new(s);
39 free(s);
33} 40}
34 41
35void 42void
diff --git a/src/bin/log.c b/src/bin/log.c
index 0ecfe4c..87c1af4 100644
--- a/src/bin/log.c
+++ b/src/bin/log.c
@@ -11,6 +11,27 @@ typedef struct _Log
11} Log; 11} Log;
12 12
13void 13void
14_log_done(void *data,
15 Store *store EINA_UNUSED,
16 char *answer,
17 size_t len)
18{
19 Smman *smman = data;
20
21 DBG("smman[%p] Having a %zd bytes answer : \n%s\n", smman, len, answer);
22}
23
24void
25_log_error(void *data,
26 Store *store EINA_UNUSED,
27 char *strerr)
28{
29 Smman *smman = data;
30
31 ERR("smman[%p] Failed to store data :\n%s\n", smman, strerr);
32}
33
34void
14_log_send(Smman *smman, 35_log_send(Smman *smman,
15 Log *log) 36 Log *log)
16{ 37{
@@ -18,7 +39,8 @@ _log_send(Smman *smman,
18 *json_tags; 39 *json_tags;
19 char *source, 40 char *source,
20 *date, 41 *date,
21 *tag; 42 *tag,
43 *s;
22 Eina_List *l; 44 Eina_List *l;
23 45
24 json = cJSON_CreateObject(); 46 json = cJSON_CreateObject();
@@ -53,10 +75,13 @@ _log_send(Smman *smman,
53 cJSON_AddStringToObject(json, "@source_host", log->source_host); 75 cJSON_AddStringToObject(json, "@source_host", log->source_host);
54 cJSON_AddStringToObject(json, "@source_path", log->source_path); 76 cJSON_AddStringToObject(json, "@source_path", log->source_path);
55 77
78 s = cJSON_Print(json);
56 79
80 store_add(smman->store, s, strlen(s), _log_done, _log_error, smman);
81
82 free(s);
57 free(date); 83 free(date);
58 free(source); 84 free(source);
59 DBG("JSON = \n%s", cJSON_Print(json));
60 cJSON_Delete(json); 85 cJSON_Delete(json);
61} 86}
62 87
@@ -90,7 +115,6 @@ _log_line_match(const char *log, Rule *rule)
90 r = regexec(&(rr->preg), log, nmatch, pmatch, 0); 115 r = regexec(&(rr->preg), log, nmatch, pmatch, 0);
91 if (r == rr->must_match) 116 if (r == rr->must_match)
92 { 117 {
93 NFO("Log \"%s\" is not affected by rule %s", log, rule->name);
94 excluded = EINA_TRUE; 118 excluded = EINA_TRUE;
95 break; 119 break;
96 } 120 }
@@ -127,12 +151,9 @@ log_line_event(void *data,
127 it = eina_hash_iterator_tuple_new(filter->rules); 151 it = eina_hash_iterator_tuple_new(filter->rules);
128 while (eina_iterator_next(it, (void **)&t)) 152 while (eina_iterator_next(it, (void **)&t))
129 { 153 {
130 const char *name;
131 Eina_List *l; 154 Eina_List *l;
132 155
133 name = t->key;
134 rule = t->data; 156 rule = t->data;
135 DBG("rule[%p][%s]", rule, name);
136 157
137 r = _log_line_match(spy_line_get(sl), rule); 158 r = _log_line_match(spy_line_get(sl), rule);
138 if (!r) 159 if (!r)
@@ -158,17 +179,6 @@ log_line_event(void *data,
158 if (log->todel) 179 if (log->todel)
159 return EINA_TRUE; 180 return EINA_TRUE;
160 181
161
162 DBG("Log to index :\n"
163 "\tmessage = %s\n"
164 "\tfilename = %s\n"
165 "\tsource_host = %s\n"
166 "\tsource_path = %s",
167 log->message,
168 log->filename,
169 log->source_host,
170 log->source_path);
171
172 _log_send(smman, log); 182 _log_send(smman, log);
173 183
174 _log_free(log); 184 _log_free(log);
diff --git a/src/bin/main.c b/src/bin/main.c
index 6f85a98..9a73992 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -112,6 +112,7 @@ int main(int argc, char **argv)
112 conf_init(); 112 conf_init();
113 rules_init(); 113 rules_init();
114 spy_init(); 114 spy_init();
115 store_init();
115 116
116 smman = init(); 117 smman = init();
117 if (!smman) 118 if (!smman)
@@ -123,6 +124,8 @@ int main(int argc, char **argv)
123 124
124 ecore_main_loop_begin(); 125 ecore_main_loop_begin();
125 126
127 store_shutdown();
128 spy_shutdown();
126 rules_shutdown(); 129 rules_shutdown();
127 conf_shutdown(); 130 conf_shutdown();
128 ecore_shutdown(); 131 ecore_shutdown();
diff --git a/src/lib/store/store_event.c b/src/lib/store/store_event.c
index 4f23c7d..73533f4 100644
--- a/src/lib/store/store_event.c
+++ b/src/lib/store/store_event.c
@@ -38,7 +38,7 @@ store_event_complete(void *data,
38 return EINA_TRUE; 38 return EINA_TRUE;
39 39
40 http_code = ecore_con_url_status_code_get(sa->ec); 40 http_code = ecore_con_url_status_code_get(sa->ec);
41 if (http_code != 200) 41 if ((http_code != 200) && (http_code != 201))
42 { 42 {
43 errstr = store_utils_dupf("Server replied HTTP code %i", http_code); 43 errstr = store_utils_dupf("Server replied HTTP code %i", http_code);
44 sa->cb.error((void *)sa->cb.data, sa->store, errstr); 44 sa->cb.error((void *)sa->cb.data, sa->store, errstr);