Windows システム用のカスタム・エバリュエーターの作成

基本的なエバリュエーターでは、正しい評価基準を使用して前提条件プロパティーの期待値と実際の値を比較できない場合は、VBScript エバリュエーターを作成できます。カスタム・エバリュエーターを作成するときは、ファイル名の末尾を _compare とする必要があります。このファイルは /Windows サブディレクトリーに保管する必要があります。カスタム・エバリュエーターでは、必要に応じ、値の比較に共通の関数やサブルーチンを使用することができます。

始める前に

エバリュエーターを作成する前に、以下の付録に記載されている一連の関数とサブルーチンを必ず確認してください。これらのうちいずれかを使用して値を比較できるかどうか判別してください。
注: 共通関数 passOrFail() では、数値一般、MB または GB 単位のサイズ、MHz または GHz 単位のプロセッサー速度、ブール値、またはストリングの各データ型の実際の値と期待値を比較できます。この passOrFail 関数を使用できない場合にのみ、カスタム・エバリュエーターを作成してください。

手順

  1. VBScript ファイルを作成します。そのファイルを ips_root/Windows ディレクトリーに保存します。このとき、以下のファイル命名規則に従った名前を付けます。
    [prefix_identifier.]property_name[.suffix_identifier]_compare.vbs
    ここで、各部分の説明は次のとおりです。
    • prefix_identifier は、表 1 で概要を示した前提条件プロパティーの事前定義済みカテゴリーを表す ID です。この接頭部 ID は、一部の事前定義済みカテゴリーでは必須です。
    • property_name は、前提条件プロパティーの名前です。
    • suffix_identifier は、表 1 で概要を示した前提条件プロパティーのサブタイプを表すオプションの ID です。
  2. VBScript COM および関連する関数を使用して、引数としてエバリュエーターに渡された実際の値と期待値を比較するコードを追加します。この比較によって以下の標準出力が返されるようにします。
    • "PASS": 前提条件プロパティーの期待値が、前提条件プロパティーの実際の値と等価であるか、それより大きい場合。
    • "FAIL": 前提条件プロパティーの期待値が、前提条件プロパティーの実際の値と等価でない場合。
    注: ツールは、エバリュエーターの実行後、前提条件プロパティーの重大度レベルを分析します。前提条件プロパティーの重大度レベルが WARN に設定されているか、実際の値がサポート対象前提条件プロパティーの期待値の範囲内である場合は、結果が FAIL である検査のうち、該当するものが WARN に再調整されます。重大度レベルを参照してください。
  3. カスタム・エバリュエーターを実行して、実行時エラーが発生しないことを確認し、必要に応じてデバッグを行います。

以下に示すカスタム・エバリュエーターは、Tivoli® Directory Integrator のバージョンの実際の値と期待値を検査します。ここでは、共通関数 versionCompare() が使用されています。

wscript.echo "expect: " & wscript.arguments(0)
wscript.echo "real value: " & wscript.arguments(1)
wscript.echo tdiVersionCompare(wscript.arguments(0), wscript.arguments(1))

function tdiVersionCompare(expect, real)
    if len(real) = 0 then
        tdiVersionCompare = "FAIL"
        exit function
    end if
    
    expect = Trim(expect)
    real = Trim(real)
    
    Dim expectedVersion
    'if (StrComp(Right(expect,1),"+")=0 or StrComp(Right(expect,1),"-")=0) Then
    if (Right(expect,1)="+" or Right(expect,1)="-") Then
        expectedVersion = Left(expect,len(expect)-1)
    else 
        expectedVersion = expect
    end if
        
    Dim cmp
    cmp = versionCompare(expectedVersion,real)
    
    if (StrComp(Right(expect,1),"+")=0) Then
        ' Version must be at least expected value
        if (cmp=0 or cmp=-1) Then
            tdiVersionCompare = "PASS"
        else 
            tdiVersionCompare = "FAIL"
        end if
    elseif (StrComp(Right(expect,1),"-")=0) Then
            ' Version must be less than or equal to expected value
            if (cmp=0 or cmp=1) Then
                tdiVersionCompare = "PASS"
            else 
                tdiVersionCompare = "FAIL"
            end if
    elseif cmp=0 then
        tdiVersionCompare = "PASS"
    else
        tdiVersionCompare = "FAIL"
    end if
end function

