2 #---------------------------------------------------------------------------
4 # Copyright (c) 1996, 1998 Hellmuth Michaelis. All rights reserved.
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #---------------------------------------------------------------------------
29 # accounting report script for the isdnd daemon accounting info
30 # -------------------------------------------------------------
32 # last edit-date: [Fri May 25 15:28:20 2001]
34 # $FreeBSD: src/share/examples/isdn/contrib/isdnd_acct,v 1.1.2.1 2001/08/10 14:59:48 obrien Exp $
35 # $DragonFly: src/share/examples/isdn/contrib/isdnd_acct,v 1.2 2003/06/17 04:36:57 dillon Exp $
37 #---------------------------------------------------------------------------
39 # where the isdnd accounting file resides
40 $ACCT_FILE = "/var/log/isdnd.acct";
42 # the charge for a unit, currently 0,12 DM
45 # open accounting file
46 open(IN, $ACCT_FILE) ||
47 die "ERROR, cannot open $ACCT_FILE !\n";
52 # process file line by line
55 # remove ( and ) from length and bytecounts
58 # split line into pieces
59 ($from_d, $from_h, $dash, $to_d, $to_h, $name, $units, $secs, $byte)
65 $from = "$from_d $from_h";
70 ($inb, $outb) = split(/\//, $byte);
73 $a_secs{$name} += $secs;
75 $a_units{$name} += $units;
76 $a_charge{$name} += $units * $UNIT_PRICE;
77 $a_inbytes{$name} += $inb;
78 $a_outbytes{$name} += $outb;
79 $a_bytes{$name} = $a_bytes{$name} + $inb + $outb;
82 # close accouting file
87 print " ISDN Accounting Report ($from -> $to_d $to_h)\n";
88 print " =====================================================================\n";
90 #write the sum for each interface/name
91 foreach $name (sort(keys %a_secs))
93 $o_secs = $a_secs{$name};
95 $o_calls = $a_calls{$name};
96 $gt_calls += $o_calls;
97 $o_units = $a_units{$name};
98 $gt_units += $o_units;
99 $o_charge = $a_charge{$name};
100 $gt_charge += $o_charge;
101 $o_inbytes = $a_inbytes{$name};
102 $gt_inbytes += $o_inbytes;
103 $o_outbytes = $a_outbytes{$name};
104 $gt_outbytes += $o_outbytes;
105 $o_bytes = $a_bytes{$name};
106 $gt_bytes += $o_bytes;
111 $o_calls = $gt_calls;
112 $o_units = $gt_units;
113 $o_charge = $gt_charge;
114 $o_inbytes = $gt_inbytes;
115 $o_outbytes = $gt_outbytes;
116 $o_bytes = $gt_bytes;
119 print "======= ====== ===== ===== ======== ============ ============ ============\n";
128 Name charge units calls secs inbytes outbytes bytes
129 ------- ------ ----- ----- -------- ------------ ------------ ------------
134 @<<<<<< @##.## @#### @#### @####### @########### @########### @###########
135 $name, $o_charge, $o_units, $o_calls, $o_secs, $o_inbytes, $o_outbytes, $o_bytes