|
| 1 | + |
| 2 | +import { readFileSync } from "fs"; |
| 3 | +import { RuleRunner } from './lib/ruleRunner' |
| 4 | +import * as yargs from 'yargs'; |
| 5 | +import { safeLoad } from "js-yaml"; |
| 6 | +import { Configuration } from './lib/configuration'; |
| 7 | +import { ConsoleLogger } from "./lib/models/logging/consoleLogger"; |
| 8 | +import { setupNumeralExtensions } from "./lib/numeralExtensions"; |
| 9 | + |
| 10 | +let argv = yargs |
| 11 | + .env("EA") |
| 12 | + .command('test', "Test a rule. Don't schedule it to run, run it right now!") |
| 13 | + .option('rule', { |
| 14 | + alias: 'r', |
| 15 | + description: 'Which rule or directory of rules to run.', |
| 16 | + type: 'string', |
| 17 | + required: true |
| 18 | + }) |
| 19 | + .option('elasticsearchHost', { |
| 20 | + alias: 'H', |
| 21 | + description: 'The elasticsearch host to connect to.', |
| 22 | + type: 'string', |
| 23 | + required: true |
| 24 | + }) |
| 25 | + .option('elasticsearchPort', { |
| 26 | + alias: 'p', |
| 27 | + description: 'The elasticsearch port to connect to.', |
| 28 | + type: 'number', |
| 29 | + default: 9200 |
| 30 | + }) |
| 31 | + .option('dryrun', { |
| 32 | + alias: 'd', |
| 33 | + description: 'Whether or not to actually send out alerts.', |
| 34 | + type: 'boolean' |
| 35 | + }) |
| 36 | + .option('outputFile', { |
| 37 | + alias: 'o', |
| 38 | + description: 'For dryruns, where to send the body of alerts to.', |
| 39 | + type: 'string' |
| 40 | + }) |
| 41 | + .option('logLevel', { |
| 42 | + alias: 'l', |
| 43 | + description: 'The log level to filter by.', |
| 44 | + type: 'string', |
| 45 | + default: 'Info', |
| 46 | + choices: ['Verbose', 'Info', 'Warning', 'Error'] |
| 47 | + }) |
| 48 | + .config('config', 'Path to a yaml config file.', (configPath: string) => |
| 49 | + { |
| 50 | + return safeLoad(readFileSync(configPath, 'utf-8')); |
| 51 | + }) |
| 52 | + .help() |
| 53 | + .alias('help', 'h') |
| 54 | + .argv; |
| 55 | + |
| 56 | +setupNumeralExtensions(); |
| 57 | + |
| 58 | +let config = new Configuration(argv, __dirname); |
| 59 | +let logger = new ConsoleLogger(config.LogLevelFilter); |
| 60 | +let runner = new RuleRunner(logger, config); |
| 61 | + |
| 62 | +if (argv._.includes('test')) |
| 63 | +{ |
| 64 | + runner.runTest(config); |
| 65 | +} |
| 66 | +else |
| 67 | +{ |
| 68 | + runner.run(config); |
| 69 | +} |
| 70 | + |
| 71 | +process.on('SIGINT', async () => { runner.stop(); process.exit(0); }); |
| 72 | +process.on('SIGTERM', async () => { runner.stop(); process.exit(0); }); |
0 commit comments