arachnys / cabot

Self-hosted, easily-deployable monitoring and alerts service - like a lightweight PagerDuty
MIT License
5.58k stars 590 forks source link

searching with part of field content doesn't seem to works using cabot api's #210

Open xinity opened 9 years ago

xinity commented 9 years ago

hi all,

I'm trying to search for example, all graphite_checks which name field contain : mydomain.com

i've tried this type of query: http://cabot:8080/api/graphite_checks/?search=mydomain doesn't return anything

but this works: http://cabot:8080/api/graphite_checks/?name=mysrv.mydomain.com

have i missed something, i've taken a closer look at Django Rest Framework documentation, but i haven't found how to fullfill my needs :(

any clues ?

thanks a lot guys,

Regards,

dbuxton commented 9 years ago

We would have to add something like django-filter (see http://www.django-rest-framework.org/api-guide/filtering/#djangofilterbackend) for this to work - I have no objection to doing that?

xinity commented 9 years ago

I'm not a python dev but i can at least try considering i've failed implementing instances alert, let's see if I can do better this time

dbuxton commented 9 years ago

It's pretty much a case of following the instructions I think, let me know if you get stuck

xinity commented 9 years ago

I'll let you know by next week-end @dbuxton anychances you could give a guideline so i can solve and make PR related to issue #204 ?

xinity commented 9 years ago

i have a working PoC for graphite_checks, sadly , Django fulltext search doesn't support Postgresql :( so i was only able to search using "starts with" and "exact" terms.

if that's enough, i can PR for all checks, let me know @dbuxton

dbuxton commented 9 years ago

You should be able to do icontains?

xinity commented 9 years ago

@dbuxton that's what is already done : " def construct_search(self, field_name): if field_name.startswith('^'): return "%sistartswith" % field_name[1:] elif field_name.startswith('='): return "%siexact" % field_name[1:] elif field_name.startswith('@'): return "%s__search" % field_name[1:] else: return "%s__icontains" % field_name" <=== !!

code from: https://github.com/tomchristie/django-rest-framework/blob/4248a8d3fc725d9ae3fe7aaaad7ee12479ab07ab/rest_framework/filters.py

maybe using tsearch2 or tools alike, but i'm afraid it's far beyond my skills :(

dbuxton commented 9 years ago

I don't understand what's wrong with this. Do you have a development branch with your changes in that I can have a look at?

xinity commented 9 years ago

not at this time, but i can make one fast if needed.

as today i found a dirty workaround using jq to dynamically built my API's queries. feel free to close this issue if not interested in full text search with django REST API's using postgresql