結果通知設定

Prev Next

Classic/VPC環境で利用できます。

Hash Filterと File Filterが REST APIを使用し、検査結果通知の設定コード作成する方法を説明します。

参考

File Filter開発の先に、File Saferご利用の申し込み、API Gatewayご利用の申し込みと API Keyを作成する必要があります。詳細は、File Safer を開始するをご参照ください。

検査結果通知設定のシナリオ

setNotiConfig APIを使用して検査結果通知を設定するシナリオは、次の通りです。

filesafer-programming-noti_scenario_ko

1.認証値作成
2.リクエスト Body作成
3.APIリクエスト

参考

検査結果通知設定のコード作成

シナリオに従ってコードを作成します。Hash Filterの setNotiConfigと File Filterの setNotiConfigは、リクエスト URIのみ異なります。認証値とパラメータ設定は同じです。

1.認証値作成

NAVERクラウドプラットフォーム API使用認証に必要な IAM認証値を作成します。認証に必要なヘッダは次の通りです。

  • x-ncp-iam-access-key: コンソールの My Account > アカウントとセキュリティ管理 > セキュリティ管理 > アクセス管理メニューから Access Keyを発行
  • x-ncp-apigw-signature-v2: Access Keyとマッピングされる Secret Keyを HmacSHA256暗号化し、signature値を作成(改行文字は \nを使用)
  • x-ncp-apigw-api-key: API Gatewayで API Keyを発行
  • x-ncp-apigw-timestamp: 認証値ではないがリクエストヘッダに含まれる。API明細を参照
参考

signature値を作成する方法とサンプルコードは、NAVERクラウドプラットフォーム APIガイド > API の概要 > 基本 API > Ncloud API > 2.ヘッダ作成をご参照ください。

2.リクエスト Body作成

setNotiConfig APIの Bodyに結果通知設定値として notificationTypeを設定します。 notificationTypeの設定値は次の通りです。

notificationType 説明
OFF 通知しない
MAL マルウェア検知(照会)時に通知
MAE マルウェア検知時、または照会失敗時に通知
ERR 照会失敗時に通知
ALL すべて通知

3.APIリクエスト

Hash Filter setNotiConfig URIまたは File Filter setNotiConfig URIにリクエストを送信します。

  • Hash Filter setNotiConfig URI: https://filesafer.apigw.ntruss.com/hashfilter/v1/setNotiConfig
  • File Filter setNotiConfig URI: https://filesafer.apigw.ntruss.com/filefilter/v1/setNotiConfig

以下は、Hash Filter setNotiConfig APIリクエストのサンプルコードです。

public void setNotiConfig() throws Exception
{
	String ACCESSKEY = "AAAAAAAAAAAAAAAAAAAA"; // access key (from portal or sub account)
    String apikey = API_GATEWAY_KEY;
	long timestamp = System.currentTimeMillis();
	String method = "POST";
	String apiURL = "/hashfilter/v1/setNotiConfig"; 

	String signature = makeSignature(method, apiURL, timestamp);

	URL url = new URL(apiDomain + apiURL);
	HttpURLConnection con = (HttpURLConnection)url.openConnection();
	con.setDoOutput(true);
	con.setRequestMethod(method);
	con.setRequestProperty("x-ncp-apigw-timestamp", Long.toString(timestamp));
	con.setRequestProperty("x-ncp-iam-access-key", ACCESSKEY);
	con.setRequestProperty("x-ncp-apigw-signature-v2", signature);
    con.setRequestProperty("x-ncp-apigw-api-key", apikey);
	con.setRequestProperty("Content-Type", "application/json");
	con.setRequestProperty("accept", "application/json");

	// write request body
	DataOutputStream dos = new DataOutputStream(con.getOutputStream());
	dos.writeBytes("{\r\n");
	dos.writeBytes("    \"notificationType\": \"ALL\"\r\n");
	dos.writeBytes("}");

	// read http response code
	int responseCode = con.getResponseCode();
	BufferedReader br = null;

	if(responseCode == 200) {
		br = new BufferedReader(new InputStreamReader(con.getInputStream()));
	} else {
		br = new BufferedReader(new InputStreamReader(con.getErrorStream()));
	}

	// read http response body
	String inputLine;
	StringBuffer response = new StringBuffer();
	while ((inputLine = br.readLine()) != null) {
		response.append(inputLine);
	}

}
参考

分析結果通知を受けるため、高度な設定機能も使用できます。高度な設定は一定時間しきい値に該当するマルウェアが検知されると、通知する機能です。当該 APIに関する詳細な説明は、setThresholdNotiConfig(Hash Filter/File Filter)をご確認ください。