JMeter Groovy SQL Connection use JDBC Connection Configuration - groovy

I have set up the JDBC Connection Configuration in JMeter
Now I would like to use this connection details across all JSR223 Sampler using groovy code but I am getting an error or really don't know how to use it
So instead of being able to simply use the connection configuration I am providing the full connection string details in each sampler
import groovy.sql.Sql
def dburl = 'jdbc:mysql://${__P(${env}_host)}:${__P(${env}_port)}/${__P(${env}_db)}?requireSSL=false&useSSL=false&rewriteBatchedStatements=true&useServerPrepStmts=true&verifyServerCertificate=false'
def user = '${__P(${env}_username)}'
def password = '${__P(${env}_password)}'
def driver = '${__P(${env}_driver)}'
def sql = Sql.newInstance(dburl, user, password, driver)
How can I simply used the connection configuration I created

Something like:
def connection = org.apache.jmeter.protocol.jdbc.config.DataSourceElement.getConnection("your pool name")
def sql = new Sql(connection)
Also don't use JMeter Functions or Variables in Groovy scripts.
More information: Apache Groovy - Why and How You Should Use It

Related

SAP ASE Extension Python Module: #stmt_query_timeout?

I am trying to move from a Windows-based pyodbc (Using the SAP Adaptive Server Enterprise 16.0 driver) to Red Hat Linux 7.9-based sybpydb solution.
Current pyodbc solution:
connection = pyodbc.connect(
"Driver={Adaptive Server Enterprise};NetworkAddress=<servername,serverport>;
Database=<database>;UID={<username>};PWD={<password>};#pool_size=10;
stmtquery_timeout=1200;#login_timeout=30;#connection_timeout=30")
df = pandas.read_sql_query("exec <storedproc_name>")
connection.close()
I am trying to replicate this under linux using the sybclient-16.0.3-2 package.
import sybpydb
connection = sybpydb.connect(user=username, password=password, servername=servername,
dsn="HostName=<hostname>;Database=<database>;LoginTimeout=30;Timeout=30")
curr = connection.cursor()
result = cursor.execute("exec <storedproc_name>")
Passing #smtmquery_timeout=1200 causes the connection to fail. But without this, the call to the stored proc will timeout. I can't see anything in the documentation about this.
Thanks in advance
Please refer to the document:
https://help.sap.com/docs/SAP_ASE_SDK/a1576559612d4e39886fc0ad4e093074/b0fd2586bbf910148c6ac638f6594153.html
There is no attribute: smtmquery_timeout
If you are using "sybpydb", you can use the openclient sdk directly instead of the ODBC style configuration for the connection.

connecting to oracle db from python using a config file

I am pretty much new to this concept.
Currently, I am connecting to oracle database directly using the credentials within a python script but I want to store the connection string in a text file or a separate .py file and call them as I use the same credentials for multiple scripts.
I am using cx_oracle and sqlalchemy packages to connect to two databases as I extract data from the source and push it to the target(both the source and target are oracle databases).
import cx_Oracle
from sqlalchemy import create_engine, types
dsn_tns = cx_Oracle.makedsn('shost', 'sport', service_name='sservice_name')
conn = cx_Oracle.connect(user='suser', password='spw', dsn = dsn_tns)
engine = create_engine('oracle://tuser:tpw#thost:tport/tservice_name')
I'd really want to automate this process as I reuse the same connection string in multiple scripts and I'd really appreciate if I can get some help.

how to form address string to connect to solace using python

I want to consume messages from a already setup solace broker in my company. When i asked for the host name etc required to connect with solace, below details were provided by my company's solace team-
Connection factory - cf/dev_test_uk
VPN - dev_test_uk
VPN Server - smf://host:port
username - user1
password - password1
topic- testtopic
For reference I am using the code provide at https://github.com/SolaceSamples/solace-samples-amqp-qpid-proton-python
My code is -
from proton import Message
from proton.handlers import MessagingHandler
from proton.reactor import Container
class HelloWorld(MessagingHandler):
def __init__(self,url,address,username,password):
super(HelloWorld,self).__init__()
self.url = url
self.address = address
self.username = username
self.password = password
def on_start(self,even):
conn = event.container.connect(url = self.url,
user=self.username,
password=self.password)
event.container.create_receiver(conn, self.address)
def on_message(self, event):
print(event.message.body)
event.connection.close()
Container(HelloWorld("smf://host:port","topic://testtopic","user1","password1")).run()
when I run this code I get 'amqp:connection:framing-error',"SASL header mismatch:Insufficient data to determine protocol [''] (connection aborted)"
Which is expected as I don't think the url or address string formed is correct.
Following are the questions I have-
where should i use this VPN and connection factory while doing the connections?
VPN server url should't it be something like amqp://.... ?
Please help me with this.
Unfortunately....
Solace NO support python module to access Solace Protocol(SMF)....
you can OLNY wrap C API by yourself.....
because I am also need this Python Client API.....
so you can ref our project....
https://pypi.org/project/pysolace/
(WARRNING - unofficial)

Pull Syslog from the server using Groovy in Jira

I am new to Groovy in Jira, and I am trying to pull syslogs off a certain database. I am wondering if anyone can put me to the right direction. I am using the script console to implement this.
I am guessing it will be on the local host. I am given these to access the database server :
-Database server with Port Number
-Database name
-Password
-Application Database User
-Syslog Servers
Are there any tutorials I can use to be able to connect to the database server
Thank you very much,
Groovy provides the Sql class to simplify connecting to JDBC data sources. Here's an example.
import groovy.sql.Sql
def jdbc = 'jdbc:h2:mem:'
def db = Sql.newInstance(jdbc, 'org.h2.Driver')
def foos = db.rows('select foo from bar')
...
db.close() // Done with connection
The driver and JDBC connection string depends on the DBMS you're connecting to (MySQL, PostgreSQL, etc).
PostgreSQL example
Here's how to connect to PostgreSQL. The code below uses Groovy's Grape to download dependencies.
Note: #GrabConfig is required to load the org.postgresql.Driver class in a way that allows jdbc to find it.
#Grab('org.postgresql:postgresql:9.3-1101-jdbc41')
#GrabConfig(systemClassLoader=true)
import groovy.sql.Sql
def host = '192.168.1.1'
def port = 5432
def dbname = 'foo'
def user = 'xxx'
def password = 'yyy'
def jdbc = "jdbc:postgresql://${host}:${port}/${dbname}"
def db = Sql.newInstance(jdbc, user, password, 'org.postgresql.Driver')

Prevent timeout when connecting

I am using groovy to connect to a database and it works great with one my sources. Recently, I have access to another database but I can seem to connect to it using Groovy.
I get the error(s):
Dec 20, 2013 12:22:26 PM org.codehaus.groovy.runtime.StackTraceUtils sanitize
WARNING: Sanitizing stacktrace:
oracle.net.ns.NetException: The Network Adapter could not establish the connection
Is there a way to extend the connection so it won't time out?
def db = Sql.newInstance(
'jdbc:oracle:thin:#10.10.18.75:1521:radd',
'report_user', 'createreport', 'oracle.jdbc.pool.OracleDataSource')
According to the Groovy API for newInstance You should be able to pass in properties key value pairs and for Oracle use the ConnectionWaitTimeout property.
def db = Sql.newInstance(
url: 'jdbc:oracle:thin:#10.10.18.75:1521:radd',
user: 'report_user', password: 'createreport', driverClassName: 'oracle.jdbc.pool.OracleDataSource', connectionWaitTimeout: 10)

Resources