| Sv translation | |||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| |||||||||||||||||||||||||||||||||||||
Для отправки события в Traffic Monitor по HTTP-протоколу реализован метод REST API
Версия API: ≥ 1.8 Метод: Ресурс: Описание: Метод отправляет событие в Traffic Monitor по протоколу HTTP. ПримерПримеры запросов:
Блок кода | | ||||||||||||||||||||||||||||||||||||
|
-X 'POST' \ 'https://109.73.44.69/xapi/push/event' \ -H 'accept: application/json' \ -H 'X-API-Auth-Token: 198igrnlnuonix672uq9' \ -H 'X-API-CompanyId: Yandex' \ -H 'X-API-Version: 1.8' \ -H 'Content-Type: multipart/form-data' \ -H 'X-Enable-OpenAPI: 1' \ -F 'event= { "evt_class": 3, "evt_service": "web_common", "evt_attributes": [ { "name": "event_name", "value": "Web Event Name" }, { "name": "capture_ts", "value": "2024-03-25T23:41:21+03:00" }, { "name": "capture_server_ip", "value": "127.0.0.1" }, { "name": "capture_server_fqdn", "value": "captureservername.domain" } ], "evt_senders": [ { "identity_id": 3, "identity_type": 0, "identity_contacts": [], "identity_contacts_with_meta": [ { "contact": { "name": "auth", "value": "userlogin@domain" } } ] }, { "identity_id": 4, "identity_type": 1, "identity_contacts": [], "identity_attributes": [ { "name": "workstation_type", "value": "ws_type_computer" } ], "identity_contacts_with_meta": [ { "contact": { "name": "dnshostname", "value": "computername.domain" } } ] } ], "evt_receivers": [ { "identity_id": 2, "identity_type": 3, "identity_contacts": [], "identity_attributes": [ { "name": "res_destination_host", "value": "testhost.com" }, { "name": "res_destination_url", "value": "\/file\/test.php" } ] } ], "evt_data": [ { "data_id": 1 } ] } |
Информация title Примечание: В примере выше значение
3поля"evt_class"
соответствует константе
kWeb.
Вместе с ним необходимо передать POST-запрос, например, в формате multipart
:
Блок кода language text title Пример запроса для отправляемых текстовых событий collapse true POST /file/test.php HTTP/1.1 Content-Type: multipart/form-data; boundary="----1234567890----" Content-Length: 110 Host: testhost.com ------1234567890---- Content-Type: text/plain Content-Disposition: inline Hello World ------1234567890------Блок кода language text title Пример запроса для отправляемых файлов collapse true POST /file/test.php HTTP/1.1 Content-Type: multipart/form-data; boundary="----1234567890----" Content-Length: 156 Host: testhost.com ------1234567890---- Content-Type: text/plain Content-Disposition: attachment; filename="file.txt" Hello World. This is text file. ------1234567890------
| Блок кода | ||||||
|---|---|---|---|---|---|---|
| ||||||
{
"data": {
"document_id": "string"
}
} |
Получение вердикта события, загруженного по протоколу HTTP
Для получения вердикта события используйте DataExport API. Необходимо предоставить массив с ID документа, полученным при загрузке события в Traffic Monitor, и датой: {documentID, date}.
| Блок кода | ||||||
|---|---|---|---|---|---|---|
| ||||||
curl -v -k -H "X-API-CompanyId: iw" \
-H "X-API-ProductName: PRODUCT" \
-H "X-API-Auth-Token: akkw713dh9a1awwhrn1" \
-H "X-API-Version: 1.8" \
"https://server.company.ru:9106/xapi/event/verdict?documentId=41a43cf1-bec3-44ae-9fd9-c1fe962e7886,7b6ad1fe-413c-486e-9dd1-c8e5a94a198b&date=2024-07-17" |
В примере выше server.company.ru – сервер с ролью Перехватчики.
Подробнее см. "Получение вердикта".
Рекомендации по производительности API при отправке событий в TM:
- Для улучшения производительности NGINX:
- В файле
/etc/nginx/nginx.confизмените значение параметраworker_processesна2. Сохраните изменения и перезагрузите сервис с помощью команды:
Блок кода language text systemctl restart nginx
- В файле
- При высокой нагрузке в журнале ошибок NGINX
/var/log/nginx/error.logмогут возникать сообщения вида:
socket() failed (24: Too many open files) while connecting to upstream.
В этом случае требуется увеличить ограничение сервиса на количество открытых файлов, например, до 10000:
Войдите в режим редактирования службы NGINX с помощью команды:
Блок кода language text systemctl edit nginx.service
Вставьте следующие строки в поле редактора:
Блок кода language text [Service]LimitNOFILE=10000
Сохраните изменения (Ctrl+O) и выйдите из режима редактирования (Ctrl+X).
Перезагрузите сервис с помощью команды:
Блок кода language text systemctl restart nginx
| Sv translation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
To upload events to Traffic Monitor via HTTP protocol, use
API Version: ≥ 1.8 Method: Resource: Description: The method sends the event to Traffic Monitor via HTTP protocol. ExampleQuery examples:
Блок кода | | title | A query for getting
' |
| Блок кода | ||||||
|---|---|---|---|---|---|---|
| ||||||
curl -X 'POST' \ 'https://109.73.44.69/xapi/push/event' \ -H 'accept: application/json' \ -H 'X-API-Auth-Token: 198igrnlnuonix672uq9' \ -H 'X-API-CompanyId: Yandex' \ -H 'X-API-Version: 1.8' \ -H 'Content-Type: multipart/form-data' \ -H 'X-Enable-OpenAPI: 1' \ -F 'event= { "evt_class": 3, "evt_service": "web_common", "evt_attributes": [ { "name": "event_name", "value": "Web Event Name" }, { "name": "capture_ts", "value": "2024-03-25T23:41:21+03:00" }, { "name": "capture_server_ip", "value": "127.0.0.1" }, { "name": "capture_server_fqdn", "value": "captureservername.domain" } ], "evt_senders": [ { "identity_id": 3, "identity_type": 0, "identity_contacts": [], "identity_contacts_with_meta": [ { "contact": { "name": "auth", "value": "userlogin@domain" } } ] |
}, {
"
identity_id":
4,
"identity_type": 1,
"identity_contacts": [],
"identity_attributes": [
{ "name": "
workstation_type", "value": "ws_type_computer" }
], "identity_contacts_with_meta": [
{ "contact": { "name": "
dnshostname", "value": "
computername.domain" }
}
] } ],
"evt_receivers": [
{
"
identity_id":
2, "identity_type": 3,
"identity_contacts": [],
"
identity_
attributes": [
{ "name": "
res_destination_host", "value": "testhost.com" }, { "
name": "res_destination_url", "value": "\/file\/test.php" }
]
} ], "
evt_
data": [ {
"
data_
id": 1 }
Value 3 of the "evt_class" field corresponds to the kWeb constant. Along with it, you must send a POST request, for example, in multipart format.
] }Информация title Note: In the example above, value
3of the"evt_class"field corresponds to thekWebconstant. Along with it, you must send a POST request, for example, in multipart format.Блок кода language text title Example query for text events being sent collapse true POST /file/test.php HTTP/1.1 Content-Type: multipart/form-data; boundary="----1234567890----" Content-Length: 110 Host: testhost.com ------1234567890---- Content-Type: text/plain Content-Disposition: inline Hello World ------1234567890------Блок кода language text title Example query for files being sent collapse true POST /file/test.php HTTP/1.1 Content-Type: multipart/form-data; boundary="----1234567890----" Content-Length:
156 Host: testhost.com ------1234567890---- Content-
| title | Example query for files being sent |
|---|---|
| collapse | true |
Type: text/plain Content-Disposition: attachment; filename="file.txt" Hello World. This is text file. ------1234567890------
| Блок кода | ||||||
|---|---|---|---|---|---|---|
| ||||||
{
"data": {
"document_id": "string"
}
} |
Getting verdict for events uploaded via HTTP protocol
To get verdict for an event, use DataExport API. Provide an array of document ID, which you received as output after the event had been uploaded to Traffic Monitor, and date: {documentID, date}.
| Блок кода | ||||||
|---|---|---|---|---|---|---|
| ||||||
curl -v -k -H "X-API-CompanyId: iw" \
-H "X-API-ProductName: PRODUCT" \
-H "X-API-Auth-Token: akkw713dh9a1awwhrn1" \
-H "X-API-Version: 1.8" \
"https://server.company.com:9106/xapi/event/verdict?documentId=41a43cf1-bec3-44ae-9fd9-c1fe962e7886,7b6ad1fe-413c-486e-9dd1-c8e5a94a198b&date=2024-07-17" |
In the example above, server.company.com is a server with Interceptors role.
For details, see "Получение вердикта".
Recommendations on API performance when uploading events to TM:
- To improve NGINX performance:
- In
/etc/nginx/nginx.conf, change theworker_processesparameter value to2. Restart the service with the command:
Блок кода language text systemctl restart nginx
- In
- In case of high load, the NGINX log file
/var/log/nginx/error.logmay contain messages which look as follows:
socket() failed (24: Too many open files) while connecting to upstream.
To avoid the error, increase the file-opening limit of the service, for example, to 10000:
Enter the NGINX service editing mode using the command:
Блок кода language text systemctl edit nginx.service
Paste the following lines into the editor:
Блок кода language text [Service]LimitNOFILE=10000
- Save changes (Ctrl+O) and exit (Ctrl+X).
Restart the service with the command:
Блок кода language text systemctl restart nginx