Logs are coming from POSTGRESQL, I am also using Script Runner to implement this. I have been searching ways to send these logs to syslog servers, since I am really new to this I do not know where to start.
Let's say this is the name of the server: syslog12 and port: 514
I would really appreciate if someone can teach me how to send the logs to the syslog server.
This is my groovy code:
return getUserId()
class Logs{
String id = ""
String created = ""
String summary =""
String category =""
String searchField =""
String toString(){
"$id ==== $created-$summary,$category,$searchField"
}
}
def getUserId(){
def driver = Class.forName('org.postgresql.Driver').newInstance() as Driver
def props = new Properties()
props.setProperty("user", "USERNAME")
props.setProperty("password", "PASSWORD")
props.setProperty("sslfactory", "org.postgresql.ssl.NonValidatingFactory")
props.setProperty("ssl", "true")
def conn = driver.connect("jdbc:postgresql://DATABASE:PORT/GRP", props)
def sql = new Sql(conn)
try {
BufferedWriter outputFile = new BufferedWriter(new FileWriter("/GRP/atlassian/testProd1.txt", true))
def logs = new Logs()
String query = "SELECT * from audit_log where created >='2015-04-15' AND created < '2015-04-26' order by id ASC"
PreparedStatement statement = conn.prepareStatement(query)
ResultSet result = statement.executeQuery()
while(result.next()){
String id1 = result.getString("id")
logs.id = id1
String created1 = result.getString("created")
logs.created = created1
String summary1 = result.getString("summary")
logs.summary = summary1
String category1 = result.getString("category")
logs.category = category1
String searchField1 = result.getString("search_field")
logs.searchField = searchField1
outputFile.write("[GRP2.0] "+logs.toString())
outputFile.newLine()
}
outputFile.close()
return ("[GRP2.0] "+logs.toString())
} finally {
sql.close()
conn.close()
}
}