Skip to content

Commit

Permalink
automatic: add a default setting to not emit boring messages
Browse files Browse the repository at this point in the history
Currently, we always emit messages every time automatic runs,
even if it does nothing very interesting (the operation succeeds
and there are no changed packages). This is flooding Fedora infra
with boring emails that effectively just say "nothing happened".

This adds a setting that controls whether we emit a message when
nothing interesting happened, and makes it default to false, so
we only emit if *something* interesting happened - the operation
failed, or we saw package changes.

Signed-off-by: Adam Williamson <[email protected]>
  • Loading branch information
AdamWill committed Dec 18, 2024
1 parent 077502a commit fe0de83
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 18 deletions.
38 changes: 20 additions & 18 deletions dnf5-plugins/automatic_plugin/automatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,25 +425,27 @@ void AutomaticCommand::run() {
}
}

for (const auto & emitter_name : config_automatic.config_emitters.emit_via.get_value()) {
std::unique_ptr<Emitter> emitter;
if (emitter_name == "stdio") {
emitter = std::make_unique<EmitterStdIO>(config_automatic, transaction, output_stream, success);
} else if (emitter_name == "motd") {
emitter = std::make_unique<EmitterMotd>(config_automatic, transaction, output_stream, success);
} else if (emitter_name == "command") {
emitter = std::make_unique<EmitterCommand>(config_automatic, transaction, output_stream, success);
} else if (emitter_name == "command_email") {
emitter = std::make_unique<EmitterCommandEmail>(config_automatic, transaction, output_stream, success);
} else if (emitter_name == "email") {
emitter = std::make_unique<EmitterEmail>(config_automatic, transaction, output_stream, success);
} else {
auto & logger = *base.get_logger();
logger.warning(_("Unknown report emitter for dnf5 automatic: \"{}\"."), emitter_name);
continue;
auto emit_no_updates = config_automatic.config_emitters.emit_no_updates.get_value();
if (emit_no_updates || !success || !transaction.empty())
for (const auto & emitter_name : config_automatic.config_emitters.emit_via.get_value()) {
std::unique_ptr<Emitter> emitter;
if (emitter_name == "stdio") {
emitter = std::make_unique<EmitterStdIO>(config_automatic, transaction, output_stream, success);
} else if (emitter_name == "motd") {
emitter = std::make_unique<EmitterMotd>(config_automatic, transaction, output_stream, success);
} else if (emitter_name == "command") {
emitter = std::make_unique<EmitterCommand>(config_automatic, transaction, output_stream, success);
} else if (emitter_name == "command_email") {
emitter = std::make_unique<EmitterCommandEmail>(config_automatic, transaction, output_stream, success);
} else if (emitter_name == "email") {
emitter = std::make_unique<EmitterEmail>(config_automatic, transaction, output_stream, success);
} else {
auto & logger = *base.get_logger();
logger.warning(_("Unknown report emitter for dnf5 automatic: \"{}\"."), emitter_name);
continue;
}
emitter->notify();
}
emitter->notify();
}

if (!success) {
throw libdnf5::cli::SilentCommandExitError(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ reboot_command = "shutdown -r +5 'Rebooting after applying package updates'"
# sendmail.
# If emit_via is left blank, no messages will be sent.
emit_via = stdio
# Whether to emit a message when nothing interesting happened - the operation
# succeeded and no packages were available/installed.
emit_no_updates = no


[command]
Expand Down
1 change: 1 addition & 0 deletions dnf5-plugins/automatic_plugin/config_automatic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ ConfigAutomaticCommands::ConfigAutomaticCommands() {
ConfigAutomaticEmitters::ConfigAutomaticEmitters() {
opt_binds().add("emit_via", emit_via);
opt_binds().add("system_name", system_name);
opt_binds().add("emit_no_updates", emit_no_updates);
}

std::string ConfigAutomaticEmitters::gethostname() {
Expand Down
1 change: 1 addition & 0 deletions dnf5-plugins/automatic_plugin/config_automatic.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ConfigAutomaticEmitters : public libdnf5::Config {

libdnf5::OptionStringList emit_via{std::vector<std::string>{"stdio"}};
libdnf5::OptionString system_name{gethostname()};
libdnf5::OptionBool emit_no_updates{false};

private:
static std::string gethostname();
Expand Down
5 changes: 5 additions & 0 deletions doc/dnf5_plugins/automatic.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ Choosing how the results should be reported.

How the system is called in the reports.

``emit_no_updates``
boolean, default: False

Whether to emit a message when nothing interesting happened - the operation succeeded and no packages were available/installed.


---------------------
``[command]`` section
Expand Down

0 comments on commit fe0de83

Please sign in to comment.