How to get execution details in Oracle Data Integrator - oracle

I have written a code using procedure to send an email in Jython. Now I have put my procedure inside a package and I am running the package.
However, what I need to get is the package name, start time of execution of package and end time of execution of package and send it via email.
I tried using getPrevStepLog but that isn't working
My procedure code as of now:
import smtplib
import string
BODY = string.join((
"From: %s" % 'test#gmail.com',
"To: %s" % 'admin#odi.com',
"Subject: %s" % 'Mail From ODI',
"",
'This is a mail from ODI Studio. Thank You.Previous step
'<%=odiRef.getPrevStepLog("STEP_NAME")%>' executed in
'<%=odiRef.getPrevStepLog("DURATION")%>' seconds'
), "\r\n")
sender = smtplib.SMTP('smtp.gmail.com',587)
sender.set_debuglevel(1)
sender.ehlo()
sender.starttls()
sender.ehlo()
sender.login('test', 'test123')
sender.sendmail('test#gmail.com',['admin#odi.com'],BODY)
sender.close()

Have you try to use the function getSession ?
public java.lang.String getSession(java.lang.String pPropertyName)
pPropertyName
SESS_NO = internal session ID
SESS_NAME = session name
SCEN_VERSION = version of current scenario
CONTEXT_NAME = name of the execution context
CONTEXT_CODE = code of the execution context
AGENT_NAME = name of the physical agent
SESS_BEG = date and hour of the begining of the session
USER_NAME = Oracle Data Integrator user executing the session
Exemple : to get the current session name
<%=odiRef.getSession("SESS_NAME")%>

Related

Error: Runtime exited without providing a reason in python lambda

This code is used to do following
This lambda gets triggered via an event rule
Event is sent when and instance state goes to running/terminated
When instance is running the instance attributes are saved to dynamodb table
Route53 record sets are created / deleted when instance is in running/ terminated state.
Now the lambda created records when instance is launched and throws below error
RequestId: 9f4fb9ed-88db-442a-bc4f-079744f5bbcf Error: Runtime exited without providing a reason
Runtime.ExitError
import ipaddress
import os
import time
from datetime import datetime
from typing import Dict, List, Optional
import boto3
from botocore.exceptions import ClientError, ParamValidationError
from pynamodb.attributes import UnicodeAttribute, UTCDateTimeAttribute
from pynamodb.exceptions import DoesNotExist
from pynamodb.models import Model
def lambda_handler(event, context):
"""Registers or de-registers private DNS resource records for a given EC2 instance."""
# Retrieve details from invocation event object.
try:
account_id = event["account"]
instance_id = event["detail"]["instance-id"]
instance_region = event["region"]
instance_state = event["detail"]["state"]
except KeyError as err:
raise RuntimeError(
f"One or more required fields missing from event object {err}"
)
print(
f"EC2 instance {instance_id} changed to state `{instance_state}` in account "
f"{account_id} and region {instance_region}."
)
print(f"Creating a new aws session in {instance_region} for account {account_id}.")
target_session = aws_session(
region=instance_region, account_id=account_id, assume_role=ASSUME_ROLE_NAME,
)
print(f"Retrieving instance and VPC attributes for instance {instance_id}.")
instance_resource = get_instance_resource(instance_id, target_session)
vpc_resource = get_vpc_resource(instance_resource.vpc_id, target_session)
route53_client = target_session.client("route53")
print(f"Retrieving DNS configuration from VPC {instance_resource.vpc_id}.")
forward_zone = get_vpc_domain(vpc_resource)
print(f"Calculating reverse DNS configuration for instance {instance_id}.")
reverse_lookup = determine_reverse_lookup(instance_resource, vpc_resource)
if instance_state == "running":
print(f"Building DNS registration record for instance {instance_id}.")
#vpc_resource = get_vpc_resource(instance_resource.vpc_id, target_session)
#print(f"Retrieving DNS configuration from VPC {instance_resource.vpc_id}.")
#forward_zone = get_vpc_domain(vpc_resource)
#print(f"Calculating reverse DNS configuration for instance {instance_id}.")
#reverse_lookup = determine_reverse_lookup(instance_resource, vpc_resource)
record = Registration(
account_id=account_id,
hostname=generate_hostname(instance_resource),
instance_id=instance_resource.id,
forward_zone=forward_zone,
forward_zone_id=get_zone_id(forward_zone, route53_client),
private_address=instance_resource.private_ip_address,
region=instance_region,
reverse_hostname=reverse_lookup["Host"],
reverse_zone=reverse_lookup["Zone"],
reverse_zone_id=get_zone_id(reverse_lookup["Zone"], route53_client),
vpc_id=instance_resource.vpc_id,
)
print(record)
try:
if record.forward_zone_id is not None:
manage_resource_record(record, route53_client)
if record.forward_zone_id and record.reverse_zone_id is not None:
manage_resource_record(record, route53_client, record_type="PTR")
except RuntimeError as err:
print(f"An error occurred while creating records: {err}")
exit(os.EX_IOERR)
if record.forward_zone_id:
print(
f"Saving DNS registration record to database for instance {instance_id}."
)
record.save()
else:
print(
f"No matching hosted zone for {record.forward_zone} associated "
f"with {record.vpc_id}."
)
else:
try:
print(
f"Getting DNS registration record from database for instance {instance_id}."
)
record = Registration.get(instance_id)
if record.forward_zone_id is not None:
manage_resource_record(record, route53_client, action="DELETE")
if record.reverse_zone_id is not None:
manage_resource_record(record, route53_client, record_type="PTR", action="DELETE")
print(
"Deleting DNS registration record from database for "
f"instance {instance_id}."
)
record.delete()
except DoesNotExist:
print(f"A registration record for instance {instance_id} does not exist.")
exit(os.EX_DATAERR)
except RuntimeError as err:
print(f"An error occurred while removing resource records: {err}")
exit(os.EX_IOERR)
exit(os.EX_OK)
I had this problem with a dotnet lambda. Turns out it'd run out of memory. Raising the memory ceiling allowed it to pass.
exit(os.EX_OK) statement in last line was causing this. Removing this line resolved my issue.
What I did to get around this, but still have an exit code if there was errors detected was the following:
def main(event=None, context=None):
logger.info('Starting Lambda')
error_count = 0
s3_objects = parse_event(event)
for s3_object in s3_objects:
logger.info('Parsing s3://{}/{}'.format(s3_object['bucket'], s3_object['key']))
error_count += parse_object(object_json)
logger.info('Total Errors: {}'.format(error_count))
if error_count > 255:
error_count = 255
logger.info('Exiting lambda')
# exit if error_count (lambda doesn't like sys.exit(0))
if error_count > 0:
sys.exit(error_count)
TL;DR - Exit only if an error is detected.

