Supervise los servicios de SharePoint (como el servicio de temporizador): envíe un correo electrónico de alerta cuando dejen de funcionar.
Continuando con mi publicación: Monitorear grupos de aplicaciones de SharePoint usando PowerShell Script. Si ciertos servicios en el servidor de SharePoint fallan, eso podría causar cortes o interrupciones del servicio en su entorno de SharePoint. Aunque las soluciones de monitoreo como SCOM pueden monitorear servicios, no pueden iniciar el servicio automáticamente (cuando se detiene). Entonces, ¡abordemos este problema con la ayuda de PowerShell! Aquí está mi ingenioso script de PowerShell para iniciar los servicios necesarios cuando se detiene y enviar correos electrónicos de alerta.
Este script no sólo analiza la disponibilidad de los servicios sino también:
- Detectar el estado de los servicios si no está en estado iniciado
- Inicia automáticamente el servicio si está detenido
- Envía un correo electrónico de alerta al equipo de administración de SharePoint (¡o a quien lo haya configurado!)
Script de PowerShell para monitorear servicios y enviar notificaciones por correo electrónico:
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
#Configuration variables
$EmailFrom = "ServiceMonitor@crescent.com"
$EmailTo = "SPAdmin@crescent.com" # Use commas for multiple addresses
$EmailSubject = "Service(s) went down in SharePoint Server"
#Services to Monitor
$ServicesToMonitor = "IISADMIN", "SPTimerV4", "SPAdminV4", "SPTraceV4" , "SPUserCodeV4" , "SPWriterV4" , "OSearch14" , "W3SVC"
#Get Outgoing Email Server of the SharePoint Farm
$SMTP= (Get-SPWebApplication -IncludeCentralAdministration | Where { $_.IsAdministrationWebApplication } ) | %{$_.outboundmailserviceinstance.server.address}
#Check the status of each service
Foreach($ServiceName in $ServicesToMonitor)
{
#Get the service
$Service = Get-Service -Name $ServiceName
#Check the Service status
if ($Service.Status -ne "Running")
{
Write-Host $Service.DisplayName Found Not running!
Try
{
#Set the Error Action
$ErrorActionPreference = "Stop"
#Try to start the service
Start-Service $ServiceName
}
catch
{
Write-Host "Attempt to start service failed. Find the Error Message below:" -ForegroundColor Red
Write-Host $_.Exception.Message -ForegroundColor Red
}
finally
{
#Reset the Error Action to Default
$ErrorActionPreference = "Continue"
}
#Send out the Alert E-mail
$EmailBody = "Hi SharePoint Team, `n `n The Service: $($Service.DisplayName) was found in stopped state!. `n`nWe tried Re-starting it... Current State of the Service: $($Service.Status). `n`nPlease take necessary actions if its not started! `n `nThanks, `nSharePoint Monitoring Script."
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -Body $EmailBody -SmtpServer $SMTP -usessl
}
}
¿Cómo monitorear los servicios en cada servidor de SharePoint Farm?
Simplemente agregue el parámetro "-ComputerName $Server.Address" a los cmdlets "Get-Service" y "Start-Service".
Entonces, el código es el siguiente:
#Get all SharePoint Servers
$ServersColl = Get-SPServer | where { $_.role -ne "Invalid"}
Foreach($Server in $ServersColl)
{
#Wrap the above code
}
Programe este script de PowerShell en el programador de tareas de Windows en cualquier servidor de aplicaciones (¡o cualquier otro servidor servirá!) para escanear periódicamente el estado del grupo de aplicaciones, digamos una vez cada 5 minutos. Se puede ajustar un intervalo de ejecución según la prioridad de su aplicación. Aquí hay otra publicación sobre la programación de scripts de PowerShell utilizando el Programador de tareas de Windows: Crear una tarea programada para el script de PowerShell con el Programador de tareas de Windows
