Comparing version 1.0.17-alpha to 1.0.18-alpha
@@ -87,3 +87,3 @@ #!/usr/bin/env node | ||
function getConfig(args) { | ||
const { file, fileInfo } = getAndValidateConfigFileInfo(args.env); | ||
const { file, fileInfo } = getAndValidateConfigFileInfo(args.rules); | ||
const env = getConfigurationFromFile(file, fileInfo); | ||
@@ -109,36 +109,39 @@ if (env.config) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
function cmdBuilder(yargs) { | ||
yargs | ||
.positional("rules", { | ||
type: "string", | ||
description: "path to the evaluator configuration yaml file", | ||
required: true | ||
}) | ||
.option("eval", { | ||
description: "Comma separated list of evaluators to run - if not provided, all are evaluated", | ||
type: "string", | ||
}) | ||
.option("digest", { | ||
description: "Run the digest step using the configuration file set with this argument", | ||
type: "string" | ||
}) | ||
.option("title", { | ||
description: "When set, is used in notifications using variable {{ title }}", | ||
type: "string", | ||
}) | ||
.implies('title', 'digest') | ||
.option("debug", { | ||
description: "If set, debug messages are printed to the console", | ||
type: "boolean" | ||
}); | ||
} | ||
const args = yield (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv)) | ||
.usage("$0 [options]") | ||
.option("debug", { | ||
description: "If set, debug messages are printed to the console", | ||
type: "boolean" | ||
}) | ||
.option("eval", { | ||
description: "Comma separated list of evaluators to run", | ||
type: "string", | ||
}) | ||
.option("env", { | ||
description: "The path to the yaml configuration file to use", | ||
type: "string" | ||
}) | ||
.option("digest", { | ||
description: "If set, the results will be processed with configured digest file", | ||
type: "string" | ||
}) | ||
.option("loop", { | ||
description: "If set, the app runs in a loop (every 30 seconds) until exit", | ||
type: "boolean" | ||
}) | ||
.option("title", { | ||
description: "When set, is used in notifications using variable {{ title }}", | ||
type: "string" | ||
}) | ||
.example("$0 --env=client", "run all evaluators using ./client.yaml") | ||
.example("$0 --eval=mysql --env=client", "runs the mysql evaluator only") | ||
.example("$0 --eval=web,mysql --env=client", "only runs mysql & web evaluators") | ||
.example("$0 --env=client --digest=my-team --title='ACME'", "runs all evaluators and uses my-team config for digest") | ||
.example("$0 --env=client --loop", "runs in a loop (every 30 seconds) until exit") | ||
.demandOption("env") | ||
.help("h") | ||
.alias("h", "help") | ||
.usage("$0 <cmd> [options]") | ||
.command("run <rules> [options]", "run the watchdog", cmdBuilder) | ||
.command("loop <rules> [options]", "run the watchdog in a loop until terminated", cmdBuilder, configureLoop) | ||
.command("killall", "kills all running barky processes", killAll) | ||
.demandCommand() | ||
.example("$0 run client", "run all evaluators using ./client.yaml") | ||
.example("$0 run client --eval=mysql", "runs the mysql evaluator only") | ||
.example("$0 run client --eval=web,mysql", "only runs mysql & web evaluators") | ||
.example("$0 run client --digest=my-team --title='ACME'", "runs all evaluators and uses my-team config for digest") | ||
.example("$0 loop client", "runs in a loop (every 30 seconds) until exit") | ||
.help() | ||
.argv; | ||
@@ -148,2 +151,29 @@ return args; | ||
} | ||
function killAll() { | ||
console.log("killing all barky processes"); | ||
const candidates = fs_1.default.readdirSync(path_1.default.join(path_1.default.dirname('')), { withFileTypes: true }) | ||
.filter(x => /^\.barky.*\.lock$/.test(x.name)) | ||
.map(x => ({ file: x, contents: fs_1.default.readFileSync(x.name, 'utf8') })) | ||
.map(data => { | ||
const fileParts = data.contents.split(' '); | ||
return Object.assign(Object.assign({}, data), { pid: parseInt(fileParts[0]), details: fileParts[1].trim() }); | ||
}) | ||
.filter(data => Number.isInteger(data.pid)); | ||
console.log(`found ${candidates.length} local barky processes`); | ||
candidates | ||
.forEach(data => { | ||
console.log(`killing barky pid ${data.pid} (${data.details}) - ${data.file.name}`); | ||
try { | ||
process.kill(data.pid, -9); | ||
} | ||
catch (err) { | ||
// no-op | ||
} | ||
fs_1.default.unlinkSync(data.file.name); | ||
}); | ||
process.exit(0); | ||
} | ||
function configureLoop(yargs) { | ||
yargs.loop = true; | ||
} | ||
//# sourceMappingURL=cli.js.map |
@@ -30,2 +30,3 @@ "use strict"; | ||
const snapshots = context.getSnapshotsForChannel(channel); | ||
alert.start_date = earliestDateFor(snapshots); | ||
yield channel.sendNewAlert(snapshots, alert); | ||
@@ -37,2 +38,10 @@ alert.last_alert_date = new Date(); | ||
} | ||
function earliestDateFor(snapshots) { | ||
if (!snapshots || snapshots.length === 0) { | ||
return new Date(); | ||
} | ||
return snapshots.reduce((prev, curr) => { | ||
return prev.date < curr.date ? prev : curr; | ||
}, snapshots[0]).date; | ||
} | ||
function sendOngoingAlerts(alerts, channelLookup, context) { | ||
@@ -39,0 +48,0 @@ return tslib_1.__awaiter(this, void 0, void 0, function* () { |
{ | ||
"name": "barky", | ||
"version": "1.0.17-alpha", | ||
"description": "A simple cloud services watchdog with no external dependencies and digest support", | ||
"version": "1.0.18-alpha", | ||
"description": "A simple cloud services watchdog with digest notification support & no external dependencies", | ||
"main": "dist/cli.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
{ | ||
"name": "barky", | ||
"version": "1.0.17-alpha", | ||
"description": "A simple cloud services watchdog with no external dependencies and digest support", | ||
"version": "1.0.18-alpha", | ||
"description": "A simple cloud services watchdog with digest notification support & no external dependencies", | ||
"main": "dist/cli.js", | ||
@@ -6,0 +6,0 @@ "scripts": { |
@@ -36,17 +36,23 @@ # Barky - Cloud Watchdog | ||
Commands: | ||
- `run` - runs the evaluator | ||
- `loop` - runs the evaluator in a loop (every 30s) until terminated | ||
- `killall` - kills all running barky processes based on lock files in the current directory | ||
```bash | ||
# run the evaluator without digest | ||
npx barky@latest --env=configs/my.yaml | ||
npx barky@latest run configs/my.yaml | ||
# run the evaluator with specific evaluator (comma separate for more) | ||
npx barky@latest --env=configs/my.yaml --eval=web | ||
npx barky@latest run configs/my.yaml --eval=web | ||
# run the evaluator and digest step | ||
npx barky@latest --env=configs/my.yaml --digest=configs/digest/my-team.yaml --title="ACME Public" | ||
npx barky@latest run configs/my.yaml --digest=configs/digest/my-team.yaml --title="ACME Public" | ||
# run in a loop (every 30s) until exit | ||
npx barky@latest --env=configs/my.yaml --digest=configs/digest/my-team.yaml --title="ACME Public" --loop | ||
npx barky@latest loop configs/my.yaml --digest=configs/digest/my-team.yaml --title="ACME Public" | ||
# bypass prompt for installation | ||
npx --yes barky@latest --env=configs/my.yaml --eval=web --digest=configs/digest/my-team.yaml --title="ACME Public" | ||
# bypass prompt for package installation | ||
npx --yes barky@latest run configs/my.yaml --eval=web --digest=configs/digest/my-team.yaml --title="ACME Public" | ||
``` | ||
@@ -331,6 +337,6 @@ | ||
```yaml | ||
quiet-windows: # alerts are silenced if generated in these window periods | ||
- date: 2023-08-27 | ||
time: 14:00 - 16:00 # 2PM to 4PM for a specific date | ||
- time: 00:00 - 06:00 # every day midnight to 6AM | ||
mute-windows: # alerts are silenced if generated in these window periods | ||
- date: 2023-08-27 | ||
time: 14:00 - 16:00 # 2PM to 4PM for a specific date | ||
- time: 00:00 - 06:00 # every day midnight to 6AM | ||
@@ -337,0 +343,0 @@ alert-policies: |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
249338
3314
419