Thursday, October 27, 2016

Script to read file and send events into object server

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 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";
 

Monday, October 24, 2016

Db2 Import - Load Commands

db2 LOAD FROM "/mnt/ImportFiles/0813.loadFile" OF DEL MODIFIED BY identityignore generatedignore rowchangetimestampignore timestampformat=\"YYYY-MM-DD hh:mm:ss\" implieddecimal  INSERT INTO DB2INST1.REPORTER_STATUS


Tuesday, October 18, 2016

Changing DB2 logfile Size

Use the following procedure to increase the size of the DB2 transaction log (logfilsiz):

1. Determine the current log file size setting by issuing the command:
    Unix
      su - <db2instance> 
      db2 list db directory # to list the database name 
      db2 connect to <databaseName> 
      db2 get db config for <databaseName> | grep -i logfilsiz
    Example:
      su - ldapdb2 
      db2 connect to amdb 
      db2 get db config for amdb | grep -i logfilsiz 
    Windows operating system
      open a DB2CMD window 
      set DB2INSTANCE=<databaseName> from the ibmslapd.conf file 
      db2 list db directory 
      db2 connect to <databaseName> 
      db2 get db config for <databaseName> 
      check the value for logfilsiz 
2. Increase the size of the log file size setting by issuing the command:
      db2 UPDATE db cfg for <databaseName> using LOGFILSIZ <new_value> 
    Example:
      db2 UPDATE db cfg for amdb using LOGFILSIZ 5000

3. Stop the ibmslapd process. 
ibmslapd -k -I <instance name> 

4. Issue the commands:
      db2 force applications all 
      db2stop force

5. Restart ibmslapd process.

Monday, October 17, 2016

DB2 Commands

Managing databases

Creating databases

create database <database-name> using codeset UTF-8 territory en
  
// For example (remember DB2 has a restrictions to 8 characters for databases' name):
create database MYDBNAME using codeset UTF-8 territory en

Changing number of concurrent databases

If you receive and error like this:
SQL1041N  The maximum number of concurrent databases have already been started. SQLSTATE=57032
Run following command:
db2 update dbm cfg using NUMDB <number-of-concurrent-databases>
  
// For example:
db2 update dbm cfg using NUMDB 20
  
// You should see something like this:
DB20000I  The UPDATE DATABASE MANAGER CONFIGURATION command completed successfully.
SQL1362W  One or more of the parameters submitted for immediate modification were not changed dynamically. Client changes will not be effective until the next time the application is started or the TERMINATE command has been issued. Server changes will not be effective until the next DB2START command.

Starting and stopping DB2


Before restarting any IBM DB2 server, I would recommend to display all applications and users that are connected to the specific database that you want to stop. To ensure that no vital or critical applications are running.
Following command list all applications
db2 list applications

If you change any configuration parameter, you will probably need to restart, so, stop database server with:
db2stop
  
// Once IBM DB2 is stopped you will see this message
SQL1064N  DB2STOP processing was successful.
Now, for starting IBM DB2 again, run following command:
db2start
  
// If everything was ok, this message would appear
SQL1063N  DB2START processing was successful.

Working with schemas

Creating a new schema

CREATE SCHEMA <schema-name>
  
// For example:
CREATE SCHEMA CSUSER
  
// After running the command a message will be displayed:
DB20000I  The SQL command completed successfully.

Obtaining users

If you want to list schema users, just run following command:
SELECT SCHEMANAME FROM syscat.schemata

As you can see part of the information about schemas and users is stored in syscat.schemata.

Grant privileges

GRANT ALL ON <schema-name>.<table-name> TO USER <user>
  
// For example:
GRANT ALL ON LCUSER.WIKI_PAGES TO USER LCUSER

Getting information about databases and tables

Connect to the database

db2 connect to <database-name>
  
// For example
db2 connect to MYDB

List information about tables

List all tables:
db2 list tables for all
To list all tables in selected schema, use:
db2 list tables for schema <schema-name>
  
// For example:
db2 list tables for schema CSUSER
To describe a table, type:
db2 describe table <table-schema.table-name>
  
// For example:
db2 describe table CSUSER.WIKI_PAGES

List information about databases

List databases:
db2 list database directory show detail | grep -B6 -i indirect | grep "Database name"
If you just want the database names, without the titles, use:
db2 list database directory show detail | grep -B6 -i indirect | grep "Database name" | sed "s/.*= //"

HANDLING ISSUES WHEN LOAD COMMAND IS IN PENDING STATE

[db2inst1@host1 ~]$ touch test.del
[db2inst1@host1 ~]$ LOAD from 'test.del' OF DEL TERMINATE INTO db2inst1.reporter_status
-bash: LOAD: command not found
[db2inst1@host1 ~]$ db2 LOAD from 'test.del' OF DEL TERMINATE INTO db2inst1.reporter_status
SQL3501W  The table space(s) in which the table resides will not be placed in
backup pending state since forward recovery is disabled for the database.

SQL3110N  The utility has completed processing.  "0" rows were read from the
input file.


Number of rows read         = 0
Number of rows skipped      = 0
Number of rows loaded       = 0
Number of rows rejected     = 0
Number of rows deleted      = 0
Number of rows committed    = 0

[db2inst1@host1 ~]$ db2 set integrity for db2inst1.reporter_status immediate checked
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL3600N  The IMMEDIATE CHECKED option of the SET INTEGRITY statement is not
valid since the table "DB2INST1.REPORTER_STATUS" is a user maintained
materialized query table or is not in the Set Integrity Pending state. 
SQLSTATE=51027
[db2inst1@host1 ~]$ db2 "select count(*) from reporter_status"

1         
-----------
     243724

  1 record(s) selected.



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