Friday, October 7, 2016

Inserting CSV file data into DB2 Reporter_Status table

We used this db2 syntax to load the data into the reporter_status database from file built via perl script

db2 connect to reporter

db2 LOAD FROM "/tmp/db2load/data_out01" OF DEL MODIFIED BY identityignore generatedignore rowchangetimestampignore timestampforma
t=\"YYYY-MM-DD hh:mm:ss\" implieddecimal  INSERT INTO DB2INST1.REPORTER_STATUS


The first two (2) lines of the input file look like:

"ch3p-gen-imn-be02 Queue Depth OGANGI SVR DEMO SMPP  1",497596055,"ch3p-gen-imn-be02","ch3p-gen-imn-be02","Socket Probe on samiam","IMNQ.ksh to socket 3","Queue Depth","OGANGI SVR DEMO SMPP ",0,"1 pending messages for OGANGI SVR DEMO SMPP  /imn_data/fq/imports/ch3p-gen-imn-be02/router/10992/MO",2016-01-27 07:41:02,2016-01-27 07:40:32,2016-01-27 07:40:32,0,1,1,1150,0,"",65534,0,0,"",360,0,0,"OGANGI SVR DEMO SMPP ","",0,0,"",0,"",0,0,"","","","","","","","",0,0,"","",2016-01-27 07:43:49,0,"NCOMS_P",497596055
"ch3p-gen-imn-be02 Queue Depth LexisNexis WS Prod  1",497596056,"ch3p-gen-imn-be02","ch3p-gen-imn-be02","Socket Probe on samiam","IMNQ.ksh to socket 3","Queue Depth","LexisNexis WS Prod ",0,"1 pending messages for LexisNexis WS Prod  /imn_data/fq/imports/ch3p-gen-imn-be02/router/11075/MO",2016-01-27 07:41:02,2016-01-27 07:40:32,2016-01-27 07:40:32,0,1,1,1150,0,"",65534,0,0,"",360,0,0,"LexisNexis WS Prod ","",0,0,"",0,"",0,0,"","","","","","","","",0,0,"","",2016-01-27 07:43:49,0,"NCOMS_P",497596056



<=============  PERL SCRIPT BELOW ==========================>>>

#!/usr/bin/perl

#use strict;
#use warnings;
use Text::CSV;
use Time::ParseDate;
use Time::Piece;


my $inputfile = "/home/wmcain/Desktop/RFP_POC/Syniverse/DataExtract_3/SCC_30DAYS.csv";
#my $inputfile = "data/data_in02";
open my $fh, "<", $inputfile or die "$inputfile: $!";

my $outputfile = "/home/wmcain/Desktop/RFP_POC/Syniverse/DataExtract_3/SCC_30DAYS.csv_extract_withTIcketInfo";
#my $outputfile = "/tmp/db2load/data_out02";
open (OUT, ">$outputfile");

my $csv = Text::CSV->new ({
    binary => 1,
    #sep_char => ',',
    always_quote => 0,        # set to 1 to keep your numbers quoted
});



