Compare commits
57 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 674ce894b5 | |||
| 23137a0fed | |||
| dfe2f63787 | |||
| bc9d2048a9 | |||
| 8bcbb1fd04 | |||
| f11d2ac73a | |||
| 1e9b24a3df | |||
| 370530efd5 | |||
| afc5aa990d | |||
| bb5bc6d9fb | |||
| 9c1585a22a | |||
| 04de457e27 | |||
| 9b8a7c3b4e | |||
| c6de62fe2c | |||
| 5170c62ad4 | |||
| d4d8fdc80c | |||
| 9d479d67ae | |||
| 130e7b6107 | |||
| 6233c981ae | |||
| 9c59909908 | |||
| c428c02edc | |||
| bf3a6972fe | |||
| 35cc6630cd | |||
| a65dcfac89 | |||
| 400114d664 | |||
| f802a95b0d | |||
| 4e73d7c80f | |||
| ac4288c7d0 | |||
| cb7aa64781 | |||
| fc3ec2dc62 | |||
| 190f816973 | |||
| bf3500e3d4 | |||
| 7e08a303e1 | |||
| 99a83665dc | |||
| 200fb08bf9 | |||
| db43d8b2cd | |||
| 21243a3e25 | |||
| 40c588c93a | |||
| 657be39f4e | |||
| bcf20b5cff | |||
| 86280a6f63 | |||
| ad98d1faff | |||
| dada78a521 | |||
| b7c3b05833 | |||
| 6754ac45f2 | |||
| 48be4fe6df | |||
| b3c84c1c5f | |||
| 0c7820d65b | |||
| f0cbd66cd9 | |||
| 784cc17af4 | |||
| 6cb9452018 | |||
| 75a450b8b3 | |||
| 0c705a2ff0 | |||
| 56a1f349ab | |||
| 0073b9f36d | |||
| 0d3068339a | |||
| 0c864d3e31 |
@@ -1,32 +1,35 @@
|
||||
######### FILE DI CONFIGURAZIONE PER SCRIPT API GIT #########
|
||||
|
||||
#### CONF GITLAB (ufficio, azzano, nembro) ####
|
||||
#### CONF LOG ####
|
||||
#cartella file di log
|
||||
$logFolder = "c:\Steamware\Logs\Gitlab\"
|
||||
#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
|
||||
|
||||
#### CONF GITLAB ####
|
||||
#access token per autenticazione gitlab da profilo marco.locatelli@egalware.com con scadenza 31 dicembre 2024
|
||||
$gitlabHead = @{"PRIVATE-TOKEN" = "glpat-VjT_SAsBk3s-yWE1LDUF" }
|
||||
#$gitlabHead2024 = @{"PRIVATE-TOKEN" = "glpat-VjT_SAsBk3s-yWE1LDUF" }
|
||||
#access token per autenticazione gitlab da profilo marco.locatelli@egalware.com con scadenza 31 dicembre 2025
|
||||
#$tokenGitlab = "glpat-AGzz46yrxj7rTjzSVYCH"
|
||||
#access token per autenticazione gitlab da profilo marco.locatelli@egalware.com con scadenza 31 dicembre 2026
|
||||
$tokenGitlab = "glpat-CnHov-GaFjozv34MsnRx8m86MQp1OjgH.01.0w1or5g5w"
|
||||
$gitlabHead = @{"PRIVATE-TOKEN" = "$($tokenGitlab)" }
|
||||
#nome utente che effettua i mirror push
|
||||
$userName = "replica"
|
||||
#token autenticazione utente replica azzano creato a gennaio 2024, scadenza 31 dicembere 2024
|
||||
$tokenAzzano = "glpat-UHLqByZZr8tns6jwc4_-"
|
||||
#access token per autenticazione gitlab da profilo marco.locatelli@egalware.com con scadenza 31 dicembre 2024
|
||||
$azzanoHead = @{"PRIVATE-TOKEN" = "$($tokenAzzano)" }
|
||||
#destinazione mirror per azzano
|
||||
$destinationAzzano = "gitlab-azzano.steamware.net"
|
||||
#token autenticazione utente replica nembro creato a gennaio 2024, scadenza 31 dicembere 2024
|
||||
$tokenNembro = "glpat-puycZnyztFioe5tmkaso"
|
||||
#access token per autenticazione gitlab-nembro
|
||||
$nembroHead = @{"PRIVATE-TOKEN" = "$($tokenNembro)" }
|
||||
#destinazione mirror per nembro
|
||||
$destinationNembro = "gitlab-nembro.steamware.net"
|
||||
|
||||
#### CONF gitea.steamware.net ####
|
||||
#destinazione mirror per gitea
|
||||
$giteaDestination = "gitea.steamware.net"
|
||||
$giteaSteamw = "gitea.steamware.net"
|
||||
#nome utente gitea che effettua i mirror push
|
||||
$giteaUser = "replica"
|
||||
$giteaSteamwUser = "replica"
|
||||
#autenticazione replica gitea
|
||||
$giteaPass = "ajejebrazorf92!"
|
||||
$giteaSteamwPass = "viadante16"
|
||||
#token autenticazione utente replica gitea
|
||||
$tokenGiteaSteamw = "e6e6944da93bbaf230e4223012035f2cd55d27a6"
|
||||
#access token per autenticazione gitea da profilo replica
|
||||
$giteaHead = @{"Authorization" = "token 3619817f299bb3d92c8a8f86d5fddbe877b60ffa" }
|
||||
$giteaSteamwHead = @{"Authorization" = "token $($tokenGiteaSteamw)" }
|
||||
|
||||
#### CONF gogs.steamware.net ####
|
||||
#destinazione mirror per gogs
|
||||
@@ -35,13 +38,31 @@ $gogsDestination = "gogs.steamware.net"
|
||||
$gogsUser = "replica"
|
||||
#password replica gogs
|
||||
$gogsPass = "viaDante16!"
|
||||
#token autenticazione utente replica gogs
|
||||
$tokenGogs = "bb6d8e9a4d76445e33b12e1664140043fdaa8d87"
|
||||
#access token per autenticazione gogs da profilo replica
|
||||
$gogsHead = @{"Authorization" = "token bb6d8e9a4d76445e33b12e1664140043fdaa8d87" }
|
||||
$gogsHead = @{"Authorization" = "token $($tokenGogs)" }
|
||||
|
||||
#### CONF LOG ####
|
||||
#cartella file di log
|
||||
$logFolder = "c:\Steamware\Logs\Gitlab\"
|
||||
#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
|
||||
#### CONF gitea-azzano.steamware.net ####
|
||||
#destinazione mirror per gitea
|
||||
$giteaAzzano = "gitea-azzano.steamware.net"
|
||||
#nome utente gitea che effettua i mirror push
|
||||
$giteaAzzanoUser = "replica"
|
||||
#autenticazione replica gitea
|
||||
$giteaAzzanoPass = "kj5uQz9QpVdrwXj"
|
||||
#token autenticazione utente replica gitea
|
||||
$tokenGiteaAzzano = "9e9958e9d46d78cc098b3ba7341e750f2d2fd8a3"
|
||||
#access token per autenticazione gitea da profilo replica
|
||||
$giteaAzzanoHead = @{"Authorization" = "token $($tokenGiteaAzzano)" }
|
||||
|
||||
#### CONF gitea-nembro.steamware.net ####
|
||||
#destinazione mirror per gitea
|
||||
$giteaNembro = "gitea-nembro.steamware.net"
|
||||
#nome utente gitea che effettua i mirror push
|
||||
$giteaNembroUser = "replica"
|
||||
#autenticazione replica gitea
|
||||
$giteaNembroPass = "IXQkDchDwMah8E"
|
||||
#token autenticazione utente replica gitea
|
||||
$tokenGiteaNembro = "c58a2fdf6493bb690e8c39b393e06a121f8a6761"
|
||||
#access token per autenticazione gitea da profilo replica
|
||||
$giteaNembroHead = @{"Authorization" = "token $($tokenGiteaNembro)" }
|
||||
@@ -15,13 +15,40 @@ Function WriteLogOutput {
|
||||
}
|
||||
}
|
||||
|
||||
#verifica esistenza folder di log
|
||||
Function CheckLogFolder {
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
}
|
||||
|
||||
#rotazione file .log in .old
|
||||
Function RotateOldLog {
|
||||
$logPath = Join-Path $logFolder $logFile
|
||||
$oldLogPath = Join-Path $logFolder $oldLogFile
|
||||
#se file .old esiste sposto contenuto di attuale .log in coda a attuale .old e cancello attuale .log
|
||||
if (Test-Path $logPath){
|
||||
if (Test-Path $oldLogPath) {
|
||||
$from = Get-Content -Path $logPath
|
||||
Add-Content -Path $oldLogPath -Value $from
|
||||
Remove-Item -Path $logPath
|
||||
}
|
||||
#se file .old non esiste rinomino attuale file.log in file.old
|
||||
else {
|
||||
Get-ChildItem $logPath | Rename-Item -NewName { $_.Name -replace '.log','.old' }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#creazione nuovo mirror
|
||||
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
|
||||
$newMirror = "http://" + $user + ":" + $auth + "@" + $destination + "/" + $path
|
||||
#creo body da convertire in json
|
||||
$body =
|
||||
@{
|
||||
@@ -41,4 +68,15 @@ Function FreshMirrorCreation {
|
||||
}
|
||||
#scrivo ID e URL nuovo mirror
|
||||
WriteLogOutput $logFile 1 "NEW ID: $mirrorId - URL: $mirrorUrl - Mirror creato con successo"
|
||||
}
|
||||
|
||||
Function TryParse-Json {
|
||||
param([string]$InputString)
|
||||
|
||||
try {
|
||||
return $InputString | ConvertFrom-Json -ErrorAction Stop
|
||||
}
|
||||
catch {
|
||||
return $null
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
###Gitlab: controllo lo stato dei JobArtifacts dei singoli progetti###
|
||||
|
||||
#Questo script passa in rassegna tutti i progetti esistenti sul gitlab aziendale e per ognuno verifica lo stato dei JobArtifacts, poi invia a zabbix le statistiche.
|
||||
#Tendenzialmente ogni progetto dovrebbe avere 4 JobArtifacts abilitati: nembro, azzano, gitea, gogs
|
||||
|
||||
#importo file contenente configurazioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
||||
#importo file contenente funzioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsFunctions.ps1
|
||||
|
||||
#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 = 1
|
||||
#conteggio progetti trovati
|
||||
$existingProjects = 0
|
||||
#conteggio job trovati
|
||||
$jobFound = 0
|
||||
#nome file di log
|
||||
$logFile = "GitlabJobArtifacts.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabJobArtifacts.old"
|
||||
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
Switch ($logLevel) {
|
||||
0 { WriteLogOutput $logFile 0 "LOG SINTETICO GITLAB Job Artifacts" }
|
||||
1 { WriteLogOutput $logFile 0 "LOG ERRORI GITLAB Job Artifacts" }
|
||||
2 { WriteLogOutput $logFile 0 "LOG FULL GITLAB Job Artifacts" }
|
||||
3 { WriteLogOutput $logFile 0 "LOG AMPOLLOSO GITLAB Job Artifacts" }
|
||||
}
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 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 JobArtifacts
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/jobs"
|
||||
WriteLogOutput $logFile 1 ""
|
||||
WriteLogOutput $logFile 1 "--------------------"
|
||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||
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 nel terminale e su file
|
||||
$deleteAllUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/artifacts"
|
||||
$deleteAllResponse = Invoke-WebRequest -URI $deleteAllUrl -Method DELETE -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
$parsedDeleteAllResponse = $deleteAllResponse.Content | ConvertFrom-Json
|
||||
|
||||
#foreach ($item in $parsedResponse) {
|
||||
# WriteLogOutput $logFile 1 "ID: $($item.id) | Creato il: $($item.created_at) | URL: $($item.web_url)"
|
||||
# $projectJobFound++
|
||||
# $jobFound++
|
||||
#compongo chiamata api per erase job
|
||||
#$eraseUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/jobs/" + $item.id + "/erase"
|
||||
#$EraseResponse = Invoke-WebRequest -URI $eraseUrl -Method DELETE -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
#$parsedEraseResponse = $EraseResponse.Content | ConvertFrom-Json
|
||||
#compongo chiamata api per delete all job artifacts in a project
|
||||
# $deleteAllUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/artifacts"
|
||||
# $deleteAllResponse = Invoke-WebRequest -URI $deleteAllUrl -Method DELETE -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
# $parsedDeleteAllResponse = $deleteAllResponse.Content | ConvertFrom-Json
|
||||
#}
|
||||
#WriteLogOutput $logFile 1 "Job trovati per il progetto $($projectCount): $($projectJobFound)"
|
||||
#$projectJobFound = 0
|
||||
$existingProjects++
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
$parsedError = $_ | ConvertFrom-Json
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount++
|
||||
}
|
||||
#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")
|
||||
|
||||
#invio a zabbix le metriche rilevate tramite zabbix_sender.exe
|
||||
#WriteLogOutput $logFile 0 ""
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.Projects -o $existingProjects
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.TotalJobArtifacts -o $JobArtifactsCount
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessJobArtifacts -o $JobArtifactsSuccessCount
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsJobArtifacts -o $JobArtifactsErrorsCount
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessJobArtifactsPercent -o $JobArtifactsSuccessPercentage
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsJobArtifactsPercent -o $JobArtifactsErrorsPercentage
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.CheckJobArtifactsDuration -o $durataScript
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "PROGETTI ANALIZZATI: $existingProjects"
|
||||
WriteLogOutput $logFile 0 "Job Artifacts TOTALI: $jobFound"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
@@ -13,9 +13,9 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
$endProj = 250
|
||||
#conteggio progetti trovati
|
||||
$projectsFound = 0
|
||||
#conteggio progetti con commit negli ultimi giorni
|
||||
@@ -30,13 +30,14 @@ $lastDays = 7
|
||||
$requestDate = (Get-Date).AddDays(-$lastDays).toString("yyyy-MM-dd")
|
||||
#nome file di log
|
||||
$logFile = "GitlabCommits.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabCommits.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -53,8 +54,8 @@ WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "RICERCA DA $requestDate | ULTIMI $lastDays GIORNI"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da 1 a N projectNumber
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++) {
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/repository/commits?per_page=100&since=" + $requestDate
|
||||
try {
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
@@ -64,18 +65,18 @@ do {
|
||||
WriteLogOutput $logFile 1 "--------------------"
|
||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||
if ($parsedResponse.Count -eq 0 ) {
|
||||
$projectWithNoCommits = $projectWithNoCommits + 1
|
||||
$projectWithNoCommits++
|
||||
}
|
||||
else {
|
||||
$projectWithCommits = $projectWithCommits + 1
|
||||
$projectWithCommits++
|
||||
foreach ($item in $parsedResponse) {
|
||||
if ($item.web_url) {
|
||||
WriteLogOutput $logFile 1 "Date: $($item.committed_date) - Web Url: $($item.web_url)"
|
||||
$recentCommits = $recentCommits + 1
|
||||
$recentCommits++
|
||||
}
|
||||
}
|
||||
}
|
||||
$projectsFound = $projectsFound + 1
|
||||
$projectsFound++
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
@@ -85,10 +86,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
#percentuale di projectWithCommits sul totale
|
||||
$projectWithCommitsPercentage = [math]::Round(($projectWithCommits / $projectsFound) * 100, 1)
|
||||
@@ -105,14 +104,14 @@ $endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#invio a zabbix le metriche rilevate tramite zabbix_sender.exe
|
||||
WriteLogOutput $logFile 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
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ProjectsFound -o $projectsFound
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.LastDaysCommits -o $lastDays
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.RecentCommits -o $recentCommits
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ProjectWithCommits -o $projectWithCommits
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ProjectWithNoCommits -o $projectWithNoCommits
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ProjectWithCommitsPercentage -o $projectWithCommitsPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ProjectWithNoCommitsPercentage -o $projectWithNoCommitsPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.CheckCommitsDuration -o $durataScript
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput $logFile 0 ""
|
||||
|
||||
@@ -13,9 +13,9 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
$endProj = 300
|
||||
#conteggio progetti trovati
|
||||
$existingProjects = 0
|
||||
#conteggio mirroring in errore
|
||||
@@ -23,14 +23,15 @@ $mirrorErrorsCount = 0
|
||||
#conteggio mirroring riusciti
|
||||
$mirrorSuccessCount = 0
|
||||
#nome file di log
|
||||
$logFile = "GitlabMirroring.log"
|
||||
$logFile = "GitlabCheckMirrors.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabCheckMirrors.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -45,8 +46,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
WriteLogOutput $logFile 1 ""
|
||||
@@ -58,29 +59,26 @@ do {
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
foreach ($item in $parsedResponse) {
|
||||
#verifico se i mirroring trovati per il progetto corrente hanno status "finished"
|
||||
#verifico se i mirroring trovati per il progetto corrente hanno status "finished" e scrivo log
|
||||
if ($item.update_status.Equals("finished")) {
|
||||
WriteLogOutput $logFile 2 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at)"
|
||||
$mirrorSuccessCount = $mirrorSuccessCount + 1
|
||||
$mirrorSuccessCount++
|
||||
}
|
||||
#i mirroring che non hanno status "finished" vengono loggati con relativo errore
|
||||
#per i mirroring che non hanno status "finished" scrivo log con relativo errore
|
||||
else {
|
||||
WriteLogOutput $logFile 1 "Mirror: $($item.url) - Status: $($item.update_status) - Last Success: $($item.last_successful_update_at) - Last Attempt: $($item.last_update_started_at)"
|
||||
WriteLogOutput $logFile 1 "Error: $($item.last_error)"
|
||||
$mirrorErrorsCount = $mirrorErrorsCount + 1
|
||||
$mirrorErrorsCount++
|
||||
}
|
||||
}
|
||||
$existingProjects = $existingProjects + 1
|
||||
$existingProjects++
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
$parsedError = $_ | ConvertFrom-Json
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
#somma di mirrorSuccess e mirrorErrors
|
||||
$mirrorCount = $mirrorSuccessCount + $mirrorErrorsCount
|
||||
@@ -100,13 +98,13 @@ $endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#invio a zabbix le metriche rilevate tramite zabbix_sender.exe
|
||||
WriteLogOutput $logFile 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
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.Projects -o $existingProjects
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.TotalMirror -o $mirrorCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessMirror -o $mirrorSuccessCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsMirror -o $mirrorErrorsCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessMirrorPercent -o $mirrorSuccessPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsMirrorPercent -o $mirrorErrorsPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.CheckMirrorDuration -o $durataScript
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput $logFile 0 ""
|
||||
|
||||
@@ -13,24 +13,21 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 170
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 250
|
||||
$endProj = 300
|
||||
#contatore mirror creati
|
||||
$createdMirrors = 0
|
||||
#nome file di log
|
||||
$logFile = "GiteaNewMirrors.log"
|
||||
$logFile = "NewMirrorsCreation.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "NewMirrorsCreation.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#chiedo all'utente il project ID su cui lavorare
|
||||
#$projectCount = Read-Host -Prompt 'Project ID per eseguire lo script: '
|
||||
|
||||
#chiedo all'utente quante volte devo ciclare sui project ID
|
||||
#$projectNumber = Read-Host -Prompt 'Contatore dei Project ID su cui lavorare: '
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -45,8 +42,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da 1 a N projectNumber
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++) {
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
try {
|
||||
$gitlabResponse = Invoke-WebRequest -URI $callUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
@@ -63,24 +60,28 @@ do {
|
||||
#compongo path con struttura Egalware/NomeProgetto.git
|
||||
$simplePath = "Egalware/" + $($parsedNameResponse.path) + ".git"
|
||||
#se la risposta non contiene "gitea" procedo a creare mirror relativo
|
||||
if ($gitlabResponse.Content -inotmatch "gitea") {
|
||||
#chiamo funzione per creare mirror verso gitea
|
||||
FreshMirrorCreation $projectCount $giteaUser $giteaPass $giteaDestination $simplePath
|
||||
if ($gitlabResponse.Content -inotmatch "gitea.steamware.net") {
|
||||
#chiamo funzione per creare mirror verso gitea-steamware
|
||||
FreshMirrorCreation $projectCount $giteaSteamwUser $giteaSteamwPass $giteaSteamw $simplePath
|
||||
$createdMirrors++
|
||||
}
|
||||
#se la risposta non contiene "gogs" procedo a creare mirror relativo
|
||||
if ($gitlabResponse.Content -inotmatch "gogs") {
|
||||
if ($gitlabResponse.Content -inotmatch "gogs.steamware.net") {
|
||||
#chiamo funzione per creare mirror verso gogs
|
||||
FreshMirrorCreation $projectCount $gogsUser $gogsPass $gogsDestination $simplePath
|
||||
$createdMirrors++
|
||||
}
|
||||
#se la risposta non contiene "gitlab-nembro" procedo a creare mirror relativo
|
||||
if ($gitlabResponse.Content -inotmatch "gitlab-nembro") {
|
||||
#chiamo funzione per creare mirror verso gitlab-nembro
|
||||
FreshMirrorCreation $projectCount $userName $tokenNembro $destinationNembro $simplePath
|
||||
#se la risposta non contiene "gitea-nembro" procedo a creare mirror relativo
|
||||
if ($gitlabResponse.Content -inotmatch "gitea-nembro") {
|
||||
#chiamo funzione per creare mirror verso gitea-nembro
|
||||
FreshMirrorCreation $projectCount $giteaNembroUser $giteaNembroPass $giteaNembro $simplePath
|
||||
$createdMirrors++
|
||||
}
|
||||
#se la risposta non contiene "gitlab-azzano" procedo a creare mirror relativo
|
||||
if ($gitlabResponse.Content -inotmatch "gitlab-azzano") {
|
||||
#chiamo funzione per creare mirror verso gitlab-azzano
|
||||
FreshMirrorCreation $projectCount $userName $tokenAzzano $destinationAzzano $simplePath
|
||||
#se la risposta non contiene "gitea-azzano" procedo a creare mirror relativo
|
||||
if ($gitlabResponse.Content -inotmatch "gitea-azzano") {
|
||||
#chiamo funzione per creare mirror verso gitea-azzano
|
||||
FreshMirrorCreation $projectCount $giteaAzzanoUser $giteaAzzanoPass $giteaAzzano $simplePath
|
||||
$createdMirrors++
|
||||
}
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
@@ -91,10 +92,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
@@ -105,6 +104,8 @@ $endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Nuovi mirror creati: $createdMirrors"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
###Gitlab: delete mirrors###
|
||||
|
||||
#Questo script passa in rassegna tutti i progetti esistenti sul gitlab aziendale e per ognuno può cancellare i mirror desiderati
|
||||
|
||||
#IMPORTANTE: SCRIPT PERICOLOSO. TOGLIERE COMMENTO A RIGA 62 PER CANCELLARE.
|
||||
|
||||
#importo file contenente configurazioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
||||
#importo file contenente funzioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsFunctions.ps1
|
||||
|
||||
#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
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$endProj = 300
|
||||
#contatore numero mirror cancellati
|
||||
$deletedMirrors = 0
|
||||
#nome file di log
|
||||
$logFile = "MirrorsDelete.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "MirrorsDelete.old"
|
||||
#stringa da cercare per cancellare il mirror
|
||||
$mirrorToDelete = "gitlab-azzano"
|
||||
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
Switch ($logLevel) {
|
||||
0 { WriteLogOutput $logFile 0 "LOG SINTETICO DELETE MIRROR" }
|
||||
1 { WriteLogOutput $logFile 0 "LOG ERRORI DELETE MIRROR" }
|
||||
2 { WriteLogOutput $logFile 0 "LOG FULL DELETE MIRROR" }
|
||||
3 { WriteLogOutput $logFile 0 "LOG AMPOLLOSO DELETE MIRROR" }
|
||||
}
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale for che cicla da 1 a N projectNumber
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++) {
|
||||
$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 $logFile 1 ""
|
||||
WriteLogOutput $logFile 1 "--------------------"
|
||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||
foreach ($gitResponse IN $parsedGitlabResponse){
|
||||
if ($gitResponse -match $mirrorToDelete) {
|
||||
#Cancello mirror verso gitlab-nembro
|
||||
$deleteUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors/" + $gitResponse.id
|
||||
#Invoke-WebRequest -URI $deleteUrl -Method DELETE -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
WriteLogOutput $logFile 1 "Eliminato mirror: $gitResponse"
|
||||
$deletedMirrors++
|
||||
}
|
||||
}
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
$parsedError = $_ | ConvertFrom-Json
|
||||
WriteLogOutput $logFile 3 ""
|
||||
WriteLogOutput $logFile 3 "--------------------"
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
}
|
||||
#fine ciclo principale
|
||||
|
||||
# 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 $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Numero mirror cancellati: $deletedMirrors"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
@@ -0,0 +1,95 @@
|
||||
###Gitlab: forzo push verso i mirror dei singoli progetti###
|
||||
|
||||
#Questo script passa in rassegna tutti i progetti esistenti sul gitlab aziendale e per ognuno verifica lo stato dei mirror, poi forza il push di tutti.
|
||||
|
||||
#importo file contenente configurazioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
||||
#importo file contenente funzioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsFunctions.ps1
|
||||
|
||||
#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
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$endProj = 300
|
||||
#conteggio progetti trovati
|
||||
$existingProjects = 0
|
||||
#contatore mirror trovati
|
||||
$mirrorCount = 0
|
||||
#nome file di log
|
||||
$logFile = "GitlabForcePushMirror.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabForcePushMirror.old"
|
||||
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
Switch ($logLevel) {
|
||||
0 { WriteLogOutput $logFile 0 "LOG SINTETICO GITLAB FORCE PUSH MIRROR" }
|
||||
1 { WriteLogOutput $logFile 0 "LOG ERRORI GITLAB FORCE PUSH MIRROR" }
|
||||
2 { WriteLogOutput $logFile 0 "LOG FULL GITLAB FORCE PUSH MIRROR" }
|
||||
3 { WriteLogOutput $logFile 0 "LOG AMPOLLOSO GITLAB FORCE PUSH MIRROR" }
|
||||
}
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale for che cicla da 1 a N projectNumber
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++) {
|
||||
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
WriteLogOutput $logFile 1 ""
|
||||
WriteLogOutput $logFile 1 "--------------------"
|
||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||
try {
|
||||
#parsing della risposta api convertita da json
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
#per ogni mirror forzo il push
|
||||
foreach ($item in $parsedResponse) {
|
||||
#compongo URL per chiamata POST per forzare PUSH
|
||||
$callUrlForcePush = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors/" + $item.id + "/sync"
|
||||
$PushResponse = Invoke-WebRequest -URI $callUrlForcePush -Method POST -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
if ($PushResponse.StatusCode -eq 204){
|
||||
WriteLogOutput $logFile 0 $("Mirror Push: Success - " + $item.url)
|
||||
}
|
||||
else {
|
||||
WriteLogOutput $logFile 0 $("Mirror Push: Unknown - " + $item.url)
|
||||
}
|
||||
$mirrorCount++
|
||||
}
|
||||
$existingProjects++
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
$parsedError = $_ | ConvertFrom-Json
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
}
|
||||
#fine ciclo principale
|
||||
|
||||
# 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 $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "PROGETTI ANALIZZATI: $existingProjects"
|
||||
WriteLogOutput $logFile 0 "MIRRORING TOTALI: $mirrorCount"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Fine Esecuzione Script: $endTime"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Durata Esecuzione Script: $durataScript secondi"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
+37
-15
@@ -12,23 +12,48 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 170
|
||||
#numero massimo di progetti
|
||||
$projectNumber = 250
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$endProj = 250
|
||||
#inizializzo variabili vuote
|
||||
$mirrorId = ""
|
||||
$mirrorUrl = ""
|
||||
$body = ""
|
||||
$jsonBody = ""
|
||||
|
||||
#nome file di log
|
||||
$logFile = "GitlabMirroringGitea.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabMirroringGitea.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
#gitea di destinazione (scegliere prima di esecuzione)
|
||||
#$target = "steamware"
|
||||
$target = "nembro"
|
||||
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
if ($target = "steamware"){
|
||||
#destinazione mirror per gitea Steamw
|
||||
$giteaDestination = $giteaSteamw
|
||||
#nome utente gitea Steamw che effettua i mirror push
|
||||
$giteaUser = $giteaSteamwUser
|
||||
#autenticazione replica gitea Steamw
|
||||
$giteaPass = $giteaSteamwPass
|
||||
#access token per autenticazione gitea Steamw da profilo replica
|
||||
$giteaHead = $giteaSteamwHead
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
if ($target = "nembro"){
|
||||
#destinazione mirror per gitea nembro
|
||||
$giteaDestination = $giteaNembro
|
||||
#nome utente gitea nembro che effettua i mirror push
|
||||
$giteaUser = $giteaNembroUser
|
||||
#autenticazione replica gitea nembro
|
||||
$giteaPass = $tokenGiteaNembro
|
||||
#access token per autenticazione gitea nembro da profilo replica
|
||||
$giteaHead = $giteaNembroHead
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
@@ -44,8 +69,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
try {
|
||||
@@ -60,8 +85,7 @@ do {
|
||||
$mirrorUrl = ""
|
||||
$trunkedPath = ""
|
||||
#controllo se l'url del mirror contiene gitea
|
||||
if ($item.url.Contains("gitea")) {
|
||||
$mirrorDestination = "@gitea.steamware.net"
|
||||
if ($item.url.Contains($giteaDestination)) {
|
||||
#salvo id mirror e url mirror
|
||||
$mirrorId = $($item.id)
|
||||
$mirrorUrl = $($item.url)
|
||||
@@ -76,7 +100,7 @@ do {
|
||||
#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 pass relativi a gitlab
|
||||
$newMirror = "https://" + $giteaUser + ":" + $giteaPass + $mirrorDestination + "/" + $trunkedPath
|
||||
$newMirror = "https://" + $giteaUser + ":" + $giteaPass + "@" + $giteaDestination + "/" + $trunkedPath
|
||||
#creo body da convertire in json
|
||||
$body =
|
||||
@{
|
||||
@@ -104,10 +128,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
@@ -1,4 +1,4 @@
|
||||
###Gitlab: Rinnovamento mirrors esistenti###
|
||||
###Gitlab: Rinnovamento mirrors esistenti (O CANCELLAZIONE)###
|
||||
|
||||
#Questo script viene utilizzato per cancellare e ricreare i mirror esistenti verso gitlab-nembro e gitlab-azzano. Da usare allo scadere dei token di autenticazione.
|
||||
#Una volta inseriti i token nuovi nel file ApiScriptConfig, facendo girare questo script tutti i mirror verso nembro e azzano sono ricreati con il token nuovo.
|
||||
@@ -13,24 +13,24 @@ $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
|
||||
$projectNumber = 200
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$endProj = 300
|
||||
#inizializzo variabili vuote
|
||||
$mirrorId = ""
|
||||
$mirrorUrl = ""
|
||||
$body = ""
|
||||
$jsonBody = ""
|
||||
|
||||
#nome file di log
|
||||
$logFile = "GitlabRebuildMirroring.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabRebuildMirroring.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -45,8 +45,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/remote_mirrors"
|
||||
try {
|
||||
@@ -62,18 +62,18 @@ do {
|
||||
$destinationToken = ""
|
||||
$mirrorUrl = ""
|
||||
$mirrorId = ""
|
||||
#controllo se l'url del mirror contiene azzano
|
||||
#controllo se l'url del mirror contiene azzano, riscrivo mirror
|
||||
if ($item.url.Contains("azzano")) {
|
||||
$doExecute = "true"
|
||||
$destinationToken = $tokenAzzano
|
||||
$mirrorDestination = "@gitlab-azzano.steamware.net"
|
||||
}
|
||||
#controllo se l'url del mirror contiene nembro
|
||||
elseif ($item.url.Contains("nembro")) {
|
||||
$doExecute = "true"
|
||||
$destinationToken = $tokenNembro
|
||||
$mirrorDestination = "@gitlab-nembro.steamware.net"
|
||||
$mirrorDestination = $destinationAzzano
|
||||
}
|
||||
#controllo se l'url del mirror contiene nembro, riscrivo mirror
|
||||
#elseif ($item.url.Contains("nembro")) {
|
||||
# $doExecute = "true"
|
||||
# $destinationToken = $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
|
||||
@@ -120,10 +120,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
|
||||
+42
-49
@@ -1,7 +1,6 @@
|
||||
###Gitlab: controllo i branch protetti (e eventualmente toglie la protezione) dai gitlab nembro e azzano###
|
||||
|
||||
#Questo script passa in rassegna tutti i progetti esistenti sui gitlab satellite nembro e azzano per verificare la presenza di branch protetti che potrebbero impedire
|
||||
#il corretto funzionamento dei mirror verso tali repo. Se necessario questo script può anche rimuovere la protezione da tali branch.
|
||||
#Questo script passa in rassegna tutti i progetti esistenti sui gitlab satellite nembro e azzano per verificare la presenza di branch protetti che potrebbero impedire il corretto funzionamento dei mirror verso tali repo. Se necessario questo script può anche rimuovere la protezione da tali branch.
|
||||
|
||||
#importo file contenente configurazioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
||||
@@ -13,9 +12,9 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 300
|
||||
$endProj = 300
|
||||
#conteggio progetti trovati
|
||||
$existingProjects = 0
|
||||
#conteggio progetti trovati
|
||||
@@ -24,19 +23,14 @@ $protectedProjects = 0
|
||||
$deleteProtection = 1
|
||||
#nome file di log
|
||||
$logFile = "GitlabProtectedBranches.log"
|
||||
|
||||
#specifica quale installazione di gitlab va controllata
|
||||
#$gitlabIstance = $destinationNembro
|
||||
#$head = $nembroHead
|
||||
$gitlabIstance = $destinationAzzano
|
||||
$head = $azzanoHead
|
||||
#nome file old log
|
||||
$oldLogFile = "GitlabProtectedBranches.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -51,43 +45,42 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 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://" + $gitlabIstance + "/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
|
||||
WriteLogOutput $logFile 1 ""
|
||||
WriteLogOutput $logFile 1 "--------------------"
|
||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||
foreach ($item in $parsedResponse) {
|
||||
WriteLogOutput $logFile 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 = "https://" + $gitlabIstance + "/api/v4/projects/" + $projectCount + "/protected_branches/" + $item.name
|
||||
#chiamo method DELETE
|
||||
Invoke-WebRequest -Method Delete -URI $callUrlDelete -Headers $head -ContentType "application/json" -UseBasicParsing
|
||||
$gitlabIstance = $destinationAzzano
|
||||
$head = $azzanoHead
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++) {
|
||||
#chiamata api che restituisce informazioni sullo stato dei mirror
|
||||
$callUrl = "https://" + $gitlabIstance + "/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
|
||||
WriteLogOutput $logFile 1 ""
|
||||
WriteLogOutput $logFile 1 "--------------------"
|
||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount $gitlabIstance**"
|
||||
foreach ($item in $parsedResponse) {
|
||||
WriteLogOutput $logFile 1 "Protected Branch Name: $($item.name) - Allow Force Push: $($item.allow_force_push)"
|
||||
$protectedProjects++
|
||||
if ($deleteProtection -eq 1) {
|
||||
#nuovo URL x delete
|
||||
$callUrlDelete = "https://" + $gitlabIstance + "/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 = $existingProjects + 1
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
$parsedError = $_ | ConvertFrom-Json
|
||||
WriteLogOutput $logFile 3 ""
|
||||
WriteLogOutput $logFile 3 "--------------------"
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
#fine ciclo dei progetti
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
$parsedError = $_ | ConvertFrom-Json
|
||||
WriteLogOutput $logFile 3 ""
|
||||
WriteLogOutput $logFile 3 "--------------------"
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
$durataScript = $mainStopWatch.Elapsed.TotalSeconds
|
||||
@@ -13,24 +13,19 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
$endProj = 250
|
||||
#nome file di log
|
||||
$logFile = "GitlabDevelopCreation.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabDevelopCreation.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#chiedo all'utente il project ID su cui lavorare
|
||||
#$projectCount = Read-Host -Prompt 'Project ID per eseguire lo script: '
|
||||
|
||||
#chiedo all'utente quante volte devo ciclare sui project ID
|
||||
#$projectNumber = Read-Host -Prompt 'Contatore dei Project ID su cui lavorare: '
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -45,8 +40,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
#compongo chiamata api per lavorare sui branch
|
||||
$branchUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/repository/branches"
|
||||
try {
|
||||
@@ -89,10 +84,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
@@ -14,18 +14,19 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
$endProj = 250
|
||||
#nome file di log
|
||||
$logFile = "GitlabTagCreation.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabTagCreation.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -40,14 +41,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#chiedo all'utente il project ID su cui lavorare
|
||||
#$projectCount = Read-Host -Prompt 'Project ID per eseguire lo script: '
|
||||
|
||||
#chiedo all'utente quante volte devo ciclare sui project ID
|
||||
#$projectNumber = Read-Host -Prompt 'Contatore dei Project ID su cui lavorare: '
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
#compongo chiamata api per lavorare sui tag
|
||||
$tagsUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/repository/tags"
|
||||
try {
|
||||
@@ -77,10 +72,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
@@ -13,18 +13,19 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
$endProj = 250
|
||||
#nome file di log
|
||||
$logFile = "EditReposNamespace.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "EditReposNamespace.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -39,8 +40,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber. su gitlab nembro e gitlab azzano il namespace 19 è il gruppo egalware
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
$callGitlabUrl = "https://" + $destinationAzzano + "/api/v4/projects/" + $projectCount + "/transfer?namespace=19"
|
||||
try {
|
||||
$gitlabResponse = Invoke-WebRequest -URI $callGitlabUrl -Method PUT -Headers $azzanoHead -ContentType "application/json" -UseBasicParsing
|
||||
@@ -59,10 +60,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
@@ -10,9 +10,9 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
$endProj = 250
|
||||
#conteggio progetti trovati
|
||||
$projectsWithPipeline = 0
|
||||
#conteggio pipeline in errore
|
||||
@@ -20,14 +20,15 @@ $pipelineErrorsCount = 0
|
||||
#conteggio pipeline riusciti
|
||||
$pipelineSuccessCount = 0
|
||||
#nome file di log
|
||||
$logFile = "Gitlab-AzzanoPipeline.log"
|
||||
$logFile = "GitlabAzzanoPipeline.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabAzzanoPipeline.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -42,8 +43,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
$callUrl = "https://gitlab-azzano.steamware.net/api/v4/projects/" + $projectCount + "/pipelines/latest"
|
||||
try {
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $azzanoHead -ContentType "application/json" -UseBasicParsing
|
||||
@@ -56,15 +57,15 @@ do {
|
||||
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
||||
if ($item.status.Equals("success")) {
|
||||
WriteLogOutput $logFile 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||
$pipelineSuccessCount = $pipelineSuccessCount + 1
|
||||
$pipelineSuccessCount++
|
||||
}
|
||||
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
||||
else {
|
||||
WriteLogOutput $logFile 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||
$pipelineErrorsCount = $pipelineErrorsCount + 1
|
||||
$pipelineErrorsCount++
|
||||
}
|
||||
}
|
||||
$projectsWithPipeline = $projectsWithPipeline + 1
|
||||
$projectsWithPipeline++
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
@@ -74,10 +75,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
#somma di pipelineSuccess e pipelineErrors
|
||||
$pipelineCount = $pipelineSuccessCount + $pipelineErrorsCount
|
||||
@@ -97,13 +96,13 @@ $endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#invio a zabbix le metriche rilevate tramite zabbix_sender.exe
|
||||
#WriteLogOutput $logFile 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
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ProjectsWithPipeline -o $projectsWithPipeline
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.TotalPipeline -o $pipelineCount
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessPipeline -o $pipelineSuccessCount
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsPipeline -o $pipelineErrorsCount
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessPipelinePercent -o $pipelineSuccessPercentage
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsPipelinePercent -o $pipelineErrorsPercentage
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.CheckPipelineDuration -o $durataScript
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput $logFile 0 ""
|
||||
|
||||
@@ -10,9 +10,9 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
$endProj = 250
|
||||
#conteggio progetti trovati
|
||||
$projectsWithPipeline = 0
|
||||
#conteggio pipeline in errore
|
||||
@@ -20,14 +20,15 @@ $pipelineErrorsCount = 0
|
||||
#conteggio pipeline riusciti
|
||||
$pipelineSuccessCount = 0
|
||||
#nome file di log
|
||||
$logFile = "Gitlab-NembroPipeline.log"
|
||||
$logFile = "GitlabNembroPipeline.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabNembroPipeline.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -42,8 +43,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
$callUrl = "https://gitlab-nembro.steamware.net/api/v4/projects/" + $projectCount + "/pipelines/latest"
|
||||
try {
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $nembroHead -ContentType "application/json" -UseBasicParsing
|
||||
@@ -56,15 +57,15 @@ do {
|
||||
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
||||
if ($item.status.Equals("success")) {
|
||||
WriteLogOutput $logFile 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||
$pipelineSuccessCount = $pipelineSuccessCount + 1
|
||||
$pipelineSuccessCount++
|
||||
}
|
||||
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
||||
else {
|
||||
WriteLogOutput $logFile 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||
$pipelineErrorsCount = $pipelineErrorsCount + 1
|
||||
$pipelineErrorsCount++
|
||||
}
|
||||
}
|
||||
$projectsWithPipeline = $projectsWithPipeline + 1
|
||||
$projectsWithPipeline++
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
@@ -74,10 +75,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
#somma di pipelineSuccess e pipelineErrors
|
||||
$pipelineCount = $pipelineSuccessCount + $pipelineErrorsCount
|
||||
@@ -97,13 +96,13 @@ $endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#invio a zabbix le metriche rilevate tramite zabbix_sender.exe
|
||||
#WriteLogOutput $logFile 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
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ProjectsWithPipeline -o $projectsWithPipeline
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.TotalPipeline -o $pipelineCount
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessPipeline -o $pipelineSuccessCount
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsPipeline -o $pipelineErrorsCount
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessPipelinePercent -o $pipelineSuccessPercentage
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsPipelinePercent -o $pipelineErrorsPercentage
|
||||
#& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.CheckPipelineDuration -o $durataScript
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput $logFile 0 ""
|
||||
|
||||
@@ -13,9 +13,9 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 1
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 200
|
||||
$endProj = 250
|
||||
#conteggio progetti trovati
|
||||
$projectsWithPipeline = 0
|
||||
#conteggio pipeline in errore
|
||||
@@ -24,13 +24,14 @@ $pipelineErrorsCount = 0
|
||||
$pipelineSuccessCount = 0
|
||||
#nome file di log
|
||||
$logFile = "GitlabPipeline.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GitlabPipeline.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -45,8 +46,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
$callUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount + "/pipelines/latest"
|
||||
try {
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
@@ -59,15 +60,15 @@ do {
|
||||
#verifico se i pipeline trovati per il progetto corrente hanno status "success"
|
||||
if ($item.status.Equals("success")) {
|
||||
WriteLogOutput $logFile 2 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||
$pipelineSuccessCount = $pipelineSuccessCount + 1
|
||||
$pipelineSuccessCount++
|
||||
}
|
||||
#i pipeline che non hanno status "success" vengono loggati con relativo errore
|
||||
else {
|
||||
WriteLogOutput $logFile 1 "Pipeline: $($item.web_url) - Status: $($item.status)"
|
||||
$pipelineErrorsCount = $pipelineErrorsCount + 1
|
||||
$pipelineErrorsCount++
|
||||
}
|
||||
}
|
||||
$projectsWithPipeline = $projectsWithPipeline + 1
|
||||
$projectsWithPipeline++
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
@@ -77,10 +78,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
#somma di pipelineSuccess e pipelineErrors
|
||||
$pipelineCount = $pipelineSuccessCount + $pipelineErrorsCount
|
||||
@@ -100,13 +99,13 @@ $endTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
|
||||
#invio a zabbix le metriche rilevate tramite zabbix_sender.exe
|
||||
WriteLogOutput $logFile 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
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ProjectsWithPipeline -o $projectsWithPipeline
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.TotalPipeline -o $pipelineCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessPipeline -o $pipelineSuccessCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsPipeline -o $pipelineErrorsCount
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.SuccessPipelinePercent -o $pipelineSuccessPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.ErrorsPipelinePercent -o $pipelineErrorsPercentage
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gitlab.CheckPipelineDuration -o $durataScript
|
||||
|
||||
#scrivo a video le statistiche
|
||||
WriteLogOutput $logFile 0 ""
|
||||
|
||||
@@ -13,17 +13,31 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 170
|
||||
#numero massimo di progetti da analizzare (messo a 1 per "sicura inserita" siccome questo script è potenzialmente pericoloso)
|
||||
$projectNumber = 300
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$endProj = 300
|
||||
#nome file di log
|
||||
$logFile = "AzzanoNembroReposCreation.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "AzzanoNembroReposCreation.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#specifica quale installazione di gitlab va controllata
|
||||
#$remote = "Nembro"
|
||||
$remote = "Azzano"
|
||||
|
||||
if ($remote -eq "Nembro"){
|
||||
$gitlabIstance = $destinationNembro
|
||||
$destinationHead = $nembroHead
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
if ($remote -eq "Azzano"){
|
||||
$gitlabIstance = $destinationAzzano
|
||||
$destinationHead = $azzanoHead
|
||||
}
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
@@ -39,10 +53,14 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
$callGitlabUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
||||
try {
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
WriteLogOutput $logFile 1 ""
|
||||
WriteLogOutput $logFile 1 "--------------------"
|
||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||
$gitlabResponse = Invoke-WebRequest -URI $callGitlabUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
$parsedGitlabResponse = $gitlabResponse.Content | ConvertFrom-Json
|
||||
#dichiaro un body da convertire in JSON con il nome del repo da creare
|
||||
@@ -50,39 +68,25 @@ do {
|
||||
@{
|
||||
name = $($parsedGitlabResponse.path);
|
||||
#name = $($parsedGitlabResponse.name);
|
||||
#namespace_id 19 è il gruppo Egalware
|
||||
namespace_id = 19
|
||||
#(namespace_id 19 è Egalware)
|
||||
}
|
||||
# Converting my hash to json format
|
||||
$bodyJSON = $body | ConvertTo-Json
|
||||
#chiamata per nembro
|
||||
$callNembroUrl = "https://gitlab-nembro.steamware.net/api/v4/projects/"
|
||||
$nembroResponse = Invoke-WebRequest -URI $callNembroUrl -Method POST -Headers $nembroHead -ContentType "application/json" -Body $bodyJSON
|
||||
$parsedNembroResponse = $nembroResponse.Content | ConvertFrom-Json
|
||||
#chiamata per azzano
|
||||
$callAzzanoUrl = "https://gitlab-azzano.steamware.net/api/v4/projects/"
|
||||
$azzanoResponse = Invoke-WebRequest -URI $callAzzanoUrl -Method POST -Headers $azzanoHead -ContentType "application/json" -Body $bodyJSON
|
||||
$parsedAzzanoResponse = $azzanoResponse.Content | ConvertFrom-Json
|
||||
#scrivo il numero del progetto nel terminale e su file
|
||||
WriteLogOutput $logFile 1 ""
|
||||
WriteLogOutput $logFile 1 "--------------------"
|
||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||
#scrivo il nome del progetto nel terminale e su file
|
||||
WriteLogOutput $logFile 1 "Gitlab Project Name: $($parsedGitlabResponse.path)"
|
||||
WriteLogOutput $logFile 1 "Progetto creato su gitlab-nembro: $($parsedNembroResponse.path_with_namespace)"
|
||||
WriteLogOutput $logFile 1 "Progetto creato su gitlab-azzano: $($parsedAzzanoResponse.path_with_namespace)"
|
||||
$bodyJSON = $body | ConvertTo-Json
|
||||
#chiamata creazione
|
||||
$callUrl = "https://" + $gitlabIstance + "/api/v4/projects/"
|
||||
$Response = Invoke-WebRequest -URI $callUrl -Method POST -Headers $destinationHead -ContentType "application/json" -Body $bodyJSON
|
||||
$parsedResponse = $Response.Content | ConvertFrom-Json
|
||||
WriteLogOutput $logFile 1 "Progetto creato su $callUrl : $($parsedResponse.path_with_namespace)"
|
||||
}
|
||||
#scrivo se trovo un errore durante il try/catch
|
||||
catch {
|
||||
$parsedError = $_ | ConvertFrom-Json
|
||||
WriteLogOutput $logFile 3 ""
|
||||
WriteLogOutput $logFile 3 "--------------------"
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
WriteLogOutput $logFile 3 "Errore: $($parsedError.message)"
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
|
||||
@@ -12,24 +12,55 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 170
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 300
|
||||
$endProj = 300
|
||||
#nome file di log
|
||||
$logFile = "GiteaReposCreation.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GiteaReposCreation.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#gitea di destinazione
|
||||
#$target = "steamware"
|
||||
#$target = "nembro"
|
||||
$target = "azzano"
|
||||
|
||||
if ($target -eq "steamware"){
|
||||
#destinazione mirror per gitea Steamw
|
||||
$giteaDestination = $giteaSteamw
|
||||
#nome utente gitea Steamw che effettua i mirror push
|
||||
$giteaUser = $giteaSteamwUser
|
||||
#autenticazione replica gitea Steamw
|
||||
$giteaPass = $giteaSteamwPass
|
||||
#access token per autenticazione gitea Steamw da profilo replica
|
||||
$giteaHead = $giteaSteamwHead
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
if ($target -eq "nembro") {
|
||||
#destinazione mirror per gitea nembro
|
||||
$giteaDestination = $giteaNembro
|
||||
#nome utente gitea nembro che effettua i mirror push
|
||||
$giteaUser = $giteaNembroUser
|
||||
#autenticazione replica gitea nembro
|
||||
$giteaPass = $giteaNembroPass
|
||||
#access token per autenticazione gitea nembro da profilo replica
|
||||
$giteaHead = $giteaNembroHead
|
||||
}
|
||||
if ($target -eq "azzano") {
|
||||
#destinazione mirror per gitea azzano
|
||||
$giteaDestination = $giteaAzzano
|
||||
#nome utente gitea azzano che effettua i mirror push
|
||||
$giteaUser = $giteaAzzanoUser
|
||||
#autenticazione replica gitea nemazzanobro
|
||||
$giteaPass = $giteaAzzanoPass
|
||||
#access token per autenticazione gitea azzano da profilo replica
|
||||
$giteaHead = $giteaAzzanoHead
|
||||
}
|
||||
|
||||
#chiedo all'utente il project ID su cui lavorare
|
||||
#$projectCount = Read-Host -Prompt 'Project ID per eseguire lo script: '
|
||||
|
||||
#chiedo all'utente quante volte devo ciclare sui project ID
|
||||
#$projectNumber = Read-Host -Prompt 'Contatore dei Project ID su cui lavorare: '
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -44,8 +75,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
$callGitlabUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
||||
try {
|
||||
$gitlabResponse = Invoke-WebRequest -URI $callGitlabUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
@@ -56,7 +87,7 @@ do {
|
||||
WriteLogOutput $logFile 1 "**PROGETTO $projectCount**"
|
||||
foreach ($gitlabItem in $parsedGitlabResponse) {
|
||||
WriteLogOutput $logFile 1 "Gitlab Project Name: $($gitlabItem.name)"
|
||||
$callGiteaUrl = "https://gitea.steamware.net/api/v1/orgs/Egalware/repos"
|
||||
$callGiteaUrl = "http://" + $giteaDestination + "/api/v1/orgs/Egalware/repos"
|
||||
#dichiaro un body da convertire in JSON con il nome del repo da creare (prendo path o name a seconda delle necessità)
|
||||
$giteaBody =
|
||||
@{
|
||||
@@ -88,10 +119,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
|
||||
@@ -12,24 +12,19 @@ $startTime = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
|
||||
# avvio stopwatch
|
||||
$mainStopWatch = [system.diagnostics.stopwatch]::StartNew()
|
||||
#contatore ciclo do while
|
||||
$projectCount = 170
|
||||
$startProj = 1
|
||||
#numero massimo di progetti da analizzare
|
||||
$projectNumber = 300
|
||||
$endProj = 300
|
||||
#nome file di log
|
||||
$logFile = "GogsReposCreation.log"
|
||||
#nome file di log old
|
||||
$oldLogFile = "GogsReposCreation.old"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
#creazione folder di Log se non esiste
|
||||
CheckLogFolder
|
||||
|
||||
#chiedo all'utente il project ID su cui lavorare
|
||||
#$projectCount = Read-Host -Prompt 'Project ID per eseguire lo script: '
|
||||
|
||||
#chiedo all'utente quante volte devo ciclare sui project ID
|
||||
#$projectNumber = Read-Host -Prompt 'Contatore dei Project ID su cui lavorare: '
|
||||
#rotazione vecchio logFile da .log a .old se esiste
|
||||
RotateOldLog
|
||||
|
||||
#scrivo intestazione e inizio analisi
|
||||
WriteLogOutput $logFile 0 "--------------------"
|
||||
@@ -44,8 +39,8 @@ WriteLogOutput $logFile 0 "Percorso log: $logFolder"
|
||||
WriteLogOutput $logFile 0 ""
|
||||
WriteLogOutput $logFile 0 "Inizio Esecuzione Script: $startTime"
|
||||
|
||||
#ciclo principale do/while che cicla da 1 a N projectNumber
|
||||
do {
|
||||
#ciclo principale for che cicla da startProj a endProj
|
||||
for ($projectCount = $startProj; $projectCount -le $endProj; $projectCount++){
|
||||
$callGitlabUrl = "https://gitlab.steamware.net/api/v4/projects/" + $projectCount
|
||||
try {
|
||||
$gitlabResponse = Invoke-WebRequest -URI $callGitlabUrl -Headers $gitlabHead -ContentType "application/json" -UseBasicParsing
|
||||
@@ -86,10 +81,8 @@ do {
|
||||
WriteLogOutput $logFile 3 "**ERRORE NEL PROGETTO $projectCount**"
|
||||
WriteLogOutput $logFile 3 $($parsedError.message)
|
||||
}
|
||||
$projectCount = $projectCount + 1
|
||||
}
|
||||
#fine ciclo principale
|
||||
while ($projectCount -le $projectNumber)
|
||||
|
||||
# fermo stopwatch e calcolo durata script
|
||||
$mainStopWatch.Stop()
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Aggiorna il livello di notifica GitLab per un range di utenti
|
||||
e logga tutto in C:\Steamware\Logs\Gitlab\notificationLevelChange.log
|
||||
#>
|
||||
|
||||
# importa configurazioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsFunctions.ps1
|
||||
|
||||
$GitlabUrl = "https://gitlab.steamware.net"
|
||||
$PrivateToken = $tokenGitlab
|
||||
|
||||
# Range utenti da aggiornare (modificabile)
|
||||
$StartId = 1
|
||||
$EndId = 50
|
||||
|
||||
# Livello notifiche da impostare (modificabile)
|
||||
$NewLevel = "mention" # altri valori: disabled, participating, watch, global, custom
|
||||
|
||||
# Percorso log
|
||||
$LogDir = "C:\Steamware\Logs\Gitlab"
|
||||
$LogFile = Join-Path $LogDir "notificationLevelChange.log"
|
||||
|
||||
# Crea cartella log se non esiste
|
||||
if (-not (Test-Path $LogDir)) {
|
||||
New-Item -Path $LogDir -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
|
||||
# Header base
|
||||
$baseHeaders = @{
|
||||
"PRIVATE-TOKEN" = $PrivateToken
|
||||
"Content-Type" = "application/json"
|
||||
}
|
||||
|
||||
# Corpo JSON della richiesta
|
||||
$body = @{ level = $NewLevel } | ConvertTo-Json
|
||||
|
||||
# Inizializza log
|
||||
"INFO [$((Get-Date).ToString('o'))] Starting notification level update for IDs $StartId-$EndId (level=$NewLevel)" |
|
||||
Out-File -FilePath $LogFile -Encoding UTF8
|
||||
|
||||
# Ciclo utenti
|
||||
for ($id = $StartId; $id -le $EndId; $id++) {
|
||||
|
||||
$separator = "----- USER $id -----"
|
||||
$url = "$GitlabUrl/api/v4/notification_settings"
|
||||
|
||||
# Clona headers e aggiunge Sudo per modificare altri utenti
|
||||
$headers = @{}
|
||||
foreach ($k in $baseHeaders.Keys) { $headers[$k] = $baseHeaders[$k] }
|
||||
$headers["Sudo"] = "$id"
|
||||
|
||||
try {
|
||||
$response = Invoke-WebRequest `
|
||||
-Method PUT `
|
||||
-Uri $url `
|
||||
-Headers $headers `
|
||||
-Body $body `
|
||||
-ErrorAction Stop
|
||||
|
||||
"$separator`nINFO [$((Get-Date).ToString('o'))] UPDATED id=$id level=$NewLevel status=$($response.StatusCode)" |
|
||||
Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||
}
|
||||
catch {
|
||||
$msg = $_.Exception.Message -replace "`r?`n"," "
|
||||
"$separator`nERROR [$((Get-Date).ToString('o'))] FAILED id=$id message=$msg" |
|
||||
Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||
}
|
||||
|
||||
Start-Sleep -Milliseconds 150
|
||||
}
|
||||
|
||||
"INFO [$((Get-Date).ToString('o'))] Completed." |
|
||||
Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||
|
||||
Write-Host "Fatto. Log salvato in $LogFile"
|
||||
@@ -0,0 +1,85 @@
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Recupera utenti GitLab per ID 1-100 e scrive output in C:\Steamware\Logs\Gitlab\gitlab_users_1-100.log
|
||||
#>
|
||||
|
||||
#importo file contenente configurazioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsConfig.ps1
|
||||
#importo file contenente funzioni
|
||||
. .\ApiGit\ApiGitResources\ApiScriptsFunctions.ps1
|
||||
|
||||
$GitlabUrl = "gitlab.steamware.net"
|
||||
$PrivateToken = $tokenGitlab
|
||||
|
||||
# Configurazione
|
||||
$StartId = 1
|
||||
$EndId = 50
|
||||
$LogDir = "C:\Steamware\Logs\Gitlab"
|
||||
$LogFile = Join-Path -Path $LogDir -ChildPath "GitlabUsers.log"
|
||||
|
||||
# Crea cartella log se non esiste
|
||||
try {
|
||||
if (-not (Test-Path -Path $LogDir)) {
|
||||
New-Item -Path $LogDir -ItemType Directory -Force | Out-Null
|
||||
}
|
||||
}
|
||||
catch {
|
||||
Write-Error "Impossibile creare la cartella di log $LogDir. Errore: $($_.Exception.Message)"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# Header autenticazione
|
||||
$baseUrl = $GitlabUrl.TrimEnd('/')
|
||||
$headers = @{ "PRIVATE-TOKEN" = $PrivateToken }
|
||||
|
||||
# Inizializza file di log (sovrascrive se esiste)
|
||||
$startLine = "INFO [{0}] Starting GitLab users retrieval for IDs {1}-{2}" -f (Get-Date -Format o), $StartId, $EndId
|
||||
$startLine | Out-File -FilePath $LogFile -Encoding UTF8
|
||||
|
||||
$retrieved = 0
|
||||
$errors = 0
|
||||
|
||||
# inizializza contatore per numeratore
|
||||
$counter = 1
|
||||
$total = $EndId - $StartId + 1
|
||||
|
||||
for ($id = $StartId; $id -le $EndId; $id++) {
|
||||
$url = "$baseUrl/api/v4/users/$id"
|
||||
# crea prefisso numerato e separatore (es. --- 001/100 ---)
|
||||
$num = "{0:D3}" -f $counter
|
||||
$separator = "----- $num/$total -----"
|
||||
|
||||
try {
|
||||
$user = Invoke-RestMethod -Uri $url -Headers $headers -Method Get -ErrorAction Stop
|
||||
$json = $user | ConvertTo-Json -Depth 10 -Compress
|
||||
$line = "{0} `nINFO [{1}] USER_FOUND id={2} data={3}" -f $separator, (Get-Date -Format o), $id, $json
|
||||
$line | Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||
$retrieved++
|
||||
}
|
||||
catch {
|
||||
$status = "unknown"
|
||||
try {
|
||||
if ($_.Exception.Response -ne $null) {
|
||||
$status = $_.Exception.Response.StatusCode.value__
|
||||
}
|
||||
} catch { $status = "unknown" }
|
||||
|
||||
if ($status -eq 404) {
|
||||
$line = "{0} `nWARN [{1}] USER_NOT_FOUND id={2} status=404 message=Not Found" -f $separator, (Get-Date -Format o), $id
|
||||
}
|
||||
else {
|
||||
$msg = $_.Exception.Message -replace "`r?`n", " "
|
||||
$line = "{0} `nERROR [{1}] USER_ERROR id={2} status={3} message={4}" -f $separator, (Get-Date -Format o), $id, $status, $msg
|
||||
}
|
||||
$line | Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||
$errors++
|
||||
}
|
||||
|
||||
$counter++
|
||||
Start-Sleep -Milliseconds 200
|
||||
}
|
||||
|
||||
$endLine = "INFO [{0}] Completed. Retrieved={1} Errors={2}" -f (Get-Date -Format o), $retrieved, $errors
|
||||
$endLine | Out-File -FilePath $LogFile -Encoding UTF8 -Append
|
||||
|
||||
Write-Host "Fatto. Log salvato in $LogFile. Utenti recuperati: $retrieved. Errori: $errors."
|
||||
@@ -104,6 +104,6 @@ else {
|
||||
# fermo stopwatch e conteggio...
|
||||
$stopwatch.Stop()
|
||||
$durata = $stopwatch.Elapsed.TotalSeconds
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gpw.Proj -o $durata
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gpw.Proj -o $durata
|
||||
LogWrite("Durata esecuzione: $durata")
|
||||
}
|
||||
|
||||
@@ -65,5 +65,5 @@ finally
|
||||
# fermo stopwatch e conteggio...
|
||||
$stopwatch.Stop()
|
||||
$durata = $stopwatch.Elapsed.TotalSeconds
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k LiMan.Lic -o $durata
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k LiMan.Lic -o $durata
|
||||
LogWrite("Durata esecuzione: $durata")
|
||||
|
||||
@@ -104,5 +104,5 @@ finally
|
||||
# fermo stopwatch e conteggio...
|
||||
$stopwatch.Stop()
|
||||
$durata = $stopwatch.Elapsed.TotalSeconds
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gpw.Timb -o $durata
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gpw.Timb -o $durata
|
||||
LogWrite("Durata esecuzione: $durata")
|
||||
@@ -80,5 +80,5 @@ finally
|
||||
# fermo stopwatch e conteggio...
|
||||
$stopwatch.Stop()
|
||||
$durata = $stopwatch.Elapsed.TotalSeconds
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "IIS04" -k Gpw.Core -o $durata
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s "W2022-IIS04" -k Gpw.Core -o $durata
|
||||
LogWrite("Durata esecuzione: $durata")
|
||||
@@ -34,4 +34,4 @@ Remove-Variable * -ErrorAction SilentlyContinue # pulisco variabili x ISE
|
||||
|
||||
$durata = 5
|
||||
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabbix.ufficio -s "IIS04" -k TESTER -o $durata
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabbix.ufficio -s "W2022-IIS04" -k TESTER -o $durata
|
||||
@@ -28,9 +28,9 @@ $sourceFolder = "U:\NextCloud\ABH\Compo"
|
||||
#folder destination per robocopy
|
||||
$destFolder = "U:\WebDoorSync\NewComp\Compo"
|
||||
|
||||
# ex IIS04
|
||||
# ex W2022-IIS04
|
||||
#$sourceFolder = "\\stor01\TEAM DRIVES\30_Clienti\ABH\DataImport\Compo"
|
||||
#$destFolder = "\\IIS04\WebDoorSync\NewComp\Compo"
|
||||
#$destFolder = "\\W2022-IIS04\WebDoorSync\NewComp\Compo"
|
||||
|
||||
####FINE DICHIARAZIONE VARIABILI####
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
# CheckLocalGitStatus
|
||||
#
|
||||
# Verifica di un set di repo GIT locali rispetto al server origin remoto
|
||||
# per stabilire quali necessitino di aggiornamento
|
||||
#
|
||||
# esempio chiamata:
|
||||
|
||||
# parametri in ingresso
|
||||
param (
|
||||
[string]$RootPath = "C:\Users\samuele.steamw\source", # Default alla cartella dei sorgenti, da passare invocando il comando
|
||||
[switch]$SwitchToMain,
|
||||
[string]$OutputFile = "$PSScriptRoot\outdated_repos.txt",
|
||||
[switch]$Help
|
||||
)
|
||||
|
||||
$branchesToCheck = @("main", "master")
|
||||
$outdatedRepos = @()
|
||||
|
||||
# Mostra help message se --help or -h passato come argomento
|
||||
if ($Help -or $args -contains "--help" -or $args -contains "-h") {
|
||||
Write-Host @"
|
||||
Usage: .\Check-GitRepos.ps1 [-RootPath <path>] [-SwitchToMain] [-OutputFile <file>] [--help]
|
||||
|
||||
Checks all Git repositories under the specified folder and compares their main/master branch
|
||||
with the remote origin. Optionally switches to main/master to perform the check.
|
||||
|
||||
Parameters:
|
||||
-RootPath Path to the root folder containing Git repositories (default: current script path)
|
||||
-SwitchToMain Temporarily switch to main/master branch to perform the check
|
||||
-OutputFile Path to the output file listing outdated repositories
|
||||
--help, -h Show this help message
|
||||
|
||||
Examples:
|
||||
.\Check-GitRepos.ps1 -RootPath "D:\Dev\Projects"
|
||||
.\Check-GitRepos.ps1 -SwitchToMain
|
||||
.\Check-GitRepos.ps1 -RootPath "C:\Code" -SwitchToMain -OutputFile "C:\outdated.txt"
|
||||
"@ -ForegroundColor Cyan
|
||||
exit
|
||||
}
|
||||
|
||||
|
||||
# Function to check Git status
|
||||
function Check-GitStatus {
|
||||
param (
|
||||
[string]$repoPath,
|
||||
[string]$OutputFile
|
||||
)
|
||||
|
||||
Write-Host "`nChecking repository at: $repoPath" -ForegroundColor Cyan
|
||||
Push-Location $repoPath
|
||||
|
||||
if (-not (Test-Path ".git")) {
|
||||
Write-Host "Not a Git repository." -ForegroundColor Yellow
|
||||
"$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss')) - Not a Git repository." | Out-File -FilePath $OutputFile -Append -Encoding UTF8
|
||||
Pop-Location
|
||||
return
|
||||
}
|
||||
|
||||
git fetch origin *> $null 2>&1
|
||||
|
||||
$originalBranch = git rev-parse --abbrev-ref HEAD 2>$null
|
||||
|
||||
$remoteBranches = git ls-remote --heads origin | ForEach-Object {
|
||||
($_ -split "\s+")[1] -replace "refs/heads/", ""
|
||||
}
|
||||
|
||||
$targetBranch = $branchesToCheck | Where-Object { $remoteBranches -contains $_ } | Select-Object -First 1
|
||||
|
||||
if (-not $targetBranch) {
|
||||
$message = "$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss')) - MISSING | $repoPath No 'main' or 'master' branch found on remote."
|
||||
Write-Host $message -ForegroundColor Red
|
||||
$message | Out-File -FilePath $OutputFile -Append -Encoding UTF8
|
||||
Pop-Location
|
||||
return
|
||||
}
|
||||
|
||||
if ($SwitchToMain -and $originalBranch -ne $targetBranch) {
|
||||
git stash push -u -m "Temp stash before switching branches" *> $null 2>&1
|
||||
git checkout $targetBranch *> $null 2>&1
|
||||
}
|
||||
|
||||
$status = git status -sb 2>$null
|
||||
$aheadBehind = git rev-list --left-right --count origin/$targetBranch...HEAD 2>$null
|
||||
|
||||
if ($aheadBehind) {
|
||||
$parts = $aheadBehind -split "`t"
|
||||
$behind = [int]$parts[0]
|
||||
$ahead = [int]$parts[1]
|
||||
|
||||
if ($ahead -gt 0 -or $behind -gt 0) {
|
||||
$message = "$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss')) - UPDATE | $repoPath is not up to date with origin/$targetBranch (ahead: $ahead, behind: $behind)"
|
||||
Write-Host $message -ForegroundColor Yellow
|
||||
$message | Out-File -FilePath $OutputFile -Append -Encoding UTF8
|
||||
$script:hasOutdated = $true
|
||||
} else {
|
||||
Write-Host "✅ Repo is up to date with origin/$targetBranch" -ForegroundColor Green
|
||||
}
|
||||
}
|
||||
|
||||
if ($SwitchToMain -and $originalBranch -ne $targetBranch) {
|
||||
git checkout $originalBranch *> $null 2>&1
|
||||
git stash pop *> $null 2>&1
|
||||
}
|
||||
|
||||
Pop-Location
|
||||
}
|
||||
|
||||
# Get all subdirectories containing .git folders
|
||||
$repos = Get-ChildItem -Path $RootPath -Recurse -Directory | Where-Object {
|
||||
Test-Path "$($_.FullName)\.git"
|
||||
}
|
||||
|
||||
# Clear or create output file
|
||||
"" | Out-File -FilePath $OutputFile -Encoding UTF8
|
||||
$script:hasOutdated = $false
|
||||
|
||||
# Check each repository
|
||||
foreach ($repo in $repos) {
|
||||
Check-GitStatus -repoPath $repo.FullName -OutputFile $OutputFile
|
||||
}
|
||||
|
||||
# Final summary
|
||||
if ($script:hasOutdated) {
|
||||
Write-Host "`n📄 Outdated repositories saved to: $OutputFile" -ForegroundColor Cyan
|
||||
} else {
|
||||
$msg = "🎉 All repositories are up to date!"
|
||||
Write-Host "`n$msg" -ForegroundColor Green
|
||||
$msg = "$((Get-Date).ToString('yyyy-MM-dd HH:mm:ss')) - 🎉 All repositories are up to date!"
|
||||
$msg | Out-File -FilePath $OutputFile -Append -Encoding UTF8
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
###ROBOCOPY VHDX VEEAM OVH VERSO TNAS UFFICIO###
|
||||
|
||||
$hostname = hostname
|
||||
$logFile = "C:\Steamware\Log\" + $hostname + "_VeeamVhdxRobocopy.log"
|
||||
|
||||
#cartella di origine
|
||||
$sourceFolder = "W:\ISO\Win\"
|
||||
|
||||
#file da copiare
|
||||
$file = "Windows10_EN_x64.iso"
|
||||
|
||||
#cartella di destinazione
|
||||
$destFolder = "\\10.74.82.201\veeam-ovh-vhdx"
|
||||
|
||||
robocopy $sourceFolder $destFolder $file /mt /tee /log:$logFile
|
||||
@@ -0,0 +1,36 @@
|
||||
###ROBOCOPY VHDX VEEAM OVH VERSO TNAS UFFICIO###
|
||||
|
||||
net use Z: /delete
|
||||
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
net use Z: \\10.74.82.201\veeam-ovh-storage $env:ZPass /user:egw-tscale-01\veeamovh
|
||||
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
#definisco file di log tramite hostname locale
|
||||
$hostname = hostname
|
||||
$logFile1 = "C:\Steamware\Logs\VeeamBackupRobocopy" + $hostname + ".log"
|
||||
$logFile2 = "C:\Steamware\Logs\VeeamConfigRobocopy" + $hostname + ".log"
|
||||
|
||||
#cartella1 di origine
|
||||
$sourceFolder1 = "B:\Backups\Backup Job WDC"
|
||||
|
||||
#cartella2 di origine
|
||||
$sourceFolder2 = "B:\Backups\VeeamConfigBackup"
|
||||
|
||||
#cartella1 di destinazione
|
||||
$destFolder1 = "Z:\VEEAM-WDC\Backup Job WDC"
|
||||
|
||||
#cartella2 di destinazione
|
||||
$destFolder2 = "Z:\VEEAM-WDC\VeeamConfigBackup"
|
||||
|
||||
#eseguo copia cartella 1
|
||||
robocopy $sourceFolder1 $destFolder1 /mir /mt /tee /log:$logFile1
|
||||
|
||||
#eseguo copia cartella 2
|
||||
robocopy $sourceFolder2 $destFolder2 /mir /mt /tee /log:$logFile2
|
||||
|
||||
Start-Sleep -Seconds 5
|
||||
|
||||
net use Z: /delete
|
||||
@@ -0,0 +1,21 @@
|
||||
###ESEMPIO COMANDO ROBOCOPY###
|
||||
|
||||
#path cartella di origine
|
||||
$sourceFolder = "C:\Users\YYY"
|
||||
|
||||
#nomi dei file da copiare
|
||||
$file1 = "nome1.txt"
|
||||
$file2 = "nome2.txt"
|
||||
$file3 = "nome3.txt"
|
||||
|
||||
#path delle cartelle di destinazione
|
||||
$destFolder1 = "C:\Users\XXX1"
|
||||
$destFolder2 = "C:\Users\XXX2"
|
||||
$destFolder3 = "C:\Users\XXX3"
|
||||
|
||||
#copio primo file
|
||||
robocopy $sourceFolder $destFolder1 $file1
|
||||
#copio secondo file
|
||||
robocopy $sourceFolder $destFolder2 $file2
|
||||
#copio terzo file
|
||||
robocopy $sourceFolder $destFolder3 $file3
|
||||
@@ -0,0 +1,57 @@
|
||||
####SCRIPT PER CONTROLLARE TIME DRIFT WINDOWS####
|
||||
|
||||
#nome file di log
|
||||
$logFile = "W32TimeDriftCheck.log"
|
||||
#cartella file di log
|
||||
$logFolder = "c:\Steamware\Logs\"
|
||||
#opzione log su file: scrivo se = 1, ignoro se = 0
|
||||
$logType = 1
|
||||
#opzione output in terminale: scrivo se = 1, ignoro se = 0
|
||||
$terminalOutput = 1
|
||||
#Ipv4 PDC
|
||||
$PDC = "10.74.82.251"
|
||||
#Ipv4 BDC
|
||||
$BDC = "10.74.82.250"
|
||||
#Nome host su Zabbix per invio con trapper
|
||||
$ZabbixHost = "WIN2022-SQL-DEV"
|
||||
|
||||
#creazione folder di Log se non già esistente
|
||||
if (Test-Path $logFolder) {
|
||||
}
|
||||
else {
|
||||
New-Item $logFolder -ItemType Directory
|
||||
}
|
||||
|
||||
#funzione locale per log su file e output su terminale
|
||||
Function WriteLogOutput {
|
||||
Param ([string]$logString)
|
||||
#compongo path per file di log
|
||||
$logPath = Join-Path $logFolder $logFile
|
||||
#scrivo su file la stringa se $logType=1
|
||||
if ($logType -eq 1) {
|
||||
Add-content $logPath -value "$logString"
|
||||
}
|
||||
#scrivo su terminale la stringa se $terminalOutput=1
|
||||
if ($terminalOutput -eq 1) {
|
||||
Write-Output($logString)
|
||||
}
|
||||
}
|
||||
|
||||
#rilevo tempo locale e differenza PDC, restituisco in secondi
|
||||
$localTime, $timeDifferencePDC = (& w32tm /stripchart /computer:$PDC /samples:1 /dataonly)[-1].Trim("s") -split ',\s*'
|
||||
#rilevo tempo locale e differenza BDC, restituisco in secondi
|
||||
$localTime, $timeDifferenceBDC = (& w32tm /stripchart /computer:$BDC /samples:1 /dataonly)[-1].Trim("s") -split ',\s*'
|
||||
|
||||
#scrivo log data e ora
|
||||
WriteLogOutput ""
|
||||
WriteLogOutput "Script Execution: $localTime"
|
||||
|
||||
#invio a zabbix i dati
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s $ZabbixHost -k W32.TimeDifferencePDC -o $timeDifferencePDC
|
||||
& "C:\Program Files\Zabbix Agent\zabbix_sender.exe" -z zabproxy.ufficio -s $ZabbixHost -k W32.TimeDifferenceBDC -o $timeDifferenceBDC
|
||||
|
||||
#output differenza PDC
|
||||
WriteLogOutput "Time Difference W2022PDC: $timeDifferencePDC s"
|
||||
#output differenza BDC
|
||||
WriteLogOutput "Time Difference W2022BDC: $timeDifferenceBDC s"
|
||||
WriteLogOutput ""
|
||||
Reference in New Issue
Block a user