Login

Script factory for monitoring django-sphinx with Nagios

Author:
johnnoone
Posted:
April 7, 2009
Language:
Python
Version:
1.0
Tags:
sphinx script management nagios monitoring django-sphinx factory
Score:
2 (after 2 ratings)

This snippet is used to create a script for monitoring sphinx status with Nagios via django-sphinx.

It returns 0 (OK) or 2 (CRITICAL).

Remember to change this strings ModelToMonitor and app_name.

Usage :

./manage your-controls-command --log > /your/script/name.py

 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
import os
import sys
from optparse import make_option
from django.core.management.base import BaseCommand
from django.conf import settings

class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--log', '-l', dest='log', action="store_true", default=False,
            help=u"returns nagios alert's script."),
    )
    
    help = u"Sphinx's administration tools."

    output_transaction = True

    def handle(self, **options):
        
        if options.get('log', False):
            return self.log_script()
    
    def log_script(self):
        """docstring for log_script"""
        
        path = __file__
        for i in range(6):
            path = os.path.dirname(path)
        path2 = os.path.dirname(path)
        params = {
            'settings':os.environ['DJANGO_SETTINGS_MODULE'],
            'pythonpath':path,
            'pythonpath2':path2,
        }
        template = r"""#!/usr/bin/python
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'wanajob_pro.%(settings)s'

sys.path.append("%(pythonpath)s")
sys.path.append("%(pythonpath2)s")

from django.conf import settings
from django.db import models
from wanajob_pro.job_board.models import JobPost
# JobPost = models.get_model('job_board','JobPost')


def log_exit(lvl=2):
    if lvl == 0:
        print "OK: sphinx is up"
    else:
        print "CRITICAL: sphinx is down"
    sys.exit(lvl)




if __name__ == '__main__':
    try:
        job = JobPost.search.query("").set_options(maxmatches=1, mode=6, limit=1)[0]
    except:
        log_exit(2)
    
    log_exit(0)
""" % params
        
        print template

More like this

  1. Monitoring django-sphinx for Nagios by johnnoone 5 years, 10 months ago
  2. Command Line Script Launcher by dakrauth 6 years, 7 months ago
  3. Auto-documenting Django Models with Sphinx by Voightkampff 3 years, 6 months ago
  4. Sphinx Search ORM by zeeg 7 years, 9 months ago
  5. Django Database Migration Management Script by paltman 6 years, 8 months ago

Comments

Please login first before commenting.