]> git.ipfire.org Git - ipfire-2.x.git/blame - config/qos/event-func.pl
Ein Paar Dateien fuer die GPLv3 angepasst.
[ipfire-2.x.git] / config / qos / event-func.pl
CommitLineData
a7fb5630
MT
1#!/usr/bin/perl
2
3##########################################
4##
5## NAME
6##
7## DESCRIPTION
8##
9## Which is part of the ADSL-optimizer.
10##
11## USAGE / FUNCTIONS
12##
13##
14##
15##
16##
17## REQUIRES
18##
19##
20## AUTHOR
21## Jesper Dangaard Brouer <hawk@diku.dk>, d.21/4-2004
22##
23## CHANGELOG
24## 2004-04-21: Initial version.
25##
a7fb5630
MT
26##########################################
27
28our $event_file_all = "${event_datadir}changes.evt";
29sub get_filename_event($) {
30 my $class_device = "$_[0]";
31 my $filename = "${event_datadir}class_${class_device}.evt";
32 return $filename;
33}
34
35sub get_filename_bandwidth_info($) {
36 my $class_device = "$_[0]";
37 my $filename = "${event_datadir}class_${class_device}_bandwidth.evt";
38 return $filename;
39}
40
41sub update_event_file($$$) {
42 my $filename = $_[0];
43 my $information = $_[1];
44 my $timestamp = $_[2];
45
46 if ("$information" ne "") {
47 # Append to file
48 open( OUTPUT, ">>$filename")
49 or print "ERROR: Opening/updating event file $filename\n";
50 print OUTPUT "$timestamp $information\n";
51 close(OUTPUT);
52 }
53}
54
55sub update_info_file($$$) {
56 my $filename = $_[0];
57 my $information = $_[1];
58 my $timestamp = $_[2];
59 # Truncate file
60 open( OUTPUT, ">$filename")
61 or print "ERROR: Opening/updating info event file $filename\n";
62 print OUTPUT "$timestamp $information\n";
63 close(OUTPUT);
64
65}
66
67sub process_events {
68
69 my @test = keys %classes_info;
70 if ( $#test < 0) {
71 print time, " [process_events] WARNING: classes_info empty!\n";
72 return "classes_info empty";
73 }
74
75 my @bandwidth_items = ( "type", "prio", "rate", "ceil" );
76
77 my $event_reduced = "";
78 my $last_update;
79
80 # Find the class_device (keys) in %classes_info
81 for my $class_device ( sort keys %classes_info ) {
82
83 if ("$class_device" eq "last_update") {next}
84
85 my $event_class = "";
86 my $bandwidth_info = "";
87
88 # Tests if something has changed
89 if ((not exists $classes_info{$class_device}{file_update}) ||
90 ($classes_info{$class_device}{last_update} >
91 $classes_info{$class_device}{file_update})) {
92
93 $last_update = $classes_info{$class_device}{last_update};
94
95 $event_class .= "($class_device)";
96 if ( "$event_reduced" eq "" ) {$event_reduced="Class changed:"}
97 $event_reduced .= " ($class_device)";
98 # The list of changed keys
99 while( $changed_key =
100 shift @{ $classes_info{$class_device}{changed} })
101 {
102 my $value = $classes_info{$class_device}{$changed_key};
103 $event_class .= " $changed_key=$value";
104 }
105
106 # When something changed always update all the bandwidth info
107 foreach my $item (@bandwidth_items) {
108 if (exists $classes_info{$class_device}{$item}) {
109 my $value = $classes_info{$class_device}{$item};
110 if (defined $value) {
111 $bandwidth_info .= " $item:$value";
112 }
113 }
114 }
115
116 print time . "($class_device) changes... ($last_update) \"$bandwidth_info\" \n";
117
118 $classes_info{$class_device}{file_update}=$last_update;
119
120 my $event_file = get_filename_event($class_device);
121 update_event_file($event_file , $event_class, $last_update);
122
123 my $info_file = get_filename_bandwidth_info($class_device);
124 update_info_file($info_file, $bandwidth_info, $last_update);
125 }
126
127 }
128 # Only one line per process_events call
129 # (notice $last_update is the latest timestamp assignment)
130 if (defined $last_update) {
131 update_event_file($event_file_all, $event_reduced, $last_update);
132 }
133}
134
135
1361;