Product SiteDocumentation Site

Documentation Djagios 0.13

Djagios on Fedora 12

Install Nagios 3.20 and Djagios 0.1.3 on Fedora 12

Jochen Maes

INUITS bvba

Robert Keersse

Don Bosco Leren en Werken

Legal Notice

Copyright © 2009 based on Jochen Maes website 'Djagios for all'.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. The original authors of this document, and Red Hat, designate the Fedora Project as the "Attribution Party" for purposes of CC-BY-SA. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the Infinity Logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
For guidelines on the permitted uses of the Fedora trademarks, refer to https://fedoraproject.org/wiki/Legal:Trademark_guidelines.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
All other trademarks are the property of their respective owners.
Abstract
A short overview and summary of the book's subject and purpose, traditionally no more than one paragraph long. Note: the abstract will appear in the front matter of your book and will also be placed in the description field of the book's RPM spec file.

1. Nagios
1.1. Prerequisites
1.2. Install Nagios
1.3. Configuration Nagios
1.4. Create nagios web account
1.5. Enable web interface for Nagios
1.6. Start apache
1.7. Start nagios
2. Djagios
2.1. Prerequisites
2.2. Install Djagios
2.3. Configuration
2.4. Setup database
2.5. Import Nagios config
2.6. Start Djagios
2.7. Export Nagios config
A. Revision History
Index

1. Nagios

1.1. Prerequisites

These packages are required for nagios: Apache web server, PHP, GCC compiler and GD development libraries. You can install them by this yum command.
yum install httpd php gcc glibc glibc-common gd gd-devel

1.2. Install Nagios

yum install nagios nagios-plugins-all

SELinux

The SELinux is enforcing by default. You need to disable it or configure it for nagios.
/etc/selinux/config
Reboot the machine after you modify the settings.

1.3. Configuration Nagios

For setting up Djagios I based myself upon the configuration documentation on the Nagios website for version 3. However the default config files on a default Nagios install contain mistakes against its own documentation. Following are the steps to be able to import the default (but incorrect) Nagios configuration:
Most of the errors are in the templates.cfg (located in /etc/nagios/objects):
  1. remove all occurances of 'failure_prediction_enabled'
  2. remove all occurances of 'parallelize_check'
  3. replace all occurances of 'retry_check_interval' with 'retry_interval'
  4. replace all occurances of 'normal_check_interval' with 'check_interval'
The last change is in nagios.cfg (located in /etc/nagios/), uncomment the line where the /etc/nagios/objects/windows.cfg is defined.
After doing these changes your default Nagios config should be importable.

1.4. Create nagios web account

create an nagiosadmin account for the web interface.
htpasswd -c /etc/nagios/passwd nagiosadmin

1.5. Enable web interface for Nagios

edit /etc/httpd/conf.d/nagios.conf
ScriptAlias /nagios/cgi-bin/ /usr/lib/nagios/cgi-bin/
<Directory /usr/lib/nagios/cgi-bin/>
...
   allow from 127.0.0.1
   allow from xxx.xxx.xxx.xxx/24
   AuthType Basic
...

Alias /nagios/ /usr/share/nagios/html/
<Directory /usr/share/nagios/html/>
...
   allow from 127.0.0.1
   allow from xxx.xxx.xxx.xxx/24
   AuthType Basic
...

1.6. Start apache

use following command:
service httpd start

Note

if you want apache to start automatically next time you boot up the system, you can use
chkconfig --levels 235 httpd on

1.7. Start nagios

use following command:
service nagios start

Note

if you want nagios to start automatically next time you boot up the system, you can use
chkconfig --levels 235 nagios on

2. Djagios

2.1. Prerequisites

  1. python-setuptools 0.6c9
  2. Django 1.1 (at least)
  3. MySQL (or other database supprted by Django)
install prerequites at Fedora 11:
yum install mysql mysql-server mod_python Django MySQL-python

2.2. Install Djagios

First download the version you wish to install at our download section.
Then run following commands:
tar xzf djagios-0.1.x.tar.gz
cd djagios-0.1.x
python setup.py install
This will install all the needed files for the djagios app. The media and template files are installed in /usr/share/djagios-0.1 for the 0.1.x versions.

2.3. Configuration

First you need to start a project for the installation. We will use /var/www/djagios/apps as project path. Run following commands:
cd /var/www/djagios/
django-admin startproject apps
Now you have setup your django environment.

2.3.1. Settings

We will need to edit the apps/settings.py file. Set following variables:
...
# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
MEDIA_ROOT = '/usr/share/djagios-0.1/media/'

# URL that handles the media served from MEDIA_ROOT. Make sure to use a
# trailing slash if there is a path component (optional in other cases).
# Examples: "http://media.lawrence.com", "http://example.com/media/"
MEDIA_URL = '/media'
LOGIN_URL='/login'
...
Also add ‘/usr/share/djagios-0.1/templates’ to the TEMPLATES_DIRS list and add 'django.contrib.admin' and ‘djagios.core’ to the INSTALLED_APPS list.
...
TEMPLATE_DIRS = (
    '/usr/share/djagios-0.1/templates'
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)
INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.admin',
    'djagios.core',
)
...

2.3.2. Urls

Now we need to make sure the apps/urls.py file contains the correct information. Below is a working example:
# Copyright (c) 2009 Jochen Maes
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

from django.conf.urls.defaults import *

from djagios.core import views
from djagios import config

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^admin/(.*)', admin.site.root),
    (r'^login/$', 'django.contrib.auth.views.login', {'template_name': '%s/login.html'%config.theme_name}),
    (r'^logout', 'django.contrib.auth.views.logout_then_login', {'login_url': '/login'},),
    (r'^@@media/(?P<path>.*)$', 'django.views.static.serve',
            {'document_root': '/usr/share/djagios-0.1/media/%s/'%config.theme_name}),
    (r'^hosttemplate/add', views.add_host_template),
    (r'^host/add', views.add_host),
    (r'^host/delete', views.delete_host),
    (r'^service/addhost', views.add_host_to_service),
    (r'^service/removehost', views.remove_host_from_service),
    (r'^json/servicesforhost/(?P<host_id>.*)/$',views.get_services_for_host ),
    (r'^$', views.home),
)

2.4. Setup database

2.4.1. Create database

In order to use djagios you need to create a database. I use following commands in MySQL:
[root@localhost djagios]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 428
Server version: 5.1.37 Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database djagios character set utf8 collate utf8_bin;
Query OK, 0 rows affected (0.01 sec)

mysql> create user 'djagios'@'localhost' identified by 'djagios';
Query OK, 0 rows affected (0.01 sec)

mysql> grant all on djagios.* to djagios;
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye

2.4.2. Djagios database settings

configure it in the apps/settings.py file
...
DATABASE_ENGINE = 'mysql'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
DATABASE_NAME = 'djagios'             # Or path to database file if using sqlite3.
DATABASE_USER = 'djagios'             # Not used with sqlite3.
DATABASE_PASSWORD = 'djagios'         # Not used with sqlite3.
DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
...

2.4.3. Create tables

Now we will create the tables for our applications:
python apps/manage.py syncdb
[root@localhost djagios]# python apps/manage.py syncdb
Creating table auth_permission
Creating table auth_group
...
...
Creating table core_hosttemplate

You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'root'): robert
E-mail address: robert@belbob.net
Password: 
Password (again): 
Superuser created successfully.

Installing index for auth.Permission model
Installing index for auth.Message model
...
...
Installing index for core.HostTemplate model
[root@localhost djagios]#

2.5. Import Nagios config

