summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Baumann <mail@andreasbaumann.cc>2014-12-07 13:16:08 +0100
committerAndreas Baumann <mail@andreasbaumann.cc>2014-12-07 13:16:08 +0100
commit9af266f6c4d44eb39754cc0e16cb7ca192addea0 (patch)
tree150c392c12ec33e8248a9751439b9fd4e15b70db
parentea248471703cc71bb1d57c0dc2b7914983cf0127 (diff)
downloadbiruda-9af266f6c4d44eb39754cc0e16cb7ca192addea0.tar.gz
biruda-9af266f6c4d44eb39754cc0e16cb7ca192addea0.tar.bz2
some better worker output reporting
-rw-r--r--src/cli.c37
-rw-r--r--src/master.c31
-rw-r--r--src/webserver.c4
-rw-r--r--src/worker.c11
4 files changed, 68 insertions, 15 deletions
diff --git a/src/cli.c b/src/cli.c
index 406649d..702c388 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -31,7 +31,7 @@ typedef enum {
static char *commands[] = {
"help", "quit", "status", "start", "stop",
- "autodisp", NULL
+ "autodisp", "messages", NULL
};
static bool print_colors = false;
@@ -132,6 +132,7 @@ static void print_help( )
" status - status of the biruda network\n"
" start - start a worker manually\n"
" stop - stop a worker manually\n"
+ " messages - show output of workers\n"
" autodisp - automatically show messages (toggle)\n"
);
}
@@ -194,6 +195,36 @@ static void print_status( )
free( data );
}
+static void print_worker_output( const char *worker_name )
+{
+ char url[128];
+ snprintf( url, sizeof( url ), "worker?op=output&name=%s", worker_name );
+ char *data = NULL;
+ int len;
+ http_retcode ret = http_get( url, &data, &len, NULL );
+ if( ret == 200 ) {
+ if( strlen( data ) > 0 && data[len-1] == '\n' ) {
+ data[len-1] = '\0';
+ len--;
+ }
+ if( strlen( data ) > 0 && data[len-1] == '\r' ) {
+ data[len-1] = '\0';
+ }
+ print_answer( data );
+ } else {
+ print_error( "ERROR: HTTP error %d", ret );
+ }
+ free( data );
+}
+
+static void print_messages( )
+{
+ get_workers( );
+ for( int i = 0; i < nof_worker_names; i++ ) {
+ print_worker_output( worker_names[i] );
+ }
+}
+
static void start_worker( const char *worker_name )
{
char url[128];
@@ -257,7 +288,7 @@ int start_interactive( bool colors, FILE *in )
}
if( autodisp_toggle ) {
- print_status( );
+ print_messages( );
}
if( is_interactive ) {
@@ -313,6 +344,8 @@ int start_interactive( bool colors, FILE *in )
command_state = START_WORKER;
} else if( strncasecmp( line, "stop", 5 ) == 0 ) {
command_state = STOP_WORKER;
+ } else if( strncasecmp( line, "messages", 8 ) == 0 ) {
+ print_messages( );
} else if( strncasecmp( line, "autodisp", 8 ) == 0 ) {
if( is_interactive ) {
autodisp_toggle = !autodisp_toggle;
diff --git a/src/master.c b/src/master.c
index fafbbbe..387fe5f 100644
--- a/src/master.c
+++ b/src/master.c
@@ -344,8 +344,12 @@ static int master_output_free( const char *name )
return 0;
}
-static int master_output_write( const char *spool_dir, const char *name, const char *msg )
+static int master_output_write( const char *spool_dir, json_object *obj )
{
+ json_object *worker_obj;
+ json_object_object_get_ex( obj, "worker", &worker_obj );
+ const char *name = json_object_get_string( worker_obj );
+
worker_t *w = worker_by_name( name );
if( w == NULL ) return 0;
@@ -356,8 +360,23 @@ static int master_output_write( const char *spool_dir, const char *name, const c
master_output_init( spool_dir, name );
if( wed->spool_file == NULL ) return 0;
}
+
+ json_object *msg_obj;
+ json_object_object_get_ex( obj, "msg", &msg_obj );
+ const char *msg = json_object_get_string( msg_obj );
+
+ json_object *stream_obj;
+ json_object_object_get_ex( obj, "stream", &stream_obj );
+ const char *stream = json_object_get_string( stream_obj );
+
+ json_object *ts_obj;
+ json_object_object_get_ex( obj, "timestamp", &ts_obj );
+ time_t ts = json_object_get_int( ts_obj );
- fputs( msg, wed->spool_file );
+ char line[1024];
+ snprintf( line, sizeof( line ), "%lu %s %s %s", ts, name, stream, msg );
+
+ fputs( line, wed->spool_file );
fflush( wed->spool_file );
return 0;
@@ -478,13 +497,7 @@ NEXT_COMMAND:
const char *worker = json_object_get_string( worker_obj );
master_output_free( worker );
} else if( strcmp( op, "output" ) == 0 ) {
- json_object *worker_obj;
- json_object_object_get_ex( recv_obj, "worker", &worker_obj );
- const char *worker = json_object_get_string( worker_obj );
- json_object *msg_obj;
- json_object_object_get_ex( recv_obj, "msg", &msg_obj );
- const char *msg = json_object_get_string( msg_obj );
- master_output_write( tdata->spool_dir, worker, msg );
+ master_output_write( tdata->spool_dir, recv_obj );
} else {
fprintf( stderr, "WARNING: master received unkown message: %s\n", answer );
}
diff --git a/src/webserver.c b/src/webserver.c
index 312105a..3e3d2e7 100644
--- a/src/webserver.c
+++ b/src/webserver.c
@@ -44,7 +44,9 @@ static int handle_request( void *cls, struct MHD_Connection *connection,
strncat( biruda_msg, part, sizeof( biruda_msg ) );
}
}
- }
+ }
+ } else if( strcmp( url, "/worker" ) == 0 ) {
+ snprintf( biruda_msg, sizeof( biruda_msg ), "messages ..\n" );
} else {
snprintf( biruda_msg, sizeof( biruda_msg ), "Welcome to biruda! Please state your wish..\n" );
}
diff --git a/src/worker.c b/src/worker.c
index e635589..d831031 100644
--- a/src/worker.c
+++ b/src/worker.c
@@ -97,9 +97,14 @@ static char *create_worker_answer( const char *name, const char *s, size_t len,
json_object *msg_obj = json_object_new_string_len( s, len );
json_object_object_add( obj, "msg", msg_obj );
- json_object *is_stdout_obj = json_object_new_boolean( is_stdout );
- json_object_object_add( obj, "stdout", is_stdout_obj );
-
+ json_object *stream_obj = json_object_new_string( is_stdout ? "stdout" : "stderr" );
+ json_object_object_add( obj, "stream", stream_obj );
+
+ time_t ts;
+ time( &ts );
+ json_object *timestamp_obj = json_object_new_int( ts );
+ json_object_object_add( obj, "timestamp", timestamp_obj );
+
/* produce message as string, caller must free it */
const char *msg = json_object_to_json_string( obj );
char *res = strdup( msg );