SunOS の「ps」など、BDL で特定のコマンド ライン ツールをリモートから実行するには、3 つの関数が必要です。
// 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; Silk Performer MeasureInc の関数には、ラッパー関数が必要です。 この関数は、すべての監視プロジェクトで使用できます。 プロジェクト属性にアクセスするため、MonitorInc という名前の関数が作成されます。 この関数は、以前に指定した属性にアクセスします。
また、MonitorInc 関数を既存の 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; これで、定義されているすべての関数を使用してスナップショットを取得するトランザクションをコーディングすることができます。 また、このトランザクションは、プロジェクト ファイル属性にもアクセスします。 目標は、これらの属性を後から Performance Explorer で設定することです。 ただし、ここでは、スクリプトが機能することを確認するため、4 つの属性をプロジェクト属性に追加する必要があります。
を選択してプロジェクト属性エディタを開き、これらの追加属性を追加します。 これらは、パスワード型の属性パスワードを除いて、すべて文字列型です。 テストのため属性に値を割り当てます。 属性の目的を示す各属性の説明を選択します。
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; これで、プロジェクトが新しく作成されたスクリプトによって構成されます。 プロジェクトを保存し、TryScript の実行を開始して、機能することを検証します。 nVal を印刷するかログ ファイルに書き込むことにより、スクリプトが機能することを検証します。 スクリプトが機能した場合は、プロジェクトを保存して閉じます。