Export PYTHONPATH: the export makes sure that the setting module will be found.
export PYTHONPATH=/var/www/djagios/apps/
Make a link to import.py
ln -s /usr/lib/python2.6/site-packages/djagios/import.py apps/import.py
To import your current nagios configuration files execute following command with a user that has all access to the nagios files!
env DJANGO_SETTINGS_MODULE=settings python apps/import.py -s localhost -p /etc/nagios/nagios.cfg
INFO:root:Temporary directory /tmp/1fa3df12-9383-4a51-a7a3-cd63fb169621 created for the parsed config files
INFO:root:NagiosConfigParser initialized!
Initial save happend!

Nagios main config imported, starting with the other objects
INFO:root:Starting with host.cfg
INFO:root:Finished with host.cfg
...
...
INFO:root:Finished with contact.cfg
[root@localhost djagios]#
That should do it!
If however something is incorrect, please fix the config file and run this prior to retrying to import:
python apps/manage.py reset core

2.6. Start Djagios

use following command:
python apps/manage.py runserver 0.0.0.0:8000
[root@localhost djagios]# python apps/manage.py runserver 0.0.0.0:8000
Validating models...
0 errors found

Django version 1.1, using settings 'apps.settings'
Development server is running at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

2.7. Export Nagios config

When you change things to Djagios you need to export to a nagios config.

2.7.1. export.py

I have a basic export.py that I use:
# Djagios export
# Copyright (c) 2009 Jochen Maes
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

import sys
from djagios.common.utils import Exporter

e = Exporter()
e.export(sys.argv[1])

2.7.2. djagios_export.sh

A script for a simple export is shown below:
#!/bin/bash
#
# Djagios export script
# Copyright (c) 2009 Jochen Maes
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

cd /var/www/djagios/
export PYTHONPATH='/var/www/djagios/apps/'
export DJANGO_SETTINGS_MODULE='settings'
mkdir /tmp/nagios3
python apps/export.py /tmp/nagios3

2.7.3. Export files

Note

remove /tmp/nagios3 if it exists
use next command:
sh djagios_export.sh
check new nagios configuration
nagios -v /tmp/nagios3/nagios.cfg
Nagios Core 3.2.0
Copyright (c) 2009 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-12-2009
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config directory '/tmp/nagios3/objects'...
Processing object config file '/tmp/nagios3/objects/contact.cfg'...
Processing object config file '/tmp/nagios3/objects/contactgroup.cfg'...
Processing object config file '/tmp/nagios3/objects/service.cfg'...
Processing object config file '/tmp/nagios3/objects/timeperiod.cfg'...
Processing object config file '/tmp/nagios3/objects/command.cfg'...
Processing object config file '/tmp/nagios3/objects/hostgroup.cfg'...
Processing object config file '/tmp/nagios3/objects/host.cfg'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
	Checked 17 services.
Checking hosts...
	Checked 4 hosts.
Checking host groups...
	Checked 2 host groups.
Checking service groups...
	Checked 0 service groups.
Checking contacts...
	Checked 1 contacts.
Checking contact groups...
	Checked 1 contact groups.
Checking service escalations...
	Checked 0 service escalations.
Checking service dependencies...
	Checked 0 service dependencies.
Checking host escalations...
	Checked 0 host escalations.
Checking host dependencies...
	Checked 0 host dependencies.
Checking commands...
	Checked 24 commands.
Checking time periods...
	Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

2.7.4. use new nagios.cfg

replace /etc/nagios/nagios.cfg with /tmp/nagios3/nagios.cfg

objects

the new /etc/nagios/nagios.cfg use /tmp/nagios3/objects
restart nagios
service nagios restart

A. Revision History

Revision History
Revision 1.0.12009-10-18Robert Keersse
Configuration Nagios (Special thanks to sejo)
Revision 1.0.22009-10-23Robert Keersse
Export Nagios configuration (Special thanks to sejo)
Revision 1.0.32009-10-27Robert Keersse
Update to Djagios 0.1.3 Release
Revision 1.0.42009-12-16Robert Keersse
Update documentation to Fedora 12

Index