src/modules/logwatch.c
author Tero Marttila <terom@fixme.fi>
Sun, 12 Apr 2009 18:56:51 +0300
changeset 135 9159bd51525f
parent 134 978041c1c04d
child 138 a716c621cb90
permissions -rw-r--r--
have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     1
#include "logwatch.h"
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     2
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     3
#include "../config.h"
127
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
     4
#include "../log.h"
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     5
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
     6
#include <assert.h>
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
     7
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     8
static err_t logwatch_init (struct nexus *nexus, void **ctx_ptr, struct error_info *err)
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
     9
{
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    10
    struct logwatch *ctx;
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    11
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    12
    // allocate
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    13
    if ((ctx = calloc(1, sizeof(*ctx))) == NULL)
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    14
        RETURN_SET_ERROR(err, ERR_CALLOC);
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    15
    
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    16
    // init
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    17
    TAILQ_INIT(&ctx->sources);
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    18
    TAILQ_INIT(&ctx->filters);
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    19
    TAILQ_INIT(&ctx->channels);
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    20
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    21
    // store
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    22
    ctx->nexus = nexus;
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    23
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    24
    // ok
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    25
    *ctx_ptr = ctx;
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    26
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    27
    return SUCCESS;
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    28
}
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    29
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    30
struct logwatch_chan* logwatch_get_chan (struct logwatch *ctx, struct irc_chan *irc_chan)
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    31
{
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    32
    struct logwatch_chan *chan;
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    33
    
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    34
    // existing?
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    35
    if ((chan = logwatch_chan_lookup(ctx, irc_chan))) {
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    36
        // get ref
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    37
        chan->refcount++;
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    38
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    39
    } else {
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    40
        // create a new one with a ref
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    41
        // XXX: errors...
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    42
        chan = logwatch_chan_create(ctx, irc_chan);
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    43
    }
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    44
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    45
    // ok
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    46
    return chan;
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    47
}
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    48
127
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    49
void logwatch_on_line (struct logwatch *ctx, const struct logwatch_source *source, const char *line)
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    50
{
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    51
    const struct logwatch_filter *filter;
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    52
    struct error_info err;
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    53
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    54
    // apply each filter
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    55
    TAILQ_FOREACH(filter, &ctx->filters, logwatch_filters) {
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    56
        if (logwatch_filter_apply(filter, source, line, &err))
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    57
            log_warn("logwatch_filter_apply(%s, %s, %s): %s", filter->name, source->name, line, error_msg(&err));
127
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    58
    }
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    59
}
94e6c3b4230f implement logwatch_on_line/logwatch_filter_apply, along with irc_*_NOTICE
Tero Marttila <terom@fixme.fi>
parents: 124
diff changeset
    60
