カスタム・アクション・スクリプトへのパラメーターの引き渡し

Bash、Python、および Perl のサンプル・スクリプトは、パラメーターをカスタム・アクション・スクリプトに渡す方法を示しています。

以下のシンプルなサンプル・スクリプトは、アセット・モデル API で指定のオフェンス・ソース IP アドレスを持つアセットを照会する方法を示しています。 この例では、便宜上、各スクリプトは、エンドポイントから返される JSON を出力します。

これらのスクリプトには以下の 3 つのパラメーターが必要です。

  • コンソール IP アドレス
  • APIトークン
  • オフェンス・ソース IP アドレス

これらのパラメーターは、以下のように、「カスタム・アクションの定義」ウィンドウの「スクリプト・パラメーター」域で構成します。

図1: カスタム・アクション・スクリプトのパラメーター
カスタム・アクション・スクリプトのパラメーター

各パラメーターは、「カスタム・アクションの定義」ウィンドウで追加された順序でスクリプトに渡されます。 この場合、以下のようになります。

  1. console_ip
  2. api_token
  3. offense_source_ip
重要: この例には、ネットワーク・イベント・プロパティーが含まれています。 テスト・ページでサンプル・スクリプトを正常に実行するためには、offense_source_ipに固定プロパティー値としてソース IP アドレス (xx.xx.xx.xx) を割り当てる必要があります。

各サンプル・スクリプトの先頭で定義されている変数では、「カスタム・アクションの定義」ウィンドウで追加されたサンプル・パラメーター名が使用されます。

図 2. call_asset_model.sh
#!/bin/bash
console_ip=$1 
api_token=$2
offense_source_ip=$3

auth_header="SEC:$api_token"

output=$(curl -k -H $auth_header https://$console_ip/console/restapi/api/
asset_model/assets?filter=interfaces%20contains%20%28%20ip_addresses
%20contains%20%28%20value%20%3D%20%22$offense_source_ip%22%29%29)

# Basic print out of the output of the command
echo $output
図 3. call_asset_model.py
#!/usr/bin/python
import sys
import requests
console_ip = sys.argv[1] 
api_token = sys.argv[2]
offense_source_ip = sys.argv[3]

auth_header = {'SEC' : api_token }

endpoint = "https://{0}/console/restapi/api/asset_model/
assets?filter=interfaces%20contains%20%28%20ip_addresses
%20contains%20%28%20value%20%3D%20%22{1}%22%29%29"
.format(console_ip, offense_source_ip)

response = requests.get(endpoint, headers=auth_header, verify=False)

# Basic print out of the output of the command
print(response.json())
図 4. call_asset_model.pl
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;

my $console_ip = $ARGV[0]; 
my $api_token = $ARGV[1];
my $offense_source_ip = $ARGV[2];

my $endpoint = "https://$console_ip/console/restapi/api/asset_model/
assets?filter=interfaces%20contains%20%28%20ip_addresses
%20contains%20%28%20value%20%3D%20%22$offense_source_ip%22%29%29";

my $client = LWP::UserAgent -> new(ssl_opts => { verify_hostname => 0 });

my $response = $client -> get($endpoint, "SEC" => $api_token);

# Basic print out of the output of the command
print $response -> decoded_content;