# HG changeset patch # User Sebastien Decugis # Date 1283499976 -32400 # Node ID 1b3b9790e7cb51877ea3350fc0ccbba9604e2db5 # Parent e27cb71abd4bbc0cb7ab632345ca970fea334bf2 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; diff -r e27cb71abd4b -r 1b3b9790e7cb doc/app_acct.conf.sample --- 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"; - - diff -r e27cb71abd4b -r 1b3b9790e7cb extensions/app_acct/acct_conf.l --- 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; } diff -r e27cb71abd4b -r 1b3b9790e7cb extensions/app_acct/acct_conf.y --- 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 ?: ""); fd_log_debug(" Table name .... : '%s'\n", acct_config->tablename ?: ""); fd_log_debug(" Timestamp field : '%s'\n", acct_config->tsfield ?: ""); + fd_log_debug(" Server name fld : '%s'\n", acct_config->srvnfield ?: ""); 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 + } + ; diff -r e27cb71abd4b -r 1b3b9790e7cb extensions/app_acct/acct_db.c --- 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); diff -r e27cb71abd4b -r 1b3b9790e7cb extensions/app_acct/app_acct.h --- 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: */