Discussion Locked

hash of hash's question - perl

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Problem:
Server that hosts multiple accounts which each has an outside ip that is defined within the rc.conf.local of a BSD machine. Bandwidth statistics are only provided for the full machine via the router and not by ip. Due to having a limit on bandwidth, a monitor of each ip's bandwidth would be prudent.

Solution:
The software firewall records bandwidth that passe's through rule sets. Set up labels to each rule set and you can see what the bandwidth is used for that rule-set(ip). This is then recorded to a database that has breakdowns by 5 minute intervals, 1 day intervals, monthly intervals, and year to date intervals.

Problem:
Graphical representation of this usage. Easy enough to pull the data from the database, but not necessarily easy to build hash Perl hash tables that can be used to produce graphical representation with. Not all ip's will have bandwidth, so you don't want to spend the time representing that in the graphic.

Perl hash of hash is perfect data structure for storing the database information. First key level of hash would be your firewall rule set label name.
ie:
debb
20071010 had bandwidth of 50000
dan
20071001 had bandwidth of 2000
steven
20071001 had bandwidth of 0
ssh
20071001 had bandwidth of 25000
20071002 had bandwidth of 100000
20071003 had bandwidth of 10000

hash table name is %CapturedBandwidth;

I can acquire the keys of the first level of this hash of hash's simply by:
@RuleSets=keys %CapturedBandwidth;

But, is there an easy way to capture the date the bandwidth occurred the same type of way?
I actually have a work around for this because I can determine all of these dates or times when I build the hash table... But, ok... The devil has me by the tail. I would like to know how to get a list of these secondary keys after the table has been built.

Dan

4 replies

by absolutely

Is this a joke?

Do you have the original log files still? and you want to get the dates from those, to put into a table?

Because if I read your last paragraph correctly, it looks like you're trying to get date data into a table which contains no date data, in which case all you could do is guess, or make it up. But, I've read enough of your material to know that's not what you're saying. So, is it a joke or what?

by danlm

At the time a specific graph is asked for?
7 day history, 30 day history, 24 hour history by what ever ip. I will read through the database and build the has table using the current date and or time as part of the keys. This will be from the current date/time backward.

I am then using the cpan gd graphics module to build the actual graphs. This requires an array of arrays to plot the graphs..

{"20071001" "20071002"]
[bandwidht bandwidth]

I can recalculate these dates or times because I know I am working from the current date time backwards which is how I extracted fromt he database. I calculate the date time(7 days back from today) and use that as part of my key. Build the hash tables, and then loop through those tables to build the graph.

Is that any clearer????? I know this sounds stupid, but it's one of those... How the bloody hell do you do that?

Never mind, dumb question..

I'll just run with it, I know what I'm trying to do... Just hard to explain... And I know how to get at the data, not a problem there.

Dan

by absolutely

And, I think I see a problem. You said in your first post something about omitting records where bandwidth=0, so counting backwards from today's date will require some care.

I haven't used Perl much myself so won't clog up your thread any more. I don't need to be a Perl-master to know an amateur watching over your shoulder won't "help".

Good luck.

by danlm

my %BandwidthUsed = ();
$BandwidthUsed{"MainIp"}{"20071010"}="50000";
$BandwidthUsed{"MainIp"}{"20071020"}="5000";
$BandwidthUsed{"AweRock"}{"20071030"}="2000";
$BandwidthUsed{"socom"}{"20071001"}="300000";

@what=keys %{$BandwidthUsed{"MainIp"}};
print "hu? @what\n";

gives me...

[22:23](root@seti)[/scripts/BandwidthShit]# perl test.pl
hu? 20071010 20071020
[22:23](root@seti)[/scripts/BandwidthShit]#

Knew it was all in my syntax. Knew there had to be a way to do that.

Dan

This discussion is closed to new replies.