create an command which sends an email to the admin Laravel

Hello every one i wanna create an command which sends an email to the admin containing the modification / deletion report + access in a table (use the data in the log file) can someone help me please
for example this is my observer it log the actions in a file so how can i make a command which sends an email to the admin containing this actions from the log file ?
public function created(AppKey $appKey)
{
Log::channel('obsinfo')
->info("id : ".$appKey->id." type : ".$appKey->type." , datetime : ".now()." operation :Creation , ip :".\Request::ip()." userAgent: ".\Request::server('HTTP_USER_AGENT'));
return true;
}

How do I make uCanAccess use Samba authentication, with special characters in username or password?

TL;DR: What Database.FileFormat constant should I use for an MS Access 2000-2003 database, when creating the Database object?
I have built a SAMBA test application using jCIFS. It allows me to create/overwrite files if given the correct authentication credentials, regardless of on which PC in the domain I use it.
I also have an application that uses uCanAccess/jackcess to connect to an MDB on a network share. However (from what I understand), it uses the credentials of the logged-in user, a number of whom have read-only access. Only system/network administrators have write permission.
The database in question is not password-protected. (I don't need to enter a password when opening it.)
My intention is to have the app ask for the administrator's Samba credentials before it writes to the DB, using those in the uCanAccess connection, so that it doesn't throw a java.nio.channels.NonWritableChannelException, as per the below stack trace:
java.nio.channels.NonWritableChannelException
at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:747)
at com.healthmarketscience.jackcess.impl.PageChannel.writePage(PageChannel.java:310)
at com.healthmarketscience.jackcess.impl.PageChannel.writePage(PageChannel.java:247)
at com.healthmarketscience.jackcess.impl.TableImpl.writeDataPage(TableImpl.java:1980)
at com.healthmarketscience.jackcess.impl.TableImpl.addRows(TableImpl.java:2229)
at com.healthmarketscience.jackcess.impl.TableImpl.addRow(TableImpl.java:2067)
at net.ucanaccess.converters.UcanaccessTable.addRow(UcanaccessTable.java:44)
at net.ucanaccess.commands.InsertCommand.insertRow(InsertCommand.java:101)
at net.ucanaccess.commands.InsertCommand.persist(InsertCommand.java:148)
at net.ucanaccess.jdbc.UcanaccessConnection.flushIO(UcanaccessConnection.java:315)
at net.ucanaccess.jdbc.UcanaccessConnection.commit(UcanaccessConnection.java:205)
at net.ucanaccess.jdbc.AbstractExecute.executeBase(AbstractExecute.java:217)
at net.ucanaccess.jdbc.Execute.execute(Execute.java:46)
at net.ucanaccess.jdbc.UcanaccessPreparedStatement.execute(UcanaccessPreparedStatement.java:228)
at myapp.db.Digger.addTransaction(Digger.java:993)
at myapp.tasks.TransactionRunnable.run(TransactionRunnable.java:42)
at java.lang.Thread.run(Thread.java:745)
Update: I have tried using the smbFileChannel class by Gord Thompson and J. T. Alhborn, shown here. My code, based off the main class shown in that answer, looks like this:
// Ask the user for login credentials and the path to the database
String smbURL = (chosenDir.endsWith("/") ? chosenDir : chosenDir + '/')
+ dbName;
System.out.println("DB Path to use for URL: " + smbURL);
URL u = new URL(smbURL);
try (
// construct the SMB DB URL
SmbFileChannel sfc = new SmbFileChannel(smbURL);
Database db = new DatabaseBuilder().setChannel(sfc)
.setFileFormat(Database.FileFormat.GENERIC_JET4).create();
) {
// Model the table
Table tbl = new TableBuilder("Transactions")
.addColumn(new ColumnBuilder("TransactionID", DataType.LONG).setAutoNumber(true))
.addColumn(new ColumnBuilder("ControllerID", DataType.LONG).setAutoNumber(false))
.addColumn(new ColumnBuilder("ReaderID", DataType.LONG).setAutoNumber(false))
.addColumn(new ColumnBuilder("Event", DataType.LONG).setAutoNumber(false))
.addColumn(new ColumnBuilder("Timestamp", DataType.SHORT_DATE_TIME).setAutoNumber(false))
.addColumn(new ColumnBuilder("Number", DataType.LONG).setAutoNumber(false))
.addIndex(new IndexBuilder(IndexBuilder.PRIMARY_KEY_NAME).addColumns("TransactionID").setPrimaryKey())
.toTable(db);
// Add the row
Map<String, Object> values = new HashMap<>();
values.put("ControllerID", cid);
values.put("ReaderID", rid);
values.put("Event", evtNum);
values.put("Timestamp", ts); // Long; must be converted to DataType.SHORT_DATE_TIME
values.put("Number", accNum);
tbl.addRowFromMap(values);
} catch (IOException IOEx) {
System.err.println(
"Failed to write record to Transactions table in database: "
+ IOEx.getMessage()
);
IOEx.printStackTrace(System.err);
} catch (Exception ex) {
System.err.println(
'[' + ex.getClass().getSimpleName() + "]: Failed to write record to "
+ "Transactions table in database: " + ex.getMessage()
);
ex.printStackTrace(System.err);
}
Executing the above code results in the following output:
DB Path to use for URL: smb://machine.vpnName/Storage/me/dbs/DBName.mdb
Failed to write record to Transactions table in database: Logon failure: account currently disabled.
jcifs.smb.SmbAuthException: Logon failure: account currently disabled.
at jcifs.smb.SmbTransport.checkStatus(SmbTransport.java:546)
at jcifs.smb.SmbTransport.send(SmbTransport.java:663)
at jcifs.smb.SmbSession.sessionSetup(SmbSession.java:390)
at jcifs.smb.SmbSession.send(SmbSession.java:218)
at jcifs.smb.SmbTree.treeConnect(SmbTree.java:176)
at jcifs.smb.SmbFile.doConnect(SmbFile.java:911)
at jcifs.smb.SmbFile.connect(SmbFile.java:957)
at jcifs.smb.SmbFile.connect0(SmbFile.java:880)
at jcifs.smb.SmbFile.open0(SmbFile.java:975)
at jcifs.smb.SmbFile.open(SmbFile.java:1009)
at jcifs.smb.SmbRandomAccessFile.<init>(SmbRandomAccessFile.java:57)
at jcifs.smb.SmbRandomAccessFile.<init>(SmbRandomAccessFile.java:42)
at samba.SmbFileChannel.<init>(SmbFileChannel.java:30)
at samba.SambaLanWriteTest.writeTest(SambaLanWriteTest.java:130)
at samba.SambaLanWriteTest.main(SambaLanWriteTest.java:181)
I have write access to a test copy of the database file in question when using Windows File Explorer. I am choosing that one when prompted.
Update 2: I realised that I neglected to add my username and password to the smb:// URL, as Thompson's example shows. I changed to code to this:
String smbCred = "smb://" + auth.getUsername() + ":" + auth.getPassword() + "#",
fixer = chosenDir.replace("\\", "/").replace("smb://", smbCred),
smbURL = fixer + dbName;
System.out.println("DB Path to use for URL: " + smbURL);
// URL u = new URL(smbURL);
The next problem I had was that my password contains special illegal characters (such as '#', ':', ';', '=' and '?'). I escaped these by using java.net.URLEncoder.encode() on auth.getUsername() and auth.getPassword() so the code doesn't throw a MalformedURLException when creating the SmbChannel. However, the next exception I encountered is as follows:
Failed to write record to Transactions table in database: File format GENERIC_JET4 [VERSION_4] does not support file creation for null
java.io.IOException: File format GENERIC_JET4 [VERSION_4] does not support file creation for null
at com.healthmarketscience.jackcess.impl.DatabaseImpl.create(DatabaseImpl.java:444)
What Database.FileFormat constant should I use for an MS Access 2000-2003 database, when creating the Database object?
It turns out that I needed to use Database.FileFormat.V2000.
After that, it was all plain sailing (although I still need to work out how to get the Long timestamp to convert correctly).

