Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

errsole-mysql

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

errsole-mysql - npm Package Compare versions

Comparing version 1.0.4 to 2.0.0

111

lib/index.js

@@ -15,7 +15,5 @@ /**

* @typedef {Object} LogFilter
* @property {string} [hostname]
* @property {number} [pid]
* @property {string[]} [hostnames]
* @property {{source: string, level: string}[]} [level_json]
* @property {string[]} [sources]
* @property {string[]} [levels]
* @property {number} [errsole_id]
* @property {number} [lt_id]

@@ -112,3 +110,3 @@ * @property {number} [gt_id]

const queries = [
`CREATE TABLE IF NOT EXISTS \`errsole_logs_v1\` (
`CREATE TABLE IF NOT EXISTS \`errsole_logs_v2\` (
\`id\` BIGINT PRIMARY KEY AUTO_INCREMENT,

@@ -122,5 +120,7 @@ \`hostname\` VARCHAR(255),

\`meta\` TEXT,
\`errsole_id\` BIGINT,
INDEX (\`source\`, \`level\`, \`id\`),
INDEX (\`source\`, \`level\`, \`timestamp\`),
INDEX (\`hostname\`, \`pid\`, \`id\`)
INDEX (\`hostname\`, \`pid\`, \`id\`),
INDEX (\`errsole_id\`)
)`,

@@ -259,3 +259,4 @@ `CREATE TABLE IF NOT EXISTS \`errsole_users\` (

logEntry.message,
logEntry.meta
logEntry.meta,
logEntry.errsole_id
]);

@@ -266,3 +267,3 @@

if (err) return reject(err);
connection.query('INSERT INTO errsole_logs_v1 (timestamp, hostname, pid, source, level, message, meta) VALUES ?', [values], () => {
connection.query('INSERT INTO errsole_logs_v2 (timestamp, hostname, pid, source, level, message, meta, errsole_id) VALUES ?', [values], () => {
connection.release();

@@ -277,2 +278,26 @@ if (err) return reject(err);

/**
* Retrieves unique hostnames from the database.
*
* @async
* @function getHostnames
* @returns {Promise<{items: string[]}>} - A Promise that resolves with an object containing an array of unique hostnames.
* @throws {Error} - Throws an error if the operation fails.
*/
async getHostnames () {
const query = `
SELECT DISTINCT hostname
FROM errsole_logs_v2
WHERE hostname IS NOT NULL AND hostname != ''
`;
return new Promise((resolve, reject) => {
this.pool.query(query, (err, results) => {
if (err) return reject(err);
const hostnames = results.map(row => row.hostname).sort();
resolve({ items: hostnames });
});
});
}
/**
* Retrieves log entries from the database based on specified filters.

@@ -295,3 +320,3 @@ *

// Apply filters
// Deprecated filters
if (filters.hostname) {

@@ -313,9 +338,26 @@ whereClauses.push('hostname = ?');

}
if (filters.level_json && filters.level_json.length > 0) {
const levelConditions = filters.level_json.map(levelObj => '(source = ? AND level = ?)');
whereClauses.push(`(${levelConditions.join(' OR ')})`);
filters.level_json.forEach(levelObj => {
values.push(levelObj.source, levelObj.level);
});
// Apply filters
if (filters.hostnames && filters.hostnames.length > 0) {
whereClauses.push('hostname IN (?)');
values.push(filters.hostnames);
}
if (filters.level_json || filters.errsole_id) {
const orConditions = [];
if (filters.level_json && filters.level_json.length > 0) {
const levelConditions = filters.level_json.map(levelObj => '(source = ? AND level = ?)');
orConditions.push(`(${levelConditions.join(' OR ')})`);
filters.level_json.forEach(levelObj => {
values.push(levelObj.source, levelObj.level);
});
}
if (filters.errsole_id) {
orConditions.push('errsole_id = ?');
values.push(filters.errsole_id);
}
whereClauses.push(`(${orConditions.join(' OR ')})`);
}
if (filters.lt_id) {

@@ -347,3 +389,3 @@ whereClauses.push('id < ?');

const whereClause = whereClauses.length ? `WHERE ${whereClauses.join(' AND ')}` : '';
const query = `SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1 ${whereClause} ORDER BY id ${sortOrder} LIMIT ?`;
const query = `SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2 ${whereClause} ORDER BY id ${sortOrder} LIMIT ?`;
values.push(filters.limit);

@@ -379,3 +421,3 @@

// Apply filters
// Deprecated filters
if (filters.hostname) {

@@ -397,9 +439,26 @@ whereClauses.push('hostname = ?');

}
if (filters.level_json && filters.level_json.length > 0) {
const levelConditions = filters.level_json.map(levelObj => '(source = ? AND level = ?)');
whereClauses.push(`(${levelConditions.join(' OR ')})`);
filters.level_json.forEach(levelObj => {
values.push(levelObj.source, levelObj.level);
});
// Apply filters
if (filters.hostnames && filters.hostnames.length > 0) {
whereClauses.push('hostname IN (?)');
values.push(filters.hostnames);
}
if (filters.level_json || filters.errsole_id) {
const orConditions = [];
if (filters.level_json && filters.level_json.length > 0) {
const levelConditions = filters.level_json.map(levelObj => '(source = ? AND level = ?)');
orConditions.push(`(${levelConditions.join(' OR ')})`);
filters.level_json.forEach(levelObj => {
values.push(levelObj.source, levelObj.level);
});
}
if (filters.errsole_id) {
orConditions.push('errsole_id = ?');
values.push(filters.errsole_id);
}
whereClauses.push(`(${orConditions.join(' OR ')})`);
}
if (filters.lt_id) {

@@ -447,3 +506,3 @@ whereClauses.push('id < ?');

const whereClause = whereClauses.length ? `WHERE ${whereClauses.join(' AND ')}` : '';
const query = `SELECT id, hostname, pid, source, timestamp, level, message FROM errsole_logs_v1 ${whereClause} ORDER BY id ${sortOrder} LIMIT ?`;
const query = `SELECT id, hostname, pid, source, timestamp, level, message, errsole_id FROM errsole_logs_v2 ${whereClause} ORDER BY id ${sortOrder} LIMIT ?`;
values.push(filters.limit);

@@ -470,3 +529,3 @@

async getMeta (id) {
const query = 'SELECT id, meta FROM errsole_logs_v1 WHERE id = ?';
const query = 'SELECT id, meta FROM errsole_logs_v2 WHERE id = ?';
return new Promise((resolve, reject) => {

@@ -507,3 +566,3 @@ this.pool.query(query, [id], (err, results) => {

this.pool.query(
'DELETE FROM errsole_logs_v1 WHERE timestamp < ? LIMIT 1000',
'DELETE FROM errsole_logs_v2 WHERE timestamp < ? LIMIT 1000',
[expirationTime],

@@ -510,0 +569,0 @@ (err, results) => {

{
"name": "errsole-mysql",
"version": "1.0.4",
"version": "2.0.0",
"description": "MySQL storage plugin for Errsole",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -13,2 +13,4 @@ declare module 'errsole-mysql' {

meta?: string;
errsole_id?: number;
}

@@ -27,2 +29,3 @@

limit?: number;
errsole_id?: number;
}

@@ -49,3 +52,3 @@

deleteConfig(key: string): Promise<{}>;
getHostnames(): Promise<{ items: string[] }>;
postLogs(logEntries: Log[]): Promise<{}>;

@@ -52,0 +55,0 @@ getLogs(filters?: LogFilter): Promise<{ items: Log[] }>;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc