changeset 528:1b3b9790e7cb

Add a new field in the app_acct.fdx database to receive the name of the local server. Update your existing tables with the following SQL command: ALTER TABLE "incoming" ADD "recorded_serv" bytea NOT NULL;
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 03 Sep 2010 16:46:16 +0900
parents e27cb71abd4b
children be646053706b
files doc/app_acct.conf.sample extensions/app_acct/acct_conf.l extensions/app_acct/acct_conf.y extensions/app_acct/acct_db.c extensions/app_acct/app_acct.h
diffstat 5 files changed, 41 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/doc/app_acct.conf.sample	Wed Sep 01 16:49:02 2010 +0900
+++ b/doc/app_acct.conf.sample	Fri Sep 03 16:46:16 2010 +0900
@@ -44,7 +44,7 @@
 #  "AVP-dictionary-name";
 #
 # Note that at the moment, GROUPED AVP are not supported. Also, only the top-level AVPs are
-# search. This behavior can be changed quite easily if needed.
+# searched. This behavior can be changed quite easily if needed.
 
 # The following list is informative only.
 # You may also consult RFC4005 sections 10.2.1 and 10.2.2 for other examples
@@ -107,8 +107,9 @@
 # "Route-Record" = { multi=5; }; # Record the last 5 hops of the message
 
 # This is the database table corresponding to this list:
-# CREATE TABLE app_acct (
+# CREATE TABLE incoming (
 #     "recorded_on" timestamp with time zone NOT NULL,
+#     "recorded_serv" bytea NOT NULL,
 #     "Origin-Host" bytea NOT NULL,
 #     "Origin-Realm" bytea NOT NULL,
 #     "Destination-Realm" bytea,
@@ -194,9 +195,14 @@
 # Timestamp_field:
 # Optionaly, you can specify a name of a field that will receive the value 'now' when a new record is inserted.
 # Default: no timestamp is inserted.
-# Example: Timestamp_field = "inc_ts";
+# Example: Timestamp_field = "recorded_on";
+
+# Server_name_field:
+# Optionaly, you can specify a field which will receive the Diameter Identity of the local server for each record saved.
+# This is useful especially if you have several Accounting servers and want to check Load-Balancing behavior or so,
+# after aggregating all the data.
+# Default: no server name inserted.
+# Example: Server_name_field = "recorded_serv";
 
 
 
-
-
--- a/extensions/app_acct/acct_conf.l	Wed Sep 01 16:49:02 2010 +0900
+++ b/extensions/app_acct/acct_conf.l	Fri Sep 03 16:46:16 2010 +0900
@@ -113,6 +113,10 @@
 				return TSFIELD;
 			}
 
+(?i:"Server_name_field") {
+				return SRVNFIELD;
+			}
+
 (?i:"field")		{
 				return FIELD;
 			}
--- a/extensions/app_acct/acct_conf.y	Wed Sep 01 16:49:02 2010 +0900
+++ b/extensions/app_acct/acct_conf.y	Fri Sep 03 16:46:16 2010 +0900
@@ -101,6 +101,7 @@
 	fd_log_debug("   ConnInfo ...... : '%s'\n", acct_config->conninfo ?: "<null>");
 	fd_log_debug("   Table name .... : '%s'\n", acct_config->tablename ?: "<null>");
 	fd_log_debug("   Timestamp field : '%s'\n", acct_config->tsfield ?: "<null>");
+	fd_log_debug("   Server name fld : '%s'\n", acct_config->srvnfield ?: "<null>");
 	fd_log_debug(" AVPs that will be saved to the database:\n");
 	for (li = acct_config->avps.next; li != &acct_config->avps; li = li->next) {
 		struct acct_conf_avp * a = (struct acct_conf_avp *)li;
@@ -136,6 +137,7 @@
 	free(acct_config->conninfo);
 	free(acct_config->tablename);
 	free(acct_config->tsfield);
+	free(acct_config->srvnfield);
 	
 	/* Done */
 	free(acct_config);
@@ -204,6 +206,7 @@
 %token 		CONNINFO
 %token 		TABLE
 %token 		TSFIELD
+%token 		SRVNFIELD
 
 /* Tokens and types */
 /* A (de)quoted string (malloc'd in lex parser; it must be freed after use) */
@@ -223,6 +226,7 @@
 			| conffile conninfoline
 			| conffile tableline
 			| conffile tsfieldline
+			| conffile srvnfieldline
 			| conffile errors
 			{
 				yyerror(&yylloc, conffile, "An error occurred while parsing the configuration file.");
@@ -320,3 +324,13 @@
 				acct_config->tsfield = $3
 			}
 			;
+
+srvnfieldline:		SRVNFIELD '=' QSTRING ';'
+			{
+				if (acct_config->srvnfield) {
+					yyerror (&yylloc, conffile, "Duplicate entry");
+					YYERROR;
+				}
+				acct_config->srvnfield = $3
+			}
+			;
--- a/extensions/app_acct/acct_db.c	Wed Sep 01 16:49:02 2010 +0900
+++ b/extensions/app_acct/acct_db.c	Fri Sep 03 16:46:16 2010 +0900
@@ -141,6 +141,12 @@
 		ADD_EXTEND("\", ");
 	}
 	
+	if (acct_config->srvnfield) {
+		ADD_EXTEND("\"");
+		ADD_ESCAPE(acct_config->srvnfield);
+		ADD_EXTEND("\", ");
+	}
+	
 	for (li = emptyrecords.all.next; li != &emptyrecords.all; li = li->next) {
 		struct acct_record_item * i = (struct acct_record_item *)(li->o);
 		ADD_EXTEND("\"");
@@ -158,6 +164,11 @@
 	if (acct_config->tsfield) {
 		ADD_EXTEND("$%d, ", ++idx);
 	}
+	if (acct_config->srvnfield) {
+		ADD_EXTEND("\"");
+		ADD_ESCAPE(fd_g_config->cnf_diamid);
+		ADD_EXTEND("\", ");
+	}
 	
 	for (li = emptyrecords.all.next; li != &emptyrecords.all; li = li->next) {
 		struct acct_record_item * i = (struct acct_record_item *)(li->o);
--- a/extensions/app_acct/app_acct.h	Wed Sep 01 16:49:02 2010 +0900
+++ b/extensions/app_acct/app_acct.h	Fri Sep 03 16:46:16 2010 +0900
@@ -74,6 +74,7 @@
 	char		*conninfo;	/* the connection string to the database, that is passed as is to the database library */
 	char 		*tablename;	/* the name of the table we are working with */
 	char 		*tsfield;	/* the name of the timestamp field, or NULL if not required */
+	char 		*srvnfield;	/* the name of the server name field, or NULL if not required */
 };
 
 /* A successfully parsed Accounting-Request produces a list of these: */
"Welcome to our mercurial repository"