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):
<SPAN class="comment token"># Ask for map service name</SPAN>
mapService <SPAN class="operator token">=</SPAN> <SPAN class="string token">"service/mapservices/air_photo_hi_res-fall_2014.MapServer"</SPAN>
<SPAN class="keyword token">for</SPAN> serverName <SPAN class="keyword token">in</SPAN> serverList<SPAN class="punctuation token">:</SPAN>
<SPAN class="comment token"># Get a token</SPAN>
token <SPAN class="operator token">=</SPAN> getToken<SPAN class="punctuation token">(</SPAN>username<SPAN class="punctuation token">,</SPAN> password<SPAN class="punctuation token">,</SPAN> serverName<SPAN class="punctuation token">,</SPAN> serverPort<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">if</SPAN> token <SPAN class="operator token">==</SPAN> <SPAN class="string token">""</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Could not generate a token with the username and password provided."</SPAN>
<SPAN class="keyword token">return</SPAN>
<SPAN class="comment token"># Construct URL to query the logs</SPAN>
logQueryURL <SPAN class="operator token">=</SPAN> <SPAN class="string token">"/arcgis/admin/logs/query"</SPAN>
logFilter <SPAN class="operator token">=</SPAN> <SPAN class="string token">"{'services': ['"</SPAN> <SPAN class="operator token">+</SPAN> mapService <SPAN class="operator token">+</SPAN> <SPAN class="string token">"']}"</SPAN>
<SPAN class="comment token"># Supply the log level, filter, token, and return format</SPAN>
now <SPAN class="operator token">=</SPAN> datetime<SPAN class="punctuation token">.</SPAN>datetime<SPAN class="punctuation token">.</SPAN>now<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
params <SPAN class="operator token">=</SPAN> urllib<SPAN class="punctuation token">.</SPAN>urlencode<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">{</SPAN>
<SPAN class="string token">'startTime'</SPAN><SPAN class="punctuation token">:</SPAN> now<SPAN class="punctuation token">.</SPAN>strftime<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'%Y-%m-%dT%H:%M:%S,%f'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'endTime'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="punctuation token">(</SPAN>now<SPAN class="operator token">-</SPAN>datetime<SPAN class="punctuation token">.</SPAN>timedelta<SPAN class="punctuation token">(</SPAN>hours <SPAN class="operator token">=</SPAN> <SPAN class="number token">24</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>strftime<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'%Y-%m-%dT%H:%M:%S,%f'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'level'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'WARNING'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'filter'</SPAN><SPAN class="punctuation token">:</SPAN> logFilter<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'token'</SPAN><SPAN class="punctuation token">:</SPAN> token<SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'pageSize'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="number token">100</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'f'</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">'JSON'</SPAN><SPAN class="punctuation token">}</SPAN><SPAN class="punctuation token">)</SPAN>
headers <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">{</SPAN><SPAN class="string token">"Content-type"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"application/x-www-form-urlencoded"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Accept"</SPAN><SPAN class="punctuation token">:</SPAN> <SPAN class="string token">"text/plain"</SPAN><SPAN class="punctuation token">}</SPAN>
<SPAN class="comment token"># Connect to URL and post parameters</SPAN>
httpConn <SPAN class="operator token">=</SPAN> httplib<SPAN class="punctuation token">.</SPAN>HTTPConnection<SPAN class="punctuation token">(</SPAN>serverName<SPAN class="punctuation token">,</SPAN> serverPort<SPAN class="punctuation token">)</SPAN>
request <SPAN class="operator token">=</SPAN> httpConn<SPAN class="punctuation token">.</SPAN>request<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"POST"</SPAN><SPAN class="punctuation token">,</SPAN>logQueryURL<SPAN class="punctuation token">,</SPAN> params<SPAN class="punctuation token">,</SPAN> headers<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Read response</SPAN>
<SPAN class="keyword token">print</SPAN> serverName
response <SPAN class="operator token">=</SPAN> httpConn<SPAN class="punctuation token">.</SPAN>getresponse<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#print response.status</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">.</SPAN>status <SPAN class="operator token">!=</SPAN> <SPAN class="number token">200</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
httpConn<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Error while querying logs."</SPAN>
<SPAN class="keyword token">return</SPAN>
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
data <SPAN class="operator token">=</SPAN> response<SPAN class="punctuation token">.</SPAN>read<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN> data
<SPAN class="comment token"># Check that data returned is not an error object</SPAN>
<SPAN class="keyword token">if</SPAN> <SPAN class="operator token">not</SPAN> assertJsonSuccess<SPAN class="punctuation token">(</SPAN>data<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Error returned by operation. "</SPAN> <SPAN class="operator token">+</SPAN> data
<SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Operation completed successfully!"</SPAN>
<SPAN class="comment token"># Deserialize response into Python object</SPAN>
dataObj <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>data<SPAN class="punctuation token">)</SPAN>
httpConn<SPAN class="punctuation token">.</SPAN>close<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Results (for each server listed):
{"hasMore":false,"startTime":0,"endTime":0,"logMessages":[]}<SPAN class="line-numbers-rows"><SPAN></SPAN></SPAN>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": "" },