[ADD] Adding the API link, database structure and admin panel to trigger measurement creation
This commit is contained in:
parent
35c54097dd
commit
2c4290a7c6
|
@ -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 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
59
atlas/atlascreator.py
Normal 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())
|
|
@ -1,3 +1,17 @@
|
||||||
from django.db import models
|
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']),
|
||||||
|
]
|
||||||
|
|
|
@ -9,3 +9,7 @@ DBUSER = "tldtest"
|
||||||
DBPASSWORD = "clubmate2010"
|
DBPASSWORD = "clubmate2010"
|
||||||
|
|
||||||
CSRF_TRUSTED_ORIGINS = []
|
CSRF_TRUSTED_ORIGINS = []
|
||||||
|
|
||||||
|
ATLAS_API = ""
|
||||||
|
|
||||||
|
BILLING_RIPE = ""
|
||||||
|
|
Loading…
Reference in a new issue