133
e2d0c0c23b39 implement logwatch_chan.c, logwatch_chan_msg, logwatch_on_error
Tero Marttila <terom@fixme.fi>
parents: 132
diff changeset
    61
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    62
void logwatch_on_error (struct logwatch *ctx, const struct logwatch_source *source, const struct error_info *err)
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    63
{
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    64
    struct logwatch_chan *chan;
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    65
    
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    66
    // notify each relevant channel
133
e2d0c0c23b39 implement logwatch_chan.c, logwatch_chan_msg, logwatch_on_error
Tero Marttila <terom@fixme.fi>
parents: 132
diff changeset
    67
    TAILQ_FOREACH(chan, &ctx->channels, logwatch_channels) {
e2d0c0c23b39 implement logwatch_chan.c, logwatch_chan_msg, logwatch_on_error
Tero Marttila <terom@fixme.fi>
parents: 132
diff changeset
    68
        // skip irrelevant channels
e2d0c0c23b39 implement logwatch_chan.c, logwatch_chan_msg, logwatch_on_error
Tero Marttila <terom@fixme.fi>
parents: 132
diff changeset
    69
        if (!logwatch_chan_has_source(chan, source))
e2d0c0c23b39 implement logwatch_chan.c, logwatch_chan_msg, logwatch_on_error
Tero Marttila <terom@fixme.fi>
parents: 132
diff changeset
    70
            continue;
e2d0c0c23b39 implement logwatch_chan.c, logwatch_chan_msg, logwatch_on_error
Tero Marttila <terom@fixme.fi>
parents: 132
diff changeset
    71
e2d0c0c23b39 implement logwatch_chan.c, logwatch_chan_msg, logwatch_on_error
Tero Marttila <terom@fixme.fi>
parents: 132
diff changeset
    72
        // send an error message
e2d0c0c23b39 implement logwatch_chan.c, logwatch_chan_msg, logwatch_on_error
Tero Marttila <terom@fixme.fi>
parents: 132
diff changeset
    73
        logwatch_chan_msg(chan, "!!! Source '%s' failed: %s", source->name, error_msg(err));
e2d0c0c23b39 implement logwatch_chan.c, logwatch_chan_msg, logwatch_on_error
Tero Marttila <terom@fixme.fi>
parents: 132
diff changeset
    74
    }
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    75
}
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    76
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    77
/**
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    78
 * Add a logwatch_source with a FIFO at the given path
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    79
 */
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    80
static err_t logwatch_conf_source_fifo (void *_ctx, const struct config_option *option, const struct config_value values[], struct error_info *err)
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    81
{
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    82
    struct logwatch *ctx = _ctx;
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    83
    
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    84
    // parse arguments
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    85
    const char *path = config_get_string(option, values, "path");
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
    86
    
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    87
    // open it
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    88
    if (logwatch_open_fifo(ctx, path, err) == NULL)
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    89
       return ERROR_CODE(err);
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    90
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    91
    // ok
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    92
    return SUCCESS;
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    93
}
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    94
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
    95
/**
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
    96
 * Add a logwatch_filter for the given bits
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
    97
 */
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
    98
static err_t logwatch_conf_filter (void *_ctx, const struct config_option *option, const struct config_value values[], struct error_info *err)
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
    99
{
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   100
    struct logwatch *ctx = _ctx;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   101
    struct logwatch_filter *filter;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   102
    
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   103
    const struct logwatch_source *source = NULL;
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   104
    struct logwatch_chan *chan;
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   105
    const char *name, *source_name, *pattern, *format;
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   106
    struct irc_chan *irc_chan;
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   107
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   108
    // parse arguments
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   109
    name        = config_get_string     (option, values, "name"     );
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   110
    source_name = config_get_string     (option, values, "source"   );
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   111
    pattern     = config_get_string     (option, values, "pattern"  );
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   112
    format      = config_get_string     (option, values, "format"   );
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   113
    irc_chan    = config_get_irc_chan   (option, values, "chan"     );
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   114
135
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   115
    // replace old filter?
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   116
    if ((filter = logwatch_filter_lookup(ctx, name))) {
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   117
        log_info("removing old filter: %s: %p", name, filter);
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   118
        logwatch_filter_destroy(filter);
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   119
    }
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   120
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   121
    // lookup source
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   122
    if (source_name && (source = logwatch_source_lookup(ctx, source_name)) == NULL)
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   123
       RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "unknown logwatch_source name");
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   124
    
135
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   125
    // lookup channel
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   126
    if ((chan = logwatch_get_chan(ctx, irc_chan)) == NULL)
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   127
        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "logwatch_get_chan failed");
134
978041c1c04d update TODO, partially update error.c, rename module_get to modules_get, update config.lua
Tero Marttila <terom@fixme.fi>
parents: 133
diff changeset
   128
    
978041c1c04d update TODO, partially update error.c, rename module_get to modules_get, update config.lua
Tero Marttila <terom@fixme.fi>
parents: 133
diff changeset
   129
    log_info("add filter: name=%s, source=%s, pattern=%s, format=%s, chan=%s",
978041c1c04d update TODO, partially update error.c, rename module_get to modules_get, update config.lua
Tero Marttila <terom@fixme.fi>
parents: 133
diff changeset
   130
        name, source_name, pattern, format, irc_chan_name(irc_chan));
