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.
- AI/__init__.py +0 -0
- AI/integration_factory.py +1392 -0
- AI/migrations/0001_initial.py +58 -0
- AI/migrations/0002_draftdefinition_normalizers.py +23 -0
- AI/migrations/0003_delete_aisettings_delete_draftdefinition.py +19 -0
- AI/migrations/__init__.py +0 -0
- AI/models.py +5 -0
- AI/static/js/integration_factory.js +1102 -0
- AI/system_prompts/dashboard_generator.md +367 -0
- AI/system_prompts/grok_patterns.txt +95 -0
- AI/system_prompts/ingest_pipeline_generator.md +331 -0
- AI/system_prompts/ingest_pipeline_processors.json +2851 -0
- AI/system_prompts/ingest_verifier.md +84 -0
- AI/system_prompts/integrations_list.json +2690 -0
- AI/system_prompts/log_classifier.md +134 -0
- AI/system_prompts/template_creator.md +123 -0
- AI/templates/integration_factory.html +200 -0
- AI/urls.py +16 -0
- AI/views.py +20 -0
- API/__init__.py +0 -0
- API/admin.py +7 -0
- API/api.http +784 -0
- API/apps.py +9 -0
- API/auth.py +101 -0
- API/connections_views.py +312 -0
- API/guides.py +88 -0
- API/mcp/__init__.py +5 -0
- API/mcp/dispatch.py +179 -0
- API/mcp/tools.py +890 -0
- API/mcp/views.py +215 -0
- API/migrations/__init__.py +0 -0
- API/models.py +7 -0
- API/pipelines_views.py +1224 -0
- API/policies_views.py +1015 -0
- API/security_views.py +488 -0
- API/simulation_detail.py +219 -0
- API/snmp_views.py +1539 -0
- API/urls.py +81 -0
- Common/__init__.py +0 -0
- Common/ai/agent_builder.py +690 -0
- Common/context_processors.py +49 -0
- Common/decorators.py +68 -0
- Common/elastic_utils.py +1154 -0
- Common/encryption.py +271 -0
- Common/error_handlers.py +65 -0
- Common/formatters.py +106 -0
- Common/logstash_config_parse.py +1469 -0
- Common/logstash_utils.py +34 -0
- Common/middleware.py +216 -0
- Common/product_ca.py +1124 -0
- Common/validators.py +66 -0
- Documentation/__init__.py +0 -0
- Documentation/admin.py +7 -0
- Documentation/apps.py +9 -0
- Documentation/content/CHANGELOG.md +890 -0
- Documentation/content/docs/getting_started.md +92 -0
- Documentation/content/docs/index.md +124 -0
- Documentation/content/docs/logstashagent/configuration/index.md +60 -0
- Documentation/content/docs/logstashagent/configuration/logstashagent.yml.md +141 -0
- Documentation/content/docs/logstashagent/general/build.md +217 -0
- Documentation/content/docs/logstashagent/general/index.md +38 -0
- Documentation/content/docs/logstashagent/general/roles.md +267 -0
- Documentation/content/docs/logstashagent/index.md +264 -0
- Documentation/content/docs/logstashui/SNMP/Quickstart.md +94 -0
- Documentation/content/docs/logstashui/SNMP/architecture.md +64 -0
- Documentation/content/docs/logstashui/SNMP/configuration.md +147 -0
- Documentation/content/docs/logstashui/SNMP/data_overview.md +59 -0
- Documentation/content/docs/logstashui/SNMP/deploying_changes.md +71 -0
- Documentation/content/docs/logstashui/SNMP/device_support.md +39 -0
- Documentation/content/docs/logstashui/SNMP/discovery.md +48 -0
- Documentation/content/docs/logstashui/SNMP/index.md +58 -0
- Documentation/content/docs/logstashui/SNMP/pipeline_generation.md +63 -0
- Documentation/content/docs/logstashui/SNMP/schema.md +595 -0
- Documentation/content/docs/logstashui/SNMP/testing.md +47 -0
- Documentation/content/docs/logstashui/SNMP/traps.md +45 -0
- Documentation/content/docs/logstashui/SNMP/tsds_implementation.md +82 -0
- Documentation/content/docs/logstashui/agent_guides/concepts.md +25 -0
- Documentation/content/docs/logstashui/agent_guides/deploy.md +30 -0
- Documentation/content/docs/logstashui/agent_guides/pipeline-review.md +24 -0
- Documentation/content/docs/logstashui/agent_guides/simulation.md +55 -0
- Documentation/content/docs/logstashui/agent_guides/snmp.md +57 -0
- Documentation/content/docs/logstashui/agent_guides/troubleshooting.md +21 -0
- Documentation/content/docs/logstashui/architecture.md +11 -0
- Documentation/content/docs/logstashui/compatibility.md +58 -0
- Documentation/content/docs/logstashui/configuration/environment.md +193 -0
- Documentation/content/docs/logstashui/configuration/host_mode.md +94 -0
- Documentation/content/docs/logstashui/configuration/index.md +72 -0
- Documentation/content/docs/logstashui/configuration/logstash_proxy.md +138 -0
- Documentation/content/docs/logstashui/configuration/logstashui.yml.md +16 -0
- Documentation/content/docs/logstashui/configuration/simulation.md +84 -0
- Documentation/content/docs/logstashui/database/examples/README.md +15 -0
- Documentation/content/docs/logstashui/database/examples/create-mariadb.sql +13 -0
- Documentation/content/docs/logstashui/database/examples/create-mysql.sql +12 -0
- Documentation/content/docs/logstashui/database/examples/create-postgresql.sql +13 -0
- Documentation/content/docs/logstashui/database/examples/schema-mysql.sql +502 -0
- Documentation/content/docs/logstashui/database/examples/schema-postgresql.sql +1709 -0
- Documentation/content/docs/logstashui/database/index.md +79 -0
- Documentation/content/docs/logstashui/database/migration.md +75 -0
- Documentation/content/docs/logstashui/general/build.md +154 -0
- Documentation/content/docs/logstashui/general/deploy.md +122 -0
- Documentation/content/docs/logstashui/general/deployment-recs.md +32 -0
- Documentation/content/docs/logstashui/general/index.md +62 -0
- Documentation/content/docs/logstashui/general/offline.md +68 -0
- Documentation/content/docs/logstashui/general/updating.md +50 -0
- Documentation/content/docs/logstashui/index.md +90 -0
- Documentation/content/docs/logstashui/kubernetes/cnpg.md +98 -0
- Documentation/content/docs/logstashui/kubernetes/envoy-gateway.md +112 -0
- Documentation/content/docs/logstashui/kubernetes/examples/README.md +46 -0
- Documentation/content/docs/logstashui/kubernetes/examples/embedded-agent.yaml +122 -0
- Documentation/content/docs/logstashui/kubernetes/examples/mysql/configmap.yaml +41 -0
- Documentation/content/docs/logstashui/kubernetes/examples/mysql/ingress.yaml +31 -0
- Documentation/content/docs/logstashui/kubernetes/examples/mysql/namespace.yaml +8 -0
- Documentation/content/docs/logstashui/kubernetes/examples/mysql/secret.yaml +19 -0
- Documentation/content/docs/logstashui/kubernetes/examples/mysql/statefulset.yaml +106 -0
- Documentation/content/docs/logstashui/kubernetes/examples/postgresql/cnpg.yaml +25 -0
- Documentation/content/docs/logstashui/kubernetes/examples/postgresql/configmap.yaml +42 -0
- Documentation/content/docs/logstashui/kubernetes/examples/postgresql/ingress.yaml +31 -0
- Documentation/content/docs/logstashui/kubernetes/examples/postgresql/namespace.yaml +8 -0
- Documentation/content/docs/logstashui/kubernetes/examples/postgresql/secret.yaml +19 -0
- Documentation/content/docs/logstashui/kubernetes/examples/postgresql/statefulset.yaml +106 -0
- Documentation/content/docs/logstashui/kubernetes/examples/sqlite/configmap.yaml +35 -0
- Documentation/content/docs/logstashui/kubernetes/examples/sqlite/ingress.yaml +31 -0
- Documentation/content/docs/logstashui/kubernetes/examples/sqlite/namespace.yaml +8 -0
- Documentation/content/docs/logstashui/kubernetes/examples/sqlite/secret.yaml +18 -0
- Documentation/content/docs/logstashui/kubernetes/examples/sqlite/statefulset.yaml +106 -0
- Documentation/content/docs/logstashui/kubernetes/index.md +121 -0
- Documentation/content/docs/logstashui/mcp.md +224 -0
- Documentation/content/docs/logstashui/mcp_scenarios.md +234 -0
- Documentation/content/docs/logstashui/rest_api.md +2783 -0
- Documentation/content/docs/logstashui/utilities/dissect_debugger.md +89 -0
- Documentation/content/docs/logstashui/utilities/grok_debugger.md +114 -0
- Documentation/content/docs/logstashui/utilities/index.md +40 -0
- Documentation/content/images/LogstashIcon.png +0 -0
- Documentation/content/images/architecture.png +0 -0
- Documentation/content/images/connection_manager.png +0 -0
- Documentation/content/images/control_plane.png +0 -0
- Documentation/content/images/graph.gif +0 -0
- Documentation/content/images/login.png +0 -0
- Documentation/content/images/monitoring.png +0 -0
- Documentation/content/images/new_connection.gif +0 -0
- Documentation/content/images/simulate.gif +0 -0
- Documentation/content/images/simulate.png +0 -0
- Documentation/content/images/snmp.gif +0 -0
- Documentation/content/images/snmp.png +0 -0
- Documentation/content/images/snmp_architecture.png +0 -0
- Documentation/migrations/__init__.py +0 -0
- Documentation/models.py +9 -0
- Documentation/static/css/markdown.css +250 -0
- Documentation/templates/documentation.html +225 -0
- Documentation/templates/nav_item.html +41 -0
- Documentation/urls.py +11 -0
- Documentation/views.py +442 -0
- LogstashUI/__init__.py +0 -0
- LogstashUI/__main__.py +10 -0
- LogstashUI/asgi.py +16 -0
- LogstashUI/cli.py +626 -0
- LogstashUI/config.py +116 -0
- LogstashUI/database.py +263 -0
- LogstashUI/insecure_http.py +117 -0
- LogstashUI/logging_config.py +99 -0
- LogstashUI/migrate_engine.py +282 -0
- LogstashUI/packaging/__init__.py +3 -0
- LogstashUI/packaging/logstashui.default +68 -0
- LogstashUI/packaging/logstashui.service.in +22 -0
- LogstashUI/paths.py +181 -0
- LogstashUI/settings.py +437 -0
- LogstashUI/telemetry.py +159 -0
- LogstashUI/urls.py +56 -0
- LogstashUI/wsgi.py +77 -0
- Management/__init__.py +0 -0
- Management/apps.py +10 -0
- Management/migrations/0001_initial.py +29 -0
- Management/migrations/0002_settings.py +25 -0
- Management/migrations/0003_settings_agent_ui_url.py +29 -0
- Management/migrations/0004_settings_logstash_artifact_base_url.py +29 -0
- Management/migrations/__init__.py +0 -0
- Management/models.py +92 -0
- Management/templates/api_tokens.html +214 -0
- Management/templates/components/api_token_created.html +38 -0
- Management/templates/components/api_token_row.html +84 -0
- Management/templates/components/logstash_artifact_row.html +100 -0
- Management/templates/components/logstash_artifact_tbody.html +26 -0
- Management/templates/components/user_row.html +67 -0
- Management/templates/logs.html +98 -0
- Management/templates/logstash_artifacts.html +172 -0
- Management/templates/management.html +80 -0
- Management/templates/management_settings.html +320 -0
- Management/templates/registration/login.html +404 -0
- Management/templates/users.html +304 -0
- Management/urls.py +23 -0
- Management/views.py +804 -0
- Monitoring/__init__.py +0 -0
- Monitoring/apps.py +9 -0
- Monitoring/migrations/__init__.py +0 -0
- Monitoring/static/js/monitoring.js +463 -0
- Monitoring/templates/components/node_metrics.html +161 -0
- Monitoring/templates/components/pipeline_metrics.html +189 -0
- Monitoring/templates/monitoring.html +271 -0
- Monitoring/urls.py +16 -0
- Monitoring/views.py +724 -0
- PipelineManager/__init__.py +0 -0
- PipelineManager/agent_api.py +1173 -0
- PipelineManager/agent_client.py +59 -0
- PipelineManager/agent_modes.py +880 -0
- PipelineManager/agent_policies.py +689 -0
- PipelineManager/agent_versions.py +151 -0
- PipelineManager/apps.py +10 -0
- PipelineManager/artifact_metrics.py +171 -0
- PipelineManager/artifacts.py +820 -0
- PipelineManager/connections_crud.py +722 -0
- PipelineManager/data/default_jvm.options +76 -0
- PipelineManager/data/default_log4j2.properties +165 -0
- PipelineManager/data/default_logstash.yml +405 -0
- PipelineManager/data/plugins.json +29109 -0
- PipelineManager/editor_views.py +608 -0
- PipelineManager/forms.py +284 -0
- PipelineManager/manager_views.py +490 -0
- PipelineManager/migrations/0001_initial.py +38 -0
- PipelineManager/migrations/0002_alter_connection_connection_type_and_more.py +38 -0
- PipelineManager/migrations/0003_policy_connection_policy.py +38 -0
- PipelineManager/migrations/0004_policy_current_revision_number_and_more.py +75 -0
- PipelineManager/migrations/0005_apikey_enrollmenttoken.py +38 -0
- PipelineManager/migrations/0006_enrollmenttoken_name.py +18 -0
- PipelineManager/migrations/0007_alter_enrollmenttoken_options_and_more.py +21 -0
- PipelineManager/migrations/0008_connection_agent_id.py +18 -0
- PipelineManager/migrations/0009_connection_last_check_in_policy_jvm_options_hash_and_more.py +33 -0
- PipelineManager/migrations/0010_keystore_revision_number_pipeline_revision_number.py +23 -0
- PipelineManager/migrations/0011_keystore_kv_hash.py +18 -0
- PipelineManager/migrations/0012_policy_binary_path.py +18 -0
- PipelineManager/migrations/0013_connection_status_blob.py +18 -0
- PipelineManager/migrations/0014_pipeline_pipeline_batch_delay_and_more.py +43 -0
- PipelineManager/migrations/0015_add_pipeline_hash.py +18 -0
- PipelineManager/migrations/0016_backfill_pipeline_hash.py +32 -0
- PipelineManager/migrations/0017_policy_keystore_password.py +31 -0
- PipelineManager/migrations/0018_policy_last_deployed_at.py +18 -0
- PipelineManager/migrations/0019_connection_restart_on_next_checkin.py +18 -0
- PipelineManager/migrations/0020_pipeline_no_input_pipeline_non_reloadable.py +23 -0
- PipelineManager/migrations/0021_connection_desired_agent_version.py +18 -0
- PipelineManager/migrations/0022_keystore_managed_by_pipeline_managed_by.py +23 -0
- PipelineManager/migrations/0023_agent_modes_policy_connection.py +89 -0
- PipelineManager/migrations/0024_seed_system_policies.py +173 -0
- PipelineManager/migrations/0025_packaged_managed_policy_types.py +166 -0
- PipelineManager/migrations/0026_normalize_opt_logstash_agent_paths.py +63 -0
- PipelineManager/migrations/0027_packaged_managed_default_ports.py +49 -0
- PipelineManager/migrations/0028_apikey_admin_tokens.py +80 -0
- PipelineManager/migrations/0029_logstash_artifacts.py +45 -0
- PipelineManager/migrations/0030_connection_allow_self_signed_certs.py +33 -0
- PipelineManager/migrations/0031_deploy_system_policies.py +93 -0
- PipelineManager/migrations/0032_connection_agent_inbound_key.py +30 -0
- PipelineManager/migrations/0033_simulation_result.py +26 -0
- PipelineManager/migrations/__init__.py +0 -0
- PipelineManager/models.py +1300 -0
- PipelineManager/pipelines_crud.py +738 -0
- PipelineManager/policies_crud.py +772 -0
- PipelineManager/sim_keystore.py +319 -0
- PipelineManager/simulation.py +1581 -0
- PipelineManager/static/css/codemirror.min.css +1 -0
- PipelineManager/static/css/graph_move.css +79 -0
- PipelineManager/static/css/monokai.min.css +1 -0
- PipelineManager/static/css/move_mode.css +144 -0
- PipelineManager/static/css/show-hint.min.css +1 -0
- PipelineManager/static/images/age.png +0 -0
- PipelineManager/static/images/aggregate.png +0 -0
- PipelineManager/static/images/alter.png +0 -0
- PipelineManager/static/images/azure_event_hubs.png +0 -0
- PipelineManager/static/images/beats.png +0 -0
- PipelineManager/static/images/boundary.png +0 -0
- PipelineManager/static/images/bytes.png +0 -0
- PipelineManager/static/images/cidr.png +0 -0
- PipelineManager/static/images/cipher.png +0 -0
- PipelineManager/static/images/circonus.png +0 -0
- PipelineManager/static/images/clone.png +0 -0
- PipelineManager/static/images/cloudwatch.png +0 -0
- PipelineManager/static/images/comment.png +0 -0
- PipelineManager/static/images/continue.png +0 -0
- PipelineManager/static/images/couchdb_changes.png +0 -0
- PipelineManager/static/images/csv.png +0 -0
- PipelineManager/static/images/datadog.png +0 -0
- PipelineManager/static/images/datadog_metrics.png +0 -0
- PipelineManager/static/images/date.png +0 -0
- PipelineManager/static/images/de_dot.png +0 -0
- PipelineManager/static/images/dead_letter_queue.png +0 -0
- PipelineManager/static/images/dissect.png +0 -0
- PipelineManager/static/images/dns.png +0 -0
- PipelineManager/static/images/drop.png +0 -0
- PipelineManager/static/images/dynatrace.png +0 -0
- PipelineManager/static/images/elapsed.png +0 -0
- PipelineManager/static/images/elastic_agent.png +0 -0
- PipelineManager/static/images/elastic_integration.png +0 -0
- PipelineManager/static/images/elastic_serverless_forwarder.png +0 -0
- PipelineManager/static/images/elastic_workplace_search.png +0 -0
- PipelineManager/static/images/elasticsearch.png +0 -0
- PipelineManager/static/images/else.png +0 -0
- PipelineManager/static/images/else_if.png +0 -0
- PipelineManager/static/images/email.png +0 -0
- PipelineManager/static/images/environment.png +0 -0
- PipelineManager/static/images/exec.png +0 -0
- PipelineManager/static/images/extractnumbers.png +0 -0
- PipelineManager/static/images/file.png +0 -0
- PipelineManager/static/images/fingerprint.png +0 -0
- PipelineManager/static/images/ganglia.png +0 -0
- PipelineManager/static/images/gelf.png +0 -0
- PipelineManager/static/images/generator.png +0 -0
- PipelineManager/static/images/geoip.png +0 -0
- PipelineManager/static/images/github.png +0 -0
- PipelineManager/static/images/google_bigquery.png +0 -0
- PipelineManager/static/images/google_cloud_storage.png +0 -0
- PipelineManager/static/images/google_pubsub.png +0 -0
- PipelineManager/static/images/graphite.png +0 -0
- PipelineManager/static/images/graphtastic.png +0 -0
- PipelineManager/static/images/grok.png +0 -0
- PipelineManager/static/images/heartbeat.png +0 -0
- PipelineManager/static/images/http.png +0 -0
- PipelineManager/static/images/http_poller.png +0 -0
- PipelineManager/static/images/i18n.png +0 -0
- PipelineManager/static/images/if.png +0 -0
- PipelineManager/static/images/imap.png +0 -0
- PipelineManager/static/images/influxdb.png +0 -0
- PipelineManager/static/images/irc.png +0 -0
- PipelineManager/static/images/java_generator.png +0 -0
- PipelineManager/static/images/java_stdin.png +0 -0
- PipelineManager/static/images/java_stdout.png +0 -0
- PipelineManager/static/images/java_uuid.png +0 -0
- PipelineManager/static/images/jdbc.png +0 -0
- PipelineManager/static/images/jdbc_static.png +0 -0
- PipelineManager/static/images/jdbc_streaming.png +0 -0
- PipelineManager/static/images/jms.png +0 -0
- PipelineManager/static/images/jmx.png +0 -0
- PipelineManager/static/images/json.png +0 -0
- PipelineManager/static/images/json_encode.png +0 -0
- PipelineManager/static/images/juggernaut.png +0 -0
- PipelineManager/static/images/kafka.png +0 -0
- PipelineManager/static/images/kinesis.png +0 -0
- PipelineManager/static/images/kv.png +0 -0
- PipelineManager/static/images/librato.png +0 -0
- PipelineManager/static/images/log4j.png +0 -0
- PipelineManager/static/images/loggly.png +0 -0
- PipelineManager/static/images/logstash.png +0 -0
- PipelineManager/static/images/lumberjack.png +0 -0
- PipelineManager/static/images/meetup.png +0 -0
- PipelineManager/static/images/memcached.png +0 -0
- PipelineManager/static/images/metriccatcher.png +0 -0
- PipelineManager/static/images/metricize.png +0 -0
- PipelineManager/static/images/metrics.png +0 -0
- PipelineManager/static/images/mongodb.png +0 -0
- PipelineManager/static/images/mutate.png +0 -0
- PipelineManager/static/images/nagios.png +0 -0
- PipelineManager/static/images/nagios_nsca.png +0 -0
- PipelineManager/static/images/opentsdb.png +0 -0
- PipelineManager/static/images/pagerduty.png +0 -0
- PipelineManager/static/images/pipe.png +0 -0
- PipelineManager/static/images/pipeline.png +0 -0
- PipelineManager/static/images/prune.png +0 -0
- PipelineManager/static/images/puppet_facter.png +0 -0
- PipelineManager/static/images/rabbitmq.png +0 -0
- PipelineManager/static/images/range.png +0 -0
- PipelineManager/static/images/redis.png +0 -0
- PipelineManager/static/images/redmine.png +0 -0
- PipelineManager/static/images/relp.png +0 -0
- PipelineManager/static/images/riak.png +0 -0
- PipelineManager/static/images/riemann.png +0 -0
- PipelineManager/static/images/rss.png +0 -0
- PipelineManager/static/images/ruby.png +0 -0
- PipelineManager/static/images/s3-sns-sqs.png +0 -0
- PipelineManager/static/images/s3.png +0 -0
- PipelineManager/static/images/salesforce.png +0 -0
- PipelineManager/static/images/sink.png +0 -0
- PipelineManager/static/images/sleep.png +0 -0
- PipelineManager/static/images/snmp.png +0 -0
- PipelineManager/static/images/snmptrap.png +0 -0
- PipelineManager/static/images/sns.png +0 -0
- PipelineManager/static/images/solr_http.png +0 -0
- PipelineManager/static/images/split.png +0 -0
- PipelineManager/static/images/sqlite.png +0 -0
- PipelineManager/static/images/sqs.png +0 -0
- PipelineManager/static/images/statsd.png +0 -0
- PipelineManager/static/images/stdin.png +0 -0
- PipelineManager/static/images/stdout.png +0 -0
- PipelineManager/static/images/stomp.png +0 -0
- PipelineManager/static/images/syslog.png +0 -0
- PipelineManager/static/images/syslog_pri.png +0 -0
- PipelineManager/static/images/tcp.png +0 -0
- PipelineManager/static/images/threats_classifier.png +0 -0
- PipelineManager/static/images/throttle.png +0 -0
- PipelineManager/static/images/timber.png +0 -0
- PipelineManager/static/images/tld.png +0 -0
- PipelineManager/static/images/translate.png +0 -0
- PipelineManager/static/images/truncate.png +0 -0
- PipelineManager/static/images/twitter.png +0 -0
- PipelineManager/static/images/udp.png +0 -0
- PipelineManager/static/images/unix.png +0 -0
- PipelineManager/static/images/urldecode.png +0 -0
- PipelineManager/static/images/useragent.png +0 -0
- PipelineManager/static/images/uuid.png +0 -0
- PipelineManager/static/images/varnishlog.png +0 -0
- PipelineManager/static/images/webhdfs.png +0 -0
- PipelineManager/static/images/websocket.png +0 -0
- PipelineManager/static/images/wmi.png +0 -0
- PipelineManager/static/images/wurfl_device_detection.png +0 -0
- PipelineManager/static/images/xml.png +0 -0
- PipelineManager/static/images/xmpp.png +0 -0
- PipelineManager/static/images/zabbix.png +0 -0
- PipelineManager/static/js/agent_inspect_modal.js +141 -0
- PipelineManager/static/js/agent_policies.js +3746 -0
- PipelineManager/static/js/agent_status_sse.js +166 -0
- PipelineManager/static/js/codemirror.min.js +1 -0
- PipelineManager/static/js/connections_table.js +551 -0
- PipelineManager/static/js/d3.v7.js +20625 -0
- PipelineManager/static/js/diff_modal.js +995 -0
- PipelineManager/static/js/expression_editor.js +291 -0
- PipelineManager/static/js/js-yaml.min.js +1 -0
- PipelineManager/static/js/logstashyml_guides.js +1063 -0
- PipelineManager/static/js/move_graph.js +577 -0
- PipelineManager/static/js/move_mode.js +559 -0
- PipelineManager/static/js/pipeline_editor.js +4102 -0
- PipelineManager/static/js/pipeline_graph_editor.js +3542 -0
- PipelineManager/static/js/pipeline_list.js +274 -0
- PipelineManager/static/js/pipeline_settings.js +121 -0
- PipelineManager/static/js/pipeline_text_editor.js +2088 -0
- PipelineManager/static/js/plugin_config_modal.js +2827 -0
- PipelineManager/static/js/policy_deploy_modal.js +1066 -0
- PipelineManager/static/js/show-hint.min.js +1 -0
- PipelineManager/static/js/sim_targets.js +380 -0
- PipelineManager/static/js/simple-comment-mode.js +56 -0
- PipelineManager/static/js/simulation_modal.js +1135 -0
- PipelineManager/static/js/simulation_results.js +2778 -0
- PipelineManager/static/js/stats_strip.js +231 -0
- PipelineManager/static/js/yaml.js +120 -0
- PipelineManager/system_policy_defaults.py +279 -0
- PipelineManager/templates/components/pipeline_editor/diff_modal.html +127 -0
- PipelineManager/templates/components/pipeline_editor/expression_editor.html +160 -0
- PipelineManager/templates/components/pipeline_editor/plugin_config_modal.html +119 -0
- PipelineManager/templates/components/pipeline_editor/plugin_modal.html +1016 -0
- PipelineManager/templates/components/pipeline_editor/simulation_modal.html +394 -0
- PipelineManager/templates/components/pipeline_editor/simulation_results.html +123 -0
- PipelineManager/templates/components/pipeline_editor/stats_strip.html +123 -0
- PipelineManager/templates/components/pipeline_editor/view_code_modal.html +133 -0
- PipelineManager/templates/components/pipeline_manager/agent_inspect_content.html +805 -0
- PipelineManager/templates/components/pipeline_manager/agent_inspect_modal.html +40 -0
- PipelineManager/templates/components/pipeline_manager/agent_policies.html +2421 -0
- PipelineManager/templates/components/pipeline_manager/change_policy_modal.html +210 -0
- PipelineManager/templates/components/pipeline_manager/collapsible_row.html +11 -0
- PipelineManager/templates/components/pipeline_manager/connection_modal.html +1361 -0
- PipelineManager/templates/components/pipeline_manager/keystore_modal.html +269 -0
- PipelineManager/templates/components/pipeline_manager/logstashyml_guides/centralized_pipeline_management.html +291 -0
- PipelineManager/templates/components/pipeline_manager/logstashyml_guides/default.html +166 -0
- PipelineManager/templates/components/pipeline_manager/mcp_modal.html +241 -0
- PipelineManager/templates/components/pipeline_manager/pipeline_list_content.html +586 -0
- PipelineManager/templates/components/pipeline_manager/policy_deploy_modal.html +238 -0
- PipelineManager/templates/pipeline_editor.html +1738 -0
- PipelineManager/templates/pipeline_graph_editor.html +99 -0
- PipelineManager/templates/pipeline_manager.html +584 -0
- PipelineManager/templates/pipeline_text_editor.html +350 -0
- PipelineManager/urls.py +99 -0
- SNMP/__init__.py +0 -0
- SNMP/ai_template_generation.py +232 -0
- SNMP/apps.py +9 -0
- SNMP/assets/device_template_generation/agents/snmp-profile-author.json +15 -0
- SNMP/assets/device_template_generation/skills/snmp-catalog.json +9 -0
- SNMP/data/authoring_instructions.md +65 -0
- SNMP/data/grounding/.gitignore +4 -0
- SNMP/data/grounding/build_grounding.py +35 -0
- SNMP/data/grounding/grounding.json +1 -0
- SNMP/data/grounding/sample_agent_payload.cisco2960x.json +2184 -0
- SNMP/data/mib_reference/std_bgp4_mib.json +43 -0
- SNMP/data/mib_reference/std_entity_sensors.json +28 -0
- SNMP/data/mib_reference/std_host_resources.json +32 -0
- SNMP/data/mib_reference/std_ospf_mib.json +55 -0
- SNMP/data/mib_reference/std_ucd_linux.json +27 -0
- SNMP/data/normalizers.json +103 -0
- SNMP/data/official_device_templates/arista_eos.json +24 -0
- SNMP/data/official_device_templates/aruba_wireless_controller.json +23 -0
- SNMP/data/official_device_templates/brocade_fc_switch.json +20 -0
- SNMP/data/official_device_templates/cisco_ios.json +21 -0
- SNMP/data/official_device_templates/default.json +13 -0
- SNMP/data/official_device_templates/dell_idrac.json +22 -0
- SNMP/data/official_device_templates/dell_x1026.json +16 -0
- SNMP/data/official_device_templates/dlink_dgs1210_switch.json +19 -0
- SNMP/data/official_device_templates/eastpower_ups.json +20 -0
- SNMP/data/official_device_templates/eaton_ups.json +22 -0
- SNMP/data/official_device_templates/epson_printer.json +18 -0
- SNMP/data/official_device_templates/geist_watchdog.json +20 -0
- SNMP/data/official_device_templates/generic_linux.json +18 -0
- SNMP/data/official_device_templates/generic_ont.json +18 -0
- SNMP/data/official_device_templates/generic_ups.json +16 -0
- SNMP/data/official_device_templates/hp_laserjet_mfp_m281cdw.json +18 -0
- SNMP/data/official_device_templates/hpe_nimble.json +17 -0
- SNMP/data/official_device_templates/huawei_ups.json +19 -0
- SNMP/data/official_device_templates/ingrasys_ups.json +19 -0
- SNMP/data/official_device_templates/isilon_onefs.json +22 -0
- SNMP/data/official_device_templates/mellanox_sx6036.json +20 -0
- SNMP/data/official_device_templates/netapp_7mode.json +22 -0
- SNMP/data/official_device_templates/palo_alto_firewall.json +21 -0
- SNMP/data/official_device_templates/phoenixtec_ups.json +18 -0
- SNMP/data/official_device_templates/ubiquiti_unifi_ap.json +19 -0
- SNMP/data/official_device_templates/ubiquiti_unifi_switch.json +18 -0
- SNMP/data/official_device_templates/ubiquiti_unifi_udm.json +19 -0
- SNMP/data/official_device_templates/versa_flexvnf_appliance.json +19 -0
- SNMP/data/official_profiles/arista_eos.json +16 -0
- SNMP/data/official_profiles/aruba_wireless_controller.json +145 -0
- SNMP/data/official_profiles/brocade_fibre_channel_switch_fibre_channel_ports.json +35 -0
- SNMP/data/official_profiles/brocade_fibre_channel_switch_name_server.json +23 -0
- SNMP/data/official_profiles/brocade_fibre_channel_switch_system_metrics.json +36 -0
- SNMP/data/official_profiles/cisco_cdp.json +26 -0
- SNMP/data/official_profiles/cisco_fans.json +18 -0
- SNMP/data/official_profiles/cisco_sensors.json +21 -0
- SNMP/data/official_profiles/cisco_system_metrics.json +40 -0
- SNMP/data/official_profiles/dell_idrac_cpu.json +19 -0
- SNMP/data/official_profiles/dell_idrac_fans.json +20 -0
- SNMP/data/official_profiles/dell_idrac_global_status.json +13 -0
- SNMP/data/official_profiles/dell_idrac_memory.json +20 -0
- SNMP/data/official_profiles/dell_idrac_power_supply.json +19 -0
- SNMP/data/official_profiles/dell_idrac_raid_controller.json +19 -0
- SNMP/data/official_profiles/dlink_dgs1210.json +15 -0
- SNMP/data/official_profiles/dlink_dgs1210_system_metrics.json +38 -0
- SNMP/data/official_profiles/eaton_ups.json +40 -0
- SNMP/data/official_profiles/geist_environment.json +50 -0
- SNMP/data/official_profiles/generic_arp.json +19 -0
- SNMP/data/official_profiles/generic_bgp.json +24 -0
- SNMP/data/official_profiles/generic_entity_psu.json +26 -0
- SNMP/data/official_profiles/generic_entity_sensor.json +22 -0
- SNMP/data/official_profiles/generic_host_system_metrics.json +68 -0
- SNMP/data/official_profiles/generic_interfaces.json +86 -0
- SNMP/data/official_profiles/generic_ip_addr.json +19 -0
- SNMP/data/official_profiles/generic_lldp.json +54 -0
- SNMP/data/official_profiles/generic_lm_sensors.json +37 -0
- SNMP/data/official_profiles/generic_mac_table.json +19 -0
- SNMP/data/official_profiles/generic_ont.json +88 -0
- SNMP/data/official_profiles/generic_ospf.json +21 -0
- SNMP/data/official_profiles/generic_printer_mib.json +48 -0
- SNMP/data/official_profiles/generic_rmon.json +38 -0
- SNMP/data/official_profiles/generic_system.json +17 -0
- SNMP/data/official_profiles/generic_ucd_system_metrics.json +63 -0
- SNMP/data/official_profiles/generic_ups_mib.json +154 -0
- SNMP/data/official_profiles/hpe_nimble_volumes.json +59 -0
- SNMP/data/official_profiles/huawei_ups.json +111 -0
- SNMP/data/official_profiles/isilon_performance.json +92 -0
- SNMP/data/official_profiles/isilon_protocols.json +77 -0
- SNMP/data/official_profiles/isilon_system.json +86 -0
- SNMP/data/official_profiles/mellanox_mlnx_os.json +15 -0
- SNMP/data/official_profiles/netapp_7mode_data_protection.json +106 -0
- SNMP/data/official_profiles/netapp_7mode_disks.json +51 -0
- SNMP/data/official_profiles/netapp_7mode_protocols.json +66 -0
- SNMP/data/official_profiles/netapp_7mode_system.json +92 -0
- SNMP/data/official_profiles/netapp_7mode_volumes.json +166 -0
- SNMP/data/official_profiles/paloalto_components.json +36 -0
- SNMP/data/official_profiles/paloalto_system.json +15 -0
- SNMP/data/official_profiles/traps.json +16 -0
- SNMP/data/official_profiles/ubiquiti_unifi_switch.json +18 -0
- SNMP/data/official_profiles/ubiquiti_unifi_switch_system.json +14 -0
- SNMP/data/official_profiles/ubiquiti_unifi_wireless.json +60 -0
- SNMP/data/official_profiles/versa_flexvnf.json +14 -0
- SNMP/data/schema.md +650 -0
- SNMP/data/schema_reference/snmp_field_schema.md +747 -0
- SNMP/data/snmp_template.json +629 -0
- SNMP/data/template_profile_context.md +3986 -0
- SNMP/inline_grounding.py +77 -0
- SNMP/management/__init__.py +1 -0
- SNMP/management/commands/__init__.py +1 -0
- SNMP/management/commands/generate_template_profile_context.py +272 -0
- SNMP/management/commands/load_test_snmp_data.py +240 -0
- SNMP/management/commands/sync_snmp_official_data.py +263 -0
- SNMP/management/commands/unload_test_snmp_data.py +77 -0
- SNMP/migrations/0001_initial.py +101 -0
- SNMP/migrations/0002_devicetemplate.py +34 -0
- SNMP/migrations/0003_remove_devicetemplate_type_remove_profile_type_and_more.py +31 -0
- SNMP/migrations/0004_device_device_template.py +19 -0
- SNMP/migrations/0005_devicetemplate_product_profile_product.py +23 -0
- SNMP/migrations/0006_alter_devicetemplate_model_and_more.py +28 -0
- SNMP/migrations/0007_remove_device_profiles.py +17 -0
- SNMP/migrations/0008_devicetemplate_type.py +18 -0
- SNMP/migrations/0009_alter_device_device_template.py +19 -0
- SNMP/migrations/0010_alter_device_device_template.py +19 -0
- SNMP/migrations/0011_network_namespace.py +18 -0
- SNMP/migrations/0012_profile_normalizers.py +18 -0
- SNMP/migrations/0013_snmpdeploymentstate.py +26 -0
- SNMP/migrations/0014_alter_snmpdeploymentstate_last_config_change.py +18 -0
- SNMP/migrations/0015_alter_snmpdeploymentstate_last_config_change.py +20 -0
- SNMP/migrations/0016_alter_snmpdeploymentstate_last_config_change.py +18 -0
- SNMP/migrations/0017_remove_network_logstash_name.py +17 -0
- SNMP/migrations/0018_add_official_key.py +39 -0
- SNMP/migrations/0019_network_namespace_from_device_template.py +18 -0
- SNMP/migrations/0020_device_hostname_alter_device_ip_address_and_more.py +27 -0
- SNMP/migrations/0021_device_building_device_latitude_device_longitude_and_more.py +43 -0
- SNMP/migrations/0022_alter_device_latitude_alter_device_longitude.py +23 -0
- SNMP/migrations/0023_network_agent_connection_network_deployment_mode_and_more.py +30 -0
- SNMP/migrations/0024_network_credential_mode.py +18 -0
- SNMP/migrations/0025_network_ssl_certificate_authorities.py +18 -0
- SNMP/migrations/__init__.py +0 -0
- SNMP/models.py +892 -0
- SNMP/network_map.py +660 -0
- SNMP/overview.py +394 -0
- SNMP/snmp_crud.py +6082 -0
- SNMP/snmp_grounding.py +146 -0
- SNMP/snmp_normalizers.py +594 -0
- SNMP/snmp_pipeline_generator.py +1658 -0
- SNMP/snmp_test.py +962 -0
- SNMP/static/css/snmp.css +33 -0
- SNMP/static/images/apc.png +0 -0
- SNMP/static/images/arista.png +0 -0
- SNMP/static/images/aruba.png +0 -0
- SNMP/static/images/brocade.png +0 -0
- SNMP/static/images/cisco.png +0 -0
- SNMP/static/images/dell.png +0 -0
- SNMP/static/images/dlink.png +0 -0
- SNMP/static/images/east.png +0 -0
- SNMP/static/images/eaton.png +0 -0
- SNMP/static/images/epson.png +0 -0
- SNMP/static/images/hauwei.png +0 -0
- SNMP/static/images/hp.png +0 -0
- SNMP/static/images/hpe.png +0 -0
- SNMP/static/images/ingrasys.png +0 -0
- SNMP/static/images/linux.png +0 -0
- SNMP/static/images/mellanox.png +0 -0
- SNMP/static/images/netapp.png +0 -0
- SNMP/static/images/paloalto.png +0 -0
- SNMP/static/images/phoenixtec.png +0 -0
- SNMP/static/images/ubiquiti.png +0 -0
- SNMP/static/images/unknown.png +0 -0
- SNMP/static/images/versa.png +0 -0
- SNMP/static/images/vertiv.png +0 -0
- SNMP/static/js/ai_device_template_modal.js +1116 -0
- SNMP/static/js/credentials_table.js +291 -0
- SNMP/static/js/devices_table.js +588 -0
- SNMP/static/js/discovered_devices.js +291 -0
- SNMP/static/js/network_map.js +1657 -0
- SNMP/static/js/networks_table.js +360 -0
- SNMP/static/js/onboarding.js +866 -0
- SNMP/static/js/overview.js +416 -0
- SNMP/static/js/snmp_changes_indicator.js +76 -0
- SNMP/static/js/snmp_commit_modal.js +39 -0
- SNMP/static/js/snmp_credentials_modal.js +217 -0
- SNMP/static/js/snmp_device_template_modal.js +669 -0
- SNMP/static/js/snmp_device_visual_preview.js +1707 -0
- SNMP/static/js/snmp_devices_modal.js +912 -0
- SNMP/static/js/snmp_diff_modal.js +1559 -0
- SNMP/static/js/snmp_network_modal.js +940 -0
- SNMP/static/js/snmp_profile_modal.js +1212 -0
- SNMP/static/js/snmp_profile_modal_helpers.js +17 -0
- SNMP/static/js/snmp_test.js +538 -0
- SNMP/templates/Credentials.html +325 -0
- SNMP/templates/DeviceTemplates.html +1059 -0
- SNMP/templates/Devices.html +274 -0
- SNMP/templates/Networks.html +469 -0
- SNMP/templates/Onboarding.html +521 -0
- SNMP/templates/Overview.html +227 -0
- SNMP/templates/components/ai_device_template_modal.html +46 -0
- SNMP/templates/components/ai_generate_template_content.html +224 -0
- SNMP/templates/components/device_template_profile_modal.html +60 -0
- SNMP/templates/components/discovered_devices_content.html +86 -0
- SNMP/templates/components/discovered_devices_modal.html +43 -0
- SNMP/templates/components/gmaps_latlon_modal.html +93 -0
- SNMP/templates/components/network_map.html +110 -0
- SNMP/templates/components/snmp_commit_modal.html +53 -0
- SNMP/templates/components/snmp_credentials_modal.html +189 -0
- SNMP/templates/components/snmp_device_modal.html +6 -0
- SNMP/templates/components/snmp_device_template_modal.html +129 -0
- SNMP/templates/components/snmp_device_visual_preview.html +347 -0
- SNMP/templates/components/snmp_devices_modal.html +330 -0
- SNMP/templates/components/snmp_diff_modal.html +148 -0
- SNMP/templates/components/snmp_network_modal.html +380 -0
- SNMP/templates/components/snmp_profile_modal.html +147 -0
- SNMP/templates/components/snmp_test_modal.html +398 -0
- SNMP/templatetags/__init__.py +0 -0
- SNMP/templatetags/snmp_extras.py +17 -0
- SNMP/urls.py +94 -0
- SNMP/views.py +913 -0
- Site/__init__.py +0 -0
- Site/apps.py +9 -0
- Site/migrations/__init__.py +0 -0
- Site/product_ca_views.py +41 -0
- Site/static/images/ElasticIcon.png +0 -0
- Site/static/images/LoggyIcon.png +0 -0
- Site/static/images/LoggyWizardIcon.png +0 -0
- Site/static/images/LogstashAgentIcon.png +0 -0
- Site/static/images/LogstashIcon.png +0 -0
- Site/static/js/base.js +192 -0
- Site/static/js/marked.min.js +69 -0
- Site/templates/base.html +52 -0
- Site/templates/error.html +65 -0
- Site/templates/home.html +148 -0
- Site/templates/navigation.html +530 -0
- Site/templates/popup.html +251 -0
- Site/templatetags/__init__.py +0 -0
- Site/templatetags/custom_filters.py +36 -0
- Site/urls.py +21 -0
- Site/views.py +200 -0
- Utilities/__init__.py +0 -0
- Utilities/apps.py +9 -0
- Utilities/data/grok-patterns/LICENSE +202 -0
- Utilities/data/grok-patterns/ecs-v1/aws +33 -0
- Utilities/data/grok-patterns/ecs-v1/bacula +53 -0
- Utilities/data/grok-patterns/ecs-v1/bind +13 -0
- Utilities/data/grok-patterns/ecs-v1/bro +30 -0
- Utilities/data/grok-patterns/ecs-v1/exim +26 -0
- Utilities/data/grok-patterns/ecs-v1/firewalls +111 -0
- Utilities/data/grok-patterns/ecs-v1/grok-patterns +95 -0
- Utilities/data/grok-patterns/ecs-v1/haproxy +40 -0
- Utilities/data/grok-patterns/ecs-v1/httpd +17 -0
- Utilities/data/grok-patterns/ecs-v1/java +34 -0
- Utilities/data/grok-patterns/ecs-v1/junos +13 -0
- Utilities/data/grok-patterns/ecs-v1/linux-syslog +16 -0
- Utilities/data/grok-patterns/ecs-v1/maven +1 -0
- Utilities/data/grok-patterns/ecs-v1/mcollective +4 -0
- Utilities/data/grok-patterns/ecs-v1/mongodb +7 -0
- Utilities/data/grok-patterns/ecs-v1/nagios +124 -0
- Utilities/data/grok-patterns/ecs-v1/postgresql +2 -0
- Utilities/data/grok-patterns/ecs-v1/rails +13 -0
- Utilities/data/grok-patterns/ecs-v1/redis +3 -0
- Utilities/data/grok-patterns/ecs-v1/ruby +2 -0
- Utilities/data/grok-patterns/ecs-v1/squid +6 -0
- Utilities/data/grok-patterns/ecs-v1/zeek +33 -0
- Utilities/data/grok-patterns/legacy/aws +14 -0
- Utilities/data/grok-patterns/legacy/bacula +50 -0
- Utilities/data/grok-patterns/legacy/bind +3 -0
- Utilities/data/grok-patterns/legacy/bro +13 -0
- Utilities/data/grok-patterns/legacy/exim +19 -0
- Utilities/data/grok-patterns/legacy/firewalls +91 -0
- Utilities/data/grok-patterns/legacy/grok-patterns +95 -0
- Utilities/data/grok-patterns/legacy/haproxy +39 -0
- Utilities/data/grok-patterns/legacy/httpd +15 -0
- Utilities/data/grok-patterns/legacy/java +17 -0
- Utilities/data/grok-patterns/legacy/junos +9 -0
- Utilities/data/grok-patterns/legacy/linux-syslog +16 -0
- Utilities/data/grok-patterns/legacy/maven +1 -0
- Utilities/data/grok-patterns/legacy/mcollective +1 -0
- Utilities/data/grok-patterns/legacy/mcollective-patterns +4 -0
- Utilities/data/grok-patterns/legacy/mongodb +7 -0
- Utilities/data/grok-patterns/legacy/nagios +124 -0
- Utilities/data/grok-patterns/legacy/postgresql +3 -0
- Utilities/data/grok-patterns/legacy/rails +13 -0
- Utilities/data/grok-patterns/legacy/redis +3 -0
- Utilities/data/grok-patterns/legacy/ruby +2 -0
- Utilities/data/grok-patterns/legacy/squid +4 -0
- Utilities/dissect.py +302 -0
- Utilities/grok.py +412 -0
- Utilities/migrations/__init__.py +0 -0
- Utilities/static/css/debugger_editor.css +88 -0
- Utilities/static/js/debugger_editor.js +93 -0
- Utilities/static/js/grok_debugger.js +131 -0
- Utilities/templates/dissect_debugger.html +95 -0
- Utilities/templates/grok_debugger.html +99 -0
- Utilities/urls.py +14 -0
- Utilities/views.py +363 -0
- logstashui-0.5.5.dev0.dist-info/METADATA +333 -0
- logstashui-0.5.5.dev0.dist-info/RECORD +762 -0
- logstashui-0.5.5.dev0.dist-info/WHEEL +4 -0
- logstashui-0.5.5.dev0.dist-info/entry_points.txt +2 -0
- logstashui-0.5.5.dev0.dist-info/licenses/LICENSE.txt +93 -0
- logstashui-0.5.5.dev0.dist-info/licenses/NOTICE.txt +2772 -0
- theme/__init__.py +0 -0
- theme/apps.py +9 -0
- theme/package-lock.json +6 -0
- theme/static/css/dist/styles.css +2 -0
- theme/static/images/favicon.ico +0 -0
- theme/static_src/.gitignore +1 -0
- theme/static_src/package-lock.json +1930 -0
- theme/static_src/package.json +26 -0
- theme/static_src/postcss.config.js +7 -0
- theme/static_src/src/styles.css +38 -0
- theme/static_src/tailwind.config.js +43 -0
- theme/templates/base.html +32 -0
|
@@ -0,0 +1,1581 @@
|
|
|
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
|
+
"""HTTP views for pipeline simulation, slot streaming, and sim-node health."""
|
|
6
|
+
|
|
7
|
+
from django.shortcuts import HttpResponse
|
|
8
|
+
from django.http import JsonResponse
|
|
9
|
+
from django.contrib.auth.decorators import login_required
|
|
10
|
+
from django.template.loader import get_template
|
|
11
|
+
from django.views.decorators.csrf import csrf_exempt
|
|
12
|
+
from django.conf import settings
|
|
13
|
+
from django.db import OperationalError
|
|
14
|
+
from django.utils.crypto import constant_time_compare, salted_hmac
|
|
15
|
+
from Common import logstash_config_parse
|
|
16
|
+
|
|
17
|
+
from Common.decorators import require_admin_role
|
|
18
|
+
from PipelineManager.agent_modes import list_simulation_targets, resolve_simulation_target
|
|
19
|
+
from datetime import datetime, timezone as dt_timezone
|
|
20
|
+
from PipelineManager.models import Connection as ConnectionTable, SimulationResult
|
|
21
|
+
|
|
22
|
+
from dataclasses import dataclass
|
|
23
|
+
|
|
24
|
+
import json
|
|
25
|
+
import os
|
|
26
|
+
import traceback
|
|
27
|
+
import logging
|
|
28
|
+
import requests
|
|
29
|
+
import uuid
|
|
30
|
+
import base64
|
|
31
|
+
import time
|
|
32
|
+
import re
|
|
33
|
+
from html import escape as _html_escape
|
|
34
|
+
from Common.product_ca import agent_requests_verify
|
|
35
|
+
from PipelineManager.agent_client import agent_auth_headers
|
|
36
|
+
|
|
37
|
+
logger = logging.getLogger(__name__)
|
|
38
|
+
|
|
39
|
+
_RUN_ID_SALT = 'PipelineManager.simulation.run_id'
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _run_id_mac(value):
|
|
43
|
+
return salted_hmac(_RUN_ID_SALT, value).hexdigest()[:16]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def new_run_id():
|
|
47
|
+
"""Return a fresh simulation run id that :func:`StreamSimulate` will accept.
|
|
48
|
+
|
|
49
|
+
The id is a UUID, its creation time, and a short HMAC under ``SECRET_KEY``,
|
|
50
|
+
so any worker can tell a run this server started from a made-up one
|
|
51
|
+
without shared state, and an id stops being accepted once its results
|
|
52
|
+
would be pruned anyway.
|
|
53
|
+
|
|
54
|
+
Examples:
|
|
55
|
+
>>> is_known_run_id(new_run_id())
|
|
56
|
+
True
|
|
57
|
+
>>> is_known_run_id('6f1c0f7e-0000-4000-8000-000000000000')
|
|
58
|
+
False
|
|
59
|
+
"""
|
|
60
|
+
value = f"{uuid.uuid4()}-{int(time.time()):08x}"
|
|
61
|
+
return f"{value}-{_run_id_mac(value)}"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def is_known_run_id(run_id):
|
|
65
|
+
"""Return True when ``run_id`` came from :func:`new_run_id` and hasn't expired.
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
run_id: The ``run_id`` a posted event carries.
|
|
69
|
+
"""
|
|
70
|
+
value, _, mac = str(run_id).rpartition('-')
|
|
71
|
+
_, _, created = value.rpartition('-')
|
|
72
|
+
try:
|
|
73
|
+
age = time.time() - int(created, 16)
|
|
74
|
+
except ValueError:
|
|
75
|
+
return False
|
|
76
|
+
return 0 <= age <= SimulationResult.MAX_AGE_SECONDS and constant_time_compare(mac, _run_id_mac(value))
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# Identical for every drop plugin so JRuby compiles it once. The drop decision
|
|
80
|
+
# matches logstash-filter-drop: percentage == 100 || rand < percentage / 100.
|
|
81
|
+
_DROP_CODE = """
|
|
82
|
+
require "net/http"
|
|
83
|
+
require "uri"
|
|
84
|
+
require "json"
|
|
85
|
+
|
|
86
|
+
percentage = event.get("[@metadata][simulation_drop_percentage]").to_f
|
|
87
|
+
event.remove("[@metadata][simulation_drop_percentage]")
|
|
88
|
+
dropped = percentage >= 100 || rand < (percentage / 100.0)
|
|
89
|
+
event.remove("[simulation][final]") unless dropped
|
|
90
|
+
|
|
91
|
+
# Create snapshot of current event state for the drop plugin
|
|
92
|
+
snapshot = {}
|
|
93
|
+
event.to_hash.each do |key, value|
|
|
94
|
+
# Skip metadata and snapshots field itself to avoid recursion
|
|
95
|
+
next if key.start_with?("@metadata") || key == "snapshots"
|
|
96
|
+
snapshot[key] = value
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
plugin_id = event.get("[simulation][id]")
|
|
100
|
+
event.set("[snapshots][#{plugin_id}]", snapshot)
|
|
101
|
+
|
|
102
|
+
if dropped
|
|
103
|
+
# A dropped event never reaches the output, so report it here
|
|
104
|
+
uri = URI.parse("__CALLBACK_URL__/ConnectionManager/StreamSimulate/")
|
|
105
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
|
106
|
+
http.use_ssl = (uri.scheme == "https")
|
|
107
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl?
|
|
108
|
+
|
|
109
|
+
request = Net::HTTP::Post.new(uri.path, {"Content-Type" => "application/json"})
|
|
110
|
+
request.body = event.to_hash.to_json
|
|
111
|
+
|
|
112
|
+
begin
|
|
113
|
+
response = http.request(request)
|
|
114
|
+
puts "Drop plugin HTTP response: #{response.code} #{response.message}"
|
|
115
|
+
rescue => e
|
|
116
|
+
puts "Drop plugin HTTP error: #{e.class} - #{e.message}"
|
|
117
|
+
puts e.backtrace.join("\\n")
|
|
118
|
+
end
|
|
119
|
+
event.cancel
|
|
120
|
+
end
|
|
121
|
+
""".strip()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _drop_instrumentation(plugin, step, callback_url):
|
|
125
|
+
"""Return the filters that stand in for a ``drop`` plugin during simulation.
|
|
126
|
+
|
|
127
|
+
A dropped event never reaches the output, so the Ruby filter posts it to
|
|
128
|
+
``StreamSimulate`` (marked ``simulation.final``) and cancels it. With
|
|
129
|
+
``percentage`` below 100 the event may survive; then nothing is posted,
|
|
130
|
+
the marker is removed, and the event continues to the next filter. The
|
|
131
|
+
original drop plugin is left out because the Ruby filter already decided.
|
|
132
|
+
|
|
133
|
+
Args:
|
|
134
|
+
plugin: The parsed ``drop`` component.
|
|
135
|
+
step: This plugin's step number in the run.
|
|
136
|
+
callback_url: LogstashUI base URL the simulate agent can reach.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
list: A ``mutate`` that sets step metadata, then the ``ruby`` filter.
|
|
140
|
+
|
|
141
|
+
Examples:
|
|
142
|
+
>>> mutate, ruby = _drop_instrumentation(
|
|
143
|
+
... {'id': 'filter_drop_2', 'plugin': 'drop', 'config': {'percentage': 40}},
|
|
144
|
+
... 3, 'https://ui:8443')
|
|
145
|
+
>>> mutate['config']['replace']['[@metadata][simulation_drop_percentage]']
|
|
146
|
+
'40'
|
|
147
|
+
"""
|
|
148
|
+
percentage = (plugin.get('config') or {}).get('percentage', 100)
|
|
149
|
+
return [
|
|
150
|
+
{
|
|
151
|
+
"type": "filter",
|
|
152
|
+
"plugin": "mutate",
|
|
153
|
+
"config": {
|
|
154
|
+
# replace, not add_field, so repeated drops don't build arrays
|
|
155
|
+
"replace": {
|
|
156
|
+
"[simulation][step]": str(step),
|
|
157
|
+
"[simulation][id]": plugin['id'],
|
|
158
|
+
"[simulation][final]": "true",
|
|
159
|
+
"[@metadata][simulation_drop_percentage]": str(percentage),
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
"type": "filter",
|
|
165
|
+
"plugin": "ruby",
|
|
166
|
+
"config": {"code": _DROP_CODE.replace("__CALLBACK_URL__", callback_url)},
|
|
167
|
+
},
|
|
168
|
+
]
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
def _sim_agent_url(request):
|
|
172
|
+
"""Resolve the simulate agent for ``request``; see :func:`_resolve_sim_agent`."""
|
|
173
|
+
connection_id = (
|
|
174
|
+
request.POST.get("sim_connection_id")
|
|
175
|
+
or request.GET.get("sim_connection_id")
|
|
176
|
+
or request.POST.get("connection_id")
|
|
177
|
+
)
|
|
178
|
+
return _resolve_sim_agent(connection_id, request.session)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def _resolve_sim_agent(connection_id, session):
|
|
182
|
+
"""Resolve the LogstashAgent base URL for simulation traffic.
|
|
183
|
+
|
|
184
|
+
Prefer explicit ``connection_id``; else sticky session / single target;
|
|
185
|
+
fall back to ``settings.LOGSTASH_AGENT_URL`` when no enrolled sim agents
|
|
186
|
+
exist (legacy embedded static URL).
|
|
187
|
+
|
|
188
|
+
Args:
|
|
189
|
+
connection_id: Simulate-agent connection, or empty for the default.
|
|
190
|
+
session: Session-like dict; the chosen target is stored back on it.
|
|
191
|
+
|
|
192
|
+
Returns:
|
|
193
|
+
``(base_url, target_dict_or_None, error_or_None)``.
|
|
194
|
+
"""
|
|
195
|
+
if connection_id in (None, "", "null", "undefined"):
|
|
196
|
+
connection_id = None
|
|
197
|
+
|
|
198
|
+
target, err = resolve_simulation_target(connection_id, session=session)
|
|
199
|
+
if target and target.get("base_url"):
|
|
200
|
+
session["sim_connection_id"] = target["connection_id"]
|
|
201
|
+
try:
|
|
202
|
+
ConnectionTable.objects.filter(pk=target["connection_id"]).update(
|
|
203
|
+
last_selected_at=datetime.now(dt_timezone.utc)
|
|
204
|
+
)
|
|
205
|
+
except Exception:
|
|
206
|
+
pass
|
|
207
|
+
return target["base_url"], target, None
|
|
208
|
+
|
|
209
|
+
# Fallback: historical static setting (embedded docker / host.docker.internal)
|
|
210
|
+
fallback = getattr(settings, "LOGSTASH_AGENT_URL", None)
|
|
211
|
+
if fallback:
|
|
212
|
+
return fallback, None, None
|
|
213
|
+
return None, None, err or "No simulation agent URL available"
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _sim_agent_headers(target):
|
|
217
|
+
"""Auth headers for the agent ``_sim_agent_url`` resolved.
|
|
218
|
+
|
|
219
|
+
``target`` None means the ``settings.LOGSTASH_AGENT_URL`` embedded fallback.
|
|
220
|
+
"""
|
|
221
|
+
return agent_auth_headers((target or {}).get("connection_id"))
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
@require_admin_role
|
|
225
|
+
def GetSimulationTargets(request):
|
|
226
|
+
"""List simulate-capable agents for the pipeline editor dropdown.
|
|
227
|
+
|
|
228
|
+
Returns:
|
|
229
|
+
JSON ``{success, targets, selected_connection_id, count}``.
|
|
230
|
+
"""
|
|
231
|
+
if request.method != "GET":
|
|
232
|
+
return JsonResponse({"error": "Method not allowed"}, status=405)
|
|
233
|
+
targets = list_simulation_targets(ensure_embedded=True)
|
|
234
|
+
selected = request.session.get("sim_connection_id")
|
|
235
|
+
# Sticky selection may be stale; clear if not in list
|
|
236
|
+
if selected is not None and not any(t["connection_id"] == selected for t in targets):
|
|
237
|
+
selected = None
|
|
238
|
+
try:
|
|
239
|
+
del request.session["sim_connection_id"]
|
|
240
|
+
except KeyError:
|
|
241
|
+
pass
|
|
242
|
+
if selected is None and len(targets) == 1:
|
|
243
|
+
selected = targets[0]["connection_id"]
|
|
244
|
+
request.session["sim_connection_id"] = selected
|
|
245
|
+
return JsonResponse(
|
|
246
|
+
{
|
|
247
|
+
"success": True,
|
|
248
|
+
"targets": targets,
|
|
249
|
+
"selected_connection_id": selected,
|
|
250
|
+
"count": len(targets),
|
|
251
|
+
}
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
@require_admin_role
|
|
256
|
+
def SelectSimulationTarget(request):
|
|
257
|
+
"""Persist the chosen simulation agent in the session (sticky selection).
|
|
258
|
+
|
|
259
|
+
Args:
|
|
260
|
+
connection_id: Simulate/embedded connection pk.
|
|
261
|
+
|
|
262
|
+
Examples:
|
|
263
|
+
payload = {"connection_id": 12}
|
|
264
|
+
# {"success": True, "selected_connection_id": 12, "label": "LogstashUI-simulate-1", ...}
|
|
265
|
+
"""
|
|
266
|
+
if request.method != "POST":
|
|
267
|
+
return JsonResponse({"error": "Method not allowed"}, status=405)
|
|
268
|
+
try:
|
|
269
|
+
data = json.loads(request.body or "{}")
|
|
270
|
+
except json.JSONDecodeError:
|
|
271
|
+
data = {}
|
|
272
|
+
connection_id = data.get("connection_id") or request.POST.get("connection_id")
|
|
273
|
+
if connection_id in (None, "", "null"):
|
|
274
|
+
return JsonResponse({"success": False, "error": "connection_id required"}, status=400)
|
|
275
|
+
target, err = resolve_simulation_target(connection_id, session=None)
|
|
276
|
+
if not target:
|
|
277
|
+
return JsonResponse({"success": False, "error": err or "not found"}, status=404)
|
|
278
|
+
request.session["sim_connection_id"] = target["connection_id"]
|
|
279
|
+
try:
|
|
280
|
+
ConnectionTable.objects.filter(pk=target["connection_id"]).update(
|
|
281
|
+
last_selected_at=datetime.now(dt_timezone.utc)
|
|
282
|
+
)
|
|
283
|
+
except Exception:
|
|
284
|
+
pass
|
|
285
|
+
return JsonResponse(
|
|
286
|
+
{
|
|
287
|
+
"success": True,
|
|
288
|
+
"selected_connection_id": target["connection_id"],
|
|
289
|
+
"label": target.get("label"),
|
|
290
|
+
"base_url": target.get("base_url"),
|
|
291
|
+
}
|
|
292
|
+
)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
@dataclass
|
|
296
|
+
class SimulationStart:
|
|
297
|
+
"""Outcome of :func:`start_simulation`.
|
|
298
|
+
|
|
299
|
+
Attributes:
|
|
300
|
+
run_id: Tracks this event's results (``"preallocation"`` for a
|
|
301
|
+
slot-only request); ``None`` if the run never started.
|
|
302
|
+
slot_id: Agent slot holding the instrumented pipeline.
|
|
303
|
+
reused: The agent reused a slot with the same config.
|
|
304
|
+
filter_count: Filters instrumented, including nested ones.
|
|
305
|
+
agent_url: Simulate agent the event went to.
|
|
306
|
+
agent_headers: Auth headers for ``agent_url``; pass them to
|
|
307
|
+
:func:`send_simulation_event` for later events in the slot.
|
|
308
|
+
error: Display message when the run did not start.
|
|
309
|
+
level: ``error``, ``warning``, or ``info`` for ``error``.
|
|
310
|
+
pipeline_failed: The agent rejected the pipeline or slot; the editor
|
|
311
|
+
stops polling for pipeline status.
|
|
312
|
+
queued: The agent queued the event while Logstash restarts.
|
|
313
|
+
forward_error: Sending the event failed or timed out; results may
|
|
314
|
+
still arrive.
|
|
315
|
+
"""
|
|
316
|
+
|
|
317
|
+
run_id: str | None = None
|
|
318
|
+
slot_id: int | None = None
|
|
319
|
+
reused: bool = False
|
|
320
|
+
filter_count: int = 0
|
|
321
|
+
agent_url: str | None = None
|
|
322
|
+
agent_headers: dict | None = None
|
|
323
|
+
error: str | None = None
|
|
324
|
+
level: str = 'error'
|
|
325
|
+
pipeline_failed: bool = False
|
|
326
|
+
queued: bool = False
|
|
327
|
+
forward_error: str | None = None
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
@require_admin_role
|
|
331
|
+
def SimulatePipeline(request):
|
|
332
|
+
"""Run a pipeline simulation with per-filter Ruby instrumentation.
|
|
333
|
+
|
|
334
|
+
Injects snapshot code after each filter plugin so the editor can show
|
|
335
|
+
step-by-step event state. Empty ``log_text`` is a slot-preallocation
|
|
336
|
+
request (deterministic ``run_id``).
|
|
337
|
+
|
|
338
|
+
Args:
|
|
339
|
+
components: Visual-editor components JSON.
|
|
340
|
+
log_text: Sample events (empty = preallocate slot).
|
|
341
|
+
ls_id / policy_id: Optional policy association for keystore sync.
|
|
342
|
+
sim_connection_id: Optional simulate target.
|
|
343
|
+
|
|
344
|
+
Examples:
|
|
345
|
+
# POST form
|
|
346
|
+
# components = '{"filter": [{"plugin": "grok", ...}]}'
|
|
347
|
+
# log_text = "one event per line"
|
|
348
|
+
# HTML result table is returned (not JSON).
|
|
349
|
+
"""
|
|
350
|
+
|
|
351
|
+
if request.method != 'POST':
|
|
352
|
+
return JsonResponse({"error": "Method not allowed"}, status=405)
|
|
353
|
+
|
|
354
|
+
components_json = request.POST.get('components')
|
|
355
|
+
if not components_json:
|
|
356
|
+
return HttpResponse('<div class="text-red-400">Error: No pipeline components provided</div>')
|
|
357
|
+
try:
|
|
358
|
+
components = json.loads(components_json)
|
|
359
|
+
except json.JSONDecodeError as e:
|
|
360
|
+
logger.error(f"Failed to parse components JSON: {e}")
|
|
361
|
+
return HttpResponse('<div class="text-red-400">Error: Invalid components data</div>')
|
|
362
|
+
|
|
363
|
+
log_text = request.POST.get('log_text', '').strip()
|
|
364
|
+
start = start_simulation(
|
|
365
|
+
components,
|
|
366
|
+
log_text,
|
|
367
|
+
ui_base_url=request.build_absolute_uri("/").rstrip("/"),
|
|
368
|
+
session=request.session,
|
|
369
|
+
sim_connection_id=(
|
|
370
|
+
request.POST.get("sim_connection_id")
|
|
371
|
+
or request.GET.get("sim_connection_id")
|
|
372
|
+
or request.POST.get("connection_id")
|
|
373
|
+
),
|
|
374
|
+
session_slot_raw=request.POST.get("slot_id") or request.POST.get("session_slot_id"),
|
|
375
|
+
policy_id=request.POST.get('policy_id') or request.GET.get('policy_id'),
|
|
376
|
+
ls_id=request.POST.get('ls_id') or request.GET.get('ls_id'),
|
|
377
|
+
pipeline_text=request.POST.get('pipeline_text', '') or '',
|
|
378
|
+
pipeline_name=request.GET.get('pipeline', 'simulation') or request.POST.get('pipeline', 'simulation'),
|
|
379
|
+
)
|
|
380
|
+
|
|
381
|
+
if start.error:
|
|
382
|
+
color = {'error': 'red', 'warning': 'yellow', 'info': 'gray'}[start.level]
|
|
383
|
+
attrs = ''
|
|
384
|
+
if start.pipeline_failed:
|
|
385
|
+
attrs = (f' data-slot-id="{start.slot_id}"' if start.slot_id else '') + ' data-pipeline-failed="true"'
|
|
386
|
+
return HttpResponse(f'<div class="text-{color}-400"{attrs}>{_html_escape(start.error)}</div>')
|
|
387
|
+
|
|
388
|
+
if not log_text:
|
|
389
|
+
return HttpResponse(f'''
|
|
390
|
+
<div class="p-4 bg-blue-900/30 border border-blue-600 rounded-lg" data-slot-id="{start.slot_id}">
|
|
391
|
+
<h3 class="text-lg font-semibold text-blue-400 mb-2">✓ Slot Allocated</h3>
|
|
392
|
+
<p class="text-blue-200">Slot {start.slot_id} {"(reused - same config)" if start.reused else "(new)"} with {len(components.get('filter', []))} instrumented filter(s)</p>
|
|
393
|
+
</div>
|
|
394
|
+
''')
|
|
395
|
+
|
|
396
|
+
# Results are streamed via StreamSimulate; the template polls for them.
|
|
397
|
+
context = {
|
|
398
|
+
'filter_count': start.filter_count,
|
|
399
|
+
'slot_id': start.slot_id,
|
|
400
|
+
'reused': start.reused,
|
|
401
|
+
'run_id': start.run_id,
|
|
402
|
+
}
|
|
403
|
+
if start.queued:
|
|
404
|
+
context['queued'] = True
|
|
405
|
+
if start.forward_error:
|
|
406
|
+
context['forward_error'] = start.forward_error
|
|
407
|
+
result_html = get_template('components/pipeline_editor/simulation_results.html').render(context, request)
|
|
408
|
+
if start.forward_error:
|
|
409
|
+
# Visible error marker the FE can parse, then the normal results
|
|
410
|
+
# bootstrap (initSimulationResults(run_id)).
|
|
411
|
+
result_html = (
|
|
412
|
+
f'<div class="text-yellow-400" data-sim-forward-error="true" '
|
|
413
|
+
f'data-run-id="{start.run_id}" data-slot-id="{start.slot_id}">'
|
|
414
|
+
f'Warning: simulation forward timed out or failed '
|
|
415
|
+
f'({_html_escape(start.forward_error[:200])}); polling for results…'
|
|
416
|
+
f'</div>'
|
|
417
|
+
+ result_html
|
|
418
|
+
)
|
|
419
|
+
return HttpResponse(result_html)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
def start_simulation(components, log_text, *, ui_base_url, session, sim_connection_id=None,
|
|
423
|
+
session_slot_raw=None, policy_id=None, ls_id=None, pipeline_text='',
|
|
424
|
+
pipeline_name='simulation'):
|
|
425
|
+
"""Instrument ``components``, get a slot on a simulate agent, and send ``log_text``.
|
|
426
|
+
|
|
427
|
+
Results arrive asynchronously at ``StreamSimulate`` and are read with
|
|
428
|
+
:meth:`~PipelineManager.models.SimulationResult.take`.
|
|
429
|
+
|
|
430
|
+
Args:
|
|
431
|
+
components: Parsed pipeline components (``{'filter': [...]}``).
|
|
432
|
+
log_text: One event (log line or JSON text). Empty only allocates a slot.
|
|
433
|
+
ui_base_url: This LogstashUI's base URL, for the agent's result callback.
|
|
434
|
+
session: Session-like dict holding the sticky ``sim_connection_id``.
|
|
435
|
+
sim_connection_id: Simulate-agent connection to use.
|
|
436
|
+
session_slot_raw: Session slot to reuse if it is still loaded on that agent.
|
|
437
|
+
policy_id: Policy whose keystore backs ``${VAR}`` references.
|
|
438
|
+
ls_id: Legacy policy reference for keystore sync.
|
|
439
|
+
pipeline_text: Raw LSCL, scanned for keystore references.
|
|
440
|
+
pipeline_name: Name sent with the slot allocation.
|
|
441
|
+
|
|
442
|
+
Returns:
|
|
443
|
+
SimulationStart: Check ``error`` first.
|
|
444
|
+
|
|
445
|
+
Examples:
|
|
446
|
+
>>> start = start_simulation({'filter': [...]}, 'a log line',
|
|
447
|
+
... ui_base_url='https://ui:8443', session={})
|
|
448
|
+
>>> start.error or start.run_id
|
|
449
|
+
'a3f0…'
|
|
450
|
+
"""
|
|
451
|
+
try:
|
|
452
|
+
# Extract filter plugins from components
|
|
453
|
+
filter_plugins = components.get('filter', [])
|
|
454
|
+
|
|
455
|
+
if not filter_plugins and not log_text:
|
|
456
|
+
return SimulationStart(error='No filters to simulate', level='info')
|
|
457
|
+
|
|
458
|
+
if not filter_plugins:
|
|
459
|
+
return SimulationStart(error='Warning: No filter plugins found in pipeline', level='warning')
|
|
460
|
+
|
|
461
|
+
# Generate run_id for this simulation
|
|
462
|
+
# For slot preallocation (empty log_text), use a deterministic ID to ensure consistent hashing
|
|
463
|
+
# For actual simulations, generate a unique UUID to track results
|
|
464
|
+
if not log_text:
|
|
465
|
+
run_id = "preallocation"
|
|
466
|
+
logger.info(f"[FE->BE] Slot preallocation request - {len(filter_plugins)} filter plugins: {[p.get('plugin', 'unknown') for p in filter_plugins]}")
|
|
467
|
+
else:
|
|
468
|
+
run_id = new_run_id()
|
|
469
|
+
logger.info(f"[FE->BE] Starting simulation with run_id: {run_id} - {len(filter_plugins)} filter plugins: {[p.get('plugin', 'unknown') for p in filter_plugins]}")
|
|
470
|
+
|
|
471
|
+
# Get logstashagent URL early so we can use it in instrumentation
|
|
472
|
+
logstash_agent_url, sim_target, sim_err = _resolve_sim_agent(sim_connection_id, session)
|
|
473
|
+
if not logstash_agent_url:
|
|
474
|
+
return SimulationStart(error=f'Error: {sim_err or "No simulation agent available"}')
|
|
475
|
+
agent_headers = _sim_agent_headers(sim_target)
|
|
476
|
+
|
|
477
|
+
# Clone source-policy keystore onto the simulate agent when ${...} vars appear
|
|
478
|
+
try:
|
|
479
|
+
from PipelineManager.sim_keystore import maybe_sync_keystore_for_simulation
|
|
480
|
+
|
|
481
|
+
maybe_sync_keystore_for_simulation(
|
|
482
|
+
agent_base_url=logstash_agent_url,
|
|
483
|
+
components=components,
|
|
484
|
+
pipeline_text=pipeline_text,
|
|
485
|
+
ls_id=ls_id,
|
|
486
|
+
policy_id=policy_id,
|
|
487
|
+
agent_headers=agent_headers,
|
|
488
|
+
)
|
|
489
|
+
except Exception as ks_err:
|
|
490
|
+
logger.error("Keystore sync before simulation failed: %s", ks_err, exc_info=True)
|
|
491
|
+
# Fail closed when refs exist would be safer; allow sim to continue so
|
|
492
|
+
# non-secret paths still work — surface error if components have refs
|
|
493
|
+
from PipelineManager.sim_keystore import find_keystore_refs_in_obj
|
|
494
|
+
if find_keystore_refs_in_obj(components):
|
|
495
|
+
return SimulationStart(
|
|
496
|
+
error=f'Error: Failed to sync keystore to simulation agent: {ks_err}'
|
|
497
|
+
)
|
|
498
|
+
|
|
499
|
+
# Callback URL for Ruby instrumentation posts (remote simulate agents need
|
|
500
|
+
# a reachable LogstashUI URL; prefer agent-reported enroll URL later).
|
|
501
|
+
policy_type = (sim_target or {}).get("policy_type") or ""
|
|
502
|
+
if policy_type == "SIMULATE":
|
|
503
|
+
logstash_ui_url = ui_base_url
|
|
504
|
+
elif policy_type == "EMBEDDED":
|
|
505
|
+
logstash_ui_url = os.environ.get(
|
|
506
|
+
"LOGSTASHUI_SIMULATION_CALLBACK_URL",
|
|
507
|
+
"https://logstashui:8443",
|
|
508
|
+
).rstrip("/")
|
|
509
|
+
else:
|
|
510
|
+
logstash_ui_url = (
|
|
511
|
+
os.environ.get("LOGSTASHUI_SIMULATION_CALLBACK_URL")
|
|
512
|
+
or ui_base_url
|
|
513
|
+
).rstrip("/")
|
|
514
|
+
|
|
515
|
+
from LogstashUI.insecure_http import force_http_url
|
|
516
|
+
|
|
517
|
+
logstash_ui_url = force_http_url(logstash_ui_url)
|
|
518
|
+
|
|
519
|
+
logger.debug("USING THIS URL: %s", logstash_ui_url)
|
|
520
|
+
# Recursive function to instrument plugins, including nested conditionals
|
|
521
|
+
step_counter = [0] # Use list to maintain counter across recursive calls
|
|
522
|
+
|
|
523
|
+
def instrument_plugins(plugins_list):
|
|
524
|
+
"""Recursively instrument plugins, including nested ``if`` branches.
|
|
525
|
+
|
|
526
|
+
Nested plugins inside conditionals are instrumented; the
|
|
527
|
+
condition itself is not.
|
|
528
|
+
"""
|
|
529
|
+
instrumented = []
|
|
530
|
+
|
|
531
|
+
for plugin in plugins_list:
|
|
532
|
+
if plugin.get('plugin') == 'if':
|
|
533
|
+
# This is a conditional plugin - we need to instrument its nested plugins
|
|
534
|
+
conditional_plugin = plugin.copy()
|
|
535
|
+
conditional_plugin['config'] = plugin['config'].copy()
|
|
536
|
+
conditional_id = plugin['id']
|
|
537
|
+
|
|
538
|
+
# Instrument plugins in the main 'if' block
|
|
539
|
+
if 'plugins' in conditional_plugin['config']:
|
|
540
|
+
# Add branch tracking at the start of the if block using mutate filter
|
|
541
|
+
# This avoids injecting unique values into Ruby code, allowing JRuby code reuse
|
|
542
|
+
if_condition = conditional_plugin['config'].get('condition', '')
|
|
543
|
+
branch_tracker = {
|
|
544
|
+
"id": f"{conditional_id}_if_tracker",
|
|
545
|
+
"type": "filter",
|
|
546
|
+
"plugin": "mutate",
|
|
547
|
+
"config": {
|
|
548
|
+
"replace": {
|
|
549
|
+
f"[simulation][conditional_branches][{conditional_id}]": "if",
|
|
550
|
+
f"[simulation][conditional_conditions][{conditional_id}]": if_condition
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
conditional_plugin['config']['plugins'] = [branch_tracker] + instrument_plugins(
|
|
555
|
+
conditional_plugin['config']['plugins']
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
# Instrument plugins in 'else_ifs' blocks
|
|
559
|
+
if 'else_ifs' in conditional_plugin['config']:
|
|
560
|
+
instrumented_else_ifs = []
|
|
561
|
+
for else_if_idx, else_if in enumerate(conditional_plugin['config']['else_ifs']):
|
|
562
|
+
else_if_copy = else_if.copy()
|
|
563
|
+
if 'plugins' in else_if_copy:
|
|
564
|
+
# Add branch tracking at the start of the else_if block using mutate filter
|
|
565
|
+
# This avoids injecting unique values into Ruby code, allowing JRuby code reuse
|
|
566
|
+
else_if_condition = else_if.get('condition', '')
|
|
567
|
+
branch_tracker = {
|
|
568
|
+
"id": f"{conditional_id}_elseif{else_if_idx}_tracker",
|
|
569
|
+
"type": "filter",
|
|
570
|
+
"plugin": "mutate",
|
|
571
|
+
"config": {
|
|
572
|
+
"replace": {
|
|
573
|
+
f"[simulation][conditional_branches][{conditional_id}]": f"else_if_{else_if_idx}",
|
|
574
|
+
f"[simulation][conditional_conditions][{conditional_id}]": else_if_condition
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
else_if_copy['plugins'] = [branch_tracker] + instrument_plugins(else_if_copy['plugins'])
|
|
579
|
+
instrumented_else_ifs.append(else_if_copy)
|
|
580
|
+
conditional_plugin['config']['else_ifs'] = instrumented_else_ifs
|
|
581
|
+
|
|
582
|
+
# Instrument plugins in 'else' block
|
|
583
|
+
if 'else' in conditional_plugin['config'] and conditional_plugin['config']['else']:
|
|
584
|
+
else_block = conditional_plugin['config']['else'].copy()
|
|
585
|
+
if 'plugins' in else_block:
|
|
586
|
+
# Add branch tracking at the start of the else block using mutate filter
|
|
587
|
+
# This avoids injecting unique values into Ruby code, allowing JRuby code reuse
|
|
588
|
+
branch_tracker = {
|
|
589
|
+
"id": f"{conditional_id}_else_tracker",
|
|
590
|
+
"type": "filter",
|
|
591
|
+
"plugin": "mutate",
|
|
592
|
+
"config": {
|
|
593
|
+
"replace": {
|
|
594
|
+
f"[simulation][conditional_branches][{conditional_id}]": "else"
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
else_block['plugins'] = [branch_tracker] + instrument_plugins(else_block['plugins'])
|
|
599
|
+
conditional_plugin['config']['else'] = else_block
|
|
600
|
+
|
|
601
|
+
# Add the conditional plugin with instrumented nested plugins
|
|
602
|
+
instrumented.append(conditional_plugin)
|
|
603
|
+
else:
|
|
604
|
+
# Regular plugin - add pre-plugin timing instrumentation
|
|
605
|
+
# Increment step counter
|
|
606
|
+
step_counter[0] += 1
|
|
607
|
+
current_step = step_counter[0]
|
|
608
|
+
|
|
609
|
+
if plugin.get('plugin') == 'drop':
|
|
610
|
+
instrumented.extend(_drop_instrumentation(plugin, current_step, logstash_ui_url))
|
|
611
|
+
else:
|
|
612
|
+
# Regular plugin - add normal timing instrumentation
|
|
613
|
+
# Add pre-plugin timing instrumentation
|
|
614
|
+
# This code is IDENTICAL for all plugins, allowing JRuby to compile once and reuse
|
|
615
|
+
pre_instrumentation_code = (
|
|
616
|
+
"# Capture start time in nanoseconds before plugin execution\n"
|
|
617
|
+
"event.set(\"[simulation][timing][start_ns]\", (Time.now.to_f * 1_000_000_000).to_i)"
|
|
618
|
+
)
|
|
619
|
+
|
|
620
|
+
pre_instrumentation_plugin = {
|
|
621
|
+
"type": "filter",
|
|
622
|
+
"plugin": "ruby",
|
|
623
|
+
"config": {
|
|
624
|
+
"code": pre_instrumentation_code
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
instrumented.append(pre_instrumentation_plugin)
|
|
629
|
+
|
|
630
|
+
# Add the actual plugin
|
|
631
|
+
instrumented.append(plugin)
|
|
632
|
+
|
|
633
|
+
# Add mutate filter to set step and id metadata
|
|
634
|
+
# This avoids embedding unique values in Ruby code, allowing code reuse
|
|
635
|
+
# Use replace instead of add_field to avoid array accumulation
|
|
636
|
+
metadata_plugin = {
|
|
637
|
+
"type": "filter",
|
|
638
|
+
"plugin": "mutate",
|
|
639
|
+
"config": {
|
|
640
|
+
"replace": {
|
|
641
|
+
"[simulation][step]": str(current_step),
|
|
642
|
+
"[simulation][id]": plugin['id']
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
instrumented.append(metadata_plugin)
|
|
647
|
+
|
|
648
|
+
# Add Ruby instrumentation after this plugin
|
|
649
|
+
# This code is now IDENTICAL for all plugins, allowing JRuby to compile once and reuse
|
|
650
|
+
instrumentation_code = (
|
|
651
|
+
"end_ns = (Time.now.to_f * 1_000_000_000).to_i\n"
|
|
652
|
+
"start_ns = event.get(\"[simulation][timing][start_ns]\")\n"
|
|
653
|
+
"if start_ns\n"
|
|
654
|
+
" execution_ns = end_ns - start_ns\n"
|
|
655
|
+
" event.set(\"[simulation][timing][execution_ns]\", execution_ns)\n"
|
|
656
|
+
" event.set(\"[simulation][timing][end_ns]\", end_ns)\n"
|
|
657
|
+
"end\n"
|
|
658
|
+
"\n"
|
|
659
|
+
"snapshot = {}\n"
|
|
660
|
+
"event.to_hash.each do |key, value|\n"
|
|
661
|
+
" next if key.start_with?(\"@metadata\") || key == \"snapshots\"\n"
|
|
662
|
+
" snapshot[key] = value\n"
|
|
663
|
+
"end\n"
|
|
664
|
+
"\n"
|
|
665
|
+
"plugin_id = event.get(\"[simulation][id]\")\n"
|
|
666
|
+
"event.set(\"[snapshots][#{plugin_id}]\", snapshot)"
|
|
667
|
+
)
|
|
668
|
+
|
|
669
|
+
instrumentation_plugin = {
|
|
670
|
+
"type": "filter",
|
|
671
|
+
"plugin": "ruby",
|
|
672
|
+
"config": {
|
|
673
|
+
"code": instrumentation_code
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
instrumented.append(instrumentation_plugin)
|
|
677
|
+
|
|
678
|
+
return instrumented
|
|
679
|
+
|
|
680
|
+
# Build instrumented filter list
|
|
681
|
+
instrumented_filters = instrument_plugins(filter_plugins)
|
|
682
|
+
|
|
683
|
+
# Count total plugins including nested ones in conditionals
|
|
684
|
+
def count_all_plugins(plugins_list):
|
|
685
|
+
"""Recursively count all plugins, including those nested in conditionals."""
|
|
686
|
+
count = 0
|
|
687
|
+
for plugin in plugins_list:
|
|
688
|
+
if plugin.get('plugin') == 'if':
|
|
689
|
+
# Count nested plugins in if block
|
|
690
|
+
if 'plugins' in plugin.get('config', {}):
|
|
691
|
+
count += count_all_plugins(plugin['config']['plugins'])
|
|
692
|
+
|
|
693
|
+
# Count nested plugins in else_ifs
|
|
694
|
+
if 'else_ifs' in plugin.get('config', {}):
|
|
695
|
+
for else_if in plugin['config']['else_ifs']:
|
|
696
|
+
if 'plugins' in else_if:
|
|
697
|
+
count += count_all_plugins(else_if['plugins'])
|
|
698
|
+
|
|
699
|
+
# Count nested plugins in else
|
|
700
|
+
if 'else' in plugin.get('config', {}) and plugin['config']['else']:
|
|
701
|
+
if 'plugins' in plugin['config']['else']:
|
|
702
|
+
count += count_all_plugins(plugin['config']['else']['plugins'])
|
|
703
|
+
else:
|
|
704
|
+
# Regular plugin - count it
|
|
705
|
+
count += 1
|
|
706
|
+
return count
|
|
707
|
+
|
|
708
|
+
total_plugin_count = count_all_plugins(filter_plugins)
|
|
709
|
+
# Add HTTP output that only sends cloned events (identified by type field).
|
|
710
|
+
# Must target LogstashUI StreamSimulate (not the agent API). On host
|
|
711
|
+
# simulate agents the agent still rebuilds slot conf with pipeline→simulate-end
|
|
712
|
+
# output, but drop-plugin instrumentation posts here directly.
|
|
713
|
+
output_plugins = [
|
|
714
|
+
{
|
|
715
|
+
"id": "http_output",
|
|
716
|
+
"type": "output",
|
|
717
|
+
"plugin": "http",
|
|
718
|
+
"config": {
|
|
719
|
+
"url": f"{logstash_ui_url}/ConnectionManager/StreamSimulate/",
|
|
720
|
+
"http_method": "post",
|
|
721
|
+
"format": "json",
|
|
722
|
+
"content_type": "application/json",
|
|
723
|
+
"ssl_verification_mode": "none",
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
]
|
|
727
|
+
|
|
728
|
+
# Convert filter components to Logstash config
|
|
729
|
+
filter_converter = logstash_config_parse.ComponentToPipeline({'filter': instrumented_filters}, test=False)
|
|
730
|
+
filter_config = filter_converter.components_to_logstash_config()
|
|
731
|
+
|
|
732
|
+
# Convert output components to Logstash config
|
|
733
|
+
output_converter = logstash_config_parse.ComponentToPipeline({'output': output_plugins}, test=False)
|
|
734
|
+
output_config = output_converter.components_to_logstash_config()
|
|
735
|
+
|
|
736
|
+
# Extract just the content (remove 'filter {' and 'output {' wrappers)
|
|
737
|
+
# The logstashagent will add these wrappers when building the complete pipeline
|
|
738
|
+
filter_lines = filter_config.strip().split('\n')
|
|
739
|
+
filter_content = '\n'.join(filter_lines[1:-1]) if len(filter_lines) > 2 else ''
|
|
740
|
+
|
|
741
|
+
output_lines = output_config.strip().split('\n')
|
|
742
|
+
output_content = '\n'.join(output_lines[1:-1]) if len(output_lines) > 2 else ''
|
|
743
|
+
|
|
744
|
+
# Prepare the pipeline data for slot allocation
|
|
745
|
+
# The slots system will hash this to detect configuration changes
|
|
746
|
+
pipeline_data = {
|
|
747
|
+
"filter_config": filter_content,
|
|
748
|
+
"output_config": output_content,
|
|
749
|
+
"index": 1
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
# Session slot: multi-document runs allocate once on the client, then pass
|
|
753
|
+
# slot_id for every document so we never re-allocate mid-session.
|
|
754
|
+
#
|
|
755
|
+
# CRITICAL: slots are per-agent / per-node. embedded "slot 1" is NOT
|
|
756
|
+
# simulate-1 "slot 1". Never skip allocate unless *this* agent both has
|
|
757
|
+
# the slot in its table AND has the named pipeline loaded (bus address).
|
|
758
|
+
# Otherwise simulate-start send_to storms ("address was unavailable").
|
|
759
|
+
session_slot_raw = str(session_slot_raw or "").strip()
|
|
760
|
+
slot_id = None
|
|
761
|
+
reused = False
|
|
762
|
+
use_session_slot = False
|
|
763
|
+
agent_label = (
|
|
764
|
+
(sim_target or {}).get("label")
|
|
765
|
+
or (sim_target or {}).get("connection_id")
|
|
766
|
+
or logstash_agent_url
|
|
767
|
+
)
|
|
768
|
+
|
|
769
|
+
if session_slot_raw and log_text:
|
|
770
|
+
try:
|
|
771
|
+
candidate = int(session_slot_raw)
|
|
772
|
+
if candidate < 1:
|
|
773
|
+
raise ValueError("slot_id must be >= 1")
|
|
774
|
+
pipeline_name = f"slot{candidate}-filter1"
|
|
775
|
+
slots_data = {}
|
|
776
|
+
has_slot = False
|
|
777
|
+
pipeline_loaded = False
|
|
778
|
+
try:
|
|
779
|
+
slots_resp = requests.get(
|
|
780
|
+
f"{logstash_agent_url}/_logstash/slots",
|
|
781
|
+
headers=agent_headers,
|
|
782
|
+
verify=agent_requests_verify(),
|
|
783
|
+
timeout=5,
|
|
784
|
+
)
|
|
785
|
+
slots_resp.raise_for_status()
|
|
786
|
+
slots_data = slots_resp.json() or {}
|
|
787
|
+
has_slot = (
|
|
788
|
+
str(candidate) in slots_data
|
|
789
|
+
or candidate in slots_data
|
|
790
|
+
)
|
|
791
|
+
except Exception as probe_err:
|
|
792
|
+
logger.warning(
|
|
793
|
+
"Could not verify session slot %s on agent %s: %s — will re-allocate",
|
|
794
|
+
candidate,
|
|
795
|
+
agent_label,
|
|
796
|
+
probe_err,
|
|
797
|
+
)
|
|
798
|
+
has_slot = False
|
|
799
|
+
|
|
800
|
+
# Slot table membership alone is not enough (table can lag deleted
|
|
801
|
+
# pipelines, or a foreign node’s slot id can collide numerically).
|
|
802
|
+
if has_slot:
|
|
803
|
+
try:
|
|
804
|
+
status_resp = requests.get(
|
|
805
|
+
f"{logstash_agent_url}/_logstash/pipelines/status",
|
|
806
|
+
headers=agent_headers,
|
|
807
|
+
verify=agent_requests_verify(),
|
|
808
|
+
timeout=5,
|
|
809
|
+
)
|
|
810
|
+
if status_resp.ok:
|
|
811
|
+
status_body = status_resp.json() or {}
|
|
812
|
+
# Agent returns various shapes; accept common ones.
|
|
813
|
+
running = (
|
|
814
|
+
status_body.get("pipelines")
|
|
815
|
+
or status_body.get("running_pipelines")
|
|
816
|
+
or status_body.get("pipeline_ids")
|
|
817
|
+
or []
|
|
818
|
+
)
|
|
819
|
+
if isinstance(running, dict):
|
|
820
|
+
pipeline_loaded = pipeline_name in running
|
|
821
|
+
elif isinstance(running, list):
|
|
822
|
+
pipeline_loaded = pipeline_name in running
|
|
823
|
+
else:
|
|
824
|
+
pipeline_loaded = False
|
|
825
|
+
else:
|
|
826
|
+
# Fallback: treat missing status as not loaded
|
|
827
|
+
pipeline_loaded = False
|
|
828
|
+
logger.warning(
|
|
829
|
+
"pipelines/status HTTP %s on agent %s for session slot check",
|
|
830
|
+
status_resp.status_code,
|
|
831
|
+
agent_label,
|
|
832
|
+
)
|
|
833
|
+
except Exception as pipe_err:
|
|
834
|
+
logger.warning(
|
|
835
|
+
"Could not verify pipeline %s on agent %s: %s — will re-allocate",
|
|
836
|
+
pipeline_name,
|
|
837
|
+
agent_label,
|
|
838
|
+
pipe_err,
|
|
839
|
+
)
|
|
840
|
+
pipeline_loaded = False
|
|
841
|
+
|
|
842
|
+
if has_slot and pipeline_loaded:
|
|
843
|
+
slot_id = candidate
|
|
844
|
+
reused = True
|
|
845
|
+
use_session_slot = True
|
|
846
|
+
logger.info(
|
|
847
|
+
"[BE->AGENT] Using session slot %s on agent %s "
|
|
848
|
+
"(pipeline %s loaded; skip allocate; document input only)",
|
|
849
|
+
slot_id,
|
|
850
|
+
agent_label,
|
|
851
|
+
pipeline_name,
|
|
852
|
+
)
|
|
853
|
+
else:
|
|
854
|
+
logger.warning(
|
|
855
|
+
"[BE->AGENT] Session slot %s not usable on agent %s "
|
|
856
|
+
"(in_table=%s pipeline_loaded=%s available_slots=%s); "
|
|
857
|
+
"re-allocating on this target (cross-node slot ids must not be reused)",
|
|
858
|
+
candidate,
|
|
859
|
+
agent_label,
|
|
860
|
+
has_slot,
|
|
861
|
+
pipeline_loaded,
|
|
862
|
+
list(slots_data.keys()) if isinstance(slots_data, dict) else slots_data,
|
|
863
|
+
)
|
|
864
|
+
except (TypeError, ValueError) as e:
|
|
865
|
+
return SimulationStart(
|
|
866
|
+
error=f'Error: invalid session slot_id {session_slot_raw!r}: {e}',
|
|
867
|
+
pipeline_failed=True,
|
|
868
|
+
)
|
|
869
|
+
|
|
870
|
+
if not use_session_slot:
|
|
871
|
+
# Allocate a slot - the logstashagent will detect if config changed
|
|
872
|
+
slot_allocation_body = {
|
|
873
|
+
"pipeline_name": pipeline_name,
|
|
874
|
+
"pipelines": [pipeline_data]
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
logger.info(f"[BE->AGENT] Sending slot allocation with {len(filter_plugins)} filter plugins")
|
|
878
|
+
logger.debug(f"[BE->AGENT] filter_config being sent:\n{filter_content}")
|
|
879
|
+
|
|
880
|
+
try:
|
|
881
|
+
# Cold allocate can take well over 30s: optional eviction wait (up to 30s),
|
|
882
|
+
# pipeline create, verify (up to ~20s), and bus settle. Keep UI→agent timeout
|
|
883
|
+
# high so page-load prealloc can finish and Run stays instant on a warm slot.
|
|
884
|
+
response = requests.post(
|
|
885
|
+
f"{logstash_agent_url}/_logstash/slots/allocate",
|
|
886
|
+
json=slot_allocation_body,
|
|
887
|
+
headers=agent_headers,
|
|
888
|
+
verify=agent_requests_verify(),
|
|
889
|
+
timeout=120,
|
|
890
|
+
)
|
|
891
|
+
|
|
892
|
+
# Try to extract slot_id from response before checking status
|
|
893
|
+
# This way we have it even if verification fails
|
|
894
|
+
response_data = {}
|
|
895
|
+
try:
|
|
896
|
+
response_data = response.json() or {}
|
|
897
|
+
slot_id = response_data.get('slot_id')
|
|
898
|
+
reused = response_data.get('reused', False)
|
|
899
|
+
except Exception:
|
|
900
|
+
pass
|
|
901
|
+
|
|
902
|
+
# Now check if the request was successful
|
|
903
|
+
response.raise_for_status()
|
|
904
|
+
|
|
905
|
+
agent_timings = response_data.get("timings_ms")
|
|
906
|
+
if agent_timings:
|
|
907
|
+
logger.info(
|
|
908
|
+
"Allocated slot %s (reused: %s) agent timings_ms=%s",
|
|
909
|
+
slot_id,
|
|
910
|
+
reused,
|
|
911
|
+
agent_timings,
|
|
912
|
+
)
|
|
913
|
+
else:
|
|
914
|
+
logger.info(f"Allocated slot {slot_id} (reused: {reused})")
|
|
915
|
+
|
|
916
|
+
except requests.exceptions.RequestException as e:
|
|
917
|
+
logger.error(f"Failed to allocate slot: {e}")
|
|
918
|
+
logger.error(f"slot_id extracted before error: {slot_id}")
|
|
919
|
+
agent_detail = None
|
|
920
|
+
|
|
921
|
+
# If slot_id wasn't extracted from successful response, try to get it from error response
|
|
922
|
+
if not slot_id and hasattr(e, 'response') and e.response is not None:
|
|
923
|
+
try:
|
|
924
|
+
logger.error(
|
|
925
|
+
"Agent allocate error status=%s body=%s",
|
|
926
|
+
e.response.status_code,
|
|
927
|
+
(e.response.text or "")[:800],
|
|
928
|
+
)
|
|
929
|
+
|
|
930
|
+
error_data = e.response.json()
|
|
931
|
+
logger.error(f"Agent allocate error JSON: {error_data}")
|
|
932
|
+
|
|
933
|
+
# Check if detail is a dict with slot_id (new format)
|
|
934
|
+
detail = error_data.get('detail')
|
|
935
|
+
agent_detail = detail
|
|
936
|
+
|
|
937
|
+
if isinstance(detail, dict):
|
|
938
|
+
slot_id = detail.get('slot_id')
|
|
939
|
+
agent_detail = detail.get('message') or detail
|
|
940
|
+
logger.debug(f"Extracted slot_id {slot_id} from error response detail dict")
|
|
941
|
+
elif isinstance(detail, str) and 'Slot' in detail:
|
|
942
|
+
# Fallback: try to extract from string
|
|
943
|
+
match = re.search(r'Slot (\d+)', detail)
|
|
944
|
+
if match:
|
|
945
|
+
slot_id = int(match.group(1))
|
|
946
|
+
logger.debug(f"Extracted slot_id {slot_id} from error detail string")
|
|
947
|
+
except Exception as extract_error:
|
|
948
|
+
logger.error(f"Could not extract slot_id from error detail: {extract_error}")
|
|
949
|
+
logger.error(traceback.format_exc())
|
|
950
|
+
|
|
951
|
+
if not slot_id:
|
|
952
|
+
logger.warning("No slot_id available for error response - logs will not be accessible")
|
|
953
|
+
|
|
954
|
+
# Prefer agent detail message for the chip/tooltip when present
|
|
955
|
+
if isinstance(agent_detail, dict):
|
|
956
|
+
human = agent_detail.get("message") or str(agent_detail)
|
|
957
|
+
elif agent_detail:
|
|
958
|
+
human = str(agent_detail)
|
|
959
|
+
else:
|
|
960
|
+
human = str(e)
|
|
961
|
+
# slot_id lets the editor open the agent logs; pipeline_failed
|
|
962
|
+
# stops it re-checking pipeline status.
|
|
963
|
+
return SimulationStart(
|
|
964
|
+
error=f'Error allocating slot: {human[:300]}',
|
|
965
|
+
slot_id=slot_id,
|
|
966
|
+
agent_url=logstash_agent_url,
|
|
967
|
+
pipeline_failed=True,
|
|
968
|
+
)
|
|
969
|
+
|
|
970
|
+
# Use the slot-based pipeline name
|
|
971
|
+
pipeline_name = f"slot{slot_id}-filter1"
|
|
972
|
+
|
|
973
|
+
# Note: No need to verify pipeline here - the slot allocation endpoint already
|
|
974
|
+
# performs comprehensive verification with polling and retries. If we got here,
|
|
975
|
+
# the pipelines are guaranteed to be loaded and ready.
|
|
976
|
+
|
|
977
|
+
started = SimulationStart(
|
|
978
|
+
run_id=run_id, slot_id=slot_id, reused=reused,
|
|
979
|
+
filter_count=total_plugin_count, agent_url=logstash_agent_url,
|
|
980
|
+
agent_headers=agent_headers,
|
|
981
|
+
)
|
|
982
|
+
if log_text:
|
|
983
|
+
started.queued, started.forward_error = send_simulation_event(
|
|
984
|
+
logstash_agent_url, slot_id, run_id, log_text,
|
|
985
|
+
agent_headers=agent_headers,
|
|
986
|
+
)
|
|
987
|
+
if not started.forward_error:
|
|
988
|
+
logger.info(f"Sent simulation input to pipeline '{pipeline_name}'")
|
|
989
|
+
return started
|
|
990
|
+
|
|
991
|
+
except Exception as e:
|
|
992
|
+
logger.error(f"Error in SimulatePipeline: {e}")
|
|
993
|
+
logger.error(traceback.format_exc())
|
|
994
|
+
return SimulationStart(error=f'Error: {e}')
|
|
995
|
+
|
|
996
|
+
def send_simulation_event(agent_url, slot_id, run_id, log_text, agent_headers=None):
|
|
997
|
+
"""Send one event into an allocated simulation slot.
|
|
998
|
+
|
|
999
|
+
Args:
|
|
1000
|
+
agent_url: Simulate agent base URL.
|
|
1001
|
+
slot_id: Slot whose instrumented pipeline should process the event.
|
|
1002
|
+
run_id: Identifier the results will carry.
|
|
1003
|
+
log_text: Log line, or JSON text for a structured event.
|
|
1004
|
+
agent_headers: Auth headers for the agent, from ``_sim_agent_headers``.
|
|
1005
|
+
|
|
1006
|
+
Returns:
|
|
1007
|
+
tuple: ``(queued, forward_error)``. ``queued`` is True when the agent
|
|
1008
|
+
accepted the event while Logstash restarts. ``forward_error`` is the
|
|
1009
|
+
error text if sending failed; the agent may still deliver results.
|
|
1010
|
+
"""
|
|
1011
|
+
try:
|
|
1012
|
+
log_data = json.loads(log_text)
|
|
1013
|
+
except json.JSONDecodeError:
|
|
1014
|
+
log_data = {"message": log_text}
|
|
1015
|
+
if not isinstance(log_data, dict):
|
|
1016
|
+
log_data = {"message": log_text}
|
|
1017
|
+
# slot routes the event in simulate_start.conf; run_id tags its results.
|
|
1018
|
+
log_data["slot"] = slot_id
|
|
1019
|
+
log_data["run_id"] = run_id
|
|
1020
|
+
|
|
1021
|
+
try:
|
|
1022
|
+
# Agent may wait up to ~20s for pipeline-bus readiness then retry
|
|
1023
|
+
# forward to Logstash (1s+2s+3s). Don't time out before that.
|
|
1024
|
+
response = requests.post(
|
|
1025
|
+
f"{agent_url}/_logstash/simulate",
|
|
1026
|
+
json=log_data,
|
|
1027
|
+
headers=agent_headers,
|
|
1028
|
+
verify=agent_requests_verify(),
|
|
1029
|
+
timeout=45,
|
|
1030
|
+
)
|
|
1031
|
+
if response.status_code == 202:
|
|
1032
|
+
logger.warning("Simulation request queued - Logstash is restarting (run_id=%s)", run_id)
|
|
1033
|
+
return True, None
|
|
1034
|
+
response.raise_for_status()
|
|
1035
|
+
return False, None
|
|
1036
|
+
except requests.exceptions.RequestException as e:
|
|
1037
|
+
logger.error("Failed to send simulation input (run_id=%s slot=%s): %s", run_id, slot_id, e)
|
|
1038
|
+
return False, str(e)
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
@csrf_exempt
|
|
1042
|
+
def StreamSimulate(request):
|
|
1043
|
+
"""Receive one simulated event from Logstash HTTP output and enqueue it.
|
|
1044
|
+
|
|
1045
|
+
Called by the instrumented pipeline's output for each event. The endpoint
|
|
1046
|
+
is unauthenticated, so only events whose ``run_id`` passes
|
|
1047
|
+
:func:`is_known_run_id` are stored, up to ``SimulationResult.MAX_PER_RUN``
|
|
1048
|
+
per run.
|
|
1049
|
+
|
|
1050
|
+
Examples:
|
|
1051
|
+
# POST JSON (from the agent / Ruby http output)
|
|
1052
|
+
event = {"run_id": "<new_run_id()>", "snapshots": {"plugin-id": {...}}, ...}
|
|
1053
|
+
# {"status": "ok"}
|
|
1054
|
+
"""
|
|
1055
|
+
if request.method != 'POST':
|
|
1056
|
+
return JsonResponse({"error": "Method not allowed"}, status=405)
|
|
1057
|
+
|
|
1058
|
+
try:
|
|
1059
|
+
# Parse the incoming event data
|
|
1060
|
+
event_data = json.loads(request.body)
|
|
1061
|
+
|
|
1062
|
+
if not isinstance(event_data, dict):
|
|
1063
|
+
return JsonResponse({"error": "Event must be a JSON object"}, status=400)
|
|
1064
|
+
if not is_known_run_id(event_data.get('run_id')):
|
|
1065
|
+
logger.warning("StreamSimulate: rejected event for unknown or expired run_id %r",
|
|
1066
|
+
str(event_data.get('run_id'))[:64])
|
|
1067
|
+
return JsonResponse({"error": "Unknown or expired run_id"}, status=403)
|
|
1068
|
+
if not SimulationResult.add(event_data):
|
|
1069
|
+
return JsonResponse({"error": "Too many results for this run"}, status=429)
|
|
1070
|
+
|
|
1071
|
+
# Log detailed information about the received event
|
|
1072
|
+
event_run_id = event_data.get('run_id', 'MISSING')
|
|
1073
|
+
snapshots = event_data.get('snapshots', {})
|
|
1074
|
+
# Logstash may nest as {"plugin-id": {...}} or leave empty on start/end only
|
|
1075
|
+
if not snapshots and isinstance(event_data.get('simulation'), dict):
|
|
1076
|
+
# Debug empty snapshots: step 0 is expected from simulate-start
|
|
1077
|
+
step = event_data.get('simulation', {}).get('step')
|
|
1078
|
+
logger.info(
|
|
1079
|
+
"[AGENT->BE] Event run_id=%s has no snapshots (simulation.step=%s, id=%s); "
|
|
1080
|
+
"keys=%s",
|
|
1081
|
+
event_run_id,
|
|
1082
|
+
step,
|
|
1083
|
+
event_data.get('simulation', {}).get('id'),
|
|
1084
|
+
list(event_data.keys())[:30],
|
|
1085
|
+
)
|
|
1086
|
+
snapshot_count = len(snapshots) if isinstance(snapshots, dict) else 0
|
|
1087
|
+
logger.info(f"[AGENT->BE] Received event with run_id={event_run_id}, snapshots={snapshot_count}")
|
|
1088
|
+
if snapshots:
|
|
1089
|
+
logger.debug(f"[AGENT->BE] Snapshot keys: {list(snapshots.keys()) if isinstance(snapshots, dict) else 'NOT A DICT'}")
|
|
1090
|
+
logger.debug(f"StreamSimulate: Event data keys: {list(event_data.keys())}")
|
|
1091
|
+
if event_run_id == 'MISSING':
|
|
1092
|
+
logger.error(f"StreamSimulate: Event is missing run_id field! Event keys: {list(event_data.keys())}")
|
|
1093
|
+
|
|
1094
|
+
return JsonResponse({"status": "ok"}, status=200)
|
|
1095
|
+
|
|
1096
|
+
except Exception as e:
|
|
1097
|
+
logger.error(f"Error in StreamSimulate: {e}")
|
|
1098
|
+
logger.error(traceback.format_exc())
|
|
1099
|
+
return JsonResponse({"error": str(e)}, status=500)
|
|
1100
|
+
|
|
1101
|
+
|
|
1102
|
+
def GetSimulationResults(request):
|
|
1103
|
+
"""Return and dequeue queued simulation events for one ``run_id``.
|
|
1104
|
+
|
|
1105
|
+
Args:
|
|
1106
|
+
run_id: Simulation run identifier.
|
|
1107
|
+
|
|
1108
|
+
Returns:
|
|
1109
|
+
JSON ``{"results": [...]}``.
|
|
1110
|
+
"""
|
|
1111
|
+
if request.method != 'GET':
|
|
1112
|
+
return JsonResponse({"error": "Method not allowed"}, status=405)
|
|
1113
|
+
|
|
1114
|
+
try:
|
|
1115
|
+
# Get run_id from query parameters
|
|
1116
|
+
run_id = request.GET.get('run_id')
|
|
1117
|
+
|
|
1118
|
+
if not run_id:
|
|
1119
|
+
return JsonResponse({"error": "Missing run_id parameter"}, status=400)
|
|
1120
|
+
|
|
1121
|
+
try:
|
|
1122
|
+
matching_results = SimulationResult.take([run_id])[run_id]
|
|
1123
|
+
except OperationalError as exc:
|
|
1124
|
+
# SQLite raises "database is locked" when a result is written mid-read.
|
|
1125
|
+
# take() rolled back, so the next poll gets these rows.
|
|
1126
|
+
logger.warning("GetSimulationResults: could not read results this poll: %s", exc)
|
|
1127
|
+
matching_results = []
|
|
1128
|
+
|
|
1129
|
+
# Log snapshot counts for each event being returned
|
|
1130
|
+
snapshot_info = []
|
|
1131
|
+
for event in matching_results:
|
|
1132
|
+
snapshots = event.get('snapshots', {})
|
|
1133
|
+
snapshot_info.append(len(snapshots) if snapshots else 0)
|
|
1134
|
+
|
|
1135
|
+
logger.info(f"[BE->FE] Returning {len(matching_results)} events for run_id {run_id}, snapshots per event: {snapshot_info}")
|
|
1136
|
+
if matching_results:
|
|
1137
|
+
logger.debug(f"GetSimulationResults: First event keys: {list(matching_results[0].keys())}")
|
|
1138
|
+
|
|
1139
|
+
return JsonResponse({"results": matching_results}, status=200)
|
|
1140
|
+
|
|
1141
|
+
except Exception as e:
|
|
1142
|
+
logger.error(f"Error in GetSimulationResults: {e}")
|
|
1143
|
+
logger.error(traceback.format_exc())
|
|
1144
|
+
return JsonResponse({"error": str(e)}, status=500)
|
|
1145
|
+
|
|
1146
|
+
|
|
1147
|
+
@login_required
|
|
1148
|
+
def CheckIfPipelineLoaded(request):
|
|
1149
|
+
"""Check whether a slot pipeline is running on the simulate agent.
|
|
1150
|
+
|
|
1151
|
+
Args:
|
|
1152
|
+
pipeline_name: Pipeline id to look up.
|
|
1153
|
+
|
|
1154
|
+
Returns:
|
|
1155
|
+
JSON with ``is_running``, ``pipeline_name``, ``running_pipelines``.
|
|
1156
|
+
"""
|
|
1157
|
+
try:
|
|
1158
|
+
pipeline_name = request.GET.get('pipeline_name')
|
|
1159
|
+
|
|
1160
|
+
if not pipeline_name:
|
|
1161
|
+
return JsonResponse({
|
|
1162
|
+
"error": "pipeline_name parameter is required"
|
|
1163
|
+
}, status=400)
|
|
1164
|
+
|
|
1165
|
+
# Call logstashagent to check pipeline status
|
|
1166
|
+
base, sim_target, _ = _sim_agent_url(request)
|
|
1167
|
+
logstash_agent_url = f"{base}/_logstash/pipelines/status"
|
|
1168
|
+
|
|
1169
|
+
try:
|
|
1170
|
+
response = requests.get(
|
|
1171
|
+
logstash_agent_url, timeout=5, verify=agent_requests_verify(),
|
|
1172
|
+
headers=_sim_agent_headers(sim_target),
|
|
1173
|
+
)
|
|
1174
|
+
response.raise_for_status()
|
|
1175
|
+
|
|
1176
|
+
data = response.json()
|
|
1177
|
+
running_pipelines = data.get('running_pipelines', [])
|
|
1178
|
+
is_running = pipeline_name in running_pipelines
|
|
1179
|
+
|
|
1180
|
+
logger.info(f"CheckIfPipelineLoaded: Pipeline '{pipeline_name}' running status: {is_running}")
|
|
1181
|
+
|
|
1182
|
+
return JsonResponse({
|
|
1183
|
+
"is_running": is_running,
|
|
1184
|
+
"pipeline_name": pipeline_name,
|
|
1185
|
+
"running_pipelines": running_pipelines
|
|
1186
|
+
}, status=200)
|
|
1187
|
+
|
|
1188
|
+
except requests.exceptions.RequestException as e:
|
|
1189
|
+
logger.error(f"Failed to connect to logstashagent: {e}")
|
|
1190
|
+
return JsonResponse({
|
|
1191
|
+
"error": f"Failed to connect to logstashagent: {str(e)}",
|
|
1192
|
+
"is_running": False,
|
|
1193
|
+
"pipeline_name": pipeline_name
|
|
1194
|
+
}, status=500)
|
|
1195
|
+
|
|
1196
|
+
except Exception as e:
|
|
1197
|
+
logger.error(f"Error in CheckIfPipelineLoaded: {e}")
|
|
1198
|
+
logger.error(traceback.format_exc())
|
|
1199
|
+
return JsonResponse({
|
|
1200
|
+
"error": str(e),
|
|
1201
|
+
"is_running": False
|
|
1202
|
+
}, status=500)
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
@login_required
|
|
1206
|
+
def GetRelatedLogs(request):
|
|
1207
|
+
"""Fetch Logstash log lines for a simulation slot pipeline.
|
|
1208
|
+
|
|
1209
|
+
Args:
|
|
1210
|
+
slot_id: Slot id (required).
|
|
1211
|
+
max_entries: Cap (default 100, max 500).
|
|
1212
|
+
min_level: Minimum level (default ``INFO``).
|
|
1213
|
+
|
|
1214
|
+
Returns:
|
|
1215
|
+
Agent JSON with ``pipeline_id``, ``log_count``, ``logs``.
|
|
1216
|
+
"""
|
|
1217
|
+
try:
|
|
1218
|
+
slot_id = request.GET.get('slot_id')
|
|
1219
|
+
max_entries = int(request.GET.get('max_entries', 100))
|
|
1220
|
+
min_level = request.GET.get('min_level', 'INFO').upper()
|
|
1221
|
+
|
|
1222
|
+
if not slot_id:
|
|
1223
|
+
return JsonResponse({
|
|
1224
|
+
"error": "slot_id parameter is required"
|
|
1225
|
+
}, status=400)
|
|
1226
|
+
|
|
1227
|
+
# Construct the slot pipeline name
|
|
1228
|
+
pipeline_id = f"slot{slot_id}-filter1"
|
|
1229
|
+
|
|
1230
|
+
# Get slot creation timestamp from logstashagent
|
|
1231
|
+
min_timestamp = None
|
|
1232
|
+
try:
|
|
1233
|
+
base, sim_target, _ = _sim_agent_url(request)
|
|
1234
|
+
slots_response = requests.get(
|
|
1235
|
+
f"{base}/_logstash/slots", timeout=5, verify=agent_requests_verify(),
|
|
1236
|
+
headers=_sim_agent_headers(sim_target),
|
|
1237
|
+
)
|
|
1238
|
+
slots_response.raise_for_status()
|
|
1239
|
+
slots_data = slots_response.json()
|
|
1240
|
+
|
|
1241
|
+
logger.debug(
|
|
1242
|
+
f"Slots data type: {type(slots_data)}, Keys: {list(slots_data.keys()) if isinstance(slots_data, dict) else 'N/A'}")
|
|
1243
|
+
logger.debug(f"Looking for slot_id: {slot_id} (type: {type(slot_id)})")
|
|
1244
|
+
|
|
1245
|
+
# Find the slot and get its creation timestamp
|
|
1246
|
+
# JSON converts int keys to strings, so try both
|
|
1247
|
+
slot_info = slots_data.get(str(slot_id)) or slots_data.get(int(slot_id))
|
|
1248
|
+
logger.debug(f"Slot info found: {slot_info is not None}")
|
|
1249
|
+
if slot_info:
|
|
1250
|
+
# Use slot creation time as minimum timestamp to avoid showing logs
|
|
1251
|
+
# from previous pipelines that used this slot
|
|
1252
|
+
min_timestamp = slot_info.get('created_at_millis')
|
|
1253
|
+
current_time_millis = int(time.time() * 1000)
|
|
1254
|
+
time_diff_seconds = (current_time_millis - min_timestamp) / 1000 if min_timestamp else 0
|
|
1255
|
+
logger.debug(
|
|
1256
|
+
f"Slot {slot_id} - Current time: {current_time_millis}, Min timestamp: {min_timestamp}, Diff: {time_diff_seconds:.1f}s ago")
|
|
1257
|
+
else:
|
|
1258
|
+
# Slot not found - use recent time window as fallback (last 30 seconds)
|
|
1259
|
+
current_time_millis = int(time.time() * 1000)
|
|
1260
|
+
min_timestamp = current_time_millis - 30000 # 30 seconds ago
|
|
1261
|
+
logger.warning(f"Slot {slot_id} not found in slots data. Available slots: {list(slots_data.keys())}")
|
|
1262
|
+
logger.warning(f"Using fallback: filtering logs from last 30 seconds (min_timestamp: {min_timestamp})")
|
|
1263
|
+
except Exception as e:
|
|
1264
|
+
# If anything fails, use fallback time window
|
|
1265
|
+
current_time_millis = int(time.time() * 1000)
|
|
1266
|
+
min_timestamp = current_time_millis - 30000 # 30 seconds ago
|
|
1267
|
+
logger.warning(f"Could not retrieve slot creation timestamp: {e}")
|
|
1268
|
+
logger.warning(f"Using fallback: filtering logs from last 30 seconds (min_timestamp: {min_timestamp})")
|
|
1269
|
+
|
|
1270
|
+
# Call logstashagent to get pipeline logs
|
|
1271
|
+
base, sim_target, _ = _sim_agent_url(request)
|
|
1272
|
+
logstash_agent_url = f"{base}/_logstash/pipeline/{pipeline_id}/logs"
|
|
1273
|
+
params = {
|
|
1274
|
+
"max_entries": min(max_entries, 500),
|
|
1275
|
+
"min_level": min_level
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
# Add min_timestamp if available
|
|
1279
|
+
if min_timestamp:
|
|
1280
|
+
params["min_timestamp"] = min_timestamp
|
|
1281
|
+
logger.debug(f"Fetching logs with min_timestamp filter: {min_timestamp}")
|
|
1282
|
+
else:
|
|
1283
|
+
logger.warning(f"No min_timestamp available - will fetch ALL logs for {pipeline_id}")
|
|
1284
|
+
|
|
1285
|
+
try:
|
|
1286
|
+
logger.debug(f"Requesting logs from {logstash_agent_url} with params: {params}")
|
|
1287
|
+
response = requests.get(
|
|
1288
|
+
logstash_agent_url, params=params, timeout=10, verify=agent_requests_verify(),
|
|
1289
|
+
headers=_sim_agent_headers(sim_target),
|
|
1290
|
+
)
|
|
1291
|
+
response.raise_for_status()
|
|
1292
|
+
|
|
1293
|
+
data = response.json()
|
|
1294
|
+
|
|
1295
|
+
log_count = data.get('log_count', 0)
|
|
1296
|
+
logger.info(f"GetRelatedLogs: Retrieved {log_count} logs for slot {slot_id}")
|
|
1297
|
+
|
|
1298
|
+
# Log timestamp range of returned logs for debugging
|
|
1299
|
+
if log_count > 0 and 'logs' in data:
|
|
1300
|
+
logs = data['logs']
|
|
1301
|
+
timestamps = [log.get('timeMillis', 0) for log in logs if 'timeMillis' in log]
|
|
1302
|
+
if timestamps:
|
|
1303
|
+
oldest = min(timestamps)
|
|
1304
|
+
newest = max(timestamps)
|
|
1305
|
+
logger.info(
|
|
1306
|
+
f"Log timestamp range - Oldest: {oldest}, Newest: {newest}, Min filter was: {min_timestamp}")
|
|
1307
|
+
if min_timestamp and oldest < min_timestamp:
|
|
1308
|
+
logger.error(
|
|
1309
|
+
f"FILTERING FAILED: Found log older ({oldest}) than min_timestamp ({min_timestamp})")
|
|
1310
|
+
|
|
1311
|
+
return JsonResponse(data, status=200)
|
|
1312
|
+
|
|
1313
|
+
except requests.exceptions.RequestException as e:
|
|
1314
|
+
logger.error(f"Failed to fetch logs from logstashagent: {e}")
|
|
1315
|
+
return JsonResponse({
|
|
1316
|
+
"error": f"Failed to fetch logs from logstashagent: {str(e)}",
|
|
1317
|
+
"pipeline_id": pipeline_id,
|
|
1318
|
+
"log_count": 0,
|
|
1319
|
+
"logs": []
|
|
1320
|
+
}, status=500)
|
|
1321
|
+
|
|
1322
|
+
except Exception as e:
|
|
1323
|
+
logger.error(f"Error in GetRelatedLogs: {e}")
|
|
1324
|
+
logger.error(traceback.format_exc())
|
|
1325
|
+
return JsonResponse({
|
|
1326
|
+
"error": str(e),
|
|
1327
|
+
"log_count": 0,
|
|
1328
|
+
"logs": []
|
|
1329
|
+
}, status=500)
|
|
1330
|
+
|
|
1331
|
+
|
|
1332
|
+
@require_admin_role
|
|
1333
|
+
def UploadFile(request):
|
|
1334
|
+
"""Upload a file to the simulate agent for use in a pipeline.
|
|
1335
|
+
|
|
1336
|
+
Args:
|
|
1337
|
+
file: Uploaded file.
|
|
1338
|
+
filename: Destination name on the agent.
|
|
1339
|
+
"""
|
|
1340
|
+
if request.method != 'POST':
|
|
1341
|
+
return JsonResponse({"error": "Method not allowed"}, status=405)
|
|
1342
|
+
|
|
1343
|
+
try:
|
|
1344
|
+
# Get the uploaded file and filename
|
|
1345
|
+
uploaded_file = request.FILES.get('file')
|
|
1346
|
+
filename = request.POST.get('filename')
|
|
1347
|
+
|
|
1348
|
+
if not uploaded_file:
|
|
1349
|
+
return JsonResponse({"error": "No file provided"}, status=400)
|
|
1350
|
+
|
|
1351
|
+
if not filename:
|
|
1352
|
+
return JsonResponse({"error": "No filename provided"}, status=400)
|
|
1353
|
+
|
|
1354
|
+
# Read file content
|
|
1355
|
+
file_content = uploaded_file.read()
|
|
1356
|
+
logger.info(f"Read {len(file_content)} bytes from uploaded file")
|
|
1357
|
+
|
|
1358
|
+
# Encode as base64 for transmission
|
|
1359
|
+
encoded_content = base64.b64encode(file_content).decode('utf-8')
|
|
1360
|
+
logger.info(f"Encoded content length: {len(encoded_content)} characters")
|
|
1361
|
+
|
|
1362
|
+
# Send to logstashagent
|
|
1363
|
+
base, sim_target, _ = _sim_agent_url(request)
|
|
1364
|
+
logstash_agent_url = f"{base}/_logstash/write-file"
|
|
1365
|
+
|
|
1366
|
+
response = requests.post(
|
|
1367
|
+
logstash_agent_url,
|
|
1368
|
+
json={
|
|
1369
|
+
"filename": filename,
|
|
1370
|
+
"content": encoded_content
|
|
1371
|
+
},
|
|
1372
|
+
headers=_sim_agent_headers(sim_target),
|
|
1373
|
+
verify=agent_requests_verify(),
|
|
1374
|
+
timeout=10
|
|
1375
|
+
)
|
|
1376
|
+
|
|
1377
|
+
response.raise_for_status()
|
|
1378
|
+
|
|
1379
|
+
logger.info(f"File uploaded successfully: {filename}")
|
|
1380
|
+
|
|
1381
|
+
return JsonResponse({
|
|
1382
|
+
"status": "ok",
|
|
1383
|
+
"message": "File uploaded successfully",
|
|
1384
|
+
"filename": filename
|
|
1385
|
+
}, status=200)
|
|
1386
|
+
|
|
1387
|
+
except requests.exceptions.RequestException as e:
|
|
1388
|
+
logger.error(f"Error transmitting file to logstashagent: {e}")
|
|
1389
|
+
return JsonResponse({
|
|
1390
|
+
"error": f"Failed to upload file to logstashagent: {str(e)}"
|
|
1391
|
+
}, status=500)
|
|
1392
|
+
except Exception as e:
|
|
1393
|
+
logger.error(f"Error in UploadFile: {e}")
|
|
1394
|
+
logger.error(traceback.format_exc())
|
|
1395
|
+
return JsonResponse({"error": str(e)}, status=500)
|
|
1396
|
+
|
|
1397
|
+
|
|
1398
|
+
@login_required
|
|
1399
|
+
def GetSimulationNodeStatus(request):
|
|
1400
|
+
"""Check whether the simulate LogstashAgent process is reachable.
|
|
1401
|
+
|
|
1402
|
+
Returns:
|
|
1403
|
+
JSON ``{status, message, agent_info?}`` where ``status`` is
|
|
1404
|
+
``running`` or ``not_responding``.
|
|
1405
|
+
"""
|
|
1406
|
+
try:
|
|
1407
|
+
logstash_agent_url, _, _ = _sim_agent_url(request)
|
|
1408
|
+
if not logstash_agent_url:
|
|
1409
|
+
logstash_agent_url = settings.LOGSTASH_AGENT_URL
|
|
1410
|
+
|
|
1411
|
+
try:
|
|
1412
|
+
response = requests.get(logstash_agent_url, timeout=3, verify=agent_requests_verify())
|
|
1413
|
+
response.raise_for_status()
|
|
1414
|
+
|
|
1415
|
+
agent_data = response.json()
|
|
1416
|
+
|
|
1417
|
+
return JsonResponse({
|
|
1418
|
+
"status": "running",
|
|
1419
|
+
"message": "Agent running",
|
|
1420
|
+
"agent_info": agent_data
|
|
1421
|
+
}, status=200)
|
|
1422
|
+
|
|
1423
|
+
except requests.exceptions.RequestException as e:
|
|
1424
|
+
logger.warning(f"logstashagent not responding: {e}")
|
|
1425
|
+
return JsonResponse({
|
|
1426
|
+
"status": "not_responding",
|
|
1427
|
+
"message": "Agent offline",
|
|
1428
|
+
"error": str(e)
|
|
1429
|
+
}, status=200)
|
|
1430
|
+
|
|
1431
|
+
except Exception as e:
|
|
1432
|
+
logger.error(f"Error in GetSimulationNodeStatus: {e}")
|
|
1433
|
+
logger.error(traceback.format_exc())
|
|
1434
|
+
return JsonResponse({
|
|
1435
|
+
"status": "error",
|
|
1436
|
+
"message": "Agent offline",
|
|
1437
|
+
"error": str(e)
|
|
1438
|
+
}, status=200)
|
|
1439
|
+
|
|
1440
|
+
|
|
1441
|
+
@login_required
|
|
1442
|
+
def GetSimulationNodeHealth(request):
|
|
1443
|
+
"""Check Logstash health inside the selected simulation node.
|
|
1444
|
+
|
|
1445
|
+
Returns:
|
|
1446
|
+
JSON with ``healthy``, ``restarting``, ``restart_count``,
|
|
1447
|
+
``queued_requests``, plus TLS pin flags.
|
|
1448
|
+
"""
|
|
1449
|
+
try:
|
|
1450
|
+
base, sim_target, err = _sim_agent_url(request)
|
|
1451
|
+
if not base:
|
|
1452
|
+
base = settings.LOGSTASH_AGENT_URL
|
|
1453
|
+
if not base:
|
|
1454
|
+
return JsonResponse({
|
|
1455
|
+
"healthy": False,
|
|
1456
|
+
"restarting": False,
|
|
1457
|
+
"restart_count": 0,
|
|
1458
|
+
"queued_requests": 0,
|
|
1459
|
+
"error": err or "No simulation agent available",
|
|
1460
|
+
}, status=200)
|
|
1461
|
+
logstash_agent_url = f"{base}/_logstash/health"
|
|
1462
|
+
|
|
1463
|
+
try:
|
|
1464
|
+
response = requests.get(
|
|
1465
|
+
logstash_agent_url, timeout=3, verify=agent_requests_verify(),
|
|
1466
|
+
headers=_sim_agent_headers(sim_target),
|
|
1467
|
+
)
|
|
1468
|
+
response.raise_for_status()
|
|
1469
|
+
|
|
1470
|
+
health_data = response.json()
|
|
1471
|
+
tls = health_data.get("tls") or {}
|
|
1472
|
+
|
|
1473
|
+
return JsonResponse({
|
|
1474
|
+
"healthy": health_data.get("healthy", False),
|
|
1475
|
+
"restarting": health_data.get("restarting", False),
|
|
1476
|
+
"restart_count": health_data.get("restart_count", 0),
|
|
1477
|
+
"queued_requests": health_data.get("queued_requests", 0),
|
|
1478
|
+
# Agent→UI product CA pin (secure) and bootstrap status
|
|
1479
|
+
"tls": tls,
|
|
1480
|
+
"secure": bool(tls.get("secure") or tls.get("ca_pinned")),
|
|
1481
|
+
"online": bool(health_data.get("healthy", False)),
|
|
1482
|
+
}, status=200)
|
|
1483
|
+
|
|
1484
|
+
except requests.exceptions.RequestException as e:
|
|
1485
|
+
logger.warning(f"Failed to get Logstash health from agent: {e}")
|
|
1486
|
+
return JsonResponse({
|
|
1487
|
+
"healthy": False,
|
|
1488
|
+
"restarting": False,
|
|
1489
|
+
"restart_count": 0,
|
|
1490
|
+
"queued_requests": 0,
|
|
1491
|
+
"online": False,
|
|
1492
|
+
"secure": False,
|
|
1493
|
+
"error": str(e)
|
|
1494
|
+
}, status=200)
|
|
1495
|
+
|
|
1496
|
+
except Exception as e:
|
|
1497
|
+
logger.error(f"Error in GetSimulationNodeHealth: {e}")
|
|
1498
|
+
logger.error(traceback.format_exc())
|
|
1499
|
+
return JsonResponse({
|
|
1500
|
+
"healthy": False,
|
|
1501
|
+
"restarting": False,
|
|
1502
|
+
"restart_count": 0,
|
|
1503
|
+
"queued_requests": 0,
|
|
1504
|
+
"error": str(e)
|
|
1505
|
+
}, status=200)
|
|
1506
|
+
|
|
1507
|
+
|
|
1508
|
+
@require_admin_role
|
|
1509
|
+
def ValidateLogstashConfig(request):
|
|
1510
|
+
"""Validate LSCL via the agent's ``logstash --config.test_and_exit``.
|
|
1511
|
+
|
|
1512
|
+
Args:
|
|
1513
|
+
components: Visual-editor components JSON.
|
|
1514
|
+
pipeline_name: Name used for the temp file.
|
|
1515
|
+
|
|
1516
|
+
Returns:
|
|
1517
|
+
Agent JSON with ``status`` (``OK``/``ERROR``), ``notifications``,
|
|
1518
|
+
optional ``error``.
|
|
1519
|
+
"""
|
|
1520
|
+
if request.method != 'POST':
|
|
1521
|
+
return JsonResponse({"error": "Method not allowed"}, status=405)
|
|
1522
|
+
|
|
1523
|
+
try:
|
|
1524
|
+
components_json = request.POST.get('components')
|
|
1525
|
+
pipeline_name = request.POST.get('pipeline_name', 'pipeline')
|
|
1526
|
+
|
|
1527
|
+
if not components_json:
|
|
1528
|
+
return JsonResponse({
|
|
1529
|
+
"status": "ERROR",
|
|
1530
|
+
"error": "No pipeline components provided"
|
|
1531
|
+
}, status=400)
|
|
1532
|
+
|
|
1533
|
+
try:
|
|
1534
|
+
components = json.loads(components_json)
|
|
1535
|
+
except json.JSONDecodeError as e:
|
|
1536
|
+
logger.error(f"Failed to parse components JSON: {e}")
|
|
1537
|
+
return JsonResponse({
|
|
1538
|
+
"status": "ERROR",
|
|
1539
|
+
"error": "Invalid components data"
|
|
1540
|
+
}, status=400)
|
|
1541
|
+
|
|
1542
|
+
# Convert components to Logstash config
|
|
1543
|
+
converter = logstash_config_parse.ComponentToPipeline(components, test=False)
|
|
1544
|
+
logstash_config = converter.components_to_logstash_config()
|
|
1545
|
+
|
|
1546
|
+
# Send to logstashagent for validation
|
|
1547
|
+
base, sim_target, _ = _sim_agent_url(request)
|
|
1548
|
+
logstash_agent_url = f"{base}/_logstash/validate"
|
|
1549
|
+
|
|
1550
|
+
try:
|
|
1551
|
+
response = requests.post(
|
|
1552
|
+
logstash_agent_url,
|
|
1553
|
+
json={
|
|
1554
|
+
"pipeline_name": pipeline_name,
|
|
1555
|
+
"config": logstash_config
|
|
1556
|
+
},
|
|
1557
|
+
headers=_sim_agent_headers(sim_target),
|
|
1558
|
+
verify=agent_requests_verify(),
|
|
1559
|
+
timeout=30
|
|
1560
|
+
)
|
|
1561
|
+
response.raise_for_status()
|
|
1562
|
+
|
|
1563
|
+
validation_result = response.json()
|
|
1564
|
+
logger.info(f"Validation result for pipeline '{pipeline_name}': {validation_result.get('status')}")
|
|
1565
|
+
|
|
1566
|
+
return JsonResponse(validation_result, status=200)
|
|
1567
|
+
|
|
1568
|
+
except requests.exceptions.RequestException as e:
|
|
1569
|
+
logger.error(f"Failed to validate config via logstashagent: {e}")
|
|
1570
|
+
return JsonResponse({
|
|
1571
|
+
"status": "ERROR",
|
|
1572
|
+
"error": f"Failed to connect to logstashagent: {str(e)}"
|
|
1573
|
+
}, status=500)
|
|
1574
|
+
|
|
1575
|
+
except Exception as e:
|
|
1576
|
+
logger.error(f"Error in ValidateLogstashConfig: {e}")
|
|
1577
|
+
logger.error(traceback.format_exc())
|
|
1578
|
+
return JsonResponse({
|
|
1579
|
+
"status": "ERROR",
|
|
1580
|
+
"error": str(e)
|
|
1581
|
+
}, status=500)
|