You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Этот класс предоставляет собой методы, позволяющие импортировать данные из внешних источников.

SimpleImport()


Используйте этот метод для создания нового экземпляра объекта класса SimpleImport.

Пример:

SimpleImport
const imp = new SimpleImport();

getErrorMessage()


Данный метод возвращает сообщение о текущей ошибке.


Возвращаемое значение:

ТипОписание
StringТекс сообщения об ошибке


getErrorMessage
const imp = new SimpleImport();
if (imp.transform(current)) {
    ss.addInfoMessage('Import succeeded');
} else {
    ss.addErrorMessage(imp.getErrorMessage());
}

import(record, testMode)


Метод берет запись из таблицы Источники для импорта (sys_import_source) и импортирует записи из вложения в таблицу, созданную с помощью поля Наименование таблицы импорта таблицы Источники для импорта (sys_import_source). В результате получается таблица с временными записями: набор импорта, из которого система импортирует записи в любую другую таблицу.

Параметр record должен быть записью из таблицы Источники для импорта (sys_import_source).

Параметр testMode является параметром Boolean. Если его значение равно «true», он выполняет тестовый импорт и отображает статус операции как «тест».


Параметры:

НазваниеТипОбязательныйЗначение по умолчанию
recordSimpleRecordДаНет
testModeBooleanНетfalse


Возвращаемое значение:

ТипОписание
BooleanМетод возвращает значение 'true' при успешном выполнении импорта; значение 'false' возвращается при ошибке.


Пример:

import
const current = new SimpleRecord('sys_import_source');
current.name='Test Imp JSON'
current.format='JSON'
current.import_set_table_name = 'c_imp_text_json2';
current.import_text = '{"token":"example_Token","user":"zabix_user","title":"Problem: Agent is not available (for 3m)","message":"Problemverity: Average","url":"/tr_events.php","url_title":"ZabbixUrlTitle","priority":"0"}';
current.type = 'Text';
current.insert();
ss.info("RecordImp: " + current.getErrors())
const imp = new SimpleImport();
const result = imp.import(current);
if (result) {
    ss.addInfoMessage("Import successful");
    return;
} else {
    ss.info("Errors Import:  " + imp.getErrorMessage());
    ss.addErrorMessage("Import failed");
}

importTransform(record)


Use this method for the automatic scheduled import.

The record parameter must be the record from the Scheduled Imports (sys_schedule_import) table.

The method gets a record from the Scheduled Imports (sys_schedule_import) table, performs import and transforms in one time.


Используйте этот метод для автоматического запланированного импорта.

Параметр записи должен быть записью из таблицы запланированного импорта (sys_schedule_import).

Метод получает запись из таблицы Scheduled Imports (sys_schedule_import), выполняет импорт и преобразование одновременно.


Параметры:

НазваниеТипОбязательныйЗначение по умолчанию
recordSimpleRecordДаНет


Возвращаемое значение:

ТипОписание
Void

Метод не возвращает значение.


Пример:

importTransform
const imp = new SimpleImport();
imp.importTransform(current);

testLdapConnection(record)


This method verifies the connection to the LDAP server and alerts about a successful connection or about an error.

The record parameter must be the filled with the sys_id of the LDAP server (sys_ldap_server) table element related to this connection.  


Параметры:

NameTypeОбязательныйЗначение по умолчанию
record

SimpleRecord

(object of the LDAP server (sys_ldap_server) table)

YN


Возвращаемое значение:

TypeОписание
ObjectThe method returns an object containing an LDAP server connection status or a connection error message (in case of connectivity issues).


Пример:

testLdapConnection
const imp = new SimpleImport();
const result = imp.testLdapConnection(current);
if (result.flash.type === "success") {
    ss.addInfoMessage(result.flash.message);
    return;
}
if (result.flash.type === "error") {
    ss.addErrorMessage(result.flash.message);
}


testLdapConnections(record)


This method verifies all connections to the LDAP server and alerts about a successful connection or about an error.

The record parameter must be the filled with the sys_id of the LDAP server (sys_ldap_server) table element related to this connection. 


Параметры:

NameTypeОбязательныйЗначение по умолчанию
record

SimpleRecord

(object of the LDAP server (sys_ldap_server) table)

YN


Возвращаемое значение:

TypeОписание
ObjectThe method returns an object containing LDAP server connections statuses or connection error messages (in case of connectivity issues).


Пример:

testLdapConnection
const imp = new SimpleImport();
const result = imp.testLdapConnections(current);
if (result.flash.type === "success") {
	ss.addInfoMessage(result.flash.message);
    return;
}
if (result.flash.type === "error") {
	ss.addErrorMessage(result.flash.message);
}

transform(record)


This method transposes the entries from the import set to the table. It uses the active transform map, which is located in the Transform Maps (sys_transform_map) table.

  • source – the current import set table
  • target – the destination import set table.

The record parameter must be the entry from the Import Set (sys_import_set) table.

A transform map is a set of field maps that determine the relationships between the fields in an import set and the fields in an existing table.


Параметры:

NameTypeОбязательныйЗначение по умолчанию
recordSimpleRecordYN


Возвращаемое значение:

TypeОписание
VoidThis method does not return a value.


Пример:

transform
const imp = new SimpleImport();
imp.transform(current);

  • No labels