Archivi tag: notifiche

Notifiche Windows Server Backup tramite e-mail pianificate

Windows backup notification Usate Windows Server Backup e vorreste ricevere le notifiche dell’esito del backup?

Un’operazione pianificata vi aiuterà!

Ecco come fare:

Create, sul server che effettua il backup, due operazioni pianificate (una per il backup riuscito l’altra per il backup con errori) importando i seguenti files XML (personalizzando le parti evidenziate):

File BackupKO.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-11-22T10:58:40.4469273</Date>
    <Author>NOMEDOMINIO\utente</Author>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Backup"&gt;&lt;Select Path="Microsoft-Windows-Backup"&gt;*[System[(EventID=5 or EventID=8 or EventID=17 or EventID=18 or EventID=19 or EventID=20 or EventID=21 or EventID=22 or EventID=49 or EventID=50 or EventID=52 or EventID=100 or EventID=517 or EventID=518 or EventID=521 or EventID=527 or EventID=528 or EventID=544 or EventID=545 or EventID=546 or EventID=561 or EventID=564 or EventID=612)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>NOMEDOMINIO\utente</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <SendEmail>
      <Server>127.0.0.1</Server>
      <Subject>Errore backup server</Subject>
      <To>info@acme.it</To>
      <From>info@acme.it</From>
      <Body>Verificare il backup da Windows server backup.</Body>
      <HeaderFields />
      <Attachments />
    </SendEmail>
  </Actions>
</Task>

E file BackupOK.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-11-22T10:58:40.4469273</Date>
    <Author>NOMEDOMINIO\utente</Author>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Backup"&gt;&lt;Select Path="Microsoft-Windows-Backup"&gt;*[System[(EventID=4)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>NOMEDOMINIO\utente</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <SendEmail>
      <Server>127.0.0.1</Server>
      <Subject>BACKUP OK </Subject>
      <To>info@acme.it</To>
      <From>info@acme.it</From>
      <Body>Backup terminato correttamente.</Body>
      <HeaderFields />
      <Attachments />
    </SendEmail>
  </Actions>
</Task>

Nei server con sistema operativo Windows 2012 R2 il comando di invio e-mail è deprecato per cui ricorriamo a Powershell. Lanceremo quindi al posto dell’attività “Invio messaggio di posta elettronica (deprecato)” l’attività “Avvio programma” con i seguenti parametri:

Programma o script:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Parametro:
-command ” & {Send-MailMessage -SMTPServer 127.0.0.1 -To ‘info@acme.it’ -From ‘info@acme.it’ -Subject ‘Errore backup server’ -Body ‘Verificare il backup da Windows server backup.’}”

O più semplicemente usare i seguenti file:

File BackupKO-2012R2.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-11-22T10:58:40.4469273</Date>
    <Author>NOMEDOMINIO\utente</Author>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Backup"&gt;&lt;Select Path="Microsoft-Windows-Backup"&gt;*[System[(EventID=5 or EventID=8 or EventID=17 or EventID=18 or EventID=19 or EventID=20 or EventID=21 or EventID=22 or EventID=49 or EventID=50 or EventID=52 or EventID=100 or EventID=517 or EventID=518 or EventID=521 or EventID=527 or EventID=528 or EventID=544 or EventID=545 or EventID=546 or EventID=561 or EventID=564 or EventID=612)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>NOMEDOMINIO\utente</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
      <Arguments>-command " &amp; {Send-MailMessage -SMTPServer 127.0.0.1 -To 'info@acme.it' -From 'info@acme.it' -Subject 'BACKUP OK' -Body 'Verificare il backup da Windows server backup.'}"</Arguments>
    </Exec> 
 </Actions>
</Task>

File BackupOK-2012R2.xml

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <RegistrationInfo>
    <Date>2012-11-22T10:58:40.4469273</Date>
    <Author>NOMEDOMINIO\utente</Author>
  </RegistrationInfo>
  <Triggers>
    <EventTrigger>
      <Enabled>true</Enabled>
      <Subscription>&lt;QueryList&gt;&lt;Query Id="0" Path="Microsoft-Windows-Backup"&gt;&lt;Select Path="Microsoft-Windows-Backup"&gt;*[System[(EventID=4)]]&lt;/Select&gt;&lt;/Query&gt;&lt;/QueryList&gt;</Subscription>
    </EventTrigger>
  </Triggers>
  <Principals>
    <Principal id="Author">
      <UserId>NOMEDOMINIO\utente</UserId>
      <LogonType>Password</LogonType>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>true</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>true</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>false</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>false</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>PT4H</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="Author">
    <Exec>
      <Command>C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe</Command>
      <Arguments>-command " &amp; {Send-MailMessage -SMTPServer 127.0.0.1 -To 'info@acme.it' -From 'info@acme.it' -Subject 'BACKUP OK' -Body 'Backup terminato correttamente.'}"
      </Arguments>
    </Exec> 
  </Actions>
