admin.py 4.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. __package__ = 'archivebox.machine'
  2. import abx
  3. from django.contrib import admin
  4. from django.utils.html import format_html
  5. from archivebox.base_models.admin import ABIDModelAdmin
  6. from machine.models import Machine, NetworkInterface, InstalledBinary
  7. class MachineAdmin(ABIDModelAdmin):
  8. list_display = ('abid', 'created_at', 'hostname', 'ips', 'os_platform', 'hw_in_docker', 'hw_in_vm', 'hw_manufacturer', 'hw_product', 'os_arch', 'os_family', 'os_release', 'hw_uuid', 'health')
  9. sort_fields = ('abid', 'created_at', 'hostname', 'ips', 'os_platform', 'hw_in_docker', 'hw_in_vm', 'hw_manufacturer', 'hw_product', 'os_arch', 'os_family', 'os_release', 'hw_uuid')
  10. # search_fields = ('id', 'abid', 'guid', 'hostname', 'hw_manufacturer', 'hw_product', 'hw_uuid', 'os_arch', 'os_family', 'os_platform', 'os_kernel', 'os_release')
  11. readonly_fields = ('guid', 'created_at', 'modified_at', 'abid_info', 'ips')
  12. fields = (*readonly_fields, 'hostname', 'hw_in_docker', 'hw_in_vm', 'hw_manufacturer', 'hw_product', 'hw_uuid', 'os_arch', 'os_family', 'os_platform', 'os_kernel', 'os_release', 'stats', 'num_uses_succeeded', 'num_uses_failed')
  13. list_filter = ('hw_in_docker', 'hw_in_vm', 'os_arch', 'os_family', 'os_platform')
  14. ordering = ['-created_at']
  15. list_per_page = 100
  16. actions = ["delete_selected"]
  17. @admin.display(
  18. description='Public IP',
  19. ordering='networkinterface__ip_public',
  20. )
  21. def ips(self, machine):
  22. return format_html(
  23. '<a href="/admin/machine/networkinterface/?q={}"><b><code>{}</code></b></a>',
  24. machine.abid,
  25. ', '.join(machine.networkinterface_set.values_list('ip_public', flat=True)),
  26. )
  27. class NetworkInterfaceAdmin(ABIDModelAdmin):
  28. list_display = ('abid', 'created_at', 'machine_info', 'ip_public', 'dns_server', 'isp', 'country', 'region', 'city', 'iface', 'ip_local', 'mac_address', 'health')
  29. sort_fields = ('abid', 'created_at', 'machine_info', 'ip_public', 'dns_server', 'isp', 'country', 'region', 'city', 'iface', 'ip_local', 'mac_address')
  30. search_fields = ('abid', 'machine__abid', 'iface', 'ip_public', 'ip_local', 'mac_address', 'dns_server', 'hostname', 'isp', 'city', 'region', 'country')
  31. readonly_fields = ('machine', 'created_at', 'modified_at', 'abid_info', 'mac_address', 'ip_public', 'ip_local', 'dns_server')
  32. fields = (*readonly_fields, 'iface', 'hostname', 'isp', 'city', 'region', 'country', 'num_uses_succeeded', 'num_uses_failed')
  33. list_filter = ('isp', 'country', 'region')
  34. ordering = ['-created_at']
  35. list_per_page = 100
  36. actions = ["delete_selected"]
  37. @admin.display(
  38. description='Machine',
  39. ordering='machine__abid',
  40. )
  41. def machine_info(self, iface):
  42. return format_html(
  43. '<a href="/admin/machine/machine/{}/change"><b><code>[{}]</code></b> &nbsp; {}</a>',
  44. iface.machine.id,
  45. iface.machine.abid,
  46. iface.machine.hostname,
  47. )
  48. class InstalledBinaryAdmin(ABIDModelAdmin):
  49. list_display = ('abid', 'created_at', 'machine_info', 'name', 'binprovider', 'version', 'abspath', 'sha256', 'health')
  50. sort_fields = ('abid', 'created_at', 'machine_info', 'name', 'binprovider', 'version', 'abspath', 'sha256')
  51. search_fields = ('abid', 'machine__abid', 'name', 'binprovider', 'version', 'abspath', 'sha256')
  52. readonly_fields = ('created_at', 'modified_at', 'abid_info')
  53. fields = ('machine', 'name', 'binprovider', 'abspath', 'version', 'sha256', *readonly_fields, 'num_uses_succeeded', 'num_uses_failed')
  54. list_filter = ('name', 'binprovider', 'machine_id')
  55. ordering = ['-created_at']
  56. list_per_page = 100
  57. actions = ["delete_selected"]
  58. @admin.display(
  59. description='Machine',
  60. ordering='machine__abid',
  61. )
  62. def machine_info(self, installed_binary):
  63. return format_html(
  64. '<a href="/admin/machine/machine/{}/change"><b><code>[{}]</code></b> &nbsp; {}</a>',
  65. installed_binary.machine.id,
  66. installed_binary.machine.abid,
  67. installed_binary.machine.hostname,
  68. )
  69. @abx.hookimpl
  70. def register_admin(admin_site):
  71. admin_site.register(Machine, MachineAdmin)
  72. admin_site.register(NetworkInterface, NetworkInterfaceAdmin)
  73. admin_site.register(InstalledBinary, InstalledBinaryAdmin)