forked from FlxPeters/netbox-plugin-prometheus-sd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'FlxPeters:main' into main
- Loading branch information
Showing
21 changed files
with
527 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,3 @@ | |
|
||
- [ ] I have performed a self-review of my code | ||
- [ ] If it is a core feature, I have added thorough tests. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: Publish | ||
name: Publish on PyPi | ||
|
||
on: | ||
release: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Release | ||
on: | ||
push: | ||
branches: | ||
- main | ||
repository_dispatch: | ||
types: [semantic-release] | ||
|
||
permissions: | ||
contents: read # for checkout | ||
|
||
jobs: | ||
release: | ||
name: Release | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write # to be able to publish a GitHub release | ||
issues: write # to be able to comment on released issues | ||
pull-requests: write # to be able to comment on released pull requests | ||
id-token: write # to enable use of OIDC for npm provenance | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "lts/*" | ||
- name: Release | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
run: npx semantic-release --dry-run --debug --ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Close Stale Pull Requests | ||
|
||
on: | ||
schedule: | ||
- cron: '0 0 * * *' # Run every day at midnight | ||
|
||
permissions: | ||
issues: write | ||
pull-requests: write | ||
|
||
jobs: | ||
close_stale_prs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Close stale pull requests | ||
uses: actions/stale@v9 | ||
with: | ||
debug-only: true | ||
stale-issue-message: | | ||
This issue has been automatically closed because it has been inactive for more than 60 days. | ||
Please reopen if you still intend to submit this pull request. | ||
days-before-stale: 60 | ||
days-before-close: 7 | ||
stale-pr-message: | | ||
This pull request has been marked as stale because it has been inactive for more than 60 days. | ||
Please update this pull request or it will be automatically closed in 7 days. | ||
stale-pr-label: stale |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"branches": ["main"], | ||
"plugins": [ | ||
"@semantic-release/commit-analyzer", | ||
"@semantic-release/release-notes-generator", | ||
"@semantic-release/github" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const Configuration = { | ||
extends: ['@commitlint/config-conventional'], | ||
rules: { | ||
// Increase to 300 characters for max line length in body | ||
"body-max-line-length": [2, "always", 300], | ||
// Increase to 300 characters for max line length in footer | ||
"footer-max-line-length": [2, "always", 300], | ||
}, | ||
}; | ||
|
||
export default Configuration; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,14 @@ | ||
ARG netbox_ver=latest | ||
|
||
FROM python:3.11 | ||
FROM netboxcommunity/netbox:${netbox_ver} | ||
|
||
ENV PYTHONUNBUFFERED 1 | ||
|
||
RUN mkdir -p /opt | ||
|
||
RUN pip install --upgrade pip\ | ||
&& pip install poetry | ||
|
||
# ------------------------------------------------------------------------------------- | ||
# Install NetBox | ||
# ------------------------------------------------------------------------------------- | ||
ARG netbox_ver=master | ||
|
||
RUN git clone --single-branch --branch ${netbox_ver} https://github.com/netbox-community/netbox.git /opt/netbox/ && \ | ||
cd /opt/netbox/ && \ | ||
pip install -r /opt/netbox/requirements.txt | ||
|
||
# Make the django-debug-toolbar always visible when DEBUG is enabled, | ||
# except when we're running Django unit-tests. | ||
RUN echo "import sys" >> /opt/netbox/netbox/netbox/settings.py && \ | ||
echo "TESTING = len(sys.argv) > 1 and sys.argv[1] == 'test'" >> /opt/netbox/netbox/netbox/settings.py && \ | ||
echo "DEBUG_TOOLBAR_CONFIG = {'SHOW_TOOLBAR_CALLBACK': lambda _: DEBUG and not TESTING }" >> /opt/netbox/netbox/netbox/settings.py | ||
|
||
# ------------------------------------------------------------------------------------- | ||
# Install Netbox Plugin | ||
# ------------------------------------------------------------------------------------- | ||
RUN mkdir -p /source | ||
WORKDIR /source | ||
COPY . /source | ||
RUN poetry config virtualenvs.create false \ | ||
&& poetry install --no-interaction --no-ansi | ||
COPY .. /source | ||
|
||
# Install the plugin in netbox | ||
RUN /opt/netbox/venv/bin/pip install -r /source/requirements.txt | ||
RUN /opt/netbox/venv/bin/pip install --editable /source | ||
|
||
WORKDIR /opt/netbox/netbox/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
text_field: | ||
type: string | ||
on_objects: ["dcim.models.DeviceType", "dcim.models.Device", "virtualization.models.VirtualMachine"] | ||
on_objects: ["dcim.models.DeviceType", "dcim.models.Device", "virtualization.models.VirtualMachine"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
netbox-plugin-prometheus-sd @ git+https://github.com/flxpeters/netbox-plugin-prometheus-sd.git@main | ||
netbox-initializers==3.7.* | ||
netbox-initializers==4.0.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Filtersets have been renamed, we support both | ||
# https://github.com/netbox-community/netbox/commit/1024782b9e0abb48f6da65f8248741227d53dbed#diff-d9224204dab475bbe888868c02235b8ef10f07c9201c45c90804d395dc161c40 | ||
from django.db.models import Q | ||
from django.utils.translation import gettext as _ | ||
|
||
from utilities.filters import MultiValueCharFilter, MultiValueNumberFilter | ||
|
||
try: | ||
from ipam.filtersets import ServiceFilterSet as NetboxServiceFilterSet | ||
except ImportError: | ||
from ipam.filters import ServiceFilterSet as NetboxServiceFilterSet | ||
|
||
|
||
class ServiceFilterSet(NetboxServiceFilterSet): | ||
"""Filter set to support tenancy over the device/VM foreign key. | ||
Tenancy in Netbox is very incosistent and the relationship on its own is defined across many different models. This | ||
means that supporting all layers is nearly impossible without a stronger upstream support. For this reason only the | ||
"first level" tenancy is supported by this filter set. | ||
""" | ||
|
||
tenant_id = MultiValueNumberFilter( | ||
method='filter_by_tenant_id', | ||
label=_('Tenant (ID)'), | ||
) | ||
|
||
tenant = MultiValueCharFilter( | ||
method='filter_by_tenant_slug', | ||
label=_('Tenant (slug)'), | ||
) | ||
|
||
# pylint: disable=unused-argument | ||
def filter_by_cluster_tenant_id(self, queryset, name, value): | ||
return queryset.filter( | ||
Q(device__cluster__tenant_id__in=value) | | ||
Q(virtual_machine__cluster__tenant_id__in=value) | ||
) | ||
|
||
def filter_by_cluster_tenant_slug(self, queryset, name, value): | ||
return queryset.filter( | ||
Q(device__cluster__tenant__slug__in=value) | | ||
Q(virtual_machine__cluster__tenant__slug__in=value) | ||
) | ||
|
||
def filter_by_tenant_id(self, queryset, name, value): | ||
return queryset.filter(Q(device__tenant_id__in=value) | Q(virtual_machine__tenant_id__in=value)) | ||
|
||
def filter_by_tenant_slug(self, queryset, name, value): | ||
return queryset.filter(Q(device__tenant__slug__in=value) | Q(virtual_machine__tenant__slug__in=value)) |
Oops, something went wrong.