function output_results(merged_results) {
    process.stdout.write('"ID","Status","Comment"\n');
    // console.log(merged_results);
    // process.exit();
    merged_results.forEach((data, id) => {

        process.stdout.write('"' + id + '","' + data[0] + '",\n');

        json_results.push({
            "ID": id,
            "Status": data[0],
            "Comment": data[1]
        });
    });

    // sort
    json_results.sort((a, b) => {
        return (a.id < b.id) ? -1 : ((a.id > b.id) ? 1 : 0);
    });

    var csvResults = json2csvParser.parse(json_results);
    fs.writeFile("./Results/mergedResults.csv", csvResults, function (err) {
        if (err) {
            return console.log(err);
        }

        console.warn("The merged result csv was saved!");
        process.exit(0);
    });
}
Esempio n. 2
0
 var createCSV = function() {
     var fields = [
       { label: 'id', value: 'public_id' },
       'name',
       'address',
       'city',
       'state',
       'zip',
       'phone',
       'email',
       { label: 'date created', value: 'createdAt' },
       { label: 'date updated', value: 'updatedAt' },
       'source',
       { label: 'count duplicates', value: 'duplicate_count' }
     ]
     var parser = new json2csv.Parser({ fields });
     var csv = parser.parse(outcome.results);
     res.setHeader('Content-Type','application/csv');
     res.setHeader('Content-Disposition','attachment; filename=smoke-alarm-requests-' + moment().format() + '.csv;');
     res.send(csv);
 }
Esempio n. 3
0
 router.get('/csv', async (req, res) => {
   res.setHeader('Content-Type', 'text/csv')
   res.setHeader('Content-disposition', `attachment; filename=qna_${moment().format('DD-MM-YYYY')}.csv`)
   const json2csvParser = new Json2csvParser({ fields: ['question', 'action', 'answer', 'answer2'], header: true })
   res.end(iconv.encode(json2csvParser.parse(await bp.qna.export({ flat: true })), config.exportCsvEncoding))
 })
function toOutput(tdId) {
    results = mergeIdenticalResults(results);
    createParents(results);

    // Push the non implemented assertions
    nonImplementedAssertions = fetchManualAssertions();
    nonImplementedAssertions.forEach((curNonImpl) => {
        results.push({
            "ID": curNonImpl,
            "Status": "null",
            "Comment": "not testable with Assertion Tester"
        });
    });

    // sort according to the ID in each item
    orderedResults = results.sort(function (a, b) {
        var idA = a.ID;
        var idB = b.ID;
        if (idA < idB) {
            return -1;
        }
        if (idA > idB) {
            return 1;
        }

        // if ids are equal
        return 0;
    });

    var csvResults = json2csvParser.parse(orderedResults);
    results = [];

    //if output is specified output there
    if (outputLocation) {

        fs.writeFile(outputLocation, csvResults, function (err) {
            if (err) {
                return console.log(err);
            }

            console.log("The csv was saved!");
        });

    } else {
        //otherwise to console and save to default directories
        console.log(csvResults);

        var fileName = tdId.replace(/:/g, "_");
        fs.writeFile("./Results/result-" + fileName + ".json", JSON.stringify(orderedResults),
            function (err) {
                if (err) {
                    return console.log(err);
                }

                console.log("The result-" + fileName + ".json is saved!");
            });

        fs.writeFile("./Results/result-" + fileName + ".csv", csvResults, function (err) {
            if (err) {
                return console.log(err);
            }

            console.log("The result-" + fileName + ".csv is saved!");
        });
    }
}
Esempio n. 5
0
'use strict';
const Parser = require('json2csv').Parser;

module.exports = {
  method(content, fields) {
    const options = { doubleQuotes: "'", flatten: true };
    if (fields) {
      options.fields = fields;
    }
    const parser = new Parser(options);
    return parser.parse(content);
  }
};
Esempio n. 6
0
const transformToCSV = (list) => {
  const Json2csvParser = require('json2csv').Parser;
  const json2csvParser = new Json2csvParser();
  return json2csvParser.parse(list);

}
Esempio n. 7
0
    /**
     * Get full data on CSV format from a list Wazuh API endpoint
     * @param {*} req
     * @param {*} res
     */
    async csv(req,reply) {
        try{

            if(!req.payload || !req.payload.path) throw new Error('Field path is required')
            if(!req.payload.id) throw new Error('Field id is required')

            const filters = req.payload && req.payload.filters && Array.isArray(req.payload.filters) ?
                            req.payload.filters :
                            [];

            const config = await this.wzWrapper.getWazuhConfigurationById(req.payload.id)

            let path_tmp = req.payload.path;

            if(path_tmp && typeof path_tmp === 'string'){
                path_tmp = path_tmp[0] === '/' ? path_tmp.substr(1) : path_tmp
            }

            if(!path_tmp) throw new Error('An error occurred parsing path field')

            // Real limit, regardless the user query
            const params = { limit: 45000 };

            if(filters.length) {
                for(const filter of filters) {
                    if(!filter.name || !filter.value) continue;
                    params[filter.name] = filter.value;
                }
            }

            const output = await needle('get', `${config.url}:${config.port}/${path_tmp}`, params, {
                headers: {
                    'wazuh-app-version': packageInfo.version
                },
                username          : config.user,
                password          : config.password,
                rejectUnauthorized: !config.insecure
            })

            if(output && output.body && output.body.data && output.body.data.totalItems) {
                const fields = Object.keys(output.body.data.items[0]);
                const data   = output.body.data.items;

                const json2csvParser = new Parser({ fields });
                const csv            = json2csvParser.parse(data);

                return reply(csv).type('text/csv')

            } else if (output && output.body && output.body.data && !output.body.data.totalItems) {

                throw new Error('No results')

            } else {

                throw new Error('An error occurred fetching data from the Wazuh API')

            }

        } catch (error) {
            return ErrorResponse(error.message || error, 3034, 500, reply);
        }
    }