Publish Idunn alarms through Bifrost CultMesh
This commit is contained in:
parent
993c98788c
commit
e06c2a6539
6 changed files with 96 additions and 2 deletions
|
|
@ -59,7 +59,9 @@ Local package surfaces:
|
|||
- Local VoidBot keepalive: `scripts\health-voidbot.cmd` and
|
||||
`scripts\restart-voidbot.cmd`
|
||||
- Operator escalation: Bifrost-owned CultMesh crossing; current compatibility
|
||||
delivery may call `voidbot.operator-dm` command `owner.dm.send`
|
||||
delivery calls `scripts\notify-idunn-operator-alarm.ps1`, which asks Bifrost
|
||||
to publish a typed `gamecult.operator_dm_request.v1` CultMesh command document
|
||||
only after Idunn raises an alarm
|
||||
|
||||
## Authority Map
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ struct Options {
|
|||
name: String,
|
||||
health_command: Option<String>,
|
||||
restart_command: Option<String>,
|
||||
operator_alarm_command: Option<String>,
|
||||
enabled: bool,
|
||||
execute: bool,
|
||||
interval_seconds: Option<u64>,
|
||||
|
|
@ -89,6 +90,7 @@ fn run_cycle(options: &Options) -> Result<()> {
|
|||
"Idunn raised operator alarm for {} through {}: {}",
|
||||
alarm.daemon_id, alarm.escalation_target, alarm.reason
|
||||
);
|
||||
run_operator_alarm_command(&options, &alarm);
|
||||
}
|
||||
} else {
|
||||
println!(
|
||||
|
|
@ -104,6 +106,7 @@ fn run_cycle(options: &Options) -> Result<()> {
|
|||
"Idunn raised operator alarm for {} through {}: {}",
|
||||
alarm.daemon_id, alarm.escalation_target, alarm.reason
|
||||
);
|
||||
run_operator_alarm_command(options, alarm);
|
||||
}
|
||||
|
||||
println!(
|
||||
|
|
@ -140,6 +143,7 @@ impl Options {
|
|||
name: String::new(),
|
||||
health_command: None,
|
||||
restart_command: None,
|
||||
operator_alarm_command: None,
|
||||
enabled: true,
|
||||
execute: false,
|
||||
interval_seconds: None,
|
||||
|
|
@ -158,6 +162,10 @@ impl Options {
|
|||
"--restart-command" => {
|
||||
options.restart_command = Some(take_value(&mut args, "--restart-command")?)
|
||||
}
|
||||
"--operator-alarm-command" => {
|
||||
options.operator_alarm_command =
|
||||
Some(take_value(&mut args, "--operator-alarm-command")?)
|
||||
}
|
||||
"--disabled" => options.enabled = false,
|
||||
"--execute" => options.execute = true,
|
||||
"--interval-seconds" => {
|
||||
|
|
@ -269,6 +277,52 @@ fn run_shell(command: &str) -> Result<std::process::Output> {
|
|||
.with_context(|| format!("running command {command:?}"))
|
||||
}
|
||||
|
||||
fn run_operator_alarm_command(options: &Options, alarm: &IdunnOperatorAlarmRecord) {
|
||||
let Some(command) = options.operator_alarm_command.as_deref() else {
|
||||
return;
|
||||
};
|
||||
if command.trim().is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
let mut process = if cfg!(windows) {
|
||||
let mut process = Command::new("cmd");
|
||||
process.arg("/C").arg(command);
|
||||
process
|
||||
} else {
|
||||
let mut process = Command::new("sh");
|
||||
process.arg("-c").arg(command);
|
||||
process
|
||||
};
|
||||
|
||||
let output = process
|
||||
.env("IDUNN_ALARM_ID", &alarm.alarm_id)
|
||||
.env("IDUNN_ALARM_DAEMON_ID", &alarm.daemon_id)
|
||||
.env("IDUNN_ALARM_SEVERITY", &alarm.severity)
|
||||
.env("IDUNN_ALARM_REASON", &alarm.reason)
|
||||
.env("IDUNN_ALARM_ESCALATION_TARGET", &alarm.escalation_target)
|
||||
.env("IDUNN_ALARM_RAISED_AT", &alarm.raised_at)
|
||||
.output();
|
||||
|
||||
match output {
|
||||
Ok(output) if output.status.success() => {
|
||||
println!("Idunn operator alarm command completed for {}.", alarm.daemon_id);
|
||||
}
|
||||
Ok(output) => {
|
||||
eprintln!(
|
||||
"Idunn operator alarm command failed for {} with {}.",
|
||||
alarm.daemon_id, output.status
|
||||
);
|
||||
}
|
||||
Err(error) => {
|
||||
eprintln!(
|
||||
"Idunn operator alarm command could not run for {}: {}",
|
||||
alarm.daemon_id, error
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn timestamp() -> Result<String> {
|
||||
let seconds = SystemTime::now()
|
||||
.duration_since(UNIX_EPOCH)
|
||||
|
|
@ -278,5 +332,5 @@ fn timestamp() -> Result<String> {
|
|||
}
|
||||
|
||||
fn help_text() -> &'static str {
|
||||
"Usage: idunn --daemon <id> [--name <name>] [--verse <verse>] [--store <path>] [--health-command <command>] [--restart-command <command>] [--execute] [--interval-seconds <seconds>]\n\nIdunn probes one daemon, writes typed CultMesh records, and executes restart only when --execute is present."
|
||||
"Usage: idunn --daemon <id> [--name <name>] [--verse <verse>] [--store <path>] [--health-command <command>] [--restart-command <command>] [--operator-alarm-command <command>] [--execute] [--interval-seconds <seconds>]\n\nIdunn probes one daemon, writes typed CultMesh records, executes restart only when --execute is present, and may invoke an operator alarm bridge command only after an alarm is raised."
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,10 @@ Idunn now shares Odin's Rust body:
|
|||
operators, and daemon authors.
|
||||
- `scripts/start-idunn-local.ps1` starts resident local watchdogs, including
|
||||
VoidBot through `health-voidbot.cmd` and `restart-voidbot.cmd`.
|
||||
- `scripts/notify-idunn-operator-alarm.ps1` is the local operator crossing:
|
||||
Idunn invokes it only after raising an operator alarm, and it asks Bifrost to
|
||||
publish a typed `gamecult.operator_dm_request.v1` CultMesh command document
|
||||
instead of learning Discord delivery itself.
|
||||
- `npm run idunn:build` builds the Rust daemon.
|
||||
- `npm run idunn:start -- ...` probes a daemon, records the decision, and can
|
||||
execute the restart command when `--execute` is present.
|
||||
|
|
@ -93,6 +97,11 @@ idunn.operator_alarm.v1
|
|||
still-VoidBot delivery path must be invoked by Bifrost or documented as
|
||||
migration debt. Idunn must not learn Discord token handling, DM delivery
|
||||
internals, or VoidBot-specific transport.
|
||||
- In the current local bridge, `--operator-alarm-command` invokes
|
||||
`notify-idunn-operator-alarm.cmd`, which forwards `IDUNN_ALARM_*`
|
||||
environment variables to `E:\Projects\Bifrost\tools\operator-notification.mjs
|
||||
publish-idunn-alarm`. Bifrost publishes the typed CultMesh command document;
|
||||
Idunn only decides that an alarm exists.
|
||||
|
||||
## First Runtime Direction
|
||||
|
||||
|
|
|
|||
2
scripts/notify-idunn-operator-alarm.cmd
Normal file
2
scripts/notify-idunn-operator-alarm.cmd
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
@echo off
|
||||
powershell.exe -NoProfile -ExecutionPolicy Bypass -File E:\Projects\Odin\scripts\notify-idunn-operator-alarm.ps1
|
||||
23
scripts/notify-idunn-operator-alarm.ps1
Normal file
23
scripts/notify-idunn-operator-alarm.ps1
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
$bifrostRoot = "E:\Projects\Bifrost"
|
||||
$publisherScript = Join-Path $bifrostRoot "tools\operator-notification.mjs"
|
||||
|
||||
if (-not (Test-Path -LiteralPath $publisherScript)) {
|
||||
throw "Bifrost operator-notification publisher is missing at $publisherScript."
|
||||
}
|
||||
|
||||
Push-Location -LiteralPath $bifrostRoot
|
||||
try {
|
||||
$arguments = @($publisherScript, "publish-idunn-alarm")
|
||||
if ($env:IDUNN_OPERATOR_ALARM_DRY_RUN -in @("1", "true", "yes", "on")) {
|
||||
$arguments += "--dry-run"
|
||||
}
|
||||
& node @arguments
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "Bifrost operator-notification publisher exited with code $LASTEXITCODE."
|
||||
}
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
|
@ -7,6 +7,7 @@ $ErrorActionPreference = "Stop"
|
|||
|
||||
$repoRoot = Split-Path -Parent $PSScriptRoot
|
||||
$idunnExe = Join-Path $repoRoot "target\debug\idunn.exe"
|
||||
$operatorAlarmCommand = Join-Path $repoRoot "scripts\notify-idunn-operator-alarm.cmd"
|
||||
$logDir = Join-Path $StateDir "logs"
|
||||
$pidDir = Join-Path $StateDir "pids"
|
||||
|
||||
|
|
@ -124,6 +125,9 @@ function Start-Watchdog {
|
|||
if (-not [string]::IsNullOrWhiteSpace($Watchdog.Restart)) {
|
||||
$arguments += @("--restart-command", $Watchdog.Restart, "--execute")
|
||||
}
|
||||
if (Test-Path -LiteralPath $operatorAlarmCommand) {
|
||||
$arguments += @("--operator-alarm-command", $operatorAlarmCommand)
|
||||
}
|
||||
$startInfo.Arguments = Join-WindowsArguments -Arguments $arguments
|
||||
|
||||
$process = [System.Diagnostics.Process]::new()
|
||||
|
|
|
|||
Loading…
Reference in a new issue