#!/usr/bin/perl -I/var/www/cacti_script/BROKER/script1
use strict;
use warnings;
use Time::Local;
use mgw;
main(@ARGV);
sub main
{
my $o = mgw->new;
$o->name("chef");
my $name = $o->name;
#message($name);
my $o2 = mgw-> new;
$o2->cdr_time("01");
#$o2->dir;
message($o->dir);
}
sub message
{
my $m = shift or return;
print("$m\n");
}
package mgw;
use strict;
use warnings;
use IO::File;
our $VERSION = "1.0";
our $log_path = "/var/www/cacti_script/BROKER/script1/log";
our $cdr_path = "";
our %REGEXP =(
CDR_TIME => qr/(\d\d).log.((\d\d\d\d\d\d)\d+)/,
);
sub new {
my $class = shift;
my $self = {};
bless($self, $class);
return $self;
}
sub name
{
my ($self, $name) = @_;
$self->{name} = $name if defined $name;
return $self->{name};
}
sub cdr_time
{
my ($self, $relay) = @_;
my $dir = "";
my $cdrtime = "";
open(FILE, "$log_path/$relay/cdr");
while(my $line = <FILE>)
{
my $regexp = $REGEXP{"CDR_TIME"};
if($line =~ /$regexp/)
{
$dir = $2;
$cdrtime = $3;
}
}
close FILE;
$self->{dir} = $dir if defined $dir;
$self->{cdrtime} = $cdrtime if defined $cdrtime;
return $self->{dir};
}