Pull Syslog from the server using Groovy in Jira - groovy

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')

Related

How to create a new DB or connect to existing one

I pulled and run neo4j docker:
sudo docker run -p7474:7474 -p7687:7687 -e NEO4J_AUTH=neo4j/s3cr3t neo4j
From python I can connect to it with:
scheme = "neo4j"
host_name = "localhost"
port = 7687
url = "{scheme}://{host_name}:{port}".format(scheme=scheme, host_name=host_name, port=port)
user = "neo4j"
password = "s3cr3t"
driver = GraphDatabase.driver(url, auth=(user, password))
But it seems that there is no API to choose the DB name I want to work with ?
Is it possible to create multiple databases (like postgres psycopg2 connect function with dbname ?)
I want to be able to create 2 different DBs (graphs) and to choose the DB (graph) to work with through python
How can I do it ?
To connect to a specific database, you can pass the database's name as the value of the database keyword argument when you create the Session used for your transactions.
For example, to create a Session for the database named "foo":
...
driver = GraphDatabase.driver(uri, auth=(user, password))
session = driver.session(database="foo")
...

JMeter Groovy SQL Connection use JDBC Connection Configuration

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

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)

pyodbc cannot connect to on-premises MSSQL server

I want to connect to MSSQL server2012 from Python using pyodbc on a Debian8 host. The current code already works for Azure SQL server but not for local SQL server.
The connection string looks like this:
import pyodbc
server = 'IP'
database = 'DB_Name'
username = 'user'
password = 'pass'
driver = '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';PORT=1433;DATABASE='+database+';UID='+username+';PWD='+ password)
I had to use IP address because I could not reach SQL server via name. I can connect to the server with SSMS on a windows machine. I have tried the following combinations as well:
server='sqlservername\instancename'
server='IP, port'
server='IP\instancename'
driver='SQL Server'
Integrated_Security=false;
Trusted_Connection=no;
but none of them worked. I got either Login timeout or error in registering user. I run the same python code on windows machine without any problem.
Finally i found the correct combination. Besides thanks to #GordThompson the TCP/IP was enabled but on another port.
import pyodbc
server = 'IP\InstanceName, port'
database = 'DB_Name'
username = 'user'
password = 'pass'
driver = '{ODBC Driver 17 for SQL Server}'
cnxn = pyodbc.connect('DRIVER='+driver+';SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+ password)

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