@porosys/pss
Version:
Porosys Server Setup (pss): General-purpose server setup and automation tool (including Netdata management)
49 lines (48 loc) • 2.16 kB
JavaScript
import path from 'path';
import { getDirname } from '../../../../utils/dirname-from-import-meta.util.js';
import { sshBruteforceAlertDeps } from './setup-ssh-bruteforce-alert.constant.js';
import { setupAlert } from '../setup-alert/setup-alert.helper.js';
const dirname = getDirname(import.meta);
export const setupSshBruteforceAlert = async ({ alertName, threshold, timeWindow, }) => {
const config = await (await import('../../../config/config.helper.js')).loadConfig();
const healthdPath = config?.healthdPath;
const healthScriptsPath = config?.healthScriptsPath;
if (!healthdPath || !healthScriptsPath) {
throw new Error('healthdPath and healthScriptsPath must be set in config before calling setupSshBruteforceAlert.');
}
const baseAlertDir = path.join(healthScriptsPath, alertName);
const scriptPath = `${baseAlertDir}/update-${alertName}-status.sh`;
const healthAlertPath = path.join(healthdPath, `${alertName}.conf`);
const scriptDir = path.join(dirname);
const metricName = `${alertName.replace(/_/g, '.')}.detected`;
const info = `SSH brute force attack detected!`;
await setupAlert({
alertName,
dependencies: sshBruteforceAlertDeps,
templates: [
{
templatePath: path.join(scriptDir, 'update-ssh-bruteforce-status.template.sh'),
destinationPath: scriptPath,
replacements: {
__THRESHOLD__: threshold.toString(),
__TIME_WINDOW__: timeWindow.toString(),
__METRIC_NAME__: metricName,
},
mode: 0o755,
},
{
templatePath: path.join(scriptDir, 'ssh-bruteforce-alert.template.conf'),
destinationPath: healthAlertPath,
replacements: {
__ALERT_NAME__: alertName,
__ON__: `statsd_${metricName}_gauge`,
__INFO__: info,
},
},
],
cronScriptPath: scriptPath,
healthdPath,
healthScriptsPath,
checkFiles: [healthAlertPath],
});
};