~jonasvp/monjo/release-0.6

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
INSTALLATION
------------

Installation is pretty basic for now. You need:

- Python (tested on 2.5, 2.4 should work as well)
- Django's newforms-admin branch (http://code.djangoproject.com/wiki/NewformsAdminBranch)
- A database supported by Django. Sqlite should be fine. Just install the package python-sqlite2

If you want to install django under /opt use this command:

  svn co http://code.djangoproject.com/svn/django/branches/newforms-admin/ /opt/django

The directory /opt/django/django below that one needs to be on your Python path. If you don't have regular Django installed, simply link from your your site-packages directory:
 
  ln -s /opt/django/django /usr/lib/python2.5/site-packages/
  
To test, start a python shell:

  python
  
At the prompt, put

  >>> import django
  
If this doesn't throw an error, you should be fine.

Now edit the file settings_local.py in your monjo directory. You should at least set the ROOT_PATH directive to your monjo directory and change the ADMINS-setting. If you don't want to use Sqlite for a database, change the corresponding settings.

Then, from your monjo directory, run

  ./manage.py syncdb
  
This will create the database. To test, run

  ./manage.py runserver
  
This will run the test server on localhost:8000. If you're on a remote server you can use

  ./manage.py runserver [IP-Adress]:8000
  
This will make the test server on the external IP adress of the host. The test server is fine for simple use on your internal LAN. For real deployment, check the Django book at: http://djangobook.com/en/1.0/chapter20/

Last not least, you need to add a cron job that takes care of doing the actual service checking. The checks are done in separate threads in order to take as little time as possible. You need to edit your crontab (a user crontab is fine, it doesn't need to run as root) and add a line like this:

  */5 *  *   *   *     cd /opt/monjo; ./cron.py

This assumes that you installed monjo under /opt/monjo. The service will run every five minutes. The cronjob determines the minimum time between two checks of a service. If you're only checking every hour you can have the cron job run hourly as well.



How to add a new service?
-------------------------

First of all, you need to write a python function that can determine if the service is running on a certain host. Use any libraries and helpers you like. For instance, if you want to check if the MySQL database is running on a host, you might import the MySQL python library and try to connect to the server.

Define the function like this:

> import mysqldb
> def mysql(host):
>   ...

and drop it into a file called mysql.py in the directory monitor/services/. Finally, check the list of services defined in the file settings.py:

> SERVICES = (
>     ('ping', 'ping'),
>     ('smtp', 'SMTP'),
>     ('http', 'HTTP'),
> )

The first value defines the name of the file and function, the second value tells Monjo how to display the service in the drop-down list. For our hypothetical MySQL function you could change this to:

> SERVICES = (
>     ('ping', 'ping'),
>     ('smtp', 'SMTP'),
>     ('http', 'HTTP'),
>     ('mysql', 'MySQL'),
> )

That's it, you can now add monitors using this service.