summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Friloux <guillaume.friloux@gmail.com>2013-12-13 09:13:12 +0100
committerGuillaume Friloux <guillaume.friloux@gmail.com>2013-12-13 09:13:12 +0100
commit0e4de792483f8539c4a60c9d1d0b6f567b2e8cfb (patch)
tree41031351c968ed7e965e7cc822edd34ccdbd3c03
parent371d0cfc0c02dfc6889be3b7e3100d380e65410a (diff)
Less files is better.
Also removed some doxygen doc.
-rw-r--r--src/bin/Makefile.mk2
-rw-r--r--src/bin/conf.c13
-rw-r--r--src/bin/conf.h33
-rw-r--r--src/bin/date.c47
-rw-r--r--src/bin/global.h113
-rw-r--r--src/bin/logfiles.c20
-rw-r--r--src/bin/logfiles.h40
-rw-r--r--src/bin/logmessages.c19
-rw-r--r--src/bin/logmessages.h36
-rw-r--r--src/bin/main.c195
-rw-r--r--src/bin/main.h42
-rw-r--r--src/bin/rules.c5
-rw-r--r--src/bin/rules.h47
-rw-r--r--src/bin/send.c19
-rw-r--r--src/bin/send.h43
-rw-r--r--src/bin/smman.h155
-rw-r--r--src/bin/spy.c23
-rw-r--r--src/bin/spy.h40
-rw-r--r--src/bin/utils.c (renamed from src/bin/date.h)34
19 files changed, 252 insertions, 674 deletions
diff --git a/src/bin/Makefile.mk b/src/bin/Makefile.mk
index a789388..0246c79 100644
--- a/src/bin/Makefile.mk
+++ b/src/bin/Makefile.mk
@@ -6,7 +6,7 @@ src/bin/smman
6 6
7src_bin_smman_SOURCES = \ 7src_bin_smman_SOURCES = \
8src/bin/conf.c \ 8src/bin/conf.c \
9src/bin/date.c \ 9src/bin/utils.c \
10src/bin/libconf.c \ 10src/bin/libconf.c \
11src/bin/logfiles.c \ 11src/bin/logfiles.c \
12src/bin/logmessages.c \ 12src/bin/logmessages.c \
diff --git a/src/bin/conf.c b/src/bin/conf.c
index f60be69..8b65a1a 100644
--- a/src/bin/conf.c
+++ b/src/bin/conf.c
@@ -16,18 +16,10 @@
16 * 16 *
17 */ 17 */
18 18
19/** 19#include "smman.h"
20 * @file conf.c 20#include "libconf.h"
21 * @brief Manages configuration loading
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Manages configuration loading
26 */
27#include "conf.h"
28 21
29/** 22/**
30 * @fn int conf_load(void)
31 * @brief This function will init libconf and ask to load our configuration 23 * @brief This function will init libconf and ask to load our configuration
32 * file 24 * file
33 * 25 *
@@ -59,7 +51,6 @@ int conf_load(void)
59} 51}
60 52
61/** 53/**
62 * @fn int conf_load_var(char *variable, char *value)
63 * @brief This function is a callback for libconf, and receives a variable + 54 * @brief This function is a callback for libconf, and receives a variable +
64 * its value found in a configuration file 55 * its value found in a configuration file
65 * 56 *
diff --git a/src/bin/conf.h b/src/bin/conf.h
deleted file mode 100644
index f598cea..0000000
--- a/src/bin/conf.h
+++ /dev/null
@@ -1,33 +0,0 @@
1/*
2 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19/**
20 * @file conf.h
21 * @brief Contains all includes and prototypes for conf.c
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Contains all includes and prototypes for conf.c
26 */
27#include <unistd.h>
28
29#include "libconf.h"
30#include "global.h"
31
32int conf_load(void);
33int conf_load_var(char *variable, char *value);
diff --git a/src/bin/date.c b/src/bin/date.c
deleted file mode 100644
index 44e0857..0000000
--- a/src/bin/date.c
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19/**
20 * @file date.c
21 * @brief Gets us the current date, like logstash does
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Gets us the current date, like logstash does
26 */
27
28#include "date.h"
29
30/**
31 * @fn char * timestamp_XML(char * date)
32 * @brief Gets us the current date, like logstash does
33 * @bug it doesnt get us date in UTC format, it gets us date on the system
34 *
35 * @param date (char *) Buffer where we will store the date
36 *
37 * @return 0
38 */
39char * timestamp_XML(char * date)
40{
41 time_t temps;
42 struct tm temp;
43 temps=time(NULL);
44 localtime_r(&temps,&temp);
45 sprintf(date,"%04d-%02d-%02dT%02d:%02d:%02d.000000Z",(temp.tm_year)+1900,(temp.tm_mon)+1,temp.tm_mday,temp.tm_hour,temp.tm_min,temp.tm_sec);
46 return(date);
47}
diff --git a/src/bin/global.h b/src/bin/global.h
deleted file mode 100644
index cc6fe43..0000000
--- a/src/bin/global.h
+++ /dev/null
@@ -1,113 +0,0 @@
1/*
2 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19/**
20 * @file global.h
21 * @brief Contains all global variables we need
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 * @todo It could be improved because not all structs are used everywhere.
25 *
26 * Contains all global variables we need
27 */
28#ifdef HAVE_CONFIG_H
29# include "config.h"
30#endif
31
32#include <Eina.h>
33#include <Ecore.h>
34#include <Ecore_File.h>
35#include <regex.h>
36
37#ifndef GLOBALVARS
38#define GLOBALVARS
39char global_rulesdir[35], /**< Allows us to store the rules directory */
40 global_conf[35], /**< Allows us to store the configuration directory */
41 global_host[35], /**< Allows us to store the default hostname */
42 global_type[35], /**< Allows us to store the default type */
43 global_ESserver[128]; /**< Allows us to store ElasticSearch server adress */
44
45/**
46 * @struct rule
47 * @brief This structure can handle a rule described in the rule directory
48 */
49struct rule
50{
51 char *name, /**< Rule's name (Guessed using the filename of the rule inside the rules directory) */
52 *filename, /**< It is the filename of the logfile(s) that match this rule (see this as a condition) */
53 *type, /**< Type we will apply to the matched log message (see this as an affectation) */
54 *source_host, /**< Host we will apply to the matched log message (see this as an affectation) */
55 *source_path, /**< Log path we will apply to the matched log message (its like renaming the log, without mv it) (see this as an affectation) */
56 *tags; /**< tags we will apply to the matched log message (see this as an affectation) */
57 int todel; /**< If set to something other than 0, every matched rule will not be indexed */
58 Eina_List *list_regex; /**< Regexps to apply to message we get from syslog, then match them (see this as a condition) */
59};
60
61/**
62 * @struct regex
63 * @brief This structure can handle a regex that will be compared to log messages
64 * in order to see if they are affected by a rule or not
65 */
66struct regex
67{
68 char *message;
69 int must_match;
70 regex_t preg;
71};
72
73/**
74 * @struct logfile
75 * @brief This structure allows us to attach a cursor position to a logfile,
76 * which is necessary to find new log entries
77 */
78struct logfile
79{
80 char *name; /**< Name of the log file */
81 fpos_t cursor; /**< Position of the cursor inside this logfile */
82 unsigned long long int
83 filesize; /**< File size, only help to see if a logfile is truncated, as far as i know */
84};
85
86/**
87 * @struct logmessage
88 * @brief This structure Contains needed information about a logfile that is going
89 * to be JSONed for ES.
90 */
91struct logmessage
92{
93 char *source_host, /**< Hostname */
94 *source_path, /**< Name of the logfile from where this message comes from */
95 timestamp[30], /**< Date of the log */
96 *type, /**< Type of message */
97 *message; /**< Log message to index in ES */
98 Eina_List *list_tags; /**< List of tags associated to this message */
99 int todel; /**< If set to something other than 0, this message wont be indexed */
100};
101
102int einadom_rules, /**< Used for eina_log inside rules.c */
103 einadom_spy, /**< Used for eina_log inside spy.c */
104 einadom_logfiles, /**< Used for eina_log inside logfiles.c */
105 einadom_send, /**< Used for eina_log inside send.c */
106 einadom_conf; /**< Used for eina_log inside conf.c */
107
108Eina_List *list_rules; /**< Used to store all the rules in memory, in an eina list */
109Eina_List *list_logfiles; /**< Used to store all the logfiles watched, in an eina list */
110
111Ecore_File_Monitor *efm; /**< Used for file monitoring by ecore */
112
113#endif
diff --git a/src/bin/logfiles.c b/src/bin/logfiles.c
index dcc1e77..c8f08a8 100644
--- a/src/bin/logfiles.c
+++ b/src/bin/logfiles.c
@@ -16,25 +16,14 @@
16 * 16 *
17 */ 17 */
18 18
19/**
20 * @file logfiles.c
21 * @brief Manages log files list
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Manages log files list
26 * @see logfile
27 * @see list_logfiles
28 */
29#ifdef HAVE_CONFIG_H 19#ifdef HAVE_CONFIG_H
30# include "config.h" 20# include "config.h"
31#endif 21#endif
32 22
33 23
34#include "logfiles.h" 24#include "smman.h"
35 25
36/** 26/**
37 * @fn int logfiles_exist(char *logfile)
38 * @brief Checks in the list of log files we are watching if we 27 * @brief Checks in the list of log files we are watching if we
39 * already watch a given logfile 28 * already watch a given logfile
40 * 29 *
@@ -58,7 +47,6 @@ int logfiles_exist(char *logfile)
58} 47}
59 48
60/** 49/**
61 * @fn int logfiles_add(struct logfile *new_logfile)
62 * @brief Adds a logfile struct inside the logfiles list 50 * @brief Adds a logfile struct inside the logfiles list
63 * 51 *
64 * @param new_logfile (struct logfile *) structure to add 52 * @param new_logfile (struct logfile *) structure to add
@@ -72,7 +60,6 @@ int logfiles_add(struct logfile *new_logfile)
72} 60}
73 61
74/** 62/**
75 * @fn int logfiles_print(void)
76 * @brief Prints on stdout the list of logfiles. Only usefull for a bit of 63 * @brief Prints on stdout the list of logfiles. Only usefull for a bit of
77 * monitoring of what is going on 64 * monitoring of what is going on
78 * 65 *
@@ -90,7 +77,6 @@ int logfiles_print(void)
90} 77}
91 78
92/** 79/**
93 * @fn int logfiles_new(struct logfile **new_logfile, char *filename, fpos_t cursor, unsigned long long int filesize)
94 * @brief Will alloc a new logfile structure and set given values 80 * @brief Will alloc a new logfile structure and set given values
95 * 81 *
96 * @param new_logfile (struct logfile *) structure to alloc 82 * @param new_logfile (struct logfile *) structure to alloc
@@ -112,7 +98,6 @@ int logfiles_new(struct logfile **new_logfile, char *filename, fpos_t cursor, un
112} 98}
113 99
114/** 100/**
115 * @fn int logfiles_del(struct logfile **old_logfile)
116 * @brief This function will free an allocated logfile structure 101 * @brief This function will free an allocated logfile structure
117 * 102 *
118 * @param old_logfile (struct logfile **) structure to free 103 * @param old_logfile (struct logfile **) structure to free
@@ -132,7 +117,6 @@ int logfiles_del(struct logfile **old_logfile)
132} 117}
133 118
134/** 119/**
135 * @fn int logfiles_getend(char *logfile, fpos_t *pos_end)
136 * @brief This function will get a cursor to the end of the file 120 * @brief This function will get a cursor to the end of the file
137 * 121 *
138 * @param logfile (char *) logfile involved 122 * @param logfile (char *) logfile involved
@@ -159,7 +143,6 @@ int logfiles_getend(char *logfile, fpos_t *pos_end)
159} 143}
160 144
161/** 145/**
162 * @fn int logfiles_getbegin(char *logfile, fpos_t *pos_begin)
163 * @brief This function will get a cursor to the begin of the file 146 * @brief This function will get a cursor to the begin of the file
164 * 147 *
165 * @param logfile (char *) logfile involved 148 * @param logfile (char *) logfile involved
@@ -185,7 +168,6 @@ int logfiles_getbegin(char *logfile, fpos_t *pos_begin)
185} 168}
186 169
187/** 170/**
188 * @fn int logfiles_getsize(char *logfile, unsigned long long int *filesize)
189 * @brief This function will get the size of a file 171 * @brief This function will get the size of a file
190 * 172 *
191 * @param logfile (char *) logfile involved 173 * @param logfile (char *) logfile involved
diff --git a/src/bin/logfiles.h b/src/bin/logfiles.h
deleted file mode 100644
index dc9e0db..0000000
--- a/src/bin/logfiles.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19/**
20 * @file logfiles.h
21 * @brief Contains all includes and prototypes for logfiles.c
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Contains all includes and prototypes for logfiles.c
26 */
27#include <errno.h>
28#include <sys/stat.h>
29
30#include "global.h"
31
32int logfiles_exist(char *logfile);
33int logfiles_add(struct logfile *new_logfile);
34int logfiles_print(void);
35int logfiles_new(struct logfile **new_logfile, char *filename, fpos_t cursor, unsigned long long int filesize);
36int logfiles_del(struct logfile **old_logfile);
37int logfiles_getend(char *logfile, fpos_t *pos_end);
38int logfiles_getbegin(char *logfile, fpos_t *pos_begin);
39int logfiles_getsize(char *logfile, unsigned long long int *filesize);
40
diff --git a/src/bin/logmessages.c b/src/bin/logmessages.c
index 6cfc8d9..aece58c 100644
--- a/src/bin/logmessages.c
+++ b/src/bin/logmessages.c
@@ -16,18 +16,9 @@
16 * 16 *
17 */ 17 */
18 18
19/** 19#include "smman.h"
20 * @file logmessages.c
21 * @brief Contains functions that helps manipulating logmessage structure
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Contains functions that helps manipulating logmessage structure
26 */
27#include "logmessages.h"
28 20
29/** 21/**
30 * @fn int logmessages_new(struct logmessage **new_logmessage, char *message, char *logname)
31 * @brief This function will init a given logmessage structure with default values 22 * @brief This function will init a given logmessage structure with default values
32 * 23 *
33 * @param new_logmessage (struct logmessage **) struct to alloc 24 * @param new_logmessage (struct logmessage **) struct to alloc
@@ -59,7 +50,7 @@ int logmessages_new(struct logmessage **new_logmessage, char *message, char *log
59 (*new_logmessage)->type = malloc( sizeof(char) * ( strlen(global_type) + 1 ) ); 50 (*new_logmessage)->type = malloc( sizeof(char) * ( strlen(global_type) + 1 ) );
60 strcpy( (*new_logmessage)->type, global_type); 51 strcpy( (*new_logmessage)->type, global_type);
61 52
62 timestamp_XML( (*new_logmessage)->timestamp); 53 (*new_logmessage)->timestamp = utils_date();
63 54
64 (*new_logmessage)->list_tags = NULL; 55 (*new_logmessage)->list_tags = NULL;
65 (*new_logmessage)->todel = 0; 56 (*new_logmessage)->todel = 0;
@@ -67,7 +58,6 @@ int logmessages_new(struct logmessage **new_logmessage, char *message, char *log
67} 58}
68 59
69/** 60/**
70 * @fn int logmessages_free(struct logmessage **old_logmessage)
71 * @brief This function will free everything allocated in the structure 61 * @brief This function will free everything allocated in the structure
72 * 62 *
73 * @param old_logmessage (struct logmessage **) struct to free 63 * @param old_logmessage (struct logmessage **) struct to free
@@ -82,6 +72,7 @@ int logmessages_free(struct logmessage **old_logmessage)
82 free( (*old_logmessage)->source_path); 72 free( (*old_logmessage)->source_path);
83 free( (*old_logmessage)->type); 73 free( (*old_logmessage)->type);
84 free( (*old_logmessage)->message); 74 free( (*old_logmessage)->message);
75 free( (*old_logmessage)->timestamp);
85 76
86 EINA_LIST_FREE( (*old_logmessage)->list_tags, ptr) 77 EINA_LIST_FREE( (*old_logmessage)->list_tags, ptr)
87 free(ptr); 78 free(ptr);
@@ -90,7 +81,6 @@ int logmessages_free(struct logmessage **old_logmessage)
90} 81}
91 82
92/** 83/**
93 * @fn int logmessages_set_type(struct logmessage *mylog, char *type)
94 * @brief This function will set a given type to a given logmessage structure 84 * @brief This function will set a given type to a given logmessage structure
95 * 85 *
96 * @param mylog (struct logmessage *) Structure to modify 86 * @param mylog (struct logmessage *) Structure to modify
@@ -109,7 +99,6 @@ int logmessages_set_type(struct logmessage *mylog, char *type)
109} 99}
110 100
111/** 101/**
112 * @fn int logmessages_set_sourcehost(struct logmessage *mylog, char *source_host)
113 * @brief This function will set a given host to a given logmessage structure 102 * @brief This function will set a given host to a given logmessage structure
114 * 103 *
115 * @param mylog (struct logmessage *) Structure to modify 104 * @param mylog (struct logmessage *) Structure to modify
@@ -128,7 +117,6 @@ int logmessages_set_sourcehost(struct logmessage *mylog, char *source_host)
128} 117}
129 118
130/** 119/**
131 * @fn int logmessages_add_tag(struct logmessage *mylog, char *tag)
132 * @brief This function will add tags to the given logmessage structure. 120 * @brief This function will add tags to the given logmessage structure.
133 * Tags has to be separated by a "," 121 * Tags has to be separated by a ","
134 * 122 *
@@ -169,7 +157,6 @@ int logmessages_add_tag(struct logmessage *mylog, char *tag)
169} 157}
170 158
171/** 159/**
172 * @fn int logmessages_set_todel(struct logmessage *mylog, int value)
173 * @brief This function will set a given value to the delete field 160 * @brief This function will set a given value to the delete field
174 * 161 *
175 * @param mylog (struct logmessage *) Structure to modify 162 * @param mylog (struct logmessage *) Structure to modify
diff --git a/src/bin/logmessages.h b/src/bin/logmessages.h
deleted file mode 100644
index ee3af51..0000000
--- a/src/bin/logmessages.h
+++ /dev/null
@@ -1,36 +0,0 @@
1/*
2 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19/**
20 * @file logmessages.h
21 * @brief Contains all includes and prototypes for logmessages.c
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Contains all includes and prototypes for logmessages.c
26 */
27#include "global.h"
28#include "date.h"
29
30int logmessages_new(struct logmessage **new_logmessage, char *message, char *logname);
31int logmessages_free(struct logmessage **old_logmessage);
32int logmessages_set_type(struct logmessage *mylog, char *type);
33int logmessages_set_sourcehost(struct logmessage *mylog, char *source_host);
34int logmessages_add_tag(struct logmessage *mylog, char *tag);
35int logmessages_set_todel(struct logmessage *mylog, int value);
36
diff --git a/src/bin/main.c b/src/bin/main.c
index 11ea95e..0e739ff 100644
--- a/src/bin/main.c
+++ b/src/bin/main.c
@@ -16,151 +16,62 @@
16 * 16 *
17 */ 17 */
18 18
19/** 19#include "smman.h"
20 * @file main.c
21 * @brief Main functions
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * @todo make an exit if receiving SIGUSR1 so we never kill -9 it
26 * @todo Index all received messages in an EET file so we dont loose them
27 * if ES is down, if we have a network problem or if we get killed
28 *
29 * Main functions
30 *
31 */
32
33/**
34 * @mainpage Syslog Message MANager
35 *
36 * @author Guillaume Friloux <kuri@efl.so>
37 *
38 * @section INTRODUCTION Introduction
39 * SMMan is gateway between syslog files and an <a href=http://www.elasticsearch.com>ElasticSearch</a> database.<br />
40 * SMMan has a few more interesting stuff : He can tag every log he sees by using defined rules on them.<br />
41 * SMMan uses a configuration file, and needs rules files that must be written by the user of SMMan.<br />
42 * SMMan will then use these rules to monitor all the specified logfiles (using inotify), and extract every new entry
43 * to filter it using the rules and then indexing it in the configured <a href=http://www.elasticsearch.com>ElasticSearch</a> database.
44 * <img src=intro.png>
45 *
46 * <br />
47 * @section CONFIGURATION Configuration
48 * The configuration file has to be in <b>/etc/smman/smman.conf</b><br />
49 * For now, there is only 3 configurable variables :
50 * @li @b server : URL to <a href=http://www.elasticsearch.com>ElasticSearch</a> database. SMMan speaks to <a href=http://www.elasticsearch.com>ElasticSearch</a> using JSON.
51 * @li @b host : Allows you to set a different host that the one returned by command hostname (optionnal).
52 * @li @b type : Default type for all logs (optionnal).
53 *
54 *
55 * Exemple of configuration file : <br />
56 * @code
57 * server = http://localhost:9200/logstash/logs/
58 * host = BlackStar
59 * type = syslog
60 * @endcode
61 *
62 * <br />
63 * @section RULES Writing rules
64 * Writing rules is quite easy. SMMan search for rules in <b>/etc/smman/rules.d/</b><br />
65 * Check the rules directory in the source code to see examples of rules.<br />
66 * Basically, rules allows you to write matches about filenames or messages (using globbing/regexp), and set informations like :
67 * @li source_host : Set a custom hostname
68 * @li type : Set a custom type
69 * @li tags : Add tags to the message
70 * @li delete : Do not index the log, just drop it
71 *
72 * <br />
73 * @section LOGSTASH Why not using logstash ?
74 * @li Its written in ruby and i know nothing to ruby (so i cant modify anything).
75 * @li I have been able to make it crash just by deleting a monitored file, or by
76 * sending chars like éàè.
77 * @li I seem to be too stupid to understand how to automatically tag messages (using Grok, which adds a dependancy seemed complicated to me).
78 */
79#include "main.h"
80 20
81/** 21void _usage(char *progname)
82 * @fn int main(int argc, char **argv)
83 * @brief Main function, will launch all needed functions
84 *
85 * @param argc args count
86 * @param argv args
87 *
88 * @return 0, exit should not happen
89 */
90int main(int argc, char **argv)
91{ 22{
92 int c; 23 printf(" _______ \n");
93 eina_init(); 24 printf(" | _ |.--------..--------..---.-..-----.\n");
94 ecore_init(); 25 printf(" | 1___|| || || _ || |\n");
95 ecore_file_init(); 26 printf(" |____ ||__|__|__||__|__|__||___._||__|__|\n");
96 //send_init(); 27 printf(" |: 1 | \n");
97 28 printf(" |::.. . | Usage for %s : \n", progname);
98 send_connected = EINA_FALSE; 29 printf(" `-------' \n");
99 30 printf("\t--help\t\t-h :\tShow this help screen\n");
100 while( 1 ) 31 printf("\t--version\t-v :\tShow revision version\n");
101 { 32 printf("\n");
102 int option_index = 0; 33 printf("\tDebugging : \n");
103 34 printf("\t\tEINA_LOG_LEVEL=5 %s\n", progname);
104 static struct option long_options[] = {
105 {"help", 0, 0, 'h'},
106 {0, 0, 0, 0}
107 };
108
109 c = getopt_long(argc, argv, "h", long_options, &option_index);
110 if (c == -1) break;
111
112 switch (c)
113 {
114 case 'h':
115 usage(argv[0]);
116 exit(0);
117 default:
118 break;
119 }
120 }
121
122 // Read conf
123 conf_load();
124
125 // Load rules
126 rules_load();
127
128 // We show the list of loaded rules
129 // Unecessary
130 rules_print();
131
132 // Begin to spy files
133 spy_init();
134
135 // We show the list of files we will watch
136 // Unecessary
137 logfiles_print();
138
139 // We wait for events (new inserts in logfiles)
140 ecore_main_loop_begin();
141
142 return(0);
143} 35}
144 36
145/** 37int main(int argc, char **argv)
146 * @fn void usage(char *progname)
147 * @brief displays basic usage
148 * http://patorjk.com/software/taag/ Cricket font
149 *
150 * @param progname (char *) Name of program
151 */
152void usage(char *progname)
153{ 38{
154 printf(" _______ \n"); 39 int c;
155 printf(" | _ |.--------..--------..---.-..-----.\n"); 40 eina_init();
156 printf(" | 1___|| || || _ || |\n"); 41 ecore_init();
157 printf(" |____ ||__|__|__||__|__|__||___._||__|__|\n"); 42 ecore_file_init();
158 printf(" |: 1 | \n"); 43
159 printf(" |::.. . | Usage for %s : \n", progname); 44 send_connected = EINA_FALSE;
160 printf(" `-------' \n"); 45
161 printf("\t--help\t\t-h :\tShow this help screen\n"); 46 while (1)
162 printf("\t--version\t-v :\tShow revision version\n"); 47 {
163 printf("\n"); 48 int option_index = 0;
164 printf("\tDebugging : \n"); 49
165 printf("\t\tEINA_LOG_LEVEL=5 %s\n", progname); 50 static struct option long_options[] = {
51 {"help", 0, 0, 'h'},
52 {0, 0, 0, 0}
53 };
54
55 c = getopt_long(argc, argv, "h", long_options, &option_index);
56 if (c == -1) break;
57
58 switch (c)
59 {
60 case 'h':
61 _usage(argv[0]);
62 exit(0);
63 default:
64 break;
65 }
66 }
67
68 conf_load();
69 rules_load();
70 rules_print();
71 spy_init();
72 logfiles_print();
73
74 ecore_main_loop_begin();
75
76 return 0;
166} 77}
diff --git a/src/bin/main.h b/src/bin/main.h
deleted file mode 100644
index 9ad717a..0000000
--- a/src/bin/main.h
+++ /dev/null
@@ -1,42 +0,0 @@
1/*
2 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19/**
20 * @file main.h
21 * @brief Header file for main.c
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Header file for main.c
26 *
27 */
28
29#include <stdio.h>
30#include <Ecore.h>
31#include <Ecore_File.h>
32#include <getopt.h>
33
34#include "global.h"
35
36#include "rules.h"
37#include "spy.h"
38#include "conf.h"
39
40void usage(char *progname);
41void version(char *progname);
42
diff --git a/src/bin/rules.c b/src/bin/rules.c
index 70f1785..7c9e0bc 100644
--- a/src/bin/rules.c
+++ b/src/bin/rules.c
@@ -27,7 +27,10 @@
27 * Functions the manipulates rules 27 * Functions the manipulates rules
28 * 28 *
29 */ 29 */
30#include "rules.h" 30#include "smman.h"
31#include "libconf.h"
32
33struct rule *rules_temp; /**< Pointer to a rule, used so rules_load_rule_loadspec() knowns which rule rules_load_rule() is processing */
31 34
32/** 35/**
33 * @fn int rules_load(void) 36 * @fn int rules_load(void)
diff --git a/src/bin/rules.h b/src/bin/rules.h
deleted file mode 100644
index 7bc2019..0000000
--- a/src/bin/rules.h
+++ /dev/null
@@ -1,47 +0,0 @@
1/*
2 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19/**
20 * @file rules.h
21 * @brief Contains all includes and prototypes for rules.c
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Contains all includes and prototypes for rules.c
26 */
27
28#include <dirent.h>
29#include <errno.h>
30#include <Eina.h>
31#include <fnmatch.h>
32#include <sys/types.h>
33#include <regex.h>
34
35#include "libconf.h"
36#include "global.h"
37#include "logmessages.h"
38
39struct rule *rules_temp; /**< Pointer to a rule, used so rules_load_rule_loadspec() knowns which rule rules_load_rule() is processing */
40
41int rules_load(void);
42int rules_load_rule(char *rule_name);
43int rules_load_rule_loadspec(char *variable, char *value);
44int rules_print(void);
45int rules_list(int (*callback)(struct rule *foundrule));
46int rules_filtermessage(struct logmessage *new_logmessage);
47
diff --git a/src/bin/send.c b/src/bin/send.c
index 872cf76..422e7b1 100644
--- a/src/bin/send.c
+++ b/src/bin/send.c
@@ -16,19 +16,12 @@
16 * 16 *
17 */ 17 */
18 18
19/** 19#include "smman.h"
20 * @file send.c
21 * @brief Contains functions to send logs to ES
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Contains functions to send logs to ES
26 */
27 20
28#include "send.h" 21CURL *curl;
22CURLcode res;
29 23
30/** 24/**
31 * @fn int send_logmessage(struct logmessage *new_logmessage)
32 * @brief This function will receive a logmessage to index, 25 * @brief This function will receive a logmessage to index,
33 * convert it into JSON data and send it to <a href=www.elasticsearch.com>ES</a> 26 * convert it into JSON data and send it to <a href=www.elasticsearch.com>ES</a>
34 * 27 *
@@ -81,7 +74,6 @@ int send_logmessage(struct logmessage *new_logmessage)
81} 74}
82 75
83/** 76/**
84 * @fn int send_convJSON(char *source_host, char *source_path, char *type, char *message, char *tags, char *timestamp, char **jsondata)
85 * @brief This Function receives all needed vars to build the JSON data for <a href=www.elasticsearch.com>ES</a>. 77 * @brief This Function receives all needed vars to build the JSON data for <a href=www.elasticsearch.com>ES</a>.
86 * @warning This function will malloc jsondata, so dont do it yourself, and dont forget to free it! 78 * @warning This function will malloc jsondata, so dont do it yourself, and dont forget to free it!
87 * 79 *
@@ -131,7 +123,6 @@ int send_convJSON(char *source_host, char *source_path, char *type, char *messag
131 123
132 124
133/** 125/**
134 * @fn char *send_escape(char *src, char **dst)
135 * @brief This Function will escape all double quote so we dont get a parsing problem 126 * @brief This Function will escape all double quote so we dont get a parsing problem
136 * @warning This function will malloc dst, so dont do it yourself, and dont forget to free it! 127 * @warning This function will malloc dst, so dont do it yourself, and dont forget to free it!
137 * 128 *
@@ -161,7 +152,6 @@ char *send_escape(char *src, char **dst)
161} 152}
162 153
163/** 154/**
164 * @fn int send_destroy(void)
165 * @brief Inits the curl object, and set necessary params 155 * @brief Inits the curl object, and set necessary params
166 * 156 *
167 * @return 0 157 * @return 0
@@ -183,7 +173,6 @@ int send_init(void)
183} 173}
184 174
185/** 175/**
186 * @fn int send_destroy(void)
187 * @brief Destroys the curl object 176 * @brief Destroys the curl object
188 * 177 *
189 * @return 0 178 * @return 0
@@ -195,7 +184,6 @@ int send_destroy(void)
195} 184}
196 185
197/** 186/**
198 * @fn int send_toES(char *jsondata)
199 * @brief This function will send a given JSON data to the configured 187 * @brief This function will send a given JSON data to the configured
200 * JSON server 188 * JSON server
201 * 189 *
@@ -248,7 +236,6 @@ int send_toES(char *jsondata)
248} 236}
249 237
250/** 238/**
251 * @fn static size_t send_fromES(void *ptr, size_t size, size_t nmemb, void *data)
252 * @brief This fonction will get response from <a href=www.elasticsearch.com>ES</A> 239 * @brief This fonction will get response from <a href=www.elasticsearch.com>ES</A>
253 * after sending our JSON data. This function is a callback used by libcurl 240 * after sending our JSON data. This function is a callback used by libcurl
254 * 241 *
diff --git a/src/bin/send.h b/src/bin/send.h
deleted file mode 100644
index ceef713..0000000
--- a/src/bin/send.h
+++ /dev/null
@@ -1,43 +0,0 @@
1/*
2 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19/**
20 * @file send.h
21 * @brief Contains all includes and prototypes for send.c
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * Contains all includes and prototypes for send.c
26 */
27
28#include <Ecore_Con.h>
29#include <curl/curl.h>
30
31#include "global.h"
32
33CURL *curl;
34CURLcode res;
35unsigned char send_connected;
36
37int send_logmessage(struct logmessage *new_logmessage);
38int send_convJSON(char *source_host, char *source_path, char *type, char *message, char *tags, char *timestamp, char **jsondata);
39char *send_escape(char *src, char **dst);
40int send_toES(char *jsondata);
41size_t send_fromES(void *ptr, size_t size, size_t nmemb, void *data);
42int send_init(void);
43int send_destroy(void);
diff --git a/src/bin/smman.h b/src/bin/smman.h
new file mode 100644
index 0000000..5cee0a8
--- /dev/null
+++ b/src/bin/smman.h
@@ -0,0 +1,155 @@
1/*
2 * Copyright © 2013 Guillaume Friloux <kuri@efl.so>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19#ifdef HAVE_CONFIG_H
20# include "config.h"
21#endif
22
23#include <Eina.h>
24#include <Ecore.h>
25#include <Ecore_File.h>
26#include <curl/curl.h>
27
28#include <dirent.h>
29#include <errno.h>
30#include <fnmatch.h>
31#include <sys/types.h>
32#include <sys/stat.h>
33#include <regex.h>
34#include <unistd.h>
35#include <libgen.h>
36#include <getopt.h>
37
38#ifndef GLOBALVARS
39#define GLOBALVARS
40char global_rulesdir[35], /**< Allows us to store the rules directory */
41 global_conf[35], /**< Allows us to store the configuration directory */
42 global_host[35], /**< Allows us to store the default hostname */
43 global_type[35], /**< Allows us to store the default type */
44 global_ESserver[128];/**< Allows us to store ElasticSearch server adress */
45
46/**
47 * @struct rule
48 * @brief This structure can handle a rule described in the rule directory
49 */
50struct rule
51{
52 char *name, /**< Rule's name (Guessed using the filename of the rule inside the rules directory) */
53 *filename,/**< It is the filename of the logfile(s) that match this rule (see this as a condition) */
54 *type,/**< Type we will apply to the matched log message (see this as an affectation) */
55 *source_host,/**< Host we will apply to the matched log message (see this as an affectation) */
56 *source_path,/**< Log path we will apply to the matched log message (its like renaming the log, without mv it) (see this as an affectation) */
57 *tags;/**< tags we will apply to the matched log message (see this as an affectation) */
58 int todel;/**< If set to something other than 0, every matched rule will not be indexed */
59 Eina_List *list_regex;/**< Regexps to apply to message we get from syslog, then match them (see this as a condition) */
60};
61
62/**
63 * @struct regex
64 * @brief This structure can handle a regex that will be compared to log messages
65 * in order to see if they are affected by a rule or not
66 */
67struct regex
68{
69 char *message;
70 int must_match;
71 regex_t preg;
72};
73
74/**
75 * @struct logfile
76 * @brief This structure allows us to attach a cursor position to a logfile,
77 * which is necessary to find new log entries
78 */
79struct logfile
80{
81 char *name; /**< Name of the log file */
82 fpos_t cursor; /**< Position of the cursor inside this logfile */
83 unsigned long long int filesize; /**< File size, only help to see if a logfile is truncated, as far as i know */
84};
85
86/**
87 * @struct logmessage
88 * @brief This structure Contains needed information about a logfile that is going
89 * to be JSONed for ES.
90 */
91struct logmessage
92{
93 char *source_host, /**< Hostname */
94 *source_path, /**< Name of the logfile from where this message comes from */
95 *timestamp, /**< Date of the log */
96 *type, /**< Type of message */
97 *message; /**< Log message to index in ES */
98 Eina_List *list_tags; /**< List of tags associated to this message */
99 int todel; /**< If set to something other than 0, this message wont be indexed */
100};
101
102int einadom_rules, /**< Used for eina_log inside rules.c */
103 einadom_spy, /**< Used for eina_log inside spy.c */
104 einadom_logfiles, /**< Used for eina_log inside logfiles.c */
105 einadom_send, /**< Used for eina_log inside send.c */
106 einadom_conf; /**< Used for eina_log inside conf.c */
107
108Eina_List *list_rules; /**< Used to store all the rules in memory, in an eina list */
109Eina_List *list_logfiles; /**< Used to store all the logfiles watched, in an eina list */
110Ecore_File_Monitor *efm; /**< Used for file monitoring by ecore */
111
112unsigned char send_connected;
113#endif
114
115int conf_load(void);
116int conf_load_var(char *variable, char *value);
117
118int logfiles_exist(char *logfile);
119int logfiles_add(struct logfile *new_logfile);
120int logfiles_print(void);
121int logfiles_new(struct logfile **new_logfile, char *filename, fpos_t cursor, unsigned long long int filesize);
122int logfiles_del(struct logfile **old_logfile);
123int logfiles_getend(char *logfile, fpos_t *pos_end);
124int logfiles_getbegin(char *logfile, fpos_t *pos_begin);
125int logfiles_getsize(char *logfile, unsigned long long int *filesize);
126
127int logmessages_new(struct logmessage **new_logmessage, char *message, char *logname);
128int logmessages_free(struct logmessage **old_logmessage);
129int logmessages_set_type(struct logmessage *mylog, char *type);
130int logmessages_set_sourcehost(struct logmessage *mylog, char *source_host);
131int logmessages_add_tag(struct logmessage *mylog, char *tag);
132int logmessages_set_todel(struct logmessage *mylog, int value);
133
134int rules_load(void);
135int rules_load_rule(char *rule_name);
136int rules_load_rule_loadspec(char *variable, char *value);
137int rules_print(void);
138int rules_list(int (*callback)(struct rule *foundrule));
139int rules_filtermessage(struct logmessage *new_logmessage);
140
141int send_logmessage(struct logmessage *new_logmessage);
142int send_convJSON(char *source_host, char *source_path, char *type, char *message, char *tags, char *timestamp, char **jsondata);
143char *send_escape(char *src, char **dst);
144int send_toES(char *jsondata);
145size_t send_fromES(void *ptr, size_t size, size_t nmemb, void *data);
146int send_init(void);
147int send_destroy(void);
148
149
150int spy_init(void);
151int spy_addwatcher(struct rule *foundrule);
152int spy_event(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path);
153int spy_extract_new_lines(char *filename, fpos_t pos_cur, fpos_t *pos_new, char *message);
154
155char * utils_date(void);
diff --git a/src/bin/spy.c b/src/bin/spy.c
index 9816449..6d27fde 100644
--- a/src/bin/spy.c
+++ b/src/bin/spy.c
@@ -16,20 +16,11 @@
16 * 16 *
17 */ 17 */
18 18
19/** 19#include "smman.h"
20 * @file spy.c 20#include <wordexp.h>
21 * @brief Contains functions that monitors logfiles 21
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 *
25 * @bug : In rules, use wildcards only for filenames, not directories
26 *
27 * Contains functions that monitors logfiles
28 */
29#include "spy.h"
30 22
31/** 23/**
32 * @fn int spy_init(void)
33 * @brief Will ask rules_list() to list all rules and tell spy_addwatcher() 24 * @brief Will ask rules_list() to list all rules and tell spy_addwatcher()
34 * of every found rule so we can process it and monitor matching log files 25 * of every found rule so we can process it and monitor matching log files
35 * 26 *
@@ -42,7 +33,6 @@ int spy_init(void)
42} 33}
43 34
44/** 35/**
45 * @fn int spy_addwatcher(struct rule *foundrule)
46 * @brief Gets a rule in param, and will check for every matching 36 * @brief Gets a rule in param, and will check for every matching
47 * files on the system 37 * files on the system
48 * 38 *
@@ -113,7 +103,6 @@ int spy_addwatcher(struct rule *foundrule)
113} 103}
114 104
115/** 105/**
116 * @fn int spy_event(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path)
117 * @brief ecore_main_loop() will call this function for every notification he gets from logfiles 106 * @brief ecore_main_loop() will call this function for every notification he gets from logfiles
118 * activity. 107 * activity.
119 * 108 *
@@ -121,7 +110,7 @@ int spy_addwatcher(struct rule *foundrule)
121 * @param em (Ecore_File_Monitor *) Not really used here. 110 * @param em (Ecore_File_Monitor *) Not really used here.
122 * @param event (Ecore_File_Event) Event type 111 * @param event (Ecore_File_Event) Event type
123 * @param path (const char *) Name of the file that raised the event 112 * @param path (const char *) Name of the file that raised the event
124 * 113 *
125 * @return ECORE_CALLBACK_RENEW 114 * @return ECORE_CALLBACK_RENEW
126 */ 115 */
127int spy_event(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path) 116int spy_event(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path)
@@ -229,7 +218,6 @@ int spy_event(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const
229 { 218 {
230 if( !strcmp(new_logfile->name, path) ) 219 if( !strcmp(new_logfile->name, path) )
231 return(ECORE_CALLBACK_RENEW); 220 return(ECORE_CALLBACK_RENEW);
232
233 } 221 }
234 222
235 EINA_LIST_FOREACH(list_rules, l, foundrule) 223 EINA_LIST_FOREACH(list_rules, l, foundrule)
@@ -289,7 +277,6 @@ int spy_event(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const
289 277
290 278
291/** 279/**
292 * @fn int spy_extract_new_lines(char *filename, fpos_t pos_cur, fpos_t *pos_new, char *message)
293 * @brief Gets the new log message that has been inserted. This function kind of sucks and has to 280 * @brief Gets the new log message that has been inserted. This function kind of sucks and has to
294 * be improved to really extract all the messages and send them to a callback that will 281 * be improved to really extract all the messages and send them to a callback that will
295 * process them intead of taking only one (which can cause a problem if we don't get 282 * process them intead of taking only one (which can cause a problem if we don't get
@@ -299,7 +286,7 @@ int spy_event(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const
299 * @param pos_cur (fpos_t) current cursor position for this file 286 * @param pos_cur (fpos_t) current cursor position for this file
300 * @param pos_new (fpos_t *) New position of the cursor after extracting the new message 287 * @param pos_new (fpos_t *) New position of the cursor after extracting the new message
301 * @param message (char *) message extracted from the logfile 288 * @param message (char *) message extracted from the logfile
302 * 289 *
303 * @return 0 or -1 if there is an error 290 * @return 0 or -1 if there is an error
304 */ 291 */
305int spy_extract_new_lines(char *filename, fpos_t pos_cur, fpos_t *pos_new, char *message) 292int spy_extract_new_lines(char *filename, fpos_t pos_cur, fpos_t *pos_new, char *message)
diff --git a/src/bin/spy.h b/src/bin/spy.h
deleted file mode 100644
index 1c5b95c..0000000
--- a/src/bin/spy.h
+++ /dev/null
@@ -1,40 +0,0 @@
1/*
2 * Copyright © 2011 ASP64 <guillaume.friloux@asp64.com>
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 */
18
19/**
20 * @file spy.h
21 * @brief Contains all includes and prototypes for spy.c
22 * @author Guillaume Friloux <guillaume.friloux@asp64.com>
23 * @version 1.0
24 *
25 * Contains all includes and prototypes for spy.c
26 */
27#include <wordexp.h>
28
29#include "global.h"
30
31#include "rules.h"
32#include "logfiles.h"
33#include "send.h"
34#include "logmessages.h"
35
36int spy_init(void);
37int spy_addwatcher(struct rule *foundrule);
38int spy_event(void *data, Ecore_File_Monitor *em, Ecore_File_Event event, const char *path);
39int spy_extract_new_lines(char *filename, fpos_t pos_cur, fpos_t *pos_new, char *message);
40
diff --git a/src/bin/date.h b/src/bin/utils.c
index 4257e66..a9a9d4a 100644
--- a/src/bin/date.h
+++ b/src/bin/utils.c
@@ -8,7 +8,7 @@
8 * 8 *
9 * This program is distributed in the hope that it will be useful, 9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
@@ -16,16 +16,32 @@
16 * 16 *
17 */ 17 */
18 18
19#include "smman.h"
20#include <time.h>
21#include <stdio.h>
22
19/** 23/**
20 * @file date.h 24 * @brief Gets us the current date, in the same format as logstash.
21 * @brief Contains all includes and prototypes for date.c
22 * @author Guillaume Friloux <kuri@efl.so>
23 * @version 1.0
24 * 25 *
25 * Contains all includes and prototypes for date.c 26 * @return Pointer to the date's string, or NULL if an error
27 * occured.
26 */ 28 */
27#include <time.h> 29char *
28#include <stdio.h> 30utils_date(void)
31{
32 char *s;
33 time_t temps;
34 struct tm temp;
35
36 temps = time(NULL);
37 if (!localtime_r(&temps,&temp))
38 return NULL;
29 39
30char * timestamp_XML(char * date); 40 s = calloc(1, 28);
41 EINA_SAFETY_ON_NULL_RETURN_VAL(s, NULL);
31 42
43 sprintf(s,"%04d-%02d-%02dT%02d:%02d:%02d.000000Z",
44 (temp.tm_year)+1900,(temp.tm_mon)+1,temp.tm_mday,
45 temp.tm_hour,temp.tm_min,temp.tm_sec);
46 return s;
47}