Eventsource
hi iam using te following code for event script. The output iam getting is There would be no script events for the selected device. IF iam running in datasource the script is working both in jason format
import groovy.sql.Sql
import groovy.json.JsonBuilder
import org.json.JSONObject
def hostname = hostProps.get("system.hostname")
def user = hostProps.get("sybase.user")
def pass = hostProps.get("sybase.pass")
def port = 21000
def url = "jdbc:sybase:Tds:" + hostname + ":21000"
def driver = "com.sybase.jdbc4.jdbc.SybDriver"
def sql = Sql.newInstance(url, user, pass, driver)
if (sql.connection) {
// println("Connected to Sybase server on ${hostname}")
def filePath = "/tmp/BTS01DEV_WNL_DS.log" // Replace with the actual file path on the Linux machine
def file = new File(filePath)
if (file.exists() && file.isFile()) {
def lines = file.readLines()
// Define the keywords to search for
def keywords = [
"warning",
"error",
"fail",
// Add more keywords as needed
]
// Find the lines that contain the keywords along with their indices
def matchedLines = lines
.findAll { line -> keywords.any { keyword -> line.toLowerCase().contains(keyword) } }
.collect { line -> [line: lines.indexOf(line) + 1, message: line] }
// Construct the final JSON object
def json = new JsonBuilder()
json {
events matchedLines
}
// Convert the JSON object to a string
def jsonString = json.toString()
// Remove leading characters until the first '{' character
def startIndex = jsonString.indexOf('{')
def trimmedJsonString = jsonString.substring(startIndex)
// Create the JSONObject from the trimmed JSON string
def jsonObject = new JSONObject(trimmedJsonString)
println(jsonObject.toString())
} else {
println("File not found or is not a regular file")
}
} else {
println("Failed to connect to Sybase server on ${hostname}")
}
out put in datasource:
{"events":[{"line":41,"message":"00:0000:00000:00000:2021/04/21 14:54:02.58 kernel Warning: Operating System stack size is greater than 2MB. If it is too large, ASE may run out of memory during thread creation. You can reconfigure it using 'limit' (csh) or 'ulimit' (bash)"},{"line":177,"message":"00:0006:00000:00002:2021/04/21 14:54:03.46 kernel Warning: Cannot set console to nonblocking mode, switching to blocking mode."},{"line":313,"message":"00:0000:00000:00000:2021/04/21 16:42:08.18 kernel Warning: Operating System stack size is greater than 2MB. If it is too large, ASE may run out of memory during thread creation. You can reconfigure it using 'limit' (csh) or 'ulimit' (bash)"},{"line":636,"message":"00:0002:00000:00002:2021/04/21 16:41:26.28 kernel Warning: Cannot set console to nonblocking mode, switching to blocking mode."}