Housekeeping from Cron should only display errors #10523

Closed
opened 2025-12-29 21:32:35 +01:00 by adam · 6 comments
Owner

Originally created by @mathieumd on GitHub (Nov 29, 2024).

Change Type

Addition

Area

Administration

Proposed Changes

Housekeeping doc produce a cron job which will send a daily email with standard output:

/etc/cron.daily/netbox-housekeeping:
[*] Clearing expired authentication sessions
	Sessions cleared.
[*] Checking for expired changelog records
	Deleting 3355 expired records... Done.
[*] Checking for expired jobs
	No expired records found.
[*] Checking for latest release
	Skipping: RELEASE_CHECK_URL not set
Finished.

In #7425 it's recommended to support --verbosity 0, which it does:

sudo /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py housekeeping --verbosity 0 |wc -l
0

So:

  1. Documentation should explain how to reduce the verbosity thanks to this --verbosity Django option;
  2. I don't know Django, so is using --verbosity 0 would still output errors? (Usually, cron jobs only redirects stdout to /dev/null, because you want to receive stderr by email)
Originally created by @mathieumd on GitHub (Nov 29, 2024). ### Change Type Addition ### Area Administration ### Proposed Changes [Housekeeping doc](https://github.com/netbox-community/netbox/blob/develop/docs/administration/housekeeping.md) produce a cron job which will send a daily email with standard output: ``` /etc/cron.daily/netbox-housekeeping: [*] Clearing expired authentication sessions Sessions cleared. [*] Checking for expired changelog records Deleting 3355 expired records... Done. [*] Checking for expired jobs No expired records found. [*] Checking for latest release Skipping: RELEASE_CHECK_URL not set Finished. ``` In #7425 it's recommended to support `--verbosity 0`, which it does: ```sh sudo /opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py housekeeping --verbosity 0 |wc -l 0 ``` So: 1. Documentation should explain how to reduce the verbosity thanks to this [`--verbosity` Django option](https://docs.djangoproject.com/en/dev/ref/django-admin/#cmdoption-verbosity); 2. I don't know Django, so is using `--verbosity 0` would still output errors? (Usually, cron jobs only redirects stdout to `/dev/null`, because you want to receive stderr by email)
adam added the type: documentation label 2025-12-29 21:32:35 +01:00
adam closed this issue 2025-12-29 21:32:35 +01:00
Author
Owner

@jeremystretch commented on GitHub (Dec 5, 2024):

What specific change(s) are you proposing to NetBox?

@jeremystretch commented on GitHub (Dec 5, 2024): What specific change(s) are you proposing to NetBox?
Author
Owner

@mathieumd commented on GitHub (Dec 6, 2024):

As I said: documentation should state how to reduce verbosity of such Cron jobs. I can make a PR if you prefer.

And in the second point I'm just asking confirmation that when using this Django's --verbosity 0, it would still display errors if there were any?

@mathieumd commented on GitHub (Dec 6, 2024): As I said: documentation should state how to reduce verbosity of such Cron jobs. I can make a PR if you prefer. And in the second point I'm just asking confirmation that when using this Django's `--verbosity 0`, it would still display errors if there were any?
Author
Owner

@jeremystretch commented on GitHub (Dec 6, 2024):

You appear to be conflating scheduled tasks and management commands. manage.py housekeeping is a management command, which can be run ad hoc or scheduled via a tool like cron. The supported arguments for management commands are not listed in the NetBox documentation because they are easily inspected locally using manage.py help $command. This is a Django convention.

@jeremystretch commented on GitHub (Dec 6, 2024): You appear to be conflating scheduled tasks and management commands. `manage.py housekeeping` is a management command, which can be run ad hoc or scheduled via a tool like cron. The supported arguments for management commands are not listed in the NetBox documentation because they are easily inspected locally using `manage.py help $command`. This is a Django convention.
Author
Owner

@mathieumd commented on GitHub (Dec 6, 2024):

Official NetBox documentation is actually recommending to add this management command to schedule task, see the Using Cron section. It should be explained there that, by only doing sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping, sysadmins will receive a daily useless email, which they usually only want to receive when errors has occurred in this management command.

That's why I opened this issue to suggest to recommend, instead, something like that, by example:

echo "/opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py housekeeping --verbosity 0" | sudo tee /etc/cron.daily/netbox-housekeeping

Now, this suggestion is only valid if --verbosity 0 is the same as >/dev/null (ie. only stdout is dropped, not stderr). But I don't know that, so I though somebody here could answer, which is why I asked.

@mathieumd commented on GitHub (Dec 6, 2024): Official NetBox documentation is actually recommending to add this management command to schedule task, see the [Using Cron](https://github.com/netbox-community/netbox/blob/develop/docs/administration/housekeeping.md#using-cron) section. It should be explained there that, by only doing `sudo ln -s /opt/netbox/contrib/netbox-housekeeping.sh /etc/cron.daily/netbox-housekeeping`, sysadmins will receive a daily useless email, which they usually only want to receive when errors has occurred in this management command. That's why I opened this issue to suggest to recommend, instead, something like that, by example: ```sh echo "/opt/netbox/venv/bin/python /opt/netbox/netbox/manage.py housekeeping --verbosity 0" | sudo tee /etc/cron.daily/netbox-housekeeping ``` Now, this suggestion is only valid if `--verbosity 0` is the same as `>/dev/null` (ie. only stdout is dropped, not stderr). But I don't know that, so I though somebody here could answer, which is why I asked.
Author
Owner

@jeremystretch commented on GitHub (Dec 6, 2024):

sysadmins will receive a daily useless email, which they usually only want to receive when errors has occurred in this management command.

This is entirely dependent on your system's default configuration; it has nothing to do with NetBox. We offer documentation in this regard merely as a starting point for system administrators. It is not intended to be comprehensive.

While I appreciate the suggestion, I'm going to decline this change as it exceeds the intended scope of NetBox's documentation.

@jeremystretch commented on GitHub (Dec 6, 2024): > sysadmins will receive a daily useless email, which they usually only want to receive when errors has occurred in this management command. This is entirely dependent on your system's default configuration; it has nothing to do with NetBox. We offer documentation in this regard merely as a starting point for system administrators. It is not intended to be comprehensive. While I appreciate the suggestion, I'm going to decline this change as it exceeds the intended scope of NetBox's documentation.
Author
Owner

@mathieumd commented on GitHub (Dec 7, 2024):

OK, fair enough, thanks.

But, do you happen to know if --verbosity 0 would still display errors?

@mathieumd commented on GitHub (Dec 7, 2024): OK, fair enough, thanks. But, do you happen to know if `--verbosity 0` would still display errors?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#10523