]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - share/examples/isdn/contrib/isdnd_acct
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / share / examples / isdn / contrib / isdnd_acct
1 #!/usr/bin/perl
2 #---------------------------------------------------------------------------
3 #
4 # Copyright (c) 1996, 1998 Hellmuth Michaelis. All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
8 # are met:
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.
14
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
25 # SUCH DAMAGE.
26 #
27 #---------------------------------------------------------------------------
28 #
29 #       accounting report script for the isdnd daemon accounting info
30 #       -------------------------------------------------------------
31 #
32 #       last edit-date: [Fri May 25 15:28:20 2001]
33 #
34 # $FreeBSD$
35 #
36 #---------------------------------------------------------------------------
37
38 # where the isdnd accounting file resides
39 $ACCT_FILE = "/var/log/isdnd.acct";
40
41 # the charge for a unit, currently 0,12 DM
42 $UNIT_PRICE = 0.12;
43
44 # open accounting file
45 open(IN, $ACCT_FILE) ||
46         die "ERROR, cannot open $ACCT_FILE !\n";
47
48 # set first thru flag
49 $first = 1;
50
51 # process file line by line
52 while (<IN>)
53 {
54         # remove ( and ) from length and bytecounts
55         tr/()//d;
56
57         # split line into pieces
58         ($from_d, $from_h, $dash, $to_d, $to_h, $name, $units, $secs, $byte)
59                 = split(/ /, $_);
60
61         # get starting date
62         if($first)
63         {
64                 $from = "$from_d $from_h";
65                 $first = 0;
66         }
67                 
68         # split bytecount
69         ($inb, $outb) = split(/\//, $byte);
70
71         # process fields
72         $a_secs{$name} += $secs;
73         $a_calls{$name}++;
74         $a_units{$name} += $units;
75         $a_charge{$name} += $units * $UNIT_PRICE;
76         $a_inbytes{$name} += $inb;
77         $a_outbytes{$name} += $outb;
78         $a_bytes{$name} = $a_bytes{$name} + $inb + $outb;
79 }
80
81 # close accouting file
82 close(IN);
83
84 # write header
85 print "\n";
86 print "     ISDN Accounting Report   ($from -> $to_d $to_h)\n";
87 print "     =====================================================================\n";
88
89 #write the sum for each interface/name
90 foreach $name (sort(keys %a_secs))
91 {
92         $o_secs = $a_secs{$name};
93         $gt_secs += $o_secs;
94         $o_calls = $a_calls{$name};
95         $gt_calls += $o_calls;
96         $o_units = $a_units{$name};
97         $gt_units += $o_units;
98         $o_charge = $a_charge{$name};
99         $gt_charge += $o_charge;
100         $o_inbytes = $a_inbytes{$name};
101         $gt_inbytes += $o_inbytes;
102         $o_outbytes = $a_outbytes{$name};
103         $gt_outbytes += $o_outbytes;
104         $o_bytes = $a_bytes{$name};
105         $gt_bytes += $o_bytes;
106         write;
107 }
108
109 $o_secs = $gt_secs;
110 $o_calls = $gt_calls;
111 $o_units = $gt_units;
112 $o_charge = $gt_charge;
113 $o_inbytes = $gt_inbytes;
114 $o_outbytes = $gt_outbytes;
115 $o_bytes = $gt_bytes;
116 $name = "Total";
117
118 print "======= ====== ===== ===== ======== ============ ============ ============\n";
119 write;
120
121 print "\n\n";
122 exit;
123
124 # top of page header
125 format top =
126
127 Name    charge units calls     secs      inbytes     outbytes        bytes
128 ------- ------ ----- ----- -------- ------------ ------------ ------------
129 .
130
131 # record template
132 format STDOUT =
133 @<<<<<< @##.## @#### @#### @####### @########### @########### @###########
134 $name,  $o_charge, $o_units, $o_calls, $o_secs, $o_inbytes, $o_outbytes, $o_bytes
135 .
136
137 # EOF