You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

319 lines
11 KiB

10 years ago
9 years ago
9 years ago
9 years ago
9 years ago
10 years ago
10 years ago
10 years ago
update Readme with pip install dependencies pip install will fail when you cannot compile some of the dependencies. one is gcc the other is the Python.h ``` Building wheels for collected packages: rcssmin, rjsmin Running setup.py bdist_wheel for rcssmin ... error Complete output from command /home/ubuntu/webapps/hc-venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-ipfho29k/rcssmin/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-u0q6mggl --python-tag cp36: running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-3.6 copying ./rcssmin.py -> build/lib.linux-x86_64-3.6 running build_ext building '_rcssmin' extension creating build/temp.linux-x86_64-3.6 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DEXT_MODULE=_rcssmin -UEXT_PACKAGE -I_setup/include -I/usr/include/python3.6m -I/home/ubuntu/webapps/hc-venv/include/python3.6m -c rcssmin.c -o build/temp.linux-x86_64-3.6/rcssmin.o unable to execute 'x86_64-linux-gnu-gcc': No such file or directory error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ---------------------------------------- Failed building wheel for rcssmin Running setup.py clean for rcssmin Running setup.py bdist_wheel for rjsmin ... error Complete output from command /home/ubuntu/webapps/hc-venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-ipfho29k/rjsmin/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-axnaq3w9 --python-tag cp36: running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-3.6 copying ./rjsmin.py -> build/lib.linux-x86_64-3.6 running build_ext building '_rjsmin' extension creating build/temp.linux-x86_64-3.6 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DEXT_MODULE=_rjsmin -UEXT_PACKAGE -I_setup/include -I/usr/include/python3.6m -I/home/ubuntu/webapps/hc-venv/include/python3.6m -c rjsmin.c -o build/temp.linux-x86_64-3.6/rjsmin.o unable to execute 'x86_64-linux-gnu-gcc': No such file or directory error: command 'x86_64-linux-gnu-gcc' failed with exit status 1 ``` ``` Running setup.py bdist_wheel for rjsmin ... error Complete output from command /home/ubuntu/webapps/hc-venv/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-cfntw7bo/rjsmin/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-ytqxu9_b --python-tag cp36: running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-3.6 copying ./rjsmin.py -> build/lib.linux-x86_64-3.6 running build_ext building '_rjsmin' extension creating build/temp.linux-x86_64-3.6 x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -DEXT_MODULE=_rjsmin -UEXT_PACKAGE -I_setup/include -I/usr/include/python3.6m -I/home/ubuntu/webapps/hc-venv/include/python3.6m -c rjsmin.c -o build/temp.linux-x86_64-3.6/rjsmin.o In file included from rjsmin.c:18:0: _setup/include/cext.h:34:10: fatal error: Python.h: No such file or directory #include "Python.h" ^~~~~~~~~~ compilation terminated. ```
6 years ago
10 years ago
  1. # healthchecks
  2. [![Build Status](https://travis-ci.org/healthchecks/healthchecks.svg?branch=master)](https://travis-ci.org/healthchecks/healthchecks)
  3. [![Coverage Status](https://coveralls.io/repos/healthchecks/healthchecks/badge.svg?branch=master&service=github)](https://coveralls.io/github/healthchecks/healthchecks?branch=master)
  4. ![Screenshot of Welcome page](/static/img/welcome.png?raw=true "Welcome Page")
  5. ![Screenshot of My Checks page](/static/img/my_checks.png?raw=true "My Checks Page")
  6. ![Screenshot of Period/Grace dialog](/static/img/period_grace.png?raw=true "Period/Grace Dialog")
  7. ![Screenshot of Cron dialog](/static/img/cron.png?raw=true "Cron Dialog")
  8. ![Screenshot of Integrations page](/static/img/channels.png?raw=true "Integrations Page")
  9. 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.
  10. It is live here: [http://healthchecks.io/](http://healthchecks.io/)
  11. The building blocks are:
  12. * Python 3
  13. * Django 2
  14. * PostgreSQL or MySQL
  15. ## Setting Up for Development
  16. These are instructions for setting up healthchecks Django app
  17. in development environment.
  18. * install dependencies (Debian/Ubuntu)
  19. $ sudo apt-get update
  20. $ sudo apt-get install -y gcc python3-dev
  21. * prepare directory for project code and virtualenv:
  22. $ mkdir -p ~/webapps
  23. $ cd ~/webapps
  24. * prepare virtual environment
  25. (with virtualenv you get pip, we'll use it soon to install requirements):
  26. $ python3 -m venv hc-venv
  27. $ source hc-venv/bin/activate
  28. * check out project code:
  29. $ git clone https://github.com/healthchecks/healthchecks.git
  30. * install requirements (Django, ...) into virtualenv:
  31. $ pip install -r healthchecks/requirements.txt
  32. * healthchecks is configured to use a SQLite database by default. To use
  33. PostgreSQL or MySQL database, create and edit `hc/local_settings.py` file.
  34. There is a template you can copy and edit as needed:
  35. $ cd ~/webapps/healthchecks
  36. $ cp hc/local_settings.py.example hc/local_settings.py
  37. * create database tables and the superuser account:
  38. $ cd ~/webapps/healthchecks
  39. $ ./manage.py migrate
  40. $ ./manage.py createsuperuser
  41. * run development server:
  42. $ ./manage.py runserver
  43. The site should now be running at `http://localhost:8080`
  44. To log into Django administration site as a super user,
  45. visit `http://localhost:8080/admin`
  46. ## Configuration
  47. Site configuration is loaded from environment variables. This is
  48. done in `hc/settings.py`. Additional configuration is loaded
  49. from `hc/local_settings.py` file, if it exists. You can create this file
  50. (should be right next to `settings.py` in the filesystem) and override
  51. settings, or add extra settings as needed.
  52. Configurations settings loaded from environment variables:
  53. | Environment variable | Default value | Notes
  54. | -------------------- | ------------- | ----- |
  55. | [SECRET_KEY](https://docs.djangoproject.com/en/2.1/ref/settings/#secret-key) | `"---"`
  56. | [DEBUG](https://docs.djangoproject.com/en/2.1/ref/settings/#debug) | `True` | Set to `False` for production
  57. | [ALLOWED_HOSTS](https://docs.djangoproject.com/en/2.1/ref/settings/#allowed-hosts) | `*` | Separate multiple hosts with commas
  58. | [DEFAULT_FROM_EMAIL](https://docs.djangoproject.com/en/2.1/ref/settings/#default-from-email) | `"[email protected]"`
  59. | USE_PAYMENTS | `False`
  60. | REGISTRATION_OPEN | `True`
  61. | DB | `"sqlite"` | Set to `"postgres"` or `"mysql"`
  62. | [DB_HOST](https://docs.djangoproject.com/en/2.1/ref/settings/#host) | `""` *(empty string)*
  63. | [DB_PORT](https://docs.djangoproject.com/en/2.1/ref/settings/#port) | `""` *(empty string)*
  64. | [DB_NAME](https://docs.djangoproject.com/en/2.1/ref/settings/#name) | `"hc"`
  65. | [DB_USER](https://docs.djangoproject.com/en/2.1/ref/settings/#user) | `"postgres"` or `"root"`
  66. | [DB_PASSWORD](https://docs.djangoproject.com/en/2.1/ref/settings/#password) | `""` *(empty string)*
  67. | [DB_CONN_MAX_AGE](https://docs.djangoproject.com/en/2.1/ref/settings/#conn-max-age) | `0`
  68. | DB_SSLMODE | `"prefer"` | PostgreSQL-specific, [details](https://blog.github.com/2018-10-21-october21-incident-report/)
  69. | DB_TARGET_SESSION_ATTRS | `"read-write"` | PostgreSQL-specific, [details](https://www.postgresql.org/docs/10/static/libpq-connect.html#LIBPQ-CONNECT-TARGET-SESSION-ATTRS)
  70. | EMAIL_HOST | `""` *(empty string)*
  71. | EMAIL_PORT | `"587"`
  72. | EMAIL_HOST_USER | `""` *(empty string)*
  73. | EMAIL_HOST_PASSWORD | `""` *(empty string)*
  74. | EMAIL_USE_TLS | `"True"`
  75. | SITE_ROOT | `"http://localhost:8000"`
  76. | SITE_NAME | `"Mychecks"`
  77. | MASTER_BADGE_LABEL | `"Mychecks"`
  78. | PING_ENDPOINT | `"http://localhost:8000/ping/"`
  79. | PING_EMAIL_DOMAIN | `"localhost"`
  80. | DISCORD_CLIENT_ID | `None`
  81. | DISCORD_CLIENT_SECRET | `None`
  82. | SLACK_CLIENT_ID | `None`
  83. | SLACK_CLIENT_SECRET | `None`
  84. | PUSHOVER_API_TOKEN | `None`
  85. | PUSHOVER_SUBSCRIPTION_URL | `None`
  86. | PUSHOVER_EMERGENCY_RETRY_DELAY | `300`
  87. | PUSHOVER_EMERGENCY_EXPIRATION | `86400`
  88. | PUSHBULLET_CLIENT_ID | `None`
  89. | PUSHBULLET_CLIENT_SECRET | `None`
  90. | TELEGRAM_BOT_NAME | `"ExampleBot"`
  91. | TELEGRAM_TOKEN | `None`
  92. | TWILIO_ACCOUNT | `None`
  93. | TWILIO_AUTH | `None`
  94. | TWILIO_FROM | `None`
  95. | PD_VENDOR_KEY | `None`
  96. | TRELLO_APP_KEY | `None`
  97. Some useful settings keys to override are:
  98. `SITE_ROOT` is used to build fully qualified URLs for pings, and for use in
  99. emails and notifications. Example:
  100. ```python
  101. SITE_ROOT = "https://my-monitoring-project.com"
  102. ```
  103. `SITE_NAME` has the default value of "Mychecks" and is used throughout
  104. the templates. Replace it with your own name to personalize your installation.
  105. Example:
  106. ```python
  107. SITE_NAME = "My Monitoring Project"
  108. ```
  109. `REGISTRATION_OPEN` controls whether site visitors can create new accounts.
  110. Set it to `False` if you are setting up a private healthchecks instance, but
  111. it needs to be publicly accessible (so, for example, your cloud services
  112. can send pings).
  113. If you close new user registration, you can still selectively invite users
  114. to your team account.
  115. ## Database Configuration
  116. Database configuration is loaded from environment variables. If you
  117. need to use a non-standard configuration, you can override the
  118. database configuration in `hc/local_settings.py` like so:
  119. ```python
  120. DATABASES = {
  121. 'default': {
  122. 'ENGINE': 'django.db.backends.postgresql',
  123. 'NAME': 'your-database-name-here',
  124. 'USER': 'your-database-user-here',
  125. 'PASSWORD': 'your-database-password-here',
  126. 'TEST': {'CHARSET': 'UTF8'},
  127. 'OPTIONS': {
  128. ... your custom options here ...
  129. }
  130. }
  131. }
  132. ```
  133. ## Sending Emails
  134. healthchecks must be able to send email messages, so it can send out login
  135. links and alerts to users. Environment variables can be used to configure
  136. SMTP settings, or your may put your SMTP server configuration in
  137. `hc/local_settings.py` like so:
  138. ```python
  139. EMAIL_HOST = "your-smtp-server-here.com"
  140. EMAIL_PORT = 587
  141. EMAIL_HOST_USER = "username"
  142. EMAIL_HOST_PASSWORD = "password"
  143. EMAIL_USE_TLS = True
  144. ```
  145. For more information, have a look at Django documentation,
  146. [Sending Email](https://docs.djangoproject.com/en/1.10/topics/email/) section.
  147. ## Receiving Emails
  148. healthchecks comes with a `smtpd` management command, which starts up a
  149. SMTP listener service. With the command running, you can ping your
  150. checks by sending email messages
  151. to `[email protected]` email addresses.
  152. Start the SMTP listener on port 2525:
  153. $ ./manage.py smtpd --port 2525
  154. Send a test email:
  155. $ curl --url 'smtp://127.0.0.1:2525' \
  156. --mail-from '[email protected]' \
  157. --mail-rcpt '[email protected]' \
  158. -F '='
  159. ## Sending Status Notifications
  160. healtchecks comes with a `sendalerts` management command, which continuously
  161. polls database for any checks changing state, and sends out notifications as
  162. needed. Within an activated virtualenv, you can manually run
  163. the `sendalerts` command like so:
  164. $ ./manage.py sendalerts
  165. In a production setup, you will want to run this command from a process
  166. manager like [supervisor](http://supervisord.org/) or systemd.
  167. ## Database Cleanup
  168. With time and use the healthchecks database will grow in size. You may
  169. decide to prune old data: inactive user accounts, old checks not assigned
  170. to users, records of outgoing email messages and records of received pings.
  171. There are separate Django management commands for each task:
  172. * Remove old records from `api_ping` table. For each check, keep 100 most
  173. recent pings:
  174. ```
  175. $ ./manage.py prunepings
  176. ```
  177. * Remove checks older than 2 hours that are not assigned to users. Such
  178. checks are by-products of random visitors and robots loading the welcome
  179. page and never setting up an account:
  180. ```
  181. $ ./manage.py prunechecks
  182. ```
  183. * Remove old records of sent notifications. For each check, remove
  184. notifications that are older than the oldest stored ping for same check.
  185. ```
  186. $ ./manage.py prunenotifications
  187. ```
  188. * Remove user accounts that match either of these conditions:
  189. * Account was created more than 6 months ago, and user has never logged in.
  190. These can happen when user enters invalid email address when signing up.
  191. * Last login was more than 6 months ago, and the account has no checks.
  192. Assume the user doesn't intend to use the account any more and would
  193. probably *want* it removed.
  194. ```
  195. $ ./manage.py pruneusers
  196. ```
  197. When you first try these commands on your data, it is a good idea to
  198. test them on a copy of your database, not on the live database right away.
  199. In a production setup, you should also have regular, automated database
  200. backups set up.
  201. ## Integrations
  202. ### Discord
  203. To enable Discord integration, you will need to:
  204. * register a new application on https://discordapp.com/developers/applications/me
  205. * add a redirect URI to your Discord application. The URI format is
  206. `SITE_ROOT/integrations/add_discord/`. For example, if you are running a
  207. development server on `localhost:8000` then the redirect URI would be
  208. `http://localhost:8000/integrations/add_discord/`
  209. * Look up your Discord app's Client ID and Client Secret. Put them
  210. in `DISCORD_CLIENT_ID` and `DISCORD_CLIENT_SECRET` environment
  211. variables.
  212. ### Pushover
  213. To enable Pushover integration, you will need to:
  214. * register a new application on https://pushover.net/apps/build
  215. * enable subscriptions in your application and make sure to enable the URL
  216. subscription type
  217. * put the application token and the subscription URL in
  218. `PUSHOVER_API_TOKEN` and `PUSHOVER_SUBSCRIPTION_URL` environment
  219. variables
  220. ### Telegram
  221. * Create a Telegram bot by talking to the
  222. [BotFather](https://core.telegram.org/bots#6-botfather). Set the bot's name,
  223. description, user picture, and add a "/start" command.
  224. * After creating the bot you will have the bot's name and token. Put them
  225. in `TELEGRAM_BOT_NAME` and `TELEGRAM_TOKEN` environment variables.
  226. * Run `settelegramwebhook` management command. This command tells Telegram
  227. where to forward channel messages by invoking Telegram's
  228. [setWebhook](https://core.telegram.org/bots/api#setwebhook) API call:
  229. ```
  230. $ ./manage.py settelegramwebhook
  231. Done, Telegram's webhook set to: https://my-monitoring-project.com/integrations/telegram/bot/
  232. ```
  233. For this to work, your `SITE_ROOT` needs to be correct and use "https://"
  234. scheme.