Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to schedule scripts & reports #8366

Closed
ryanmerolle opened this issue Jan 15, 2022 · 11 comments · Fixed by #10417
Closed

Add ability to schedule scripts & reports #8366

ryanmerolle opened this issue Jan 15, 2022 · 11 comments · Fixed by #10417
Assignees
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Milestone

Comments

@ryanmerolle
Copy link
Contributor

NetBox version

v3.1.5

Feature type

New functionality

Proposed functionality

This feature request is to add the ability to schedule report and script runs.

One idea is to create a new page/section for these schedules and possibly associated results that allows users to view all scheduled operations.

Another idea is to just add this functionality right into the existing scripts and reports page/section

Use case

As a user, I want to be able to schedule recurring scripts and reports in NetBox itself.

Alternatively, a user could setup a schedule outside of UI using an external tool to execute an API call / POST or via the cli. The challenge is that if you are not a user who is aware of the NetBox setup, its hard to follow how and what triggered the script or report run.

Database changes

No response

External dependencies

No response

@ryanmerolle ryanmerolle added the type: feature Introduction of new functionality to the application label Jan 15, 2022
@jeremystretch
Copy link
Member

Alternatively, a user could setup a schedule outside of UI using an external tool to execute an API call / POST or via the cli.

The recommended approach would be to execute the runscript and runreport management commands provided by NetBox as cron jobs.

@jeremystretch jeremystretch added the status: under review Further discussion is needed to determine this issue's scope and/or implementation label Jan 17, 2022
@ryanmerolle
Copy link
Contributor Author

Alternatively, a user could setup a schedule outside of UI using an external tool to execute an API call / POST or via the cli.

The recommended approach would be to execute the runscript and runreport management commands provided by NetBox as cron jobs.

Yep, I forgot to mention that particular approach, but with all those "non-native" schedulers the downside would be that you have no way to see or update the schedule (for users not able to ssh to the host).

@ziggekatten
Copy link

ziggekatten commented Jan 22, 2022

I have spent some time looking at external tools to do this (currently using cron), but they are either overly complex, not python based and the more important, separate authentication and authorization from NetbBox.

The result is a napkin with some scribbles for a plugin using the Django extension for job scheduling somehow. Will maybe be my first real project coding Django/NetBox plugin. Alternatively I would go the Celery route, though my experience is that it is rather fiddly, at least with Flask. DOnt know yet if Django is more straight forward. Key is to have a single process manage the schedule, like the house keeping in netbox, or beat in Celery.

But I believe this is a valid candidate for a plugin.

@jeremystretch
Copy link
Member

It looks like django-rq provides a couple options for scheduling jobs.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Please see our contributing guide.

@github-actions github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Mar 30, 2022
@kkthxbye-code
Copy link
Contributor

@jeremystretch - I might take a stab at this soonish if it's accepted. I think it would be a shame to auto-close at least. It would be blocked until #8957 is merged though in my opinion. It would be confusing to trigger a job at night, and then missing the result because someone ran the same script in the morning.

@ryanmerolle ryanmerolle removed the pending closure Requires immediate attention to avoid being closed for inactivity label Mar 30, 2022
@jeremystretch
Copy link
Member

@kkthxbye-code Ok, I'll mark this as blocked for now.

@jeremystretch jeremystretch added status: blocked Another issue or external requirement is preventing implementation and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation labels Mar 30, 2022
@kkthxbye-code
Copy link
Contributor

Not blocked anymore.

I have been experimenting a little with this. The scheduling part is easy and works fine. My worry is that the current script/report system is already a little messy and a rework might be in order.

The split between reports and scripts is already a little thin and I think Jeremy has mentioned merging them before.

Then we have the JobResults class which I'm not really sure is aptly named. Isn't it already more of a JobExecution, JobTask or just Job? Do we want to add a new status to JobResultStatusChoices for scheduled tasks? Otherwise we only know a task has been scheduled by asking django-rq. Do we want to duplicate the scheduled time and add it to the model, or are we satisfied only having that in redis? All this might be fine, but if a user wants to cancel the scheduled task, what does that do to the JobResult?

I can for sure implement a solution with just adding a field for scheduling scripts/reports and moving job results out of the admin panel. Then creating a new view for scheduled tasks, which pretty much just asks django-rq for a list of these, with the option of canceling a task. Not sure if it's the right way to go though.

@DanSheps DanSheps added status: accepted This issue has been accepted for implementation and removed status: blocked Another issue or external requirement is preventing implementation labels Apr 22, 2022
@DanSheps DanSheps added status: under review Further discussion is needed to determine this issue's scope and/or implementation and removed status: accepted This issue has been accepted for implementation labels Apr 22, 2022
@DanSheps
Copy link
Member

The split between reports and scripts is already a little thin and I think Jeremy has mentioned merging them before.

It has been brought up before. We could definitely open an issue for this, do you think it would be wise to again blocked this issue by the merge issue?

Then we have the JobResults class which I'm not really sure is aptly named. Isn't it already more of a JobExecution, JobTask or just Job? Do we want to add a new status to JobResultStatusChoices for scheduled tasks? Otherwise we only know a task has been scheduled by asking django-rq. Do we want to duplicate the scheduled time and add it to the model, or are we satisfied only having that in redis? All this might be fine, but if a user wants to cancel the scheduled task, what does that do to the JobResult?

So, I played with this in my backup plugin. There are so many things that can be impacted by django-rq to cause the schedule to not kick off correctly. If we do that, we would almost need a "watcher" job to run to make sure it doesn't get dropped into the canceled queue or something equally weird doesn't happen to it.

I can for sure implement a solution with just adding a field for scheduling scripts/reports and moving job results out of the admin panel. Then creating a new view for scheduled tasks, which pretty much just asks django-rq for a list of these, with the option of canceling a task. Not sure if it's the right way to go though.

I will let Jeremy weigh in, but I think this might be the correct course:

  1. Merge Scripts/Reports into a single "Job" workflow
  2. Move "Jobs" to the main UI and removed from the admin UI
  3. Add the scheduling piece
  4. Update any existing views/management commands

This likely should be fleshed out in a new issue. Should probably also be done in a 3.x release and not a patch.

@github-actions
Copy link
Contributor

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions github-actions bot added the pending closure Requires immediate attention to avoid being closed for inactivity label Jun 22, 2022
@jeremystretch jeremystretch added needs milestone Awaiting prioritization for inclusion with a future NetBox release and removed status: under review Further discussion is needed to determine this issue's scope and/or implementation pending closure Requires immediate attention to avoid being closed for inactivity labels Jun 22, 2022
@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed needs milestone Awaiting prioritization for inclusion with a future NetBox release labels Jul 27, 2022
@jeremystretch jeremystretch added this to the v3.4 milestone Jul 27, 2022
@kkthxbye-code kkthxbye-code self-assigned this Sep 10, 2022
@kkthxbye-code
Copy link
Contributor

I'll give this a shot, see if I can come up with a good solution. If anyone has any additional input, feel free to share.

As a first step the implementation might just be the addition of a time/date schedule field to scripts/reports and then we'll rely on the built-in admin panel views for managing scheduled tasks. FR's can then be created for moving tasks management out of the admin panel if deemed necessary.

jeremystretch added a commit that referenced this issue Oct 21, 2022
jeremystretch added a commit that referenced this issue Dec 12, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: feature Introduction of new functionality to the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants