Skip to content

Commit ee01061

Browse files
committed
generate balance-checker prometheusrules
1 parent 923176a commit ee01061

File tree

1 file changed

+51
-1
lines changed

1 file changed

+51
-1
lines changed

src/commands/setup/configs.ts

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,20 @@ export default class SetupConfigs extends Command {
519519
}
520520
}
521521

522+
try {
523+
this.log(chalk.blue(`generating balance-checker alert rules file...`));
524+
const scrollMonitorProductionFilePath = path.join(targetDir, "scroll-monitor-production.yaml");
525+
const balanceCheckerConfigFilePath = path.join(targetDir, "balance-checker-config.yaml");
526+
const addedAlertRules = this.generateAlertRules(balanceCheckerConfigFilePath);
527+
const existingContent = fs.readFileSync(scrollMonitorProductionFilePath, 'utf8');
528+
const existingYaml = yaml.load(existingContent) as any;
529+
existingYaml["kube-prometheus-stack"].additionalPrometheusRules = addedAlertRules;
530+
fs.writeFileSync(scrollMonitorProductionFilePath, yaml.dump(existingYaml, { indent: 2 }));
531+
}
532+
catch {
533+
this.error(`generating balance-checker alert rules file failed`);
534+
}
535+
522536
// Remove source files after all processing is complete
523537
for (const mapping of fileMappings) {
524538
const sourcePath = path.join(sourceDir, mapping.source);
@@ -705,4 +719,40 @@ export default class SetupConfigs extends Command {
705719

706720
this.log(chalk.green('Configuration setup completed.'))
707721
}
708-
}
722+
723+
private generateAlertRules(sourcePath: string): any {
724+
const yamlContent = fs.readFileSync(sourcePath, 'utf8');
725+
const parsedYaml = yaml.load(yamlContent) as any;
726+
const jsonConfig = JSON.parse(parsedYaml.scrollConfig);
727+
const { addresses } = jsonConfig;
728+
729+
const alertRules =
730+
[
731+
{
732+
groups: [
733+
{
734+
name: "balance-cheker-group",
735+
rules: addresses.map((item: { address: string, min_balance_ether: string; name: string; rpc_url: string }) => ({
736+
alert: `ether_balance_of_${item.name}`,
737+
annotations: {
738+
description: `Balance of ${item.name} (${item.address}) is less than threshold ${item.min_balance_ether}`,
739+
summary: `Balance of ${item.name} is less than threshold ${item.min_balance_ether}`
740+
},
741+
expr: `ether_balance_of_${item.name} < ${item.min_balance_ether}`,
742+
for: '5m',
743+
labels: {
744+
severity: 'critical'
745+
}
746+
}))
747+
}],
748+
labels: {
749+
release: "scroll-monitor",
750+
role: "alert-rules"
751+
},
752+
name: "balance-cheker"
753+
}
754+
];
755+
return alertRules;
756+
}
757+
758+
}

0 commit comments

Comments
 (0)