Script to read file and generate insert statements for nco_sql and then send events into object server
#!/opt/IBM/tivoli/netcool/precision/perl/bin/perl
use Date::Parse;
use Text::CSV;
# Control Variables:
$InputCSVFileToParse="/home/ncoadmin/DockerMount/Scripts/08-12-16.csv";
## Do not set both variables to 1 at same time
$GenerateCSVSuitedForDB2insert=0; # Use this variable to generate csv to load directly into db2
$GenerateCSVSuitedForOmnibusGLFProbe=1; # Use this variable to generate csv file for event replay
open my $fh, "<", $InputCSVFileToParse or die "$InputCSVFileToParse $!";
undef($csv);
if( $GenerateCSVSuitedForOmnibusGLFProbe == 1)
{
print "\n\n";
print ">>>>>>>>>>>>>>>> Begin of format with Omnibus fields and well suited for GLF probe processing\n";
print "\n\n";
my $csv = Text::CSV->new ({
always_quote => 0,
binary => 1, # Allow special character. Always set this
auto_diag => 1, # Report irregularities immediately
eol => "\n"
});
while (my $row = $csv->getline ($fh)) {
$FO = str2time($row->[11]);
$LO= str2time($row->[12]);
print "\n";
print "insert into alerts.status (FirstOccurrence,LastOccurrence,Manager,Node,NodeAlias,Identifier,AlertGroup,AlertKey,Location,Summary,Severity,Type,ExpireTime) values ($FO,$LO,'$row->[4]','$row->[2]','$row->[3]','$row->[0]','$row->[6]','$row->[7]','$row->[18]','$row->[9]',$row->[8],$row->[14],600)\;\n";
}
print "\n\n";
print ">>>>>>>>>>>>>>>> End of format with Omnibus fields and well suited for GLF probe processing\n";
}
print "\n\n";
close $fh;
OUTPUT OF THE SCRIPT BELOW
[netcool@omnibus bin]$ ./nco_sql -server NCOMS -user root
Password:
1> insert into alerts.status (FirstOccurrence,LastOccurrence,Manager,Node,NodeAlias,Identifier,AlertGroup,AlertKey,Location,Summary,Severity,Type,ExpireTime) values (1471047551,1471047551,'MTTrapd Probe','10.31.34.1','10.31.34.1','10.31.34.1 ccmHistoryEventEntry.521500 Configuration Change 13 Cisco-Configuration Management MTTrapd Probe 1 1 3 2','Configuration Change','ccmHistoryEventEntry.521500','(null)','Configuration Changed via Command Line ( Source: Running Configuration-:- Destination: Command Source )',2,13,600);
#!/opt/IBM/tivoli/netcool/precision/perl/bin/perl
use Date::Parse;
use Text::CSV;
# Control Variables:
$InputCSVFileToParse="/home/ncoadmin/DockerMount/Scripts/08-12-16.csv";
## Do not set both variables to 1 at same time
$GenerateCSVSuitedForDB2insert=0; # Use this variable to generate csv to load directly into db2
$GenerateCSVSuitedForOmnibusGLFProbe=1; # Use this variable to generate csv file for event replay
open my $fh, "<", $InputCSVFileToParse or die "$InputCSVFileToParse $!";
undef($csv);
if( $GenerateCSVSuitedForOmnibusGLFProbe == 1)
{
print "\n\n";
print ">>>>>>>>>>>>>>>> Begin of format with Omnibus fields and well suited for GLF probe processing\n";
print "\n\n";
my $csv = Text::CSV->new ({
always_quote => 0,
binary => 1, # Allow special character. Always set this
auto_diag => 1, # Report irregularities immediately
eol => "\n"
});
while (my $row = $csv->getline ($fh)) {
$FO = str2time($row->[11]);
$LO= str2time($row->[12]);
print "\n";
print "insert into alerts.status (FirstOccurrence,LastOccurrence,Manager,Node,NodeAlias,Identifier,AlertGroup,AlertKey,Location,Summary,Severity,Type,ExpireTime) values ($FO,$LO,'$row->[4]','$row->[2]','$row->[3]','$row->[0]','$row->[6]','$row->[7]','$row->[18]','$row->[9]',$row->[8],$row->[14],600)\;\n";
}
print "\n\n";
print ">>>>>>>>>>>>>>>> End of format with Omnibus fields and well suited for GLF probe processing\n";
}
print "\n\n";
close $fh;
OUTPUT OF THE SCRIPT BELOW
[netcool@omnibus bin]$ ./nco_sql -server NCOMS -user root
Password:
1> insert into alerts.status (FirstOccurrence,LastOccurrence,Manager,Node,NodeAlias,Identifier,AlertGroup,AlertKey,Location,Summary,Severity,Type,ExpireTime) values (1471047551,1471047551,'MTTrapd Probe','10.31.34.1','10.31.34.1','10.31.34.1 ccmHistoryEventEntry.521500 Configuration Change 13 Cisco-Configuration Management MTTrapd Probe 1 1 3 2','Configuration Change','ccmHistoryEventEntry.521500','(null)','Configuration Changed via Command Line ( Source: Running Configuration-:- Destination: Command Source )',2,13,600);
#!/opt/IBM/tivoli/netcool/precision/perl/bin/perl use Time::HiRes qw(usleep nanosleep); $file="/home/netcool/Desktop/21July/21July_ReadFromOracle6.log.sql"; $printSTDOUT = 1; $sendToOmnibus=1; open(f1,"$file") or die "No file $file\n"; @Array=<f1>; close(f1); chomp(@Array); $loopCount = 0; open(f2,"|/opt/IBM/tivoli/netcool/omnibus/bin/nco_sql -server NOI_AGG_P -user root -password object00"); $countTheInserts=0; foreach $i (@Array) { $loopCount = $loopCount +1; print "$i\n" if($printSTDOUT); print "-----------------------------------------------\n" if($printSTDOUT); print f2 "$i\n" if($sendToOmnibus); if( $loopCount % 101 == 0 ) # Break the nco_sql insert statements into chunks { $countTheInserts = $countTheInserts + 1; print f2 "go\n" if($sendToOmnibus); print "HEY BILL - loopCount=$loopCount\n" if($printSTDOUT); print "HEY BILL it inserted $countTheInserts\n" if($printSTDOUT); } #usleep(100000); #sleep(1); print "loopCount=$loopCount\n"; } close(f2); print "loopCount=$loopCount\n"; |