Merge branch 'develop' into main
This commit is contained in:
@@ -1,167 +0,0 @@
|
||||
################START SCRIPT################
|
||||
|
||||
#rilevo time per log inizio analisi
|
||||
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
|
||||
#conteggio progetti trovati
|
||||
$projectsFound = 0
|
||||
|
||||
#conteggio progetti con commit negli ultimi giorni
|
||||
$projectWithCommits = 0
|
||||
|
||||
#conteggio progetti senza commit negli ultimi giorni
|
||||
$projectWithNoCommits = 0
|
||||
|
||||
#conteggio commits degli ultimi giorni
|
||||
$recentCommits = 0
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 0
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 0
|
||||
|
||||
#ultimi giorni da considerare
|
||||
$lastDays = 7
|
||||
|
||||
#data per conteggio commits degli ultimi giorni
|
||||
$requestDate = (Get-Date).AddDays(-$lastDays).toString("yyyy-MM-dd")
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
||||
|
||||
#nome file di log
|
||||
$logFile = Join-Path $GitLogFolder "GitlabCommits.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
{
|
||||
Param ($logType, [string]$logString)
|
||||
#scrivo su file la stringa se il tipo di log è > o = al livello di log richieeso
|
||||
if($logType -le $logLevel)
|
||||
{
|
||||
Add-content $logFile -value "$logString"
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if($terminalOutput -eq 1)
|
||||
{
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $GitLogFolder)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
New-Item $GitLogFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput 0 "--------------------"
|
||||
Switch ($logLevel)
|
||||
{
|
||||
0 {WriteLogOutput 0 "LOG SINTETICO GITLAB COMMITS"}
|
||||
1 {WriteLogOutput 0 "LOG ERRORI GITLAB COMMITS"}
|
||||
2 {WriteLogOutput 0 "LOG FULL GITLAB COMMITS"}
|
||||
3 {WriteLogOutput 0 "LOG AMPOLLOSO GITLAB COMMITS"}
|
||||
}
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "RICERCA DA $requestDate | ULTIMI $lastDays GIORNI"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do
|
||||
{
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/repository/commits?per_page=100&since=" + $requestDate
|
||||
try
|
||||
{
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
if($parsedResponse.Count -eq 0 )
|
||||
{
|
||||
$projectWithNoCommits=$projectWithNoCommits+1
|
||||
}
|
||||
else
|
||||
{
|
||||
$projectWithCommits=$projectWithCommits+1
|
||||
foreach($item in $parsedResponse)
|
||||
{
|
||||
if($item.web_url)
|
||||
{
|
||||
WriteLogOutput 1 "Date: $($item.committed_date) - Web Url: $($item.web_url)"
|
||||
$recentCommits=$recentCommits+1
|
||||
}
|
||||
}
|
||||
}
|
||||
$projectsFound=$projectsFound+1
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto non trovato o privo di commits) durante il try/catch (solo se loglevel è = 3)
|
||||
catch
|
||||
{
|
||||
WriteLogOutput 3 ""
|
||||
WriteLogOutput 3 "--------------------"
|
||||
WriteLogOutput 3 "**PROGETTO $projectCount NON ESISTENTE**"
|
||||
}
|
||||
$projectCount=$projectCount+1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while($projectCount -le $projectNumber)
|
||||
|
||||
#percentuale di projectWithCommits sul totale
|
||||
$projectWithCommitsPercentage = [math]::Round(($projectWithCommits/$projectsFound)*100,1)
|
||||
|
||||
#percentuale di projectWithNoCommits sul totale
|
||||
$projectWithNoCommitsPercentage = [math]::Round(($projectWithNoCommits/$projectsFound)*100,1)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||
|
||||
#rilevo time per log fine analisi
|
||||
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#invio a zabbix le metriche rilevate tramite zabbix_sender.exe
|
||||
WriteLogOutput 0 ""
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ProjectsFound -o $projectsFound
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.LastDaysCommits -o $lastDays
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.RecentCommits -o $recentCommits
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ProjectWithCommits -o $projectWithCommits
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ProjectWithNoCommits -o $projectWithNoCommits
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ProjectWithCommitsPercentage -o $projectWithCommitsPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ProjectWithNoCommitsPercentage -o $projectWithNoCommitsPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.CheckCommitsDuration -o $durataScript
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "PROGETTI TOTALI: $projectsFound"
|
||||
WriteLogOutput 0 "COMMITS TOTALI: $recentCommits"
|
||||
WriteLogOutput 0 "PROGETTI CON COMMITS: $projectWithCommits ($projectWithCommitsPercentage%)"
|
||||
WriteLogOutput 0 "PROGETTI SENZA COMMITS: $projectWithNoCommits ($projectWithNoCommitsPercentage%)"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput 0 ""
|
||||
@@ -1,159 +0,0 @@
|
||||
################START SCRIPT################
|
||||
|
||||
#rilevo time per log inizio analisi
|
||||
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
|
||||
#conteggio progetti trovati
|
||||
$existingProjects = 0
|
||||
|
||||
#conteggio mirroring in errore
|
||||
$mirrorErrorsCount = 0
|
||||
|
||||
#conteggio mirroring riusciti
|
||||
$mirrorSuccessCount = 0
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 3
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 1
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
||||
|
||||
#nome file di log
|
||||
$logFile = Join-Path $GitLogFolder "GitlabMirroring.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
{
|
||||
Param ($logType, [string]$logString)
|
||||
if($logType -le $logLevel)
|
||||
{
|
||||
#scrivo su file la stringa
|
||||
Add-content $logFile -value "$logString"
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if($terminalOutput -eq 1){
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $GitLogFolder)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
New-Item $GitLogFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput 0 "--------------------"
|
||||
Switch ($logLevel)
|
||||
{
|
||||
0 {WriteLogOutput 0 "LOG SINTETICO GITLAB MIRRORING"}
|
||||
1 {WriteLogOutput 0 "LOG ERRORI GITLAB MIRRORING"}
|
||||
2 {WriteLogOutput 0 "LOG FULL GITLAB MIRRORING"}
|
||||
3 {WriteLogOutput 0 "LOG AMPOLLOSO GITLAB MIRRORING"}
|
||||
}
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do
|
||||
{
|
||||
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
try
|
||||
{
|
||||
#parsing della risposta api convertita da json
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
foreach($item in $parsedResponse)
|
||||
{
|
||||
#verifico se i mirroring trovati per il progetto corrente hanno status "finished"
|
||||
if($item.update_status.Equals("finished"))
|
||||
{
|
||||
WriteLogOutput 2 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at)"
|
||||
$mirrorSuccessCount=$mirrorSuccessCount+1
|
||||
}
|
||||
#i mirroring che non hanno status "finished" vengono loggati con relativo errore
|
||||
else
|
||||
{
|
||||
WriteLogOutput 1 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at) - Last Attempt: $($item.last_update_started_at)"
|
||||
WriteLogOutput 1 "Error: $($item.last_error)"
|
||||
$mirrorErrorsCount=$mirrorErrorsCount+1
|
||||
}
|
||||
}
|
||||
$existingProjects=$existingProjects+1
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto ID non trovato) durante il try/catch
|
||||
catch
|
||||
{
|
||||
WriteLogOutput 3 ""
|
||||
WriteLogOutput 3 "--------------------"
|
||||
WriteLogOutput 3 "**ERRORE: PROGETTO $projectCount NON ESISTENTE**"
|
||||
}
|
||||
$projectCount=$projectCount+1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while($projectCount -le $projectNumber)
|
||||
|
||||
#somma di mirrorSuccess e mirrorErrors
|
||||
$mirrorCount = $mirrorSuccessCount+$mirrorErrorsCount
|
||||
|
||||
#percentuale di mirrorSuccess sul totale
|
||||
$mirrorSuccessPercentage = [math]::Round(($mirrorSuccessCount/$mirrorCount)*100,1)
|
||||
|
||||
#percentuale di mirrorErrors sul totale
|
||||
$mirrorErrorsPercentage = [math]::Round(($mirrorErrorsCount/$mirrorCount)*100,1)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||
|
||||
#rilevo time per log fine analisi
|
||||
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#invio a zabbix le metriche rilevate tramite zabbix_sender.exe
|
||||
WriteLogOutput 0 ""
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.Projects -o $existingProjects
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.TotalMirror -o $mirrorCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.SuccessMirror -o $mirrorSuccessCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ErrorsMirror -o $mirrorErrorsCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.SuccessMirrorPercent -o $mirrorSuccessPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ErrorsMirrorPercent -o $mirrorErrorsPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.CheckMirrorDuration -o $durataScript
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "PROGETTI ANALIZZATI: $existingProjects"
|
||||
WriteLogOutput 0 "MIRRORING TOTALI: $mirrorCount"
|
||||
WriteLogOutput 0 "MIRRORING RIUSCITI: $mirrorSuccessCount ($mirrorSuccessPercentage%)"
|
||||
WriteLogOutput 0 "MIRRORING FALLITI: $mirrorErrorsCount ($mirrorErrorsPercentage%)"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput 0 ""
|
||||
@@ -1,161 +0,0 @@
|
||||
#DOCS: https://docs.gitlab.com/ee/api/pipelines.html
|
||||
|
||||
#ESEMPIO: https://gitlab.steamware.net/api/v4/projects/12/pipelines
|
||||
|
||||
################START SCRIPT################
|
||||
|
||||
#rilevo time per log inizio analisi
|
||||
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
|
||||
#conteggio progetti trovati
|
||||
$projectsWithPipeline = 0
|
||||
|
||||
#conteggio pipeline in errore
|
||||
$pipelineErrorsCount = 0
|
||||
|
||||
#conteggio pipeline riusciti
|
||||
$pipelineSuccessCount = 0
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 0
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 0
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
||||
|
||||
#nome file di log
|
||||
$logFile = Join-Path $GitLogFolder "GitlabPipeline.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
{
|
||||
Param ($logType, [string]$logString)
|
||||
#scrivo su file la stringa se il tipo di log è > o = al livello di log richieeso
|
||||
if($logType -le $logLevel)
|
||||
{
|
||||
Add-content $logFile -value "$logString"
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if($terminalOutput -eq 1)
|
||||
{
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $GitLogFolder)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
New-Item $GitLogFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput 0 "--------------------"
|
||||
Switch ($logLevel)
|
||||
{
|
||||
0 {WriteLogOutput 0 "LOG SINTETICO GITLAB PIPELINE"}
|
||||
1 {WriteLogOutput 0 "LOG ERRORI GITLAB PIPELINE"}
|
||||
2 {WriteLogOutput 0 "LOG FULL GITLAB PIPELINE"}
|
||||
3 {WriteLogOutput 0 "LOG AMPOLLOSO GITLAB PIPELINE"}
|
||||
}
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do
|
||||
{
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/pipelines/latest"
|
||||
try
|
||||
{
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
foreach($item in $parsedResponse)
|
||||
{
|
||||
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
||||
if($item.status.Equals("success"))
|
||||
{
|
||||
WriteLogOutput 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||
$pipelineSuccessCount=$pipelineSuccessCount+1
|
||||
}
|
||||
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
||||
else
|
||||
{
|
||||
WriteLogOutput 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||
$pipelineErrorsCount=$pipelineErrorsCount+1
|
||||
}
|
||||
}
|
||||
$projectsWithPipeline=$projectsWithPipeline+1
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto non trovato o privo di pipeline) durante il try/catch (solo se loglevel è = 3)
|
||||
catch
|
||||
{
|
||||
WriteLogOutput 3 ""
|
||||
WriteLogOutput 3 "--------------------"
|
||||
WriteLogOutput 3 "**PROGETTO $projectCount NON ESISTENTE O PRIVO DI PIPELINE**"
|
||||
}
|
||||
$projectCount=$projectCount+1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while($projectCount -le $projectNumber)
|
||||
|
||||
#somma di pipelineSuccess e pipelineErrors
|
||||
$pipelineCount = $pipelineSuccessCount+$pipelineErrorsCount
|
||||
|
||||
#percentuale di pipelineSuccess sul totale
|
||||
$pipelineSuccessPercentage = [math]::Round(($pipelineSuccessCount/$pipelineCount)*100,1)
|
||||
|
||||
#percentuale di pipelineErrors sul totale
|
||||
$pipelineErrorsPercentage = [math]::Round(($pipelineErrorsCount/$pipelineCount)*100,1)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||
|
||||
#rilevo time per log fine analisi
|
||||
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#invio a zabbix le metriche rilevate tramite zabbix_sender.exe
|
||||
WriteLogOutput 0 ""
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ProjectsWithPipeline -o $projectsWithPipeline
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.TotalPipeline -o $pipelineCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.SuccessPipeline -o $pipelineSuccessCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ErrorsPipeline -o $pipelineErrorsCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.SuccessPipelinePercent -o $pipelineSuccessPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.ErrorsPipelinePercent -o $pipelineErrorsPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gitlab.CheckPipelineDuration -o $durataScript
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "PROGETTI CON PIPELINE ATTIVE: $projectsWithPipeline"
|
||||
WriteLogOutput 0 "PIPELINE TROVATE: $pipelineCount"
|
||||
WriteLogOutput 0 "PIPELINE RIUSCITE: $pipelineSuccessCount ($pipelineSuccessPercentage%)"
|
||||
WriteLogOutput 0 "PIPELINE FALLITE: $pipelineErrorsCount ($pipelineErrorsPercentage%)"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput 0 ""
|
||||
@@ -1,137 +0,0 @@
|
||||
################START SCRIPT################
|
||||
|
||||
#rilevo time per log inizio analisi
|
||||
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 150
|
||||
|
||||
#conteggio progetti trovati
|
||||
$existingProjects = 0
|
||||
|
||||
#conteggio progetti trovati
|
||||
$protectedProjects = 0
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 3
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 1
|
||||
|
||||
#abilita o disabilita la cancellazione della protezione (1=cancella, 0=toca negot)
|
||||
$deleteProtection = 0
|
||||
|
||||
#specifica quale installazione di gitlab va controllata
|
||||
|
||||
#$gitlabIstance = "https://gitlab-nembro"
|
||||
#$head = @{"PRIVATE-TOKEN"="glpat-TzZkRUoYAdKikgwFXW_E"}
|
||||
$gitlabIstance = "https://gitlab-azzano"
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-gADkrEhkEsvQxGxKez4y"}
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
||||
|
||||
#nome file di log
|
||||
$logFile = Join-Path $GitLogFolder "GitlabProtectedBranches.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
{
|
||||
Param ($logType, [string]$logString)
|
||||
if($logType -le $logLevel)
|
||||
{
|
||||
#scrivo su file la stringa
|
||||
Add-content $logFile -value "$logString"
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if($terminalOutput -eq 1){
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $GitLogFolder)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
New-Item $GitLogFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput 0 "--------------------"
|
||||
Switch ($logLevel)
|
||||
{
|
||||
0 {WriteLogOutput 0 "LOG SINTETICO GITLAB PROTECTED_BRANCHES"}
|
||||
1 {WriteLogOutput 0 "LOG ERRORI GITLAB PROTECTED_BRANCHES"}
|
||||
2 {WriteLogOutput 0 "LOG FULL GITLAB PROTECTED_BRANCHES"}
|
||||
3 {WriteLogOutput 0 "LOG AMPOLLOSO PROTECTED_BRANCHES"}
|
||||
}
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do
|
||||
{
|
||||
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||
$callUrl = $gitlabIstance + ".steamware.net/api/v4/projects/" + $projectCount + "/protected_branches"
|
||||
try
|
||||
{
|
||||
#parsing della risposta api convertita da json
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
foreach($item in $parsedResponse)
|
||||
{
|
||||
WriteLogOutput 1 "Protected Branch Name: $($item.name) - Allow Force Push: $($item.allow_force_push)"
|
||||
$protectedProjects=$protectedProjects+1
|
||||
if($deleteProtection -eq 1)
|
||||
{
|
||||
#nuovo URL x delete
|
||||
$callUrlDelete = $gitlabIstance + ".steamware.net/api/v4/projects/" + $projectCount + "/protected_branches/" + $item.name
|
||||
#chiamo method DELETE
|
||||
Invoke-WebRequest -Method Delete -URI $callUrlDelete -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
}
|
||||
}
|
||||
$existingProjects=$existingProjects+1
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto ID non trovato) durante il try/catch
|
||||
catch
|
||||
{
|
||||
WriteLogOutput 3 ""
|
||||
WriteLogOutput 3 "--------------------"
|
||||
WriteLogOutput 3 "**ERRORE: PROGETTO $projectCount NON ESISTENTE**"
|
||||
}
|
||||
$projectCount=$projectCount+1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||
|
||||
#rilevo time per log fine analisi
|
||||
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "PROGETTI ANALIZZATI: $existingProjects"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "PROGETTI CON BRANCH PROTETTI: $protectedProjects"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput 0 ""
|
||||
@@ -1,138 +0,0 @@
|
||||
################START SCRIPT################
|
||||
|
||||
#rilevo time per log inizio analisi
|
||||
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$gitlabHead = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo replica su gitea2.steamware.net
|
||||
$giteaHead = @{"Authorization"="token 21c3e674ae369eda349d0e1fadaddd526f90419d"}
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 2
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 1
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="C:\Steamware\Logs\Gitlab\"
|
||||
|
||||
#nome file di log
|
||||
$logFile = Join-Path $GitLogFolder "GiteaReposCreation.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
{
|
||||
Param ($logType, [string]$logString)
|
||||
#scrivo su file la stringa se il tipo di log è > o = al livello di log richieeso
|
||||
if($logType -le $logLevel)
|
||||
{
|
||||
Add-content $logFile -value "$logString"
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if($terminalOutput -eq 1)
|
||||
{
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $GitLogFolder)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
New-Item $GitLogFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput 0 "--------------------"
|
||||
Switch ($logLevel)
|
||||
{
|
||||
0 {WriteLogOutput 0 "LOG SINTETICO GITEA"}
|
||||
1 {WriteLogOutput 0 "LOG ERRORI GITEA"}
|
||||
2 {WriteLogOutput 0 "LOG FULL GITEA"}
|
||||
3 {WriteLogOutput 0 "LOG AMPOLLOSO GITEA"}
|
||||
}
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do
|
||||
{
|
||||
$callGitlabUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
||||
try
|
||||
{
|
||||
$gitlabResponse = Invoke-WebRequest -URI $callGitlabUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
$parsedGitlabResponse = $gitlabResponse.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
foreach($gitlabItem in $parsedGitlabResponse)
|
||||
{
|
||||
WriteLogOutput 1 "Gitlab Project Name: $($gitlabItem.name)"
|
||||
$callGiteaUrl = "https://gitea2.steamware.net/api/v1/orgs/Egalware/repos"
|
||||
#dichiaro un body da convertire in JSON con il nome del repo da creare
|
||||
$giteaBody =
|
||||
@{
|
||||
name = $($gitlabItem.name);
|
||||
}
|
||||
# Converting my hash to json format
|
||||
$GiteaJSON = $giteaBody | ConvertTo-Json
|
||||
try
|
||||
{
|
||||
$giteaResponse = Invoke-WebRequest -URI $callGiteaUrl -Method POST -Headers $giteaHead -ContentType "application/json" -Body $GiteaJSON
|
||||
$parsedGiteaResponse = $giteaResponse.Content | ConvertFrom-Json
|
||||
foreach($giteaItem in $parsedGiteaResponse)
|
||||
{
|
||||
WriteLogOutput 1 "Gitea New Project Name: $($giteaItem.name)"
|
||||
WriteLogOutput 1 "Status: $($giteaResponse.StatusDescription)"
|
||||
WriteLogOutput 1 "When: $($giteaItem.created_at)"
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto non trovato) durante il try/catch (solo se loglevel è = 3)
|
||||
catch
|
||||
{
|
||||
WriteLogOutput 3 ""
|
||||
WriteLogOutput 3 "--------------------"
|
||||
WriteLogOutput 3 "**PROGETTO $projectCount NON ESISTENTE**"
|
||||
}
|
||||
$projectCount=$projectCount+1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||
|
||||
#rilevo time per log fine analisi
|
||||
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput 0 ""
|
||||
@@ -1,172 +0,0 @@
|
||||
################START SCRIPT################
|
||||
|
||||
#rilevo time per log inizio analisi
|
||||
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$gitlabHead = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo replica su gitea2.steamware.net
|
||||
#$giteaHead = @{"Authorization"="token 21c3e674ae369eda349d0e1fadaddd526f90419d"}
|
||||
$giteaPass = "ajejebrazorf92!"
|
||||
|
||||
#nome utente che effettua i mirror push
|
||||
$userName = "replica"
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
#numero massimo di progetti
|
||||
$projectNumber = 200
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 3
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 1
|
||||
|
||||
#inizializzo variabili vuote
|
||||
$mirrorId = ""
|
||||
$mirrorUrl = ""
|
||||
$body = ""
|
||||
$jsonBody = ""
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
||||
|
||||
#nome file di log
|
||||
$logFile = Join-Path $GitLogFolder "GitlabMirroringGitea.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
{
|
||||
Param ($logType, [string]$logString)
|
||||
if($logType -le $logLevel)
|
||||
{
|
||||
#scrivo su file la stringa
|
||||
Add-content $logFile -value "$logString"
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if($terminalOutput -eq 1){
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $GitLogFolder)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
New-Item $GitLogFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput 0 "--------------------"
|
||||
Switch ($logLevel)
|
||||
{
|
||||
0 {WriteLogOutput 0 "LOG SINTETICO GITLAB MIRRORING"}
|
||||
1 {WriteLogOutput 0 "LOG ERRORI GITLAB MIRRORING"}
|
||||
2 {WriteLogOutput 0 "LOG FULL GITLAB MIRRORING"}
|
||||
3 {WriteLogOutput 0 "LOG AMPOLLOSO GITLAB MIRRORING"}
|
||||
}
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do
|
||||
{
|
||||
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
try
|
||||
{
|
||||
#parsing della risposta api convertita da json
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
foreach($item in $parsedResponse)
|
||||
{
|
||||
$doExecute = "false"
|
||||
$token = ""
|
||||
$mirrorUrl = ""
|
||||
$trunkedPath = ""
|
||||
#controllo se l'url del mirror contiene gitea
|
||||
if($item.url.Contains("gitea"))
|
||||
{
|
||||
$doExecute = "true"
|
||||
$token = $giteaPass
|
||||
$mirrorDestination = "@gitea2.steamware.net"
|
||||
}
|
||||
#verifico se devo effettuare cancellazione e creazione nuovo mirror
|
||||
if($doExecute -eq "true")
|
||||
{
|
||||
#salvo id mirror e url mirror
|
||||
$mirrorId = $($item.id)
|
||||
$mirrorUrl = $($item.url)
|
||||
WriteLogOutput 1 "ID: $mirrorId - URL: $mirrorUrl"
|
||||
#tronco url fino a ".net"
|
||||
$splitUrl = $mirrorUrl -split '.steamware.net/'
|
||||
$trunkedPath = $splitUrl[1]
|
||||
#compongo URL per cancellare mirror con ID trovato
|
||||
$callUrlDeleteMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors/" + $mirrorId
|
||||
#chiamata api con method delete che cancella mirror con id specificato
|
||||
Invoke-WebRequest -Method Delete -URI $callUrlDeleteMirror -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
#compongo url da chiamare per creazione nuovo mirror
|
||||
$callUrlCreateMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
#creo url del nuovo mirror con username e token relativi a gitlab
|
||||
$newMirror = "https://" + $userName + ":" + $token + $mirrorDestination + "/" + $trunkedPath
|
||||
#creo body da convertire in json
|
||||
$body =
|
||||
@{
|
||||
url = $newMirror
|
||||
enabled = 1
|
||||
}
|
||||
#converto body in json prima di passarlo alla chiamata POST
|
||||
$jsonBody = ConvertTo-Json -InputObject $body
|
||||
#chiamata api POST che crea mirror con url e body specificati
|
||||
$rebuildResponse = Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $gitlabHead -ContentType "application/json" -Body $jsonBody -UseBasicParsing
|
||||
$parsedRebuild = $rebuildResponse.Content | ConvertFrom-Json
|
||||
foreach($item in $parsedRebuild){
|
||||
$mirrorId = $($item.id)
|
||||
$mirrorUrl = $($item.url)
|
||||
}
|
||||
WriteLogOutput 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror ricostruito con successo"
|
||||
}
|
||||
}
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto ID non trovato) durante il try/catch
|
||||
catch
|
||||
{
|
||||
WriteLogOutput 3 ""
|
||||
WriteLogOutput 3 "--------------------"
|
||||
WriteLogOutput 3 "**ERRORE: PROGETTO $projectCount NON ESISTENTE**"
|
||||
}
|
||||
$projectCount=$projectCount+1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||
|
||||
#rilevo time per log fine analisi
|
||||
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput 0 ""
|
||||
@@ -1,164 +0,0 @@
|
||||
################START SCRIPT################
|
||||
|
||||
#rilevo time per log inizio analisi
|
||||
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
#creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
$gitlabHead = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#access token per autenticazione
|
||||
#creato da profilo replica su gitea2.steamware.net
|
||||
#$giteaHead = @{"Authorization"="token 21c3e674ae369eda349d0e1fadaddd526f90419d"}
|
||||
$giteaPass = "ajejebrazorf92!"
|
||||
|
||||
#nome utente gitea che effettua i mirror push
|
||||
$giteaUser = "replica"
|
||||
|
||||
#password replcia gogs
|
||||
$gogsPass = "viaDante16!"
|
||||
|
||||
#nome utente gogs che effettua i mirror push
|
||||
$gogsUser = "replica"
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 140
|
||||
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 1
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 2
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 1
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="C:\Steamware\Logs\Gitlab\"
|
||||
|
||||
#nome file di log
|
||||
$logFile = Join-Path $GitLogFolder "GiteaNewMirrors.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
{
|
||||
Param ($logType, [string]$logString)
|
||||
#scrivo su file la stringa se il tipo di log è > o = al livello di log richieeso
|
||||
if($logType -le $logLevel)
|
||||
{
|
||||
Add-content $logFile -value "$logString"
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if($terminalOutput -eq 1)
|
||||
{
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#funzione che crea mirror con chiamata API
|
||||
Function FreshMirrorCreation
|
||||
{
|
||||
Param ($projectNumber, $user, $auth, $destination, $path)
|
||||
#compongo url da chiamare per creazione nuovo mirror
|
||||
$callUrlCreateMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectNumber + "/remote_mirrors"
|
||||
#creo url del nuovo mirror con username e token relativi a gitlab
|
||||
$newMirror = "https://" + $user + ":" + $auth + $destination + "/" + $path
|
||||
#creo body da convertire in json
|
||||
$body =
|
||||
@{
|
||||
url = $newMirror
|
||||
enabled = 1
|
||||
}
|
||||
#converto body in json prima di passarlo alla chiamata POST
|
||||
$jsonBody = ConvertTo-Json -InputObject $body
|
||||
#chiamata api POST che crea mirror con url e body specificati
|
||||
$rebuildResponse = Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $gitlabHead -ContentType "application/json" -Body $jsonBody -UseBasicParsing
|
||||
$parsedRebuild = $rebuildResponse.Content | ConvertFrom-Json
|
||||
foreach($item in $parsedRebuild){
|
||||
$mirrorId = $($item.id)
|
||||
$mirrorUrl = $($item.url)
|
||||
}
|
||||
WriteLogOutput 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror creato con successo"
|
||||
}
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $GitLogFolder)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
New-Item $GitLogFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput 0 "--------------------"
|
||||
Switch ($logLevel)
|
||||
{
|
||||
0 {WriteLogOutput 0 "LOG SINTETICO NUOVI MIRROR"}
|
||||
1 {WriteLogOutput 0 "LOG ERRORI NUOVI MIRROR"}
|
||||
2 {WriteLogOutput 0 "LOG FULL NUOVI MIRROR"}
|
||||
3 {WriteLogOutput 0 "LOG AMPOLLOSO NUOVI MIRROR"}
|
||||
}
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do
|
||||
{
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
try
|
||||
{
|
||||
$gitlabResponse = Invoke-WebRequest -URI $callUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
#$parsedGitlabResponse = $gitlabResponse.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
if($gitlabResponse.Content -eq "[]")
|
||||
{
|
||||
$callUrl2 = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
||||
$gitlabResponse2 = Invoke-WebRequest -URI $callUrl2 -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse2 = $gitlabResponse2.Content | ConvertFrom-Json
|
||||
$repoPath = $($parsedResponse2.path)
|
||||
$path = "Egalware/" + $repoPath + ".git"
|
||||
try
|
||||
{
|
||||
FreshMirrorCreation $projectCount $giteaUser $giteaPass "@gitea2.steamware.net" $path
|
||||
FreshMirrorCreation $projectCount $gogsUser $gogsPass "@gogs.steamware.net" $path
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto non trovato) durante il try/catch (solo se loglevel è = 3)
|
||||
catch
|
||||
{
|
||||
WriteLogOutput 3 ""
|
||||
WriteLogOutput 3 "--------------------"
|
||||
WriteLogOutput 3 "**PROGETTO $projectCount NON ESISTENTE**"
|
||||
}
|
||||
$projectCount=$projectCount+1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||
|
||||
#rilevo time per log fine analisi
|
||||
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput 0 ""
|
||||
@@ -1,181 +0,0 @@
|
||||
################START SCRIPT################
|
||||
|
||||
#rilevo time per log inizio analisi
|
||||
$startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
|
||||
#access token per autenticazione creazione 04 gennaio 2024, scadenza 31 dicembre 2024
|
||||
#creato da profilo marco.locatelli@egalware.com su gitlab.steamware.net
|
||||
$head = @{"PRIVATE-TOKEN"="glpat-VjT_SAsBk3s-yWE1LDUF"}
|
||||
|
||||
#nome utente che effettua i mirror push
|
||||
$userName = "replica"
|
||||
|
||||
#token autenticazione utente replica azzano creato a gennaio 2024, scadenza 31 dicembere 2024
|
||||
#$tokenAzzano = "glpat-gADkrEhkEsvQxGxKez4y" <<< TOKEN 2023 (IN DISUSO)
|
||||
$tokenAzzano = "glpat-UHLqByZZr8tns6jwc4_-"
|
||||
|
||||
#token autenticazione utente replica nembro creato a gennaio 2024, scadenza 31 dicembere 2024
|
||||
#$tokenNembro = "glpat-TzZkRUoYAdKikgwFXW_E" <<< TOKEN 2023 (IN DISUSO)
|
||||
$tokenNembro = "glpat-puycZnyztFioe5tmkaso"
|
||||
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
|
||||
#numero massimo di progetti
|
||||
$projectNumber = 200
|
||||
|
||||
#livello di log: 0=log sintetico, 1=log errori, 2=log full, 3=log ampolloso
|
||||
$logLevel = 3
|
||||
|
||||
#output a terminale: 0=disattivo, 1=abilitato
|
||||
$terminalOutput = 1
|
||||
|
||||
#inizializzo variabili vuote
|
||||
$mirrorId = ""
|
||||
$mirrorUrl = ""
|
||||
$body = ""
|
||||
$jsonBody = ""
|
||||
|
||||
#cartella file di log
|
||||
$GitLogFolder="c:\Steamware\Logs\Gitlab\"
|
||||
|
||||
#nome file di log
|
||||
$logFile = Join-Path $GitLogFolder "GitlabRebuildMirroring.log"
|
||||
|
||||
#dichiaro funzione per scrittura output
|
||||
Function WriteLogOutput
|
||||
{
|
||||
Param ($logType, [string]$logString)
|
||||
if($logType -le $logLevel)
|
||||
{
|
||||
#scrivo su file la stringa
|
||||
Add-content $logFile -value "$logString"
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if($terminalOutput -eq 1){
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $GitLogFolder)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
New-Item $GitLogFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput 0 "--------------------"
|
||||
Switch ($logLevel)
|
||||
{
|
||||
0 {WriteLogOutput 0 "LOG SINTETICO GITLAB MIRRORING"}
|
||||
1 {WriteLogOutput 0 "LOG ERRORI GITLAB MIRRORING"}
|
||||
2 {WriteLogOutput 0 "LOG FULL GITLAB MIRRORING"}
|
||||
3 {WriteLogOutput 0 "LOG AMPOLLOSO GITLAB MIRRORING"}
|
||||
}
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Percorso log: $GitLogFolder"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do
|
||||
{
|
||||
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
try
|
||||
{
|
||||
#parsing della risposta api convertita da json
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto
|
||||
WriteLogOutput 1 ""
|
||||
WriteLogOutput 1 "--------------------"
|
||||
WriteLogOutput 1 "**PROGETTO $projectCount**"
|
||||
foreach($item in $parsedResponse)
|
||||
{
|
||||
$doExecute = "false"
|
||||
$token = ""
|
||||
$mirrorUrl = ""
|
||||
$mirrorId = ""
|
||||
$trunkedPath = ""
|
||||
#controllo se l'url del mirror contiene azzano
|
||||
if($item.url.Contains("azzano"))
|
||||
{
|
||||
$doExecute = "true"
|
||||
$token = $tokenAzzano
|
||||
$mirrorDestination = "@gitlab-azzano.steamware.net"
|
||||
}
|
||||
#controllo se l'url del mirror contiene nembro
|
||||
elseif($item.url.Contains("nembro"))
|
||||
{
|
||||
$doExecute = "true"
|
||||
$token = $tokenNembro
|
||||
$mirrorDestination = "@gitlab-nembro.steamware.net"
|
||||
}
|
||||
#verifico se devo effettuare cancellazione e creazione nuovo mirror
|
||||
if($doExecute -eq "true")
|
||||
{
|
||||
#salvo id mirror e url mirror
|
||||
$mirrorId = $($item.id)
|
||||
$mirrorUrl = $($item.url)
|
||||
#tronco url fino a ".net/"
|
||||
$splitUrl = $mirrorUrl -split '.steamware.net/'
|
||||
$trunkedPath = $splitUrl[1]
|
||||
#compongo URL per cancellare mirror con ID trovato
|
||||
$callUrlDeleteMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors/" + $mirrorId
|
||||
#chiamata api con method delete che cancella mirror con id specificato
|
||||
Invoke-WebRequest -Method Delete -URI $callUrlDeleteMirror -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
#compongo url da chiamare per creazione nuovo mirror
|
||||
$callUrlCreateMirror = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
#creo url del nuovo mirror con username e token relativi a gitlab
|
||||
$newMirror = "https://" + $userName + ":" + $token + $mirrorDestination + "/" + $trunkedPath
|
||||
#creo body da convertire in json
|
||||
$body =
|
||||
@{
|
||||
url = $newMirror
|
||||
enabled = 1
|
||||
}
|
||||
#converto body in json prima di passarlo alla chiamata POST
|
||||
$jsonBody = ConvertTo-Json -InputObject $body
|
||||
#chiamata api POST che crea mirror con url e body specificati
|
||||
$rebuildResponse = Invoke-WebRequest -Method Post -URI $callUrlCreateMirror -Headers $head -ContentType "application/json" -Body $jsonBody -UseBasicParsing
|
||||
$parsedRebuild = $rebuildResponse.Content | ConvertFrom-Json
|
||||
foreach($item in $parsedRebuild){
|
||||
$mirrorId = $($item.id)
|
||||
$mirrorUrl = $($item.url)
|
||||
}
|
||||
WriteLogOutput 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror ricostruito con successo"
|
||||
}
|
||||
}
|
||||
}
|
||||
#scrivo se trovo un errore (in particolare progetto ID non trovato) durante il try/catch
|
||||
catch
|
||||
{
|
||||
WriteLogOutput 3 ""
|
||||
WriteLogOutput 3 "--------------------"
|
||||
WriteLogOutput 3 "**ERRORE: PROGETTO $projectCount NON ESISTENTE**"
|
||||
}
|
||||
$projectCount=$projectCount+1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||
|
||||
#rilevo time per log fine analisi
|
||||
$endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput 0 ""
|
||||
WriteLogOutput 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput 0 ""
|
||||
Reference in New Issue
Block a user