run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
Future<void> run() async {
final client = _apiClientFrom(argResults!);
try {
final alerts = (await client.get('/alerts') as List).cast<Map>();
if (alerts.isEmpty) {
stdout.writeln('nothing is alerting');
return;
}
final now = DateTime.now();
for (final alert in alerts) {
final since = DateTime.parse(alert['since'] as String).toLocal();
final held = now.difference(since);
stdout.writeln('${alert['message']} (for ${_humanize(held)})');
}
// Non-zero while anything is alerting, so this works as a health check in a
// pipeline or a supervision script.
exitCode = 1;
} finally {
client.close();
}
}