forked from GithubBackups/healthchecks
MySQL version of trigger, setup instructions in README
This commit is contained in:
parent
4ccbac7e4a
commit
71b5e1ef87
48
README.md
48
README.md
@ -1,13 +1,53 @@
|
|||||||
# healthchecks
|
# healthchecks
|
||||||
|
|
||||||
healthchecks is a watchdog for your cron jobs. It's a web server that listens for pings from your cron jobs, plus a web interface.
|
healthchecks is a watchdog for your cron jobs. It's a web server that listens for pings from your cron jobs, plus a web interface.
|
||||||
|
|
||||||
It is live here: [http://healthchecks.io/](http://healthchecks.io/)
|
It is live here: [http://healthchecks.io/](http://healthchecks.io/)
|
||||||
|
|
||||||
The building blocks are:
|
The building blocks are:
|
||||||
|
|
||||||
* Python 3
|
* Python 2 or Python 3
|
||||||
* virtualenv
|
|
||||||
* Django 1.8
|
* Django 1.8
|
||||||
* PostgreSQL
|
* PostgreSQL or MySQL
|
||||||
|
|
||||||
|
## Setting Up for Development
|
||||||
|
|
||||||
|
These are instructions for setting up HealthChecks Django app
|
||||||
|
in development environment.
|
||||||
|
|
||||||
|
* prepare directory for project code and virtualenv:
|
||||||
|
|
||||||
|
$ mkdir -p ~/webapps
|
||||||
|
$ cd ~/webapps
|
||||||
|
|
||||||
|
* prepare virtual environment
|
||||||
|
(with virtualenv you get pip, we'll use it soon to install requirements):
|
||||||
|
|
||||||
|
$ virtualenv --python=python3 hc-venv
|
||||||
|
$ source hc-venv/bin/activate
|
||||||
|
|
||||||
|
* check out project code:
|
||||||
|
|
||||||
|
$ git clone git@github.com:healthchecks/healthchecks.git
|
||||||
|
|
||||||
|
* install requirements (Django, ...) into virtualenv:
|
||||||
|
|
||||||
|
$ pip install -r healthchecks/requirements.txt
|
||||||
|
|
||||||
|
* make sure PostgreSQL server is installed and running, create
|
||||||
|
database "hc":
|
||||||
|
|
||||||
|
$ psql --user postgres
|
||||||
|
postgres=# create database hc;
|
||||||
|
|
||||||
|
* create database tables, triggers, superuser:
|
||||||
|
|
||||||
|
$ cd ~/webapps/healthchecks
|
||||||
|
$ ./manage.py migrate
|
||||||
|
$ ./manage.py ensuretriggers
|
||||||
|
$ ./manage.py createsuperuser
|
||||||
|
|
||||||
|
* run development server:
|
||||||
|
|
||||||
|
$ ./manage.py runserver
|
||||||
|
|
||||||
|
@ -2,26 +2,45 @@ from django.core.management.base import BaseCommand
|
|||||||
from django.db import connection
|
from django.db import connection
|
||||||
|
|
||||||
|
|
||||||
|
def _pg(cursor):
|
||||||
|
cursor.execute("""
|
||||||
|
CREATE OR REPLACE FUNCTION update_alert_after()
|
||||||
|
RETURNS trigger AS $update_alert_after$
|
||||||
|
BEGIN
|
||||||
|
IF NEW.last_ping IS NOT NULL THEN
|
||||||
|
NEW.alert_after := NEW.last_ping + NEW.timeout + NEW.grace;
|
||||||
|
END IF;
|
||||||
|
RETURN NEW;
|
||||||
|
END;
|
||||||
|
$update_alert_after$ LANGUAGE plpgsql;
|
||||||
|
|
||||||
|
DROP TRIGGER IF EXISTS update_alert_after ON api_check;
|
||||||
|
|
||||||
|
CREATE TRIGGER update_alert_after
|
||||||
|
BEFORE INSERT OR UPDATE OF last_ping, timeout, grace ON api_check
|
||||||
|
FOR EACH ROW EXECUTE PROCEDURE update_alert_after();
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
|
def _mysql(cursor):
|
||||||
|
cursor.execute("""
|
||||||
|
DROP TRIGGER IF EXISTS update_alert_after;
|
||||||
|
|
||||||
|
CREATE TRIGGER update_alert_after
|
||||||
|
BEFORE UPDATE ON api_check
|
||||||
|
FOR EACH ROW SET NEW.alert_after = NEW.last_ping + INTERVAL (NEW.timeout + NEW.grace) MICROSECOND;
|
||||||
|
""")
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
help = 'Ensures triggers exist in database'
|
help = 'Ensures triggers exist in database'
|
||||||
|
|
||||||
def handle(self, *args, **options):
|
def handle(self, *args, **options):
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
|
|
||||||
cursor.execute("""
|
if connection.vendor == "postgresql":
|
||||||
CREATE OR REPLACE FUNCTION update_alert_after()
|
_pg(cursor)
|
||||||
RETURNS trigger AS $update_alert_after$
|
print("Created PostgreSQL trigger")
|
||||||
BEGIN
|
if connection.vendor == "mysql":
|
||||||
IF NEW.last_ping IS NOT NULL THEN
|
_mysql(cursor)
|
||||||
NEW.alert_after := NEW.last_ping + NEW.timeout + NEW.grace;
|
print("Created MySQL trigger")
|
||||||
END IF;
|
|
||||||
RETURN NEW;
|
|
||||||
END;
|
|
||||||
$update_alert_after$ LANGUAGE plpgsql;
|
|
||||||
|
|
||||||
DROP TRIGGER IF EXISTS update_alert_after ON api_check;
|
|
||||||
|
|
||||||
CREATE TRIGGER update_alert_after
|
|
||||||
BEFORE INSERT OR UPDATE OF last_ping, timeout, grace ON api_check
|
|
||||||
FOR EACH ROW EXECUTE PROCEDURE update_alert_after();
|
|
||||||
""")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user