src/modules/logwatch.c
changeset 135 9159bd51525f
parent 134 978041c1c04d
child 138 a716c621cb90
equal deleted inserted replaced
134:978041c1c04d 135:9159bd51525f
   110     source_name = config_get_string     (option, values, "source"   );
   110     source_name = config_get_string     (option, values, "source"   );
   111     pattern     = config_get_string     (option, values, "pattern"  );
   111     pattern     = config_get_string     (option, values, "pattern"  );
   112     format      = config_get_string     (option, values, "format"   );
   112     format      = config_get_string     (option, values, "format"   );
   113     irc_chan    = config_get_irc_chan   (option, values, "chan"     );
   113     irc_chan    = config_get_irc_chan   (option, values, "chan"     );
   114 
   114 
   115     // lookup name
   115     // replace old filter?
       
   116     if ((filter = logwatch_filter_lookup(ctx, name))) {
       
   117         log_info("removing old filter: %s: %p", name, filter);
       
   118         logwatch_filter_destroy(filter);
       
   119     }
       
   120 
       
   121     // lookup source
   116     if (source_name && (source = logwatch_source_lookup(ctx, source_name)) == NULL)
   122     if (source_name && (source = logwatch_source_lookup(ctx, source_name)) == NULL)
   117        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "unknown logwatch_source name");
   123        RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "unknown logwatch_source name");
   118     
   124     
   119     // lookup the channel
   125     // lookup channel
   120     if ((chan = logwatch_get_chan(ctx, irc_chan)) == NULL)
   126     if ((chan = logwatch_get_chan(ctx, irc_chan)) == NULL)
   121         RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "logwatch_get_chan failed");
   127         RETURN_SET_ERROR_STR(err, ERR_MODULE_CONF, "logwatch_get_chan failed");
   122     
   128     
   123     log_info("add filter: name=%s, source=%s, pattern=%s, format=%s, chan=%s",
   129     log_info("add filter: name=%s, source=%s, pattern=%s, format=%s, chan=%s",
   124         name, source_name, pattern, format, irc_chan_name(irc_chan));
   130         name, source_name, pattern, format, irc_chan_name(irc_chan));
   125 
   131 
   126     // invoke
   132     // create a new one
   127     if ((filter = logwatch_filter(ctx, name, source, pattern, format, chan, err)) == NULL)
   133     if ((filter = logwatch_filter(ctx, name, source, pattern, format, chan, err)) == NULL)
   128         goto error;
   134         goto error;
   129 
   135 
   130     // ok
   136     // ok
   131     return SUCCESS;
   137     return SUCCESS;
   144         CONFIG_PARAM(       "path",     CONFIG_STRING,      "filesystem path to FIFO",                  false   )
   150         CONFIG_PARAM(       "path",     CONFIG_STRING,      "filesystem path to FIFO",                  false   )
   145     ),
   151     ),
   146 
   152 
   147     CONFIG_OPT(         "filter",       logwatch_conf_filter, 
   153     CONFIG_OPT(         "filter",       logwatch_conf_filter, 
   148         "filter lines from source (or all), using the given regular expression (or all lines), and format output "
   154         "filter lines from source (or all), using the given regular expression (or all lines), and format output "
   149         "using the given format expression (or pass through directly), and finally send the output to the given channel",
   155         "using the given format expression (or pass through directly), and finally send the output to the given channel. "
       
   156         "If a filter with the same name already exists, it will be replaced.",
   150 
   157 
   151         CONFIG_PARAM(       "name",    CONFIG_STRING,      "filter name",                              false   ),
   158         CONFIG_PARAM(       "name",    CONFIG_STRING,      "filter name",                              false   ),
   152         CONFIG_PARAM(       "source",  CONFIG_STRING,      "optional logwatch_source to use",          true    ),
   159         CONFIG_PARAM(       "source",  CONFIG_STRING,      "optional logwatch_source to use",          true    ),
   153         CONFIG_PARAM(       "pattern", CONFIG_STRING,      "optional regular expression pattern",      true    ),
   160         CONFIG_PARAM(       "pattern", CONFIG_STRING,      "optional regular expression pattern",      true    ),
   154         CONFIG_PARAM(       "format",  CONFIG_STRING,      "optional output format",                   true    ),
   161         CONFIG_PARAM(       "format",  CONFIG_STRING,      "optional output format",                   true    ),