Login

Monitoring django-sphinx for Nagios

Author:
johnnoone
Posted:
April 7, 2009
Language:
Python
Version:
1.0
Tags:
sphinx management nagios monitoring django-sphinx
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. Script factory for monitoring django-sphinx with Nagios by johnnoone 6 years, 4 months ago
  2. Auto-documenting Django Models with Sphinx by Voightkampff 4 years ago
  3. Sphinx Search ORM by zeeg 8 years, 3 months ago
  4. Testing for failure in management commands by David 5 years ago
  5. Test Integration for mako templates by eriklee 6 years, 9 months ago

Comments

Please login first before commenting.