while (my $row = $csv->getline ($fh)) {
    chomp($row);
    s/\n/ /g for @$row;
    s/\r\n/ /g for @$row;
    $line=$csv->string($row);
    s/\n/ /g for $line;
    $status  = $csv->parse($line);
    @columns = $csv->fields($line);
    $lm=substr($columns[10],0,18);
    $fo=substr($columns[11],0,18);
    $lo=substr($columns[12],0,18);
    $da=substr($columns[47],0,18);
    $t = Time::Piece->strptime( "$lm", "%d-%b-%y %H.%M.%S");
    $lastModified = $t->strftime("%Y-%m-%d %H:%M:%S");
    $t = Time::Piece->strptime( "$fo", "%d-%b-%y %H.%M.%S");
    $firstOccurrence = $t->strftime("%Y-%m-%d %H:%M:%S");
    $t = Time::Piece->strptime( "$lo", "%d-%b-%y %H.%M.%S");
    $lastOccurrence = $t->strftime("%Y-%m-%d %H:%M:%S");
    $t = Time::Piece->strptime( "$da", "%d-%b-%y %H.%M.%S");
    $deletedAt = $t->strftime("%Y-%m-%d %H:%M:%S");
    foreach (@columns){
      s/\"//g for $_;
    }
    print OUT "\"$columns[0]\","; #IDENTIFIER
    print OUT "$columns[1],"; #SERIAL
    print OUT "\"$columns[2]\","; #NODE
    print OUT "\"$columns[3]\","; #NODEALIAS
    print OUT "\"$columns[4]\","; #MANAGER
    print OUT "\"$columns[5]\","; #AGENT
    print OUT "\"$columns[6]\","; #ALERTGROUP
    print OUT "\"$columns[7]\","; #ALERTKEY
    print OUT "$columns[8],"; #SEVERITY
    print OUT "\"$columns[9]\","; #SUMMARY
    print OUT "$lastModified,"; #LASTMODIFIED
    print OUT "$firstOccurrence,"; #FIRSTOCCURRENCE
    print OUT "$lastOccurrence,"; #LASTOCCURRENCE
    print OUT "$columns[13],"; #POLL
    print OUT "$columns[14],"; #TYPE
    print OUT "$columns[15],"; #TALLY
    print OUT "$columns[16],"; #CLASS
    print OUT "$columns[17],"; #GRADE
    print OUT "\"$columns[18]\","; #LOCATION
    print OUT "$columns[19],"; #OWNERUID
    print OUT "$columns[20],"; #OWNERGID
    print OUT "$columns[21],"; #ACKNOWLEDGED
    print OUT "\"$columns[22]\","; #EVENTID
    print OUT "$columns[23],"; #EXPIRETIME
    print OUT "$columns[24],"; #PROCESSREQ
    print OUT "$columns[25],"; #SUPPRESSESCL
    print OUT "\"$columns[26]\","; #CUSTOMER
    print OUT "\"$columns[27]\","; #SERVICE
    print OUT "$columns[28],"; #PHYSICALSLOT
    print OUT "$columns[29],"; #PHYSICALPORT
    print OUT "\"$columns[30]\","; #PHYSICALCARD
    print OUT "$columns[31],"; #TASKLIST
    print OUT "\"$columns[32]\","; #NMOSSERIAL
    print OUT "$columns[33],"; #NMOSOBJINST
    print OUT "$columns[34],"; #NMOSCAUSETYPE
    print OUT "\"$columns[35]\","; #LOCALNODEALIAS
    print OUT "\"$columns[36]\","; #LOCALPRIOBJ
    print OUT "\"$columns[37]\","; #LOCALSECOBJ
    print OUT "\"$columns[38]\","; #LOCALROOTOBJ
    print OUT "\"$columns[39]\","; #REMOTENODEALIAS
    print OUT "\"$columns[40]\","; #REMOTEPRIOBJ
    print OUT "\"$columns[41]\","; #REMOTESECOBJ
    print OUT "\"$columns[42]\","; #REMOTEROOTOBJ
    print OUT "$columns[43],"; #X733EVENTTYPE
    print OUT "$columns[44],"; #X733PROBABLECAUSE
    print OUT "\"$columns[45]\","; #X733SPECIFICPROB
    print OUT "\"$columns[46]\","; #X733CORRNOTIF
    print OUT "$deletedAt,"; #DELETEDAT
    print OUT "$columns[48],"; #ORIGINALSEVERITY
    print OUT "\"$columns[49]\","; #SERVERNAME
    print OUT "\"$columns[50]\","; #SERVERSERIAL
    print OUT "\"$columns[110]\","; #TICKET_ELIGIBLE
    print OUT "\"$columns[153]\","; #ARS_TICKETABLE
    print OUT "\"$columns[154]\","; #ARS_INCIDENT
    print OUT "\"$columns[155]\""; #ARS_TICKETSTATUS
    print OUT "\r\n";
    }
close $fh;
close OUT;

No comments:

Post a Comment