3 ##########################################
9 ## Which is part of the ADSL-optimizer.
21 ## Jesper Dangaard Brouer <hawk@diku.dk>, d.21/4-2004
24 ## 2004-04-21: Initial version.
26 ## $Id: event-func.pl,v 1.10 2004/08/10 16:05:46 hawk Exp $
27 ##########################################
29 our $event_file_all = "${event_datadir}changes.evt";
30 sub get_filename_event
($) {
31 my $class_device = "$_[0]";
32 my $filename = "${event_datadir}class_${class_device}.evt";
36 sub get_filename_bandwidth_info
($) {
37 my $class_device = "$_[0]";
38 my $filename = "${event_datadir}class_${class_device}_bandwidth.evt";
42 sub update_event_file
($$$) {
44 my $information = $_[1];
45 my $timestamp = $_[2];
47 if ("$information" ne "") {
49 open( OUTPUT
, ">>$filename")
50 or print "ERROR: Opening/updating event file $filename\n";
51 print OUTPUT
"$timestamp $information\n";
56 sub update_info_file
($$$) {
58 my $information = $_[1];
59 my $timestamp = $_[2];
61 open( OUTPUT
, ">$filename")
62 or print "ERROR: Opening/updating info event file $filename\n";
63 print OUTPUT
"$timestamp $information\n";
70 my @test = keys %classes_info;
72 print time, " [process_events] WARNING: classes_info empty!\n";
73 return "classes_info empty";
76 my @bandwidth_items = ( "type", "prio", "rate", "ceil" );
78 my $event_reduced = "";
81 # Find the class_device (keys) in %classes_info
82 for my $class_device ( sort keys %classes_info ) {
84 if ("$class_device" eq "last_update") {next}
87 my $bandwidth_info = "";
89 # Tests if something has changed
90 if ((not exists $classes_info{$class_device}{file_update
}) ||
91 ($classes_info{$class_device}{last_update
} >
92 $classes_info{$class_device}{file_update
})) {
94 $last_update = $classes_info{$class_device}{last_update
};
96 $event_class .= "($class_device)";
97 if ( "$event_reduced" eq "" ) {$event_reduced="Class changed:"}
98 $event_reduced .= " ($class_device)";
99 # The list of changed keys
100 while( $changed_key =
101 shift @
{ $classes_info{$class_device}{changed
} })
103 my $value = $classes_info{$class_device}{$changed_key};
104 $event_class .= " $changed_key=$value";
107 # When something changed always update all the bandwidth info
108 foreach my $item (@bandwidth_items) {
109 if (exists $classes_info{$class_device}{$item}) {
110 my $value = $classes_info{$class_device}{$item};
111 if (defined $value) {
112 $bandwidth_info .= " $item:$value";
117 print time . "($class_device) changes... ($last_update) \"$bandwidth_info\" \n";
119 $classes_info{$class_device}{file_update
}=$last_update;
121 my $event_file = get_filename_event
($class_device);
122 update_event_file
($event_file , $event_class, $last_update);
124 my $info_file = get_filename_bandwidth_info
($class_device);
125 update_info_file
($info_file, $bandwidth_info, $last_update);
129 # Only one line per process_events call
130 # (notice $last_update is the latest timestamp assignment)
131 if (defined $last_update) {
132 update_event_file
($event_file_all, $event_reduced, $last_update);