Can a Python script be triggered to run based on a ArcGIS Server Log message?

2665
1
06-06-2016 12:18 PM
SethStark1
New Contributor II


I'm using ArcGIS Server 10.2. I am getting a reoccurring message in my server logs related to one specific service. When this message occurs, the service stops working until I stop and restart the service. Then it works again for a few hours, before the whole process repeats itself.

Here is the message:

Level: SEVERE

Message: "A database error occurred"

Source: TSI_MH_Edit.MapServer

Code: 17000

I cannot fix the root cause of this problem (I am working under time constraints--eventually I will fix it), so I'm wondering if, in the meantime, a script could be triggered to run which would stop and start the service in question when this error occurs. So, when the message above appears in the Server Logs, it would trigger a script to stop and restart the service.

Has anyone ever done anything like this?

Tags (2)
1 Reply
JonathanQuinn
Esri Notable Contributor

Sure can!  You can use Python to parse the logs by querying them, and then if it finds a certain code, (or just query the logs for a message code, for example code 17000), it can then stop and start the service, send you an email, whatever you'd like.  The two links to documentation contain code samples that can be easily modified.  This can run as a scheduled task within Windows Task Scheduler, see this help document or this blog post.