' Generic function for comparing 2 version strings
'
' Parameters
'       ver1 The first version string
'       ver2 The second version string
'
' ver1 and ver2 are expected to be dot-separated version strings 
'(e.g. 1.0.0.4, 2.3, 3.40.26.7800, 2.3.a)Version strings can have any 
' number of parts. When comparing versions with different numbers of 
' parts, missing parts of the shorter version string will be treated 
' as if there was a zero there. If any non-numeric characters are 
' included in a version part, those corresponding parts will be compared 
' asstrings and not parsed into numeric form
'
' Returns
'       1 version1 > version2
'      -1 version1 < version2
'       0 version1 = version2
'
' Special cases:
' RESULT    version 1    version 2
'   0         empty        empty
'   1      validString     empty
'  -1         empty     validString
'
' NOTE: This function should eventually move to common_functions.vbs
  
function versionCompare(ver1, ver2)
    WScript.echo "Comparing [" & ver1 & "] to [" & ver2 & "]"
    
    Const UNASSIGNED = "*UNASSIGNED*"
    Dim v1Default, v2Default
    
    ' Handle special cases:
    if (IsEmpty(ver1) and IsEmpty(ver2)) Then
        versionCompare = 0
        exit function
    end if
    if (IsEmpty(ver1) and not IsEmpty(ver2)) Then
        versionCompare = -1
        exit function
    end if
    if (not IsEmpty(ver1) and IsEmpty(ver2)) Then
        versionCompare = 1
        exit function
    end if    
    
    Dim ver1Parts, ver2Parts
    
    ' Versions are not empty.  Break into parts and compare numbers
    ver1Parts = Split(ver1,".")
    ver2Parts = Split(ver2,".")
    
    Dim v1Size, v2Size
    v1Size = ubound(ver1Parts)
    v2Size = ubound(ver2Parts)
    
    ' If last version part is "*", treat all missing parts as "*" 
    '(so 2.* matches 2.1.3, for example)
    if (v1Size > v2Size) Then
        Redim Preserve ver2Parts(v1Size)
        if (ver2Parts(v2Size)="*") Then
            for i = v2Size to v1Size
                ver2Parts(i) = "*"
            next
        end if
    elseif (v2Size > v1Size) Then
        Redim Preserve ver1Parts(v2Size)
        if (ver1Parts(v1Size)="*") Then
            for i = v1Size to v2Size
                ver1Parts(i) = "*"
            next
        end if
    end if
    
    Dim i
    i = 0
    
    Do While (i<=ubound(ver1Parts) or i<=ubound(ver2Parts))
        Dim v1, v2, v1Str, v2Str
                
        v1Str = UNASSIGNED
        v2Str = UNASSIGNED
               
        if (i<=ubound(ver1Parts)) Then
            on error resume next
            v1 = Int(ver1Parts(i))
            if not Err=0 Then
                v1Str = ver1Parts(i)
                if (i<=ubound(ver2Parts)) Then
                    v2Str = ver2Parts(i)
                else 
                    v2Str = "0"
                end if
            end if
        else 
            v1 = 0
        end if
        
        if (i<=ubound(ver2Parts)) Then
            on error resume next
            v2 = Int(ver2Parts(i))
            if not Err=0 Then
                if (i<=ubound(ver1Parts)) Then
                    v1Str = ver1Parts(i)
                else 
                    v1Str = "0"
                end if
                v2Str = ver2Parts(i)
            end if
        else 
            v2 = 0
        end if
        
        if (not v1Str=UNASSIGNED or not v2Str=UNASSIGNED) Then                            
            if (IsEmpty(v1Str)) Then
                v1Str = "0"
            end if
            if (IsEmpty(v2Str)) Then
                v2Str = "0"
            End if
            
            'WScript.echo "Comparing as strings: " & v1Str & " : " & v2Str            
            ' Compare as Strings if either part could not be converted to a number
            if (not v1Str="*" and not v2Str="*") Then
                if (not v1Str=v2Str) Then
                    versionCompare = StrComp(v1Str,v2Str)
                    exit function
                end if
            end if
        else
            'WScript.echo "Comparing as numbers: " & v1 & " : " & v2

            if (v1 > v2) Then
                versionCompare = 1
                exit function
            end if
            if (v2 > v1) Then
                versionCompare = -1
                exit function
            end if
        end if
    
        i = i + 1
    Loop
    
    ' If we got here, versions must be equal
    versionCompare = 0
    
end function