</Task>

Al verificarsi dell’evento di fine backup sarà spedito un messaggio e-mail con l’esito del salvataggio.

Se non avete un server di posta interno vi consigliamo di leggere il nostro post Configurare un SMTP server su Windows 2008 senza Exchange

Inviare notifiche tramite il protocollo SMTP di Exchange 2007/2010

Notifiche ExchangeSpesso i programmi che provano ad inviare notifiche tramite Exchange 2007/2010 restituiscono un errore. Questo perché i connettori di Exchange consentono l’accesso solo ai client della rete autenticati.

Come consentire a questi programmi di inviare e-mail anche all’esterno?

Se le notifiche partono dallo stesso server allora bisogna creare un connettore che usi l’indirizzo ip 127.0.0.1. Il comando con la Exchange Management Shell è

new-ReceiveConnector -Name 'Localhost SMTP' -Usage 'Custom' -Bindings '127.0.0.1:25' -Fqdn 'localhost' -RemoteIPRanges '0.0.0.0-255.255.255.255' -Server 'NOMESERVER'

Se le notifiche partono da altri servers/stampanti allora i comandi saranno i seguenti:

  • per verificare quale connettore viene usato internamente (confrontare i ranges dei connettori con l’IP di partenza del server/stampante)

get-ReceiveConnector |fl Name,RemoteIPRange

  • una volta intercettato il corretto connettore modificare l’intervallo di IP per escludere l’IP da cui partirà la mail, usando il comando

set-ReceiveConnector 'NOMECONNETORE' -RemoteIPRanges ('IPPARTENZA1-IPDESTINAZIONE1','IPPARTENZA2-IPDESTINAZIONE2')

  • poi bisognerà creare il nuovo connettore apposito con il comando

new-ReceiveConnector -Name 'Connettore per notifiche da server e stampanti' -Usage 'Custom' -Bindings '0.0.0.0:25' -RemoteIPRanges ('IPPARTENZASERVERSTAMPANTI-IPDESTINAZIONESERVERSTAMPANTI') -Server 'NOMESERVER' -PermissionGroups 'AnonymousUsers, ExchangeServers'

Esempio con IP di partenza email da 192.168.143.2 a .29 oppure da .100 a .254 (ricordarsi di escludere l’IP del default gateway!!!):


PS C:\Windows\system32>get-ReceiveConnector |fl Name,RemoteIPRanges

Name : Default SBS2008
RemoteIPRanges : {192.168.143.10-192.168.143.254, 192.168.143.0-192.168.143.8}
Name : Windows SBS Internet Receive SBS2008
RemoteIPRanges : {192.168.144.0-255.255.255.255, 192.168.143.1-192.168.143.1, 0.0.0.0-192.168.142.255}
Name : Windows SBS Fax Sharepoint Receive SBS2008
RemoteIPRanges : {127.0.0.1-127.0.0.1}


PS C:\Windows\system32>set-ReceiveConnector 'Default SBS2008' -RemoteIPRanges ('192.168.143.30-192.168.143.99','192.168.143.0-192.168.143.0')
PS C:\Windows\system32>new-ReceiveConnector -Name 'Connettore per notifiche da server e stampanti' -Usage 'Custom' -Bindings '0.0.0.0:25' -RemoteIPRanges ('192.168.143.1-192.168.143.29','192.168.143.100-192.168.143.254') -Server 'SBS2008' -PermissionGroups 'AnonymousUsers, ExchangeServers'

Identity Bindings Enabled
-------- -------- -------
SBS2008\Connettore per notifiche da server e stampanti {0.0.0.0:25} True

PER CONSENTIRE IL RELAY:

Get-ReceiveConnector "Connettore per notifiche esterne" | Add-ADPermission -user "DOMINIO\utente" -ExtendedRights "ms-Exch-SMTP-Accept-Any-Recipient"