To remotely execute certain command line tools in BDL, for example "ps" on a SunOs, three functions are required:
// hCon will be assigned the connection handle function Connect(/*inout*/hCon : number; sHost : string) begin WebTcpipConnect(hCon, sHost, 512); end Connect; // Send a request to the remote execution server // remote execution protocol: // What does a request look like in binary: // 00username00password00shellCommandToExecute00 // What does the response look like // 00responseData // sample request: // 00root00labpass00ps -ef | egrep -c ".*"00 function Request(hCon: number; sUser: string; sPwd: string; sCmd: string):number var sSend : string; sBuf : string; nSize : number; nRec : number; begin sSend := "\h00"; SetString(sSend, 2, sUser); SetString(sSend, Strlen(sUser) + 3, sPwd); SetString(sSend, Strlen(sUser) + Strlen(sPwd) + 4, sCmd); nSize := 3 + Strlen(sUser) + Strlen(sPwd) + Strlen(sCmd) + 1; WebTcpipSendBin(hCon, sSend, nSize); WebTcpipRecvExact(hCon, NULL, 1); WebTcpipRecv(hCon, sBuf, sizeof(sBuf), nRec); Request := number(sBuf); end Request; // Closes the connection to the remote exec server function Close(hCon : number) begin WebTcpipShutdown(hCon); end Close;
A function wrapper is needed around the Silk Performer MeasureInc functions. This function can be used in all monitoring projects. A function named MonitorInc is created to access project attributes. This function accesses the attributes you specified earlier.
The MonitorInc function can also be imported from an existing bdh, bdlMonitor.bdh.
function MonitorInc(nMon : number; nVal : number) var sMeasure : string; begin // This will check whether the attribute // "#BDLMonitor1.Enabled" was set to true if AttributeGetBoolean("#BDLMonitor" + string(nMon) + ".Enabled") then // If yes then let's read the name of the measure. // To do this we read the the project attribute // "#BDLMonitor1.Name" and store it // to a local variable named sMeasure. // sMeasure will have the value: // "SunOs\Processes\CountNrOfProcesses" AttributeGetString("#BDLMonitor" + string(nMon) + ".Name", sMeasure, sizeof(sMeasure)); // Set a new value for // "SunOs\Processes\CountNrOfProcesses" MeasureInc(sMeasure, nVal, MEASURE_KIND_AVERAGE); end; end MonitorInc;
Now the transaction that will take the snapshot using all the functions that have been defined can be coded. This transaction also accesses the project file attributes. The goal is to later have these attributes set in Performance Explorer. For now however, to ensure that the script works, four attributes need to be added to the project attributes.
Open the project attributes editor by choosing
and add these additional attributes. All are of type string except for the attribute password which is type password. Assign values to the attributes for testing purposes. Choose a description for each attribute that conveys the purpose of the attribute.const nMeasure := 1; dcluser user VMonitor transactions TSnap : 1; dclfunc .... // your functions here dcltrans transaction TSnap var hCon : number init 0; sHost : string; sCmd : string; sUser : string; sPwd : string; nVal : number; begin AttributeGetString("host", sHost, sizeof(sHost)); AttributeGetString("command", sCmd, sizeof(sCmd)); AttributeGetString("user", sUser, sizeof(sUser)); AttributeGetString("password", sPwd, sizeof(sPwd)); Connect(hCon, sHost); nVal := Request(hCon, sUser, sPwd, sCmd); MonitorInc(nMeasure, nVal); Close(hCon); end TSnap;
The project now consists of the newly created script. Save the project and verify that it works by initiating a TryScript run. Have nVal printed or written to a log file to verify that the script works. If the script works, save and close the project.