1

A particular https endpoint I'm interested in is down. I want a way to monitor when it comes back up, and get an audible alert when that happens. How do I do that in Windows?

  • Write a program that attempts to make an https connection to the address. When the status goes from Red to Green (in other words from being down to being up) make it play a sound effect. – Ramhound Jan 12 '17 at 15:26
  • I could, but why bother? I like the power of Lego bricks - see my answer on how I did it. – Cristian Diaconescu Jan 12 '17 at 16:21
  • You asked, "How do I do that in Windows?", I told you how I would do it. – Ramhound Jan 12 '17 at 17:27
  • Why the downvote? This is a perfectly valid question. – Jens Ehrich Jan 24 at 14:54
1

Another option: use httping

It has a version for Windows, nice colored output, and can beep:

httping --audible-ping --colors --url http://google.com

enter image description here

| improve this answer | |
0

TL;DR

  • Download curl
  • run this in cmd.exe:

    c:\> echo echo ^G > beep.bat
    c:\> for /L %x in () do ( curl --insecure https://endpoi.nt > nul && call beep )

That's Ctrl-G. You can't copy that character from above, you actually need to type Ctrl-G

Long story

I want to make this work from the command line. There are a couple things to solve.

  1. How to access an http(s) endpoint from cmd line?

    c:\> curl http://the.site

    Is it an https endpoint that's missing the correct certificates?

    c:\> curl --insecure https://the.site

    Skip the output?

    c:\> curl http://the.site > nul
  2. How to make a sound from the command line?

    c:\> echo ^G

    That's Ctrl+G

  3. How to conditionally beep when the curl comand succeeds?

    c:\> curl http://the.site && echo ^G

    What if you want the beep when it fails?

    c:\> curl http://the.site || echo ^G
  4. How do you run something in a loop?

    Use for /L %x in (start,step,end) without specifying start, step, end:

    c:\> for /L %x in () do ( echo again ) 
  5. Putting echo ^G inside the body of the loop outputs it to the console and thus makes a beep sound regardless of the curl command failing or not.
    We must therefore find a way to beep without directly outputting the ^G character.

    c:\> echo echo ^G > beep.bat 

    You can now make a beep sound just by calling beep.

  6. Putting it all together:

c:\> for /L %x in () do ( curl --insecure https://endpoi.nt > nul && call beep )
| improve this answer | |
  • 1
    I would suggest a few elaborations. (1) Keep a flag to remember the previous curl completion status, so that you beep only on a transition. (2) Add a delay into the loop to prevent high network traffic and CPU use. (3) Maybe use one beep for up, three for down (you will need a short pause between). (4) Instead of Ctl-G, you can get any sounds you want with start [/wait] AudioFile, eg sounds in %SystemRoot%\Media. PS Great profile image, though I prefer bass clef! – AFH Jan 12 '17 at 17:50
  • @AFH Very good suggestions! For my particular use case, I wanted 'infinite beeps' when site is up, because I used it as an alarm clock! The joys of being 24h on call... As for high network traffic - again, in my scenario - the endpoint was load-balanced on a cluster of 300 VMs x 12 cores that had gone down (ouch), so DoS-ing it from my laptop on a consumer network was hardly an issue :) – Cristian Diaconescu Jan 13 '17 at 1:51
0

Regarding a beep in windows: if you use:: start [/wait] AudioFile, eg sounds in %SystemRoot%\Media" it will open a media player, which will cause problems. You can play a .wav with vbs script, which still works in Windows 10v1803. eg alarm05.vbs

' alarm sound
Set oVoice = CreateObject("SAPI.SpVoice")
set oSpFileStream = CreateObject("SAPI.SpFileStream")
oSpFileStream.Open "C:\Windows\Media\Alarm05.wav"
oVoice.SpeakStream oSpFileStream
oSpFileStream.Close

call this from a bat eg beep.bat

:: start a VBScript
start "" alarm05.vbs
exit

Complete Webcheck Version with Powershell eg checksite.ps1 right-click 'run with powershell'

# https://www.dennis-stepp.com/post/uricheck/   ps by Dennis Eugene Stepp, Jr.

# First we create the request.
$HTTP_Request = [System.Net.WebRequest]::Create('http://google.com')
# $HTTP_Request = [System.Net.WebRequest]::Create('http://google.off')

# We then get a response from the site.
$HTTP_Response = $HTTP_Request.GetResponse()

# We then get the HTTP code as an integer.
$HTTP_Status = [int]$HTTP_Response.StatusCode

If ($HTTP_Status -eq 200) {
    Write-Host "Site is OK!"
    [console]::beep(880,300)
}
Else {
    Write-Host "The Site may be down, please check!"
    [console]::beep(440,300)
}

# Finally, we clean up the http request by closing it.
$HTTP_Response.Close()

pause
| improve this answer | |
  • That answers only half of the question. – zx485 May 10 '19 at 19:48
0

A simple solution is to use Fping (https://github.com/dexit/fping-windows) with the -b flag to beep every time you get a response:

fping.exe host.domain.com -b

You can also use -b- to get a beep every time the ping fails which is useful when you want to be notified when a host goes down:

fping.exe 12.34.56.67 -b-

Fping also supports pinging multiple hosts and logging to a file, avoiding the need to open multiple command prompts.

NOTE: this uses ICMP so only shows whether the host is up, not the actual HTTP(S) endpoint, but may still be useful depending on your needs.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.