84 lines
2.8 KiB
PowerShell
84 lines
2.8 KiB
PowerShell
<#
|
|
|
|
ESEGUE UNA CHIAMATA A UNA uri e fa il log dei dati restituiti ...
|
|
|
|
Se tutto Ok scrive un file di check, questo file viene usato per verificare che non sia già stato eseguito in modo corretto nelle
|
|
precedenti n. ore, così posso schedularlo più volte
|
|
|
|
Esegue prima una chiamata ping al server, poi una chiamata a una URL di test e infine la chiamata effettiva
|
|
|
|
Sarebbe da sistemare e rendere parametrica / procedura ...
|
|
|
|
|
|
# *** NOTE TECNICHE PER SCHEDULAZIONE
|
|
|
|
# Per far scrivere il ritorno dalla chiamata di IIS nel file di log ho creato la schedulazione entrando con
|
|
# l'utente stesso (Steamware) che esegue lo script e ho fatto import della schedulazione ( in ambiente ISE il log lo scrive )
|
|
# Ho messo anche permessi all'utente "Logon as batch job" ( vedi sotto )
|
|
|
|
# Utente messo in PowerUser e permessi scrittura cartella Steamware
|
|
|
|
# Logon as batch job policy is set for the user. This policy is accessible by opening the Control Panel, Administrative Tools,
|
|
# and then Local Security Policy -> Local Policy -> User Rights Assignment -> then Logon as batch job.
|
|
|
|
# Task Security Context
|
|
# https://forsenergy.com/en-us/taskscheduler/html/a922c2b5-6a43-4503-ab7f-4f3d77b3cc8a.htm
|
|
|
|
# Mod. 2022-05-16 Minor Fix
|
|
# Mod. 2022-05-17 Ping e Varie
|
|
# Mod. 2022-05-18 add Check ObjTest
|
|
|
|
#>
|
|
|
|
Remove-Variable * -ErrorAction SilentlyContinue # pulisco variabili x ISE
|
|
|
|
# avvio stopwatch
|
|
$stopwatch = [system.diagnostics.stopwatch]::StartNew()
|
|
|
|
$FolderName="c:\Steamware\Logs"
|
|
$Logfile = Join-Path $FolderName "\GPW_Core_Start.log"
|
|
|
|
$Server = "office.egalware.com"
|
|
$testUri = "https://office.egalware.com/GPW/Api/api/VC19"
|
|
$callUri01 = "https://office.egalware.com/GPW/CORE.WRKLOG/"
|
|
$callUri02 = "https://office.egalware.com/GPW/CORE.SMART/"
|
|
|
|
Function LogWrite
|
|
{ Param ([string]$logstring)
|
|
|
|
$Stamp = (Get-Date).toString("yyyy/MM/dd HH:mm:ss.fff")
|
|
Add-content $Logfile -value "$Stamp $logstring"
|
|
}
|
|
|
|
# test e creazione DIR di Log
|
|
if (Test-Path $FolderName)
|
|
{
|
|
#Write-Host "Folder Exists"
|
|
}
|
|
else
|
|
{ #PowerShell Create directory if not exists
|
|
New-Item $FolderName -ItemType Directory
|
|
Write-Host "Folder Created successfully"
|
|
}
|
|
|
|
try { # vera chiamata
|
|
LogWrite("Test Call effettuata, effettuo chiamata target")
|
|
$Response = Invoke-WebRequest -URI $callUri01 -UseBasicParsing
|
|
$Response = Invoke-WebRequest -URI $callUri02 -UseBasicParsing
|
|
LogWrite("Call effettuate!")
|
|
#[string]$Return = $Response.Content # messo per prova visto che non creava nulla in LOG - potrebbe non servire
|
|
}
|
|
catch {
|
|
$Response = 'CALL ERROR ...'
|
|
LogWrite($Error[0])
|
|
}
|
|
finally
|
|
{
|
|
LogWrite("*** END Call ***")
|
|
}
|
|
|
|
# fermo stopwatch e conteggio...
|
|
$stopwatch.Stop()
|
|
$durata = $stopwatch.Elapsed.TotalSeconds
|
|
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gpw.Core -o $durata
|
|
LogWrite("Durata esecuzione: $durata") |