aboutsummaryrefslogtreecommitdiff
path: root/modules/logstat/mod_logstat.c
blob: bf735884f3411b00284fbdb85e7fa4dfc92c0d0e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/* wydawca - automatic release submission daemon
   Copyright (C) 2007-2019 Sergey Poznyakoff

   Wydawca is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by the
   Free Software Foundation; either version 3 of the License, or (at your
   option) any later version.

   Wydawca is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with wydawca. If not, see <http://www.gnu.org/licenses/>. */

#include <config.h>
#include <stdlib.h>
#include <syslog.h>
#include <grecs.h>
#include <wydawca/wydawca.h>
#include <wydawca/cfg.h>

#define WY_MODULE mod_logstat

static int stat_mask;
static struct grecs_list *log_msg;

static struct grecs_keyword logstat_kw[] = {
	{ "statistics", N_("items"),
	  N_("Log these statistics items"),
	  grecs_type_string, GRECS_DFLT, &stat_mask, 0,
	  wy_cb_statistics },
	{ "message", N_("text"),
	  N_("Log additional message"),
	  grecs_type_string, GRECS_LIST|GRECS_AGGR, &log_msg, 0, NULL },
	{ NULL }
};


void *
wy_config(grecs_node_t *node)
{
	grecs_tree_reduce(node, logstat_kw, 0);
	if (grecs_tree_process(node->down, logstat_kw))
		return NULL;
	return &stat_mask;
}

void
wy_notify(void *data, int ev, wy_triplet_t trp)
{
	struct grecs_list_entry *ep;
	char *text;
	
	if (ev != wy_ev_statistics)
		return;

	if (log_msg) {
		for (ep = log_msg->head; ep; ep = ep->next) {
			text = wy_expand_stats(ep->data);
			wy_log(LOG_INFO, "%s", text);
			free(text);
		}
	}
}

void
wy_help(void)
{
	static struct grecs_keyword top[] = {
		{ "module-config", NULL,
		  "module configuration",
		  grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL,
		  logstat_kw },
		{ NULL }
	};

	printf("\n\n# Usage in notify-event statement:\n");
	printf("notify-event {\n  event statistics;\n  module logstat;");
	grecs_print_statement_array(top, 1, 1, stdout);
	printf("}\n");
}

Return to:

Send suggestions and report system problems to the System administrator.