add format_cdr.conf

This commit is contained in:
Donghuang 2021-09-08 00:06:27 +08:00
parent 1e102b6bad
commit 33e026a92d
7 changed files with 172 additions and 12 deletions

View File

@ -56,6 +56,17 @@ public class BaseXmlController {
return view; return view;
} }
/**
* add view attr model
*
* @param view view
* @param val attr value
* @return view
*/
protected FreeMarkerView attr(final FreeMarkerView view, final Object val) {
return attr(view, "model", val);
}
/** /**
* add view attr * add view attr
* *

View File

@ -13,6 +13,8 @@ import com.pudonghot.yo.fsagent.util.OdbcUtils;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import com.pudonghot.yo.fsagent.service.IvrMenuService; import com.pudonghot.yo.fsagent.service.IvrMenuService;
import com.pudonghot.yo.fsagent.service.GatewayService; import com.pudonghot.yo.fsagent.service.GatewayService;
import com.pudonghot.yo.fsagent.service.LocalApiService;
import com.pudonghot.yo.fsagent.model.FormatCdrConfFtlModel;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
@ -40,6 +42,8 @@ public class ConfigController extends BaseXmlController {
private DataSource dataSource; private DataSource dataSource;
@Autowired @Autowired
private IvrMenuService ivrMenuService; private IvrMenuService ivrMenuService;
@Autowired
private LocalApiService localApiService;
public static final Pattern PATTERN_IP_SIP_HOST = patternIpSipHost(); public static final Pattern PATTERN_IP_SIP_HOST = patternIpSipHost();
private List<String> REALM_PARAM_NAMES = private List<String> REALM_PARAM_NAMES =
@ -81,8 +85,7 @@ public class ConfigController extends BaseXmlController {
@RequestParam @RequestParam
final Map<String, Object> params) { final Map<String, Object> params) {
log.info("Fetch sofia config XML."); log.info("Fetch sofia config XML, params [{}].", params);
log.debug("XML sofia config [{}].", params);
val view = configView("sofia.conf.xml"); val view = configView("sofia.conf.xml");
val gateways = gatewayService.list( val gateways = gatewayService.list(
@ -98,8 +101,7 @@ public class ConfigController extends BaseXmlController {
@RequestParam @RequestParam
final Map<String, Object> params) { final Map<String, Object> params) {
log.info("Fetch ACL config XML."); log.info("Fetch ACL config XML, params [{}].", params);
log.debug("XML ACL config [{}].", params);
return configView("acl.conf.xml"); return configView("acl.conf.xml");
} }
@ -114,8 +116,7 @@ public class ConfigController extends BaseXmlController {
@RequestParam @RequestParam
final Map<String, Object> params) { final Map<String, Object> params) {
log.info("Fetch ODBC CDR config XML."); log.info("Fetch ODBC CDR config XML, params [{}].", params);
log.debug("XML ODBC CDR [{}].", params);
val view = configView("odbc_cdr.conf.xml"); val view = configView("odbc_cdr.conf.xml");
attr(view, "odbcDsn", OdbcUtils.odbcDsn((DruidDataSource) dataSource)); attr(view, "odbcDsn", OdbcUtils.odbcDsn((DruidDataSource) dataSource));
@ -128,8 +129,7 @@ public class ConfigController extends BaseXmlController {
@RequestParam @RequestParam
final Map<String, Object> params) { final Map<String, Object> params) {
log.info("Fetch event socket config XML."); log.info("Fetch event socket config XML, params [{}].", params);
log.debug("XML event socket config [{}].", params);
return configView("event_socket.conf.xml"); return configView("event_socket.conf.xml");
} }
@ -138,8 +138,7 @@ public class ConfigController extends BaseXmlController {
@RequestParam @RequestParam
final Map<String, Object> params) { final Map<String, Object> params) {
log.info("Fetch cURL config XML."); log.info("Fetch cURL config XML, params [{}].", params);
log.debug("XML cURL [{}].", params);
return configView("curl.conf.xml"); return configView("curl.conf.xml");
} }
@ -169,12 +168,22 @@ public class ConfigController extends BaseXmlController {
@RequestParam @RequestParam
final Map<String, Object> params) { final Map<String, Object> params) {
log.info("Fetch FIFO config XML."); log.info("Fetch FIFO config XML, params [{}].", params);
log.debug("XML IVR [{}].", params);
return configView("fifo.conf.xml"); return configView("fifo.conf.xml");
} }
@RequestMapping(params = "key_value=format_cdr.conf")
public FreeMarkerView formatCdrConfig(
@RequestParam
final Map<String, Object> params) {
log.info("Fetch Format config XML, params [{}].", params);
return attr(configView("format_cdr.conf.xml"),
new FormatCdrConfFtlModel(localApiService.getCdrPostUrl()));
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */

View File

@ -0,0 +1,23 @@
package com.pudonghot.yo.fsagent.controller;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
* @author Donghuang <br>
* Jan 06, 2020 18:05:31
*/
@Slf4j
@Controller
public class PostCdrController {
@PostMapping("/fsa/api/cdr/post")
public void postCdr(
@RequestParam
final Map<String, String> params) {
log.info("Post cdr params: {}", params);
}
}

View File

@ -0,0 +1,19 @@
package com.pudonghot.yo.fsagent.model;
import lombok.Getter;
import lombok.ToString;
import java.io.Serializable;
import lombok.RequiredArgsConstructor;
/**
* @author Donghuang
* @date Sep 07, 2021 10:38:18
*/
@Getter
@ToString
@RequiredArgsConstructor
public class FormatCdrConfFtlModel implements Serializable {
private static final long serialVersionUID = 1L;
private final String postUrl;
}

