AnsweredAssumed Answered

Query server logs using python script not returning results

Question asked by rralbritton on Sep 29, 2016
Latest reply on Nov 21, 2018 by dklassen@kamloops.ca

I've adapted this python script to query a server across all of our servers for the past 24 hours. The script runs, but the error logs return empty when they shouldn't and I can't figure out why. Any thoughts?

 

Script (partial):

 

# Ask for map service name
mapService = "service/mapservices/air_photo_hi_res-fall_2014.MapServer"
for serverName in serverList:

# Get a token
token = getToken(username, password, serverName, serverPort)
if token == "":
print "Could not generate a token with the username and password provided."
return

# Construct URL to query the logs
logQueryURL = "/arcgis/admin/logs/query"
logFilter = "{'services': ['" + mapService + "']}"

# Supply the log level, filter, token, and return format
now = datetime.datetime.now()
params = urllib.urlencode({
'startTime': now.strftime('%Y-%m-%dT%H:%M:%S,%f'),
'endTime': (now-datetime.timedelta(hours = 24)).strftime('%Y-%m-%dT%H:%M:%S,%f'),
'level': 'WARNING',
'filter': logFilter,
'token': token,
'pageSize': 100,
'f': 'JSON'})
headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}

# Connect to URL and post parameters
httpConn = httplib.HTTPConnection(serverName, serverPort)
request = httpConn.request("POST",logQueryURL, params, headers)

# Read response
print serverName
response = httpConn.getresponse()
#print response.status
if (response.status != 200):
httpConn.close()
print "Error while querying logs."
return
else:
data = response.read()
print data
# Check that data returned is not an error object
if not assertJsonSuccess(data):
print "Error returned by operation. " + data
else:
print "Operation completed successfully!"
# Deserialize response into Python object
dataObj = json.loads(data)
httpConn.close()

 

Results (for each server listed):

{"hasMore":false,"startTime":0,"endTime":0,"logMessages":[]}

 

But if I query the logs directly, I get the errors that I expect to see:

 

{   "hasMore": true,   "startTime": 1475158749762,   "endTime": 1472583010032,   "logMessages": [     {       "type": "SEVERE",       "message": "Unable to process request. json",       "time": 1475158749762,       "source": "Rest",       "machine": "SERVER001",       "user": "",       "code": 9003,       "elapsed": "",       "process": "26244",       "thread": "39",       "methodName": ""     },

Outcomes