~ubuntu-branches/ubuntu/oneiric/rsyslog/oneiric

« back to all changes in this revision

Viewing changes to plugins/impstats/impstats.c

  • Committer: Dave Walker (Daviey)
  • Author(s): Scott Moser
  • Date: 2011-06-17 20:59:38 UTC
  • mfrom: (36.1.8 oneiric.merge)
  • Revision ID: davewalker@ubuntu.com-20110617205938-pfkizxz2wsgzi2ot
Tags: 5.8.1-1ubuntu1
* Resynchronise with Debian (LP: #794230).  Remaining changes:
  - Run as rsyslog:rsyslog, set $FileOwner to syslog
  - Replace init script with debian/rsyslog.upstart.
  - debian/rsyslog.logrotate: Use reload command to restart rsyslog
  - debian/rsyslog.conf: enable $RepeatedMsgReduction 
    to avoid bloating the syslog file (LP #453444)
  - Add debian/rsyslog.dmesg.upstart to save initial dmesg into a file.
    Install it in debian/rules.
  - debian/50-default.conf: set of default rules for syslog (forwarded to
    Debian #603160). remove file in postrm on purge. manage with ucf.
  - debian/rules: build with LDFLAGS=""
* Dropped:
  - debian/control: Bump build-dependency on debhelper
    debian now depends on dh >= 8
* New upstream release.
* Bump Standards-Version to 3.9.2. No further changes.
* Enable and install impstats module. (Closes: #620114)
* Update logcheck rule. (Closes: #616659)
* debian/rsyslog.init: Set correct compat level (5).
* The way rsyslog processes SIGHUP has changed. It no longer does a reload
  of its configuration, but simply closes all open files. To apply a changed
  configuration, rsyslogd needs to be restarted now.
  - Drop "reload" action from debian/rsyslog.init, map "force-reload" to
    "restart". (Closes: #580897)
  - Add "rotate" action to debian/rsyslog.init which sends SIGHUP to
    rsyslogd. Use that in debian/rsyslog.logrotate. (Closes: #626365)
  - Update debian/rsyslog-mysql.postinst and rsyslog-pgsql.postinst to use
    restart instead of reload.
  - Add a NEWS file explaining the changed SIGHUP handling.
* New upstream stable release.
* New upstream release.
  - Properly handle ANSI SQL strings in ompgsql. (Closes: #600479)
* New upstream release.
* debian/patches/02-pmaixforwardedfrom_type_nokeep.patch
  - Remove, merged upstream.
* debian/patches/03-epoll_create1-fallback.patch
  - Remove, merged upstream.
* debian/patches/03-epoll_create1-fallback.patch
  - If epoll_create1() is not available during runtime, fall back to
    epoll_create(). This fixes remote syslog when runnig rsyslog on a
    lenny kernel. (Closes: #617996)
* New upstream release.
* debian/rsyslog.links
  - Create symlink for rsyslog.service in multi-user.target.wants so rsyslog
    is enabled by default when using systemd.
* debian/patches/02-pmaixforwardedfrom_type_nokeep.patch
  - Fix build failure in aixforwardedfrom parser module by setting the
    module type to NOKEEP.
* debian/rsyslog.preinst
  - Remove old rsyslog.socket symlink from sockets.target.wants on upgrades
    as rsyslog uses syslog.socket now which is provided by systemd.
* debian/rsyslog.install
  - Stop installing rsyslog.socket.
* New upstream release.
* New upstream release.
  - Fix regression in imuxsock plugin which did no longer sanitize received
    messages. This makes 02-cleanup-trailing-lf.patch obsolete and also
    fixes the SQL syntax errors in the mysql output if the input contained
    NUL bytes. Closes: #614061
* Enable and install omprog output plugin. Closes: #552095
* Improve package description. Closes: #612948
  Thanks to Justin B Rye for the patch.
* debian/patches/02-cleanup-trailing-lf.patch
  - Fix regression in imuxsock plugin which did not remove a trailing LF
    anymore. Patch cherry-picked from upstream Git. Closes: #612829
* New upstream release.
* Enable and install parser modules.
* New upstream release.
* Upload to unstable.
* debian/patches/02-typo_fix_equation_sign.patch
  - Removed, merged upstream.
* debian/patches/03-atomic_operations.patch
  - Removed, merged upstream.
* debian/patches/03-atomic_operations.patch
  - Fix build failures on platforms which don't have 64 bit atomic
    operations. Patch cherry-picked from upstream Git. Closes: #600930
* New upstream development release.
* Remove patches, merged upstream
  - debian/patches/02-install_also_rsyslog_socket.patch
  - debian/patches/02-tls_loop_fix.patch
* debian/patches/02-typo_fix_equation_sign.patch
  - Fix small typo ("equation sign"). Closes: #575589
* debian/rsyslog.postinst
  - Remove pre-lenny migration code to rotate old log files from sysklogd.
* New upstream development release.
* debian/rsyslog.install
  - Install omruleset.so plugin: http://www.rsyslog.com/doc/omruleset.html
* debian/rsyslog.default
  - Start rsyslogd with native -c5 mode.
* Install systemd unit files which allow to run rsyslog in socket activation
  mode when systemd is used.
* debian/patches/02-install_also_rsyslog_socket.patch
  - When enabling rsyslog.service also enable rsyslog.socket. Patch
    cherry-picked from upstream Git.
* Bump debhelper compatibility level to 8. Update Build-Depends accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* impstats.c
 
2
 * A module to periodically output statistics gathered by rsyslog.
 
3
 *
 
4
 * NOTE: read comments in module-template.h to understand how this file
 
5
 *       works!
 
6
 *
 
7
 * File begun on 2007-07-20 by RGerhards (extracted from syslogd.c)
 
8
 * This file is under development and has not yet arrived at being fully
 
9
 * self-contained and a real object. So far, it is mostly an excerpt
 
10
 * of the "old" message code without any modifications. However, it
 
11
 * helps to have things at the right place one we go to the meat of it.
 
12
 *
 
13
 * Copyright 2010 Rainer Gerhards and Adiscon GmbH.
 
14
 *
 
15
 * This file is part of rsyslog.
 
16
 *
 
17
 * Rsyslog is free software: you can redistribute it and/or modify
 
18
 * it under the terms of the GNU General Public License as published by
 
19
 * the Free Software Foundation, either version 3 of the License, or
 
20
 * (at your option) any later version.
 
21
 *
 
22
 * Rsyslog is distributed in the hope that it will be useful,
 
23
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
24
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
25
 * GNU General Public License for more details.
 
26
 *
 
27
 * You should have received a copy of the GNU General Public License
 
28
 * along with Rsyslog.  If not, see <http://www.gnu.org/licenses/>.
 
29
 *
 
30
 * A copy of the GPL can be found in the file "COPYING" in this distribution.
 
31
 */
 
32
#include "config.h"
 
33
#include "rsyslog.h"
 
34
#include <stdlib.h>
 
35
#include <stdio.h>
 
36
#include <assert.h>
 
37
#include <signal.h>
 
38
#include <string.h>
 
39
#include <pthread.h>
 
40
#include "dirty.h"
 
41
#include "cfsysline.h"
 
42
#include "module-template.h"
 
43
#include "errmsg.h"
 
44
#include "msg.h"
 
45
#include "srUtils.h"
 
46
#include "unicode-helper.h"
 
47
#include "glbl.h"
 
48
#include "statsobj.h"
 
49
#include "prop.h"
 
50
 
 
51
MODULE_TYPE_INPUT
 
52
MODULE_TYPE_NOKEEP
 
53
 
 
54
/* defines */
 
55
#define DEFAULT_STATS_PERIOD (5 * 60)
 
56
#define DEFAULT_FACILITY 5 /* syslog */
 
57
#define DEFAULT_SEVERITY 6 /* info */
 
58
 
 
59
/* Module static data */
 
60
DEF_IMOD_STATIC_DATA
 
61
DEFobjCurrIf(glbl)
 
62
DEFobjCurrIf(prop)
 
63
DEFobjCurrIf(statsobj)
 
64
DEFobjCurrIf(errmsg)
 
65
 
 
66
typedef struct configSettings_s {
 
67
        int iStatsInterval;
 
68
        int iFacility;
 
69
        int iSeverity;
 
70
} configSettings_t;
 
71
 
 
72
static configSettings_t cs;
 
73
 
 
74
static prop_t *pInputName = NULL;
 
75
static prop_t *pLocalHostIP = NULL;
 
76
 
 
77
BEGINisCompatibleWithFeature
 
78
CODESTARTisCompatibleWithFeature
 
79
        if(eFeat == sFEATURENonCancelInputTermination)
 
80
                iRet = RS_RET_OK;
 
81
ENDisCompatibleWithFeature
 
82
 
 
83
static inline void
 
84
initConfigSettings(void)
 
85
{
 
86
        cs.iStatsInterval = DEFAULT_STATS_PERIOD;
 
87
        cs.iFacility = DEFAULT_FACILITY;
 
88
        cs.iSeverity = DEFAULT_SEVERITY;
 
89
}
 
90
 
 
91
 
 
92
/* actually submit a message to the rsyslog core
 
93
 */
 
94
static inline rsRetVal
 
95
doSubmitMsg(uchar *line)
 
96
{
 
97
        msg_t *pMsg;
 
98
        DEFiRet;
 
99
 
 
100
        CHKiRet(msgConstruct(&pMsg));
 
101
        MsgSetInputName(pMsg, pInputName);
 
102
        MsgSetRawMsgWOSize(pMsg, (char*)line);
 
103
        MsgSetHOSTNAME(pMsg, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName()));
 
104
        MsgSetRcvFrom(pMsg, glbl.GetLocalHostNameProp());
 
105
        MsgSetRcvFromIP(pMsg, pLocalHostIP);
 
106
        MsgSetMSGoffs(pMsg, 0);
 
107
        MsgSetTAG(pMsg, UCHAR_CONSTANT("rsyslogd-pstats:"), sizeof("rsyslogd-pstats:") - 1);
 
108
        pMsg->iFacility = cs.iFacility;
 
109
        pMsg->iSeverity = cs.iSeverity;
 
110
        pMsg->msgFlags  = 0;
 
111
 
 
112
        submitMsg(pMsg);
 
113
 
 
114
finalize_it:
 
115
        RETiRet;
 
116
 
 
117
}
 
118
 
 
119
 
 
120
/* callback for statsobj
 
121
 * Note: usrptr exists only to satisfy requirements of statsobj callback interface!
 
122
 */
 
123
static rsRetVal
 
124
doStatsLine(void __attribute__((unused)) *usrptr, cstr_t *cstr)
 
125
{
 
126
        DEFiRet;
 
127
        doSubmitMsg(rsCStrGetSzStrNoNULL(cstr));
 
128
        RETiRet;
 
129
}
 
130
 
 
131
 
 
132
/* the function to generate the actual statistics messages
 
133
 * rgerhards, 2010-09-09
 
134
 */
 
135
static inline void
 
136
generateStatsMsgs(void)
 
137
{
 
138
        statsobj.GetAllStatsLines(doStatsLine, NULL);
 
139
}
 
140
 
 
141
 
 
142
BEGINrunInput
 
143
CODESTARTrunInput
 
144
        /* this is an endless loop - it is terminated when the thread is
 
145
         * signalled to do so. This, however, is handled by the framework,
 
146
         * right into the sleep below.
 
147
         */
 
148
        while(1) {
 
149
                srSleep(cs.iStatsInterval, 0); /* seconds, micro seconds */
 
150
 
 
151
                if(glbl.GetGlobalInputTermState() == 1)
 
152
                        break; /* terminate input! */
 
153
 
 
154
                generateStatsMsgs();
 
155
        }
 
156
ENDrunInput
 
157
 
 
158
 
 
159
BEGINwillRun
 
160
        rsRetVal localRet;
 
161
CODESTARTwillRun
 
162
        DBGPRINTF("impstats: stats interval %d seconds\n", cs.iStatsInterval);
 
163
        if(cs.iStatsInterval == 0)
 
164
                ABORT_FINALIZE(RS_RET_NO_RUN);
 
165
        localRet = statsobj.EnableStats();
 
166
        if(localRet != RS_RET_OK) {
 
167
                errmsg.LogError(0, localRet, "impstat: error enabling statistics gathering");
 
168
                ABORT_FINALIZE(RS_RET_NO_RUN);
 
169
        }
 
170
finalize_it:
 
171
ENDwillRun
 
172
 
 
173
 
 
174
BEGINafterRun
 
175
CODESTARTafterRun
 
176
ENDafterRun
 
177
 
 
178
 
 
179
BEGINmodExit
 
180
CODESTARTmodExit
 
181
        prop.Destruct(&pInputName);
 
182
        prop.Destruct(&pLocalHostIP);
 
183
        /* release objects we used */
 
184
        objRelease(glbl, CORE_COMPONENT);
 
185
        objRelease(prop, CORE_COMPONENT);
 
186
        objRelease(errmsg, CORE_COMPONENT);
 
187
        objRelease(statsobj, CORE_COMPONENT);
 
188
ENDmodExit
 
189
 
 
190
 
 
191
 
 
192
BEGINqueryEtryPt
 
193
CODESTARTqueryEtryPt
 
194
CODEqueryEtryPt_STD_IMOD_QUERIES
 
195
CODEqueryEtryPt_IsCompatibleWithFeature_IF_OMOD_QUERIES
 
196
ENDqueryEtryPt
 
197
 
 
198
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
 
199
{
 
200
        initConfigSettings();
 
201
        return RS_RET_OK;
 
202
}
 
203
 
 
204
 
 
205
BEGINmodInit()
 
206
CODESTARTmodInit
 
207
        *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
 
208
CODEmodInit_QueryRegCFSLineHdlr
 
209
        DBGPRINTF("impstats version %s loading\n", VERSION);
 
210
        initConfigSettings();
 
211
        CHKiRet(objUse(glbl, CORE_COMPONENT));
 
212
        CHKiRet(objUse(prop, CORE_COMPONENT));
 
213
        CHKiRet(objUse(errmsg, CORE_COMPONENT));
 
214
        CHKiRet(objUse(statsobj, CORE_COMPONENT));
 
215
        /* the pstatsinverval is an alias to support a previous screwed-up syntax... */
 
216
        CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatsinterval", 0, eCmdHdlrInt, NULL, &cs.iStatsInterval, STD_LOADABLE_MODULE_ID));
 
217
        CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatinterval", 0, eCmdHdlrInt, NULL, &cs.iStatsInterval, STD_LOADABLE_MODULE_ID));
 
218
        CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatfacility", 0, eCmdHdlrInt, NULL, &cs.iFacility, STD_LOADABLE_MODULE_ID));
 
219
        CHKiRet(omsdRegCFSLineHdlr((uchar *)"pstatseverity", 0, eCmdHdlrInt, NULL, &cs.iSeverity, STD_LOADABLE_MODULE_ID));
 
220
        CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
 
221
 
 
222
        CHKiRet(prop.Construct(&pInputName));
 
223
        CHKiRet(prop.SetString(pInputName, UCHAR_CONSTANT("impstats"), sizeof("impstats") - 1));
 
224
        CHKiRet(prop.ConstructFinalize(pInputName));
 
225
 
 
226
        CHKiRet(prop.Construct(&pLocalHostIP));
 
227
        CHKiRet(prop.SetString(pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1));
 
228
        CHKiRet(prop.ConstructFinalize(pLocalHostIP));
 
229
ENDmodInit
 
230
/* vi:set ai:
 
231
 */