Creating a copy of all syslog error records into a custom table using scheduled script execution

Bart Jan Bultma
Kilo Sage

In short, we want to have a dashboard with reports on errors from syslog. OOTB it's not allowed (nor advised) to do this. So we came up with the solution to copy all the errors in syslog table to a custom table and report on those. We can easily flush this table on a schedule or whenever we need to withouth causing issues.

 

I've created a Scheduled Script Execution that runs every 1 hour. This script should query all type=error created=last hour records and add those to my custom table. However, the query doesnt seem to be working, and I'm not sure why.

 

If I comment the query and change the script to just create a single record, it works. So I conclude the issue is with the query.

 

Spoiler
//query the syslog records created in the last hour

var gr = new GlideRecord('syslog');
gr.addEncodedQuery('sys_created_onRELATIVEGT@hour@ago@1^level=2');
gr.query();


//for each of the resulting records, create a corresponding record in our custom error log table
while (gr.next()) {
    var newGr = new GlideRecord('x_iasrn_asr_error_error_log');
    newGr.initialize();

    //fill the required information and create the new record
    newGr.message = 'test message 2';//gr.message;
    newGr.level = '2';//gr.level;
    newGr.u_error_created_by = records.sys_created_by;
    newGr.source = records.source;
    newGr.context_map = records.context_map;
    newGr.insert();
}
0 REPLIES 0