Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SiteMonitor

A Windows Service that periodically checks whether a website is responding, and sends an email alert when the site goes down or comes back up.

What it does

  • Polls a configured URL on a fixed interval (default 5 minutes).
  • Treats any response other than HTTP 200 — or a failure to connect at all — as "down."
  • Sends an email when the site's state changes (up→down or down→up), so an ongoing outage produces a single alert rather than one per check.
  • Logs activity to the Windows Event Log when running as a service, or to the console when run in interactive mode.

Requirements

  • .NET Framework 4.7.2
  • A sending email account. Gmail requires an app password (not your normal password), which means 2-Step Verification must be enabled on the account.

Setup

  1. Clone the repo.

  2. Copy SiteMonitor/App.config.template to SiteMonitor/App.config.

  3. Fill in your own values in App.config:

    Key Description
    MonitorUrl The site to check, e.g. https://example.com/
    SmtpHost SMTP server, e.g. smtp.gmail.com
    SmtpPort SMTP port, e.g. 587
    SmtpUser Sending account username
    SmtpPassword App password for the sending account
    EmailFrom From address
    EmailTo Where alerts are sent
    PollIntervalMs Check interval in milliseconds (300000 = 5 min)

    App.config is gitignored so your credentials never get committed. Only the template with placeholder values lives in the repo.

Running in development (console mode)

Currently it runs as a Windows Service with the steps later in the document, but it runs as a console app so you can see log output and test changes quickly if you edit the csproj and change the Output Type as below:

<OutputType>WinExe</OutputType>  <!-- For Windows Service -->
<OutputType>Exe</OutputType>     <!-- For debugging in console -->

For testing, set PollIntervalMs to something short (e.g. 5000) and point MonitorUrl at a test endpoint (e.g. https://httpbin.org/status/500 for a failure) to watch the down/recovered logic fire.

Installing as a Windows Service

Build the project, then from an Administrator command prompt:

sc create SiteMonitor binPath= "C:\full\path\to\SiteMonitor.exe"
sc start SiteMonitor

Manage it with:

sc stop SiteMonitor
sc delete SiteMonitor

View activity in Event Viewer (eventvwr.msc) under the Application log, source MySource.

Notes

  • Credentials are stored in plaintext in App.config. This keeps them out of source control but is not encryption; secure the machine accordingly.

About

Tracks a website, sends an email to a users email if the websites state changes or does not return a 200 code.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages