[ADD] Adding the API link, database structure and admin panel to trigger measurement creation

This commit is contained in:
Arnold Dechamps 2024-06-01 23:47:54 +02:00
parent 35c54097dd
commit 2c4290a7c6
No known key found for this signature in database
GPG key ID: AE66543374E41C89
4 changed files with 97 additions and 2 deletions

View file

@ -1,3 +1,21 @@
from admin_extra_buttons.api import ExtraButtonsMixin, button
from admin_extra_buttons.utils import HttpResponseRedirectToReferrer
from django.contrib import admin
from .models import Atlas
import atlas.atlascreator as atlascreator
import threading
# Register your models here.
class atlas(ExtraButtonsMixin, admin.ModelAdmin):
list_display = ('unicodetld', 'stack', 'measurement', 'lastEdition')
@button(change_form=True, html_attrs={'style': 'background-color:#88FF88;color:black'})
def refresh(self, request):
self.message_user(request, 'refresh called')
t1 = threading.Thread(target=atlascreator.main())
t1.start()
# Optional: returns HttpResponse
return HttpResponseRedirectToReferrer(request)
admin.site.register(Atlas, atlas)

59
atlas/atlascreator.py Normal file
View file

@ -0,0 +1,59 @@
import requests
import config
def webrequest():
url = "https://atlas.ripe.net/api/v2/measurements/"
api_key = config.ATLAS_API
headers = {
"Authorization": f"Key {api_key}",
"Content-Type": "application/json"
}
data = {
"definitions": [
{
"type": "dns",
"af": 6,
"resolve_on_probe": True,
"description": "DNS measurement for be",
"query_class": "IN",
"query_type": "SOA",
"use_macros": False,
"protocol": "UDP",
"udp_payload_size": 512,
"retry": 0,
"skip_dns_check": False,
"include_qbuf": False,
"include_abuf": True,
"prepend_probe_id": False,
"set_rd_bit": True,
"set_do_bit": False,
"set_cd_bit": False,
"timeout": 5000,
"use_probe_resolver": True,
"set_nsid_bit": True,
"query_argument": "be"
}
],
"probes": [
{
"type": "msm",
"value": 69775666,
"requested": 624
}
],
"is_oneoff": True,
"bill_to": config.BILLING_RIPE
}
response = requests.post(url, headers=headers, json=data)
print(response.status_code)
print(response.json())
print("https://atlas.ripe.net/measurementdetail/")
def dbwriter(response):
print(response)
def main():
dbwriter(webrequest())

View file

@ -1,3 +1,17 @@
from django.db import models
# Create your models here.
class Atlas(models.Model):
STACK = ((0, "Unknown"), (4, "IPv4"), (6, "IPv6"))
unicodetld = models.CharField(max_length=100)
stack = models.IntegerField(default=0, choices=STACK)
measurement = models.IntegerField(default=0)
lastEdition = models.DateTimeField(auto_now=True)
def __str__(self):
return self.unicodetld
class Meta:
indexes = [
models.Index(fields=['stack', 'unicodetld']),
]

View file

@ -9,3 +9,7 @@ DBUSER = "tldtest"
DBPASSWORD = "clubmate2010"
CSRF_TRUSTED_ORIGINS = []
ATLAS_API = ""
BILLING_RIPE = ""