[Pkg-nagios-changes] [SCM] UNNAMED PROJECT branch, debian/master, updated. 810edbdd3feedbfe37f4a65bee50b57b2f60fa2a
Gerhard Lausser
gerhard.lausser at consol.de
Tue Feb 28 22:21:37 UTC 2012
The following commit has been merged in the debian/master branch:
commit 698ffefa06cae8a747130e76e7946794a7e2be36
Author: Gerhard Lausser <gerhard.lausser at consol.de>
Date: Sat Feb 18 02:18:02 2012 +0100
Add missing lql operators to the logstore backends
diff --git a/shinken/modules/livestatus_broker/livestatus_query.py b/shinken/modules/livestatus_broker/livestatus_query.py
index 8a24103..32efa34 100644
--- a/shinken/modules/livestatus_broker/livestatus_query.py
+++ b/shinken/modules/livestatus_broker/livestatus_query.py
@@ -747,7 +747,6 @@ class LiveStatusQuery(object):
# The filters are closures.
# Add parameter Class (Host, Service), lookup datatype (default string), convert reference
def eq_filter(item):
- #print "eq_filter %s %s(%s) == %s(%s)" % (attribute, type(getattr(item, attribute)(self)), getattr(item, attribute)(self), type(reference), reference)
try:
return getattr(item, attribute)(self) == reference
except Exception:
@@ -756,16 +755,32 @@ class LiveStatusQuery(object):
else:
raise LiveStatusQueryError(450, attribute.replace('lsm_', ''))
+ def match_filter(item):
+ try:
+ p = re.compile(reference)
+ return p.search(getattr(item, attribute)(self))
+ except Exception:
+ raise LiveStatusQueryError(450, attribute.replace('lsm_', ''))
+
def eq_nocase_filter(item):
- return getattr(item, attribute)(self).lower() == reference.lower()
+ try:
+ return getattr(item, attribute)(self).lower() == reference.lower()
+ except Exception:
+ if hasattr(item, attribute):
+ return getattr(item.__class__, attribute).im_func.default == reference
+ else:
+ raise LiveStatusQueryError(450, attribute.replace('lsm_', ''))
- def ne_filter(item):
- #print "ne_filter %s %s(%s) != %s(%s)" % (attribute, type(getattr(item, attribute)(self)), getattr(item, attribute)(self), type(reference), reference)
+ def match_nocase_filter(item):
+ p = re.compile(reference, re.I)
+ return p.search(getattr(item, attribute)(self))
+
+ def lt_filter(item):
try:
- return getattr(item, attribute)(self) != reference
+ return getattr(item, attribute)(self) < reference
except Exception:
if hasattr(item, attribute):
- return getattr(item.__class__, attribute).im_func.default != reference
+ return getattr(item.__class__, attribute).im_func.default < reference
else:
raise LiveStatusQueryError(450, attribute.replace('lsm_', ''))
@@ -778,50 +793,44 @@ class LiveStatusQuery(object):
else:
raise LiveStatusQueryError(450, attribute.replace('lsm_', ''))
- def ge_filter(item):
+ def le_filter(item):
try:
- return getattr(item, attribute)(self) >= reference
+ return getattr(item, attribute)(self) <= reference
except Exception:
if hasattr(item, attribute):
- return getattr(item.__class__, attribute).im_func.default >= reference
+ return getattr(item.__class__, attribute).im_func.default <= reference
else:
raise LiveStatusQueryError(450, attribute.replace('lsm_', ''))
- def lt_filter(item):
+ def ge_contains_filter(item):
try:
- return getattr(item, attribute)(self) < reference
+ if getattr(item, attribute).im_func.datatype == list:
+ return reference in getattr(item, attribute)(self)
+ else:
+ return getattr(item, attribute)(self) >= reference
except Exception:
if hasattr(item, attribute):
- return getattr(item.__class__, attribute).im_func.default < reference
+ return getattr(item.__class__, attribute).im_func.default >= reference
else:
raise LiveStatusQueryError(450, attribute.replace('lsm_', ''))
- def le_filter(item):
+ def ne_filter(item):
try:
- return getattr(item, attribute)(self) <= reference
+ return getattr(item, attribute)(self) != reference
except Exception:
if hasattr(item, attribute):
- return getattr(item.__class__, attribute).im_func.default <= reference
+ return getattr(item.__class__, attribute).im_func.default != reference
else:
raise LiveStatusQueryError(450, attribute.replace('lsm_', ''))
- def match_filter(item):
- #print "ma_filter %s %s(%s) ~ %s(%s)" % (attribute, type(getattr(item, attribute)(self)), getattr(item, attribute)(self), type(reference), reference)
- try:
- p = re.compile(reference)
- return p.search(getattr(item, attribute)(self))
- except Exception:
- raise LiveStatusQueryError(450, attribute.replace('lsm_', ''))
+ def not_match_filter(item):
+ return not match_filter(item)
- def match_nocase_filter(item):
- p = re.compile(reference, re.I)
- return p.search(getattr(item, attribute)(self))
+ def not_eq_nocase_filter(item):
+ return eq_nocase_filter(item)
- def ge_contains_filter(item):
- if getattr(item, attribute).im_func.datatype == list:
- return reference in getattr(item, attribute)(self)
- else:
- return getattr(item, attribute)(self) >= reference
+ def not_match_nocase_filter(item):
+ return not match_nocase_filter(item)
def dummy_filter(item):
return True
@@ -855,22 +864,28 @@ class LiveStatusQuery(object):
if operator == '=':
return eq_filter
- elif operator == '!=':
- return ne_filter
- elif operator == '>':
- return gt_filter
- elif operator == '>=':
- return ge_contains_filter
- elif operator == '<':
- return lt_filter
- elif operator == '<=':
- return le_filter
- elif operator == '=~':
- return eq_nocase_filter
elif operator == '~':
return match_filter
+ elif operator == '=~':
+ return eq_nocase_filter
elif operator == '~~':
return match_nocase_filter
+ elif operator == '<':
+ return lt_filter
+ elif operator == '>':
+ return gt_filter
+ elif operator == '<=':
+ return le_filter
+ elif operator == '>=':
+ return ge_contains_filter
+ elif operator == '!=':
+ return ne_filter
+ elif operator == '!~':
+ return not_match_filter
+ elif operator == '!=~':
+ return ne_nocase_filter
+ elif operator == '!~~':
+ return not_match_nocase_filter
elif operator == 'dummy':
return dummy_filter
elif operator == 'sum':
diff --git a/shinken/modules/logstore_mongodb.py b/shinken/modules/logstore_mongodb.py
index e58b9cd..b61fcd3 100644
--- a/shinken/modules/logstore_mongodb.py
+++ b/shinken/modules/logstore_mongodb.py
@@ -257,43 +257,80 @@ class LiveStatusLogStoreMongoDB(BaseModule):
return '\'%s\' : \'\'' % (attribute,)
else:
return '\'%s\' : %s' % (attribute, reference)
- def ne_filter():
+
+ def match_filter():
+ return '\'%s\' : { \'$regex\' : %s }' % (attribute, reference)
+
+ def eq_nocase_filter():
if reference == '':
- return '\'%s\' : { \'$ne\' : '' }' % (attribute,)
+ return '\'%s\' : \'\'' % (attribute,)
else:
- return '\'%s\' : { \'$ne\' : %s }' % (attribute, reference)
- def gt_filter():
- return '\'%s\' : { \'$gt\' : %s }' % (attribute, reference)
- def ge_filter():
- return '\'%s\' : { \'$gte\' : %s }' % (attribute, reference)
+ return '\'%s\' : { \'$regex\' : %s, \'$options\' : \'i\' }' % (attribute, '^'+reference+'$')
+
+ def match_nocase_filter():
+ return '\'%s\' : { \'$regex\' : %s, \'$options\' : \'i\' }' % (attribute, reference)
+
def lt_filter():
return '\'%s\' : { \'$lt\' : %s }' % (attribute, reference)
+
+ def gt_filter():
+ return '\'%s\' : { \'$gt\' : %s }' % (attribute, reference)
+
def le_filter():
return '\'%s\' : { \'$lte\' : %s }' % (attribute, reference)
- def match_filter():
- return '\'%s\' : { \'$regex\' : %s }' % (attribute, reference)
- def match_nocase_filter():
- return '\'%s\' : { \'$regex\' : %s, $options: 'i' }' % (attribute, reference)
+
+ def ge_filter():
+ return '\'%s\' : { \'$gte\' : %s }' % (attribute, reference)
+
+ def ne_filter():
+ if reference == '':
+ return '\'%s\' : { \'$ne\' : '' }' % (attribute,)
+ else:
+ return '\'%s\' : { \'$ne\' : %s }' % (attribute, reference)
+
+ def not_match_filter():
+ # http://myadventuresincoding.wordpress.com/2011/05/19/mongodb-negative-regex-query-in-mongo-shell/
+ return '\'%s\' : { \'$regex\' : %s }' % (attribute, '^((?!'+reference+').)')
+
+ def ne_nocase_filter():
+ if reference == '':
+ return '\'%s\' : \'\'' % (attribute,)
+ else:
+ return '\'%s\' : { \'$regex\' : %s, \'$options\' : \'i\' }' % (attribute, '^((?!'+reference+').)')
+
+ def not_match_nocase_filter():
+ return '\'%s\' : { \'$regex\' : %s, \'$options\' : \'i\' }' % (attribute, '^((?!'+reference+').)')
+
def no_filter():
return '\'time\' : { \'$exists\' : True }'
+
if attribute not in good_attributes:
return no_filter
if operator == '=':
return eq_filter
- if operator == '>':
- return gt_filter
- if operator == '>=':
- return ge_filter
- if operator == '<':
+ elif operator == '~':
+ return match_filter
+ elif operator == '=~':
+ return eq_nocase_filter
+ elif operator == '~~':
+ return match_nocase_filter
+ elif operator == '<':
return lt_filter
- if operator == '<=':
+ elif operator == '>':
+ return gt_filter
+ elif operator == '<=':
return le_filter
- if operator == '!=':
+ elif operator == '>=':
+ return ge_filter
+ elif operator == '!=':
return ne_filter
- if operator == '~':
- return match_filter
- if operator == '~~':
- return match_nocase_filter
+ elif operator == '!~':
+ return not_match_filter
+ elif operator == '!=~':
+ return not_eq_nocase_filter
+ elif operator == '!~~':
+ return not_match_nocase_filter
+
class LiveStatusMongoStack(LiveStatusStack):
diff --git a/shinken/modules/logstore_sqlite.py b/shinken/modules/logstore_sqlite.py
index 1966294..47980fd 100644
--- a/shinken/modules/logstore_sqlite.py
+++ b/shinken/modules/logstore_sqlite.py
@@ -469,47 +469,84 @@ class LiveStatusLogStoreSqlite(BaseModule):
return ['%s IS NULL' % attribute, ()]
else:
return ['%s = ?' % attribute, (reference, )]
- def ne_filter():
- if reference == '':
- return ['%s IS NOT NULL' % attribute, ()]
- else:
- return ['%s != ?' % attribute, (reference, )]
- def gt_filter():
- return ['%s > ?' % attribute, (reference, )]
- def ge_filter():
- return ['%s >= ?' % attribute, (reference, )]
- def lt_filter():
- return ['%s < ?' % attribute, (reference, )]
- def le_filter():
- return ['%s <= ?' % attribute, (reference, )]
+
def match_filter():
# sqlite matches case-insensitive by default. We make
# no difference between case-sensitive and case-insensitive
# here. The python filters will care for the correct
# matching later.
return ['%s LIKE ?' % attribute, ('%'+reference+'%', )]
+
+ def eq_nocase_filter():
+ if reference == '':
+ return ['%s IS NULL' % attribute, ()]
+ else:
+ return ['%s = ?' % attribute.lower(), (reference.lower(), )]
+
def match_nocase_filter():
return ['%s LIKE ?' % attribute, ('%'+reference+'%', )]
+
+ def lt_filter():
+ return ['%s < ?' % attribute, (reference, )]
+
+ def gt_filter():
+ return ['%s > ?' % attribute, (reference, )]
+
+ def le_filter():
+ return ['%s <= ?' % attribute, (reference, )]
+
+ def ge_filter():
+ return ['%s >= ?' % attribute, (reference, )]
+
+ def ne_filter():
+ if reference == '':
+ return ['%s IS NOT NULL' % attribute, ()]
+ else:
+ return ['%s != ?' % attribute, (reference, )]
+
+ def not_match_filter():
+ return ['NOT %s LIKE ?' % attribute, ('%'+reference+'%', )]
+
+ def ne_nocase_filter():
+ if reference == '':
+ return ['NOT %s IS NULL' % attribute, ()]
+ else:
+ return ['NOT %s = ?' % attribute.lower(), (reference.lower(), )]
+
+ def not_match_nocase_filter():
+ return ['NOT %s LIKE ?' % attribute, ('%'+reference+'%', )]
+
def no_filter():
return ['1 = 1', ()]
+
if attribute not in good_attributes:
return no_filter
if operator == '=':
return eq_filter
- if operator == '>':
- return gt_filter
- if operator == '>=':
- return ge_filter
- if operator == '<':
+ elif operator == '~':
+ return match_filter
+ elif operator == '=~':
+ return eq_nocase_filter
+ elif operator == '~~':
+ return match_nocase_filter
+ elif operator == '<':
return lt_filter
- if operator == '<=':
+ elif operator == '>':
+ return gt_filter
+ elif operator == '<=':
return le_filter
- if operator == '!=':
+ elif operator == '>=':
+ return ge_filter
+ elif operator == '!=':
return ne_filter
- if operator == '~':
- return match_filter
- if operator == '~~':
- return match_nocase_filter
+ elif operator == '!~':
+ return not_match_filter
+ elif operator == '!=~':
+ return ne_nocase_filter
+ elif operator == '!~~':
+ return not_match_nocase_filter
+
+
class LiveStatusSqlStack(LiveStatusStack):
diff --git a/test/test_livestatus_mongodb.py b/test/test_livestatus_mongodb.py
index 9c67914..7abcb5f 100755
--- a/test/test_livestatus_mongodb.py
+++ b/test/test_livestatus_mongodb.py
@@ -118,13 +118,16 @@ class TestConfig(ShinkenTest):
self.livestatus_broker.rg = LiveStatusRegenerator()
self.livestatus_broker.datamgr = datamgr
datamgr.load(self.livestatus_broker.rg)
+ self.livestatus_broker.query_cache = LiveStatusQueryCache()
+ self.livestatus_broker.query_cache.disable()
+ self.livestatus_broker.rg.register_cache(self.livestatus_broker.query_cache)
#--- livestatus_broker.main
self.livestatus_broker.init()
for i in self.livestatus_broker.modules_manager.instances:
print "instance", i
self.livestatus_broker.db = self.livestatus_broker.modules_manager.instances[0]
- self.livestatus_broker.livestatus = LiveStatus(self.livestatus_broker.datamgr, self.livestatus_broker.db, self.livestatus_broker.pnp_path, self.livestatus_broker.from_q)
+ self.livestatus_broker.livestatus = LiveStatus(self.livestatus_broker.datamgr, self.livestatus_broker.query_cache, self.livestatus_broker.db, self.livestatus_broker.pnp_path, self.livestatus_broker.from_q)
#--- livestatus_broker.do_main
self.livestatus_broker.db.open()
--
UNNAMED PROJECT
More information about the Pkg-nagios-changes
mailing list