diff options
author | Timothy Pearson <kb9vqf@pearsoncomputing.net> | 2012-09-20 00:26:14 -0500 |
---|---|---|
committer | Timothy Pearson <tpearson@raptorengineering.com> | 2019-03-04 08:04:29 -0600 |
commit | 510a925fe3f95b8229124d7f855736008b8c918e (patch) | |
tree | 4bc7b2ac8118929e7736dd61dbca78a12b8a34ec | |
parent | ecce8da35f52b9ade32eeffea40df625192d2368 (diff) | |
download | xrdp-proprietary-510a925fe3f95b8229124d7f855736008b8c918e.tar.gz xrdp-proprietary-510a925fe3f95b8229124d7f855736008b8c918e.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 | 22 |
3 files changed, 71 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 ba9d02a3..c719f84f 100644 --- a/xrdp/xrdp.c +++ b/xrdp/xrdp.c @@ -21,6 +21,9 @@ #include "xrdp.h" #include "log.h" +#include <netdb.h> +#include "libraptorsmiface.h" + #define THREAD_WAITING 100 static struct xrdp_listen *g_listen = 0; @@ -544,6 +547,17 @@ main(int argc, char **argv) /* 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 */ @@ -587,5 +601,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; } |