]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame_incremental - config/qos/event-func.pl
QoS-Update - Komplette grafische Ueberarbeitung
[people/pmueller/ipfire-2.x.git] / config / qos / event-func.pl
... / ...
CommitLineData
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##
26## $Id: event-func.pl,v 1.10 2004/08/10 16:05:46 hawk Exp $
27##########################################
28
29our $event_file_all = "${event_datadir}changes.evt";
30sub get_filename_event($) {
31 my $class_device = "$_[0]";
32 my $filename = "${event_datadir}class_${class_device}.evt";
33 return $filename;
34}
35
36sub get_filename_bandwidth_info($) {
37 my $class_device = "$_[0]";
38 my $filename = "${event_datadir}class_${class_device}_bandwidth.evt";
39 return $filename;
40}
41
42sub update_event_file($$$) {
43 my $filename = $_[0];
44 my $information = $_[1];
45 my $timestamp = $_[2];
46
47 if ("$information" ne "") {
48 # Append to file
49 open( OUTPUT, ">>$filename")
50 or print "ERROR: Opening/updating event file $filename\n";
51 print OUTPUT "$timestamp $information\n";
52 close(OUTPUT);
53 }
54}
55
56sub update_info_file($$$) {
57 my $filename = $_[0];
58 my $information = $_[1];
59 my $timestamp = $_[2];
60 # Truncate file
61 open( OUTPUT, ">$filename")
62 or print "ERROR: Opening/updating info event file $filename\n";
63 print OUTPUT "$timestamp $information\n";
64 close(OUTPUT);
65
66}
67
68sub process_events {
69
70 my @test = keys %classes_info;
71 if ( $#test < 0) {
72 print time, " [process_events] WARNING: classes_info empty!\n";
73 return "classes_info empty";
74 }
75
76 my @bandwidth_items = ( "type", "prio", "rate", "ceil" );
77
78 my $event_reduced = "";
79 my $last_update;
80
81 # Find the class_device (keys) in %classes_info
82 for my $class_device ( sort keys %classes_info ) {
83
84 if ("$class_device" eq "last_update") {next}
85
86 my $event_class = "";
87 my $bandwidth_info = "";
88
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})) {
93
94 $last_update = $classes_info{$class_device}{last_update};
95
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} })
102 {
103 my $value = $classes_info{$class_device}{$changed_key};
104 $event_class .= " $changed_key=$value";
105 }
106
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";
113 }
114 }
115 }
116
117 print time . "($class_device) changes... ($last_update) \"$bandwidth_info\" \n";
118
119 $classes_info{$class_device}{file_update}=$last_update;
120
121 my $event_file = get_filename_event($class_device);
122 update_event_file($event_file , $event_class, $last_update);
123
124 my $info_file = get_filename_bandwidth_info($class_device);
125 update_info_file($info_file, $bandwidth_info, $last_update);
126 }
127
128 }
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);
133 }
134}
135
136
1371;