diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-09-20 00:26:14 -0500 |
---|---|---|
committer | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-09-20 00:26:14 -0500 |
commit | a53204b8c9260b8af5043651f1a9ae0ec3a32c1e (patch) | |
tree | d3ad09e8037f720050f1106992dd62c8c303c75d | |
parent | 880b8ccbe8a9f5bab3035de3c4697152ec539883 (diff) | |
download | xrdp-proprietary-a53204b8c9260b8af5043651f1a9ae0ec3a32c1e.tar.gz xrdp-proprietary-a53204b8c9260b8af5043651f1a9ae0ec3a32c1e.zip |
Add additional statistics reporting
-rw-r--r-- | raptorsmiface/libraptorsmiface.c | 46 | ||||
-rw-r--r-- | raptorsmiface/libraptorsmiface.h | 4 | ||||
-rw-r--r-- | xrdp/xrdp.c | 23 |
3 files changed, 72 insertions, 1 deletions
diff --git a/raptorsmiface/libraptorsmiface.c b/raptorsmiface/libraptorsmiface.c index 98bf2efa..987939f5 100644 --- a/raptorsmiface/libraptorsmiface.c +++ b/raptorsmiface/libraptorsmiface.c @@ -988,3 +988,49 @@ void raptor_sm_terminate_server(char* username) { free(command_string); } } + +void raptor_sm_stats_report_server_start(char* hostname) { + MYSQL_RES *res; + MYSQL_ROW row; + char* query; + + MYSQL *conn = connect_if_needed(); + if (!conn) { + return -1; + } + + // Insert information into the statistics database + char* safe_servername = get_mysql_escaped_string(conn, hostname); + long long timestamp = time(NULL); + asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid) VALUES ('%lld', '%d', '%s', '%d', '%d')", timestamp, STATISTICS_SERVER_START_EVENT, safe_servername, -1, -1); + free(safe_servername); + if (mysql_query_internal(conn, query)) { + // Server error + dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn)); + } + free(query); + mysql_close(conn); +} + +void raptor_sm_stats_report_server_stop(char* hostname) { + MYSQL_RES *res; + MYSQL_ROW row; + char* query; + + MYSQL *conn = connect_if_needed(); + if (!conn) { + return -1; + } + + // Insert information into the statistics database + char* safe_servername = get_mysql_escaped_string(conn, hostname); + long long timestamp = time(NULL); + asprintf(&query, "INSERT INTO statistics (timestamp, eventtypeid, servername, display, typeid) VALUES ('%lld', '%d', '%s', '%d', '%d')", timestamp, STATISTICS_SERVER_STOP_EVENT, safe_servername, -1, -1); + free(safe_servername); + if (mysql_query_internal(conn, query)) { + // Server error + dprint("Unable to insert data into statistics database! [%s]\n\r", mysql_error(conn)); + } + free(query); + mysql_close(conn); +}
\ No newline at end of file diff --git a/raptorsmiface/libraptorsmiface.h b/raptorsmiface/libraptorsmiface.h index b27110bc..5d03b3e1 100644 --- a/raptorsmiface/libraptorsmiface.h +++ b/raptorsmiface/libraptorsmiface.h @@ -44,4 +44,6 @@ bool raptor_sm_sesslimit_reached(char* username); char raptor_sm_set_session_state(int display, int state); void raptor_sm_run_remote_desktop(char* username, int display, char* executable); void raptor_sm_terminate_server(char* username); -char* raptor_sm_get_hostname_for_display(int display);
\ No newline at end of file +char* raptor_sm_get_hostname_for_display(int display); +void raptor_sm_stats_report_server_start(char* hostname); +void raptor_sm_stats_report_server_stop(char* hostname);
\ No newline at end of file diff --git a/xrdp/xrdp.c b/xrdp/xrdp.c index 4af8c4d7..bb7dc021 100644 --- a/xrdp/xrdp.c +++ b/xrdp/xrdp.c @@ -23,6 +23,9 @@ #include "xrdp.h" #include "log.h" +#include <netdb.h> +#include "libraptorsmiface.h" + #define THREAD_WAITING 100 static struct xrdp_listen* g_listen = 0; @@ -499,6 +502,18 @@ main(int argc, char** argv) g_file_open("/dev/null"); /* end of daemonizing code */ } + + // Update statistics + char hostname[512]; + gethostname(hostname, 512); + struct hostent* hostinfo; + if(hostinfo=gethostbyname(hostname)) { + raptor_sm_stats_report_server_start(hostinfo->h_name); + } + else { + raptor_sm_stats_report_server_start(hostname); + } + g_threadid = tc_get_threadid(); g_listen = xrdp_listen_create(); g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */ @@ -536,5 +551,13 @@ main(int argc, char** argv) } g_free(startup_params); g_deinit(); + + if(hostinfo) { + raptor_sm_stats_report_server_stop(hostinfo->h_name); + } + else { + raptor_sm_stats_report_server_stop(hostname); + } + return 0; } |