From baccf4dcfecd8e0e9e11a6d0362d692065111723 Mon Sep 17 00:00:00 2001 From: lub Date: Fri, 2 Apr 2021 10:59:29 +0200 Subject: [PATCH] add check if there is something to failover --- failover.ps1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/failover.ps1 b/failover.ps1 index aa7afe5..bd01752 100644 --- a/failover.ps1 +++ b/failover.ps1 @@ -4,6 +4,12 @@ $nodeList = docker node ls --format '{{json .}}'| ConvertFrom-Json | ForEach-Obj docker node inspect $_.ID | ConvertFrom-Json } $onlineNodeList = $nodeList | Where-Object {$_.Spec.Availability -eq 'active'} +$offlineNodeList = $nodeList | Where-Object {$_.Spec.Availability -ne 'active'} + +if (!$offlineNodeList.Count) { + Write-Output 'all hosts online, nothing to failover' + exit +} $failoverAddressList = (Invoke-RestMethod -Uri 'https://robot-ws.your-server.de/failover' -Authentication Basic -Credential $hetznerCredentials).failover $offlineAddressList = $failoverAddressList | Where-Object active_server_ip -notin $onlineNodeList.Status.Addr