简体   繁体   English

使用Jira中的Groovy从服务器拉系统日志

[英]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. 我是Jira的Groovy的新手,并且正在尝试从某个数据库中提取系统日志。 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 -Syslog服务器

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. Groovy提供了Sql类来简化与JDBC数据源的连接。 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). 驱动程序和JDBC连接字符串取决于您要连接的DBMS(MySQL,PostgreSQL等)。

PostgreSQL example PostgreSQL范例

Here's how to connect to PostgreSQL. 这是连接到PostgreSQL的方法。 The code below uses Groovy's Grape to download dependencies. 下面的代码使用Groovy的Grape下载依赖。

Note: @GrabConfig is required to load the org.postgresql.Driver class in a way that allows jdbc to find it. 注意:需要@GrabConfig以允许jdbc找到它的方式加载org.postgresql.Driver类。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM