2

I am trying to retrieve Websphere server logs through wsadmin. When connected to a ND, I might have to retrieve logs from remote nodes where I dont have SSH access.

Since I can view the logs using the Management Console, I was wondering if I could retrieve the logs using wsadmin.

I've managed to do the following:

    s1 = AdminConfig.getid('/Node:'+nodeName+'/Server:'+serverName)
    log = AdminConfig.showAttribute(s1, 'outputStreamRedirect')

For each server, this prints something like this:

[baseHour 24]
[fileName ${SERVER_LOG_ROOT}/SystemOut.log]
[formatWrites true]
[maxNumberOfBackupFiles 5]
[messageFormatKind BASIC]
[rolloverPeriod 24]
[rolloverSize 1]
[rolloverType SIZE]
[suppressStackTrace false]
[suppressWrites false]
[baseHour 24]
[fileName ${SERVER_LOG_ROOT}/SystemErr.log]
[formatWrites true]
[maxNumberOfBackupFiles 5]
[messageFormatKind BASIC]
[rolloverPeriod 24]
[rolloverSize 1]
[rolloverType SIZE]
[suppressStackTrace false]
[suppressWrites false]

Is there any object in wsadmin that could help me retrieve the contents of that fileName attribute?

Perro
  • 61
  • 2
  • 8

1 Answers1

2

This works for a single server but it's easy to edit for multiple servers and configurations.

It locates the log path, and sends an ant job to load its contents, and then gets the ant log.

Parsing the file to get only the log should be easy enough.

from java.lang import String
import jarray

serverName = sys.argv[0]
s1 = AdminConfig.getid('/Server:'+serverName)
log = AdminConfig.showAttribute(s1, 'outputStreamRedirect')
errLog = AdminConfig.showAttribute(s1, 'errorStreamRedirect')
adminOperations = AdminControl.queryNames('WebSphere:*,type=AdminOperations,process='+serverName).splitlines()[0]
sysOutLogPath = AdminControl.invoke(adminOperations, 'expandVariable', [AdminConfig.showAttribute(log, 'fileName')])
#sysErrLogPath = AdminControl.invoke(adminOperations, 'expandVariable', [AdminConfig.showAttribute(errLog, 'fileName')])
fileContent_outLog = '<project name="printLog" default="printLog"><target name="printLog"><loadfile property="logContents" srcFile="'+sysOutLogPath+'"/></target></project>'
str = String(fileContent_outLog)
bytes = str.getBytes()
antAgent = AdminControl.makeObjectName(AdminControl.queryNames('WebSphere:*,type=AntAgent,process='+serverName))
AdminControl.invoke_jmx(antAgent, 'putScript', [String('printLog.xml'),bytes], jarray.array(['java.lang.String', '[B'], String))
AdminControl.invoke_jmx(antAgent, 'invokeAnt', [jarray.array([], String), String('printLog.xml'), String('printLog')], jarray.array(['[Ljava.lang.String;', 'java.lang.String', 'java.lang.String'], String))
logBytes = AdminControl.invoke_jmx(antAgent, 'getLastLog', [],jarray.array([],  String))
tempFile = open('./'+serverName+'.SystemOut.log','w')
tempFile.write(String(logBytes))
tempFile.close()
Perro
  • 61
  • 2
  • 8