tpcolson

Email alerts from ArcGIS Server

Discussion created by tpcolson Champion on Mar 20, 2019
Latest reply on Mar 26, 2019 by jmjohnson91

There's all sorts of ways to get email alerts from ArcGIS server (Configure email notifications—ArcGIS Monitor Administrator | ArcGIS EnterpriseA simple e-mail notification system for Survey123 for ArcGIS , python - Is there any way to get an email when ArcGIS Server services are stopped/down? - Geographic Information Systems… , GeoSystems Monitor Enterprise — Vestra ). This just happens to be what worked for my environment.

 

While working on another must-get-alert-when-it-happens issue, I realized how solving one problem also solves my "I want to know when ArcGIS Server hiccups problem" as well. I have quite a large GIS server farm, and it's important to me to be able to get in front of GIS server issues before my customers encounter any stop-work issues. 

 

Creating the Powershell scripts that will harvest the events

 

We need two scripts: 

System Events: Looking at System Events with the string "Arc" for the last year, I discovered that I'm interested in all of them except routine ArcGIS has started traffic:

$event = get-eventlog -LogName System -Message *Arc* -newest 1 | Where-Object {$_.Message -ne "The ArcGIS Server service entered the running state."}

$PCName = $env:COMPUTERNAME
$EmailBody = $event | format-list -property * | out-string
$EmailFrom = "$PCName sasquatch@bigfoot.com"
$EmailTo = "you_cant_find@me.com"
$EmailSubject = "ArcGIS Warning!!!!!!!!!!!!"
$SMTPServer = "smtp.server"
Write-host "Sending Email"
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body $EmailBody -SmtpServer $SMTPServer

Save this as C:\ALERTS\ALERT_ARC_SYSTEM.ps1

 

Application Events:Looking at Application Events with the string "Arc" for the last year, I discovered that I'm interested in all of them except routine MsiInstaller traffic:

$event = get-eventlog -LogName Application -Message *Arc* -newest 1 | Where-Object {$_.Source -notlike "MsiInstaller"}
$PCName = $env:COMPUTERNAME
$EmailBody = $event | format-list -property * | out-string
$EmailFrom = "$PCName sasquatch@bigfoot.com"
$EmailTo = "you_cant_find@me.com"
$EmailSubject = "ArcGIS Warning!!!!!!!!!!!!"
$SMTPServer = "smtp.server"
Write-host "Sending Email"
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body $EmailBody -SmtpServer $SMTPServer

Save this as Save this as C:\ALERTS\ALERT_ARC_APPLICATION.ps1

 

The flexibility here is that you can filter whatever types of Events you want to receive an email for. Using Get-EventLog properties, I'm expecting about 1-5 emails per week with the filters I'm using. 

 

Setting up Task Scheduler to monitor the event log

Right-click on the Application Log and select Attach a Task To this Log

When you get to Action, select the PS script you created for Application Events

 

Finish the Basic Task Wizard then go into Task Scheduler and set things up to run as a service account, etc. 

 

Testing

From an administrative PS prompt:

 

PS C:\Windows\system32> New-EventLog –LogName System –Source "Test Arc System"
PS C:\Windows\system32> Write-EventLog –LogName System –Source "Test Arc System" –EventID 1 –Message "Test Arc System 4"
PS C:\Windows\system32> New-EventLog –LogName Application –Source "Test Arc"
PS C:\Windows\system32> Write-EventLog –LogName Application –Source "Test Arc" –EventID 1 –Message "Test Arc Application 4"

And you should see: 

 

In conclusion, there are many ways to do this, and my Powershell won't get me hired as a Powershell scripter, but this should give you some ideas on how to customize and automate how you're getting ArcGIS Server alerts. 

 

 

Credit: I was inspired by https://www.ryadel.com/en/event-viewer-send-notification-e-mail-messages-with-powershell/  

Outcomes