How to retrieve the event type that triggered an event-rule #19482
Unanswered
kawalex
asked this question in
Help Wanted!
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I have a custom script that is triggered by an event rule each time an IP Address is created, modified or deleted.
In the script, I'd like to retrieve the type of event that triggered it, meaning if it was a creation, a modification or a deletion.
Today in the data argument of the script I only retrieve the IP Address object but not enough information:
{'log': [], 'tests': {}, 'output': "data={'id': 244, 'url': '/api/ipam/ip-addresses/244/', 'display_url': '/ipam/ip-addresses/244/', 'display': '198.19.120.2/32', 'family': {'value': 4, 'label': 'IPv4'}, 'address': '198.19.120.2/32', 'vrf': None, 'tenant': None, 'status': {'value': 'active', 'label': 'Active'}, 'role': None, 'assigned_object_type': 'dcim.interface', 'assigned_object_id': 7558, 'assigned_object': {'id': 7558, 'url': '/api/dcim/interfaces/7558/', 'display': 'Loopback99', 'device': {'id': 462, 'url': '/api/dcim/devices/462/', 'display': 'OB-C008', 'name': 'OB-C008', 'description': 'Ex BLOS401'}, 'name': 'Loopback99', 'description': '', 'cable': None, '_occupied': False}, 'nat_inside': None, 'nat_outside': [], 'dns_name': '', 'description': '', 'comments': '', 'tags': [], 'custom_fields': {}, 'created': '2025-05-13T15:20:12.316849Z', 'last_updated': '2025-05-13T15:20:12.316860Z'}"}
In this case I can guess it is a creation if 'created' and 'last_updated' are almost the same.
{'log': [], 'tests': {}, 'output': "data={'id': 244, 'url': '/api/ipam/ip-addresses/244/', 'display_url': '/ipam/ip-addresses/244/', 'display': '198.19.120.2/32', 'family': {'value': 4, 'label': 'IPv4'}, 'address': '198.19.120.2/32', 'vrf': None, 'tenant': None, 'status': {'value': 'active', 'label': 'Active'}, 'role': None, 'assigned_object_type': 'dcim.interface', 'assigned_object_id': 7558, 'assigned_object': {'id': 7558, 'url': '/api/dcim/interfaces/7558/', 'display': 'Loopback99', 'device': {'id': 462, 'url': '/api/dcim/devices/462/', 'display': 'OB-C008', 'name': 'OB-C008', 'description': 'Ex BLOS401'}, 'name': 'Loopback99', 'description': '', 'cable': None, '_occupied': False}, 'nat_inside': None, 'nat_outside': [], 'dns_name': '', 'description': 'Test', 'comments': '', 'tags': [], 'custom_fields': {}, 'created': '2025-05-13T15:20:12.316849Z', 'last_updated': '2025-05-13T15:21:57.999324Z'}"}
In this case I can guess it is a modification as 'created' and 'last_updated' are not the same.
{'log': [], 'tests': {}, 'output': "data={'id': 244, 'url': '/api/ipam/ip-addresses/244/', 'display_url': '/ipam/ip-addresses/244/', 'display': '198.19.120.2/32', 'family': {'value': 4, 'label': 'IPv4'}, 'address': '198.19.120.2/32', 'vrf': None, 'tenant': None, 'status': {'value': 'active', 'label': 'Active'}, 'role': None, 'assigned_object_type': 'dcim.interface', 'assigned_object_id': 7558, 'assigned_object': {'id': 7558, 'url': '/api/dcim/interfaces/7558/', 'display': 'Loopback99', 'device': {'id': 462, 'url': '/api/dcim/devices/462/', 'display': 'OB-C008', 'name': 'OB-C008', 'description': 'Ex BLOS401'}, 'name': 'Loopback99', 'description': '', 'cable': None, '_occupied': False}, 'nat_inside': None, 'nat_outside': [], 'dns_name': '', 'description': 'Test', 'comments': '', 'tags': [], 'custom_fields': {}, 'created': '2025-05-13T15:20:12.316849Z', 'last_updated': '2025-05-13T15:21:57.999324Z'}"}
In this case, we get same data as after a modification, no sign of deletion. So I cannot guess the IP address was deleted (without checking if it still exists which may be a workaround).
Does someone know how I can retrieve the event action type from Netbox ?
Beta Was this translation helpful? Give feedback.
All reactions