130
ffefb6d85ea6 implement logwatch_filter::format using str_format
Tero Marttila <terom@fixme.fi>
parents: 127
diff changeset
   131
135
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   132
    // create a new one
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   133
    if ((filter = logwatch_filter(ctx, name, source, pattern, format, chan, err)) == NULL)
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   134
        goto error;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   135
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   136
    // ok
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   137
    return SUCCESS;
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   138
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   139
error:
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   140
    return ERROR_CODE(err);    
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   141
}
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   142
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   143
/**
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   144
 * Configuration options
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   145
 */
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   146
struct config_option logwatch_config_options[] = CONFIG_OPTIONS(
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   147
    CONFIG_OPT(         "source_fifo",  logwatch_conf_source_fifo,
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   148
        "read input lines from the FIFO at the given path",
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   149
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   150
        CONFIG_PARAM(       "path",     CONFIG_STRING,      "filesystem path to FIFO",                  false   )
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   151
    ),
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   152
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   153
    CONFIG_OPT(         "filter",       logwatch_conf_filter, 
124
f18d69425c4f fix up lua_module_conf/config_* enough so that logwatch_conf_filter works
Tero Marttila <terom@fixme.fi>
parents: 121
diff changeset
   154
        "filter lines from source (or all), using the given regular expression (or all lines), and format output "
135
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   155
        "using the given format expression (or pass through directly), and finally send the output to the given channel. "
9159bd51525f have logwatch_conf_filter replace any old filter with the same name, and move irc_log.sql to modules/
Tero Marttila <terom@fixme.fi>
parents: 134
diff changeset
   156
        "If a filter with the same name already exists, it will be replaced.",
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   157
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   158
        CONFIG_PARAM(       "name",    CONFIG_STRING,      "filter name",                              false   ),
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   159
        CONFIG_PARAM(       "source",  CONFIG_STRING,      "optional logwatch_source to use",          true    ),
121
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   160
        CONFIG_PARAM(       "pattern", CONFIG_STRING,      "optional regular expression pattern",      true    ),
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   161
        CONFIG_PARAM(       "format",  CONFIG_STRING,      "optional output format",                   true    ),
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   162
        CONFIG_PARAM(       "chan",    CONFIG_IRC_CHAN,    "channel to send output to",                false   )
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   163
    )
4682ebbc5644 implement logwatch_conf_filter such that it compiles and loads, but not yet tested
Tero Marttila <terom@fixme.fi>
parents: 119
diff changeset
   164
);
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   165
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   166
static void logwatch_destroy (void *_ctx)
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   167
{
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   168
    struct logwatch *ctx = _ctx;
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   169
    struct logwatch_filter *filter;
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   170
    struct logwatch_source *source;
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   171
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   172
    // flush the filters list
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   173
    while ((filter = TAILQ_FIRST(&ctx->filters)))
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   174
        logwatch_filter_destroy(filter);
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   175
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   176
    // flush the sources list
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   177
    while ((source = TAILQ_FIRST(&ctx->sources)))
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   178
        logwatch_source_destroy(source);
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   179
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   180
    // release the context
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   181
    free(ctx);
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   182
}
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   183
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   184
/**
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   185
 * The module function table
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   186
 */
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   187
struct module_desc logwatch_module = {
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   188
    .init               = logwatch_init,
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   189
    .config_options     = logwatch_config_options,
132
f2ece471fb07 implement logwatch_source names, and logwatch_chan
Tero Marttila <terom@fixme.fi>
parents: 130
diff changeset
   190
    .unload             = NULL,
119
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   191
    .destroy            = logwatch_destroy
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   192
};
64f50072db9e add logwatch module, that can already open FIFOs
Tero Marttila <terom@fixme.fi>
parents:
diff changeset
   193