/* All user scripts should derive from the base "Application" class */ require ("Application"); /* Get the Gamma library functions and methods for ODBC and/or * Windows programming. Uncomment either or both. */ //require ("WindowsSupport"); //require ("ODBCSupport"); /* Applications share the execution thread and the global name * space, so we create a class that contains all of the functions * and variables for the application. This does two things: * 1) creates a private name space for the application, and * 2) allows you to re-load the application to create either * a new unique instance or multiple instances without * damaging an existing running instance. */ class MonitorTunnelStatus Application { //the interval that we check the tunnel connection status in seconds interval = 5; connection1Host = "74.81.191.189"; connection1Tag = "default:TunnelStatusTest"; connection2Host = "demo.skkynet.com"; connection2Tag = "default:TunnelStatusTest2"; } method MonitorTunnelStatus.checkTunnelStatus (tunnelHost, statusTag) { local tunnelStatusString = datahub_command (format("(TunnelSlaveStatus %s)", tunnelHost), 1); princ(tunnelStatusString, "\n"); local tunnelStatusArray = list_to_array(string_split(tunnelStatusString, " ", 0)); princ(tunnelStatusArray[15], " is the status of Host:", tunnelHost, "\n"); if(strcmp(tunnelStatusArray[15],"\"Running\"") == 0) { if(eval(symbol(statusTag)) >= 60) { datahub_write(statusTag, 1); } else { datahub_write(statusTag, eval(symbol(statusTag)) + 1); } } else { datahub_write(statusTag, 0); //princ(0, "\n"); } } /* Write the 'main line' of the program here. */ method MonitorTunnelStatus.constructor () { .TimerEvery(.interval, `(@self).checkTunnelStatus(@.connection1Host, @.connection1Tag)); .TimerEvery(.interval, `(@self).checkTunnelStatus(@.connection2Host, @.connection2Tag)); //.checkTunnelStatus(.connection1Host, .connection1Tag); //.checkTunnelStatus(.connection2Host, .connection2Tag); } /* Any code to be run when the program gets shut down. */ method MonitorTunnelStatus.destructor () { } /* Start the program by instantiating the class. If your * constructor code does not create a persistent reference to * the instance (self), then it will be destroyed by the * garbage collector soon after creation. If you do not want * this to happen, assign the instance to a global variable, or * create a static data member in your class to which you assign * 'self' during the construction process. ApplicationSingleton() * does this for you automatically. */ ApplicationSingleton (MonitorTunnelStatus);