aboutsummaryrefslogtreecommitdiff
path: root/modules/logstat/mod_logstat.c
blob: 02452e24fb6b6f7a46d90795b51c289447da9cc9 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* 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 <string.h>
#include <syslog.h>
#include <grecs.h>
#include <wydawca/wydawca.h>
#include <wydawca/cfg.h>

#define WY_MODULE mod_logstat

static int stat_mask = WY_STAT_MASK_ALL;
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;
}

static void
logmsg(char *s)
{
	char *p;

	while ((p = strchr(s, '\n'))) {
		*p++ = 0;
		wy_log(LOG_INFO, "%s", s);
		s = p;
	}
	if (*s)
		wy_log(LOG_INFO, "%s", s);
}

static char *default_log_message[] = {
	"errors: ${stat:errors}",
	"warnings: ${stat:warnings}",
	"bad signatures: ${stat:bad_signatures}",
	"access violation attempts: ${stat:access_violations}",
	"complete triplets: ${stat:complete_triplets}",
	"incomplete triplets: ${stat:incomplete_triplets}",
	"bad triplets: ${stat:bad_triplets}",
	"expired triplets: ${stat:expired_triplets}",
	"triplet successes: ${stat:triplet_success}",
	"files uploaded: ${stat:uploads}",
	"files archived: ${stat:archives}",
	"symlinks created: ${stat:symlinks}",
	"symlinks removed: ${stat:rmsymlinks}",
	"check failures: ${stat:check-failures}",
	NULL
};

void
wy_notify(void *data, int ev, wy_triplet_t trp)
{
	struct grecs_list_entry *ep;
	char *text;

	if (ev != wy_ev_finish || !wy_stat_mask_p(stat_mask))
		return;

	if (log_msg) {
		for (ep = log_msg->head; ep; ep = ep->next) {
			text = wy_expand_stats(ep->data);
			logmsg(text);
			free(text);
		}
	} else {
		int i;
		for (i = 0; default_log_message[i]; i++) {
			if (wy_stat_mask_p(WY_STAT_MASK(i))) {
				text = wy_expand_stats(default_log_message[i]);
				logmsg(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 }
	};
	static char const *docstring = "\n\
mod_logstat sends statistics reports to syslog\n";

	puts(docstring);
	printf("# 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.