Login

Monitoring django-sphinx for Nagios

Author:
johnnoone
Posted:
April 7, 2009
Language:
Python
Version:
1.0
Score:
2 (after 2 ratings)

This snippet is used to monitor sphinx status 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

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

class Command(BaseCommand):
    option_list = BaseCommand.option_list + (
        make_option('--log', '-l', dest='log', action="store_true", default=False,
            help=u"prints nagios alert level."),
    )
    
    help = u"Sphinx's administration tools."
    
    output_transaction = True
    
    def handle(self, **options):
        
        if options.get('log', False):
            return self.log()
    
    def log(self):
        """ Prints the sphinx state for Nagios
        """
        
        from django.db import models
        ModelToMonitor = models.get_model('app_name','ModelName')
        
        try:
            # doit retourner la 1re entree de l'index sphinx
            job = ModelToMonitor.search.query("").set_options(maxmatches=1, mode=6, limit=1)[0]
        except:
            return self.log_exit(2)
        
        return self.log_exit(0)
    
    def log_exit(self, lvl=2):
        if lvl == 0:
            print "OK: Sphinx is up"
        else:
            print "CRITICAL: Sphinx is down"
        sys.exit(lvl)
    

More like this

  1. Template tag - list punctuation for a list of items by shapiromatron 3 months, 1 week ago
  2. JSONRequestMiddleware adds a .json() method to your HttpRequests by cdcarter 3 months, 2 weeks ago
  3. Serializer factory with Django Rest Framework by julio 10 months, 1 week ago
  4. Image compression before saving the new model / work with JPG, PNG by Schleidens 11 months ago
  5. Help text hyperlinks by sa2812 11 months, 3 weeks ago

Comments

Please login first before commenting.