Metadata-Version: 2.4
Name: netbox-poweroutage
Version: 0.1.0
Summary: Show utility power outages (PGE, ODIN) near NetBox sites on a dashboard and per-site map tab
Author-email: sieteunoseis <jeremy.worden@gmail.com>
License: Apache-2.0
Project-URL: Homepage, https://github.com/sieteunoseis/netbox-poweroutage
Project-URL: Repository, https://github.com/sieteunoseis/netbox-poweroutage
Project-URL: Issues, https://github.com/sieteunoseis/netbox-poweroutage/issues
Project-URL: Documentation, https://github.com/sieteunoseis/netbox-poweroutage/wiki
Project-URL: Changelog, https://github.com/sieteunoseis/netbox-poweroutage/blob/main/CHANGELOG.md
Keywords: netbox,power,outage,odin,pge,plugin
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: Django
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28.0
Provides-Extra: dev
Requires-Dist: black; extra == "dev"
Requires-Dist: flake8; extra == "dev"
Requires-Dist: isort; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Dynamic: license-file

# NetBox Power Outage

A NetBox plugin that shows utility power outages near your sites.

- **Dashboard** — every site with active outages within a chosen radius (½, 1, 2 or 5 miles; default 1), with a map and a utility feed freshness table.
- **Site tab** — a "Power Outage" tab on each site with a map (site pin, radius ring, outage dots sized by customers out) and a list of nearby outages.
- **Background collector** — a NetBox system job pulls outages every few minutes and stores them; pages never call the outage sources directly.
- **Geocode Sites** — a page listing sites without coordinates, and a `geocode_sites` command that fills in site latitude/longitude from the physical address (US Census geocoder, OpenStreetMap fallback).
- **Read-only REST API** — outages, site matches and feeds.

## Data sources

| Source | Coverage | Notes |
|--------|----------|-------|
| `pge` | Portland General Electric | Uses the public, **undocumented** GraphQL API behind portlandgeneral.com's outage map. Read-only queries only, polled every 15 minutes by default. It may change without notice. |
| `odin` | Utilities reporting to [ODIN](https://odin.ornl.gov) (DOE / ORNL) | Public `/odi` endpoints, no account needed. Some utilities report exact points, others county-level only. |

Sources are tried in priority order (`sources` setting). When a higher-priority source covers a utility and its feed is fresh, lower-priority data for that utility is not used for matching. If that feed goes stale, the lower-priority data is used again.

Outage locations are approximate. County-level reports match every site in that county.

## Scope

This plugin is **Oregon-focused** today: the PGE source and the ODIN states default to Oregon and Washington, and it was built for an Oregon network. The source adapters are pluggable (`netbox_poweroutage/sources/`), so other utilities or regions can be added by writing one adapter that returns the same outage records.

## Requirements

- NetBox 4.7.5 or later
- A running NetBox worker (`rqworker`) for the scheduled collector

## Installation

```bash
pip install netbox-poweroutage
```

```python
# configuration.py / plugins.py
PLUGINS = ["netbox_poweroutage"]
PLUGINS_CONFIG = {"netbox_poweroutage": {}}
```

Then run `manage.py migrate` and restart NetBox.

## Configuration

| Setting | Default | Description |
|---------|---------|-------------|
| `sources` | `["pge", "odin"]` | Enabled sources, in priority order |
| `odin_states` | `["41", "53"]` | FIPS state codes to pull from ODIN (Oregon, Washington) |
| `odin_base_url` | `https://odin.ornl.gov` | ODIN base URL |
| `odin_client_id` / `odin_client_secret` | `""` | Reserved for authenticated ODIN endpoints (unused in 0.1.0) |
| `collect_interval_minutes` | `5` | System job interval |
| `pge_interval_minutes` | `15` | Minimum minutes between PGE polls |
| `pge_details` | `True` | Fetch cause / crew status / estimated restore for PGE outages near a site (one extra call per outage, refreshed every 15 minutes) |
| `pge_details_radius_miles` | `1` | Only PGE outages within this distance of a site get detail lookups |
| `default_radius_miles` | `1` | Default radius on the dashboard and site tab |
| `stale_after_minutes` | `60` | A utility feed older than this is flagged stale |
| `retention_days` | `90` | Ended outages older than this are purged |
| `timeout` | `30` | HTTP timeout in seconds |
| `tab_weight` | `9006` | Site tab ordering weight |
| `top_level_menu` | `False` | Show a top-level menu instead of items under Plugins |

## Commands

```bash
python manage.py collect_outages [--force]
python manage.py geocode_sites [--apply] [--overwrite]
```

`geocode_sites` is a dry run unless `--apply` is given, and lists every address it could not match.

## Support

If you find this plugin helpful, consider supporting development:

[![Buy Me A Coffee](https://img.shields.io/badge/Buy%20Me%20A%20Coffee-support-yellow?style=flat&logo=buy-me-a-coffee)](https://buymeacoffee.com/automatebldrs)

## License

Apache-2.0