Python winappdbg getting process name from event object

I'm developing a debugging automation system using https://github.com/MarioVilas/winappdbg.
I would like to retrieve process name from event object. Here is my code:
def EventHandler(event):
print 'Inside event handler'
# I want to print the process name here, In this case which should be somefile.exe
debug = Debug( EventHandler, bKillOnExit = True )
proc = debug.execv(['c:\somefile.exe','arg'])
debug.loop()
The tool author answered my question on github : Here is the solution
We can do event.get_process().get_filename(), or if we want to be more fancy:
process = event.get_process()
name = process.get_filename()
print "Process: %s" % name

PG::ERROR: another command is already in progress

I have an importer which takes a list of emails and saves them into a postgres database. Here is a snippet of code within a tableless importer class:
query_temporary_table = "CREATE TEMPORARY TABLE subscriber_imports (email CHARACTER VARYING(255)) ON COMMIT DROP;"
query_copy = "COPY subscriber_imports(email) FROM STDIN WITH CSV;"
query_delete = "DELETE FROM subscriber_imports WHERE email IN (SELECT email FROM subscribers WHERE suppressed_at IS NOT NULL OR list_id = #{list.id}) RETURNING email;"
query_insert = "INSERT INTO subscribers(email, list_id, created_at, updated_at) SELECT email, #{list.id}, NOW(), NOW() FROM subscriber_imports RETURNING id;"
conn = ActiveRecord::Base.connection_pool.checkout
conn.transaction do
raw = conn.raw_connection
raw.exec(query_temporary_table)
raw.exec(query_copy)
CSV.read(csv.path, headers: true).each do |row|
raw.put_copy_data row['email']+"\n" unless row.nil?
end
raw.put_copy_end
while res = raw.get_result do; end # very important to do this after a copy
result_delete = raw.exec(query_delete)
result_insert = raw.exec(query_insert)
ActiveRecord::Base.connection_pool.checkin(conn)
{
deleted: result_delete.count,
inserted: result_insert.count,
updated: 0
}
end
The issue I am having is that when I try to upload I get an exception:
PG::ERROR: another command is already in progress: ROLLBACK
This is all done in one action, the only other queries I am making are user validation and I have a DB mutex preventing overlapping imports. This query worked fine up until my latest push which included updating my pg gem to 0.14.1 from 0.13.2 (along with other "unrelated" code).
The error initially started on our staging server, but I was then able to reproduce it locally and am out of ideas.
If I need to be more clear with my question, let me know.
Thanks
Found my own answer, and this might be useful if anyone finds the same issue when importing loads of data using "COPY"
An exception is being thrown within the CSV.read() block, and I do catch it, but I was not ending the process correctly.
begin
CSV.read(csv.path, headers: true).each do |row|
raw.put_copy_data row['email']+"\n" unless row.nil?
end
ensure
raw.put_copy_end
while res = raw.get_result do; end # very important to do this after a copy
end
This block ensures that the COPY command is completed. I also added this at the end to release the connection back into the pool, without disrupting the flow in the case of a successful import:
rescue
ActiveRecord::Base.connection_pool.checkin(conn)

Resources