/* * This script will * - Read the statistics for a subset of the current connections * - Create a class instance for each connection * - Print the resulting instances to the script log */ require ("Application"); class TunnelInfo Application { } class ClientStats { Type; Description; Status; UserName; SessionId; PointsIn; PointsOut; ConnectOk; ConnectFail; Disconnect; Block; Unblock; PointsCreate; PointsRead; PointsRegister; PointsUnregister; CmdInvalid; CmdFailed; PointsDropped; QueueSize; } /* * Read the status of all connections matching a given pattern. The pattern is compared * to both the Type and the Description of each connection. If either matches then the * connection is returned. * * The return value is a list of ClientStats instances. */ method TunnelInfo.readStatus(pattern) { local result = datahub_command("(get_client_stats \"*\")", 1); local stats, client, clients; result = parse_string(result, nil); with info in cadr(result) clients = tcollect { info = list_to_array(info); stats = list_to_array(info[6]); if (shell_match(info[1], pattern) || shell_match(info[2], pattern)) { client = new ClientStats(); client.Type = info[1]; client.Description = info[2]; client.Status = info[3]; client.UserName = info[4]; client.SessionId = info[5]; with stat in stats do { client..symbol(car(stat)) = cadr(stat); } // Cause tcollect to add this client to its result client; } else { // Cause tcollect to ignore this item nil; } } clients; } /* Write the 'main line' of the program here. */ method TunnelInfo.constructor () { local clients = .readStatus("*TCP Incoming*"); pretty_print(clients); terpri(); } /* Any code to be run when the program gets shut down. */ method TunnelInfo.destructor () { } /* Start the program by instantiating the class. */ ApplicationSingleton (TunnelInfo);