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
MigrateContractLCMToContract
¶
Bases: Job
Migrate every ContractLCM row from nautobot-app-device-lifecycle-mgmt into our Contract model.
Mirrors DLM's own :class:DLMToNautobotCoreModelMigration Job idiom: each
source ContractLCM gets stamped with a custom-field marker
migrated_to_contract_models=True after migration, so re-runs are
idempotent — already-stamped rows are excluded from the queryset.
One-way. Source ContractLCM rows are stamped but NOT deleted; operators delete from DLM's UI when they're confident the migration is correct.
Maps the ContractLCM.devices M2M into our polymorphic
:class:ContractAssignment rows (one per Device, content_type=dcim.Device).
Source code in src/nautobot_contract_models/jobs.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 | |
Meta
¶
Job metadata.
Source code in src/nautobot_contract_models/jobs.py
run(dry_run, default_billing_period, provider_match_strategy)
¶
Walk unmarked ContractLCM rows, copy to Contract + ContractAssignment, stamp the source.
Returns a dict summarizing counts; surfaces as the JobResult "result" field.
Source code in src/nautobot_contract_models/jobs.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 | |
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
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 136 137 138 139 140 141 142 143 144 145 146 | |
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.