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

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."

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

# Supply the log level, filter, token, and return format
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):
print "Error while querying logs."
data =
print data
# Check that data returned is not an error object
if not assertJsonSuccess(data):
print "Error returned by operation. " + data
print "Operation completed successfully!"
# Deserialize response into Python object
dataObj = json.loads(data)


Results (for each server listed):



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": ""     },