Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
This class provides methods that allow importing data from external parties.
SimpleImport()
Instantiates a new SimpleImport class object.
Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
const imp = new SimpleImport(); |
getErrorMessage()
This method returns the current error message.
Return:
Type | Description |
---|---|
String | The error message text |
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const imp = new SimpleImport();
if (imp.transform(current)) {
ss.addInfoMessage('Import succeeded');
} else {
ss.addErrorMessage(imp.getErrorMessage());
} |
import(record, testMode)
The method takes a record from the Import Sources (sys_import_source) tables and imports the entries from the attachment to the table created via the Import Set Table Name field of the Import Sources (sys_import_source) table. As a result, we get a table with temporary records – an import set, from which the system will import records to any other table.
The record parameter should be a record from the Import Sources (sys_import_source) table.
The testmode parameter is a Boolean parameter. If its value is 'true', then it will perform the test import and indicate operation status as "test".
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
record | SimpleRecord | Y | N |
testMode | Boolean | N | 'false' |
Return:
Type | Description |
---|---|
Boolean | This method returns 'true' if the import has been completed successfully; otherwise, it returns 'false'. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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)
This method is used for the automatic scheduled import.
The record parameter must be the record from the Scheduled Imports (sys_schedule_import)
table.
Method gets the record from the Scheduled Imports (sys_schedule_import) table and performs import and transform in one time.Method description
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
record | SimpleRecord | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||
---|---|---|---|---|
|
transform(record)
| |||||
const imp = new SimpleImport();
imp.importTransform(current); |
testLdapConnection(record)
This method checks the connection to the LDAP server and alerts about the 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 with this connection. Method description
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
record | SimpleRecord (object of the LDAP server (sys_ldap_server) table) | Y | N |
Return:
Type | Description |
---|---|
Object | Returns an object containing LDAP server connection status or connection error message (in case of connectivity issues). |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
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 checks all connections to the LDAP server and alerts about the 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 with this connection. Method description
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
record | SimpleRecord (object of the LDAP server (sys_ldap_server) table) | Y | N |
Return:
Type | Description |
---|---|
Object | Returns an object containing LDAP server connections statuses or connection error messages (in case of connectivity issues). |
Example:
Code Block | ||||
---|---|---|---|---|
|
importTransform(record)
| |||||
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 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 fields in an import set and fields in an existing table.Method description
Parameter(s):
Name | Type | Mandatory | Default Value |
---|---|---|---|
record | SimpleRecord | Y | N |
Return:
Type | Description |
---|---|
Void | This method does not return a value. |
Example:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
const imp = new SimpleImport();
imp.transform(current); |
Table of Contents | ||||
---|---|---|---|---|
|