4 * accounting module for GNU Gatekeeper for the syslog.
6 * Copyright (c) 2006, Jan Willamowius
8 * This work is published under the GNU Public License (GPL)
9 * see file COPYING for details.
10 * We also explicitely grant the right to link this code
11 * with the OpenH323 library.
13 * $Log: syslogacct.cxx,v $
14 * Revision 1.2 2006/07/31 08:34:22 willamowius
15 * make logging facility and priority configurable (patch by Brian Thompson)
17 * Revision 1.1 2006/06/30 08:07:05 willamowius
18 * new accounting module SyslogAcct
25 #if (_MSC_VER >= 1200)
26 #pragma warning( disable : 4786 ) // warning about too long debug symbols off
33 #include "syslogacct.h"
36 const char* const SyslogSec = "SyslogAcct";
37 static int syslog_level = LOG_INFO;
38 static int syslog_facility = LOG_USER;
40 SyslogAcct::SyslogAcct(
41 const char* moduleName,
42 const char* cfgSecName
45 GkAcctLogger(moduleName, cfgSecName)
47 // it is very important to set what type of accounting events
48 // are supported for each accounting module, otherwise the Log method
50 SetSupportedEvents(SyslogAcctEvents);
52 PConfig* cfg = GetConfig();
53 const PString& cfgSec = GetConfigSectionName();
54 m_timestampFormat = cfg->GetString(cfgSec, "TimestampFormat", "");
55 m_startEvent = cfg->GetString(cfgSec, "StartEvent", "CALL|Start|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}");
56 m_stopEvent = cfg->GetString(cfgSec, "StopEvent", "CALL|Stop|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}");
57 m_updateEvent = cfg->GetString(cfgSec, "UpdateEvent", "CALL|Update|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}");
58 m_connectEvent = cfg->GetString(cfgSec, "ConnectEvent", "CALL|Connect|%{caller-ip}:%{caller-port}|%{callee-ip}:%{callee-port}|%{CallId}");
61 SyslogAcct::~SyslogAcct()
65 GkAcctLogger::Status SyslogAcct::Log(
66 GkAcctLogger::AcctEvent evt,
70 // a workaround to prevent processing end on "sufficient" module
71 // if it is not interested in this event type
72 if ((evt & GetEnabledEvents() & GetSupportedEvents()) == 0)
76 PTRACE(1,"SYSLOGACCT\t"<<GetName()<<" - missing call info for event "<<evt);
80 PString sysloglevelconfig = GkConfig()->GetString(SyslogSec, "SyslogLevel", "LOG_INFO");
81 PString syslogfacilityconfig = GkConfig()->GetString(SyslogSec, "SyslogFacility", "LOG_USER");
84 if (sysloglevelconfig == "LOG_EMERG") {
85 syslog_level = LOG_EMERG;
86 } else if (sysloglevelconfig == "LOG_ALERT") {
87 syslog_level = LOG_ALERT;
88 } else if (sysloglevelconfig == "LOG_CRIT") {
89 syslog_level = LOG_CRIT;
90 } else if (sysloglevelconfig == "LOG_ERR") {
91 syslog_level = LOG_ERR;
92 } else if (sysloglevelconfig == "LOG_WARNING") {
93 syslog_level = LOG_WARNING;
94 } else if (sysloglevelconfig == "LOG_NOTICE") {
95 syslog_level = LOG_NOTICE;
96 } else if (sysloglevelconfig == "LOG_INFO") {
97 syslog_level = LOG_INFO;
98 } else if (sysloglevelconfig == "LOG_DEBUG") {
99 syslog_level = LOG_DEBUG;
101 syslog_level = LOG_INFO;
104 if (syslogfacilityconfig == "LOG_DAEMON") {
105 syslog_facility = LOG_DAEMON;
106 } else if (syslogfacilityconfig == "LOG_USER") {
107 syslog_facility = LOG_USER;
108 } else if (syslogfacilityconfig == "LOG_AUTH") {
109 syslog_facility = LOG_AUTH;
110 } else if (syslogfacilityconfig == "LOG_LOCAL0") {
111 syslog_facility = LOG_LOCAL0;
112 } else if (syslogfacilityconfig == "LOG_LOCAL1") {
113 syslog_facility = LOG_LOCAL1;
114 } else if (syslogfacilityconfig == "LOG_LOCAL2") {
115 syslog_facility = LOG_LOCAL2;
116 } else if (syslogfacilityconfig == "LOG_LOCAL3") {
117 syslog_facility = LOG_LOCAL3;
118 } else if (syslogfacilityconfig == "LOG_LOCAL4") {
119 syslog_facility = LOG_LOCAL4;
120 } else if (syslogfacilityconfig == "LOG_LOCAL5") {
121 syslog_facility = LOG_LOCAL5;
122 } else if (syslogfacilityconfig == "LOG_LOCAL6") {
123 syslog_facility = LOG_LOCAL6;
124 } else if (syslogfacilityconfig == "LOG_LOCAL7") {
125 syslog_facility = LOG_LOCAL7;
127 syslog_facility = LOG_USER;
132 if (evt == AcctStart) {
133 eventTmpl = m_startEvent;
134 } else if (evt == AcctConnect) {
135 eventTmpl = m_connectEvent;
136 } else if (evt == AcctUpdate) {
137 eventTmpl = m_updateEvent;
138 } else if (evt == AcctStop) {
139 eventTmpl = m_stopEvent;
142 if (!eventTmpl.IsEmpty()) { // don't send event if the template string is empty
143 std::map<PString, PString> params;
144 SetupAcctParams(params, call, m_timestampFormat);
145 PString msg = ReplaceAcctParams(eventTmpl, params);
146 openlog("GnuGk", LOG_PID, syslog_facility);
147 syslog(syslog_facility | syslog_level, "%s", (const char *)msg);
154 PString SyslogAcct::EscapeAcctParam(const PString& param) const
156 return "\"" + param + "\""; // test: quote
160 // append syslog accounting logger to the global list of loggers
161 GkAcctLoggerCreator<SyslogAcct> SyslogAcctCreator("SyslogAcct");