Set result notifications

Prev Next

Available in Classic and VPC

You can write codes that set scan result notifications using the REST API of Hash Filter and File Filter.

Note

Before developing File Filter, you need to subscribe to File Safer and API Gateway, and create an API Key. For more information, see Getting started.

Scenario for setting scan result notifications

The scenario for using the setNotiConfig API to set scan result notification is as follows:

filesafer-programming-noti_scenario_ko

1. Create authentication value
2. Create request body
3. Request API

Note

Writing codes for setting scan result notifications

Write the codes according to the scenario. setNotiConfig of Hash Filter and setNotiConfig of File Filter differ only in the request URI, and the authentication value and parameter settings are the same.

1. Create authentication value

Create an IAM authentication value required for the NAVER Cloud Platform API use authentication. The headers required for authentication are as follows:

  • x-ncp-iam-access-key: Issue Access Key from the My Account > Account and security management > Security management > Access management menu on the console.
  • x-ncp-apigw-signature-v2: Create a signature value by HmacSHA256-encrypting the Secret Key mapped with the Access Key (use \n for a new-line character).
  • x-ncp-apigw-api-key: Issue API Key through API Gateway.
  • x-ncp-apigw-timestamp: Not an authentication value, but included in the request header. See API specifications.
Note

For information on how to create a signature value and example codes, see NAVER Cloud Platform API guide > API overview > Basic API > Ncloud API > 2. Create header.

2. Create request body

Set notificationType, which is the result notification setting value, in the body of the setNotiConfig API. The notificationType setting value is as follows:

notificationType Description
OFF Do not notify.
MAL Notify when malware is detected (queried).
MAE Notify when malware is detected or query fails.
ERR Notify when query fails.
ALL Notify all.

3. Request API

Send the request to the Hash Filter setNotiConfig URI or 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

The following is an example code for requesting the 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);
	}

}
Note

You can also use the advanced settings feature to receive notifications of analysis results. This feature notifies you when malware detections reach the specified threshold within a set period. For detailed information about this API, see setThresholdNotiConfig (Hash Filter/File Filter).