netskope/ntskp-api-01.pl

46 lines
1.0 KiB
Perl
Executable File

#!/usr/bin/perl -w
use strict;
use warnings;
use autodie;
use POSIX qw(strftime);
use Cpanel::JSON::XS;
my $file;
{
local $/;
open my $fh, "<", "amsjson.txt";
$file = <$fh>;
close $fh;
}
my $json = Cpanel::JSON::XS->new->utf8->decode($file);
my $data = $json->{'data'};
my $domain;
my $cci;
for (my $i = 0; $i < (@{$data}); $i++) {
#print "Timestamp: $data->[$i]->{'timestamp'}\n";
#print "Domain: $data->[$i]->{'domain'}\n";
if (!$data->[$i]->{'domain'}) {
my $url = $data->[$i]->{'url'};
$url =~ s!^https?://(?:www\.)?!!i;
$url =~ s!/.*!!;
$url =~ s/[\?\#\:].*//;
$domain = $url;
} else {
$domain = $data->[$i]->{'domain'};
}
if ($data->[$i]->{'cci'}) {
$cci = $data->[$i]->{'cci'};
} else {
$cci = 'none';
}
#print "Category: $data->[$i]->{'category'}\n";
#print "CCI: $data->[$i]->{'ccl'}\n";
#print "User: $data->[$i]->{'user'}\n";
my $timestamp = strftime("%Y-%m-%d %H:%M:%S", gmtime($data->[$i]->{'timestamp'}));
print "$timestamp,$domain,$cci,$data->[$i]->{'category'},$data->[$i]->{'ccl'}\n";
}