LogstashUI 0.5.5.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (762) hide show
  1. AI/__init__.py +0 -0
  2. AI/integration_factory.py +1392 -0
  3. AI/migrations/0001_initial.py +58 -0
  4. AI/migrations/0002_draftdefinition_normalizers.py +23 -0
  5. AI/migrations/0003_delete_aisettings_delete_draftdefinition.py +19 -0
  6. AI/migrations/__init__.py +0 -0
  7. AI/models.py +5 -0
  8. AI/static/js/integration_factory.js +1102 -0
  9. AI/system_prompts/dashboard_generator.md +367 -0
  10. AI/system_prompts/grok_patterns.txt +95 -0
  11. AI/system_prompts/ingest_pipeline_generator.md +331 -0
  12. AI/system_prompts/ingest_pipeline_processors.json +2851 -0
  13. AI/system_prompts/ingest_verifier.md +84 -0
  14. AI/system_prompts/integrations_list.json +2690 -0
  15. AI/system_prompts/log_classifier.md +134 -0
  16. AI/system_prompts/template_creator.md +123 -0
  17. AI/templates/integration_factory.html +200 -0
  18. AI/urls.py +16 -0
  19. AI/views.py +20 -0
  20. API/__init__.py +0 -0
  21. API/admin.py +7 -0
  22. API/api.http +784 -0
  23. API/apps.py +9 -0
  24. API/auth.py +101 -0
  25. API/connections_views.py +312 -0
  26. API/guides.py +88 -0
  27. API/mcp/__init__.py +5 -0
  28. API/mcp/dispatch.py +179 -0
  29. API/mcp/tools.py +890 -0
  30. API/mcp/views.py +215 -0
  31. API/migrations/__init__.py +0 -0
  32. API/models.py +7 -0
  33. API/pipelines_views.py +1224 -0
  34. API/policies_views.py +1015 -0
  35. API/security_views.py +488 -0
  36. API/simulation_detail.py +219 -0
  37. API/snmp_views.py +1539 -0
  38. API/urls.py +81 -0
  39. Common/__init__.py +0 -0
  40. Common/ai/agent_builder.py +690 -0
  41. Common/context_processors.py +49 -0
  42. Common/decorators.py +68 -0
  43. Common/elastic_utils.py +1154 -0
  44. Common/encryption.py +271 -0
  45. Common/error_handlers.py +65 -0
  46. Common/formatters.py +106 -0
  47. Common/logstash_config_parse.py +1469 -0
  48. Common/logstash_utils.py +34 -0
  49. Common/middleware.py +216 -0
  50. Common/product_ca.py +1124 -0
  51. Common/validators.py +66 -0
  52. Documentation/__init__.py +0 -0
  53. Documentation/admin.py +7 -0
  54. Documentation/apps.py +9 -0
  55. Documentation/content/CHANGELOG.md +890 -0
  56. Documentation/content/docs/getting_started.md +92 -0
  57. Documentation/content/docs/index.md +124 -0
  58. Documentation/content/docs/logstashagent/configuration/index.md +60 -0
  59. Documentation/content/docs/logstashagent/configuration/logstashagent.yml.md +141 -0
  60. Documentation/content/docs/logstashagent/general/build.md +217 -0
  61. Documentation/content/docs/logstashagent/general/index.md +38 -0
  62. Documentation/content/docs/logstashagent/general/roles.md +267 -0
  63. Documentation/content/docs/logstashagent/index.md +264 -0
  64. Documentation/content/docs/logstashui/SNMP/Quickstart.md +94 -0
  65. Documentation/content/docs/logstashui/SNMP/architecture.md +64 -0
  66. Documentation/content/docs/logstashui/SNMP/configuration.md +147 -0
  67. Documentation/content/docs/logstashui/SNMP/data_overview.md +59 -0
  68. Documentation/content/docs/logstashui/SNMP/deploying_changes.md +71 -0
  69. Documentation/content/docs/logstashui/SNMP/device_support.md +39 -0
  70. Documentation/content/docs/logstashui/SNMP/discovery.md +48 -0
  71. Documentation/content/docs/logstashui/SNMP/index.md +58 -0
  72. Documentation/content/docs/logstashui/SNMP/pipeline_generation.md +63 -0
  73. Documentation/content/docs/logstashui/SNMP/schema.md +595 -0
  74. Documentation/content/docs/logstashui/SNMP/testing.md +47 -0
  75. Documentation/content/docs/logstashui/SNMP/traps.md +45 -0
  76. Documentation/content/docs/logstashui/SNMP/tsds_implementation.md +82 -0
  77. Documentation/content/docs/logstashui/agent_guides/concepts.md +25 -0
  78. Documentation/content/docs/logstashui/agent_guides/deploy.md +30 -0
  79. Documentation/content/docs/logstashui/agent_guides/pipeline-review.md +24 -0
  80. Documentation/content/docs/logstashui/agent_guides/simulation.md +55 -0
  81. Documentation/content/docs/logstashui/agent_guides/snmp.md +57 -0
  82. Documentation/content/docs/logstashui/agent_guides/troubleshooting.md +21 -0
  83. Documentation/content/docs/logstashui/architecture.md +11 -0
  84. Documentation/content/docs/logstashui/compatibility.md +58 -0
  85. Documentation/content/docs/logstashui/configuration/environment.md +193 -0
  86. Documentation/content/docs/logstashui/configuration/host_mode.md +94 -0
  87. Documentation/content/docs/logstashui/configuration/index.md +72 -0
  88. Documentation/content/docs/logstashui/configuration/logstash_proxy.md +138 -0
  89. Documentation/content/docs/logstashui/configuration/logstashui.yml.md +16 -0
  90. Documentation/content/docs/logstashui/configuration/simulation.md +84 -0
  91. Documentation/content/docs/logstashui/database/examples/README.md +15 -0
  92. Documentation/content/docs/logstashui/database/examples/create-mariadb.sql +13 -0
  93. Documentation/content/docs/logstashui/database/examples/create-mysql.sql +12 -0
  94. Documentation/content/docs/logstashui/database/examples/create-postgresql.sql +13 -0
  95. Documentation/content/docs/logstashui/database/examples/schema-mysql.sql +502 -0
  96. Documentation/content/docs/logstashui/database/examples/schema-postgresql.sql +1709 -0
  97. Documentation/content/docs/logstashui/database/index.md +79 -0
  98. Documentation/content/docs/logstashui/database/migration.md +75 -0
  99. Documentation/content/docs/logstashui/general/build.md +154 -0
  100. Documentation/content/docs/logstashui/general/deploy.md +122 -0
  101. Documentation/content/docs/logstashui/general/deployment-recs.md +32 -0
  102. Documentation/content/docs/logstashui/general/index.md +62 -0
  103. Documentation/content/docs/logstashui/general/offline.md +68 -0
  104. Documentation/content/docs/logstashui/general/updating.md +50 -0
  105. Documentation/content/docs/logstashui/index.md +90 -0
  106. Documentation/content/docs/logstashui/kubernetes/cnpg.md +98 -0
  107. Documentation/content/docs/logstashui/kubernetes/envoy-gateway.md +112 -0
  108. Documentation/content/docs/logstashui/kubernetes/examples/README.md +46 -0
  109. Documentation/content/docs/logstashui/kubernetes/examples/embedded-agent.yaml +122 -0
  110. Documentation/content/docs/logstashui/kubernetes/examples/mysql/configmap.yaml +41 -0
  111. Documentation/content/docs/logstashui/kubernetes/examples/mysql/ingress.yaml +31 -0
  112. Documentation/content/docs/logstashui/kubernetes/examples/mysql/namespace.yaml +8 -0
  113. Documentation/content/docs/logstashui/kubernetes/examples/mysql/secret.yaml +19 -0
  114. Documentation/content/docs/logstashui/kubernetes/examples/mysql/statefulset.yaml +106 -0
  115. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/cnpg.yaml +25 -0
  116. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/configmap.yaml +42 -0
  117. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/ingress.yaml +31 -0
  118. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/namespace.yaml +8 -0
  119. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/secret.yaml +19 -0
  120. Documentation/content/docs/logstashui/kubernetes/examples/postgresql/statefulset.yaml +106 -0
  121. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/configmap.yaml +35 -0
  122. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/ingress.yaml +31 -0
  123. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/namespace.yaml +8 -0
  124. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/secret.yaml +18 -0
  125. Documentation/content/docs/logstashui/kubernetes/examples/sqlite/statefulset.yaml +106 -0
  126. Documentation/content/docs/logstashui/kubernetes/index.md +121 -0
  127. Documentation/content/docs/logstashui/mcp.md +224 -0
  128. Documentation/content/docs/logstashui/mcp_scenarios.md +234 -0
  129. Documentation/content/docs/logstashui/rest_api.md +2783 -0
  130. Documentation/content/docs/logstashui/utilities/dissect_debugger.md +89 -0
  131. Documentation/content/docs/logstashui/utilities/grok_debugger.md +114 -0
  132. Documentation/content/docs/logstashui/utilities/index.md +40 -0
  133. Documentation/content/images/LogstashIcon.png +0 -0
  134. Documentation/content/images/architecture.png +0 -0
  135. Documentation/content/images/connection_manager.png +0 -0
  136. Documentation/content/images/control_plane.png +0 -0
  137. Documentation/content/images/graph.gif +0 -0
  138. Documentation/content/images/login.png +0 -0
  139. Documentation/content/images/monitoring.png +0 -0
  140. Documentation/content/images/new_connection.gif +0 -0
  141. Documentation/content/images/simulate.gif +0 -0
  142. Documentation/content/images/simulate.png +0 -0
  143. Documentation/content/images/snmp.gif +0 -0
  144. Documentation/content/images/snmp.png +0 -0
  145. Documentation/content/images/snmp_architecture.png +0 -0
  146. Documentation/migrations/__init__.py +0 -0
  147. Documentation/models.py +9 -0
  148. Documentation/static/css/markdown.css +250 -0
  149. Documentation/templates/documentation.html +225 -0
  150. Documentation/templates/nav_item.html +41 -0
  151. Documentation/urls.py +11 -0
  152. Documentation/views.py +442 -0
  153. LogstashUI/__init__.py +0 -0
  154. LogstashUI/__main__.py +10 -0
  155. LogstashUI/asgi.py +16 -0
  156. LogstashUI/cli.py +626 -0
  157. LogstashUI/config.py +116 -0
  158. LogstashUI/database.py +263 -0
  159. LogstashUI/insecure_http.py +117 -0
  160. LogstashUI/logging_config.py +99 -0
  161. LogstashUI/migrate_engine.py +282 -0
  162. LogstashUI/packaging/__init__.py +3 -0
  163. LogstashUI/packaging/logstashui.default +68 -0
  164. LogstashUI/packaging/logstashui.service.in +22 -0
  165. LogstashUI/paths.py +181 -0
  166. LogstashUI/settings.py +437 -0
  167. LogstashUI/telemetry.py +159 -0
  168. LogstashUI/urls.py +56 -0
  169. LogstashUI/wsgi.py +77 -0
  170. Management/__init__.py +0 -0
  171. Management/apps.py +10 -0
  172. Management/migrations/0001_initial.py +29 -0
  173. Management/migrations/0002_settings.py +25 -0
  174. Management/migrations/0003_settings_agent_ui_url.py +29 -0
  175. Management/migrations/0004_settings_logstash_artifact_base_url.py +29 -0
  176. Management/migrations/__init__.py +0 -0
  177. Management/models.py +92 -0
  178. Management/templates/api_tokens.html +214 -0
  179. Management/templates/components/api_token_created.html +38 -0
  180. Management/templates/components/api_token_row.html +84 -0
  181. Management/templates/components/logstash_artifact_row.html +100 -0
  182. Management/templates/components/logstash_artifact_tbody.html +26 -0
  183. Management/templates/components/user_row.html +67 -0
  184. Management/templates/logs.html +98 -0
  185. Management/templates/logstash_artifacts.html +172 -0
  186. Management/templates/management.html +80 -0
  187. Management/templates/management_settings.html +320 -0
  188. Management/templates/registration/login.html +404 -0
  189. Management/templates/users.html +304 -0
  190. Management/urls.py +23 -0
  191. Management/views.py +804 -0
  192. Monitoring/__init__.py +0 -0
  193. Monitoring/apps.py +9 -0
  194. Monitoring/migrations/__init__.py +0 -0
  195. Monitoring/static/js/monitoring.js +463 -0
  196. Monitoring/templates/components/node_metrics.html +161 -0
  197. Monitoring/templates/components/pipeline_metrics.html +189 -0
  198. Monitoring/templates/monitoring.html +271 -0
  199. Monitoring/urls.py +16 -0
  200. Monitoring/views.py +724 -0
  201. PipelineManager/__init__.py +0 -0
  202. PipelineManager/agent_api.py +1173 -0
  203. PipelineManager/agent_client.py +59 -0
  204. PipelineManager/agent_modes.py +880 -0
  205. PipelineManager/agent_policies.py +689 -0
  206. PipelineManager/agent_versions.py +151 -0
  207. PipelineManager/apps.py +10 -0
  208. PipelineManager/artifact_metrics.py +171 -0
  209. PipelineManager/artifacts.py +820 -0
  210. PipelineManager/connections_crud.py +722 -0
  211. PipelineManager/data/default_jvm.options +76 -0
  212. PipelineManager/data/default_log4j2.properties +165 -0
  213. PipelineManager/data/default_logstash.yml +405 -0
  214. PipelineManager/data/plugins.json +29109 -0
  215. PipelineManager/editor_views.py +608 -0
  216. PipelineManager/forms.py +284 -0
  217. PipelineManager/manager_views.py +490 -0
  218. PipelineManager/migrations/0001_initial.py +38 -0
  219. PipelineManager/migrations/0002_alter_connection_connection_type_and_more.py +38 -0
  220. PipelineManager/migrations/0003_policy_connection_policy.py +38 -0
  221. PipelineManager/migrations/0004_policy_current_revision_number_and_more.py +75 -0
  222. PipelineManager/migrations/0005_apikey_enrollmenttoken.py +38 -0
  223. PipelineManager/migrations/0006_enrollmenttoken_name.py +18 -0
  224. PipelineManager/migrations/0007_alter_enrollmenttoken_options_and_more.py +21 -0
  225. PipelineManager/migrations/0008_connection_agent_id.py +18 -0
  226. PipelineManager/migrations/0009_connection_last_check_in_policy_jvm_options_hash_and_more.py +33 -0
  227. PipelineManager/migrations/0010_keystore_revision_number_pipeline_revision_number.py +23 -0
  228. PipelineManager/migrations/0011_keystore_kv_hash.py +18 -0
  229. PipelineManager/migrations/0012_policy_binary_path.py +18 -0
  230. PipelineManager/migrations/0013_connection_status_blob.py +18 -0
  231. PipelineManager/migrations/0014_pipeline_pipeline_batch_delay_and_more.py +43 -0
  232. PipelineManager/migrations/0015_add_pipeline_hash.py +18 -0
  233. PipelineManager/migrations/0016_backfill_pipeline_hash.py +32 -0
  234. PipelineManager/migrations/0017_policy_keystore_password.py +31 -0
  235. PipelineManager/migrations/0018_policy_last_deployed_at.py +18 -0
  236. PipelineManager/migrations/0019_connection_restart_on_next_checkin.py +18 -0
  237. PipelineManager/migrations/0020_pipeline_no_input_pipeline_non_reloadable.py +23 -0
  238. PipelineManager/migrations/0021_connection_desired_agent_version.py +18 -0
  239. PipelineManager/migrations/0022_keystore_managed_by_pipeline_managed_by.py +23 -0
  240. PipelineManager/migrations/0023_agent_modes_policy_connection.py +89 -0
  241. PipelineManager/migrations/0024_seed_system_policies.py +173 -0
  242. PipelineManager/migrations/0025_packaged_managed_policy_types.py +166 -0
  243. PipelineManager/migrations/0026_normalize_opt_logstash_agent_paths.py +63 -0
  244. PipelineManager/migrations/0027_packaged_managed_default_ports.py +49 -0
  245. PipelineManager/migrations/0028_apikey_admin_tokens.py +80 -0
  246. PipelineManager/migrations/0029_logstash_artifacts.py +45 -0
  247. PipelineManager/migrations/0030_connection_allow_self_signed_certs.py +33 -0
  248. PipelineManager/migrations/0031_deploy_system_policies.py +93 -0
  249. PipelineManager/migrations/0032_connection_agent_inbound_key.py +30 -0
  250. PipelineManager/migrations/0033_simulation_result.py +26 -0
  251. PipelineManager/migrations/__init__.py +0 -0
  252. PipelineManager/models.py +1300 -0
  253. PipelineManager/pipelines_crud.py +738 -0
  254. PipelineManager/policies_crud.py +772 -0
  255. PipelineManager/sim_keystore.py +319 -0
  256. PipelineManager/simulation.py +1581 -0
  257. PipelineManager/static/css/codemirror.min.css +1 -0
  258. PipelineManager/static/css/graph_move.css +79 -0
  259. PipelineManager/static/css/monokai.min.css +1 -0
  260. PipelineManager/static/css/move_mode.css +144 -0
  261. PipelineManager/static/css/show-hint.min.css +1 -0
  262. PipelineManager/static/images/age.png +0 -0
  263. PipelineManager/static/images/aggregate.png +0 -0
  264. PipelineManager/static/images/alter.png +0 -0
  265. PipelineManager/static/images/azure_event_hubs.png +0 -0
  266. PipelineManager/static/images/beats.png +0 -0
  267. PipelineManager/static/images/boundary.png +0 -0
  268. PipelineManager/static/images/bytes.png +0 -0
  269. PipelineManager/static/images/cidr.png +0 -0
  270. PipelineManager/static/images/cipher.png +0 -0
  271. PipelineManager/static/images/circonus.png +0 -0
  272. PipelineManager/static/images/clone.png +0 -0
  273. PipelineManager/static/images/cloudwatch.png +0 -0
  274. PipelineManager/static/images/comment.png +0 -0
  275. PipelineManager/static/images/continue.png +0 -0
  276. PipelineManager/static/images/couchdb_changes.png +0 -0
  277. PipelineManager/static/images/csv.png +0 -0
  278. PipelineManager/static/images/datadog.png +0 -0
  279. PipelineManager/static/images/datadog_metrics.png +0 -0
  280. PipelineManager/static/images/date.png +0 -0
  281. PipelineManager/static/images/de_dot.png +0 -0
  282. PipelineManager/static/images/dead_letter_queue.png +0 -0
  283. PipelineManager/static/images/dissect.png +0 -0
  284. PipelineManager/static/images/dns.png +0 -0
  285. PipelineManager/static/images/drop.png +0 -0
  286. PipelineManager/static/images/dynatrace.png +0 -0
  287. PipelineManager/static/images/elapsed.png +0 -0
  288. PipelineManager/static/images/elastic_agent.png +0 -0
  289. PipelineManager/static/images/elastic_integration.png +0 -0
  290. PipelineManager/static/images/elastic_serverless_forwarder.png +0 -0
  291. PipelineManager/static/images/elastic_workplace_search.png +0 -0
  292. PipelineManager/static/images/elasticsearch.png +0 -0
  293. PipelineManager/static/images/else.png +0 -0
  294. PipelineManager/static/images/else_if.png +0 -0
  295. PipelineManager/static/images/email.png +0 -0
  296. PipelineManager/static/images/environment.png +0 -0
  297. PipelineManager/static/images/exec.png +0 -0
  298. PipelineManager/static/images/extractnumbers.png +0 -0
  299. PipelineManager/static/images/file.png +0 -0
  300. PipelineManager/static/images/fingerprint.png +0 -0
  301. PipelineManager/static/images/ganglia.png +0 -0
  302. PipelineManager/static/images/gelf.png +0 -0
  303. PipelineManager/static/images/generator.png +0 -0
  304. PipelineManager/static/images/geoip.png +0 -0
  305. PipelineManager/static/images/github.png +0 -0
  306. PipelineManager/static/images/google_bigquery.png +0 -0
  307. PipelineManager/static/images/google_cloud_storage.png +0 -0
  308. PipelineManager/static/images/google_pubsub.png +0 -0
  309. PipelineManager/static/images/graphite.png +0 -0
  310. PipelineManager/static/images/graphtastic.png +0 -0
  311. PipelineManager/static/images/grok.png +0 -0
  312. PipelineManager/static/images/heartbeat.png +0 -0
  313. PipelineManager/static/images/http.png +0 -0
  314. PipelineManager/static/images/http_poller.png +0 -0
  315. PipelineManager/static/images/i18n.png +0 -0
  316. PipelineManager/static/images/if.png +0 -0
  317. PipelineManager/static/images/imap.png +0 -0
  318. PipelineManager/static/images/influxdb.png +0 -0
  319. PipelineManager/static/images/irc.png +0 -0
  320. PipelineManager/static/images/java_generator.png +0 -0
  321. PipelineManager/static/images/java_stdin.png +0 -0
  322. PipelineManager/static/images/java_stdout.png +0 -0
  323. PipelineManager/static/images/java_uuid.png +0 -0
  324. PipelineManager/static/images/jdbc.png +0 -0
  325. PipelineManager/static/images/jdbc_static.png +0 -0
  326. PipelineManager/static/images/jdbc_streaming.png +0 -0
  327. PipelineManager/static/images/jms.png +0 -0
  328. PipelineManager/static/images/jmx.png +0 -0
  329. PipelineManager/static/images/json.png +0 -0
  330. PipelineManager/static/images/json_encode.png +0 -0
  331. PipelineManager/static/images/juggernaut.png +0 -0
  332. PipelineManager/static/images/kafka.png +0 -0
  333. PipelineManager/static/images/kinesis.png +0 -0
  334. PipelineManager/static/images/kv.png +0 -0
  335. PipelineManager/static/images/librato.png +0 -0
  336. PipelineManager/static/images/log4j.png +0 -0
  337. PipelineManager/static/images/loggly.png +0 -0
  338. PipelineManager/static/images/logstash.png +0 -0
  339. PipelineManager/static/images/lumberjack.png +0 -0
  340. PipelineManager/static/images/meetup.png +0 -0
  341. PipelineManager/static/images/memcached.png +0 -0
  342. PipelineManager/static/images/metriccatcher.png +0 -0
  343. PipelineManager/static/images/metricize.png +0 -0
  344. PipelineManager/static/images/metrics.png +0 -0
  345. PipelineManager/static/images/mongodb.png +0 -0
  346. PipelineManager/static/images/mutate.png +0 -0
  347. PipelineManager/static/images/nagios.png +0 -0
  348. PipelineManager/static/images/nagios_nsca.png +0 -0
  349. PipelineManager/static/images/opentsdb.png +0 -0
  350. PipelineManager/static/images/pagerduty.png +0 -0
  351. PipelineManager/static/images/pipe.png +0 -0
  352. PipelineManager/static/images/pipeline.png +0 -0
  353. PipelineManager/static/images/prune.png +0 -0
  354. PipelineManager/static/images/puppet_facter.png +0 -0
  355. PipelineManager/static/images/rabbitmq.png +0 -0
  356. PipelineManager/static/images/range.png +0 -0
  357. PipelineManager/static/images/redis.png +0 -0
  358. PipelineManager/static/images/redmine.png +0 -0
  359. PipelineManager/static/images/relp.png +0 -0
  360. PipelineManager/static/images/riak.png +0 -0
  361. PipelineManager/static/images/riemann.png +0 -0
  362. PipelineManager/static/images/rss.png +0 -0
  363. PipelineManager/static/images/ruby.png +0 -0
  364. PipelineManager/static/images/s3-sns-sqs.png +0 -0
  365. PipelineManager/static/images/s3.png +0 -0
  366. PipelineManager/static/images/salesforce.png +0 -0
  367. PipelineManager/static/images/sink.png +0 -0
  368. PipelineManager/static/images/sleep.png +0 -0
  369. PipelineManager/static/images/snmp.png +0 -0
  370. PipelineManager/static/images/snmptrap.png +0 -0
  371. PipelineManager/static/images/sns.png +0 -0
  372. PipelineManager/static/images/solr_http.png +0 -0
  373. PipelineManager/static/images/split.png +0 -0
  374. PipelineManager/static/images/sqlite.png +0 -0
  375. PipelineManager/static/images/sqs.png +0 -0
  376. PipelineManager/static/images/statsd.png +0 -0
  377. PipelineManager/static/images/stdin.png +0 -0
  378. PipelineManager/static/images/stdout.png +0 -0
  379. PipelineManager/static/images/stomp.png +0 -0
  380. PipelineManager/static/images/syslog.png +0 -0
  381. PipelineManager/static/images/syslog_pri.png +0 -0
  382. PipelineManager/static/images/tcp.png +0 -0
  383. PipelineManager/static/images/threats_classifier.png +0 -0
  384. PipelineManager/static/images/throttle.png +0 -0
  385. PipelineManager/static/images/timber.png +0 -0
  386. PipelineManager/static/images/tld.png +0 -0
  387. PipelineManager/static/images/translate.png +0 -0
  388. PipelineManager/static/images/truncate.png +0 -0
  389. PipelineManager/static/images/twitter.png +0 -0
  390. PipelineManager/static/images/udp.png +0 -0
  391. PipelineManager/static/images/unix.png +0 -0
  392. PipelineManager/static/images/urldecode.png +0 -0
  393. PipelineManager/static/images/useragent.png +0 -0
  394. PipelineManager/static/images/uuid.png +0 -0
  395. PipelineManager/static/images/varnishlog.png +0 -0
  396. PipelineManager/static/images/webhdfs.png +0 -0
  397. PipelineManager/static/images/websocket.png +0 -0
  398. PipelineManager/static/images/wmi.png +0 -0
  399. PipelineManager/static/images/wurfl_device_detection.png +0 -0
  400. PipelineManager/static/images/xml.png +0 -0
  401. PipelineManager/static/images/xmpp.png +0 -0
  402. PipelineManager/static/images/zabbix.png +0 -0
  403. PipelineManager/static/js/agent_inspect_modal.js +141 -0
  404. PipelineManager/static/js/agent_policies.js +3746 -0
  405. PipelineManager/static/js/agent_status_sse.js +166 -0
  406. PipelineManager/static/js/codemirror.min.js +1 -0
  407. PipelineManager/static/js/connections_table.js +551 -0
  408. PipelineManager/static/js/d3.v7.js +20625 -0
  409. PipelineManager/static/js/diff_modal.js +995 -0
  410. PipelineManager/static/js/expression_editor.js +291 -0
  411. PipelineManager/static/js/js-yaml.min.js +1 -0
  412. PipelineManager/static/js/logstashyml_guides.js +1063 -0
  413. PipelineManager/static/js/move_graph.js +577 -0
  414. PipelineManager/static/js/move_mode.js +559 -0
  415. PipelineManager/static/js/pipeline_editor.js +4102 -0
  416. PipelineManager/static/js/pipeline_graph_editor.js +3542 -0
  417. PipelineManager/static/js/pipeline_list.js +274 -0
  418. PipelineManager/static/js/pipeline_settings.js +121 -0
  419. PipelineManager/static/js/pipeline_text_editor.js +2088 -0
  420. PipelineManager/static/js/plugin_config_modal.js +2827 -0
  421. PipelineManager/static/js/policy_deploy_modal.js +1066 -0
  422. PipelineManager/static/js/show-hint.min.js +1 -0
  423. PipelineManager/static/js/sim_targets.js +380 -0
  424. PipelineManager/static/js/simple-comment-mode.js +56 -0
  425. PipelineManager/static/js/simulation_modal.js +1135 -0
  426. PipelineManager/static/js/simulation_results.js +2778 -0
  427. PipelineManager/static/js/stats_strip.js +231 -0
  428. PipelineManager/static/js/yaml.js +120 -0
  429. PipelineManager/system_policy_defaults.py +279 -0
  430. PipelineManager/templates/components/pipeline_editor/diff_modal.html +127 -0
  431. PipelineManager/templates/components/pipeline_editor/expression_editor.html +160 -0
  432. PipelineManager/templates/components/pipeline_editor/plugin_config_modal.html +119 -0
  433. PipelineManager/templates/components/pipeline_editor/plugin_modal.html +1016 -0
  434. PipelineManager/templates/components/pipeline_editor/simulation_modal.html +394 -0
  435. PipelineManager/templates/components/pipeline_editor/simulation_results.html +123 -0
  436. PipelineManager/templates/components/pipeline_editor/stats_strip.html +123 -0
  437. PipelineManager/templates/components/pipeline_editor/view_code_modal.html +133 -0
  438. PipelineManager/templates/components/pipeline_manager/agent_inspect_content.html +805 -0
  439. PipelineManager/templates/components/pipeline_manager/agent_inspect_modal.html +40 -0
  440. PipelineManager/templates/components/pipeline_manager/agent_policies.html +2421 -0
  441. PipelineManager/templates/components/pipeline_manager/change_policy_modal.html +210 -0
  442. PipelineManager/templates/components/pipeline_manager/collapsible_row.html +11 -0
  443. PipelineManager/templates/components/pipeline_manager/connection_modal.html +1361 -0
  444. PipelineManager/templates/components/pipeline_manager/keystore_modal.html +269 -0
  445. PipelineManager/templates/components/pipeline_manager/logstashyml_guides/centralized_pipeline_management.html +291 -0
  446. PipelineManager/templates/components/pipeline_manager/logstashyml_guides/default.html +166 -0
  447. PipelineManager/templates/components/pipeline_manager/mcp_modal.html +241 -0
  448. PipelineManager/templates/components/pipeline_manager/pipeline_list_content.html +586 -0
  449. PipelineManager/templates/components/pipeline_manager/policy_deploy_modal.html +238 -0
  450. PipelineManager/templates/pipeline_editor.html +1738 -0
  451. PipelineManager/templates/pipeline_graph_editor.html +99 -0
  452. PipelineManager/templates/pipeline_manager.html +584 -0
  453. PipelineManager/templates/pipeline_text_editor.html +350 -0
  454. PipelineManager/urls.py +99 -0
  455. SNMP/__init__.py +0 -0
  456. SNMP/ai_template_generation.py +232 -0
  457. SNMP/apps.py +9 -0
  458. SNMP/assets/device_template_generation/agents/snmp-profile-author.json +15 -0
  459. SNMP/assets/device_template_generation/skills/snmp-catalog.json +9 -0
  460. SNMP/data/authoring_instructions.md +65 -0
  461. SNMP/data/grounding/.gitignore +4 -0
  462. SNMP/data/grounding/build_grounding.py +35 -0
  463. SNMP/data/grounding/grounding.json +1 -0
  464. SNMP/data/grounding/sample_agent_payload.cisco2960x.json +2184 -0
  465. SNMP/data/mib_reference/std_bgp4_mib.json +43 -0
  466. SNMP/data/mib_reference/std_entity_sensors.json +28 -0
  467. SNMP/data/mib_reference/std_host_resources.json +32 -0
  468. SNMP/data/mib_reference/std_ospf_mib.json +55 -0
  469. SNMP/data/mib_reference/std_ucd_linux.json +27 -0
  470. SNMP/data/normalizers.json +103 -0
  471. SNMP/data/official_device_templates/arista_eos.json +24 -0
  472. SNMP/data/official_device_templates/aruba_wireless_controller.json +23 -0
  473. SNMP/data/official_device_templates/brocade_fc_switch.json +20 -0
  474. SNMP/data/official_device_templates/cisco_ios.json +21 -0
  475. SNMP/data/official_device_templates/default.json +13 -0
  476. SNMP/data/official_device_templates/dell_idrac.json +22 -0
  477. SNMP/data/official_device_templates/dell_x1026.json +16 -0
  478. SNMP/data/official_device_templates/dlink_dgs1210_switch.json +19 -0
  479. SNMP/data/official_device_templates/eastpower_ups.json +20 -0
  480. SNMP/data/official_device_templates/eaton_ups.json +22 -0
  481. SNMP/data/official_device_templates/epson_printer.json +18 -0
  482. SNMP/data/official_device_templates/geist_watchdog.json +20 -0
  483. SNMP/data/official_device_templates/generic_linux.json +18 -0
  484. SNMP/data/official_device_templates/generic_ont.json +18 -0
  485. SNMP/data/official_device_templates/generic_ups.json +16 -0
  486. SNMP/data/official_device_templates/hp_laserjet_mfp_m281cdw.json +18 -0
  487. SNMP/data/official_device_templates/hpe_nimble.json +17 -0
  488. SNMP/data/official_device_templates/huawei_ups.json +19 -0
  489. SNMP/data/official_device_templates/ingrasys_ups.json +19 -0
  490. SNMP/data/official_device_templates/isilon_onefs.json +22 -0
  491. SNMP/data/official_device_templates/mellanox_sx6036.json +20 -0
  492. SNMP/data/official_device_templates/netapp_7mode.json +22 -0
  493. SNMP/data/official_device_templates/palo_alto_firewall.json +21 -0
  494. SNMP/data/official_device_templates/phoenixtec_ups.json +18 -0
  495. SNMP/data/official_device_templates/ubiquiti_unifi_ap.json +19 -0
  496. SNMP/data/official_device_templates/ubiquiti_unifi_switch.json +18 -0
  497. SNMP/data/official_device_templates/ubiquiti_unifi_udm.json +19 -0
  498. SNMP/data/official_device_templates/versa_flexvnf_appliance.json +19 -0
  499. SNMP/data/official_profiles/arista_eos.json +16 -0
  500. SNMP/data/official_profiles/aruba_wireless_controller.json +145 -0
  501. SNMP/data/official_profiles/brocade_fibre_channel_switch_fibre_channel_ports.json +35 -0
  502. SNMP/data/official_profiles/brocade_fibre_channel_switch_name_server.json +23 -0
  503. SNMP/data/official_profiles/brocade_fibre_channel_switch_system_metrics.json +36 -0
  504. SNMP/data/official_profiles/cisco_cdp.json +26 -0
  505. SNMP/data/official_profiles/cisco_fans.json +18 -0
  506. SNMP/data/official_profiles/cisco_sensors.json +21 -0
  507. SNMP/data/official_profiles/cisco_system_metrics.json +40 -0
  508. SNMP/data/official_profiles/dell_idrac_cpu.json +19 -0
  509. SNMP/data/official_profiles/dell_idrac_fans.json +20 -0
  510. SNMP/data/official_profiles/dell_idrac_global_status.json +13 -0
  511. SNMP/data/official_profiles/dell_idrac_memory.json +20 -0
  512. SNMP/data/official_profiles/dell_idrac_power_supply.json +19 -0
  513. SNMP/data/official_profiles/dell_idrac_raid_controller.json +19 -0
  514. SNMP/data/official_profiles/dlink_dgs1210.json +15 -0
  515. SNMP/data/official_profiles/dlink_dgs1210_system_metrics.json +38 -0
  516. SNMP/data/official_profiles/eaton_ups.json +40 -0
  517. SNMP/data/official_profiles/geist_environment.json +50 -0
  518. SNMP/data/official_profiles/generic_arp.json +19 -0
  519. SNMP/data/official_profiles/generic_bgp.json +24 -0
  520. SNMP/data/official_profiles/generic_entity_psu.json +26 -0
  521. SNMP/data/official_profiles/generic_entity_sensor.json +22 -0
  522. SNMP/data/official_profiles/generic_host_system_metrics.json +68 -0
  523. SNMP/data/official_profiles/generic_interfaces.json +86 -0
  524. SNMP/data/official_profiles/generic_ip_addr.json +19 -0
  525. SNMP/data/official_profiles/generic_lldp.json +54 -0
  526. SNMP/data/official_profiles/generic_lm_sensors.json +37 -0
  527. SNMP/data/official_profiles/generic_mac_table.json +19 -0
  528. SNMP/data/official_profiles/generic_ont.json +88 -0
  529. SNMP/data/official_profiles/generic_ospf.json +21 -0
  530. SNMP/data/official_profiles/generic_printer_mib.json +48 -0
  531. SNMP/data/official_profiles/generic_rmon.json +38 -0
  532. SNMP/data/official_profiles/generic_system.json +17 -0
  533. SNMP/data/official_profiles/generic_ucd_system_metrics.json +63 -0
  534. SNMP/data/official_profiles/generic_ups_mib.json +154 -0
  535. SNMP/data/official_profiles/hpe_nimble_volumes.json +59 -0
  536. SNMP/data/official_profiles/huawei_ups.json +111 -0
  537. SNMP/data/official_profiles/isilon_performance.json +92 -0
  538. SNMP/data/official_profiles/isilon_protocols.json +77 -0
  539. SNMP/data/official_profiles/isilon_system.json +86 -0
  540. SNMP/data/official_profiles/mellanox_mlnx_os.json +15 -0
  541. SNMP/data/official_profiles/netapp_7mode_data_protection.json +106 -0
  542. SNMP/data/official_profiles/netapp_7mode_disks.json +51 -0
  543. SNMP/data/official_profiles/netapp_7mode_protocols.json +66 -0
  544. SNMP/data/official_profiles/netapp_7mode_system.json +92 -0
  545. SNMP/data/official_profiles/netapp_7mode_volumes.json +166 -0
  546. SNMP/data/official_profiles/paloalto_components.json +36 -0
  547. SNMP/data/official_profiles/paloalto_system.json +15 -0
  548. SNMP/data/official_profiles/traps.json +16 -0
  549. SNMP/data/official_profiles/ubiquiti_unifi_switch.json +18 -0
  550. SNMP/data/official_profiles/ubiquiti_unifi_switch_system.json +14 -0
  551. SNMP/data/official_profiles/ubiquiti_unifi_wireless.json +60 -0
  552. SNMP/data/official_profiles/versa_flexvnf.json +14 -0
  553. SNMP/data/schema.md +650 -0
  554. SNMP/data/schema_reference/snmp_field_schema.md +747 -0
  555. SNMP/data/snmp_template.json +629 -0
  556. SNMP/data/template_profile_context.md +3986 -0
  557. SNMP/inline_grounding.py +77 -0
  558. SNMP/management/__init__.py +1 -0
  559. SNMP/management/commands/__init__.py +1 -0
  560. SNMP/management/commands/generate_template_profile_context.py +272 -0
  561. SNMP/management/commands/load_test_snmp_data.py +240 -0
  562. SNMP/management/commands/sync_snmp_official_data.py +263 -0
  563. SNMP/management/commands/unload_test_snmp_data.py +77 -0
  564. SNMP/migrations/0001_initial.py +101 -0
  565. SNMP/migrations/0002_devicetemplate.py +34 -0
  566. SNMP/migrations/0003_remove_devicetemplate_type_remove_profile_type_and_more.py +31 -0
  567. SNMP/migrations/0004_device_device_template.py +19 -0
  568. SNMP/migrations/0005_devicetemplate_product_profile_product.py +23 -0
  569. SNMP/migrations/0006_alter_devicetemplate_model_and_more.py +28 -0
  570. SNMP/migrations/0007_remove_device_profiles.py +17 -0
  571. SNMP/migrations/0008_devicetemplate_type.py +18 -0
  572. SNMP/migrations/0009_alter_device_device_template.py +19 -0
  573. SNMP/migrations/0010_alter_device_device_template.py +19 -0
  574. SNMP/migrations/0011_network_namespace.py +18 -0
  575. SNMP/migrations/0012_profile_normalizers.py +18 -0
  576. SNMP/migrations/0013_snmpdeploymentstate.py +26 -0
  577. SNMP/migrations/0014_alter_snmpdeploymentstate_last_config_change.py +18 -0
  578. SNMP/migrations/0015_alter_snmpdeploymentstate_last_config_change.py +20 -0
  579. SNMP/migrations/0016_alter_snmpdeploymentstate_last_config_change.py +18 -0
  580. SNMP/migrations/0017_remove_network_logstash_name.py +17 -0
  581. SNMP/migrations/0018_add_official_key.py +39 -0
  582. SNMP/migrations/0019_network_namespace_from_device_template.py +18 -0
  583. SNMP/migrations/0020_device_hostname_alter_device_ip_address_and_more.py +27 -0
  584. SNMP/migrations/0021_device_building_device_latitude_device_longitude_and_more.py +43 -0
  585. SNMP/migrations/0022_alter_device_latitude_alter_device_longitude.py +23 -0
  586. SNMP/migrations/0023_network_agent_connection_network_deployment_mode_and_more.py +30 -0
  587. SNMP/migrations/0024_network_credential_mode.py +18 -0
  588. SNMP/migrations/0025_network_ssl_certificate_authorities.py +18 -0
  589. SNMP/migrations/__init__.py +0 -0
  590. SNMP/models.py +892 -0
  591. SNMP/network_map.py +660 -0
  592. SNMP/overview.py +394 -0
  593. SNMP/snmp_crud.py +6082 -0
  594. SNMP/snmp_grounding.py +146 -0
  595. SNMP/snmp_normalizers.py +594 -0
  596. SNMP/snmp_pipeline_generator.py +1658 -0
  597. SNMP/snmp_test.py +962 -0
  598. SNMP/static/css/snmp.css +33 -0
  599. SNMP/static/images/apc.png +0 -0
  600. SNMP/static/images/arista.png +0 -0
  601. SNMP/static/images/aruba.png +0 -0
  602. SNMP/static/images/brocade.png +0 -0
  603. SNMP/static/images/cisco.png +0 -0
  604. SNMP/static/images/dell.png +0 -0
  605. SNMP/static/images/dlink.png +0 -0
  606. SNMP/static/images/east.png +0 -0
  607. SNMP/static/images/eaton.png +0 -0
  608. SNMP/static/images/epson.png +0 -0
  609. SNMP/static/images/hauwei.png +0 -0
  610. SNMP/static/images/hp.png +0 -0
  611. SNMP/static/images/hpe.png +0 -0
  612. SNMP/static/images/ingrasys.png +0 -0
  613. SNMP/static/images/linux.png +0 -0
  614. SNMP/static/images/mellanox.png +0 -0
  615. SNMP/static/images/netapp.png +0 -0
  616. SNMP/static/images/paloalto.png +0 -0
  617. SNMP/static/images/phoenixtec.png +0 -0
  618. SNMP/static/images/ubiquiti.png +0 -0
  619. SNMP/static/images/unknown.png +0 -0
  620. SNMP/static/images/versa.png +0 -0
  621. SNMP/static/images/vertiv.png +0 -0
  622. SNMP/static/js/ai_device_template_modal.js +1116 -0
  623. SNMP/static/js/credentials_table.js +291 -0
  624. SNMP/static/js/devices_table.js +588 -0
  625. SNMP/static/js/discovered_devices.js +291 -0
  626. SNMP/static/js/network_map.js +1657 -0
  627. SNMP/static/js/networks_table.js +360 -0
  628. SNMP/static/js/onboarding.js +866 -0
  629. SNMP/static/js/overview.js +416 -0
  630. SNMP/static/js/snmp_changes_indicator.js +76 -0
  631. SNMP/static/js/snmp_commit_modal.js +39 -0
  632. SNMP/static/js/snmp_credentials_modal.js +217 -0
  633. SNMP/static/js/snmp_device_template_modal.js +669 -0
  634. SNMP/static/js/snmp_device_visual_preview.js +1707 -0
  635. SNMP/static/js/snmp_devices_modal.js +912 -0
  636. SNMP/static/js/snmp_diff_modal.js +1559 -0
  637. SNMP/static/js/snmp_network_modal.js +940 -0
  638. SNMP/static/js/snmp_profile_modal.js +1212 -0
  639. SNMP/static/js/snmp_profile_modal_helpers.js +17 -0
  640. SNMP/static/js/snmp_test.js +538 -0
  641. SNMP/templates/Credentials.html +325 -0
  642. SNMP/templates/DeviceTemplates.html +1059 -0
  643. SNMP/templates/Devices.html +274 -0
  644. SNMP/templates/Networks.html +469 -0
  645. SNMP/templates/Onboarding.html +521 -0
  646. SNMP/templates/Overview.html +227 -0
  647. SNMP/templates/components/ai_device_template_modal.html +46 -0
  648. SNMP/templates/components/ai_generate_template_content.html +224 -0
  649. SNMP/templates/components/device_template_profile_modal.html +60 -0
  650. SNMP/templates/components/discovered_devices_content.html +86 -0
  651. SNMP/templates/components/discovered_devices_modal.html +43 -0
  652. SNMP/templates/components/gmaps_latlon_modal.html +93 -0
  653. SNMP/templates/components/network_map.html +110 -0
  654. SNMP/templates/components/snmp_commit_modal.html +53 -0
  655. SNMP/templates/components/snmp_credentials_modal.html +189 -0
  656. SNMP/templates/components/snmp_device_modal.html +6 -0
  657. SNMP/templates/components/snmp_device_template_modal.html +129 -0
  658. SNMP/templates/components/snmp_device_visual_preview.html +347 -0
  659. SNMP/templates/components/snmp_devices_modal.html +330 -0
  660. SNMP/templates/components/snmp_diff_modal.html +148 -0
  661. SNMP/templates/components/snmp_network_modal.html +380 -0
  662. SNMP/templates/components/snmp_profile_modal.html +147 -0
  663. SNMP/templates/components/snmp_test_modal.html +398 -0
  664. SNMP/templatetags/__init__.py +0 -0
  665. SNMP/templatetags/snmp_extras.py +17 -0
  666. SNMP/urls.py +94 -0
  667. SNMP/views.py +913 -0
  668. Site/__init__.py +0 -0
  669. Site/apps.py +9 -0
  670. Site/migrations/__init__.py +0 -0
  671. Site/product_ca_views.py +41 -0
  672. Site/static/images/ElasticIcon.png +0 -0
  673. Site/static/images/LoggyIcon.png +0 -0
  674. Site/static/images/LoggyWizardIcon.png +0 -0
  675. Site/static/images/LogstashAgentIcon.png +0 -0
  676. Site/static/images/LogstashIcon.png +0 -0
  677. Site/static/js/base.js +192 -0
  678. Site/static/js/marked.min.js +69 -0
  679. Site/templates/base.html +52 -0
  680. Site/templates/error.html +65 -0
  681. Site/templates/home.html +148 -0
  682. Site/templates/navigation.html +530 -0
  683. Site/templates/popup.html +251 -0
  684. Site/templatetags/__init__.py +0 -0
  685. Site/templatetags/custom_filters.py +36 -0
  686. Site/urls.py +21 -0
  687. Site/views.py +200 -0
  688. Utilities/__init__.py +0 -0
  689. Utilities/apps.py +9 -0
  690. Utilities/data/grok-patterns/LICENSE +202 -0
  691. Utilities/data/grok-patterns/ecs-v1/aws +33 -0
  692. Utilities/data/grok-patterns/ecs-v1/bacula +53 -0
  693. Utilities/data/grok-patterns/ecs-v1/bind +13 -0
  694. Utilities/data/grok-patterns/ecs-v1/bro +30 -0
  695. Utilities/data/grok-patterns/ecs-v1/exim +26 -0
  696. Utilities/data/grok-patterns/ecs-v1/firewalls +111 -0
  697. Utilities/data/grok-patterns/ecs-v1/grok-patterns +95 -0
  698. Utilities/data/grok-patterns/ecs-v1/haproxy +40 -0
  699. Utilities/data/grok-patterns/ecs-v1/httpd +17 -0
  700. Utilities/data/grok-patterns/ecs-v1/java +34 -0
  701. Utilities/data/grok-patterns/ecs-v1/junos +13 -0
  702. Utilities/data/grok-patterns/ecs-v1/linux-syslog +16 -0
  703. Utilities/data/grok-patterns/ecs-v1/maven +1 -0
  704. Utilities/data/grok-patterns/ecs-v1/mcollective +4 -0
  705. Utilities/data/grok-patterns/ecs-v1/mongodb +7 -0
  706. Utilities/data/grok-patterns/ecs-v1/nagios +124 -0
  707. Utilities/data/grok-patterns/ecs-v1/postgresql +2 -0
  708. Utilities/data/grok-patterns/ecs-v1/rails +13 -0
  709. Utilities/data/grok-patterns/ecs-v1/redis +3 -0
  710. Utilities/data/grok-patterns/ecs-v1/ruby +2 -0
  711. Utilities/data/grok-patterns/ecs-v1/squid +6 -0
  712. Utilities/data/grok-patterns/ecs-v1/zeek +33 -0
  713. Utilities/data/grok-patterns/legacy/aws +14 -0
  714. Utilities/data/grok-patterns/legacy/bacula +50 -0
  715. Utilities/data/grok-patterns/legacy/bind +3 -0
  716. Utilities/data/grok-patterns/legacy/bro +13 -0
  717. Utilities/data/grok-patterns/legacy/exim +19 -0
  718. Utilities/data/grok-patterns/legacy/firewalls +91 -0
  719. Utilities/data/grok-patterns/legacy/grok-patterns +95 -0
  720. Utilities/data/grok-patterns/legacy/haproxy +39 -0
  721. Utilities/data/grok-patterns/legacy/httpd +15 -0
  722. Utilities/data/grok-patterns/legacy/java +17 -0
  723. Utilities/data/grok-patterns/legacy/junos +9 -0
  724. Utilities/data/grok-patterns/legacy/linux-syslog +16 -0
  725. Utilities/data/grok-patterns/legacy/maven +1 -0
  726. Utilities/data/grok-patterns/legacy/mcollective +1 -0
  727. Utilities/data/grok-patterns/legacy/mcollective-patterns +4 -0
  728. Utilities/data/grok-patterns/legacy/mongodb +7 -0
  729. Utilities/data/grok-patterns/legacy/nagios +124 -0
  730. Utilities/data/grok-patterns/legacy/postgresql +3 -0
  731. Utilities/data/grok-patterns/legacy/rails +13 -0
  732. Utilities/data/grok-patterns/legacy/redis +3 -0
  733. Utilities/data/grok-patterns/legacy/ruby +2 -0
  734. Utilities/data/grok-patterns/legacy/squid +4 -0
  735. Utilities/dissect.py +302 -0
  736. Utilities/grok.py +412 -0
  737. Utilities/migrations/__init__.py +0 -0
  738. Utilities/static/css/debugger_editor.css +88 -0
  739. Utilities/static/js/debugger_editor.js +93 -0
  740. Utilities/static/js/grok_debugger.js +131 -0
  741. Utilities/templates/dissect_debugger.html +95 -0
  742. Utilities/templates/grok_debugger.html +99 -0
  743. Utilities/urls.py +14 -0
  744. Utilities/views.py +363 -0
  745. logstashui-0.5.5.dev0.dist-info/METADATA +333 -0
  746. logstashui-0.5.5.dev0.dist-info/RECORD +762 -0
  747. logstashui-0.5.5.dev0.dist-info/WHEEL +4 -0
  748. logstashui-0.5.5.dev0.dist-info/entry_points.txt +2 -0
  749. logstashui-0.5.5.dev0.dist-info/licenses/LICENSE.txt +93 -0
  750. logstashui-0.5.5.dev0.dist-info/licenses/NOTICE.txt +2772 -0
  751. theme/__init__.py +0 -0
  752. theme/apps.py +9 -0
  753. theme/package-lock.json +6 -0
  754. theme/static/css/dist/styles.css +2 -0
  755. theme/static/images/favicon.ico +0 -0
  756. theme/static_src/.gitignore +1 -0
  757. theme/static_src/package-lock.json +1930 -0
  758. theme/static_src/package.json +26 -0
  759. theme/static_src/postcss.config.js +7 -0
  760. theme/static_src/src/styles.css +38 -0
  761. theme/static_src/tailwind.config.js +43 -0
  762. theme/templates/base.html +32 -0
