Jobs¶
nautobot_contract_models.jobs
¶
Nautobot Jobs for the contract-models plugin.
Currently exposes :class:RenewalCheckJob — finds contracts expiring within
a configurable window and writes a per-contract log entry. Operators can run
it on demand from the Jobs UI, or configure a scheduled invocation via the
Nautobot scheduler so the renewal report runs nightly.
The Job's logger calls (self.logger.info, warning, error) flow
into the standard JobResult / JobLogEntry surface — operators see the output
in the Job result detail page, can search/filter past runs, and can wire
webhook hooks to JobLogEntry creation if they want notifications routed
into Slack / email / PagerDuty.
CostAnomalyJob
¶
Bases: Job
Diff this week's cost snapshots against lookback_weeks ago, log anomalies.
Read-only. Operators schedule weekly to get an alert when burn rate
or renewal forecast changes by more than threshold_pct from the
historical baseline. Hooks into existing JobLogEntry webhook plumbing,
so anomalies can route into Slack / email / a ticket.
Requires that CostHistoryJob has been running long enough to
have a snapshot at-or-before (today - lookback_weeks). Without
historical data the helper reports nothing and the Job logs an INFO
line saying so.
Source code in src/nautobot_contract_models/jobs.py
Meta
¶
run(threshold_pct, lookback_weeks)
¶
Compute anomalies and emit one WARNING per finding.
Source code in src/nautobot_contract_models/jobs.py
CostHistoryJob
¶
Bases: Job
Persist a CostSnapshot per currency for today's date.
Operators schedule this weekly. Each run creates (or refreshes) snapshot rows that drive the cost-history visualization. Re-running the same day is idempotent — the unique (snapshot_date, currency) constraint plus update_or_create means duplicates can't accumulate.
Distinct from CostReportJob: CostReportJob writes to JobLogEntry (ephemeral, search-but-not-queryable). CostHistoryJob writes to a real model so we can render time-series UI.
Source code in src/nautobot_contract_models/jobs.py
Meta
¶
Job metadata.
Source code in src/nautobot_contract_models/jobs.py
run()
¶
Take a snapshot and log one INFO line per currency captured.
Source code in src/nautobot_contract_models/jobs.py
CostReportJob
¶
Bases: Job
Log a snapshot of fleet-wide contract costs to JobLogEntry.
Read-only. Operators schedule this weekly to get a cost trend in the Job result history without running a separate time-series store — each scheduled run becomes a row of JobLogEntry that can be searched, exported, or piped to a notification webhook.
Fields logged
- Monthly burn rate per currency
- 90-day renewal cost per currency
- Top vendor by current monthly spend
- Direct coverage-gap count (Devices with no direct ContractAssignment)
Source code in src/nautobot_contract_models/jobs.py
Meta
¶
run(forecast_window_days)
¶
Compute the cost summary and write per-line INFO log entries.
Source code in src/nautobot_contract_models/jobs.py
CoverageGapJob
¶
Bases: Job
Find Devices with no active contract coverage and log each one.
Walks the configured Devices (optionally filtered by Location) and uses the transitive coverage helper — so a Device is "covered" if it OR its Location OR its Tenant (etc.) has any active ContractAssignment today.
Read-only. Logs one entry per uncovered Device at WARNING level so a JobLogEntry webhook can route the list into Slack / email / a ticket.
Source code in src/nautobot_contract_models/jobs.py
Meta
¶
Job metadata.
Source code in src/nautobot_contract_models/jobs.py
run(location=None)
¶
Walk Devices, log each one without active coverage. Returns the count.
Source code in src/nautobot_contract_models/jobs.py
RenewalCheckJob
¶
Bases: Job
Find contracts expiring within window_days and log a summary per contract.
Usage
- On-demand: Jobs → Contracts → "Check upcoming renewals" → Run
- Scheduled: configure a recurring schedule (Jobs → Scheduled Jobs)
The Job is read-only — it does not modify any contracts or send out notifications directly. Operators wire notification routing via webhook hooks on JobLogEntry creation.
Source code in src/nautobot_contract_models/jobs.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
Meta
¶
Job metadata — name, description, grouping, scheduling-friendliness.
Source code in src/nautobot_contract_models/jobs.py
run(window_days, include_expired)
¶
Walk contracts; log each one expiring within the window.
Returns the count of contracts reported, which surfaces as the Job result's "result" field in the UI for at-a-glance review.