- Print
- PDF
Set result notifications
- Print
- PDF
Available in Classic and VPC
It describes how to write codes that set scan result notifications using the REST API of Hash Filter and File Filter.
Before developing File Filter, you need to subscribe to File Safer, subscribe to API Gateway, and create an API Key. For more information, see Getting started with File Safer.
Scenario for setting scan result notifications
The scenario for using the setNotiConfig API to set scan result notification is as follows:
1. Create authentication value
2. Create request body
3. Request API
- For information on setNotiConfig API specifications, see setNotiConfig (Hash Filter/File Filter).
- To check current settings, see getNotiConfig (Hash Filter/File Filter).
Write result notification settings code
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
: get the access key issued in the My page> Manage API authentication key menu of the NAVER Cloud Platform portalx-ncp-apigw-signature-v2
: create a signature value by HmacSHA256-encrypting the Secret Key mapped with the Access Key (Use \n for the newline character)x-ncp-apigw-api-key
: get the API Key issued through the API Gatewayx-ncp-apigw-timestamp
: it is not an authentication value, but it is included in the request header. See API specifications.
For information on how to create a signature value and example codes, see NAVER Cloud Platform API guide > API overview > Default API > Ncloud API > 2. Create headers.
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 |
MAE | Notify when malware is detected or search fails |
ERR | Notify when search failed |
ALL | Notify everyone |
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);
}
}
You can also use the advanced settings feature to be notified of the analysis results. The advanced setting is a function that notifies you when malware corresponding to a threshold is detected for a certain period. For a detailed description of the API, see setThresholdNotiConfig (Hash Filter/File Filter)