@@ -0,0 +1,1657 @@
1
+ /*
2
+ * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3
+ * or more contributor license agreements. Licensed under the Elastic License;
4
+ * you may not use this file except in compliance with the Elastic License.
5
+ */
6
+
7
+ // ─────────────────────────────────────────────────────────────────────────────
8
+ // Module-level state
9
+ // ─────────────────────────────────────────────────────────────────────────────
10
+
11
+ let networkMapZoomBehavior = null;
12
+ let currentNetworkTransform = null;
13
+ let networkTopologyData = null; // full adjacency_table from last API response
14
+ let networkMapIsDragging = false;
15
+
16
+ // Active force simulation (stopped before each re-render so stale 'end' events
17
+ // can't trigger a fit), and auto-fit guards. The graph auto-fits at most once
18
+ // per render, and never after the user has zoomed, panned, or dragged.
19
+ let networkMapSimulation = null;
20
+ let _nmUserInteracted = false;
21
+ let _nmInitialFitDone = false;
22
+
23
+ // Network filter state — set of selected network IDs (integers); empty = show all
24
+ let _selectedNetworkIds = new Set();
25
+ // All available networks fetched from GetNetworksList
26
+ let _availableNetworks = [];
27
+
28
+ // Color scale shared between hulls and pills — assigned lazily per network label
29
+ const _networkColorScale = d3.scaleOrdinal([
30
+ '#3b82f6', '#10b981', '#f59e0b', '#ef4444', '#8b5cf6',
31
+ '#ec4899', '#06b6d4', '#84cc16', '#f97316', '#6366f1',
32
+ ]);
33
+ const _networkColorCache = {};
34
+
35
+ function networkColor(networkLabel) {
36
+ if (!_networkColorCache[networkLabel]) {
37
+ _networkColorCache[networkLabel] = _networkColorScale(networkLabel);
38
+ }
39
+ return _networkColorCache[networkLabel];
40
+ }
41
+
42
+ // Scale guardrail threshold
43
+ const NODE_WARN_THRESHOLD = 40;
44
+
45
+ // Fullscreen state
46
+ let _nmFullscreen = false;
47
+
48
+ // ─────────────────────────────────────────────────────────────────────────────
49
+ // Bootstrap — called once from inline <script> in network_map.html
50
+ // ─────────────────────────────────────────────────────────────────────────────
51
+
52
+ /**
53
+ * Entry point: load network list and map data in parallel so neither blocks
54
+ * the other. The networks list feeds the filter dropdown; the map data renders
55
+ * the topology. Both use the Django DB — no Elasticsearch involved here.
56
+ */
57
+ function initNetworkMap() {
58
+ Promise.all([
59
+ fetch('/SNMP/GetNetworksList/').then(r => r.json()).catch(() => ({ networks: [] })),
60
+ fetch('/SNMP/GetNetworkMapData/').then(r => r.json()).catch(() => null),
61
+ ]).then(([listData, mapData]) => {
62
+ _availableNetworks = listData.networks || [];
63
+ _buildFilterDropdown(_availableNetworks);
64
+
65
+ // Auto-select the network with the most devices; re-fetch scoped to it.
66
+ // The initial parallel fetch was unfiltered — we discard it and re-fetch
67
+ // so the map always opens on the most relevant network.
68
+ const defaultIds = _autoSelectDefaultNetwork(_availableNetworks);
69
+ if (defaultIds.length > 0) {
70
+ fetchNetworkMapData(defaultIds);
71
+ } else {
72
+ handleNetworkMapData(mapData || { success: false, graph: { nodes: [], edges: [] } });
73
+ }
74
+ });
75
+ }
76
+
77
+ // ─────────────────────────────────────────────────────────────────────────────
78
+ // Network filter dropdown (multiselect, auto-apply on checkbox change)
79
+ // ─────────────────────────────────────────────────────────────────────────────
80
+
81
+ let _nmFilterDebounce = null;
82
+
83
+ /**
84
+ * Pre-check the network with the most devices and return its ID in an array.
85
+ * Updates the checkbox and trigger label so the UI reflects the selection.
86
+ * Returns [] if no networks or all have 0 devices.
87
+ */
88
+ function _autoSelectDefaultNetwork(networks) {
89
+ if (!networks || networks.length === 0) return [];
90
+ const best = networks.reduce((a, b) => (b.device_count > a.device_count ? b : a), networks[0]);
91
+ if (!best || best.device_count === 0) return [];
92
+
93
+ _selectedNetworkIds.add(best.id);
94
+ // Tick the checkbox (it may not be in the DOM yet if the pill list is empty,
95
+ // but _buildFilterDropdown runs before this, so it should exist)
96
+ const cb = document.getElementById(`nmnet-${best.id}`);
97
+ if (cb) cb.checked = true;
98
+ _updateNmFilterLabel();
99
+ return [best.id];
100
+ }
101
+
102
+ function _buildFilterDropdown(networks) {
103
+ const optionsEl = document.getElementById('nmFilterOptions');
104
+ if (!optionsEl) return;
105
+
106
+ if (networks.length === 0) {
107
+ optionsEl.innerHTML = '<p class="px-3 py-2 text-xs text-gray-500 italic">No networks configured</p>';
108
+ return;
109
+ }
110
+
111
+ optionsEl.innerHTML = networks.map(net => {
112
+ const label = `${net.name} <span class="text-gray-500 font-mono text-xs">${net.network_range}</span>`;
113
+ return `
114
+ <label class="nm-filter-option">
115
+ <input type="checkbox" id="nmnet-${net.id}" value="${net.id}"
116
+ onchange="_onNmFilterChange()">
117
+ <span class="text-sm text-white leading-tight">${label}</span>
118
+ </label>`;
119
+ }).join('');
120
+ }
121
+
122
+ /** Called whenever any network checkbox is toggled — debounced 250ms. */
123
+ function _onNmFilterChange() {
124
+ clearTimeout(_nmFilterDebounce);
125
+ _nmFilterDebounce = setTimeout(() => {
126
+ // Rebuild selected set from checkboxes
127
+ _selectedNetworkIds.clear();
128
+ document.querySelectorAll('#nmFilterOptions input[type="checkbox"]:checked')
129
+ .forEach(cb => _selectedNetworkIds.add(parseInt(cb.value)));
130
+
131
+ // Update trigger label
132
+ _updateNmFilterLabel();
133
+
134
+ // Nothing selected → show empty state immediately, no round-trip needed
135
+ if (_selectedNetworkIds.size === 0) {
136
+ _showMapEmptyState();
137
+ return;
138
+ }
139
+
140
+ // Re-fetch and redraw
141
+ fetchNetworkMapData([..._selectedNetworkIds]);
142
+ }, 250);
143
+ }
144
+
145
+ function _updateNmFilterLabel() {
146
+ const label = document.getElementById('nmFilterLabel');
147
+ if (!label) return;
148
+ const count = _selectedNetworkIds.size;
149
+ if (count === 0) {
150
+ label.textContent = 'All networks';
151
+ label.classList.add('text-gray-400');
152
+ label.classList.remove('text-white');
153
+ } else if (count === 1) {
154
+ const id = [..._selectedNetworkIds][0];
155
+ const net = _availableNetworks.find(n => n.id === id);
156
+ label.textContent = net ? net.name : `${count} selected`;
157
+ label.classList.add('text-white');
158
+ label.classList.remove('text-gray-400');
159
+ } else {
160
+ label.textContent = `${count} networks`;
161
+ label.classList.add('text-white');
162
+ label.classList.remove('text-gray-400');
163
+ }
164
+ }
165
+
166
+ function toggleNmFilterDropdown(event) {
167
+ event.stopPropagation();
168
+ const dd = document.getElementById('nmFilterDropdown');
169
+ if (!dd) return;
170
+ dd.classList.toggle('hidden');
171
+ if (!dd.classList.contains('hidden')) {
172
+ // Focus search on open
173
+ const search = document.getElementById('nmFilterSearch');
174
+ if (search) { search.value = ''; filterNmDropdownOptions(''); search.focus(); }
175
+ }
176
+ }
177
+
178
+ function filterNmDropdownOptions(query) {
179
+ const q = query.trim().toLowerCase();
180
+ document.querySelectorAll('.nm-filter-option').forEach(opt => {
181
+ const text = opt.textContent.toLowerCase();
182
+ opt.style.display = (!q || text.includes(q)) ? '' : 'none';
183
+ });
184
+ }
185
+
186
+ // Close dropdown when clicking outside
187
+ document.addEventListener('click', function(e) {
188
+ const wrapper = document.getElementById('nmFilterWrapper');
189
+ if (wrapper && !wrapper.contains(e.target)) {
190
+ const dd = document.getElementById('nmFilterDropdown');
191
+ if (dd) dd.classList.add('hidden');
192
+ }
193
+ });
194
+
195
+ // ─────────────────────────────────────────────────────────────────────────────
196
+ // Data fetch
197
+ // ─────────────────────────────────────────────────────────────────────────────
198
+
199
+ // True once the map container has been shown at least once — subsequent fetches
200
+ // keep the container visible and use a lightweight overlay instead of swapping
201
+ // the whole card between loading/container/empty states.
202
+ let _mapInitialized = false;
203
+
204
+ /**
205
+ * Fetch network map data, optionally scoped to a list of network IDs.
206
+ */
207
+ function fetchNetworkMapData(networkIds) {
208
+ const loadingEl = document.getElementById('networkMapLoading');
209
+ const containerEl = document.getElementById('networkMapContainer');
210
+ const emptyEl = document.getElementById('networkMapEmpty');
211
+
212
+ if (!_mapInitialized) {
213
+ // Initial load: use the full loading state so the card doesn't jump
214
+ if (loadingEl) loadingEl.classList.remove('hidden');
215
+ if (containerEl) containerEl.classList.add('hidden');
216
+ if (emptyEl) emptyEl.classList.add('hidden');
217
+ } else {
218
+ // Subsequent filter changes: keep the canvas visible, show a thin overlay
219
+ _setMapRefreshing(true);
220
+ }
221
+
222
+ let url = '/SNMP/GetNetworkMapData/';
223
+ if (networkIds && networkIds.length > 0) {
224
+ const params = networkIds.map(id => `networks=${encodeURIComponent(id)}`).join('&');
225
+ url += '?' + params;
226
+ }
227
+
228
+ fetch(url)
229
+ .then(r => r.json())
230
+ .then(data => handleNetworkMapData(data))
231
+ .catch(err => {
232
+ console.error('Error fetching network map data:', err);
233
+ _setMapRefreshing(false);
234
+ if (!_mapInitialized) {
235
+ if (loadingEl) loadingEl.classList.add('hidden');
236
+ if (emptyEl) emptyEl.classList.remove('hidden');
237
+ } else {
238
+ _renderEmptyInsideCanvas('Failed to load topology data');
239
+ }
240
+ });
241
+ }
242
+
243
+ // ─────────────────────────────────────────────────────────────────────────────
244
+ // Data handler
245
+ // ─────────────────────────────────────────────────────────────────────────────
246
+
247
+ function handleNetworkMapData(data) {
248
+ const loadingEl = document.getElementById('networkMapLoading');
249
+ const containerEl = document.getElementById('networkMapContainer');
250
+ const emptyEl = document.getElementById('networkMapEmpty');
251
+
252
+ _setMapRefreshing(false);
253
+
254
+ if (data.success && data.graph && data.graph.nodes && data.graph.nodes.length > 0) {
255
+ networkTopologyData = data.adjacency_table;
256
+
257
+ if (!_mapInitialized) {
258
+ // First successful render: transition from loading state to canvas
259
+ if (loadingEl) loadingEl.classList.add('hidden');
260
+ if (emptyEl) emptyEl.classList.add('hidden');
261
+ if (containerEl) containerEl.classList.remove('hidden');
262
+ _mapInitialized = true;
263
+ }
264
+ // Always re-render (filter changes re-use the already-visible container)
265
+ renderNetworkMap(data.graph);
266
+ } else {
267
+ if (data.errors && data.errors.length > 0) {
268
+ console.warn('Errors fetching network map data:', data.errors);
269
+ }
270
+ if (!_mapInitialized) {
271
+ // Never shown the canvas — use the dedicated empty state outside it
272
+ if (loadingEl) loadingEl.classList.add('hidden');
273
+ if (emptyEl) emptyEl.classList.remove('hidden');
274
+ } else {
275
+ // Canvas is visible — render the empty message inside the SVG
276
+ _renderEmptyInsideCanvas('No topology data for the selected networks');
277
+ }
278
+ }
279
+ }
280
+
281
+ /**
282
+ * Show/hide a semi-transparent refresh overlay on top of the existing canvas.
283
+ * This lets filter changes feel instant without collapsing the card.
284
+ */
285
+ function _setMapRefreshing(on) {
286
+ const containerEl = document.getElementById('networkMapContainer');
287
+ if (!containerEl) return;
288
+ let overlay = document.getElementById('nmRefreshOverlay');
289
+ if (on) {
290
+ if (!overlay) {
291
+ overlay = document.createElement('div');
292
+ overlay.id = 'nmRefreshOverlay';
293
+ overlay.className = 'absolute inset-0 flex items-center justify-center bg-gray-900/50 rounded-lg z-40 pointer-events-none';
294
+ overlay.innerHTML = `
295
+ <div class="flex items-center gap-2 text-gray-300 text-sm bg-gray-800/80 px-4 py-2 rounded-lg border border-gray-700">
296
+ <div class="animate-spin rounded-full h-4 w-4 border-b-2 border-blue-400"></div>
297
+ Updating…
298
+ </div>`;
299
+ // Insert relative to the SVG wrapper so it sits over the canvas
300
+ const wrapper = document.getElementById('nmSvgWrapper');
301
+ if (wrapper) {
302
+ wrapper.style.position = 'relative';
303
+ wrapper.appendChild(overlay);
304
+ } else {
305
+ containerEl.appendChild(overlay);
306
+ }
307
+ }
308
+ } else {
309
+ if (overlay) overlay.remove();
310
+ }
311
+ }
312
+
313
+ /**
314
+ * Replace the SVG content with a plain empty-state message while keeping
315
+ * the container (and its fixed height) fully visible.
316
+ */
317
+ function _renderEmptyInsideCanvas(message) {
318
+ networkTopologyData = null;
319
+ const containerEl = document.getElementById('networkMapContainer');
320
+ if (!containerEl) return;
321
+ const wrapperHeight = _nmFullscreen ? 'calc(100vh - 56px)' : '600px';
322
+ containerEl.innerHTML = `
323
+ <div class="flex flex-col items-center justify-center w-full rounded-lg bg-gray-900"
324
+ style="height:${wrapperHeight};">
325
+ <div class="inline-flex items-center justify-center w-14 h-14 bg-gray-700/50 rounded-full mb-4">
326
+ <svg class="w-7 h-7 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24">
327
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
328
+ d="M9 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 00-.553-.894L15 4m0 13V4m0 0L9 7"/>
329
+ </svg>
330
+ </div>
331
+ <p class="text-gray-400 text-sm">${escapeHtml(message)}</p>
332
+ </div>`;
333
+ }
334
+
335
+ /**
336
+ * Show the empty state — used when the user de-selects all networks without
337
+ * making any API call. Keeps the canvas visible if already initialized.
338
+ */
339
+ function _showMapEmptyState() {
340
+ networkTopologyData = null;
341
+ if (_mapInitialized) {
342
+ _renderEmptyInsideCanvas('Select at least one network to view the topology');
343
+ } else {
344
+ const loadingEl = document.getElementById('networkMapLoading');
345
+ const containerEl = document.getElementById('networkMapContainer');
346
+ const emptyEl = document.getElementById('networkMapEmpty');
347
+ if (loadingEl) loadingEl.classList.add('hidden');
348
+ if (containerEl) containerEl.classList.add('hidden');
349
+ if (emptyEl) emptyEl.classList.remove('hidden');
350
+ }
351
+ }
352
+
353
+ // ─────────────────────────────────────────────────────────────────────────────
354
+ // D3 Rendering
355
+ // ─────────────────────────────────────────────────────────────────────────────
356
+
357
+ function renderNetworkMap(graphData) {
358
+ const containerElement = document.getElementById('networkMapContainer');
359
+ const nodeCount = graphData.nodes.length;
360
+
361
+ // Build inner HTML — scale guardrail banner shown when over threshold
362
+ const warnBanner = nodeCount > NODE_WARN_THRESHOLD ? `
363
+ <div id="nmWarnBanner" class="mx-4 mt-3 px-4 py-2 bg-yellow-900/30 border border-yellow-600/40 rounded-lg flex items-center justify-between gap-3">
364
+ <div class="flex items-center gap-2 text-yellow-300 text-sm">
365
+ <svg class="w-4 h-4 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
366
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
367
+ d="M12 9v2m0 4h.01M10.29 3.86L1.82 18a2 2 0 001.71 3h16.94a2 2 0 001.71-3L13.71 3.86a2 2 0 00-3.42 0z"/>
368
+ </svg>
369
+ Large topology (${nodeCount} nodes). Use the network filter above to focus your view.
370
+ </div>
371
+ <button onclick="document.getElementById('nmWarnBanner').remove()"
372
+ class="text-yellow-400 hover:text-yellow-200 shrink-0">
373
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
374
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
375
+ </svg>
376
+ </button>
377
+ </div>` : '';
378
+
379
+ // In fullscreen the SVG wrapper should fill the card body, not a fixed 600px
380
+ const svgWrapperHeight = _nmFullscreen ? 'calc(100vh - 56px)' : '600px';
381
+
382
+ containerElement.innerHTML = `
383
+ ${warnBanner}
384
+ <div class="relative w-full mt-2" id="nmSvgWrapper" style="height: ${svgWrapperHeight};">
385
+ <svg id="networkMapSvg" class="w-full h-full bg-gray-900 rounded-lg">
386
+ <g id="networkMapGroup"></g>
387
+ </svg>
388
+ <div id="networkMapTooltip"
389
+ class="absolute hidden bg-gray-800 border border-gray-600 rounded-lg px-3 py-2 text-sm text-white shadow-lg pointer-events-none z-50"
390
+ style="max-width: 300px;">
391
+ <div id="tooltipContent"></div>
392
+ </div>
393
+ <div class="absolute top-4 right-4 flex gap-2">
394
+ <button onclick="showAdjacencyData()"
395
+ class="px-3 py-2 bg-blue-700 hover:bg-blue-600 text-white rounded-lg text-sm flex items-center gap-2">
396
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
397
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
398
+ d="M10 20l4-16m4 4l4 4-4 4M6 16l-4-4 4-4"/>
399
+ </svg>
400
+ Show JSON
401
+ </button>
402
+ <button onclick="resetNetworkMapZoom()"
403
+ class="px-3 py-2 bg-gray-700 hover:bg-gray-600 text-white rounded-lg text-sm">
404
+ Reset View
405
+ </button>
406
+ <button id="nmFullscreenBtn" onclick="toggleNetworkMapFullscreen()"
407
+ class="p-2 bg-gray-700 hover:bg-gray-600 text-white rounded-lg transition-colors"
408
+ title="Toggle fullscreen">
409
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
410
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
411
+ d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"/>
412
+ </svg>
413
+ </button>
414
+ </div>
415
+ </div>
416
+ `;
417
+
418
+ // New render: stop any previous simulation and re-arm the one-time auto-fit
419
+ if (networkMapSimulation) networkMapSimulation.stop();
420
+ networkMapSimulation = null;
421
+ _nmUserInteracted = false;
422
+ _nmInitialFitDone = false;
423
+
424
+ const svg = document.getElementById('networkMapSvg');
425
+ const svgRect = svg.getBoundingClientRect();
426
+ const width = svgRect.width;
427
+ const height = svgRect.height;
428
+
429
+ initializeNetworkMapZoom(svg, nodeCount);
430
+
431
+ if (!graphData.nodes.length) {
432
+ d3.select('#networkMapGroup')
433
+ .append('text')
434
+ .attr('text-anchor', 'middle')
435
+ .attr('fill', '#9ca3af')
436
+ .attr('font-size', '16px')
437
+ .text('No network topology data available');
438
+ return;
439
+ }
440
+
441
+ // Dynamic force distances — spread more with more nodes
442
+ const linkDistance = Math.max(100, Math.min(200, 3000 / nodeCount));
443
+ const chargeStr = Math.max(-600, Math.min(-200, -15000 / nodeCount));
444
+
445
+ const simulation = d3.forceSimulation(graphData.nodes)
446
+ .force('link', d3.forceLink(graphData.edges).id(d => d.id).distance(linkDistance))
447
+ .force('charge', d3.forceManyBody().strength(chargeStr))
448
+ .force('center', d3.forceCenter(0, 0))
449
+ .force('collision', d3.forceCollide().radius(55));
450
+ networkMapSimulation = simulation;
451
+
452
+ const g = d3.select('#networkMapGroup');
453
+
454
+ // ── Hull layer (drawn first so nodes/edges sit on top) ──
455
+ const hullGroup = g.append('g').attr('class', 'network-hulls');
456
+
457
+ // ── Edge layer ──
458
+ const tooltip = document.getElementById('networkMapTooltip');
459
+ const tooltipContent = document.getElementById('tooltipContent');
460
+
461
+ const link = g.append('g')
462
+ .attr('class', 'links')
463
+ .selectAll('line')
464
+ .data(graphData.edges)
465
+ .enter()
466
+ .append('line')
467
+ .attr('stroke', '#6b7280')
468
+ .attr('stroke-width', 2)
469
+ .style('cursor', 'pointer')
470
+ .on('mouseenter', function(event, d) {
471
+ d3.select(this).attr('stroke', '#60a5fa').attr('stroke-width', 3);
472
+ const src = d.source.id || d.source;
473
+ const tgt = d.target.id || d.target;
474
+ tooltipContent.innerHTML = `
475
+ <div class="font-semibold mb-1">Connection</div>
476
+ <div class="text-gray-300 mb-2">
477
+ <div>${escapeHtml(src)}</div>
478
+ <div class="text-xs text-gray-400 ml-2">└─ ${escapeHtml(d.source_interface)}</div>
479
+ <div class="text-center text-blue-400 my-1">↕</div>
480
+ <div>${escapeHtml(tgt)}</div>
481
+ <div class="text-xs text-gray-400 ml-2">└─ ${escapeHtml(d.target_interface)}</div>
482
+ </div>
483
+ <div class="text-xs text-gray-500 border-t border-gray-600 pt-1">Click for details</div>
484
+ ${d.platform ? `<div class="text-xs text-gray-400 mt-1">Platform: ${escapeHtml(d.platform)}</div>` : ''}
485
+ `;
486
+ tooltip.classList.remove('hidden');
487
+ })
488
+ .on('mousemove', function(event) {
489
+ const cr = containerElement.getBoundingClientRect();
490
+ tooltip.style.left = (event.clientX - cr.left + 15) + 'px';
491
+ tooltip.style.top = (event.clientY - cr.top + 15) + 'px';
492
+ })
493
+ .on('mouseleave', function() {
494
+ d3.select(this).attr('stroke', '#6b7280').attr('stroke-width', 2);
495
+ tooltip.classList.add('hidden');
496
+ })
497
+ .on('click', function(event, d) {
498
+ event.stopPropagation();
499
+ tooltip.classList.add('hidden');
500
+ showEdgeDetail(d);
501
+ });
502
+
503
+ // ── Node layer ──
504
+ const node = g.append('g')
505
+ .attr('class', 'nodes')
506
+ .selectAll('g')
507
+ .data(graphData.nodes)
508
+ .enter()
509
+ .append('g')
510
+ .call(d3.drag()
511
+ .on('start', dragStarted)
512
+ .on('drag', dragged)
513
+ .on('end', dragEnded));
514
+
515
+ node.append('circle')
516
+ .attr('r', 20)
517
+ .attr('fill', d => d.managed ? '#3b82f6' : '#6b7280')
518
+ .attr('stroke', d => d.managed ? '#60a5fa' : '#9ca3af')
519
+ .attr('stroke-width', 2)
520
+ .attr('stroke-dasharray', d => d.managed ? '0' : '5,5')
521
+ .style('cursor', d => d.managed ? 'pointer' : 'default');
522
+
523
+ node.append('text')
524
+ .attr('text-anchor', 'middle')
525
+ .attr('dy', '0.35em')
526
+ .attr('font-size', '20px')
527
+ .attr('fill', '#ffffff')
528
+ .attr('pointer-events', 'none')
529
+ .text('🖧');
530
+
531
+ node.append('text')
532
+ .attr('text-anchor', 'middle')
533
+ .attr('dy', '35px')
534
+ .attr('font-size', '12px')
535
+ .attr('fill', '#e5e7eb')
536
+ .attr('pointer-events', 'none')
537
+ .text(d => d.id);
538
+
539
+ node.append('circle')
540
+ .attr('cx', 15).attr('cy', -15).attr('r', 10)
541
+ .attr('fill', '#10b981').attr('stroke', '#059669').attr('stroke-width', 1);
542
+
543
+ node.append('text')
544
+ .attr('x', 15).attr('y', -15)
545
+ .attr('text-anchor', 'middle').attr('dy', '0.35em')
546
+ .attr('font-size', '10px').attr('fill', '#ffffff').attr('font-weight', 'bold')
547
+ .attr('pointer-events', 'none')
548
+ .text(d => d.interface_count);
549
+
550
+ node
551
+ .on('mouseenter', function(event, d) {
552
+ const badge = d.managed
553
+ ? '<span class="inline-block px-2 py-0.5 bg-blue-600 text-white text-xs rounded">Managed</span>'
554
+ : '<span class="inline-block px-2 py-0.5 bg-gray-600 text-white text-xs rounded">Discovered</span>';
555
+ tooltipContent.innerHTML = `
556
+ <div class="font-semibold mb-1">${escapeHtml(d.id)}</div>
557
+ <div class="mb-2">${badge}</div>
558
+ <div class="text-xs text-gray-400">
559
+ <div>Network: ${escapeHtml(d.network)}</div>
560
+ <div>Adjacencies: ${d.interface_count}</div>
561
+ </div>
562
+ ${d.managed ? '<div class="text-xs text-gray-500 border-t border-gray-600 pt-1 mt-1">Click to inspect</div>' : ''}
563
+ `;
564
+ tooltip.classList.remove('hidden');
565
+ })
566
+ .on('mousemove', function(event) {
567
+ const cr = containerElement.getBoundingClientRect();
568
+ tooltip.style.left = (event.clientX - cr.left + 15) + 'px';
569
+ tooltip.style.top = (event.clientY - cr.top + 15) + 'px';
570
+ })
571
+ .on('mouseleave', function() {
572
+ tooltip.classList.add('hidden');
573
+ });
574
+
575
+ // ── Simulation tick ──
576
+ simulation.on('tick', () => {
577
+ link
578
+ .attr('x1', d => d.source.x).attr('y1', d => d.source.y)
579
+ .attr('x2', d => d.target.x).attr('y2', d => d.target.y);
580
+ node.attr('transform', d => `translate(${d.x},${d.y})`);
581
+ _drawNetworkHulls(hullGroup, graphData.nodes);
582
+ });
583
+
584
+ // Auto-fit once, the first time the simulation settles. Later restarts
585
+ // (e.g. from clicking/dragging a node) and user zoom/pan must not re-fit.
586
+ simulation.on('end', () => {
587
+ if (_nmInitialFitDone) return;
588
+ _nmInitialFitDone = true;
589
+ if (_nmUserInteracted) return;
590
+ _fitGraphToView(svg, graphData.nodes);
591
+ });
592
+
593
+ // ── Drag helpers ──
594
+ function dragStarted(event, d) {
595
+ networkMapIsDragging = false;
596
+ _nmUserInteracted = true;
597
+ if (!event.active) simulation.alphaTarget(0.3).restart();
598
+ d.fx = d.x; d.fy = d.y;
599
+ }
600
+ function dragged(event, d) {
601
+ networkMapIsDragging = true;
602
+ d.fx = event.x; d.fy = event.y;
603
+ }
604
+ function dragEnded(event, d) {
605
+ if (!event.active) simulation.alphaTarget(0);
606
+ d.fx = null; d.fy = null;
607
+ if (!networkMapIsDragging && d.managed) {
608
+ showNodeCard(d);
609
+ }
610
+ networkMapIsDragging = false;
611
+ }
612
+ }
613
+
614
+ // ─────────────────────────────────────────────────────────────────────────────
615
+ // Hull rendering
616
+ // ─────────────────────────────────────────────────────────────────────────────
617
+
618
+ /**
619
+ * Draw a convex hull background region for each network group.
620
+ * Called on every simulation tick; uses D3 data join for efficiency.
621
+ */
622
+ function _drawNetworkHulls(hullGroup, nodes) {
623
+ const byNetwork = d3.group(nodes, d => d.network);
624
+ const hullData = [];
625
+
626
+ byNetwork.forEach((pts, networkLabel) => {
627
+ if (pts.length === 0) return;
628
+
629
+ // d3.polygonHull requires at least 3 distinct points; for 1-2 nodes we
630
+ // synthesise a small bounding pad so a visible region still appears.
631
+ let points = pts.map(d => [d.x, d.y]);
632
+
633
+ if (points.length === 1) {
634
+ const [cx, cy] = points[0];
635
+ points = [
636
+ [cx - 40, cy - 40], [cx + 40, cy - 40],
637
+ [cx + 40, cy + 40], [cx - 40, cy + 40],
638
+ ];
639
+ } else if (points.length === 2) {
640
+ const [x1, y1] = points[0];
641
+ const [x2, y2] = points[1];
642
+ const mx = (x1 + x2) / 2, my = (y1 + y2) / 2;
643
+ const dx = (x2 - x1) || 1, dy = (y2 - y1) || 1;
644
+ const len = Math.sqrt(dx * dx + dy * dy);
645
+ const nx = -dy / len * 35, ny = dx / len * 35;
646
+ points = [
647
+ [x1 - nx, y1 - ny], [x2 - nx, y2 - ny],
648
+ [x2 + nx, y2 + ny], [x1 + nx, y1 + ny],
649
+ ];
650
+ }
651
+
652
+ const hull = d3.polygonHull(points);
653
+ if (!hull) return;
654
+
655
+ // Pad the hull outward by 36px from centroid
656
+ const centroid = d3.polygonCentroid(hull);
657
+ const padded = hull.map(([x, y]) => {
658
+ const dx = x - centroid[0], dy = y - centroid[1];
659
+ const dist = Math.sqrt(dx * dx + dy * dy) || 1;
660
+ return [x + (dx / dist) * 36, y + (dy / dist) * 36];
661
+ });
662
+
663
+ hullData.push({ networkLabel, path: padded, centroid });
664
+ });
665
+
666
+ // Data join
667
+ const paths = hullGroup.selectAll('path.network-hull').data(hullData, d => d.networkLabel);
668
+
669
+ paths.enter()
670
+ .append('path')
671
+ .attr('class', 'network-hull')
672
+ .attr('fill-opacity', 0.07)
673
+ .attr('stroke-opacity', 0.35)
674
+ .attr('stroke-width', 1.5)
675
+ .attr('stroke-dasharray', '6,4')
676
+ .merge(paths)
677
+ .attr('fill', d => networkColor(d.networkLabel))
678
+ .attr('stroke', d => networkColor(d.networkLabel))
679
+ .attr('d', d => 'M' + d.path.map(p => p.join(',')).join('L') + 'Z');
680
+
681
+ paths.exit().remove();
682
+
683
+ // Hull labels
684
+ const labels = hullGroup.selectAll('text.hull-label').data(hullData, d => d.networkLabel);
685
+
686
+ labels.enter()
687
+ .append('text')
688
+ .attr('class', 'hull-label')
689
+ .attr('font-size', '11px')
690
+ .attr('font-weight', '600')
691
+ .attr('opacity', 0.65)
692
+ .attr('pointer-events', 'none')
693
+ .merge(labels)
694
+ .attr('fill', d => networkColor(d.networkLabel))
695
+ .attr('x', d => d.centroid[0])
696
+ .attr('y', d => d.path.reduce((mn, p) => Math.min(mn, p[1]), Infinity) - 6)
697
+ .attr('text-anchor', 'middle')
698
+ .text(d => d.networkLabel);
699
+
700
+ labels.exit().remove();
701
+ }
702
+
703
+ // ─────────────────────────────────────────────────────────────────────────────
704
+ // Zoom / pan
705
+ // ─────────────────────────────────────────────────────────────────────────────
706
+
707
+ function initializeNetworkMapZoom(svg, nodeCount) {
708
+ const svgEl = d3.select(svg);
709
+ const minScale = nodeCount > 0 ? Math.min(0.05, 5 / nodeCount) : 0.1;
710
+
711
+ networkMapZoomBehavior = d3.zoom()
712
+ .scaleExtent([minScale, 3])
713
+ .on('zoom', event => {
714
+ svgEl.select('g').attr('transform', event.transform);
715
+ currentNetworkTransform = event.transform;
716
+ // sourceEvent is null for programmatic transforms (auto-fit, reset);
717
+ // it is set for real wheel / drag-pan / touch input.
718
+ if (event.sourceEvent) _nmUserInteracted = true;
719
+ });
720
+
721
+ svgEl.call(networkMapZoomBehavior);
722
+
723
+ if (currentNetworkTransform) {
724
+ svgEl.call(networkMapZoomBehavior.transform, currentNetworkTransform);
725
+ } else {
726
+ const r = svg.getBoundingClientRect();
727
+ const t = d3.zoomIdentity.translate(r.width / 2, r.height / 2);
728
+ svgEl.call(networkMapZoomBehavior.transform, t);
729
+ currentNetworkTransform = t;
730
+ }
731
+
732
+ svgEl.on('dblclick.zoom', () => {
733
+ const r = svg.getBoundingClientRect();
734
+ svgEl.transition().duration(750)
735
+ .call(networkMapZoomBehavior.transform,
736
+ d3.zoomIdentity.translate(r.width / 2, r.height / 2));
737
+ });
738
+ }
739
+
740
+ function resetNetworkMapZoom() {
741
+ const svg = document.getElementById('networkMapSvg');
742
+ if (!svg || !networkMapZoomBehavior) return;
743
+ const r = svg.getBoundingClientRect();
744
+ d3.select(svg).transition().duration(750)
745
+ .call(networkMapZoomBehavior.transform,
746
+ d3.zoomIdentity.translate(r.width / 2, r.height / 2));
747
+ }
748
+
749
+ /**
750
+ * Toggle the network map card between normal and fullscreen mode.
751
+ * Matches the same pattern used by the pipeline graph editor.
752
+ */
753
+ function toggleNetworkMapFullscreen() {
754
+ const card = document.getElementById('networkMapCard');
755
+ const btn = document.getElementById('nmFullscreenBtn');
756
+ const wrapper = document.getElementById('nmSvgWrapper');
757
+ if (!card) return;
758
+
759
+ _nmFullscreen = !_nmFullscreen;
760
+
761
+ if (_nmFullscreen) {
762
+ card.style.position = 'fixed';
763
+ card.style.top = '0';
764
+ card.style.left = '0';
765
+ card.style.right = '0';
766
+ card.style.bottom = '0';
767
+ card.style.zIndex = '9000';
768
+ card.style.borderRadius = '0';
769
+ card.style.marginBottom = '0';
770
+ card.style.display = 'flex';
771
+ card.style.flexDirection = 'column';
772
+ // SVG wrapper grows to fill the card below the header (~56px)
773
+ if (wrapper) wrapper.style.height = 'calc(100vh - 56px)';
774
+
775
+ if (btn) {
776
+ btn.title = 'Exit fullscreen';
777
+ btn.innerHTML = `
778
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
779
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
780
+ d="M6 18L18 6M6 6l12 12"/>
781
+ </svg>`;
782
+ }
783
+ } else {
784
+ card.style.position = '';
785
+ card.style.top = '';
786
+ card.style.left = '';
787
+ card.style.right = '';
788
+ card.style.bottom = '';
789
+ card.style.zIndex = '';
790
+ card.style.borderRadius = '';
791
+ card.style.marginBottom = '';
792
+ card.style.display = '';
793
+ card.style.flexDirection = '';
794
+ if (wrapper) wrapper.style.height = '600px';
795
+
796
+ if (btn) {
797
+ btn.title = 'Toggle fullscreen';
798
+ btn.innerHTML = `
799
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
800
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
801
+ d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"/>
802
+ </svg>`;
803
+ }
804
+ }
805
+
806
+ // Re-fit the graph to the new viewport after the layout settles
807
+ const svg = document.getElementById('networkMapSvg');
808
+ if (svg && networkMapZoomBehavior) {
809
+ setTimeout(() => {
810
+ // Use the current node positions from the live DOM if available
811
+ const nodes = networkTopologyData ? _liveNodesFromSvg() : null;
812
+ if (nodes && nodes.length > 0) {
813
+ _fitGraphToView(svg, nodes);
814
+ } else {
815
+ // Fall back to re-centering
816
+ const r = svg.getBoundingClientRect();
817
+ d3.select(svg).transition().duration(400)
818
+ .call(networkMapZoomBehavior.transform,
819
+ d3.zoomIdentity.translate(r.width / 2, r.height / 2));
820
+ }
821
+ }, 50);
822
+ }
823
+ }
824
+
825
+ /**
826
+ * Read current node x/y coordinates from the live D3 simulation via the
827
+ * transform attributes on each node group — used to re-fit after a resize.
828
+ */
829
+ function _liveNodesFromSvg() {
830
+ const nodes = [];
831
+ document.querySelectorAll('#networkMapGroup .nodes g').forEach(el => {
832
+ const t = el.getAttribute('transform');
833
+ if (!t) return;
834
+ const m = t.match(/translate\(([^,]+),([^)]+)\)/);
835
+ if (m) nodes.push({ x: parseFloat(m[1]), y: parseFloat(m[2]) });
836
+ });
837
+ return nodes;
838
+ }
839
+
840
+ // Escape key exits fullscreen
841
+ document.addEventListener('keydown', function(e) {
842
+ if (e.key === 'Escape' && _nmFullscreen) toggleNetworkMapFullscreen();
843
+ });
844
+
845
+ /**
846
+ * After the simulation settles, compute the bounding box of all nodes and zoom
847
+ * the viewport to contain them with some padding.
848
+ */
849
+ function _fitGraphToView(svgEl, nodes) {
850
+ if (!networkMapZoomBehavior || nodes.length === 0) return;
851
+
852
+ const r = svgEl.getBoundingClientRect();
853
+ const pad = 80;
854
+ const xs = nodes.map(d => d.x);
855
+ const ys = nodes.map(d => d.y);
856
+ const minX = Math.min(...xs), maxX = Math.max(...xs);
857
+ const minY = Math.min(...ys), maxY = Math.max(...ys);
858
+ const gw = maxX - minX || 1;
859
+ const gh = maxY - minY || 1;
860
+
861
+ const scale = Math.min(
862
+ (r.width - pad * 2) / gw,
863
+ (r.height - pad * 2) / gh,
864
+ 1.5 // don't over-zoom into a tiny graph
865
+ );
866
+ const tx = r.width / 2 - scale * (minX + gw / 2);
867
+ const ty = r.height / 2 - scale * (minY + gh / 2);
868
+
869
+ d3.select(svgEl).transition().duration(800)
870
+ .call(networkMapZoomBehavior.transform,
871
+ d3.zoomIdentity.translate(tx, ty).scale(scale));
872
+ }
873
+
874
+ // ─────────────────────────────────────────────────────────────────────────────
875
+ // Edge detail modal
876
+ // ─────────────────────────────────────────────────────────────────────────────
877
+
878
+ function showEdgeDetail(d) {
879
+ const srcName = d.source.id || d.source;
880
+ const tgtName = d.target.id || d.target;
881
+
882
+ const existing = document.getElementById('edge-detail-modal');
883
+ if (existing) existing.remove();
884
+
885
+ const modal = document.createElement('div');
886
+ modal.id = 'edge-detail-modal';
887
+ modal.className = 'fixed inset-0 flex items-center justify-center z-[60] p-4';
888
+ modal.innerHTML = `
889
+ <div class="absolute inset-0 bg-black/50 backdrop-blur-sm"
890
+ onclick="document.getElementById('edge-detail-modal').remove()"></div>
891
+ <div class="bg-gray-800 rounded-lg w-full max-w-2xl relative z-10 border border-gray-700 shadow-2xl max-h-[90vh] flex flex-col">
892
+ <div class="p-4 border-b border-gray-700 flex items-center justify-between shrink-0">
893
+ <h3 class="text-base font-semibold text-white flex items-center gap-2">
894
+ <svg class="w-4 h-4 text-blue-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
895
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
896
+ d="M8 9l3 3-3 3m5 0h3M5 20h14a2 2 0 002-2V6a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/>
897
+ </svg>
898
+ Link Detail
899
+ </h3>
900
+ <button onclick="document.getElementById('edge-detail-modal').remove()"
901
+ class="text-gray-400 hover:text-white transition-colors">
902
+ <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
903
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
904
+ </svg>
905
+ </button>
906
+ </div>
907
+ <!-- Loading state -->
908
+ <div id="edgeDetailBody" class="p-5 overflow-y-auto flex-1 min-h-0">
909
+ <div class="flex items-center justify-center py-8 gap-3 text-gray-400">
910
+ <div class="animate-spin rounded-full h-5 w-5 border-b-2 border-blue-500"></div>
911
+ <span class="text-sm">Fetching interface data…</span>
912
+ </div>
913
+ </div>
914
+ </div>
915
+ `;
916
+ document.body.appendChild(modal);
917
+
918
+ // Build query string
919
+ const params = new URLSearchParams({
920
+ source: srcName,
921
+ source_iface: d.source_interface,
922
+ target: tgtName,
923
+ target_iface: d.target_interface,
924
+ });
925
+
926
+ fetch(`/SNMP/GetEdgeInterfaceDetail/?${params}`)
927
+ .then(r => r.json())
928
+ .then(data => {
929
+ const body = document.getElementById('edgeDetailBody');
930
+ if (!body) return;
931
+ if (!data.success) {
932
+ body.innerHTML = `<p class="text-red-400 text-sm p-4">${escapeHtml(data.error || 'Failed to load interface data')}</p>`;
933
+ return;
934
+ }
935
+ body.innerHTML = _renderEdgeDetailBody(d, data);
936
+ })
937
+ .catch(err => {
938
+ const body = document.getElementById('edgeDetailBody');
939
+ if (body) body.innerHTML = `<p class="text-red-400 text-sm p-4">Error: ${escapeHtml(err.message)}</p>`;
940
+ });
941
+ }
942
+
943
+ /** Build the HTML for a populated edge detail modal body. */
944
+ function _renderEdgeDetailBody(d, data) {
945
+ const capStr = _decodeCapabilities(d.capabilities);
946
+
947
+ function _ifaceBlock(side) {
948
+ const iface = side.interface;
949
+ if (!iface) {
950
+ return `<p class="text-xs text-gray-500 italic mt-1">No interface data found in Elasticsearch</p>`;
951
+ }
952
+
953
+ const adminStatus = iface.admin_status;
954
+ const operStatus = iface.oper_status;
955
+ const upColor = (adminStatus === 'UP' && operStatus === 'UP') ? 'text-green-400' : 'text-gray-400';
956
+ const adminTxt = adminStatus === 'UP' ? '<span class="text-green-400">Up</span>'
957
+ : adminStatus === 'DOWN' ? '<span class="text-gray-400">Down</span>'
958
+ : '<span class="text-yellow-400">Testing</span>';
959
+ const operTxt = operStatus === 'UP' ? '<span class="text-green-400">Up</span>'
960
+ : operStatus === 'DOWN' ? '<span class="text-gray-400">Down</span>'
961
+ : operStatus === 'LOWER_LAYER_DOWN' ? '<span class="text-orange-400">Lower Layer Down</span>'
962
+ : operStatus === 'DORMANT' ? '<span class="text-yellow-400">Dormant</span>'
963
+ : operStatus === 'NOT_PRESENT' ? '<span class="text-gray-500">Not Present</span>'
964
+ : `<span class="text-yellow-400">${escapeHtml(operStatus ?? 'Unknown')}</span>`;
965
+
966
+ const speedMbps = iface.speed_high_mbps ?? (iface.speed ? Math.round(iface.speed / 1e6) : null);
967
+ const speedTxt = speedMbps == null ? null
968
+ : speedMbps >= 1000 ? `${speedMbps / 1000}G`
969
+ : speedMbps > 0 ? `${speedMbps}M`
970
+ : null;
971
+
972
+ // Byte counters
973
+ const inBytes = iface.in_octets ?? null;
974
+ const outBytes = iface.out_octets ?? null;
975
+
976
+ // Error / discard counters
977
+ const inErrors = iface.in_errors ?? null;
978
+ const outErrors = iface.out_errors ?? null;
979
+ const inDisc = iface.in_discards ?? null;
980
+ const outDisc = iface.out_discards ?? null;
981
+
982
+ // Packet counters
983
+ const inUcast = iface.in_unicast_pkts ?? null;
984
+ const outUcast = iface.out_unicast_pkts ?? null;
985
+ const inMcast = iface.in_multicast_pkts ?? null;
986
+ const outMcast = iface.out_multicast_pkts ?? null;
987
+ const inBcast = iface.in_broadcast_pkts ?? null;
988
+ const outBcast = iface.out_broadcast_pkts ?? null;
989
+
990
+ const alias = iface.alias ?? '';
991
+ const altName = iface.alt_name ?? '';
992
+ const desc = iface.description ?? '';
993
+ const mtu = iface.mtu ?? null;
994
+ const mac = iface.mac ?? null;
995
+ const vlanId = iface.vlan_id ?? null;
996
+ const ifIndex = iface.index ?? null;
997
+ const lastChange = iface.last_change ?? null; // sysUpTime hundredths
998
+
999
+ // SNMP ifType → human-readable (common values only)
1000
+ const ifTypeNum = iface.type ?? null;
1001
+ const IF_TYPES = {6:'ethernetCsmacd', 24:'softwareLoopback', 53:'propVirtual',
1002
+ 131:'tunnel', 161:'ieee8023adLag', 166:'mpls'};
1003
+ const ifTypeTxt = ifTypeNum != null
1004
+ ? (IF_TYPES[ifTypeNum] || `type ${ifTypeNum}`) : null;
1005
+
1006
+ const fmtBytes = n => {
1007
+ if (n == null) return null;
1008
+ if (n >= 1e12) return (n / 1e12).toFixed(2) + ' TB';
1009
+ if (n >= 1e9) return (n / 1e9).toFixed(2) + ' GB';
1010
+ if (n >= 1e6) return (n / 1e6).toFixed(2) + ' MB';
1011
+ if (n >= 1e3) return (n / 1e3).toFixed(1) + ' KB';
1012
+ return n + ' B';
1013
+ };
1014
+ const fmtN = n => (n == null ? null : n.toLocaleString());
1015
+
1016
+ const hasTraffic = inBytes != null || outBytes != null;
1017
+ const hasErrors = inErrors != null || outErrors != null || inDisc != null || outDisc != null;
1018
+ const hasPackets = inUcast != null || outUcast != null || inMcast != null || inBcast != null;
1019
+
1020
+ return `
1021
+ <!-- Status + core -->
1022
+ <div class="grid grid-cols-2 gap-x-4 gap-y-1 text-xs mt-2">
1023
+ <div><span class="text-gray-400">Admin:</span> ${adminTxt}</div>
1024
+ <div><span class="text-gray-400">Oper:</span> ${operTxt}</div>
1025
+ ${speedTxt ? `<div><span class="text-gray-400">Speed:</span> <span class="${upColor}">${speedTxt}</span></div>` : ''}
1026
+ ${mtu != null ? `<div><span class="text-gray-400">MTU:</span> <span class="text-white">${fmtN(mtu)}</span></div>` : ''}
1027
+ ${mac ? `<div class="col-span-2"><span class="text-gray-400">MAC:</span> <span class="text-white font-mono">${escapeHtml(mac)}</span></div>` : ''}
1028
+ ${alias && alias !== side.iface_name ? `<div class="col-span-2"><span class="text-gray-400">Alias:</span> <span class="text-white">${escapeHtml(alias)}</span></div>` : ''}
1029
+ ${altName && altName !== side.iface_name ? `<div class="col-span-2"><span class="text-gray-400">Alt name:</span> <span class="text-white">${escapeHtml(altName)}</span></div>` : ''}
1030
+ ${desc && desc !== side.iface_name ? `<div class="col-span-2"><span class="text-gray-400">Desc:</span> <span class="text-white">${escapeHtml(desc)}</span></div>` : ''}
1031
+ ${vlanId != null ? `<div><span class="text-gray-400">VLAN:</span> <span class="text-white">${vlanId}</span></div>` : ''}
1032
+ ${ifTypeTxt ? `<div><span class="text-gray-400">Type:</span> <span class="text-white">${escapeHtml(ifTypeTxt)}</span></div>` : ''}
1033
+ ${ifIndex != null ? `<div><span class="text-gray-400">Index:</span> <span class="text-white">${ifIndex}</span></div>` : ''}
1034
+ ${lastChange != null && lastChange > 0 ? `<div><span class="text-gray-400">Last change:</span> <span class="text-white">${formatUptime(lastChange)}</span></div>` : ''}
1035
+ </div>
1036
+ ${hasTraffic ? `
1037
+ <!-- Traffic counters -->
1038
+ <div class="mt-2 border-t border-gray-700/60 pt-2">
1039
+ <p class="text-xs text-gray-500 uppercase tracking-wide mb-1">Traffic (cumulative)</p>
1040
+ <div class="grid grid-cols-2 gap-2 text-xs">
1041
+ <div class="bg-gray-900/50 rounded px-2 py-1.5 space-y-0.5">
1042
+ <div class="text-gray-400 font-medium">↓ In</div>
1043
+ ${fmtBytes(inBytes) != null ? `<div class="text-blue-300 font-mono">${fmtBytes(inBytes)}</div>` : ''}
1044
+ ${fmtN(inUcast) != null ? `<div class="text-gray-400">${fmtN(inUcast)} unicast</div>` : ''}
1045
+ ${fmtN(inMcast) != null ? `<div class="text-gray-400">${fmtN(inMcast)} mcast</div>` : ''}
1046
+ ${fmtN(inBcast) != null ? `<div class="text-gray-400">${fmtN(inBcast)} bcast</div>` : ''}
1047
+ ${inErrors != null && inErrors > 0 ? `<div class="text-red-400">${fmtN(inErrors)} errors</div>` : ''}
1048
+ ${inDisc != null && inDisc > 0 ? `<div class="text-yellow-400">${fmtN(inDisc)} discards</div>` : ''}
1049
+ </div>
1050
+ <div class="bg-gray-900/50 rounded px-2 py-1.5 space-y-0.5">
1051
+ <div class="text-gray-400 font-medium">↑ Out</div>
1052
+ ${fmtBytes(outBytes) != null ? `<div class="text-green-300 font-mono">${fmtBytes(outBytes)}</div>` : ''}
1053
+ ${fmtN(outUcast) != null ? `<div class="text-gray-400">${fmtN(outUcast)} unicast</div>` : ''}
1054
+ ${fmtN(outMcast) != null ? `<div class="text-gray-400">${fmtN(outMcast)} mcast</div>` : ''}
1055
+ ${fmtN(outBcast) != null ? `<div class="text-gray-400">${fmtN(outBcast)} bcast</div>` : ''}
1056
+ ${outErrors != null && outErrors > 0 ? `<div class="text-red-400">${fmtN(outErrors)} errors</div>` : ''}
1057
+ ${outDisc != null && outDisc > 0 ? `<div class="text-yellow-400">${fmtN(outDisc)} discards</div>` : ''}
1058
+ </div>
1059
+ </div>
1060
+ </div>` : ''}`;
1061
+ }
1062
+
1063
+ return `
1064
+ <div class="space-y-4">
1065
+ <!-- Endpoint panels -->
1066
+ <div class="grid grid-cols-2 gap-3">
1067
+ <div class="bg-gray-900/60 rounded-lg p-3 overflow-hidden">
1068
+ <p class="text-xs text-gray-400 mb-0.5">Source</p>
1069
+ <p class="text-white font-semibold text-sm truncate">${escapeHtml(data.source.sysname)}</p>
1070
+ <p class="text-blue-300 text-xs font-mono mt-0.5 truncate">${escapeHtml(data.source.iface_name)}</p>
1071
+ ${_ifaceBlock(data.source)}
1072
+ </div>
1073
+ <div class="bg-gray-900/60 rounded-lg p-3 overflow-hidden">
1074
+ <p class="text-xs text-gray-400 mb-0.5">Target</p>
1075
+ <p class="text-white font-semibold text-sm truncate">${escapeHtml(data.target.sysname)}</p>
1076
+ <p class="text-blue-300 text-xs font-mono mt-0.5 truncate">${escapeHtml(data.target.iface_name)}</p>
1077
+ ${_ifaceBlock(data.target)}
1078
+ </div>
1079
+ </div>
1080
+ <!-- CDP metadata -->
1081
+ <div class="border-t border-gray-700 pt-3 grid grid-cols-2 gap-x-4 gap-y-1.5 text-xs">
1082
+ ${d.platform ? `<div class="col-span-2"><span class="text-gray-400">Platform: </span><span class="text-white font-mono">${escapeHtml(d.platform)}</span></div>` : ''}
1083
+ ${capStr ? `<div class="col-span-2"><span class="text-gray-400">Capabilities: </span><span class="text-white">${escapeHtml(capStr)}</span></div>` : ''}
1084
+ ${d.network ? `<div class="col-span-2"><span class="text-gray-400">Network: </span><span class="text-white">${escapeHtml(d.network)}</span></div>` : ''}
1085
+ </div>
1086
+ </div>`;
1087
+ }
1088
+
1089
+ /**
1090
+ * Decode CDP capability bitmask into readable labels.
1091
+ * Handles colon-separated hex bytes (e.g. "00:00:00:12") as well as plain hex.
1092
+ */
1093
+ function _decodeCapabilities(raw) {
1094
+ if (!raw) return '';
1095
+ // Strip colons so "00:00:00:12" → "00000012" before parsing
1096
+ const clean = raw.replace(/:/g, '');
1097
+ const val = parseInt(clean, 16);
1098
+ if (isNaN(val) || val === 0) return raw;
1099
+ const caps = [];
1100
+ if (val & 0x01) caps.push('Router');
1101
+ if (val & 0x02) caps.push('Trans-Bridge');
1102
+ if (val & 0x04) caps.push('Source-Bridge');
1103
+ if (val & 0x08) caps.push('Switch');
1104
+ if (val & 0x10) caps.push('Host');
1105
+ if (val & 0x20) caps.push('IGMP');
1106
+ if (val & 0x40) caps.push('Repeater');
1107
+ if (val & 0x80) caps.push('VoIP Phone');
1108
+ return caps.length ? caps.join(', ') : raw;
1109
+ }
1110
+
1111
+ // ─────────────────────────────────────────────────────────────────────────────
1112
+ // Adjacency debug modal
1113
+ // ─────────────────────────────────────────────────────────────────────────────
1114
+
1115
+ function showAdjacencyData() {
1116
+ if (!networkTopologyData) {
1117
+ console.warn('No adjacency data available');
1118
+ return;
1119
+ }
1120
+
1121
+ const existing = document.getElementById('adjacency-data-modal');
1122
+ if (existing) existing.remove();
1123
+
1124
+ const modal = document.createElement('div');
1125
+ modal.id = 'adjacency-data-modal';
1126
+ modal.className = 'fixed inset-0 flex items-center justify-center z-[60] p-4';
1127
+ modal.innerHTML = `
1128
+ <div class="absolute inset-0 bg-black/50 backdrop-blur-sm"
1129
+ onclick="document.getElementById('adjacency-data-modal').remove()"></div>
1130
+ <div class="bg-gray-800 rounded-lg w-full max-w-6xl max-h-[90vh] flex flex-col relative z-10 border border-gray-700">
1131
+ <div class="p-4 border-b border-gray-700 flex justify-between items-center">
1132
+ <h3 class="text-lg font-semibold text-white">Network Adjacency Data (Debug)</h3>
1133
+ <button onclick="document.getElementById('adjacency-data-modal').remove()"
1134
+ class="text-gray-400 hover:text-white">
1135
+ <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1136
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
1137
+ </svg>
1138
+ </button>
1139
+ </div>
1140
+ <div class="p-6 overflow-y-auto flex-grow">
1141
+ <div class="bg-gray-900 rounded-lg p-4">
1142
+ <pre class="text-gray-300 text-xs overflow-auto">${escapeHtml(JSON.stringify(networkTopologyData, null, 2))}</pre>
1143
+ </div>
1144
+ </div>
1145
+ <div class="p-4 border-t border-gray-700 flex justify-end">
1146
+ <button onclick="copyAdjacencyData(this)"
1147
+ class="px-4 py-2 bg-blue-600 hover:bg-blue-500 text-white rounded-lg text-sm flex items-center gap-2">
1148
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1149
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1150
+ d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v2m-6 12h8a2 2 0 002-2v-8a2 2 0 00-2-2h-8a2 2 0 00-2 2v8a2 2 0 002 2z"/>
1151
+ </svg>
1152
+ Copy to Clipboard
1153
+ </button>
1154
+ </div>
1155
+ </div>
1156
+ `;
1157
+ document.body.appendChild(modal);
1158
+ }
1159
+
1160
+ /**
1161
+ * Copy adjacency data to clipboard.
1162
+ * @param {HTMLButtonElement} btn - the button element that was clicked
1163
+ */
1164
+ function copyAdjacencyData(btn) {
1165
+ if (!networkTopologyData) return;
1166
+
1167
+ const jsonString = JSON.stringify(networkTopologyData, null, 2);
1168
+ navigator.clipboard.writeText(jsonString).then(() => {
1169
+ const originalHTML = btn.innerHTML;
1170
+ btn.innerHTML = `
1171
+ <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1172
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
1173
+ </svg>
1174
+ Copied!
1175
+ `;
1176
+ btn.classList.add('bg-green-600');
1177
+ btn.classList.remove('bg-blue-600');
1178
+ setTimeout(() => {
1179
+ btn.innerHTML = originalHTML;
1180
+ btn.classList.remove('bg-green-600');
1181
+ btn.classList.add('bg-blue-600');
1182
+ }, 2000);
1183
+ }).catch(err => {
1184
+ console.error('Failed to copy:', err);
1185
+ });
1186
+ }
1187
+
1188
+ // ─────────────────────────────────────────────────────────────────────────────
1189
+ // Compact node card
1190
+ // ─────────────────────────────────────────────────────────────────────────────
1191
+
1192
+ let _ncTopZ = 10010;
1193
+ let _ncSpawnIdx = 0;
1194
+ let _ncActive = null;
1195
+ let _ncStartX = 0, _ncStartY = 0, _ncStartL = 0, _ncStartT = 0;
1196
+
1197
+ document.addEventListener('mousemove', function(e) {
1198
+ if (!_ncActive) return;
1199
+ _ncActive.style.left = (_ncStartL + e.clientX - _ncStartX) + 'px';
1200
+ _ncActive.style.top = (_ncStartT + e.clientY - _ncStartY) + 'px';
1201
+ });
1202
+ document.addEventListener('mouseup', function() { _ncActive = null; });
1203
+
1204
+ /**
1205
+ * Show a compact floating card for a node. Opens the full window on demand via
1206
+ * the "Open Full Details" button.
1207
+ */
1208
+ function showNodeCard(nodeData) {
1209
+ const safeId = (nodeData.device_id || nodeData.id.replace(/[^a-z0-9]/gi, '_'));
1210
+ const cardId = 'nc-' + safeId;
1211
+
1212
+ // Bring existing card to front
1213
+ const existing = document.getElementById(cardId);
1214
+ if (existing) {
1215
+ existing.style.zIndex = ++_ncTopZ;
1216
+ return;
1217
+ }
1218
+
1219
+ const offset = (_ncSpawnIdx % 8) * 28;
1220
+ _ncSpawnIdx++;
1221
+ const spawnTop = 80 + offset;
1222
+ const spawnLeft = 80 + offset;
1223
+
1224
+ const badge = nodeData.managed
1225
+ ? `<span class="inline-flex items-center gap-1 px-2 py-0.5 bg-blue-600/20 text-blue-300 border border-blue-500/30 rounded text-xs">
1226
+ <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1227
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1228
+ d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
1229
+ </svg>Managed</span>`
1230
+ : `<span class="inline-flex items-center px-2 py-0.5 bg-gray-600/20 text-gray-400 border border-gray-500/30 rounded text-xs">Discovered</span>`;
1231
+
1232
+ const card = document.createElement('div');
1233
+ card.id = cardId;
1234
+ card.className = 'node-card fixed bg-gray-800 rounded-lg border border-gray-700 shadow-2xl flex flex-col';
1235
+ card.style.cssText = `width:360px; top:${spawnTop}px; left:${spawnLeft}px; z-index:${++_ncTopZ};`;
1236
+
1237
+ card.innerHTML = `
1238
+ <!-- Header (draggable) -->
1239
+ <div class="nc-header px-3 py-2.5 border-b border-gray-700 flex items-center justify-between rounded-t-lg cursor-move bg-gray-700/60 shrink-0">
1240
+ <div class="flex items-center gap-2 min-w-0 flex-1">
1241
+ <svg class="w-4 h-4 text-blue-400 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1242
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1243
+ d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
1244
+ </svg>
1245
+ <div class="min-w-0">
1246
+ <div class="flex items-center gap-2 flex-wrap">
1247
+ <span class="text-white font-semibold text-sm truncate">${escapeHtml(nodeData.id)}</span>
1248
+ ${badge}
1249
+ </div>
1250
+ ${nodeData.network ? `<p class="text-xs text-gray-400 mt-0.5 truncate">${escapeHtml(nodeData.network)}</p>` : ''}
1251
+ </div>
1252
+ </div>
1253
+ <button class="nc-close-btn p-1.5 text-gray-400 hover:text-red-400 hover:bg-gray-600 rounded transition-colors shrink-0 ml-2">
1254
+ <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1255
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
1256
+ </svg>
1257
+ </button>
1258
+ </div>
1259
+
1260
+ <!-- Stats row (populated async) -->
1261
+ <div class="nc-stats px-4 py-3 border-b border-gray-700/60 grid grid-cols-3 gap-3 text-center shrink-0">
1262
+ <div>
1263
+ <p class="text-xs text-gray-400 mb-0.5">Uptime</p>
1264
+ <p class="text-white text-sm font-semibold nc-uptime">—</p>
1265
+ </div>
1266
+ <div>
1267
+ <p class="text-xs text-gray-400 mb-0.5">CPU</p>
1268
+ <p class="text-white text-sm font-semibold nc-cpu">—</p>
1269
+ </div>
1270
+ <div>
1271
+ <p class="text-xs text-gray-400 mb-0.5">Memory</p>
1272
+ <p class="text-white text-sm font-semibold nc-mem">—</p>
1273
+ </div>
1274
+ </div>
1275
+
1276
+ <!-- Neighbors list -->
1277
+ <div class="nc-neighbors flex-1 overflow-y-auto px-4 py-3 min-h-0" style="max-height:220px;">
1278
+ <p class="text-xs font-semibold text-gray-400 uppercase tracking-wide mb-2">CDP Neighbors</p>
1279
+ <div class="nc-neighbor-list space-y-1">
1280
+ <p class="text-xs text-gray-500 italic">Loading…</p>
1281
+ </div>
1282
+ </div>
1283
+
1284
+ <!-- Footer -->
1285
+ ${nodeData.managed && nodeData.device_id ? `
1286
+ <div class="px-4 py-2.5 border-t border-gray-700/60 flex justify-end shrink-0">
1287
+ <button class="nc-open-full-btn px-3 py-1.5 bg-blue-700 hover:bg-blue-600 text-white text-xs rounded-lg transition-colors flex items-center gap-1.5">
1288
+ <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1289
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1290
+ d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"/>
1291
+ </svg>
1292
+ Open Full Details
1293
+ </button>
1294
+ </div>` : ''}
1295
+ `;
1296
+
1297
+ document.body.appendChild(card);
1298
+
1299
+ // Drag on header
1300
+ card.querySelector('.nc-header').addEventListener('mousedown', function(e) {
1301
+ if (e.target.closest('.nc-close-btn')) return;
1302
+ card.style.zIndex = ++_ncTopZ;
1303
+ _ncActive = card;
1304
+ _ncStartX = e.clientX;
1305
+ _ncStartY = e.clientY;
1306
+ _ncStartL = card.offsetLeft;
1307
+ _ncStartT = card.offsetTop;
1308
+ e.preventDefault();
1309
+ });
1310
+
1311
+ // Bring to front on click
1312
+ card.addEventListener('mousedown', () => { card.style.zIndex = ++_ncTopZ; });
1313
+
1314
+ // Close
1315
+ card.querySelector('.nc-close-btn').addEventListener('click', () => card.remove());
1316
+
1317
+ // Open full details window — closes compact card first, passes back callback
1318
+ const openFullBtn = card.querySelector('.nc-open-full-btn');
1319
+ if (openFullBtn) {
1320
+ openFullBtn.addEventListener('click', () => {
1321
+ card.remove();
1322
+ createDeviceWindow(nodeData, () => showNodeCard(nodeData));
1323
+ });
1324
+ }
1325
+
1326
+ // Populate stats and neighbor list
1327
+ _populateNodeCard(card, nodeData);
1328
+ }
1329
+
1330
+ /** Fetch the slim summary and populate card stats + build neighbor list from memory. */
1331
+ function _populateNodeCard(card, nodeData) {
1332
+ // ── Neighbors from in-memory adjacency table ──
1333
+ const neighborList = card.querySelector('.nc-neighbor-list');
1334
+ const neighbors = _getNeighborsFromAdjacency(nodeData.id);
1335
+
1336
+ if (neighbors.length === 0) {
1337
+ neighborList.innerHTML = '<p class="text-xs text-gray-500 italic">No neighbors found</p>';
1338
+ } else {
1339
+ neighborList.innerHTML = neighbors.map(nb => `
1340
+ <div class="flex items-start gap-2 py-1 border-b border-gray-700/40 last:border-0">
1341
+ <div class="shrink-0 w-1.5 h-1.5 rounded-full mt-1.5 ${nb.managed ? 'bg-blue-400' : 'bg-gray-500'}"></div>
1342
+ <div class="min-w-0 flex-1">
1343
+ <p class="text-white text-xs font-medium truncate">${escapeHtml(nb.deviceId)}</p>
1344
+ <p class="text-gray-400 text-xs font-mono">
1345
+ ${escapeHtml(nb.localIface)} ↔ ${escapeHtml(nb.remoteIface)}
1346
+ </p>
1347
+ </div>
1348
+ ${nb.platform ? `<p class="text-gray-500 text-xs shrink-0 max-w-[90px] truncate" title="${escapeHtml(nb.platform)}">${escapeHtml(nb.platform.split(' ')[0])}</p>` : ''}
1349
+ </div>
1350
+ `).join('');
1351
+ }
1352
+
1353
+ // ── Stats — reuse GetDeviceVisualization (same source as the full window) ──
1354
+ if (!nodeData.managed || !nodeData.device_id) return;
1355
+
1356
+ fetch(`/SNMP/GetDeviceVisualization/${nodeData.device_id}/`)
1357
+ .then(r => r.json())
1358
+ .then(data => {
1359
+ if (!card.isConnected) return;
1360
+ const uptimeEl = card.querySelector('.nc-uptime');
1361
+ const cpuEl = card.querySelector('.nc-cpu');
1362
+ const memEl = card.querySelector('.nc-mem');
1363
+
1364
+ const metrics = data.visualizations?.metrics;
1365
+ if (!metrics) return;
1366
+
1367
+ // Uptime: stored as hundredths of seconds (raw SNMP sysUpTime).
1368
+ // formatUptime() from snmp_device_visual_preview.js handles the conversion.
1369
+ if (metrics.Uptime != null && metrics.Uptime > 0) {
1370
+ uptimeEl.textContent = formatUptime(metrics.Uptime);
1371
+ }
1372
+
1373
+ // CPU / Memory: arrays of 0-1 fractional values sorted oldest→newest
1374
+ // (same order renderMetricChart uses). Use the last element for the
1375
+ // most recent reading.
1376
+ if (metrics.CPU && metrics.CPU.length > 0) {
1377
+ const pct = Math.round(metrics.CPU[metrics.CPU.length - 1] * 100);
1378
+ const cls = pct >= 90 ? 'text-red-400' : pct >= 75 ? 'text-orange-400' : 'text-green-400';
1379
+ cpuEl.className = `text-sm font-semibold nc-cpu ${cls}`;
1380
+ cpuEl.textContent = pct + '%';
1381
+ }
1382
+
1383
+ if (metrics.Memory && metrics.Memory.length > 0) {
1384
+ const pct = Math.round(metrics.Memory[metrics.Memory.length - 1] * 100);
1385
+ const cls = pct >= 90 ? 'text-red-400' : pct >= 75 ? 'text-orange-400' : 'text-green-400';
1386
+ memEl.className = `text-sm font-semibold nc-mem ${cls}`;
1387
+ memEl.textContent = pct + '%';
1388
+ }
1389
+ })
1390
+ .catch(() => {
1391
+ // Stats stay as '—' — non-fatal
1392
+ });
1393
+ }
1394
+
1395
+ /**
1396
+ * Build a neighbor list for a given device ID from the in-memory adjacency table.
1397
+ * Returns [{deviceId, localIface, remoteIface, platform, managed}, ...]
1398
+ */
1399
+ function _getNeighborsFromAdjacency(deviceId) {
1400
+ if (!networkTopologyData) return [];
1401
+ const results = [];
1402
+ const managedDevices = new Set();
1403
+
1404
+ // First pass: collect all managed device names
1405
+ for (const devices of Object.values(networkTopologyData)) {
1406
+ for (const dn of Object.keys(devices)) {
1407
+ managedDevices.add(dn);
1408
+ }
1409
+ }
1410
+
1411
+ // Second pass: find this device's entries
1412
+ for (const devices of Object.values(networkTopologyData)) {
1413
+ if (!devices[deviceId]) continue;
1414
+ for (const [localIface, cdpData] of Object.entries(devices[deviceId])) {
1415
+ results.push({
1416
+ deviceId: cdpData.device_id || '(unknown)',
1417
+ localIface,
1418
+ remoteIface: cdpData.port || '',
1419
+ platform: cdpData.platform || '',
1420
+ managed: managedDevices.has(cdpData.device_id),
1421
+ });
1422
+ }
1423
+ }
1424
+ return results;
1425
+ }
1426
+
1427
+ // ─────────────────────────────────────────────────────────────────────────────
1428
+ // Floating Device Detail Window System (full / heavy — opened on demand)
1429
+ // Each click on "Open Full Details" spawns an independent floating window.
1430
+ // ─────────────────────────────────────────────────────────────────────────────
1431
+
1432
+ let _dwTopZ = 11000;
1433
+ let _dwSpawnIdx = 0;
1434
+
1435
+ let _dwActive = null;
1436
+ let _dwOp = null;
1437
+ let _dwStartX = 0, _dwStartY = 0;
1438
+ let _dwStartW = 0, _dwStartH = 0;
1439
+ let _dwStartL = 0, _dwStartT = 0;
1440
+
1441
+ document.addEventListener('mousemove', function(e) {
1442
+ if (!_dwActive || !_dwOp) return;
1443
+ const dx = e.clientX - _dwStartX;
1444
+ const dy = e.clientY - _dwStartY;
1445
+ if (_dwOp === 'drag') {
1446
+ _dwActive.style.left = (_dwStartL + dx) + 'px';
1447
+ _dwActive.style.top = (_dwStartT + dy) + 'px';
1448
+ } else {
1449
+ let newW = _dwStartW, newH = _dwStartH, newL = _dwStartL, newT = _dwStartT;
1450
+ if (_dwOp.includes('e')) newW = Math.max(400, _dwStartW + dx);
1451
+ if (_dwOp.includes('w')) { newW = Math.max(400, _dwStartW - dx); newL = _dwStartL + (_dwStartW - newW); }
1452
+ if (_dwOp.includes('s')) newH = Math.max(280, _dwStartH + dy);
1453
+ if (_dwOp.includes('n')) { newH = Math.max(280, _dwStartH - dy); newT = _dwStartT + (_dwStartH - newH); }
1454
+ _dwActive.style.width = newW + 'px';
1455
+ _dwActive.style.height = newH + 'px';
1456
+ _dwActive.style.left = newL + 'px';
1457
+ _dwActive.style.top = newT + 'px';
1458
+ }
1459
+ });
1460
+ document.addEventListener('mouseup', function() { _dwActive = null; _dwOp = null; });
1461
+
1462
+ /**
1463
+ * @param {object} nodeData
1464
+ * @param {Function|null} onBack Optional callback invoked when the user clicks
1465
+ * "Back to Summary" in the window header.
1466
+ */
1467
+ function createDeviceWindow(nodeData, onBack) {
1468
+ const safeId = (nodeData.device_id || nodeData.id.replace(/[^a-z0-9]/gi, '_'));
1469
+ const windowId = 'device-window-' + safeId;
1470
+
1471
+ const existing = document.getElementById(windowId);
1472
+ if (existing) {
1473
+ existing.style.zIndex = ++_dwTopZ;
1474
+ return;
1475
+ }
1476
+
1477
+ const offset = (_dwSpawnIdx % 8) * 30;
1478
+ _dwSpawnIdx++;
1479
+ const spawnTop = 60 + offset;
1480
+ const spawnLeft = 60 + offset;
1481
+
1482
+ const badge = nodeData.managed
1483
+ ? `<span class="inline-flex items-center gap-1 px-2 py-0.5 bg-blue-600/20 text-blue-300 border border-blue-500/30 rounded text-xs font-medium">
1484
+ <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1485
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1486
+ d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/>
1487
+ </svg>Managed</span>`
1488
+ : `<span class="inline-flex items-center gap-1 px-2 py-0.5 bg-gray-600/20 text-gray-400 border border-gray-500/30 rounded text-xs font-medium">Discovered Only</span>`;
1489
+
1490
+ const win = document.createElement('div');
1491
+ win.id = windowId;
1492
+ win.className = 'device-window fixed bg-gray-800 rounded-lg border border-gray-700 shadow-2xl flex flex-col';
1493
+ win.style.cssText = `width:720px; height:580px; top:${spawnTop}px; left:${spawnLeft}px; z-index:${++_dwTopZ};`;
1494
+
1495
+ win.innerHTML = `
1496
+ <div class="resize-handle resize-handle-n"></div>
1497
+ <div class="resize-handle resize-handle-e"></div>
1498
+ <div class="resize-handle resize-handle-s"></div>
1499
+ <div class="resize-handle resize-handle-w"></div>
1500
+ <div class="resize-handle resize-handle-ne"></div>
1501
+ <div class="resize-handle resize-handle-nw"></div>
1502
+ <div class="resize-handle resize-handle-se"></div>
1503
+ <div class="resize-handle resize-handle-sw"></div>
1504
+
1505
+ <div class="window-header px-3 py-2.5 border-b border-gray-700 flex items-center justify-between rounded-t-lg cursor-move shrink-0 bg-gray-700/60">
1506
+ <div class="flex items-center gap-2 min-w-0 flex-1">
1507
+ <svg class="w-4 h-4 text-blue-400 shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1508
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1509
+ d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
1510
+ </svg>
1511
+ <div class="min-w-0">
1512
+ <div class="flex items-center gap-2 flex-wrap">
1513
+ <span class="text-white font-semibold text-sm truncate">${escapeHtml(nodeData.id)}</span>
1514
+ ${badge}
1515
+ </div>
1516
+ ${nodeData.network ? `<p class="text-xs text-gray-400 mt-0.5">${escapeHtml(nodeData.network)}</p>` : ''}
1517
+ </div>
1518
+ </div>
1519
+ <div class="flex items-center gap-0.5 shrink-0 ml-2">
1520
+ ${onBack ? `
1521
+ <button class="dw-back-btn px-2 py-1 text-xs text-blue-300 hover:text-blue-200 hover:bg-gray-600 rounded transition-colors flex items-center gap-1" title="Back to summary">
1522
+ <svg class="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1523
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 19l-7-7 7-7"/>
1524
+ </svg>
1525
+ Summary
1526
+ </button>` : ''}
1527
+ <button class="dw-maximize-btn p-1.5 text-gray-400 hover:text-white hover:bg-gray-600 rounded transition-colors" title="Maximize / Restore">
1528
+ <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1529
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1530
+ d="M4 8V4m0 0h4M4 4l5 5m11-1V4m0 0h-4m4 0l-5 5M4 16v4m0 0h4m-4 0l5-5m11 5l-5-5m5 5v-4m0 4h-4"/>
1531
+ </svg>
1532
+ </button>
1533
+ <button class="dw-close-btn p-1.5 text-gray-400 hover:text-red-400 hover:bg-gray-600 rounded transition-colors" title="Close">
1534
+ <svg class="w-3.5 h-3.5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1535
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
1536
+ </svg>
1537
+ </button>
1538
+ </div>
1539
+ </div>
1540
+
1541
+ <div class="dw-body flex-1 overflow-y-auto min-h-0"></div>`;
1542
+
1543
+ document.body.appendChild(win);
1544
+
1545
+ const header = win.querySelector('.window-header');
1546
+ header.addEventListener('mousedown', function(e) {
1547
+ if (e.target.closest('.dw-close-btn') || e.target.closest('.dw-maximize-btn')) return;
1548
+ _dwBringToFront(win);
1549
+ _dwActive = win; _dwOp = 'drag';
1550
+ _dwStartX = e.clientX; _dwStartY = e.clientY;
1551
+ _dwStartL = win.offsetLeft; _dwStartT = win.offsetTop;
1552
+ e.preventDefault();
1553
+ });
1554
+
1555
+ win.querySelectorAll('.resize-handle').forEach(function(handle) {
1556
+ handle.addEventListener('mousedown', function(e) {
1557
+ _dwBringToFront(win);
1558
+ const dir = Array.from(handle.classList)
1559
+ .find(c => c.startsWith('resize-handle-') && c !== 'resize-handle')
1560
+ .replace('resize-handle-', '');
1561
+ const rect = win.getBoundingClientRect();
1562
+ _dwActive = win; _dwOp = dir;
1563
+ _dwStartX = e.clientX; _dwStartY = e.clientY;
1564
+ _dwStartW = win.offsetWidth; _dwStartH = win.offsetHeight;
1565
+ _dwStartL = rect.left; _dwStartT = rect.top;
1566
+ win.style.left = rect.left + 'px';
1567
+ win.style.top = rect.top + 'px';
1568
+ e.preventDefault();
1569
+ e.stopPropagation();
1570
+ });
1571
+ });
1572
+
1573
+ win.addEventListener('mousedown', function() { _dwBringToFront(win); });
1574
+ win.querySelector('.dw-close-btn').addEventListener('click', () => win.remove());
1575
+
1576
+ // Back to Summary — close full window and reopen compact card
1577
+ const backBtn = win.querySelector('.dw-back-btn');
1578
+ if (backBtn && onBack) {
1579
+ backBtn.addEventListener('click', () => {
1580
+ win.remove();
1581
+ onBack();
1582
+ });
1583
+ }
1584
+
1585
+ let _maximized = false, _savedStyle = null;
1586
+ win.querySelector('.dw-maximize-btn').addEventListener('click', function() {
1587
+ if (!_maximized) {
1588
+ _savedStyle = { w: win.style.width, h: win.style.height, t: win.style.top, l: win.style.left };
1589
+ win.style.cssText += 'width:100vw;height:100vh;top:0;left:0;';
1590
+ _maximized = true;
1591
+ } else {
1592
+ win.style.width = _savedStyle.w;
1593
+ win.style.height = _savedStyle.h;
1594
+ win.style.top = _savedStyle.t;
1595
+ win.style.left = _savedStyle.l;
1596
+ _maximized = false;
1597
+ }
1598
+ });
1599
+
1600
+ _dwPopulateBody(nodeData, win.querySelector('.dw-body'));
1601
+ }
1602
+
1603
+ function _dwBringToFront(win) { win.style.zIndex = ++_dwTopZ; }
1604
+
1605
+ function _dwPopulateBody(nodeData, bodyEl) {
1606
+ if (nodeData.managed && nodeData.device_id) {
1607
+ bodyEl.innerHTML = `
1608
+ <div class="flex items-center justify-center" style="min-height:200px;">
1609
+ <div class="text-center">
1610
+ <div class="inline-block animate-spin rounded-full h-8 w-8 border-b-2 border-blue-500 mb-3"></div>
1611
+ <p class="text-gray-400 text-sm">Loading device details...</p>
1612
+ </div>
1613
+ </div>`;
1614
+
1615
+ fetch(`/SNMP/GetDeviceVisualization/${nodeData.device_id}/`)
1616
+ .then(r => r.json())
1617
+ .then(data => {
1618
+ if (data.success) {
1619
+ bodyEl.innerHTML = '';
1620
+ const wrapper = document.createElement('div');
1621
+ wrapper.id = `device-preview-content-${nodeData.device_id}`;
1622
+ bodyEl.appendChild(wrapper);
1623
+ renderDevicePreview(nodeData.device_id, data.device, data.visualizations);
1624
+ } else {
1625
+ bodyEl.innerHTML = `<div class="p-8 text-center text-red-400"><p>${escapeHtml(data.error || 'Error loading device')}</p></div>`;
1626
+ }
1627
+ })
1628
+ .catch(err => {
1629
+ bodyEl.innerHTML = `<div class="p-8 text-center text-red-400"><p>Error: ${escapeHtml(err.message)}</p></div>`;
1630
+ });
1631
+ } else {
1632
+ const isManaged = nodeData.managed;
1633
+ bodyEl.innerHTML = `
1634
+ <div class="flex items-center justify-center" style="min-height:200px;">
1635
+ <div class="text-center p-8">
1636
+ <div class="inline-flex items-center justify-center w-14 h-14 bg-gray-700/50 rounded-full mb-4">
1637
+ <svg class="w-7 h-7 text-gray-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
1638
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
1639
+ d="M9.75 17L9 20l-1 1h8l-1-1-.75-3M3 13h18M5 17h14a2 2 0 002-2V5a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/>
1640
+ </svg>
1641
+ </div>
1642
+ <h4 class="text-white font-semibold mb-2">
1643
+ ${isManaged ? 'Device Not Found in Inventory' : 'Discovered Device'}
1644
+ </h4>
1645
+ <p class="text-gray-400 text-sm max-w-xs mx-auto">
1646
+ ${isManaged
1647
+ ? 'This device is sending SNMP data but could not be matched to a device in your inventory.'
1648
+ : 'This device was discovered via CDP/LLDP but is not currently in your inventory.'}
1649
+ </p>
1650
+ <a href="/SNMP/Devices/"
1651
+ class="mt-5 inline-block px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-sm transition-colors">
1652
+ Add to Inventory
1653
+ </a>
1654
+ </div>
1655
+ </div>`;
1656
+ }
1657
+ }