- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2020 12:56 AM
this is the sample data of text file first coloumn represents location field and second column asset tag how to load this data in data source if parsing then how do i parse with script
Thank you
Solved! Go to Solution.
- Labels:
-
Integrations
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2020 04:38 PM
One approach is to use the 'Custom (Parse by Script)' format for a data source.
Based on the file you provided, the following parsing script can be used in the data source:
Parsing Script
// The input value can be accessed through the variables named "line", "lineNumber" and "result"
// The function uses result variable to return parse result back.
(function(line, lineNumber, result) {
var map = {};
var items = line.split("|");
map['location'] = items[0];
map['asset'] = items[1];
result.addRow(map);
})(line, lineNumber, result);
Data Source Record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2020 05:01 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2020 05:22 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2020 04:38 PM
One approach is to use the 'Custom (Parse by Script)' format for a data source.
Based on the file you provided, the following parsing script can be used in the data source:
Parsing Script
// The input value can be accessed through the variables named "line", "lineNumber" and "result"
// The function uses result variable to return parse result back.
(function(line, lineNumber, result) {
var map = {};
var items = line.split("|");
map['location'] = items[0];
map['asset'] = items[1];
result.addRow(map);
})(line, lineNumber, result);
Data Source Record
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2020 07:44 AM
Thank you very much
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-19-2023 11:14 PM - edited 01-19-2023 11:18 PM
@Jon23 Thanks for sharing this, adding to your script I have utilized this concept to parse midserver logs.
Since its in .txt format I wanted a way to convert that to data source and import set table to better analyze the data and I didnt want to manually convert it to csv or touch the file, below is the script I created to achieve that.
// The input value can be accessed through the variables named "line", "lineNumber" and "result"
// The function uses result variable to return parse result back.
(function(line, lineNumber, result) {
var map = {};
var items = line.split(" ");
map['datetime'] = items[0];
var items1 = line.split(" ");
map['level'] = items1[0];
map['message'] = items1[1];
result.addRow(map);
})(line, lineNumber, result);