結果通知設定
    • PDF

    結果通知設定

    • PDF

    Article Summary

    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: NAVERクラウドプラットフォームポータルのマイページ > API認証キー管理メニューから 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)をご確認ください。


    この記事は役に立ちましたか?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.