Can someone explain what I'm missing. I'm trying to do a simple PS script running remotely on the monitored via Invoke-Command. The script is just testing a web URL for availability.

However, the script always shows as In Error (x days) and it never sends an OK alert even though I'm trying to tell it to do that.

Here's my code: NOTE: please swap a usable URL as I have XXX'ed the real URL.

$mon.FireActions = $True

$mon.Details = ""

$mon.SetMonitorStatus($mon.msOK)

$Server = $mon.computername

$Result = Invoke-Command -computername $Server -ScriptBlock { Try { (Invoke-WebRequest -uri "https://api-xxxxxx.duosecurity.com/auth/v2/ping").StatusCode } Catch { $($.Exception.Response.StatusCode.Value_) }}

If ($Result -eq 200) #200 is an OK response

{

$mon.Details = "Duo API Website is available on $Server"

#$mon.FireActions = $True #Commented out, no change

$mon.SetMonitorStatus($mon.msOK) #Set to OK status

}

Else # Any other response is an Error and should throw an Alert

{

$mon.Details = "Duo API Website is not available on $Server. The error code is: " + $Result

$mon.SetMonitorStatus($mon.msError) #Set to Alert status

#$mon.FireActions = $True #Commented out, no change

}

asked 11 May '21, 18:08

ashmite's gravatar image

ashmite
55411
accept rate: 50%

edited 12 May '21, 08:06

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×38
×16
×10

Asked: 11 May '21, 18:08

Seen: 1,011 times

Last updated: 12 May '21, 08:06