Skip to content

Commit

Permalink
[req-changes] Don't discard accounting metrics if related device is n…
Browse files Browse the repository at this point in the history
…ot found
  • Loading branch information
pandafy committed Mar 14, 2024
1 parent 000707a commit d436d40
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions openwisp_radius/integrations/monitoring/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def post_save_radiusaccounting(
return
else:
registration_method = clean_registration_method(registration_method)

try:
device = (
Device.objects.select_related('devicelocation')
Expand All @@ -116,19 +117,23 @@ def post_save_radiusaccounting(
f' and organization "{organization_id}".'
' Skipping radius_acc metric writing!'
)
return
device_id = str(device.id)
if hasattr(device, 'devicelocation'):
location_id = str(device.devicelocation.location_id)
else:
object_id = None
content_type = None
location_id = None
else:
object_id = str(device.id)
content_type = ContentType.objects.get_for_model(Device)
if hasattr(device, 'devicelocation'):
location_id = str(device.devicelocation.location_id)
else:
location_id = None

metric, created = Metric._get_or_create(
configuration='radius_acc',
name='RADIUS Accounting',
key='radius_acc',
object_id=device_id,
content_type=ContentType.objects.get_for_model(Device),
object_id=object_id,
content_type=content_type,
extra_tags={
'organization_id': organization_id,
'method': registration_method,
Expand All @@ -137,14 +142,15 @@ def post_save_radiusaccounting(
'location_id': location_id,
},
)
print('===========================================')
metric.write(
input_octets,
extra_values={
'output_octets': output_octets,
'username': sha1_hash(username),
},
)
if created:
if created and object_id:
for configuration in metric.config_dict['charts'].keys():
chart = Chart(metric=metric, configuration=configuration)
chart.full_clean()
Expand Down

0 comments on commit d436d40

Please sign in to comment.