Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve query errors #131

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/AndingFilter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ void AndingFilter::combineFilters(int count, int andor)
if (count > (int)_subfilters.size()) {
logger(LG_INFO, "Cannot combine %d filters with '%s': only %d are on stack",
count, andor == ANDOR_AND ? "AND" : "OR", _subfilters.size());
this->setError(400, "Cannot combine %d filters with '%s': only %d are on stack",
count, andor == ANDOR_AND ? "AND" : "OR", _subfilters.size());
return;
}

Expand All @@ -126,4 +128,3 @@ void AndingFilter::combineFilters(int count, int andor)
}
addSubfilter(andorfilter);
}

6 changes: 6 additions & 0 deletions src/EmptyColumn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@
// Boston, MA 02110-1301 USA.

#include "EmptyColumn.h"
#include "EmptyFilter.h"
#include "Query.h"

void EmptyColumn::output(void *data __attribute__ ((__unused__)), Query *query)
{
query->outputString("");
}

Filter *EmptyColumn::createFilter(int operator_id, char *value)
{
return new EmptyFilter(this, operator_id, value);
}
1 change: 1 addition & 0 deletions src/EmptyColumn.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class EmptyColumn : public Column
Column(name, description, -1) {}
int type() { return COLTYPE_STRING; }
void output(void *data, Query *);
Filter *createFilter(int operator_id, char *value);
};

#endif // EmptyColumn_h
28 changes: 28 additions & 0 deletions src/EmptyFilter.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <stdlib.h>
#include "EmptyFilter.h"
#include "EmptyColumn.h"
#include "opids.h"
#include "logger.h"
#include "OutputBuffer.h"
EmptyFilter::EmptyFilter(Column *column, int opid, char *value)
: _column(column)
, _opid(abs(opid))
{
}

EmptyFilter::~EmptyFilter()
{
}


bool EmptyFilter::accepts(void *data)
{
bool pass = false;

return pass != _negate;
}

void *EmptyFilter::indexFilter(const char *column)
{
return 0;
}
24 changes: 24 additions & 0 deletions src/EmptyFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef EmptyFilter_h
#define EmptyFilter_h

#include "config.h"

using namespace std;

#include "Filter.h"
class EmptyColumn;

class EmptyFilter : public Filter
{
Column *_column;
int _opid;
bool _negate;
public:
EmptyFilter(Column *_column, int opid, char *value);
~EmptyFilter();
bool accepts(void *data);
void *indexFilter(const char *column);
};


#endif // EmptyFilter_h
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ livestatus_la_SOURCES = \
HostlistDependencyColumn.cc HostlistDependencyColumnFilter.cc \
ServicelistDependencyColumn.cc ServicelistDependencyColumnFilter.cc \
ContactgroupsColumn.cc RowSortedSet.cc HostServiceState.cc opids.cc auth.cc \
ContactgroupsObjectlistColumn.cc CommandsMemberColumn.cc
ContactgroupsObjectlistColumn.cc CommandsMemberColumn.cc EmptyFilter.cc

if HAVE_DIET
diet -v $(CC) -x c -Wno-deprecated-declarations $(CFLAGS) $(LDFLAGS) -I.. -s -o $@ $^
Expand Down
10 changes: 4 additions & 6 deletions src/Makefile.manual
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
# | |
# | Copyright Mathias Kettner 2009 [email protected] |
# +------------------------------------------------------------------+
#
#
# This file is part of check_mk 1.1.0beta17.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation in version 2. check_mk is distributed
Expand All @@ -34,7 +34,7 @@ CFLAGS = -O2 -fPIC -I..
#endif
CXXFLAGS = $(CFLAGS)


OBJECTS = TableServices.o TableHosts.o Table.o Query.o StringColumn.o \
OffsetStringColumn.o Store.o store.o logger.o strutil.o \
Filter.o IntColumn.o OffsetIntColumn.o \
Expand All @@ -51,7 +51,7 @@ OBJECTS = TableServices.o TableHosts.o Table.o Query.o StringColumn.o \
ServicegroupsColumn.o HostgroupsColumn.o EmptyColumn.o \
OutputBuffer.o DoubleColumn.o DoubleColumnFilter.o \
OffsetDoubleColumn.o ClientQueue.o InputBuffer.o \
HostSpecialIntColumn.o
HostSpecialIntColumn.o EmptyFilter.o



Expand All @@ -75,5 +75,3 @@ deps:
gcc -MM *.cc > .deps

-include .deps


11 changes: 9 additions & 2 deletions src/Query.cc
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,17 @@ void Query::parseAndOrLine(char *line, int andor, bool filter)
andor == ANDOR_OR ? "Or" : "And");
return;
}
if (filter)
if (filter) {
_filter.combineFilters(number, andor);
else
if (_filter.hasError()) {
_output->setError(_filter.errorCode(), "error in %s header: %s", andor == ANDOR_OR ? "Or" : "And", _filter.errorMessage().c_str());
}
} else {
_wait_condition.combineFilters(number, andor);
if (_wait_condition.hasError()) {
_output->setError(_wait_condition.errorCode(), "error in WaitCondition%s header: %s", andor == ANDOR_OR ? "Or" : "And", _filter.errorMessage().c_str());
}
}
}

void Query::parseNegateLine(char *line, bool filter)
Expand Down