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,1469 @@
1
+ #Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
2
+ #or more contributor license agreements. Licensed under the Elastic License;
3
+ #you may not use this file except in compliance with the Elastic License.
4
+
5
+ """Convert between Logstash pipeline config text and component JSON via Lark."""
6
+
7
+ from lark import Lark, Transformer, UnexpectedToken, UnexpectedCharacters
8
+ from typing import Dict, List, Any
9
+ import json
10
+ import re
11
+
12
+ import logging
13
+ logger = logging.getLogger(__name__)
14
+
15
+ ################################ Logstash config to component JSON ################################
16
+ LOGSTASH_GRAMMAR = r"""
17
+ ?start: comment* (section comment*)+
18
+
19
+ section: section_type "{" [statement+] "}"
20
+
21
+ statement: plugin | conditional | comment
22
+
23
+ comment: COMMENT
24
+
25
+ conditional: "if" condition "{" [statement+] "}" (else_if_condition | else_condition)*
26
+ condition: CMP_OPERATORS
27
+ else_if_condition: "else" "if" condition "{" [statement+] "}"
28
+ else_condition: "else" "{" [statement+] "}"
29
+
30
+ CMP_OPERATORS: /(?:[^\n{"'\/]|"(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|\/(?:[^\/\\]|\\.)*\/)+/ // Matches anything except newline and unquoted {, handles quoted strings and /regex/ literals
31
+ section_type: "input" -> input_section
32
+ | "filter" -> filter_section
33
+ | "output" -> output_section
34
+
35
+
36
+ // Define plugin with flexible parameter formatting
37
+ // plugin_item allows both key=>value pairs and standalone comment lines
38
+ plugin: CNAME "{" [plugin_item (WS | ";")*]* "}"
39
+ plugin_item: pair | comment
40
+
41
+
42
+ pair: "codec" "=>" CNAME "{" codec_config "}" -> codec_pair_with_config
43
+ | "codec" "=>" (CNAME | MULTILINE_STRING | ESCAPED_STRING) -> codec_pair_simple
44
+ | (CNAME | ESCAPED_STRING) "=>" (UNQUOTED_STRING | CNAME | value) -> regular_pair
45
+
46
+ codec_config: [codec_setting (","? codec_setting)*]
47
+ codec_setting: (CNAME | ESCAPED_STRING) "=>" (UNQUOTED_STRING | CNAME | value)
48
+
49
+ ?value: multiline_string
50
+ | string
51
+ | number
52
+ | array
53
+ | hash
54
+ | env_var
55
+ | plugin
56
+
57
+ multiline_string: MULTILINE_STRING
58
+ string: ESCAPED_STRING
59
+ number: SIGNED_NUMBER
60
+ array: "[" [value ("," value)*] "]"
61
+ hash: "{" [pair (","? pair)*] "}"
62
+ env_var: "${" CNAME "}"
63
+
64
+ // Multi-line string: matches strings that can span multiple lines
65
+ // Handles both single and double quotes with escaped quotes inside
66
+ MULTILINE_STRING.3: /"([^"\\]|\\.|\n)*"/s | /'([^'\\]|\\.|\n)*'/s
67
+
68
+ %import common.ESCAPED_STRING
69
+ %import common.SIGNED_NUMBER
70
+ %import common.CNAME
71
+ %import common.WS
72
+ %import common.NEWLINE
73
+
74
+ UNQUOTED_STRING.2: /[a-zA-Z_][a-zA-Z0-9_-]*/
75
+ COMMENT: /#[^\n]*/
76
+ %ignore WS
77
+ """
78
+
79
+
80
+ class LogstashTransformer(Transformer):
81
+ """Lark transformer that turns parse trees into component dicts."""
82
+
83
+ def _unescape_string(self, s):
84
+ """Unescape special characters in parsed strings."""
85
+ # Process escape sequences in the correct order
86
+ # We need to handle \\\\ -> \\ first, then other escapes
87
+ result = []
88
+ i = 0
89
+ while i < len(s):
90
+ if i < len(s) - 1 and s[i] == '\\':
91
+ next_char = s[i + 1]
92
+ if next_char == 'n':
93
+ result.append('\n')
94
+ i += 2
95
+ elif next_char == 't':
96
+ result.append('\t')
97
+ i += 2
98
+ elif next_char == 'r':
99
+ result.append('\r')
100
+ i += 2
101
+ elif next_char == '"':
102
+ result.append('"')
103
+ i += 2
104
+ elif next_char == "'":
105
+ result.append("'")
106
+ i += 2
107
+ elif next_char == '\\':
108
+ result.append('\\')
109
+ i += 2
110
+ else:
111
+ # Unknown escape sequence, keep as-is
112
+ result.append(s[i])
113
+ i += 1
114
+ else:
115
+ result.append(s[i])
116
+ i += 1
117
+ return ''.join(result)
118
+
119
+ def multiline_string(self, s):
120
+ # Remove quotes and unescape the content
121
+ raw_value = self._unescape_string(s[0][1:-1])
122
+
123
+ # For multi-line strings, strip file indentation (tabs) from each line after the first
124
+ # When ComponentToPipeline writes single-quoted strings across multiple lines,
125
+ # each line picks up the file's indentation context (tabs from the f-string).
126
+ # We need to remove these file-context tabs while preserving intentional indentation.
127
+ lines = raw_value.split('\n')
128
+ if len(lines) > 1:
129
+ # Find the common leading tabs on lines after the first (file indentation)
130
+ # Count leading tabs on the second line (first line after opening quote)
131
+ if len(lines) > 1 and lines[1]:
132
+ # Count leading tabs (file indentation)
133
+ file_indent_tabs = len(lines[1]) - len(lines[1].lstrip('\t'))
134
+
135
+ # Remove file indentation tabs from all lines after the first
136
+ normalized_lines = [lines[0]]
137
+ for line in lines[1:]:
138
+ # Remove the file indentation tabs, but keep any additional indentation
139
+ if line.startswith('\t' * file_indent_tabs):
140
+ normalized_lines.append(line[file_indent_tabs:])
141
+ else:
142
+ # Line doesn't have expected file indentation, keep as-is
143
+ normalized_lines.append(line)
144
+ return '\n'.join(normalized_lines)
145
+
146
+ return raw_value
147
+
148
+ def string(self, s):
149
+ # Remove quotes and unescape the content
150
+ return self._unescape_string(s[0][1:-1])
151
+
152
+ def condition(self, items):
153
+ return items[0].strip()
154
+
155
+ def comment(self, items):
156
+ # Extract the comment text (remove the # prefix and any leading/trailing whitespace)
157
+ comment_text = str(items[0]).lstrip('#').strip()
158
+ return {"type": "comment", "text": comment_text}
159
+
160
+ def statement(self, items):
161
+ return items[0]
162
+
163
+ def conditional(self, items):
164
+ # First item is the if condition, rest are if_body statements and else clauses
165
+ result = {
166
+ 'type': 'conditional',
167
+ 'if_condition': items[0],
168
+ 'if_body': [],
169
+ 'else_ifs': [],
170
+ 'else_body': None
171
+ }
172
+
173
+ # Collect if_body statements and else clauses
174
+ i = 1
175
+ # Collect all statements until we hit an else_if or else
176
+ while i < len(items):
177
+ item = items[i]
178
+ if isinstance(item, dict) and item.get('type') in ['else_if_condition', 'else_condition']:
179
+ break
180
+ result['if_body'].append(item)
181
+ i += 1
182
+
183
+ # Process remaining items (else ifs and else)
184
+ while i < len(items):
185
+ item = items[i]
186
+ if isinstance(item, dict):
187
+ if item.get('type') == 'else_if_condition':
188
+ result['else_ifs'].append({
189
+ 'condition': item['condition'],
190
+ 'body': item['body']
191
+ })
192
+ elif item.get('type') == 'else_condition':
193
+ result['else_body'] = item['body']
194
+ i += 1
195
+
196
+ return result
197
+
198
+ def else_if_condition(self, items):
199
+ # First item is condition, rest are body statements
200
+ return {
201
+ 'type': 'else_if_condition',
202
+ 'condition': items[0],
203
+ 'body': items[1:] if len(items) > 1 else []
204
+ }
205
+
206
+ def else_condition(self, items):
207
+ # All items are body statements
208
+ return {
209
+ 'type': 'else_condition',
210
+ 'body': items if items else []
211
+ }
212
+
213
+ def number(self, n):
214
+ return float(n[0]) if '.' in n[0] else int(n[0])
215
+
216
+ def env_var(self, v):
217
+ return {"type": "env_var", "value": v[0]}
218
+
219
+ def array(self, items):
220
+ # Filter out None values that may come from parsing
221
+ return [item for item in items if item is not None]
222
+
223
+ def hash(self, pairs):
224
+ return dict(pairs)
225
+
226
+ def codec_setting(self, items):
227
+ """Transform codec settings into (key, value) tuples."""
228
+ if len(items) >= 2:
229
+ # Handle ESCAPED_STRING tokens for keys - strip quotes
230
+ key = items[0]
231
+ if hasattr(key, 'type') and key.type == 'ESCAPED_STRING':
232
+ key = str(key)[1:-1]
233
+ return (key, items[1])
234
+ elif len(items) == 1:
235
+ key = items[0]
236
+ if hasattr(key, 'type') and key.type == 'ESCAPED_STRING':
237
+ key = str(key)[1:-1]
238
+ return (key, None)
239
+ else:
240
+ return (None, None)
241
+
242
+ def codec_config(self, items):
243
+ """Transform a codec config into a list of tuples."""
244
+ return [item for item in items if item is not None]
245
+
246
+ def codec_pair_with_config(self, items):
247
+ """Handle ``codec => name { config }`` as a nested dict pair."""
248
+ codec_name = str(items[0])
249
+ # items[1] is the codec_config (list of tuples)
250
+ config_list = items[1] if len(items) > 1 and isinstance(items[1], list) else []
251
+
252
+ # Convert list of tuples to dict
253
+ codec_config = {}
254
+ for key, value in config_list:
255
+ codec_config[key] = value
256
+
257
+ # Return as nested dict: {"codec": {"codec_name": {...}}}
258
+ return ("codec", {codec_name: codec_config})
259
+ def codec_pair_simple(self, items):
260
+ """Handle ``codec => simple_value`` as a nested dict with empty config.
261
+
262
+ Example:
263
+ ``codec => "json"`` -> ``("codec", {"json": {}})``
264
+ """
265
+ codec_name = str(items[0])
266
+ # Only unquote plain names; the generator writes codec names back unquoted
267
+ if re.fullmatch(r'(["\'])[A-Za-z0-9_-]+\1', codec_name):
268
+ codec_name = codec_name[1:-1]
269
+ return ("codec", {codec_name: {}})
270
+
271
+ def regular_pair(self, items):
272
+ """Handle regular ``key => value`` pairs."""
273
+ if len(items) >= 2:
274
+ # Handle ESCAPED_STRING tokens for keys - strip quotes
275
+ key = items[0]
276
+ if hasattr(key, 'type') and key.type == 'ESCAPED_STRING':
277
+ key = str(key)[1:-1] # Remove surrounding quotes
278
+ return (key, items[1])
279
+ elif len(items) == 1:
280
+ # Single item - might be a key with no value
281
+ key = items[0]
282
+ if hasattr(key, 'type') and key.type == 'ESCAPED_STRING':
283
+ key = str(key)[1:-1]
284
+ return (key, None)
285
+ else:
286
+ return (None, None)
287
+
288
+ def pair(self, items):
289
+ """Fall back for pair; codec_pair or regular_pair should handle this."""
290
+ if len(items) >= 2:
291
+ key = items[0]
292
+ if hasattr(key, 'type') and key.type == 'ESCAPED_STRING':
293
+ key = str(key)[1:-1]
294
+ return (key, items[1])
295
+ elif len(items) == 1:
296
+ key = items[0]
297
+ if hasattr(key, 'type') and key.type == 'ESCAPED_STRING':
298
+ key = str(key)[1:-1]
299
+ return (key, None)
300
+ else:
301
+ return (None, None)
302
+
303
+ def plugin_item(self, items):
304
+ """Pass through the single child (a pair tuple or a comment dict)."""
305
+ return items[0] if items else None
306
+
307
+ def plugin(self, items):
308
+ name = items[0]
309
+ settings = {}
310
+ comments = []
311
+ # If there are items after the name, they are plugin_items (pairs or comments)
312
+ if len(items) > 1 and items[1]:
313
+ # Flatten the list (handling both direct items and nested lists)
314
+ all_items = []
315
+ for item in items[1:]:
316
+ if isinstance(item, list):
317
+ all_items.extend([i for i in item if i is not None])
318
+ elif item is not None:
319
+ all_items.append(item)
320
+
321
+ for item in all_items:
322
+ # Comment dicts come from the comment() transformer
323
+ if isinstance(item, dict) and item.get('type') == 'comment':
324
+ comments.append(item.get('text', ''))
325
+ continue
326
+
327
+ # Everything else is a pair tuple
328
+ pair = item
329
+ if isinstance(pair, (list, tuple)) and len(pair) == 2:
330
+ k, v = pair
331
+
332
+ # If key already exists, merge the values
333
+ if k in settings:
334
+ existing = settings[k]
335
+
336
+ # Both are dicts: merge them
337
+ if isinstance(existing, dict) and isinstance(v, dict):
338
+ settings[k] = {**existing, **v}
339
+
340
+ # Both are lists: concatenate them
341
+ elif isinstance(existing, list) and isinstance(v, list):
342
+ settings[k] = existing + v
343
+
344
+ # One is a list: append the other to it
345
+ elif isinstance(existing, list):
346
+ settings[k] = existing + [v]
347
+ elif isinstance(v, list):
348
+ settings[k] = [existing] + v
349
+
350
+ # Both are scalars: convert to list
351
+ else:
352
+ settings[k] = [existing, v]
353
+ else:
354
+ settings[k] = v
355
+ return {"type": "plugin", "name": name, "settings": settings, "comments": comments}
356
+
357
+ def section(self, items):
358
+ section_type = items[0]
359
+ statements = items[1:]
360
+ return {"type": section_type, "statements": statements}
361
+
362
+ def input_section(self, _):
363
+ return "input"
364
+
365
+ def filter_section(self, _):
366
+ return "filter"
367
+
368
+ def output_section(self, _):
369
+ return "output"
370
+
371
+ def start(self, items):
372
+ return list(items)
373
+
374
+ def _format_plugin(self, plugin_data, section_type, component_count):
375
+ """Format a plugin with a proper ID and type.
376
+
377
+ Args:
378
+ plugin_data: Parsed plugin dict with a name.
379
+ section_type: Pipeline section (input, filter, or output).
380
+ component_count: Running component index.
381
+
382
+ Returns:
383
+ Tuple of (plugin_dict, next_component_count).
384
+ """
385
+ if not isinstance(plugin_data, dict) or 'name' not in plugin_data:
386
+ return plugin_data, component_count
387
+
388
+ plugin = {
389
+ 'id': f"{section_type}_{plugin_data['name']}_{component_count}",
390
+ 'type': section_type,
391
+ 'plugin': plugin_data['name'],
392
+ 'config': plugin_data.get('settings', {}),
393
+ 'comments': plugin_data.get('comments', [])
394
+ }
395
+ return plugin, component_count + 1
396
+
397
+ def _process_plugins(self, plugins, section_type, component_count, target_list=None):
398
+ """Process a list of plugins, adding IDs and types.
399
+
400
+ Args:
401
+ plugins: Plugin, comment, or conditional dicts.
402
+ section_type: Pipeline section.
403
+ component_count: Running component index.
404
+ target_list: Unused; kept for call-site compatibility.
405
+
406
+ Returns:
407
+ Tuple of (formatted_plugins, next_component_count).
408
+ """
409
+ result = []
410
+ if not plugins:
411
+ return result, component_count
412
+
413
+ if not isinstance(plugins, list):
414
+ plugins = [plugins]
415
+
416
+ for plugin in plugins:
417
+ if not plugin:
418
+ continue
419
+
420
+ if isinstance(plugin, dict):
421
+ if plugin.get('type') == 'comment':
422
+ # It's a comment - convert to comment plugin format
423
+ comment_plugin = {
424
+ 'id': f"{section_type}_comment_{component_count}",
425
+ 'type': section_type,
426
+ 'plugin': 'comment',
427
+ 'config': {
428
+ 'text': plugin.get('text', '')
429
+ }
430
+ }
431
+ result.append(comment_plugin)
432
+ component_count += 1
433
+ elif 'name' in plugin: # It's a regular plugin
434
+ formatted_plugin, component_count = self._format_plugin(plugin, section_type, component_count)
435
+ result.append(formatted_plugin)
436
+ elif plugin.get('type') == 'conditional':
437
+ # For conditionals, just process them and add to result
438
+ conditional_blocks, component_count = self._process_conditional(
439
+ plugin, section_type, None, component_count
440
+ )
441
+ result.extend(conditional_blocks)
442
+
443
+ return result, component_count
444
+
445
+ def _process_conditional(self, cond, section_type, data, component_count):
446
+ """Process a conditional statement into UI component blocks.
447
+
448
+ Args:
449
+ cond: Parsed conditional dict.
450
+ section_type: Pipeline section.
451
+ data: Optional list to append the block to (for nested conditionals).
452
+ component_count: Running component index.
453
+
454
+ Returns:
455
+ Tuple of ([conditional_block], next_component_count).
456
+ """
457
+ # Create the conditional block ID first
458
+ conditional_id = component_count
459
+
460
+ # Process plugins in if body
461
+ if_plugins, component_count = self._process_plugins(
462
+ cond.get('if_body', []), section_type, component_count + 1
463
+ )
464
+
465
+ # Process else if conditions
466
+ else_ifs = []
467
+ for else_if in cond.get('else_ifs', []):
468
+ # Get the condition string from the else_if_condition
469
+ condition = ''
470
+ if isinstance(else_if, dict) and 'condition' in else_if:
471
+ if isinstance(else_if['condition'], dict):
472
+ if 'condition' in else_if['condition']:
473
+ condition = else_if['condition']['condition']
474
+ elif 'value' in else_if['condition']:
475
+ condition = else_if['condition']['value']
476
+ else:
477
+ condition = str(else_if['condition'])
478
+ # Process the plugins in the else if body
479
+ elif_plugins = []
480
+ if 'body' in else_if:
481
+ elif_plugins, component_count = self._process_plugins(
482
+ else_if['body'], section_type, component_count
483
+ )
484
+ # Add to else_ifs list with proper structure
485
+ if condition:
486
+ else_ifs.append({
487
+ 'condition': condition.strip(),
488
+ 'plugins': elif_plugins
489
+ })
490
+
491
+ # Process else condition - only create if it exists
492
+ else_block = None
493
+ if 'else_body' in cond and cond['else_body'] is not None:
494
+ else_plugins, component_count = self._process_plugins(
495
+ cond['else_body'], section_type, component_count
496
+ )
497
+ else_block = {'plugins': else_plugins}
498
+ # Create the conditional block using the original component_count
499
+ conditional_block = {
500
+ 'id': f"{section_type}_if_{conditional_id}",
501
+ 'type': section_type,
502
+ 'plugin': 'if',
503
+ 'config': {
504
+ 'condition': cond['if_condition'],
505
+ 'plugins': if_plugins,
506
+ 'else_ifs': else_ifs,
507
+ 'else': else_block
508
+ }
509
+ }
510
+
511
+ # If data is provided, append to it (for nested conditionals)
512
+ if data is not None:
513
+ data.append(conditional_block)
514
+
515
+ return [conditional_block], component_count
516
+
517
+
518
+ def _extract_error_context(config_text: str, line: int, column: int, context_lines: int = 3) -> str:
519
+ """Extract the code context around an error location.
520
+
521
+ Args:
522
+ config_text: Full config text.
523
+ line: Line number where the error occurred (1-indexed).
524
+ column: Column number where the error occurred (1-indexed).
525
+ context_lines: Number of lines to show before and after the error.
526
+
527
+ Returns:
528
+ Formatted string showing the error context with a pointer.
529
+ """
530
+ lines = config_text.split('\n')
531
+
532
+ # Calculate the range of lines to show
533
+ start_line = max(0, line - context_lines - 1)
534
+ end_line = min(len(lines), line + context_lines)
535
+
536
+ # Build the context string
537
+ context_parts = []
538
+ context_parts.append("\n" + "="*60)
539
+ context_parts.append("PROBLEMATIC CODE:")
540
+ context_parts.append("="*60)
541
+
542
+ for i in range(start_line, end_line):
543
+ line_num = i + 1
544
+ line_content = lines[i]
545
+
546
+ # Mark the error line with an arrow
547
+ if line_num == line:
548
+ context_parts.append(f">>> {line_num:4d} | {line_content}")
549
+ # Add a pointer to the exact column
550
+ if column > 0:
551
+ pointer = " " * (len(f">>> {line_num:4d} | ") + column - 1) + "^"
552
+ context_parts.append(pointer)
553
+ else:
554
+ context_parts.append(f" {line_num:4d} | {line_content}")
555
+
556
+ context_parts.append("="*60)
557
+ return "\n".join(context_parts)
558
+
559
+
560
+ def _count_unquoted_braces(line: str):
561
+ """Count ``{`` and ``}`` that appear outside quoted strings and escape sequences."""
562
+ open_count = 0
563
+ close_count = 0
564
+ in_str = False
565
+ str_char = None
566
+ esc = False
567
+ for ch in line:
568
+ if esc:
569
+ esc = False
570
+ continue
571
+ if ch == '\\':
572
+ esc = True
573
+ continue
574
+ if ch in ('"', "'"):
575
+ if not in_str:
576
+ in_str = True
577
+ str_char = ch
578
+ elif ch == str_char:
579
+ in_str = False
580
+ str_char = None
581
+ continue
582
+ if not in_str:
583
+ if ch == '{':
584
+ open_count += 1
585
+ elif ch == '}':
586
+ close_count += 1
587
+ return open_count, close_count
588
+
589
+
590
+ def _ends_in_open_double_quote(line: str, in_dq: bool) -> bool:
591
+ """Track a double-quoted string that spans lines.
592
+
593
+ Args:
594
+ line: One raw config line.
595
+ in_dq: Whether the line starts inside an open double-quoted string.
596
+
597
+ Returns:
598
+ Whether the line ends inside an open double-quoted string.
599
+
600
+ Example:
601
+ ``_ends_in_open_double_quote('code => "', False)`` -> ``True``
602
+ ``_ends_in_open_double_quote(' # ruby "', True)`` -> ``False``
603
+ """
604
+ in_sq = False
605
+ esc = False
606
+ for ch in line:
607
+ if esc:
608
+ esc = False
609
+ elif ch == '\\':
610
+ esc = True
611
+ elif in_dq:
612
+ if ch == '"':
613
+ in_dq = False
614
+ elif in_sq:
615
+ if ch == "'":
616
+ in_sq = False
617
+ elif ch == '"':
618
+ in_dq = True
619
+ elif ch == "'":
620
+ in_sq = True
621
+ elif ch == '#':
622
+ break
623
+ return in_dq
624
+
625
+
626
+ def _strip_line_comment(line: str):
627
+ """Strip an inline # comment from a line, ignoring # inside quoted strings.
628
+
629
+ Returns:
630
+ Tuple of (cleaned_line, comment_text_or_None, ends_in_unclosed_single_quote).
631
+ """
632
+ cleaned = []
633
+ comment_text = None
634
+ in_str = False
635
+ str_char = None
636
+ esc = False
637
+
638
+ for i, ch in enumerate(line):
639
+ if esc:
640
+ cleaned.append(ch)
641
+ esc = False
642
+ continue
643
+ if ch == '\\':
644
+ cleaned.append(ch)
645
+ esc = True
646
+ continue
647
+ if ch in ('"', "'"):
648
+ if not in_str:
649
+ in_str = True
650
+ str_char = ch
651
+ cleaned.append(ch)
652
+ elif ch == str_char:
653
+ in_str = False
654
+ str_char = None
655
+ cleaned.append(ch)
656
+ else:
657
+ cleaned.append(ch)
658
+ continue
659
+ if ch == '#' and not in_str:
660
+ text = line[i:].lstrip('#').strip()
661
+ comment_text = text if text else None
662
+ while cleaned and cleaned[-1] in (' ', '\t'):
663
+ cleaned.pop()
664
+ break
665
+ cleaned.append(ch)
666
+
667
+ return ''.join(cleaned), comment_text, (in_str and str_char == "'")
668
+
669
+
670
+ def _strip_inline_comments(config_text: str) -> str:
671
+ """Preprocess Logstash config text before grammar parsing.
672
+
673
+ Behaviour by context:
674
+ - INSIDE PLUGIN BLOCKS: inline comments (on any line, at any brace depth)
675
+ are stripped from the line and collected. They are injected as standalone
676
+ # comment lines immediately before the plugin's closing brace, where the
677
+ grammar can parse them and attach them to the plugin as plugin.comments[].
678
+ Standalone # lines inside a plugin block are preserved in place.
679
+ - OUTSIDE PLUGIN BLOCKS (sections, conditionals): standalone # comment lines
680
+ are preserved unchanged. Inline comments on non-plugin lines are stripped
681
+ and discarded (they would break the grammar and carry no useful context).
682
+ - MULTILINE SINGLE-QUOTED STRINGS: passed through completely unchanged —
683
+ # characters inside them are not comments.
684
+
685
+ Args:
686
+ config_text: Raw Logstash configuration text.
687
+
688
+ Returns:
689
+ Config text with inline comments relocated or stripped for the grammar.
690
+ """
691
+ lines = config_text.split('\n')
692
+ result_lines = []
693
+
694
+ # outer_stack tracks section/conditional blocks only, for standalone-comment
695
+ # preservation decisions outside plugin blocks.
696
+ outer_stack = [] # entries: 'section' | 'conditional'
697
+
698
+ # Plugin block tracking (separate from outer_stack).
699
+ in_plugin = False
700
+ plugin_brace_depth = 0 # net open braces inside the current plugin block
701
+ pending_plugin_comments = [] # inline comments collected from the current plugin
702
+ in_dq_string = False # inside a "..." string that spans lines
703
+
704
+ in_multiline_string = False
705
+
706
+ for line in lines:
707
+ stripped = line.lstrip()
708
+
709
+ # ── Multiline single-quoted string passthrough ────────────────────────
710
+ if in_multiline_string:
711
+ esc = False
712
+ for ch in line:
713
+ if esc:
714
+ esc = False
715
+ continue
716
+ if ch == '\\':
717
+ esc = True
718
+ continue
719
+ if ch == "'":
720
+ in_multiline_string = False
721
+ break
722
+ result_lines.append(line)
723
+ continue
724
+
725
+ # ── INSIDE A PLUGIN BLOCK ─────────────────────────────────────────────
726
+ if in_plugin:
727
+ # Standalone comment lines are valid at plugin scope (grammar supports
728
+ # them after the grammar change) — keep them as-is. Inside nested
729
+ # blocks (codec => x { }, hashes) the grammar has no comment rule, so
730
+ # relocate them to plugin scope like inline comments. Lines inside a
731
+ # multi-line "..." string (e.g. ruby code) are content, not comments.
732
+ starts_in_dq = in_dq_string
733
+ in_dq_string = _ends_in_open_double_quote(line, in_dq_string)
734
+ if stripped.startswith('#'):
735
+ if plugin_brace_depth > 1 and not starts_in_dq:
736
+ text = stripped.lstrip('#').strip()
737
+ if text:
738
+ pending_plugin_comments.append(text)
739
+ else:
740
+ result_lines.append(line)
741
+ continue
742
+
743
+ # Strip inline comment, track multiline strings.
744
+ cleaned_line, inline_comment, ends_in_sq = _strip_line_comment(line)
745
+ if ends_in_sq:
746
+ in_multiline_string = True
747
+
748
+ # Count braces on the CLEANED line to maintain plugin depth.
749
+ brace_open, brace_close = _count_unquoted_braces(cleaned_line)
750
+ plugin_brace_depth += brace_open - brace_close
751
+
752
+ if plugin_brace_depth <= 0:
753
+ # This line closes the plugin block.
754
+ plugin_brace_depth = 0
755
+ indent = ' ' * (len(line) - len(line.lstrip()))
756
+ # Inject all collected inline comments before the closing }.
757
+ for c in pending_plugin_comments:
758
+ result_lines.append(f'{indent}\t# {c}')
759
+ pending_plugin_comments = []
760
+ in_plugin = False
761
+ result_lines.append(cleaned_line)
762
+ # If the closing } itself had an inline comment, emit it at outer
763
+ # scope so the grammar picks it up as a section-level comment.
764
+ if inline_comment:
765
+ result_lines.append(f'{indent}# {inline_comment}')
766
+ else:
767
+ # Still inside plugin — collect inline comment, emit cleaned line.
768
+ if inline_comment:
769
+ pending_plugin_comments.append(inline_comment)
770
+ result_lines.append(cleaned_line)
771
+
772
+ continue
773
+
774
+ # ── OUTSIDE PLUGIN BLOCKS ─────────────────────────────────────────────
775
+
776
+ # Detect section / conditional openers for outer_stack.
777
+ if stripped.startswith(('input {', 'filter {', 'output {')):
778
+ outer_stack.append('section')
779
+ # If the section opener has an inline comment (e.g. "filter {# here2}"),
780
+ # strip it from the opener and re-emit it as a standalone comment line
781
+ # so the grammar picks it up as a section-level comment plugin.
782
+ cleaned_opener, section_opener_comment, ends_in_sq = _strip_line_comment(line)
783
+ if ends_in_sq:
784
+ in_multiline_string = True
785
+ result_lines.append(cleaned_opener)
786
+ if section_opener_comment:
787
+ result_lines.append(f'# {section_opener_comment}')
788
+ continue
789
+ elif not stripped.startswith('#'):
790
+ if stripped.startswith('if ') and '{' in line:
791
+ outer_stack.append('conditional')
792
+ elif stripped.startswith('else if ') and '{' in line:
793
+ outer_stack.append('conditional')
794
+ elif stripped.startswith('else {'):
795
+ outer_stack.append('conditional')
796
+ elif '{' in line and not stripped.startswith('}'):
797
+ pre_brace = line.split('{')[0]
798
+ if '=>' not in pre_brace:
799
+ # Plugin opener (e.g. "mutate {").
800
+ # Strip any inline comment from the opener line and begin tracking.
801
+ cleaned_opener, opener_comment, ends_in_sq = _strip_line_comment(line)
802
+ if ends_in_sq:
803
+ in_multiline_string = True
804
+
805
+ in_plugin = True
806
+ in_dq_string = False
807
+ pending_plugin_comments = []
808
+ if opener_comment:
809
+ pending_plugin_comments.append(opener_comment)
810
+
811
+ # Count braces on the cleaned opener to set initial depth.
812
+ brace_open, brace_close = _count_unquoted_braces(cleaned_opener)
813
+ plugin_brace_depth = brace_open - brace_close
814
+
815
+ if plugin_brace_depth <= 0:
816
+ # Single-line plugin like "drop { }" — already closed.
817
+ plugin_brace_depth = 0
818
+ indent = ' ' * (len(line) - len(line.lstrip()))
819
+ for c in pending_plugin_comments:
820
+ result_lines.append(f'{indent}\t# {c}')
821
+ pending_plugin_comments = []
822
+ in_plugin = False
823
+
824
+ result_lines.append(cleaned_opener)
825
+ continue
826
+
827
+ # Count closing braces to pop outer_stack (skip comment lines — braces
828
+ # inside # comments are not structural).
829
+ if not stripped.startswith('#'):
830
+ _, close_count = _count_unquoted_braces(line)
831
+ for _ in range(close_count):
832
+ if outer_stack:
833
+ outer_stack.pop()
834
+
835
+ # Standalone comment lines outside plugin blocks: preserve unchanged.
836
+ if stripped.startswith('#'):
837
+ result_lines.append(line)
838
+ continue
839
+
840
+ # Non-comment lines outside plugin blocks: strip inline comments and emit.
841
+ cleaned_line, _, ends_in_sq = _strip_line_comment(line)
842
+ if ends_in_sq:
843
+ in_multiline_string = True
844
+ result_lines.append(cleaned_line)
845
+
846
+ return '\n'.join(result_lines)
847
+
848
+
849
+ def parse_logstash_config(config_text: str) -> List[Dict[str, Any]]:
850
+ """Parse Logstash config text into a structured format.
851
+
852
+ Args:
853
+ config_text: Raw Logstash configuration text.
854
+
855
+ Returns:
856
+ List of section and comment dicts from the Lark transformer.
857
+
858
+ Raises:
859
+ ValueError: If the config cannot be parsed.
860
+ """
861
+ # Preprocess to remove inline comments that would break parsing
862
+ config_text = _strip_inline_comments(config_text)
863
+
864
+ parser = Lark(LOGSTASH_GRAMMAR, parser='lalr', transformer=LogstashTransformer())
865
+ try:
866
+ return parser.parse(config_text)
867
+ except UnexpectedToken as e:
868
+ # Extract detailed error information
869
+ error_line = e.line
870
+ error_column = e.column
871
+
872
+ # Get the code context
873
+ context = _extract_error_context(config_text, error_line, error_column)
874
+
875
+ # Build a detailed error message
876
+ error_msg = f"Failed to parse Logstash config at line {error_line}, column {error_column}\n"
877
+ error_msg += f"Unexpected token: {e.token}\n"
878
+ error_msg += f"Expected one of: {', '.join(e.expected)}\n"
879
+ error_msg += context
880
+
881
+ raise ValueError(error_msg)
882
+ except UnexpectedCharacters as e:
883
+ # Extract detailed error information
884
+ error_line = e.line
885
+ error_column = e.column
886
+
887
+ # Get the code context
888
+ context = _extract_error_context(config_text, error_line, error_column)
889
+
890
+ # Build a detailed error message
891
+ error_msg = f"Failed to parse Logstash config at line {error_line}, column {error_column}\n"
892
+ error_msg += f"Unexpected character(s): {config_text[e.pos_in_stream:e.pos_in_stream+10]}\n"
893
+ error_msg += f"Expected one of: {', '.join(e.allowed)}\n"
894
+ error_msg += context
895
+
896
+ raise ValueError(error_msg)
897
+ except Exception as e:
898
+ # Fallback for other errors
899
+ raise ValueError(f"Failed to parse Logstash config: {str(e)}")
900
+
901
+
902
+ def logstash_config_to_components(config_text: str) -> List[Dict[str, Any]]:
903
+ """Convert Logstash configuration text to UI components format.
904
+
905
+ Args:
906
+ config_text: Raw Logstash configuration text.
907
+
908
+ Returns:
909
+ JSON string of component dictionaries in the UI format, keyed by
910
+ input, filter, and output.
911
+
912
+ Raises:
913
+ Exception: If conversion fails; the view surfaces the message to the user.
914
+ """
915
+ try:
916
+ parsed = parse_logstash_config(config_text)
917
+
918
+ # Initialize data with all three sections (even if not in input)
919
+ data = {
920
+ "input": [],
921
+ "filter": [],
922
+ "output": []
923
+ }
924
+
925
+ component_count = 0
926
+ transformer = LogstashTransformer()
927
+
928
+ # Handle case where parsed might not be a list or could be empty
929
+ if not isinstance(parsed, list):
930
+ parsed = [parsed] if parsed else []
931
+
932
+ # Walk parsed items in order.
933
+ # - Comments before the first section → input
934
+ # - Comments between input and filter → filter
935
+ # - Comments between filter and output → output
936
+ # - Trailing comments after the last section → last section seen
937
+ # Consecutive inter-section comments are grouped into a single comment plugin.
938
+ last_section_type = 'input'
939
+ pending_toplevel_comments = []
940
+
941
+ def _flush_toplevel_comments(target_section):
942
+ nonlocal component_count
943
+ if not pending_toplevel_comments:
944
+ return
945
+ comment_texts = [c.get('text', '') for c in pending_toplevel_comments]
946
+ data[target_section].append({
947
+ 'id': f"{target_section}_comment_{component_count}",
948
+ 'type': target_section,
949
+ 'plugin': 'comment',
950
+ 'config': {'text': '\n'.join(comment_texts)},
951
+ })
952
+ component_count += 1
953
+ pending_toplevel_comments.clear()
954
+
955
+ for item in parsed:
956
+ if isinstance(item, dict) and item.get('type') == 'comment':
957
+ # Buffer the comment; will be flushed when the next section is seen.
958
+ pending_toplevel_comments.append(item)
959
+ continue
960
+
961
+ section = item
962
+
963
+ # Defensive checks
964
+ if not isinstance(section, dict):
965
+ logger.warning(f"Skipping non-dict section: {type(section)}")
966
+ continue
967
+ if 'type' not in section:
968
+ logger.warning(f"Section missing 'type' key: {section}")
969
+ continue
970
+
971
+ section_type = section['type']
972
+ if section_type not in ['input', 'filter', 'output']:
973
+ logger.warning(f"Warning: Unknown section type '{section_type}', skipping")
974
+ continue
975
+
976
+ # Flush any buffered inter-section comments into THIS section.
977
+ _flush_toplevel_comments(section_type)
978
+ last_section_type = section_type
979
+
980
+ section_components = []
981
+
982
+ # Group consecutive comments together
983
+ statements = section.get('statements', [])
984
+ i = 0
985
+ while i < len(statements):
986
+ stmt = statements[i]
987
+ if not isinstance(stmt, dict):
988
+ i += 1
989
+ continue
990
+
991
+ if stmt.get('type') == 'comment':
992
+ # Start collecting consecutive comments
993
+ comment_texts = [stmt.get('text', '')]
994
+ i += 1
995
+
996
+ # Look ahead for more consecutive comments
997
+ while i < len(statements) and isinstance(statements[i], dict) and statements[i].get('type') == 'comment':
998
+ comment_texts.append(statements[i].get('text', ''))
999
+ i += 1
1000
+
1001
+ # Create a single comment component with all lines joined
1002
+ comment_plugin = {
1003
+ 'id': f"{section_type}_comment_{component_count}",
1004
+ 'type': section_type,
1005
+ 'plugin': 'comment',
1006
+ 'config': {
1007
+ 'text': '\n'.join(comment_texts)
1008
+ }
1009
+ }
1010
+ section_components.append(comment_plugin)
1011
+ component_count += 1
1012
+ elif 'name' in stmt: # It's a regular plugin
1013
+ component, component_count = transformer._format_plugin(stmt, section_type, component_count)
1014
+ section_components.append(component)
1015
+ i += 1
1016
+ elif stmt.get('type') == 'conditional':
1017
+ # Process conditional and get the updated component count
1018
+ # Pass None as the data parameter to prevent auto-adding to the section
1019
+ conditional_blocks, component_count = transformer._process_conditional(
1020
+ stmt, section_type, None, component_count
1021
+ )
1022
+ section_components.extend(conditional_blocks)
1023
+ i += 1
1024
+ else:
1025
+ i += 1
1026
+
1027
+ # Add all components to the section
1028
+ data[section_type].extend(section_components)
1029
+
1030
+ # Flush any trailing comments (after the last section) into the last section seen.
1031
+ _flush_toplevel_comments(last_section_type)
1032
+
1033
+ return json.dumps(data, indent=4)
1034
+
1035
+ except Exception as e:
1036
+ # Re-raise the exception so the view can handle it and show to the user
1037
+ error_msg = str(e)
1038
+ logger.error(f"Error converting config to components: {error_msg}")
1039
+ raise Exception(f"Error converting config to components: {error_msg}")
1040
+
1041
+
1042
+ ################################ Component JSON to Logstash config ################################
1043
+
1044
+ class ComponentToPipeline:
1045
+ """Convert UI component JSON back into Logstash pipeline config text."""
1046
+
1047
+ def __init__(self, components, test=False, add_ids=False):
1048
+ """Initialize a converter for a component tree.
1049
+
1050
+ Args:
1051
+ components: Mapping of section name (input/filter/output) to a list
1052
+ of component dicts.
1053
+ test: If True, replace input/output with stdin/stdout for simulation.
1054
+ add_ids: If True, inject generated ``id =>`` settings when missing.
1055
+ """
1056
+ self.components = components
1057
+ self.plugin_num = 0
1058
+ self.test = test
1059
+ self.add_ids = add_ids
1060
+ self.plugin_counters = {} # Track plugin counts for ID generation
1061
+
1062
+ def _generate_plugin_id(self, plugin_name, section):
1063
+ """Generate a predictable, reusable ID for a plugin.
1064
+
1065
+ Args:
1066
+ plugin_name: Plugin type name.
1067
+ section: Pipeline section.
1068
+
1069
+ Returns:
1070
+ ID in the form ``section_pluginname_count``.
1071
+ """
1072
+ # Create a counter key for this plugin type in this section
1073
+ counter_key = f"{section}_{plugin_name}"
1074
+
1075
+ # Increment the counter for this plugin type
1076
+ if counter_key not in self.plugin_counters:
1077
+ self.plugin_counters[counter_key] = 0
1078
+
1079
+ self.plugin_counters[counter_key] += 1
1080
+
1081
+ # Generate ID in format: section_pluginname_count
1082
+ return f"{section}_{plugin_name}_{self.plugin_counters[counter_key]}"
1083
+
1084
+ def _format_hash_block(self, d, indent):
1085
+ """Recursively format a Python dict as a Logstash hash block.
1086
+
1087
+ Returns a string starting with '{' and ending with '}' (no trailing newline),
1088
+ suitable for inline use after a '=>' on the same line.
1089
+
1090
+ Args:
1091
+ d: Dict to format.
1092
+ indent: Tab depth of the opening-brace line. Inner pairs are at
1093
+ indent+1, and the closing brace is at indent.
1094
+
1095
+ Returns:
1096
+ Logstash hash block string.
1097
+ """
1098
+ tabs = '\t' * indent
1099
+ inner_tabs = '\t' * (indent + 1)
1100
+ lines = ['{']
1101
+ for k, v in d.items():
1102
+ if isinstance(v, dict):
1103
+ nested = self._format_hash_block(v, indent + 1)
1104
+ lines.append(f'{inner_tabs}"{k}" => {nested}')
1105
+ elif isinstance(v, bool):
1106
+ lines.append(f'{inner_tabs}"{k}" => {str(v).lower()}')
1107
+ elif isinstance(v, (int, float)):
1108
+ lines.append(f'{inner_tabs}"{k}" => {v}')
1109
+ else:
1110
+ lines.append(f'{inner_tabs}"{k}" => {self._format_string_value(v)}')
1111
+ lines.append(f'{tabs}}}')
1112
+ return '\n'.join(lines)
1113
+
1114
+ def _format_string_value(self, value):
1115
+ """Format a string value for Logstash config, choosing appropriate quoting.
1116
+
1117
+ If the string contains double quotes (like JSON or Ruby code), use single
1118
+ quotes. Otherwise, use double quotes and escape as needed.
1119
+ """
1120
+ if not isinstance(value, str):
1121
+ return value
1122
+
1123
+ # For multiline strings (like Ruby code), use single quotes to preserve literal newlines/tabs
1124
+ # Single quotes in Logstash don't interpret escape sequences, so \n stays as actual newline
1125
+ if '\n' in value:
1126
+ # Multiline with newlines - use single quotes if possible
1127
+ if "'" not in value:
1128
+ return f"'{value}'"
1129
+ # Has single quotes - escape them and use single quotes
1130
+ escaped_value = value.replace("'", "\\'")
1131
+ return f"'{escaped_value}'"
1132
+
1133
+ # If string contains double quotes but no single quotes, use single quotes
1134
+ if '"' in value and "'" not in value:
1135
+ return f"'{value}'"
1136
+
1137
+ # If string contains single quotes but no double quotes, use double quotes (no escaping needed)
1138
+ if "'" in value and '"' not in value:
1139
+ return f'"{value}"'
1140
+
1141
+ # If string contains both or neither, use double quotes and escape double quotes
1142
+ # Also handle backslashes properly
1143
+ result = []
1144
+ i = 0
1145
+ while i < len(value):
1146
+ if value[i] == '"':
1147
+ result.append('\\"')
1148
+ i += 1
1149
+ elif value[i] == '\\' and i + 1 < len(value):
1150
+ next_char = value[i + 1]
1151
+ # Only escape backslash if it's followed by a char that creates an escape sequence
1152
+ # in double-quoted strings: \", \\
1153
+ if next_char in ['"', '\\']:
1154
+ result.append('\\\\')
1155
+ else:
1156
+ # Keep backslash as-is for patterns like \[, \], \d, \s, etc.
1157
+ result.append('\\')
1158
+ i += 1
1159
+ else:
1160
+ result.append(value[i])
1161
+ i += 1
1162
+ return f'"{"".join(result)}"'
1163
+
1164
+ def _extract_plugin_values(self, plugin, section):
1165
+ config = ""
1166
+ # Setup testing
1167
+
1168
+ if section == "filter" and self.test == True:
1169
+ config += f"\tif [plugin_num] >= {self.plugin_num} {{\n"
1170
+ config += f'{plugin["plugin"]} {{\n'
1171
+
1172
+ # Serialize any comments that were collected from this plugin block
1173
+ for comment_text in plugin.get('comments', []):
1174
+ config += f'\t# {comment_text}\n'
1175
+
1176
+ # Add ID if requested and not already present
1177
+ if self.add_ids and 'id' not in plugin.get('config', {}):
1178
+ generated_id = self._generate_plugin_id(plugin['plugin'], section)
1179
+ config += f'\tid => "{generated_id}"\n'
1180
+
1181
+ for plugin_config_name in plugin['config']:
1182
+ plugin_config_value = plugin['config'][plugin_config_name]
1183
+
1184
+
1185
+ if type(plugin_config_value) in [str, int, float]:
1186
+ if type(plugin_config_value) is str:
1187
+ formatted_value = self._format_string_value(plugin_config_value)
1188
+ config += f'\t{plugin_config_name} => {formatted_value}\n'
1189
+ else:
1190
+ # Write numeric values without quotes to preserve their type
1191
+ config += f'\t{plugin_config_name} => {plugin_config_value}\n'
1192
+
1193
+ elif type(plugin_config_value) is dict and plugin_config_name == "codec":
1194
+ # Special handling for codec: {"codec_name": {config}}
1195
+ for codec_name, codec_config in plugin_config_value.items():
1196
+ if codec_config:
1197
+ # Codec with configuration
1198
+ config += f"\t{plugin_config_name} => {codec_name} {{\n"
1199
+ for codec_key, codec_value in codec_config.items():
1200
+ if type(codec_value) in [str]:
1201
+ formatted_value = self._format_string_value(codec_value)
1202
+ config += f'\t\t{codec_key} => {formatted_value}\n'
1203
+ elif type(codec_value) is bool:
1204
+ config += f'\t\t{codec_key} => {str(codec_value).lower()}\n'
1205
+ elif type(codec_value) in [int, float]:
1206
+ config += f'\t\t{codec_key} => {codec_value}\n'
1207
+ elif type(codec_value) is dict:
1208
+ # Nested hash in codec
1209
+ nested = ', '.join([f'"{k}" => {self._format_string_value(v)}' for k, v in codec_value.items()])
1210
+ config += f'\t\t{codec_key} => {{ {nested} }}\n'
1211
+ else:
1212
+ config += f'\t\t{codec_key} => {json.dumps(codec_value)}\n'
1213
+ config += "\t}\n"
1214
+ else:
1215
+ # Codec without configuration
1216
+ config += f"\t{plugin_config_name} => {codec_name}\n"
1217
+
1218
+ elif type(plugin_config_value) is dict:
1219
+ # Regular dict (not codec)
1220
+ config += f"\t{plugin_config_name} => {{\n"
1221
+
1222
+ for dict_key in plugin_config_value:
1223
+ dict_value = plugin_config_value[dict_key]
1224
+ # Handle different value types within dictionaries
1225
+ if type(dict_value) is list:
1226
+ # Format list with proper indentation and line breaks
1227
+ config += f'\t\t"{dict_key}" => [\n'
1228
+ for i, item in enumerate(dict_value):
1229
+ comma = "," if i < len(dict_value) - 1 else ""
1230
+ if type(item) is str:
1231
+ formatted_item = self._format_string_value(item)
1232
+ config += f'\t\t\t{formatted_item}{comma}\n'
1233
+ else:
1234
+ config += f'\t\t\t{json.dumps(item)}{comma}\n'
1235
+ config += "\t\t]\n"
1236
+ elif type(dict_value) is dict:
1237
+ block = self._format_hash_block(dict_value, indent=2)
1238
+ config += f'\t\t"{dict_key}" => {block}\n'
1239
+ elif type(dict_value) is bool:
1240
+ config += f'\t\t"{dict_key}" => {str(dict_value).lower()}\n'
1241
+ elif type(dict_value) in [int, float]:
1242
+ config += f'\t\t"{dict_key}" => {dict_value}\n'
1243
+ else:
1244
+ formatted_dict_value = self._format_string_value(dict_value)
1245
+ config += f'\t\t"{dict_key}" => {formatted_dict_value}\n'
1246
+
1247
+ config += "\t}\n"
1248
+ elif type(plugin_config_value) is list:
1249
+ # Check if this is an array of hashes (list of dictionaries)
1250
+ if plugin_config_value and isinstance(plugin_config_value[0], dict):
1251
+ # Array of hashes - format each hash using Logstash syntax
1252
+ config += f"\t{plugin_config_name} => [\n"
1253
+ for i, hash_item in enumerate(plugin_config_value):
1254
+ # Build the hash content
1255
+ hash_pairs = []
1256
+ for key, value in hash_item.items():
1257
+ if isinstance(value, str):
1258
+ formatted_value = self._format_string_value(value)
1259
+ hash_pairs.append(f'{key} => {formatted_value}')
1260
+ elif isinstance(value, bool):
1261
+ hash_pairs.append(f'{key} => {str(value).lower()}')
1262
+ elif isinstance(value, (int, float)):
1263
+ hash_pairs.append(f'{key} => {value}')
1264
+ else:
1265
+ # Fallback to JSON for complex types
1266
+ hash_pairs.append(f'{key} => {json.dumps(value)}')
1267
+
1268
+ # Join pairs with spaces and wrap in braces
1269
+ hash_content = ' '.join(hash_pairs)
1270
+ # Add comma after each entry except the last one
1271
+ comma = ',' if i < len(plugin_config_value) - 1 else ''
1272
+ config += f"\t\t{{ {hash_content} }}{comma}\n"
1273
+ config += "\t]\n"
1274
+ else:
1275
+ # Regular array - use JSON format
1276
+ config += "\t" + plugin_config_name + " => " + json.dumps(plugin_config_value) + "\n"
1277
+ elif type(plugin_config_value) is bool:
1278
+
1279
+ config += f'\t{plugin_config_name} => {str(plugin_config_value).lower()}\n'
1280
+
1281
+ # Closes the plugin
1282
+ config += "}\n"
1283
+
1284
+ if section == "filter" and self.test == True:
1285
+ config += "\t}\n"
1286
+
1287
+ self.plugin_num += 1
1288
+ return config
1289
+
1290
+ def _add_tab_level(self, input, skip_string_content=False):
1291
+ lines = input.split('\n')
1292
+ result = []
1293
+ in_multiline_string = False
1294
+ skip_this_string = False
1295
+
1296
+ for i, line in enumerate(lines):
1297
+ # Determine if we should add a tab to this line BEFORE updating state
1298
+ should_add_tab = True
1299
+
1300
+ # Check if we should skip this line (if we're inside a code/script/body string)
1301
+ if skip_this_string and in_multiline_string and 'code =>' not in line and 'script =>' not in line and 'body =>' not in line:
1302
+ should_add_tab = False
1303
+
1304
+ # Now check if this line starts or continues a multi-line string
1305
+ if '=>' in line and '"' in line:
1306
+ # Check if this is a code/script/body parameter
1307
+ if 'code =>' in line or 'script =>' in line or 'body =>' in line:
1308
+ skip_this_string = True
1309
+
1310
+ # Count quotes after the =>
1311
+ after_arrow = line.split('=>', 1)[1] if '=>' in line else line
1312
+ quote_count = after_arrow.count('"')
1313
+ # Odd number of quotes means we're starting/ending a multi-line string
1314
+ if quote_count % 2 == 1:
1315
+ in_multiline_string = not in_multiline_string
1316
+ if not in_multiline_string:
1317
+ skip_this_string = False # Reset when exiting string
1318
+ elif '"' in line:
1319
+ # Check if this line ends the multi-line string
1320
+ quote_count = line.count('"')
1321
+ if quote_count % 2 == 1:
1322
+ in_multiline_string = not in_multiline_string
1323
+ if not in_multiline_string:
1324
+ skip_this_string = False # Reset when exiting string
1325
+
1326
+ # Add tab unless we're skipping or it's the last empty line
1327
+ if not should_add_tab:
1328
+ result.append(line)
1329
+ elif line or i < len(lines) - 1:
1330
+ result.append('\t' + line)
1331
+ else:
1332
+ result.append(line)
1333
+
1334
+ return '\n'.join(result)
1335
+
1336
+ def _extract_condition_values(self, condition, section):
1337
+ config = ""
1338
+
1339
+ # --- Start if ---
1340
+ config += f"if {condition['config']['condition']} {{\n"
1341
+ for plugin in condition['config']['plugins']:
1342
+ if plugin['plugin'] == 'comment':
1343
+ # Handle comment inside conditional
1344
+ comment_text = plugin['config'].get('text', '')
1345
+ comment_lines = comment_text.split('\n')
1346
+ for line in comment_lines:
1347
+ config += f"\t# {line}\n"
1348
+ elif plugin['plugin'] == 'if':
1349
+ config += self._add_tab_level(self._extract_condition_values(plugin, section))
1350
+ else:
1351
+ config += self._add_tab_level(self._extract_plugin_values(plugin, section))
1352
+ config += "}\n"
1353
+
1354
+ # --- Start else if ---
1355
+ if condition['config'].get('else_ifs'):
1356
+ for plugin in condition['config']['else_ifs']:
1357
+ config += f"else if {plugin['condition']} {{\n"
1358
+ for nested_plugin in plugin['plugins']:
1359
+ if nested_plugin['plugin'] == 'comment':
1360
+ # Handle comment inside else if
1361
+ comment_text = nested_plugin['config'].get('text', '')
1362
+ comment_lines = comment_text.split('\n')
1363
+ for line in comment_lines:
1364
+ config += f"\t# {line}\n"
1365
+ elif nested_plugin['plugin'] == 'if':
1366
+ config += self._add_tab_level(self._extract_condition_values(nested_plugin, section))
1367
+ else:
1368
+ config += self._add_tab_level(self._extract_plugin_values(nested_plugin, section))
1369
+ config += "}\n"
1370
+
1371
+ # --- Start else ---
1372
+ if condition['config'].get('else') and condition['config']['else'].get('plugins'):
1373
+ config += f"else {{\n"
1374
+
1375
+ for plugin in condition['config']['else']['plugins']:
1376
+ if plugin['plugin'] == 'comment':
1377
+ # Handle comment inside else
1378
+ comment_text = plugin['config'].get('text', '')
1379
+ comment_lines = comment_text.split('\n')
1380
+ for line in comment_lines:
1381
+ config += f"\t# {line}\n"
1382
+ elif plugin['plugin'] == 'if':
1383
+ config += self._add_tab_level(self._extract_condition_values(plugin, section))
1384
+ else:
1385
+ config += self._add_tab_level(self._extract_plugin_values(plugin, section))
1386
+ config += "}\n"
1387
+
1388
+ return config
1389
+
1390
+
1391
+
1392
+ def components_to_logstash_config(self):
1393
+ """Render the component tree as Logstash pipeline config text.
1394
+
1395
+ When test is True, input and output are replaced with stdin/stdout codecs
1396
+ so a simulation can send events in and read them back.
1397
+
1398
+ Returns:
1399
+ Pipeline config string with input, filter, and output sections.
1400
+ """
1401
+ config = ""
1402
+ # "test" is used for simulating pipelines so that we can send input via stdin
1403
+ # and receive output via stdout
1404
+ if self.test:
1405
+ self.components['components']['input'] = [{
1406
+ 'id': 'stdin',
1407
+ 'type': 'input',
1408
+ 'plugin': 'stdin',
1409
+ 'config': {
1410
+ "codec": {"json": {}}
1411
+ }
1412
+ }]
1413
+ self.components['components']['output'] = [{
1414
+ 'id': 'stdout',
1415
+ 'type': 'output',
1416
+ 'plugin': 'stdout',
1417
+ 'config': {
1418
+ "codec": {"json_lines": {}}
1419
+ }
1420
+ }]
1421
+
1422
+ for section in self.components:
1423
+ # Adding section, this is static and indentation never changes
1424
+ config += section + " {\n"
1425
+
1426
+ # plugin_num used for running simulations
1427
+ for plugin in self.components[section]:
1428
+ if plugin['plugin'] == 'comment':
1429
+ # Convert comment plugin back to comment lines
1430
+ comment_text = plugin['config'].get('text', '')
1431
+ # Split by newlines and prefix each line with # (with space)
1432
+ comment_lines = comment_text.split('\n')
1433
+ for line in comment_lines:
1434
+ config += f"\t# {line}\n"
1435
+ elif plugin['plugin'] == 'if':
1436
+ config += self._add_tab_level(self._extract_condition_values(plugin, section))
1437
+ else:
1438
+ config += self._add_tab_level(self._extract_plugin_values(plugin, section))
1439
+
1440
+ # ending section, this is static and indentation never changes
1441
+ config += "}\n"
1442
+ return config
1443
+
1444
+
1445
+
1446
+ def main():
1447
+ """Run a debug parse of a sample pipeline and log the component JSON."""
1448
+ condition_output_no_filter = logstash_config_to_components('''input { stdin { } }
1449
+
1450
+ filter {
1451
+ grok {
1452
+ match => { "message" => "%{COMBINEDAPACHELOG}" }
1453
+ }
1454
+ date {
1455
+ match => [ "timestamp" , "dd/MMM/yyyy:HH:mm:ss Z" ]
1456
+ }
1457
+ }
1458
+
1459
+ output {
1460
+ elasticsearch { hosts => ["localhost:9200"] }
1461
+ stdout { codec => rubydebug }
1462
+ }
1463
+ ''')
1464
+ logger.debug(condition_output_no_filter)
1465
+
1466
+
1467
+
1468
+ if __name__ == "__main__":
1469
+ main()