<commit_before>#!/usr/bin/perl -w

# arch.pl - read dbeacon dump file and fill related rrds
# use history.pl to see data
#
# You can start arch.pl from crontab with a line like:
# * * * * * cd /home/seb/dbeacon/contrib/history/ ; ./arch.pl > arch.log 2>&1
#
# Or directly from dbeacon using for instance:
# ./dbeacon [...] -L contrib/history/arch.pl
#
# Originally by <NAME>
# Lot of lines are comming from Hoerdt Micka<EB>l's matrix.pl

use strict;
use XML::Parser;
use RRDs;

our $dumpfile;
our $historydir;

# to use with dbeacon -L
#$dumpfile = shift @ARGV;

# Load perl config script
do("history.conf");

# Assign default values
if (!$dumpfile)
{
	$dumpfile = '../../dump.xml';
}
if (!$historydir)
{
	$historydir = 'data';
}


my $verbose = 1;

my $dstbeacon;
my $srcbeacon;

# initialize parser and read the file
my $parser = new XML::Parser(Style => 'Tree');
$parser->setHandlers(Start => \&start_handler);
my $tree = $parser->parsefile($dumpfile);

# Parser callback
sub start_handler
{
        my ($p, $tag, %atts) = @_;

	if ($tag eq "beacon")
	{
		if ($atts{"name"} and $atts{"addr"})
		{
			$dstbeacon = $atts{"name"}.'.'.$atts{"addr"};
		}
		else
		{
			$dstbeacon = undef;
		}
	}
	elsif ($tag eq "source")
	{

		if ($atts{"name"} and $atts{"addr"})
		{
			$srcbeacon = $atts{"name"}.'.'.$atts{"addr"};
		}
		else
		{
			$srcbeacon = undef;
		}
	}
	elsif ($tag eq "asm" or $tag eq "ssm")
	{
		my %values;
		foreach my $valuetype ('ttl','loss','delay','jitter')
		{
			if (defined($atts{$valuetype}))
			{
				$values{$valuetype} = $atts{$valuetype};
			}
		}
		if (defined($values{'ttl'}) and defined($values{'loss'}) and defined($values{'delay'}) and defined($values{'jitter'}))
		{
			if ($srcbeacon and $dstbeacon) {
				storedata($dstbeacon,$srcbeacon,$tag,%values);
			}
		}
	}
}

sub rrd_file_path {
	my ($dstbeacon, $srcbeacon, $asmorssm) = @_;

	return "$historydir/$dstbeacon/$srcbeacon.$asmorssm.rrd";
}
<commit_msg>we dont need %values, we use %atts directly<commit_after>#!/usr/bin/perl -w

# arch.pl - read dbeacon dump file and fill related rrds
# use history.pl to see data
#
# You can start arch.pl from crontab with a line like:
# * * * * * cd /home/seb/dbeacon/contrib/history/ ; ./arch.pl > arch.log 2>&1
#
# Or directly from dbeacon using for instance:
# ./dbeacon [...] -L contrib/history/arch.pl
#
# Originally by <NAME>
# Lot of lines are comming from Hoerdt Micka<EB>l's matrix.pl

use strict;
use XML::Parser;
use RRDs;

our $dumpfile;
our $historydir;

# to use with dbeacon -L
#$dumpfile = shift @ARGV;

# Load perl config script
do("history.conf");

# Assign default values
if (!$dumpfile)
{
	$dumpfile = '../../dump.xml';
}
if (!$historydir)
{
	$historydir = 'data';
}


my $verbose = 1;

my $dstbeacon;
my $srcbeacon;

# initialize parser and read the file
my $parser = new XML::Parser(Style => 'Tree');
$parser->setHandlers(Start => \&start_handler);
my $tree = $parser->parsefile($dumpfile);

# Parser callback
sub start_handler
{
        my ($p, $tag, %atts) = @_;

	if ($tag eq "beacon")
	{
		if ($atts{"name"} and $atts{"addr"})
		{
			$dstbeacon = $atts{"name"}.'.'.$atts{"addr"};
		}
		else
		{
			$dstbeacon = undef;
		}
	}
	elsif ($tag eq "source")
	{

		if ($atts{"name"} and $atts{"addr"})
		{
			$srcbeacon = $atts{"name"}.'.'.$atts{"addr"};
		}
		else
		{
			$srcbeacon = undef;
		}
	}
	elsif ($tag eq "asm" or $tag eq "ssm")
	{
		if (defined($atts{'ttl'}) and defined($atts{'loss'}) and defined($atts{'delay'}) and defined($atts{'jitter'})) {
			if ($srcbeacon and $dstbeacon) {
				storedata($dstbeacon,$srcbeacon,$tag,%atts);
			}
		}
	}
}

sub rrd_file_path {
	my ($dstbeacon, $srcbeacon, $asmorssm) = @_;

	return "$historydir/$dstbeacon/$srcbeacon.$asmorssm.rrd";
}

{'fraction_non_alphanumeric': 0.19071888412017168, 'fraction_numerical': 0.001609442060085837, 'mean_word_length': 3.672932330827068, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2450655', 'n_tokens_mistral': 1555, 'n_tokens_neox': 1446, 'n_words': 363}