/
README
1102 lines (838 loc) · 38.1 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Acc Module
__________________________________________________________
Table of Contents
1. Admin Guide
1.1. Overview
1.1.1. General Example
1.2. Extra accounting
1.2.1. Overview
1.2.2. Definitions and syntax
1.2.3. How it works
1.2.4. Radius accounting dependencies
1.3. Multi Call-Legs accounting
1.3.1. Overview
1.3.2. Configuration
1.3.3. Logged data
1.4. CDRs accounting
1.4.1. Overview
1.4.2. Configuration
1.4.3. How it works
1.5. Dependencies
1.5.1. OpenSIPS Modules
1.5.2. External Libraries or Applications
1.6. Exported Parameters
1.6.1. early_media (integer)
1.6.2. report_cancels (integer)
1.6.3. detect_direction (integer)
1.6.4. extra_fields (string)
1.6.5. leg_fields (string)
1.6.6. log_level (integer)
1.6.7. log_facility (string)
1.6.8. aaa_url (string)
1.6.9. service_type (integer)
1.6.10. db_table_acc (string)
1.6.11. db_table_missed_calls (string)
1.6.12. db_url (string)
1.6.13. acc_method_column (string)
1.6.14. acc_from_tag_column (string)
1.6.15. acc_to_tag_column (string)
1.6.16. acc_callid_column (string)
1.6.17. acc_sip_code_column (string)
1.6.18. acc_sip_reason_column (string)
1.6.19. acc_time_column (string)
1.6.20. acc_created_avp_name (string)
1.7. Exported Pseudo-Variables
1.7.1. $acc_extra(tag_name)
1.7.2. $(acc_leg(tag_name)[leg_index])
1.7.3. $acc_current_leg (read-only)
1.8. Exported Functions
1.8.1. do_accounting(type, [flags], [table])
1.8.2. drop_accounting([type], [flags])
1.8.3. acc_log_request(comment)
1.8.4. acc_db_request(comment, table)
1.8.5. acc_aaa_request(comment)
1.8.6. acc_evi_request(comment)
1.8.7. acc_new_leg()
1.9. Exported Events
1.9.1. E_ACC_CDR
1.9.2. E_ACC_EVENT
1.9.3. E_ACC_MISSED_EVENT
2. Frequently Asked Questions
3. Contributors
3.1. By Commit Statistics
3.2. By Commit Activity
4. Documentation
4.1. Contributors
List of Tables
3.1. Top contributors by DevScore^(1), authored commits^(2) and
lines added/removed^(3)
3.2. Most recently active contributors^(1) to this module
List of Examples
1.1. early_media example
1.2. report_cancels example
1.3. detect_direction example
1.4. Setting extra_fields example:
1.5. Setting leg_fields example:
1.6. log_level example
1.7. log_facility example
1.8. Set aaa_url parameter
1.9. service_type example
1.10. db_table_acc example
1.11. db_table_missed_calls example
1.12. db_url example
1.13. acc_method_column example
1.14. acc_from_tag_column example
1.15. acc_to_tag_column example
1.16. acc_callid_column example
1.17. acc_sip_code_column example
1.18. acc_sip_reason_column example
1.19. acc_time_column example
1.20. acc_created_avp_name example
1.21. do_accounting usage
1.22. drop_accounting usage
1.23. acc_log_request usage
1.24. acc_db_request usage
1.25. acc_aaa_request usage
1.26. acc_evi_request usage
1.27. acc_new_leg usage
Chapter 1. Admin Guide
1.1. Overview
The ACC module is used to account transaction information to
different backends such as syslog, SQL, AAA.
To account a transaction and to choose which set of backends to
be used, the script writer only has to mark the transaction for
accounting by using the do_accounting() script function. Note
that the function is not actually doing the accounting at that
very time, it is just setting a marker - the actual accounting
will be done later when the transaction or dialog will be
completed.
Even so, the module allows the script writer to force
accounting on the spot in special cases via some other script
functions.
The accounting module will log by default a fixed set of
attributes for the transaction - if you customize your
accounting by adding more information to be logged, please see
the next chapter about extra accounting - Section 1.2, “Extra
accounting”.
The fixed minimal accounting information is:
* Request Method name
* From header TAG parameter
* To header TAG parameter
* Call-Id
* 3-digit Status code from final reply
* Reason phrase from final reply
* Timestamp when transaction was completed
If a value is not present in the request, the empty string is
accounted instead.
Note that:
* A single INVITE may produce multiple accounting reports --
that's most likely due to the SIP forking feature.
* Since version 2.2, all flags used for accounting have been
replaced with the do_accounting() function. No need to
worry anymore whether you have set the flags or not, or be
confused by various flag names, now you only have to call
the function and it will do all the work for you.
* OpenSIPS now supports session/dialog accounting. It can
automatically correlate INVITEs with BYEs for generating
proper CDRs, for example for billing purposes.
* If a UA fails in the middle of a conversation, a proxy will
never find out about it. In general, a better practice is
to account from an end-device (such as PSTN gateway), which
best knows about call status (including media status and
PSTN status in case of the gateway).
The SQL, Event Interface and AAA backend support are compiled
in the module.
A very comprehensive description of how the accounting module
works in terms accounting scope, accounting events and
accounting backends can be found in this online Advanced
Accounting Tutorial.
1.1.1. General Example
loadmodule "modules/acc/acc.so"
if ($ru=~"sip:+40") /* calls to Romania */ {
if (!proxy_authorize("sip_domain.net" /* realm */,
"subscriber" /* table name */)) {
proxy_challenge("sip_domain.net" /* realm */, "0" /* no qop */ )
;
exit;
}
if (is_method("INVITE") && $au!=$fU) {
xlog("FROM URI != digest username\n");
sl_send_reply("403","Forbidden");
}
do_accounting("log"); /* set for accounting via syslog */
t_relay(); /* enter stateful mode now */
};
1.2. Extra accounting
1.2.1. Overview
Along the static default information, the ACC module allows
dynamic selection of extra information to be logged using the
acc_extra pseudovariable. This allows you to log any
pseudo-variable (AVPs, parts of the request, parts of the
reply, etc).
1.2.2. Definitions and syntax
Selection of extra information is done via extra_field
parameter by specifying tags and log_names for the additional
information. This information is defined via acc_extra
pseudovariable, referenced with the define tag. If the tag is
not specified, its value will be considered to be the same as
the log_value. Accounting backend(log, db, aaa, evi) is
specified at the beginning of the definition, separated by ':'
from the rest. The syntax of the parameter is:
* backend : tag -> log_name (';'tag -> log_name)*
* backend : tag (';' tag)*
Extra values are consistent during the whole call. Setting a
value during a request, will cause it to remain visible during
all replies. Also, concerning CDR logging, setting a value on
the initial INVITE will result in having that value throughout
the dialog.
Via log_name you define how/where the data will be logged. Its
meaning depends of the accounting support which is used:
* LOG accounting - log_name will be just printed along with
the data in log_name=data format;
* DB accounting - log_name will be the name of the DB column
where the data will be stored.IMPORTANT: add in db acc
table the columns corresponding to each extra data;
* AAA accounting - log_name will be the AVP name used for
packing the data into AAA message. The log_name will be
translated to AVP number via the dictionary. IMPORTANT: add
in AAA dictionary the log_name attribute.
* Events accounting - log_name will be the name of the
parameter in the event raised.
1.2.3. How it works
Declaring an extra in the format of
modparam("acc", "extra_fields", "log: a -> test_a")
will enable you to set the value for test_a field of the log
only by setting $acc_extra(a) variable. Otherwise, the field
shall be logged with no value(null).
1.2.4. Radius accounting dependencies
If radius accounting is used, except from a radius client
library which is mandatory, dictionary.rfc2866 must be included
for the module to work properly.
1.3. Multi Call-Legs accounting
1.3.1. Overview
A SIP call can have multiple legs due forwarding actions. For
example user A calls user B which forwards the call to user C.
There is only one SIP call but with 2 legs ( A to B and B to
C). Accounting the legs of a call is required for proper
billing of the calls (if C is a PSTN number and the call is
billed, user B must pay for the call - as last party modifing
the call destination-, and not A - as initiator of the call.
Call forwarding on server is only one example which shows the
necessity of the having an accounting engine with multiple legs
support.
1.3.2. Configuration
First how it works: The idea is to have a variable to store a
set of values for each leg. The meaning of the variable content
is strictly decided by the script writer - it can be the origin
and source of the leg, its status or any other related
information. By default there is defined only one leg. Script
writer has to decide when is the time to create a new leg, by
using acc_new_leg() script function. When creating a new leg,
all the values for that leg will be set to NULL by default.
When the accounting information for the call will be
written/sent, all the call-leg pairs will be added.
By default, the multiple call-leg support is disabled - it can
be enabled just by setting acc_leg variable leg_fields module
parameter. Note that the last one only makes sense only for
CDRs that are generated automatically by OpenSIPS.
1.3.3. Logged data
For each call, all the values from the acc_leg variable will be
logged. How the information will be actually logged, depends of
the data backend:
* syslog -- all leg-sets will be added to one record string
as acc_leg(leg1)=xxx, acc_leg(leg2)=xxxx ,... sets.
* database -- each pair will be separately logged (due DB
data structure constraints); several records will be
written, the difference between them being only the fields
corresponding to the call-leg info.
Note
You will need to add in your DB (all acc related tables)
the colums for call-leg info (a column for each leg value
of the set).
* AAA -- all sets will be added to the same AAA accounting
message as AAA AVPs - for each call-leg a set of AAA AVPs
will be added (corresponding to the per-leg set)
Note
You will need to add in your dictionary the AAA AVPs used
in call-leg set definition.
* events -- each pair will appear as a different
parameter-value pair in the event. Similar to the database
behavior, multiple events will be raised, and the only
difference between them is the leg information.
Important!!! In order to use RADIUS, one must include the AVPs
which are located in
$(opensips_install_dir)/etc/dictionary.opensips, both in
opensips radius config script dictionary and radius server
dictionary. Most important are the last three AVPs (IDs : 227,
228, 229) which you won't find in any SIP dictionary (at least
at this moment) because they are only used in openSips.
1.4. CDRs accounting
1.4.1. Overview
ACC module can now also maintain session/dialog accounting.
This allows you to log useful information like call duration,
call start time and setup time.
1.4.2. Configuration
In order to have CDRs accounting, first you need to set the cdr
flag when calling do_accounting() script function for the
initial INVITE of the dialog.
1.4.3. How it works
This type of accounting is based on the dialog module. When an
initial INVITE is received, if the cdr flag is set, then the
dialog creation time is saved. Once the call is answered and
the ACK is received, other information like extra values or leg
values are saved. When the corresponding BYE is received, the
call duration is computed and all information is stored to the
desired backend.
1.5. Dependencies
1.5.1. OpenSIPS Modules
The module depends on the following modules (in the other words
the listed modules must be loaded before this module):
* tm -- Transaction Manager
* a database module -- If SQL support is used.
* rr -- Record Route, if “detect_direction” module parameter
is enabled.
* an aaa module
* dialog -- Dialog, if “cdr” option is used
1.5.2. External Libraries or Applications
The following libraries or applications must be installed
before running OpenSIPS with this module loaded:
* none.
1.6. Exported Parameters
1.6.1. early_media (integer)
Should be early media (any provisional reply with body)
accounted too ?
Default value is 0 (no).
Example 1.1. early_media example
modparam("acc", "early_media", 1)
1.6.2. report_cancels (integer)
By default, CANCEL reporting is disabled -- most accounting
applications wants to see INVITE's cancellation status. Turn on
if you explicitly want to account CANCEL transactions.
Default value is 0 (no).
Example 1.2. report_cancels example
modparam("acc", "report_cancels", 1)
1.6.3. detect_direction (integer)
Controls the direction detection for sequential requests. If
enabled (non zero value), for sequential requests with upstream
direction (from callee to caller), the FROM and TO will be
swapped (the direction will be preserved as in the original
request).
It affects all values related to TO and FROM headers (body,
URI, username, domain, TAG).
Default value is 0 (disabled).
Example 1.3. detect_direction example
modparam("acc", "detect_direction", 1)
1.6.4. extra_fields (string)
Defines the tag-log_value set to be used in extra fields
accounting. See Section 1.2, “Extra accounting” for a detailed
description of the Extra accounting.
If empty, extra accounting support will be disabled.
Default value is 0 (disabled).
Example 1.4. Setting extra_fields example:
# for syslog-based accounting, use any text you want to be printed
# if setting $acc_extra(a) you will see "My_a_Field=<value> in logs
# if setting $acc_extra(b) you will see "b=<value> in logs
modparam("acc", "extra_fields", "log: a->My_a_Field; b")
# for mysql-based accounting, use the names of the columns
# $acc_extra(a) = <value> results in setting col_a with <value> in db
modparam("acc", "extra_fields", "db: a->col_a; col_b")
# for AAA-based accounting, use the names of the AAA AVPs
modparam("acc", "extra_fields","aaa:a->AAA_SRC;b->AAA_DST")
# evi definition example
modparam("acc", "extra_fields","a->2345;b->2346")
1.6.5. leg_fields (string)
Defines the tag-log_value set to be used in multi-leg
accounting. See Section 1.3, “Multi Call-Legs accounting” for a
detailed description of the Multi Call-Legs accounting.
If empty, multi-leg accounting support will be disabled.
Default value is 0 (disabled).
Example 1.5. Setting leg_fields example:
# for syslog-based accounting, use any text you want to be printed
# if setting $(acc_leg(a)[0]) you will see "My_a_Field=<value> in logs
# if setting $(acc_leg(b)[0]) you will see "b=<value> in logs
modparam("acc", "leg_fields", "log: a->My_a_Field; b")
# for mysql-based accounting, use the names of the columns
# $acc_leg(a) = <value> results in setting col_a with <value> in db
modparam("acc", "leg_fields", "db: a->col_a; col_b")
# for AAA-based accounting, use the names of the AAA AVPs
modparam("acc", "leg_fields","aaa:a->AAA_LEG_SRC;b->AAA_LEG_DST")
# evi definition example
modparam("acc", "leg_fields","a->2345;b->2346")
1.6.6. log_level (integer)
Log level at which accounting messages are issued to syslog.
Default value is L_NOTICE.
Example 1.6. log_level example
modparam("acc", "log_level", 2) # Set log_level to 2
1.6.7. log_facility (string)
Log facility to which accounting messages are issued to syslog.
This allows to easily seperate the accounting specific logging
from the other log messages.
Default value is LOG_DAEMON.
Example 1.7. log_facility example
modparam("acc", "log_facility", "LOG_DAEMON")
1.6.8. aaa_url (string)
This is the url representing the AAA protocol used and the
location of the configuration file of this protocol.
If the parameter is set to empty string, the AAA accounting
support will be disabled.
Default value is “NULL”.
Example 1.8. Set aaa_url parameter
...
modparam("acc", "aaa_url", "radius:/etc/radiusclient-ng/radiusclient.con
f")
...
1.6.9. service_type (integer)
AAA service type used for accounting.
Default value is not-set.
Example 1.9. service_type example
# Default value of service type for SIP is 15
modparam("acc", "service_type", 15)
1.6.10. db_table_acc (string)
Table name of accounting successfull calls -- database
specific.
Default value is “acc”
Example 1.10. db_table_acc example
modparam("acc", "db_table_acc", "myacc_table")
1.6.11. db_table_missed_calls (string)
Table name for accounting missed calls -- database specific.
Default value is “missed_calls”
Example 1.11. db_table_missed_calls example
modparam("acc", "db_table_missed_calls", "myMC_table")
1.6.12. db_url (string)
SQL address -- database specific. If is set to NULL or empty
string, the SQL support is disabled.
Default value is “NULL” (SQL disabled).
Example 1.12. db_url example
modparam("acc", "db_url", "mysql://user:password@localhost/opensips")
1.6.13. acc_method_column (string)
Column name in accounting table to store the request's method
name as string.
Default value is “method”.
Example 1.13. acc_method_column example
modparam("acc", "acc_method_column", "method")
1.6.14. acc_from_tag_column (string)
Column name in accounting table to store the From header TAG
parameter.
Default value is “from_tag”.
Example 1.14. acc_from_tag_column example
modparam("acc", "acc_from_tag_column", "from_tag")
1.6.15. acc_to_tag_column (string)
Column name in accounting table to store the To header TAG
parameter.
Default value is “to_tag”.
Example 1.15. acc_to_tag_column example
modparam("acc", "acc_to_tag_column", "to_tag")
1.6.16. acc_callid_column (string)
Column name in accounting table to store the request's Callid
value.
Default value is “callid”.
Example 1.16. acc_callid_column example
modparam("acc", "acc_callid_column", "callid")
1.6.17. acc_sip_code_column (string)
Column name in accounting table to store the final reply's
numeric code value in string format.
Default value is “sip_code”.
Example 1.17. acc_sip_code_column example
modparam("acc", "acc_sip_code_column", "sip_code")
1.6.18. acc_sip_reason_column (string)
Column name in accounting table to store the final reply's
reason phrase value.
Default value is “sip_reason”.
Example 1.18. acc_sip_reason_column example
modparam("acc", "acc_sip_reason_column", "sip_reason")
1.6.19. acc_time_column (string)
Column name in accounting table to store the time stamp of the
transaction completion in date-time format.
Default value is “time”.
Example 1.19. acc_time_column example
modparam("acc", "acc_time_column", "time")
1.6.20. acc_created_avp_name (string)
The name of the openSips avp that will be used to hold the time
when the call was created. This time will only be logged on
missed calls.
Default value is "accX_created".
Example 1.20. acc_created_avp_name example
modparam("acc", "acc_created_avp_name", "call_created_avp")
1.7. Exported Pseudo-Variables
1.7.1. $acc_extra(tag_name)
This variable can addresed with the tag names defined using
extra_fields. If do_accounting() isn't called, this variable is
visible during the whole processing of one message, enabling
calling acc_XXX_request(). If do_accounting() is called, the
variable will be visible from the first call of this function
until the actual accounting is being made.
1.7.2. $(acc_leg(tag_name)[leg_index])
This variable can be addressed with the tag names defined using
leg_fields and a valid leg index (<= $acc_current_leg). This
variable cannot be used unless do_accounting() is used. The
variable also accepts negative indexes, which start from -1
(the lastly added leg).
# the "caller" value of the current leg
$acc_leg(caller)
# the "caller" value of the lastly added leg
$(acc_leg(caller)[-1]) # equivalent to $acc_leg(caller)
# equivalent to $(acc_leg(caller)[$acc_current_le
g])
# the "caller" value of the next-to-last leg
$(acc_leg(caller)[-2])
1.7.3. $acc_current_leg (read-only)
Holds the index of the current leg, starting from 0. Calling
acc_new_leg() will increment this index.
1.8. Exported Functions
1.8.1. do_accounting(type, [flags], [table])
do_accounting() replaces all the *_flag and, *_missed_flag,
cdr_flag, failed transaction_flag and the db_table_avp
modparams. Just call do_accounting(), select where and how you
want the accounting to take place, and the function will do all
the work for you.
Meaning of the parameters is as follows:
* type (string) - the type of accounting you want to do. All
types have to be separated by '|'. The following parameters
can be used:
+ log - syslog accounting;
+ db - database accounting;
+ aaa - aaa specific accounting;
+ evi - Event Interface accounting;
* flags (string, optional) - flags for the accounting type
you have selected. All the types have to be separated by
'|'. The following parameters can be used:
+ cdr - enables dialog-level accounting. OpenSIPS will
internally detect dialog termination
(generation/receipt of a BYE request), and store the
CDR as soon as the BYE request is replied to. By
enabling the "cdr" flag, the following additional
fields will be populated: duration, ms_duration,
setuptime, created. (requires dialog module support)
+ missed - log missed calls; take care that this flag
will be deactivated after the first missed call; you
will have to reactivate it in the failure_route if you
want to account each destination that did not respond
to the call;
+ failed - flag which indicates if the transaction
should also be accounted in case of failure
(status>=300);
* table (string, optional) - table where to do the
accounting; it replaces old table_avp parameter;
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.21. do_accounting usage
...
if (!has_totag()) {
if (is_method("INVITE")) {
/* enable cdr and missed calls accounting in the
database
* and to syslog; db accounting shall be done in
"my_acc" table */
do_accounting("db|log", "cdr|missed", "m
y_acc");
}
}
...
if (is_method("BYE")) {
/* do normal accounting via aaa */
do_accounting("aaa");
}
...
1.8.2. drop_accounting([type], [flags])
drop_accounting() resets flags and types of accounting set with
do_accounting(). If called with no arguments all accounting
will be stopped. If called with only one argument all
accounting for that type will be stopped. If called with two
arguments normal accounting will still be enabled.
Meaning of the parameters is as follows:
* type (string, optional) - the type of accounting you want
to stop. All the types have to be separated by '|'. The
following parameters can be used:
+ log - stop syslog accounting;
+ db - stop database accounting;
+ aaa - stop aaa specific accounting;
+ evi - stop Event Interface accounting;
* flags (string, optional) - flags to be reset for the
accouting type you have selected. All the types have to be
separated by '|'. The following parameters can be used:
+ cdr - stop CDR accounting;
+ missed - stop logging missed calls;
+ failed - stop failed transaction accounting;
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.22. drop_accounting usage
...
acc_log_request("403 Destination not allowed");
if (!has_totag()) {
if (is_method("INVITE")) {
/* enable cdr and missed calls accounting in the
database
* and to syslog; db accounting shall be done in
"my_acc" table */
do_accounting("db|log", "cdr|missed", "m
y_acc");
}
}
...
/* later in your script */
if (...) { /* you don't want accounting anymore */
/* stop all syslog accounting */
drop_accounting("log");
/* or stop missed calls and cdr accounting for s
yslog;
* normal accounting will still be enabled */
drop_accounting("log", "missed|cdr");
/* or stop all types of accounting */
drop_accounting();
}
...
1.8.3. acc_log_request(comment)
acc_request reports on a request, for example, it can be used
to report on missed calls to off-line users who are replied 404
- Not Found. To avoid multiple reports on UDP request
retransmission, you would need to embed the action in stateful
processing.
Meaning of the parameters is as follows:
* comment (string) - Comment describing how the request
completed - this string has to contain a reply code
followed by a reply reason phrase (ex: "480 Nobody Home").
Variables are accepted in this string.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.23. acc_log_request usage
...
acc_log_request("403 Destination not allowed");
...
1.8.4. acc_db_request(comment, table)
Like acc_log_request, acc_db_request reports on a request. The
report is sent to database at “db_url”, in the table referred
to in the second action parameter.
Meaning of the parameters is as follows:
* comment (string) - Comment describing how the request
completed - this string has to contain a reply code
followed by a reply reason phrase (ex: "480 Nobody Home").
Variables are accepted in this string.
* table (string) - Database table to be used.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.24. acc_db_request usage
...
acc_db_request("Some comment", "Some table");
acc_db_request("$T_reply_code $(<reply>rr)", "acc");
...
1.8.5. acc_aaa_request(comment)
Like acc_log_request, acc_aaa_request reports on a request. It
reports to aaa server as configured in “aaa_url”.
Meaning of the parameters is as follows:
* comment (string) - Comment describing how the request
completed - this string has to contain a reply code
followed by a reply reason phrase (ex: "404 Nobody home").
Variables are accepted in this string.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.25. acc_aaa_request usage
...
acc_aaa_request("403 Destination not allowed");
...
1.8.6. acc_evi_request(comment)
Like acc_log_request, acc_evi_request reports on a request. The
report is packed as an event sent through the OpenSIPS Event
Interface as E_ACC_EVENT if the reply code is a positive one
(lower than 300), or E_ACC_MISSED_EVENT for negative or no
codes. More information on this in Exported Events.
Meaning of the parameters is as follows:
* comment (string) - Comment describing how the request
completed - this string has to contain a reply code
followed by a reply reason phrase (ex: "404 Nobody home")
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.26. acc_evi_request usage
...
acc_evi_request("403 Destination not allowed");
...
1.8.7. acc_new_leg()
Creates a new leg and increments $acc_current_leg only if
multi-leg accounting is used. All values of the new leg will be
initialized to null.
This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
BRANCH_ROUTE and LOCAL_ROUTE.
Example 1.27. acc_new_leg usage
...
acc_new_leg();
...
1.9. Exported Events
1.9.1. E_ACC_CDR
The event raised when a CDR is generated. Note that this event
will only be triggered if the auto CDR accounting is used.
Parameters:
* method - Request method name
* from_tag - From header tag parameter
* to_tag - To header tag parameter
* callid - Message Call-id
* sip_code - The status code from the final reply
* sip_reason - The status reason from the final reply
* time - The timestamp when the call was established
* evi_extra* - Extra parameters added by the evi_extra
parameter.
* evi_extra_bye* - Extra parameters added by the
evi_extra_bye parameter
* multi_leg_info* - Extra parameters added by the
multi_leg_info parameter
* multi_leg_bye_info* - Extra parameters added by the
multi_leg_bye_info parameter
* duration - The call duration in seconds
* setuptime - The call setup time in seconds
* created - The timestamp when the call was created (the
initial Invite was received)
1.9.2. E_ACC_EVENT
This event is triggered when old-style accounting is used. It
is generated when the requests (INVITE and BYE) transaction
have positive final replies, or by the acc_evi_request()
function that has a positive reply code in comment.
Parameters:
* method - Request method name
* from_tag - From header tag parameter
* to_tag - To header tag parameter
* callid - Message Call-id
* sip_code - The status code from the final reply
* sip_reason - The status reason from the final reply
* time - The timestamp when the transaction was created
* evi_extra* - Extra parameters added by the evi_extra
parameter
* multi_leg_info* - Extra parameters added by the
multi_leg_info parameter
1.9.3. E_ACC_MISSED_EVENT
This event is triggered when old-style accounting is used. It
is generated when the requests (INVITE and BYE) transaction
have negative final replies, or by the acc_evi_request()
function that has a negative reply code in comment.
Parameters:
* method - Request method name
* from_tag - From header tag parameter
* to_tag - To header tag parameter
* callid - Message Call-id
* sip_code - The status code from the final reply
* sip_reason - The status reason from the final reply
* time - The timestamp when the transaction was created
* evi_extra* - Extra parameters added by the evi_extra
parameter
* multi_leg_info* - Extra parameters added by the
multi_leg_info parameter
* created - Timestamp when the call was created
* setuptime - The call setup time in seconds
Chapter 2. Frequently Asked Questions
2.1.
What happened with old report_ack parameter
The parameter is considered obsolete. It was removed as acc
module is doing SIP transaction based accouting and according
to SIP RFC, end2end ACKs are a different transaction (still
part of the same dialog). ACKs can be individually accouted as
any other sequential (in-dialog) request.
$
2.2.
What happened with old log_fmt parameter
The parameter became obsolete with the restructure of the data
logged by ACC module (refer to the Overview chapter). For
similar behaviour you can use the extra accouting (see the
corresponding chapter).
2.3.
What happened with old multi_leg_enabled parameter
The parameter became obsolete by the addition of the new
multi_leg_info parameter. The multi-leg accouting is
automatically enabled when multi_leg_info is defined.
2.4.
What happened with old src_leg_avp_id and dst_leg_avp_id
parameters
The parameter was replaced by the more generic new parameter
multi_leg_info. This allows logging (per-leg) of more
information than just dst and src.
2.5.
Where can I find more about OpenSIPS?
Take a look at http://www.opensips.org/.
2.6.
Where can I post a question about this module?
First at all check if your question was already answered on one
of our mailing lists:
* User Mailing List -
http://lists.opensips.org/cgi-bin/mailman/listinfo/users
* Developer Mailing List -
http://lists.opensips.org/cgi-bin/mailman/listinfo/devel
E-mails regarding any stable OpenSIPS release should be sent to
<users@lists.opensips.org> and e-mails regarding development
versions should be sent to <devel@lists.opensips.org>.