Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
dcdb
dcdb
Commits
d056354d
Commit
d056354d
authored
Mar 19, 2016
by
Axel Auweter
Browse files
Add CGI interface for DCDBQuery.
parent
6bd94015
Changes
3
Hide whitespace changes
Inline
Side-by-side
DCDBTools/dcdbquery/Makefile
View file @
d056354d
include
../../config.mk
CXXFLAGS
=
-O
2
-ggdb
--std
=
c++11
-Wall
-Wno-unused-local-typedefs
-Wno-unknown-warning-option
-fmessage-length
=
0
-I
$(DCDBDEPLOYPATH)
/include/
-I
$(DCDBBASEPATH)
/include/
-DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
CXXFLAGS
=
-O
0
-ggdb
--std
=
c++11
-Wall
-Wno-unused-local-typedefs
-Wno-unknown-warning-option
-fmessage-length
=
0
-I
$(DCDBDEPLOYPATH)
/include/
-I
$(DCDBBASEPATH)
/include/
-DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG
OBJS
=
dcdbquery.o query.o
LIBS
=
-L
$(DCDBDEPLOYPATH)
/lib/
-ldcdb
-lcassandra
-luv
-lboost_random
-lboost_system
-lboost_date_time
-lboost_regex
-lssl
-lcrypto
TARGET
=
dcdbquery
...
...
DCDBTools/dcdbquery/dcdbquery.cpp
View file @
d056354d
...
...
@@ -19,8 +19,9 @@
void
usage
(
void
)
{
/* 0---------1---------2---------3---------4---------5---------6---------7--------- */
std
::
cout
<<
"Usage:"
<<
std
::
endl
if
(
isatty
(
fileno
(
stdin
)))
{
/* 0---------1---------2---------3---------4---------5---------6---------7--------- */
std
::
cout
<<
"Usage:"
<<
std
::
endl
<<
"dcdbquery [-h <hostname>] [-r] [-l] <Sensor 1> [<Sensor 2> ...] <Start> <End>"
<<
std
::
endl
<<
"where"
<<
std
::
endl
<<
" <hostname> - the name of the DB server"
<<
std
::
endl
...
...
@@ -34,13 +35,47 @@ void usage(void)
<<
"format (nanoseconds since epoch) insted of ISO human readable form."
<<
std
::
endl
<<
"When the -l option is specified, times for <Start>, <End>, and in the generated"
<<
std
::
endl
<<
"output will be interpreted / printed in the local time zone."
<<
std
::
endl
;
}
else
{
std
::
cout
<<
"Invalid request."
<<
std
::
endl
;
}
exit
(
EXIT_SUCCESS
);
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
const
argv
[])
{
/* Check if run from command line */
int
argcReal
;
char
**
argvReal
;
if
(
isatty
(
fileno
(
stdin
)))
{
argcReal
=
argc
;
argvReal
=
(
char
**
)
argv
;
}
else
{
/* Check if we are a CGI program */
if
(
!
getenv
(
"QUERY_STRING"
))
{
std
::
cout
<<
"No terminal and no QUERY_STRING environment variable."
<<
std
::
endl
;
std
::
cout
<<
"Exiting."
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
/* Create argcReal and argvReal */
argcReal
=
1
;
argvReal
=
(
char
**
)
malloc
(
sizeof
(
char
*
));
argvReal
[
0
]
=
strdup
(
"dcdbquery"
);
/* dummy to make consistent with command line invocation */
char
*
token
=
strtok
(
getenv
(
"QUERY_STRING"
),
"&"
);
while
(
token
)
{
argcReal
++
;
argvReal
=
(
char
**
)
realloc
((
void
*
)
argvReal
,
argcReal
*
sizeof
(
char
*
));
/* FIXME: should check if argvReal is NULL */
argvReal
[
argcReal
-
1
]
=
token
;
token
=
strtok
(
NULL
,
"&"
);
}
}
/* Check command line arguments */
if
(
argc
<=
3
)
{
if
(
argc
Real
<=
3
)
{
usage
();
}
...
...
@@ -55,7 +90,7 @@ int main(int argc, char* argv[])
host
=
"localhost"
;
}
while
((
ret
=
getopt
(
argc
,
argv
,
"+h:rlf"
))
!=-
1
)
{
while
((
ret
=
getopt
(
argc
Real
,
argv
Real
,
"+h:rlf"
))
!=-
1
)
{
switch
(
ret
)
{
case
'h'
:
host
=
optarg
;
...
...
@@ -79,8 +114,8 @@ int main(int argc, char* argv[])
DCDB
::
TimeStamp
start
,
end
;
try
{
bool
local
=
myQuery
->
getLocalTimeEnabled
();
start
=
DCDB
::
TimeStamp
(
argv
[
argc
-
2
],
local
);
end
=
DCDB
::
TimeStamp
(
argv
[
argc
-
1
],
local
);
start
=
DCDB
::
TimeStamp
(
argv
Real
[
argc
Real
-
2
],
local
);
end
=
DCDB
::
TimeStamp
(
argv
Real
[
argc
Real
-
1
],
local
);
}
catch
(
std
::
exception
&
e
)
{
std
::
cout
<<
"Wrong time format."
<<
std
::
endl
;
...
...
@@ -95,8 +130,8 @@ int main(int argc, char* argv[])
/* Build a list of sensornames */
std
::
list
<
std
::
string
>
sensors
;
for
(
int
arg
=
optind
;
arg
<
argc
-
2
;
arg
++
)
{
sensors
.
push_back
(
argv
[
arg
]);
for
(
int
arg
=
optind
;
arg
<
argc
Real
-
2
;
arg
++
)
{
sensors
.
push_back
(
argv
Real
[
arg
]);
}
myQuery
->
doQuery
(
host
,
sensors
,
start
,
end
);
...
...
DCDBTools/dcdbquery/query.cpp
View file @
d056354d
...
...
@@ -123,6 +123,7 @@ void DCDBQuery::doQuery(const char* hostname, std::list<std::string> sensors, DC
connection
->
setHostname
(
hostname
);
if
(
!
connection
->
connect
())
{
std
::
cout
<<
"Cannot connect to database."
<<
std
::
endl
;
exit
(
EXIT_FAILURE
);
}
/* Initialize the SensorConfig interface */
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment