three types of event logs, transaction logs, and system logs by sending them to ZIP file

shaik13
Tera Contributor

Hi Team,

 

Three types of event logs, transaction logs, and system logs by sending them to a file and attaching them by email.

And need to attach these three types of files in a single zip file when attaching files to an email in the script of a job.

so, I have developed three different csv files but need concern on those three types of files in a single zip file when attaching files to an email in the script of a job.

 

Here I am using this script, please need your suggestion on the below script three types of files in a single zip file.

 

//var sysid = g_request.getParameter('sysparm_sys_id');
//var table = g_request.getParameter('sysparm_table');

// var theRecord = new GlideRecord('syslog_transaction');
// theRecord.addQuery('sys_id', f5241fb7473231102977da97436d43bc);
// theRecord.query();
// theRecord.next();

var zipName = 'attachments.zip';

//var StringUtil = GlideStringUtil;

var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', '76821227473631102977da97436d4368');
gr.addQuery('table_name', 'sys_email');
gr.query();

if (gr.hasNext()) {
    g_response.setHeader('Pragma', 'public');
    g_response.addHeader('Cache-Control', 'max-age=0');
    g_response.setContentType('application/octet-stream');
    g_response.addHeader('Content-Disposition', 'attachment;filename=' + zipName);
    var out = new Packages.java.util.zip.ZipOutputStream(g_response.getOutputStream());
    var count = 0;
    while (gr.next()) {
        var sa = new GlideSysAttachment();
        var binData = sa.getBytes(gr);

        var file = gr.file_name;
        addBytesToZip(out, zipName, file, binData);
        count++;
    }
    // Complete the ZIP file
    out.close();
}

function addBytesToZip(out, dir, file, stream) {
    // Add ZIP entry to output stream.
    out.putNextEntry(new Packages.java.util.zip.ZipEntry(file));
    out.write(stream, 0, stream.length);
    out.closeEntry();
}
3 REPLIES 3

Maik Skoddow
Tera Patron
Tera Patron

Hi @shaik13 

 

instead of asking for a solution, you should provide the underlying business requirement first to help us understand you better,

 

Of course, it is possible to build ZIP files and attach it to emails but this is highly dangerous and can crash your instance. All the described tables are really large, and their contents are loaded into the RAM of an application node for building the ZIP file. However, their contents will exceed the available memory, leading to serious issues. So stop this and explain first what you want to achieve.

 

And you should also be familiar with all the new ServiceNow capabilities as there is a feature called "Log Export Service" you should check: https://docs.servicenow.com/bundle/vancouver-platform-security/page/administer/log-export-service/co... 

Maik

want to send three-table report information into csv file and these three types of files in a single zip file send through email. 

Hi @shaik13 

sorry, but you are just repeating the solution approach, but again you don't explain WHY you want to do this. What do you want to do with the data? Apart from this it would be a serious violation of data protection and security laws because you want to send these contents via email in plain text and without security or encryption!

Maik