View File

@ -48,4 +48,11 @@ public interface LocalApiService {
* @return post rec url * @return post rec url
*/ */
String getPostRecUrl(); String getPostRecUrl();
/**
* on cdr post url
*
* @return post cdr url
*/
String getCdrPostUrl();
} }

View File

@ -41,6 +41,8 @@ public class LocalApiServiceImpl
private String agentReadyUrl; private String agentReadyUrl;
@Getter @Getter
private String agentNotReadyUrl; private String agentNotReadyUrl;
@Getter
private String cdrPostUrl;
/** /**
* {@inheritDoc} * {@inheritDoc}
@ -67,5 +69,6 @@ public class LocalApiServiceImpl
postRecUrl = getUrl("/fsa/api/post-rec"); postRecUrl = getUrl("/fsa/api/post-rec");
agentReadyUrl = getUrl("/fsa/api/agent/ready"); agentReadyUrl = getUrl("/fsa/api/agent/ready");
agentNotReadyUrl = getUrl("/fsa/api/agent/not-ready"); agentNotReadyUrl = getUrl("/fsa/api/agent/not-ready");
cdrPostUrl = getUrl("/fsa/api/cdr/post");
} }
} }

View File

@ -0,0 +1,88 @@
<configuration name="format_cdr.conf" description="Multi Format CDR CURL logger">
<!-- You can have multiple profiles, to allow logging to both JSON and XML simultaneously, or to
different paths or servers with different settings, just be sure to use different name for
each profile. -->
<profiles>
<profile name="default">
<settings>
<!-- the format of data to send, defaults to xml -->
<!-- <param name="format" value="json|xml"/> -->
<param name="format" value="json"/>
<!-- the url to post to if blank web posting is disabled -->
<param name="url" value="${model.postUrl}"/>
<!-- optional: credentials to send to web server -->
<!-- <param name="cred" value="user:pass"/> -->
<!-- the total number of retries (not counting the first 'try') to post to webserver incase of failure -->
<param name="retries" value="2"/>
<!-- delay between retries in seconds, default is 5 seconds -->
<param name="delay" value="4200"/>
<!-- Log via http and on disk, default is false -->
<!-- <param name="log-http-and-disk" value="true"/> -->
<!-- optional: if not present we do not log every record to disk -->
<!-- either an absolute path, a relative path assuming ${prefix}/logs or a blank value will default to ${prefix}/logs/format_cdr -->
<param name="log-dir" value="/var/log/freeswitch/format_cdr"/>
<!-- optional: if not present we do log the b leg -->
<!-- true or false if we should create a cdr for the b leg of a call-->
<param name="log-b-leg" value="true"/>
<!-- optional: if not present, all filenames are the uuid of the call -->
<!-- true or false if a leg files are prefixed "a_" -->
<param name="prefix-a-leg" value="true"/>
<!-- encode the post data may be 'true' for url encoding, 'false' for no encoding, 'base64' for base64 encoding, 'textxml' for text/xml or 'appljson' for application/json-->
<param name="encode" value="true"/>
<!-- optional: set to true to disable Expect: 100-continue lighttpd requires this setting -->
<!--<param name="disable-100-continue" value="true"/>-->
<!-- optional: full path to the error log dir for failed web posts if not specified its the same as log-dir -->
<!-- either an absolute path, a relative path assuming ${prefix}/logs or a blank or omitted value will default to ${prefix}/logs/format_cdr -->
<param name="err-log-dir" value="/var/log/freeswitch/format_cdr/failed"/>
<!-- which auhtentification scheme to use. Supported values are: basic, digest, NTLM, GSS-NEGOTIATE or "any" for automatic detection -->
<!--<param name="auth-scheme" value="basic"/>-->
<!-- optional: this will enable the CA root certificate check by libcurl to
verify that the certificate was issued by a major Certificate Authority.
note: default value is disabled. only enable if you want this! -->
<!--<param name="enable-cacert-check" value="true"/>-->
<!-- optional: verify that the server is actually the one listed in the cert -->
<!-- <param name="enable-ssl-verifyhost" value="true"/> -->
<!-- optional: these options can be used to specify custom SSL certificates
to use for HTTPS communications. Either use both options or neither.
Specify your public key with 'ssl-cert-path' and the private key with
'ssl-key-path'. If your private key has a password, specify it with
'ssl-key-password'. -->
<!-- <param name="ssl-cert-path" value="$${base_dir}/conf/certs/public_key.pem"/> -->
<!-- <param name="ssl-key-path" value="$${base_dir}/conf/certs/private_key.pem"/> -->
<!-- <param name="ssl-key-password" value="MyPrivateKeyPassword"/> -->
<!-- optional: use a custom CA certificate in PEM format to verify the peer
with. This is useful if you are acting as your own certificate authority.
note: only makes sense if used in combination with "enable-cacert-check." -->
<!-- <param name="ssl-cacert-file" value="$${base_dir}/conf/certs/cacert.pem"/> -->
<!-- optional: specify the SSL version to force HTTPS to use. Valid options are
"SSLv3" and "TLSv1". Otherwise libcurl will auto-negotiate the version. -->
<!-- <param name="ssl-version" value="TLSv1"/> -->
<!-- optional: enables cookies and stores them in the specified file. -->
<!-- <param name="cookie-file" value="/tmp/cookie-mod_format_cdr_curl.txt"/> -->
<!-- Whether to URL encode the individual JSON values. Defaults to true, set to false for standard JSON. -->
<param name="encode-values" value="true"/>
</settings>
</profile>
</profiles>
</configuration>