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

WIP: add QH command to access the query handler via livestatus #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 31 additions & 0 deletions src/Store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ bool Store::answerRequest(InputBuffer *input, OutputBuffer *output, int fd)
answerCommandRequest(unescape_newlines(lstrip((char *)line + 8)), output);
output->setDoKeepalive(true);
}
else if (!strncmp(line, "QH ", 3)) {
output->setDoKeepalive(true);
answerQueryHandlerRequest(lstrip((char *)line + 3), output, fd);
}
else if (!strncmp(line, "LOGROTATE", 9)) {
logger(LG_INFO, "Forcing logfile rotation");
rotate_log_file(time(0));
Expand Down Expand Up @@ -174,6 +178,33 @@ void Store::answerCommandRequest(const char *command, OutputBuffer *output)
return;
}

void Store::answerQueryHandlerRequest(const char *command, OutputBuffer *output, int fd)
{
int ret, sd;
char buf[4096];
sd = nsock_unix(qh_socket_path, NSOCK_TCP | NSOCK_CONNECT);
if (sd < 0) {
logger(LG_INFO, "Failed to connect to query socket '%s': %s: %s", qh_socket_path, nsock_strerror(sd), strerror(errno));
return;
}
ret = nsock_printf_nul(sd, "%s", command);
if (ret < 0) {
logger(LG_INFO, "failed to submit command by query handler");
}
output->reset();
while(TRUE) {
ret = read(sd, buf, 4095);
if(ret <= 0)
break;
buf[ret] = 0;
dprintf(fd, "%s", buf);
}
close(sd);
return;
}




void Store::answerGetRequest(InputBuffer *input, OutputBuffer *output, const char *tablename, int fd)
{
Expand Down
1 change: 1 addition & 0 deletions src/Store.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Store
Table *findTable(string name);
void answerGetRequest(InputBuffer *, OutputBuffer *, const char *, int fd);
void answerCommandRequest(const char *, OutputBuffer *);
void answerQueryHandlerRequest(const char *, OutputBuffer *, int);
};

#endif // Store_h
Loading