PowerShell アクティブモニタでのコンテキストオブジェクトの使用
- Last Updated: September 25, 2024
- 5 minute read
- WhatsUp Gold
- Version 2024
使用可能なモニタのオブジェクトと属性
PowerShell アクティブモニタスクリプトでは、2 つのインスタンス化セッションオブジェクトを利用できます。
- [コンテキスト]。IScriptContext インターフェイスの実装。このオブジェクトを使用するとランタイム変数にアクセスでき、結果をクライアントに返すメカニズムも提供します。便利なメソッドの一部を以下に示します。
- object GetProperty(string propertyName) - コンテキスト変数値を名前で取得できます。
- object SetProperty (string propertyName, string propertyValue ) - コンテキスト変数値を名前で指定できます。
- void SetResult(int resultCode, ResultsString) - 成功を示す値をスクリプトで設定できます。通常、0 は成功、1 は失敗です。
- ロガー。ILog インターフェイスの実装。このオブジェクトは、C# アプリケーションで利用可能なメソッドと同じメソッドを提供します。便利なメソッドの一部を以下に示します。
- void Error(string message) - メッセージを含んでいるエラー固有のログエントリを作成します。
- void Information(string message) - メッセージを含んでいる情報固有のログエントリを作成します。
- void WriteLine(string message) - メッセージを含んでいる汎用ログエントリを作成します。
コンテキストオブジェクトのプロパティの取得または設定
PowerShell アクティブモニタスクリプトを使用してコンテキストのプロパティの値をフェッチできます。
構文
Property-Value = Context.GetProperty("Property-Name")
Context.SetProperty("Property-Name","Property-Value")
例
$DeviceIpAddress = $Context.GetProperty("Address")
$Context.SetProperty("Timeout","180")
結果文字列とモニタステータスインジケータの設定
設定した結果文字列は、モニタのステータス変更の説明に追加されます。設定するステータスフラグ (0, 1) 稼働/停止 によって、[状態変化タイムライン] に表示されるインジケータが決まります。
# デバイス IP を正常に取得した後、結果として設定し、成功フラグを設定 ...
$Context.SetResult(0, "Device IP address is: " + $DeviceIpAddress)
コンテキストオブジェクトのプロパティ
次のプロパティには、PowerShell アクティブモニタスクリプトの構文の例★次の文節の訳を挿入★の実行時に作成された接続オブジェクトからアクセスできます。 ★前の文節に訳文を統合★
プロパティ名 |
説明 |
|---|---|
|
DeviceID |
WhatsUp Gold デバイスの識別文字列。 |
|
Address |
IP アドレス。 |
|
Timeout |
このセッションのタイムアウト値。(秒) |
コンテキストオブジェクトの認証情報プロパティ
PowerShell アクティブモニタスクリプトの構文の例について、次の認証情報プロパティを設定できます。これらは、アクティブモニタを使用して PowerShell の初期接続を確立した後、その他のサービス、プラットフォーム、アプリケーションに接続する必要がある場合に役立ちます。
プロパティ名 |
説明 |
|---|---|
|
CredWindows:DomainAndUserid |
Windows 認証情報のドメインおよびユーザー。 |
|
CredWindows:Password |
Windows パスワードを設定します。 |
|
CredSnmpV1:ReadCommunity |
SNMPv1 の読み取りコミュニティ文字列。 |
|
CredSnmpV1:WriteCommunity |
SNMPv1 の書き込みコミュニティ文字列。 |
|
CredSnmpV2:ReadCommunity |
SNMPv2 の読み取りコミュニティ文字列。 |
|
CredSnmpV2:WriteCommunity |
SNMPv2 の書き込みコミュニティ文字列。 |
|
CredSnmpV3:AuthPassword |
SNMPv3 のパスワード。 |
|
CredSnmpV3:AuthProtocol(integer-value) |
SNMPv3 認証プロトコル。値: 1 = なし、2 = MD5、3 = SHA |
|
CredSnmpV3:EncryptProtocol(integer-value) |
整数値には、次のいずれかを指定できます。
|
|
CredSnmpV3:EncryptPassword |
SNMPv3 の暗号化パスワード。 |
|
CredSnmpV3:Username |
SNMPv3 のユーザー。 |
|
CredSnmpV3:Context |
SNMPv3 のコンテキスト。 |
|
CredADO:Password |
ADO のパスワード。 |
|
CredADO:Username |
ADO のユーザー名。 |
|
CredSSH:Username |
SSH のユーザー名。 |
|
CredSSH:Password |
SSH のパスワード。 |
|
CredSSH:EnablePassword |
パスワードのフラグを有効にします。 |
|
CredSSH:Port |
デフォルト以外の場合、SSH ポート。 |
|
CredSSH:Timeout |
SSH セッションのタイムアウト。 |
|
CredVMware:Username |
VMware のユーザー名。 |
|
CredVMware:Password |
VMware のパスワード。 |
|
CredTelnet:Timeout |
Telnet 接続のタイムアウト値。 |
|
CredTelnet:Port |
Telnet ポート (デフォルト以外の場合)。 |
|
CredTelnet:Username |
Telnet のユーザー名。 |
|
CredTelnet:Password |
Telnet のパスワード。 |
|
CredJMX:Username |
Java Management Extensions のユーザー名。 |
|
CredJMX:Password |
Java Management Extensions のパスワード。 |
|
CredSMIS:Timeout |
Storage Management のタイムアウト。 |
|
CredSMIS:Port |
Storage Management のポート。 |
|
CredSMIS:Protocol |
Storage Management のプロトコル。 |
|
CredSMIS:Username |
Storage Management のユーザー名。 |
|
CredSMIS:Password |
Storage Management のパスワード。 |
|
CredAWS:AccessKeyID |
Amazon Web Services のアカウント ID。 |
|
CredAWS:SecureAccessKey |
Amazon Web Services のアクセスキー。 |
|
CredAzure:TenantID |
Azure のサブスクリプション ID。 |
|
CredAzure:ClientID |
Azure クライアントのアカウント ID。 |
|
CredAzure:SecureKey |
Azure のアカウントキー。 |
|
CredRestAPI:Username |
デバイスに対して認証を行うためのユーザー名。 |
|
CredRestAPI:Password |
ユーザー名に関連付けられたパスワード。 |
| CredRedfish:Username | ハードウェアデバイスへのアクセスに必要なユーザ名。 |
| CredRedfish:Password | ハードウェアデバイスへのアクセスに必要なパスワード。 |
|
CredRedfish:Protocol |
デバイスとのセキュアな通信に使用されるプロトコル。 |
|
CredRedfish:Port |
デバイスとの通信に使用されるポート番号。 |
| CredRedfish:Timeout | 接続を試行する時間。 |
|
CredRedfish:Retries |
WhatsUp Gold がデバイスとの通信に使用する試行回数。 |
|
CredRedfish:IgnoreCertificateErrors |
認証エラーを無視する |
例: サービスが稼働中かどうかをチェックする
保存されている認証情報を使用して DNS クライアントが実行されている場合にのみ、稼働のステータスを示す PowerShell アクティブモニタを作成します。
# Device to Poll
$DeviceIpAddress = $Context.GetProperty("Address")
# Set the computer name directly, or...
# $CompName = mydb02.corpnet.example.com (for example)
# ...get it using WMI...
$WmiRes = Invoke-Command -ComputerName $DeviceIpAddress -ScriptBlock { Get-WmiObject Win32_Computersystem }
$CompName = $WMIRes.PSComputerName
# Run command on remote device
$PsResult = Invoke-Command -ComputerName $DeviceName -ScriptBlock { Get-Service | where { $_.Name -match "Dnscache" } }
# Check for condition of 'running'
if ($PsResult.Status -match 'Running') {
$RespondingMessage = "Process '" + $processName + "' running on " + $DeviceIpAddress + " is responding."
$Context.SetResult(0, $RespondingMessage )
} else {
$NotRunningMessage = "Process '" + $processName + "' running on " + $DeviceIpAddress + " is not responding."
$Context.SetResult(1, $NotRunningMessage )
}