Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let dateEnd = colors.magenta(dateFormat(scenario.end, "mmm d, h:MM:ssTT"));
date = colors.magenta(dateFormat(Math.min(scenario.time, scenario.end), "mmm d, h:MM:ssTT"));
out += ` | Backtesting from ${dateStart} to ${dateEnd}\n\n`;
}
let columns = [];
for (var i = 0; i < this.strategies.length; i++) {
let strategy = this.strategies[i];
try {
let value = await strategy.portfolio.value(this.params.quote, this.exchange.price.bind(this.exchange));
if (!strategy.originalValue)
strategy.originalValue = value;
let total = types_1.BN(value.all.free).plus(value.all.reserved).toFixed(2);
let originalTotal = types_1.BN(strategy.originalValue.all.free).plus(strategy.originalValue.all.reserved).toFixed(2);
let valstr = colors.green("$" + total);
let ovalstr = colors.green("$" + originalTotal);
columns.push({ strategy: colors.blue(strategy.title), value: valstr, "original value": ovalstr });
}
catch (err) {
throw err;
}
}
let table = columnify(columns, { minWidth: 20 });
table = table.split("\n").join("\n | ");
// console.log(" | " + table);
out += " | " + table + "\n";
if (types_1.Scenario.getInstance().mode == types_1.ScenarioMode.PLAYBACK) {
out += (`\n | ${date}\n`);
}
console.log(`\n${out}\n`);
this.print = false;
}
}
var date = "";
if (this.exchange.isBacktesting()) {
let dateStart = colors.magenta(dateFormat(config.scenario.start, "mmm d, h:MM:ssTT"));
let dateEnd = colors.magenta(dateFormat(config.scenario.end, "mmm d, h:MM:ssTT"));
date = colors.magenta(dateFormat(Math.min(this.exchange.time, config.scenario.end), "mmm d, h:MM:ssTT"));
console.log(` | Backtesting from ${dateStart} to ${dateEnd}\n`);
}
let columns = [];
for (var i = 0; i < this.strategies.length; i++) {
let strategy = this.strategies[i];
try {
let value = await strategy.portfolio.value("USDT");
if(!strategy.originalValue) strategy.originalValue = value;
let valstr = colors.green("$" + value.total.toFixed(2));
let ovalstr = colors.green("$" + strategy.originalValue.total.toFixed(2));
columns.push({strategy: colors.blue(strategy.title), value: valstr, "original value": ovalstr});
// console.log(" |=> " + strategy.prettyTitle(), valstr + ", original value:", ovalstr);
} catch(err) {
throw err;
console.log("Error calculating value");
}
}
let table = columnify(columns, {minWidth: 20});
table = table.split("\n").join("\n | ");
console.log(" | " + table);
console.log("");
console.log(` | ${date}`);
console.log("\n");
}
module.exports = function (server, options) {
// Require some libraries
const pciRequirementsFile = '';
const fs = require('fs');
const path = require('path');
const needle = require('needle');
var fetchAgentsExternal = require(path.resolve(__dirname, "../wazuh-monitoring.js"));
const wazuh_config_file = '../../configuration/config.json';
var colors = require('ansicolors');
var blueWazuh = colors.blue('wazuh');
var wazuh_config = {};
var package_info = {};
const package_file = '../../package.json';
var appVersion = "";
// Read Wazuh App package file
try {
package_info = JSON.parse(fs.readFileSync(path.resolve(__dirname, package_file), 'utf8'));
appVersion = package_info.version;
} catch (e) {
server.log([blueWazuh, 'initialize', 'error'], 'Could not read the Wazuh package file.');
server.log([blueWazuh, 'initialize', 'error'], 'Path: ' + package_file);
server.log([blueWazuh, 'initialize', 'error'], 'Exception: ' + e);
};
// Read Wazuh App configuration file
try {
module.exports = function (server, options) {
// Require some libraries
const pciRequirementsFile = '';
const fs = require('fs');
const path = require('path');
const needle = require('needle');
var fetchAgentsExternal = require(path.resolve(__dirname, "../wazuh-monitoring.js"));
const wazuh_config_file = '../../configuration/config.json';
var colors = require('ansicolors');
var blueWazuh = colors.blue('wazuh');
var wazuh_config = {};
var package_info = {};
const package_file = '../../package.json';
var appVersion = "";
var permissions = {}
// Read Wazuh App package file
try {
package_info = JSON.parse(fs.readFileSync(path.resolve(__dirname, package_file), 'utf8'));
appVersion = package_info.version;
} catch (e) {
server.log([blueWazuh, 'initialize', 'error'], 'Could not read the Wazuh package file.');
server.log([blueWazuh, 'initialize', 'error'], 'Path: ' + package_file);
server.log([blueWazuh, 'initialize', 'error'], 'Exception: ' + e);
};
// Read Wazuh App configuration file
try {
// Elastic JS Client
const serverConfig = server.config();
const elasticsearch = require('elasticsearch');
const elasticRequest = server.plugins.elasticsearch.getCluster('data');
//callWithInternalUser
// External libraries
//const uiSettings = server.uiSettings();
const fs = require('fs');
const path = require('path');
// Colors for console logging
const colors = require('ansicolors');
const blueWazuh = colors.blue('wazuh');
// Initialize variables
var req = { path : "", headers : {}};
var index_pattern = "wazuh-alerts-*";
var index_prefix = "wazuh-alerts-";
// External files template or objects
const OBJECTS_FILE = 'integration_files/objects_file.json';
const TEMPLATE_FILE = 'integration_files/template_file.json';
const KIBANA_FIELDS_FILE = 'integration_files/kibana_fields_file.json';
const ALERT_SAMPLE_FILE = 'integration_files/alert_sample.json';
// Initialize objects
var kibana_fields_data = {};
var alert_sample = {};
var map_jsondata = {};
function anchorStyle(url) {
return styles.underline(colors.blue(url));
}
, warn: function () {
this.output.write(colors.blue('WARN ') + format.apply(this, arguments) + '\n');
}
, error: function () {
function onfile(err, data) {
if(err) {
io.error(err.stack)
return nextHandler(server, req, resp, parsed)
}
parsed.loggedPathname = ansicolors.blue(parsed.pathname) +
' (' + ansicolors.blue('generated') + ')'
resp.setHeader('content-type', 'text/html; charset=utf-8')
resp.end(data.replace(
/\{\{entry\}\}/g
, Object.keys(opts.entries || {})[0] || ''
))
}
}
function onfile(err, data) {
if(err) {
io.error(err.stack)
return nextHandler(server, req, resp, parsed)
}
parsed.loggedPathname = ansicolors.blue(parsed.pathname) +
' (' + ansicolors.blue('generated') + ')'
resp.setHeader('content-type', 'text/html; charset=utf-8')
resp.end(data.replace(
/\{\{entry\}\}/g
, Object.keys(opts.entries || {})[0] || ''
))
}
}
_summary(infos) {
const { id } = infos
const {
functionName
, file
, line
, column
} = infos[0]
const fullLoc = colors.brightBlack(`${functionName} at ${file}:${line}:${column}`)
const locationString = colors.blue(id)
return `(${locationString}): ${fullLoc}\n\n`
}