############################################################################## # SCRIPT DE RECUPERATION DES ALERTES D'UNE APPLIANCE HPONEVIEW ET MISE EN ETAT CLEARED # author: cjourdan # PARAMETRES: # $ApplianceName: Nom de l'appliance # $RessourceName: Nom de la ressource (Server,Enclosure ...). # $DomainName: Domaine AD. # $AlertSeverity: Critical, Warning, OK, Unknown, Disabled # $AlertState: Active, Locked, Cleared, Pending, Running, Completed, Interrupted, Error, Warning, Terminated, Killed. # $DescInclude: Chaine de caractère dans la champ Description a inclure dans la recherche. # $DescExclude: Chaine de caractère dans la champ Description a exclure de la recherche. # $DayOffset = Recuperer les alertes plus recente que J-DayOffset. # Apres Recuperation des alertes, le script demande validation pour mettre les alertes en état Cleared Param( [Parameter(Mandatory=$false)] $ApplianceName = "MyAppliance", [Parameter(Mandatory=$false)] # Server,Enclosure ... $RessourceName = "MyResource", [Parameter(Mandatory=$false)] $DomainName = "MyDomain", [Parameter(Mandatory=$false)] $AlertSeverity = "Critical", [Parameter(Mandatory=$false)] $AlertState = "Cleared", $DescInclude = "*", $DescExclude = "azerty", $DayOffset = 2 ) $user = Read-Host -Prompt "Enter MyDomain Credential without Domain" $passwd = Read-Host -Prompt "Password" -AsSecureString if (-not (get-module HPOneview.200)) { Import-Module HPOneView.200 } # Connexion a l'appliance OneView if (-not($global:ConnectedSessions)) { Connect-HPOVMgmt -Hostname $ApplianceName -UserName $user -Password $passwd -AuthLoginDomain $DomainName } write-host -BackgroundColor White -ForegroundColor Blue "APPLIANCE ONEVIEW: $ApplianceName"`n # NB: Preciser au minimum un filtre de recherche avant le '|' afin de reduire le temps de recuperation des alertes Try { $Alerts = Get-HPOVAlert -ApplianceConnection $ApplianceName -Severity $AlertSeverity | Where-Object {$_.AlertState -eq $AlertState ` -AND $_.associatedresource -like "*$RessourceName*" ` -AND $_.description -like "*$DescInclude*" ` -AND $_.description -notlike "*$DescExclude*"` -AND $([datetime]$_.created) -gt $(get-date).AddDays(-$DayOffset) } $FormAlerts = foreach ($alert in $Alerts) { Write-output "DESCRIPTION: "$alert.description"" ; Write-Output "SEVERITY: "$alert.severity"" ; Write-Output "STATE: "$alert.alertState"" ; Write-Output "CREATED: "(get-date -format G $alert.Created)"" ; Write-Output "CLEARED: "(get-date -format G $alert.clearedtime)"" ; Write-Output "RESSOURCE_NAME: "$alert.associatedresource.resourcename"" ; Write-Output "APPLIANCE: "$alert.ApplianceConnection.Name"" ; Write-Output "" ; Write-Output "*******************" ; Write-Output "" } write-host -BackgroundColor White -ForegroundColor Blue "CRITERES DE RECHERCHE: Resource: $RessourceName / Severity: $AlertSeverity / Status: $AlertState / a inclure: $DescInclude / a exclure: $DescExclude / Plus recentes que: J-$DayOffset"`n $count=$Alerts | Measure-Object | select count -ExpandProperty count write-host -BackgroundColor White -ForegroundColor Blue "NOMBRE D ALERTES: $count" `n $FormAlerts } Catch { Write-Error -ErrorRecord $_ -ErrorAction Stop } $answer = Read-Host -Prompt "VOULEZ VOUS MODIFIER L'ETAT DES CES ALERTES EN ETAT 'CLEARED' ?: Y/N" switch($answer) { "Y" {"MISE EN ETAT CLEARED"} "N" {"AUCUNE ACTION" ; exit} default {"MAUVAISE REPONSE - AUCUNE ACTION" ; exit} } # Clear Alerts Try { $updatedAlert = $Alerts | set-HPOVAlert -Cleared } Catch { Write-Error -ErrorRecord $_ -ErrorAction Stop } $updatedAlert Write-Host -ForegroundColor Green "MISE EN ETAT CLEARED TERMINEE SANS ERREUR !"