Added a -h option to sicslog querying

Fixed the mongodb path in sicslogmain to point to the production server
This commit is contained in:
2016-04-14 14:57:55 +02:00
parent 1fb85ef6b5
commit 78f6b92960
4 changed files with 18 additions and 6 deletions

View File

@ -182,7 +182,11 @@ static int MongoQueryAction(SConnection * pCon, SicsInterp * pSics,
status = sicslogQuery(argc,argv,QueryCallback,result); status = sicslogQuery(argc,argv,QueryCallback,result);
if(status != 0){ if(status != 0){
error = sicslogGetError(); error = sicslogGetError();
SCPrintf(pCon,eError,"Error %s querying mongodb", error); if(strstr(error,"Options") != NULL){
SCPrintf(pCon,eValue,"%s", error);
} else {
SCPrintf(pCon,eError,"Error %s querying mongodb", error);
}
} else { } else {
SCPureSockWrite(pCon,GetCharArray(result),eLog); SCPureSockWrite(pCon,GetCharArray(result),eLog);
} }

View File

@ -87,7 +87,7 @@ int sicslogQuery(int argc, char *argv[], ResultCallback_t func, void *userData)
parse options parse options
*/ */
optind = 1; optind = 1;
while((c = getopt(argc,argv,"s:l:f:t:i:e:c:")) != -1) { while((c = getopt(argc,argv,"s:l:f:t:i:e:c:h")) != -1) {
switch (c){ switch (c){
case 's': case 's':
sub = strdup(optarg); sub = strdup(optarg);
@ -129,6 +129,13 @@ int sicslogQuery(int argc, char *argv[], ResultCallback_t func, void *userData)
case 'c': case 'c':
severity = sevFromText(optarg); severity = sevFromText(optarg);
break; break;
case 'h':
snprintf(
lastError,sizeof(lastError),
"Options: -s subsystem\n-l last(h,d)\n-f fromtime\n-t totime\n-i instrument\n-c severity\n%s",
"-e search-expression");
return 1;
break;
case '?': case '?':
if( optopt == 's' || optopt == 'l' || optopt == 'f' || optopt == 't' if( optopt == 's' || optopt == 'l' || optopt == 'f' || optopt == 't'
|| optopt == 'i' || optopt == 'e' || optopt == 'c') { || optopt == 'i' || optopt == 'e' || optopt == 'c') {

View File

@ -25,8 +25,8 @@ int sicslogSetup(char *url, char *inst);
int sicslogQuery(int argc, char *argv[], ResultCallback_t func, void *userData); int sicslogQuery(int argc, char *argv[], ResultCallback_t func, void *userData);
/* /*
If sicslogQuery returned or sicslogSetup returns an error, retrieve a description If sicslogQuery or sicslogSetup returns an error, retrieve a description
of it. Only valid right after the error inducing call. of it. Only valid right after the error inducing call.
*/ */
char *sicslogGetError(); char *sicslogGetError();

View File

@ -9,7 +9,7 @@
#include <bson.h> #include <bson.h>
#include <logv2.h> #include <logv2.h>
static void formatSeverity(unsigned int severity, char *buffer, unsigned int bufferLength) void formatSeverity(unsigned int severity, char *buffer, unsigned int bufferLength)
{ {
static const char *severityText[] = {"FATAL", static const char *severityText[] = {"FATAL",
"ERROR", "ERROR",
@ -25,6 +25,7 @@ static void formatSeverity(unsigned int severity, char *buffer, unsigned int buf
} }
strncpy(buffer,severityText[severity-1],bufferLength); strncpy(buffer,severityText[severity-1],bufferLength);
} }
/*----------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------*/
static void ResultPrint(const bson_t *doc, void *userData) static void ResultPrint(const bson_t *doc, void *userData)
{ {
@ -55,7 +56,7 @@ int main(int argc, char *argv[])
int status; int status;
char *error; char *error;
sicslogSetup("mongodb://logwriter:sinqsics@localhost:27017/?authSource=admin",NULL); sicslogSetup("mongodb://logwriter:sinqsics@mpc1965:27017/?authSource=admin",NULL);
status = sicslogQuery(argc,argv,ResultPrint,NULL); status = sicslogQuery(argc,argv,ResultPrint,NULL);
if(status != 0){ if(status != 0){
error = sicslogGetError(); error = sicslogGetError();