- 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
- Automatically setup raw_id_fields ForeignKey & OneToOneField by agusmakmun 8 months ago
- Crispy Form by sourabhsinha396 8 months, 4 weeks ago
- ReadOnlySelect by mkoistinen 9 months, 1 week ago
- Verify events sent to your webhook endpoints by santos22 10 months, 1 week ago
- Django Language Middleware by agusmakmun 10 months, 2 weeks ago
Comments
Please login first before commenting.