meetjestad-monitor

command module
v0.0.0-...-d157cd7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2019 License: MIT Imports: 15 Imported by: 0

README

meetjestad-monitor

A health monitoring service for Meet je stad weather stations. Also check out the UI and monitor your own weather station.

Features

The service will query a number of sensors at a given frequency and send an email to the sensor's owner if one of the sensor's vitals is critical.

The following data is monitored:

  • Has the sensor sent any messages in the last six hours?
  • Is the sensor's battery voltage running low (<3.26V, configurable)?
  • Does the sensor report its location (i.e. do the messages include GPS data)?

Data about sensors and raised alarms is stored in Firebase and e-mails are sent with Mailgun.

Building

Run make meetjestad-monitor to download dependencies and compile the program for your platform.

The Makefile also offers a dist target to compile for Linux which is a common thing to do if you want to deploy the service somewhere.

Configuration & running

Config file

Create a YAML file called config.yaml and put it in the same directory as the binary.

The structure of the file is like this:

frequency: 1h # duration to wait between checks
mailer:
  secretPath: /path/to/file/with/mailgun.key
  domain: yourdomain.com # the domain Mailgun is configured for
  apibase: "https://api.eu.mailgun.net/v3" # for non-US domains

The frequency is a Go time.Duration string. A duration string is a possibly signed sequence of decimal numbers, each with optional fraction and a unit suffix, such as "300ms", "-1.5h" or "2h45m". Valid time units are "ns", "us" (or "µs"), "ms", "s", "m", "h". (documentation)

Mailgun API key and domain

Currently the service uses Mailgun for sending alerts. You need an active Mailgun account and it must be set up with a domain you own.

Once Mailgun is ready you have to configure this service as follows:

  • domain name
  • API key
  • API base URL

All of these values can be found on the domain's page in Mailgun.

Put the API key in a file on disk (remember to limit access to it) and set the mailer.secretPath to the path. If you leave the secret out, mails are printed to the log. This can be useful for testing.

Firestore

To give the service access to Firestore you need to set up a service account. Keep the config file in the same folder as the binary. Name the file serviceaccount.json.

The service requires two collections:

  • sensors:
    sensor_id     string
    threshold     number
    email_address string
    
  • alarms:
    gps     time
    offline time
    voltage time
    
Sensors

The threshold field is the value of battery voltage level that will trigger an alarm.

Alarms

All fields are timestamps indicating when the type last triggered an alarm.

Running

To run the service just execute meetjestad-monitor, for example ./meetjestad-monitor > service.log 2>&1 & to write the logs to a file called service.log.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL