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,1300 @@
|
|
|
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
|
+
"""PipelineManager data models: policies, connections, pipelines, and artifacts."""
|
|
6
|
+
|
|
7
|
+
from django.conf import settings
|
|
8
|
+
from django.db import models, transaction
|
|
9
|
+
from Common.encryption import encrypt_credential, decrypt_credential
|
|
10
|
+
from django.core.exceptions import ValidationError
|
|
11
|
+
from django.contrib.auth.hashers import make_password, check_password, identify_hasher
|
|
12
|
+
from django.utils import timezone
|
|
13
|
+
from datetime import timedelta
|
|
14
|
+
import hashlib
|
|
15
|
+
import re
|
|
16
|
+
import secrets
|
|
17
|
+
from Common import logstash_config_parse
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Policy(models.Model):
|
|
21
|
+
"""A Logstash Agent policy: settings, pipelines, and keystore for a role.
|
|
22
|
+
|
|
23
|
+
``policy_type``:
|
|
24
|
+
|
|
25
|
+
PACKAGED — distro Logstash (system unit ``logstash``); one system seed.
|
|
26
|
+
MANAGED — agent-owned isolated Logstash tree(s); multi-instance.
|
|
27
|
+
SIMULATE — simulation agents with isolated paths.
|
|
28
|
+
EMBEDDED — Docker compose sim (no enroll).
|
|
29
|
+
DEFAULT — legacy alias for PACKAGED (pre-release DB rows).
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
class PolicyType(models.TextChoices):
|
|
33
|
+
PACKAGED = 'PACKAGED', 'Packaged'
|
|
34
|
+
MANAGED = 'MANAGED', 'Managed'
|
|
35
|
+
SIMULATE = 'SIMULATE', 'Simulate'
|
|
36
|
+
EMBEDDED = 'EMBEDDED', 'Embedded'
|
|
37
|
+
# Legacy; prefer PACKAGED. Kept so unmigrated rows still validate.
|
|
38
|
+
DEFAULT = 'DEFAULT', 'Default (legacy)'
|
|
39
|
+
|
|
40
|
+
class LogstashSource(models.TextChoices):
|
|
41
|
+
SYSTEM = 'SYSTEM', 'System Logstash'
|
|
42
|
+
VERSION = 'VERSION', 'Pinned version (download)'
|
|
43
|
+
|
|
44
|
+
name = models.CharField(
|
|
45
|
+
max_length=100,
|
|
46
|
+
unique=True,
|
|
47
|
+
help_text="Policy name"
|
|
48
|
+
)
|
|
49
|
+
policy_type = models.CharField(
|
|
50
|
+
max_length=20,
|
|
51
|
+
choices=PolicyType.choices,
|
|
52
|
+
default=PolicyType.PACKAGED,
|
|
53
|
+
help_text="Agent role this policy targets"
|
|
54
|
+
)
|
|
55
|
+
is_system = models.BooleanField(
|
|
56
|
+
default=False,
|
|
57
|
+
help_text="System-seeded policy (restricted delete / structural edit)"
|
|
58
|
+
)
|
|
59
|
+
cloned_from = models.ForeignKey(
|
|
60
|
+
'self',
|
|
61
|
+
on_delete=models.SET_NULL,
|
|
62
|
+
blank=True,
|
|
63
|
+
null=True,
|
|
64
|
+
related_name='clones',
|
|
65
|
+
help_text="Source policy if this was cloned"
|
|
66
|
+
)
|
|
67
|
+
settings_path = models.CharField(
|
|
68
|
+
max_length=255,
|
|
69
|
+
default="/etc/logstash/",
|
|
70
|
+
help_text="Path to Logstash settings directory"
|
|
71
|
+
)
|
|
72
|
+
logs_path = models.CharField(
|
|
73
|
+
max_length=255,
|
|
74
|
+
default="/var/log/logstash",
|
|
75
|
+
help_text="Path to Logstash logs directory"
|
|
76
|
+
)
|
|
77
|
+
binary_path = models.CharField(
|
|
78
|
+
max_length=255,
|
|
79
|
+
default="/usr/share/logstash/bin",
|
|
80
|
+
help_text="Path to Logstash binary directory"
|
|
81
|
+
)
|
|
82
|
+
data_path = models.CharField(
|
|
83
|
+
max_length=255,
|
|
84
|
+
blank=True,
|
|
85
|
+
default="",
|
|
86
|
+
help_text="Path to Logstash data directory (optional; simulate derives from instance)"
|
|
87
|
+
)
|
|
88
|
+
agent_api_port = models.PositiveIntegerField(
|
|
89
|
+
default=9500,
|
|
90
|
+
help_text="Policy default agent FastAPI port (Packaged 9550 as-is; Managed 9550+N; Simulate/Embedded 9500+N or 9500)"
|
|
91
|
+
)
|
|
92
|
+
logstash_api_port = models.PositiveIntegerField(
|
|
93
|
+
default=9560,
|
|
94
|
+
help_text="Policy default Logstash HTTP API port (Packaged 9600 as-is; Managed 9700+N; Simulate/Embedded 9560+N or 9560)"
|
|
95
|
+
)
|
|
96
|
+
keystore_env_file = models.CharField(
|
|
97
|
+
max_length=512,
|
|
98
|
+
blank=True,
|
|
99
|
+
default="/etc/default/logstash",
|
|
100
|
+
help_text="Env file path where LOGSTASH_KEYSTORE_PASS is written for systemd"
|
|
101
|
+
)
|
|
102
|
+
logstash_source = models.CharField(
|
|
103
|
+
max_length=20,
|
|
104
|
+
choices=LogstashSource.choices,
|
|
105
|
+
default=LogstashSource.SYSTEM,
|
|
106
|
+
help_text="Where the simulate agent obtains the Logstash binary"
|
|
107
|
+
)
|
|
108
|
+
logstash_version = models.CharField(
|
|
109
|
+
max_length=32,
|
|
110
|
+
blank=True,
|
|
111
|
+
default="",
|
|
112
|
+
help_text="Pinned Logstash version when logstash_source=VERSION (e.g. 9.4.3)"
|
|
113
|
+
)
|
|
114
|
+
logstash_download_dir = models.CharField(
|
|
115
|
+
max_length=512,
|
|
116
|
+
blank=True,
|
|
117
|
+
default="/opt/logstash-agent/logstash-versions",
|
|
118
|
+
help_text="Directory for auto-downloaded Logstash versions"
|
|
119
|
+
)
|
|
120
|
+
logstash_via_ui = models.BooleanField(
|
|
121
|
+
default=False,
|
|
122
|
+
help_text=(
|
|
123
|
+
"Fetch the Logstash tarball from LogstashUI instead of "
|
|
124
|
+
"artifacts.elastic.co. Only meaningful when logstash_source=VERSION "
|
|
125
|
+
"on a MANAGED or SIMULATE policy."
|
|
126
|
+
)
|
|
127
|
+
)
|
|
128
|
+
logstash_yml = models.TextField(
|
|
129
|
+
help_text="Content of logstash.yml configuration file"
|
|
130
|
+
)
|
|
131
|
+
jvm_options = models.TextField(
|
|
132
|
+
help_text="Content of jvm.options configuration file"
|
|
133
|
+
)
|
|
134
|
+
log4j2_properties = models.TextField(
|
|
135
|
+
help_text="Content of log4j2.properties configuration file"
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
# Configuration file hashes (auto-computed on save)
|
|
139
|
+
logstash_yml_hash = models.CharField(
|
|
140
|
+
max_length=64,
|
|
141
|
+
blank=True,
|
|
142
|
+
editable=False,
|
|
143
|
+
help_text="SHA256 hash of logstash.yml content"
|
|
144
|
+
)
|
|
145
|
+
jvm_options_hash = models.CharField(
|
|
146
|
+
max_length=64,
|
|
147
|
+
blank=True,
|
|
148
|
+
editable=False,
|
|
149
|
+
help_text="SHA256 hash of jvm.options content"
|
|
150
|
+
)
|
|
151
|
+
log4j2_properties_hash = models.CharField(
|
|
152
|
+
max_length=64,
|
|
153
|
+
blank=True,
|
|
154
|
+
editable=False,
|
|
155
|
+
help_text="SHA256 hash of log4j2.properties content"
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
# Keystore password (encrypted at rest)
|
|
159
|
+
keystore_password = models.CharField(
|
|
160
|
+
max_length=512,
|
|
161
|
+
blank=True,
|
|
162
|
+
null=True,
|
|
163
|
+
help_text="Keystore password (encrypted at rest)"
|
|
164
|
+
)
|
|
165
|
+
keystore_password_hash = models.CharField(
|
|
166
|
+
max_length=64,
|
|
167
|
+
blank=True,
|
|
168
|
+
editable=False,
|
|
169
|
+
help_text="SHA256 hash of keystore password for change detection"
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
# Deployment tracking
|
|
173
|
+
has_undeployed_changes = models.BooleanField(
|
|
174
|
+
default=True,
|
|
175
|
+
help_text="Indicates if there are changes that haven't been deployed"
|
|
176
|
+
)
|
|
177
|
+
current_revision_number = models.IntegerField(
|
|
178
|
+
default=0,
|
|
179
|
+
help_text="Current revision number of the policy"
|
|
180
|
+
)
|
|
181
|
+
last_deployed_at = models.DateTimeField(
|
|
182
|
+
null=True,
|
|
183
|
+
blank=True,
|
|
184
|
+
help_text="Timestamp of the most recent successful deployment"
|
|
185
|
+
)
|
|
186
|
+
|
|
187
|
+
# Metadata
|
|
188
|
+
created_at = models.DateTimeField(auto_now_add=True)
|
|
189
|
+
updated_at = models.DateTimeField(auto_now=True)
|
|
190
|
+
|
|
191
|
+
class Meta:
|
|
192
|
+
ordering = ['name']
|
|
193
|
+
verbose_name = 'Policy'
|
|
194
|
+
verbose_name_plural = 'Policies'
|
|
195
|
+
|
|
196
|
+
def save(self, *args, **kwargs):
|
|
197
|
+
"""Compute config hashes, encrypt the keystore password, and persist.
|
|
198
|
+
|
|
199
|
+
SHA-256 hashes of ``logstash_yml``, ``jvm_options``, and
|
|
200
|
+
``log4j2_properties`` are stored for agent change detection. A
|
|
201
|
+
plaintext keystore password is hashed then Fernet-encrypted.
|
|
202
|
+
"""
|
|
203
|
+
# Compute hashes from configuration file contents
|
|
204
|
+
self.logstash_yml_hash = hashlib.sha256(self.logstash_yml.encode('utf-8')).hexdigest()
|
|
205
|
+
self.jvm_options_hash = hashlib.sha256(self.jvm_options.encode('utf-8')).hexdigest()
|
|
206
|
+
self.log4j2_properties_hash = hashlib.sha256(self.log4j2_properties.encode('utf-8')).hexdigest()
|
|
207
|
+
|
|
208
|
+
# Encrypt keystore password and compute hash if provided as plaintext
|
|
209
|
+
if self.keystore_password and not self._is_encrypted(self.keystore_password):
|
|
210
|
+
self.keystore_password_hash = hashlib.sha256(
|
|
211
|
+
self.keystore_password.encode('utf-8')
|
|
212
|
+
).hexdigest()
|
|
213
|
+
self.keystore_password = encrypt_credential(self.keystore_password)
|
|
214
|
+
elif not self.keystore_password:
|
|
215
|
+
self.keystore_password_hash = ''
|
|
216
|
+
|
|
217
|
+
super().save(*args, **kwargs)
|
|
218
|
+
|
|
219
|
+
def _is_encrypted(self, value):
|
|
220
|
+
"""Return True when ``value`` is already a Fernet token (``gAAAAA`` prefix)."""
|
|
221
|
+
return value and value.startswith('gAAAAA')
|
|
222
|
+
|
|
223
|
+
def get_keystore_password(self):
|
|
224
|
+
"""Return the decrypted keystore password, or None if unset."""
|
|
225
|
+
return decrypt_credential(self.keystore_password) if self.keystore_password else None
|
|
226
|
+
|
|
227
|
+
@property
|
|
228
|
+
def is_simulate_capable(self):
|
|
229
|
+
"""True when this policy can be used as a simulation target."""
|
|
230
|
+
return self.policy_type in (self.PolicyType.SIMULATE, self.PolicyType.EMBEDDED)
|
|
231
|
+
|
|
232
|
+
def __str__(self):
|
|
233
|
+
return self.name
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
class Connection(models.Model):
|
|
237
|
+
"""A Logstash Agent row or a Centralized Pipeline Management ES connection.
|
|
238
|
+
|
|
239
|
+
AGENT connections enroll via token, hold an ``ApiKey``, and attach to a
|
|
240
|
+
``Policy``. CENTRALIZED connections store Elasticsearch credentials
|
|
241
|
+
(encrypted at rest) and have no agent check-in.
|
|
242
|
+
"""
|
|
243
|
+
|
|
244
|
+
class ConnectionType(models.TextChoices):
|
|
245
|
+
AGENT = 'AGENT', 'Logstash Agent'
|
|
246
|
+
CENTRALIZED = 'CENTRALIZED', 'Centralized Pipeline Management'
|
|
247
|
+
|
|
248
|
+
name = models.CharField(
|
|
249
|
+
max_length=100,
|
|
250
|
+
help_text="A friendly name for this connection"
|
|
251
|
+
)
|
|
252
|
+
connection_type = models.CharField(
|
|
253
|
+
max_length=20,
|
|
254
|
+
choices=ConnectionType.choices,
|
|
255
|
+
help_text="Type of connection (Agent or Centralized)"
|
|
256
|
+
)
|
|
257
|
+
|
|
258
|
+
# Agent Connection Fields (optional)
|
|
259
|
+
agent_id = models.CharField(
|
|
260
|
+
max_length=255,
|
|
261
|
+
blank=True,
|
|
262
|
+
null=True,
|
|
263
|
+
unique=True,
|
|
264
|
+
help_text="Unique agent ID for Agent connections"
|
|
265
|
+
)
|
|
266
|
+
host = models.CharField(
|
|
267
|
+
max_length=255,
|
|
268
|
+
blank=True,
|
|
269
|
+
null=True,
|
|
270
|
+
help_text="Hostname or IP address for Agent connection"
|
|
271
|
+
)
|
|
272
|
+
port = models.PositiveIntegerField(
|
|
273
|
+
default=22,
|
|
274
|
+
blank=True,
|
|
275
|
+
null=True,
|
|
276
|
+
help_text="Agent port (default: 22)"
|
|
277
|
+
)
|
|
278
|
+
username = models.CharField(
|
|
279
|
+
max_length=100,
|
|
280
|
+
blank=True,
|
|
281
|
+
null=True,
|
|
282
|
+
help_text="Username for authentication"
|
|
283
|
+
)
|
|
284
|
+
password = models.CharField(
|
|
285
|
+
max_length=512,
|
|
286
|
+
blank=True,
|
|
287
|
+
null=True,
|
|
288
|
+
help_text="Password for authentication (leave empty if using key-based auth)"
|
|
289
|
+
)
|
|
290
|
+
ssh_key = models.TextField(
|
|
291
|
+
blank=True,
|
|
292
|
+
null=True,
|
|
293
|
+
help_text="Private key (PEM format) for key-based authentication"
|
|
294
|
+
)
|
|
295
|
+
|
|
296
|
+
# Centralized Management Fields (optional)
|
|
297
|
+
cloud_id = models.CharField(
|
|
298
|
+
max_length=255,
|
|
299
|
+
blank=True,
|
|
300
|
+
null=True,
|
|
301
|
+
help_text="Elastic Cloud ID for centralized management"
|
|
302
|
+
)
|
|
303
|
+
cloud_url = models.URLField(
|
|
304
|
+
blank=True,
|
|
305
|
+
null=True,
|
|
306
|
+
help_text="Elastic Cloud URL (alternative to Cloud ID)"
|
|
307
|
+
)
|
|
308
|
+
api_key = models.CharField(
|
|
309
|
+
max_length=512,
|
|
310
|
+
blank=True,
|
|
311
|
+
null=True,
|
|
312
|
+
help_text="API key for authentication (alternative to username/password)"
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
# Policy for Agent connections
|
|
316
|
+
policy = models.ForeignKey(
|
|
317
|
+
Policy,
|
|
318
|
+
on_delete=models.SET_NULL,
|
|
319
|
+
blank=True,
|
|
320
|
+
null=True,
|
|
321
|
+
related_name='connections',
|
|
322
|
+
help_text="Policy to apply to this agent (only for AGENT connection type)"
|
|
323
|
+
)
|
|
324
|
+
|
|
325
|
+
# Metadata
|
|
326
|
+
created_at = models.DateTimeField(auto_now_add=True)
|
|
327
|
+
updated_at = models.DateTimeField(auto_now=True)
|
|
328
|
+
last_check_in = models.DateTimeField(
|
|
329
|
+
null=True,
|
|
330
|
+
blank=True,
|
|
331
|
+
help_text="Last time the agent checked in with logstashui"
|
|
332
|
+
)
|
|
333
|
+
status_blob = models.JSONField(
|
|
334
|
+
null=True,
|
|
335
|
+
blank=True,
|
|
336
|
+
help_text="JSON blob containing agent health status information"
|
|
337
|
+
)
|
|
338
|
+
is_active = models.BooleanField(default=True)
|
|
339
|
+
restart_on_next_checkin = models.BooleanField(
|
|
340
|
+
default=False,
|
|
341
|
+
help_text="If true, instructs the agent to restart Logstash on its next check-in"
|
|
342
|
+
)
|
|
343
|
+
allow_self_signed_certs = models.BooleanField(
|
|
344
|
+
default=True,
|
|
345
|
+
help_text=(
|
|
346
|
+
"Allow self-signed TLS certificates when connecting to Elasticsearch/Kibana. "
|
|
347
|
+
"Defaults to True so existing connections keep working after migration."
|
|
348
|
+
),
|
|
349
|
+
)
|
|
350
|
+
desired_agent_version = models.CharField(
|
|
351
|
+
max_length=20,
|
|
352
|
+
blank=True,
|
|
353
|
+
null=True,
|
|
354
|
+
help_text="Desired LogstashAgent version for this connection (triggers upgrade on next check-in)"
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
# Simulate-instance fields (null for default / non-sim agents)
|
|
358
|
+
instance_id = models.PositiveIntegerField(
|
|
359
|
+
blank=True,
|
|
360
|
+
null=True,
|
|
361
|
+
help_text="Simulate instance number N (paths under /opt/logstash-agent/simulate-N)"
|
|
362
|
+
)
|
|
363
|
+
agent_api_port = models.PositiveIntegerField(
|
|
364
|
+
blank=True,
|
|
365
|
+
null=True,
|
|
366
|
+
help_text="Agent FastAPI port for this connection (packaged 9550; managed 9550+N; simulate 9500+N; embedded 9500)"
|
|
367
|
+
)
|
|
368
|
+
logstash_api_port = models.PositiveIntegerField(
|
|
369
|
+
blank=True,
|
|
370
|
+
null=True,
|
|
371
|
+
help_text="Logstash HTTP API port for this connection (packaged 9600; managed 9700+N; simulate 9560+N; embedded 9560)"
|
|
372
|
+
)
|
|
373
|
+
agent_inbound_key = models.CharField(
|
|
374
|
+
max_length=512,
|
|
375
|
+
blank=True,
|
|
376
|
+
null=True,
|
|
377
|
+
help_text="Encrypted key the UI presents to this agent's API (Authorization: ApiKey)"
|
|
378
|
+
)
|
|
379
|
+
logstash_version_resolved = models.CharField(
|
|
380
|
+
max_length=64,
|
|
381
|
+
blank=True,
|
|
382
|
+
default="",
|
|
383
|
+
help_text="Logstash version reported by the agent (for sim target dropdown)"
|
|
384
|
+
)
|
|
385
|
+
last_selected_at = models.DateTimeField(
|
|
386
|
+
blank=True,
|
|
387
|
+
null=True,
|
|
388
|
+
help_text="Last time this connection was selected as a sim target (sticky UX only)"
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
class Meta:
|
|
392
|
+
ordering = ['name']
|
|
393
|
+
verbose_name = 'Connection'
|
|
394
|
+
verbose_name_plural = 'Connections'
|
|
395
|
+
|
|
396
|
+
def __str__(self):
|
|
397
|
+
return f"{self.name} ({self.get_connection_type_display()})"
|
|
398
|
+
|
|
399
|
+
def clean(self):
|
|
400
|
+
"""Validate required fields for the connection type.
|
|
401
|
+
|
|
402
|
+
AGENT rows need ``host``. CENTRALIZED rows need Cloud ID or host,
|
|
403
|
+
plus either an API key or username/password.
|
|
404
|
+
|
|
405
|
+
For *updates* (pk already set) the form may clear the credential
|
|
406
|
+
fields on submission when the user didn't re-enter them. In that
|
|
407
|
+
case we fall back to the persisted DB row to confirm that credentials
|
|
408
|
+
are still stored — the form's ``save()`` will restore the encrypted
|
|
409
|
+
value before writing to the database.
|
|
410
|
+
"""
|
|
411
|
+
if self.connection_type == self.ConnectionType.AGENT:
|
|
412
|
+
if not self.host:
|
|
413
|
+
raise ValidationError("Host is required for Agent connections")
|
|
414
|
+
# Note: AGENT connections use ApiKey table (FK reference), so no ssh_key/username/password required here
|
|
415
|
+
else: # CENTRALIZED
|
|
416
|
+
if not (self.cloud_id or self.host):
|
|
417
|
+
raise ValidationError(
|
|
418
|
+
"Either Cloud ID or Cloud URL is required for centralized connections"
|
|
419
|
+
)
|
|
420
|
+
if not (self.api_key or (self.username and self.password)):
|
|
421
|
+
# Bug 2 fix: for partial PUT requests the form clears the credential
|
|
422
|
+
# field that wasn't re-submitted. If this is an existing row, check
|
|
423
|
+
# the persisted record to see whether a credential is already stored;
|
|
424
|
+
# if yes, validation passes and form.save() will restore it.
|
|
425
|
+
has_stored_credential = False
|
|
426
|
+
if self.pk:
|
|
427
|
+
try:
|
|
428
|
+
db = Connection.objects.get(pk=self.pk)
|
|
429
|
+
has_stored_credential = bool(
|
|
430
|
+
db.api_key or (db.username and db.password)
|
|
431
|
+
)
|
|
432
|
+
except Connection.DoesNotExist:
|
|
433
|
+
pass
|
|
434
|
+
if not has_stored_credential:
|
|
435
|
+
raise ValidationError(
|
|
436
|
+
"Either API key or username/password is required for centralized connections"
|
|
437
|
+
)
|
|
438
|
+
|
|
439
|
+
def save(self, *args, **kwargs):
|
|
440
|
+
"""Validate, encrypt credentials, and persist the connection.
|
|
441
|
+
|
|
442
|
+
Encrypts ``password``, ``ssh_key``, and ``api_key`` when they are
|
|
443
|
+
still plaintext (Fernet tokens start with ``gAAAAA``).
|
|
444
|
+
"""
|
|
445
|
+
self.full_clean()
|
|
446
|
+
|
|
447
|
+
# Encrypt sensitive fields before saving
|
|
448
|
+
if self.password and not self._is_encrypted(self.password):
|
|
449
|
+
self.password = encrypt_credential(self.password)
|
|
450
|
+
if self.ssh_key and not self._is_encrypted(self.ssh_key):
|
|
451
|
+
self.ssh_key = encrypt_credential(self.ssh_key)
|
|
452
|
+
if self.api_key and not self._is_encrypted(self.api_key):
|
|
453
|
+
self.api_key = encrypt_credential(self.api_key)
|
|
454
|
+
if self.agent_inbound_key and not self._is_encrypted(self.agent_inbound_key):
|
|
455
|
+
self.agent_inbound_key = encrypt_credential(self.agent_inbound_key)
|
|
456
|
+
|
|
457
|
+
super().save(*args, **kwargs)
|
|
458
|
+
|
|
459
|
+
def _is_encrypted(self, value):
|
|
460
|
+
"""Return True when ``value`` is already a Fernet token (``gAAAAA`` prefix)."""
|
|
461
|
+
return value and value.startswith('gAAAAA')
|
|
462
|
+
|
|
463
|
+
def get_password(self):
|
|
464
|
+
"""Return the decrypted password, or None if unset."""
|
|
465
|
+
return decrypt_credential(self.password) if self.password else None
|
|
466
|
+
|
|
467
|
+
def get_api_key(self):
|
|
468
|
+
"""Return the decrypted API key, or None if unset."""
|
|
469
|
+
return decrypt_credential(self.api_key) if self.api_key else None
|
|
470
|
+
|
|
471
|
+
def get_agent_inbound_key(self):
|
|
472
|
+
"""Return the decrypted agent inbound API key, or None if unset."""
|
|
473
|
+
return decrypt_credential(self.agent_inbound_key) if self.agent_inbound_key else None
|
|
474
|
+
|
|
475
|
+
|
|
476
|
+
MANAGED_BY_CHOICES = [
|
|
477
|
+
('user', 'User'),
|
|
478
|
+
('snmp', 'SNMP'),
|
|
479
|
+
('library', 'Library'),
|
|
480
|
+
]
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
class Pipeline(models.Model):
|
|
484
|
+
"""A Logstash pipeline configuration belonging to a policy.
|
|
485
|
+
|
|
486
|
+
Names are unique within a policy and may be reused across policies.
|
|
487
|
+
``managed_by`` distinguishes user-authored pipelines from SNMP/library
|
|
488
|
+
ones; only user pipelines enter policy revisions.
|
|
489
|
+
"""
|
|
490
|
+
#: Fields stored per pipeline in a policy revision snapshot.
|
|
491
|
+
SNAPSHOT_FIELDS = (
|
|
492
|
+
'name', 'description', 'lscl', 'no_input', 'non_reloadable',
|
|
493
|
+
'pipeline_workers', 'pipeline_batch_size', 'pipeline_batch_delay',
|
|
494
|
+
'queue_type', 'queue_max_bytes', 'queue_checkpoint_writes',
|
|
495
|
+
)
|
|
496
|
+
#: Snapshot fields ``policies_diff`` compares besides ``name``. Older
|
|
497
|
+
#: snapshots without a field are compared only on the fields they have.
|
|
498
|
+
DIFF_FIELDS = (
|
|
499
|
+
'lscl', 'pipeline_workers', 'pipeline_batch_size', 'pipeline_batch_delay',
|
|
500
|
+
'queue_type', 'queue_max_bytes', 'queue_checkpoint_writes',
|
|
501
|
+
)
|
|
502
|
+
|
|
503
|
+
policy = models.ForeignKey(
|
|
504
|
+
Policy,
|
|
505
|
+
on_delete=models.CASCADE,
|
|
506
|
+
related_name='pipelines',
|
|
507
|
+
help_text="Policy this pipeline belongs to"
|
|
508
|
+
)
|
|
509
|
+
name = models.CharField(
|
|
510
|
+
max_length=100,
|
|
511
|
+
help_text="Pipeline name (unique within policy)"
|
|
512
|
+
)
|
|
513
|
+
managed_by = models.CharField(
|
|
514
|
+
max_length=20,
|
|
515
|
+
choices=MANAGED_BY_CHOICES,
|
|
516
|
+
default='user',
|
|
517
|
+
help_text="Which subsystem owns this pipeline (user, snmp, library)"
|
|
518
|
+
)
|
|
519
|
+
description = models.TextField(
|
|
520
|
+
blank=True,
|
|
521
|
+
null=True,
|
|
522
|
+
help_text="Description of the pipeline"
|
|
523
|
+
)
|
|
524
|
+
lscl = models.TextField(
|
|
525
|
+
help_text="Logstash Configuration Language (pipeline configuration)"
|
|
526
|
+
)
|
|
527
|
+
lscl_hash = models.CharField(
|
|
528
|
+
max_length=64,
|
|
529
|
+
blank=True,
|
|
530
|
+
null=True,
|
|
531
|
+
help_text="Hash of the LSCL content for change detection"
|
|
532
|
+
)
|
|
533
|
+
pipeline_hash = models.CharField(
|
|
534
|
+
max_length=64,
|
|
535
|
+
blank=True,
|
|
536
|
+
editable=False,
|
|
537
|
+
help_text="SHA256 hash of pipeline name + lscl + all settings, for agent change detection"
|
|
538
|
+
)
|
|
539
|
+
last_updated = models.DateTimeField(auto_now=True)
|
|
540
|
+
|
|
541
|
+
revision_number = models.IntegerField(
|
|
542
|
+
help_text="Revision number for this deployment",
|
|
543
|
+
default=0
|
|
544
|
+
)
|
|
545
|
+
|
|
546
|
+
# Pipeline Settings
|
|
547
|
+
pipeline_workers = models.IntegerField(
|
|
548
|
+
default=1,
|
|
549
|
+
help_text="Number of worker threads for pipeline execution"
|
|
550
|
+
)
|
|
551
|
+
pipeline_batch_size = models.IntegerField(
|
|
552
|
+
default=128,
|
|
553
|
+
help_text="Maximum number of events per batch"
|
|
554
|
+
)
|
|
555
|
+
pipeline_batch_delay = models.IntegerField(
|
|
556
|
+
default=50,
|
|
557
|
+
help_text="Batch delay in milliseconds"
|
|
558
|
+
)
|
|
559
|
+
queue_type = models.CharField(
|
|
560
|
+
max_length=20,
|
|
561
|
+
default='memory',
|
|
562
|
+
help_text="Queue type (memory or persisted)"
|
|
563
|
+
)
|
|
564
|
+
queue_max_bytes = models.CharField(
|
|
565
|
+
max_length=20,
|
|
566
|
+
default='1gb',
|
|
567
|
+
help_text="Maximum queue size (e.g., 1gb, 512mb)"
|
|
568
|
+
)
|
|
569
|
+
queue_checkpoint_writes = models.IntegerField(
|
|
570
|
+
default=1024,
|
|
571
|
+
help_text="Number of writes before checkpoint (for persisted queue)"
|
|
572
|
+
)
|
|
573
|
+
|
|
574
|
+
# Pipeline analysis flags (auto-computed on save)
|
|
575
|
+
no_input = models.BooleanField(
|
|
576
|
+
default=False,
|
|
577
|
+
help_text="True if the pipeline's input block contains no plugins"
|
|
578
|
+
)
|
|
579
|
+
non_reloadable = models.BooleanField(
|
|
580
|
+
default=False,
|
|
581
|
+
help_text="True if the pipeline contains a stdin input plugin (prevents hot-reload)"
|
|
582
|
+
)
|
|
583
|
+
|
|
584
|
+
class Meta:
|
|
585
|
+
ordering = ['policy', 'name']
|
|
586
|
+
verbose_name = 'Pipeline'
|
|
587
|
+
verbose_name_plural = 'Pipelines'
|
|
588
|
+
constraints = [
|
|
589
|
+
models.UniqueConstraint(
|
|
590
|
+
fields=['policy', 'name'],
|
|
591
|
+
name='unique_pipeline_per_policy'
|
|
592
|
+
)
|
|
593
|
+
]
|
|
594
|
+
|
|
595
|
+
def save(self, *args, **kwargs):
|
|
596
|
+
"""Recompute ``pipeline_hash`` and analysis flags, then persist.
|
|
597
|
+
|
|
598
|
+
``pipeline_hash`` is SHA-256 of name, LSCL, and all pipeline settings.
|
|
599
|
+
``no_input`` and ``non_reloadable`` are derived from the parsed LSCL;
|
|
600
|
+
a parse failure leaves existing flags unchanged.
|
|
601
|
+
"""
|
|
602
|
+
hash_input = (
|
|
603
|
+
f"{self.name}{self.lscl}{self.pipeline_workers}{self.pipeline_batch_size}"
|
|
604
|
+
f"{self.pipeline_batch_delay}{self.queue_type}{self.queue_max_bytes}"
|
|
605
|
+
f"{self.queue_checkpoint_writes}"
|
|
606
|
+
)
|
|
607
|
+
self.pipeline_hash = hashlib.sha256(hash_input.encode('utf-8')).hexdigest()
|
|
608
|
+
|
|
609
|
+
# Compute analysis flags from parsed pipeline
|
|
610
|
+
try:
|
|
611
|
+
import json as _json
|
|
612
|
+
components = _json.loads(logstash_config_parse.logstash_config_to_components(self.lscl))
|
|
613
|
+
inputs = components.get("input", [])
|
|
614
|
+
|
|
615
|
+
self.no_input = len(inputs) == 0
|
|
616
|
+
|
|
617
|
+
def _has_stdin(plugins):
|
|
618
|
+
for plugin in plugins:
|
|
619
|
+
if plugin.get("plugin") == "stdin":
|
|
620
|
+
return True
|
|
621
|
+
nested = plugin.get("config", {}).get("plugins", [])
|
|
622
|
+
if nested and _has_stdin(nested):
|
|
623
|
+
return True
|
|
624
|
+
return False
|
|
625
|
+
|
|
626
|
+
self.non_reloadable = _has_stdin(inputs)
|
|
627
|
+
except Exception:
|
|
628
|
+
# Parsing failure — leave existing flags unchanged
|
|
629
|
+
pass
|
|
630
|
+
|
|
631
|
+
super().save(*args, **kwargs)
|
|
632
|
+
|
|
633
|
+
def __str__(self):
|
|
634
|
+
return f"{self.policy.name} - {self.name}"
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
class Keystore(models.Model):
|
|
638
|
+
"""An encrypted key-value entry in a policy's Logstash keystore.
|
|
639
|
+
|
|
640
|
+
Key names are unique within a policy and may be reused across policies.
|
|
641
|
+
``kv_hash`` is SHA-256 of plaintext ``key_name`` + ``key_value``.
|
|
642
|
+
"""
|
|
643
|
+
policy = models.ForeignKey(
|
|
644
|
+
Policy,
|
|
645
|
+
on_delete=models.CASCADE,
|
|
646
|
+
related_name='keystore_entries',
|
|
647
|
+
help_text="Policy this keystore entry belongs to"
|
|
648
|
+
)
|
|
649
|
+
key_name = models.CharField(
|
|
650
|
+
max_length=100,
|
|
651
|
+
help_text="Key name (unique within policy)"
|
|
652
|
+
)
|
|
653
|
+
key_value = models.CharField(
|
|
654
|
+
max_length=512,
|
|
655
|
+
help_text="Encrypted key value"
|
|
656
|
+
)
|
|
657
|
+
managed_by = models.CharField(
|
|
658
|
+
max_length=20,
|
|
659
|
+
choices=MANAGED_BY_CHOICES,
|
|
660
|
+
default='user',
|
|
661
|
+
help_text="Which subsystem owns this keystore entry (user, snmp, library)"
|
|
662
|
+
)
|
|
663
|
+
kv_hash = models.CharField(
|
|
664
|
+
max_length=64,
|
|
665
|
+
blank=True,
|
|
666
|
+
editable=False,
|
|
667
|
+
help_text="SHA256 hash of key_name + key_value for change detection"
|
|
668
|
+
)
|
|
669
|
+
last_updated = models.DateTimeField(auto_now=True)
|
|
670
|
+
|
|
671
|
+
revision_number = models.IntegerField(
|
|
672
|
+
help_text="Revision number for this deployment",
|
|
673
|
+
default=0
|
|
674
|
+
)
|
|
675
|
+
|
|
676
|
+
class Meta:
|
|
677
|
+
ordering = ['policy', 'key_name']
|
|
678
|
+
verbose_name = 'Keystore Entry'
|
|
679
|
+
verbose_name_plural = 'Keystore Entries'
|
|
680
|
+
constraints = [
|
|
681
|
+
models.UniqueConstraint(
|
|
682
|
+
fields=['policy', 'key_name'],
|
|
683
|
+
name='unique_key_per_policy'
|
|
684
|
+
)
|
|
685
|
+
]
|
|
686
|
+
|
|
687
|
+
def save(self, *args, **kwargs):
|
|
688
|
+
"""Encrypt ``key_value`` and recompute ``kv_hash`` from plaintext.
|
|
689
|
+
|
|
690
|
+
Hashing happens before encryption so the same key-value pair always
|
|
691
|
+
yields the same hash. An already-encrypted value cannot be rehashed
|
|
692
|
+
from plaintext; the existing hash is kept, or a hash of the
|
|
693
|
+
ciphertext is stored if none exists.
|
|
694
|
+
"""
|
|
695
|
+
# Compute hash from plaintext key_name + key_value BEFORE encryption
|
|
696
|
+
# This ensures the hash is consistent for the same key-value pair
|
|
697
|
+
if self.key_value and not self._is_encrypted(self.key_value):
|
|
698
|
+
# Hash the plaintext value
|
|
699
|
+
combined = f"{self.key_name}{self.key_value}"
|
|
700
|
+
self.kv_hash = hashlib.sha256(combined.encode('utf-8')).hexdigest()
|
|
701
|
+
# Then encrypt
|
|
702
|
+
self.key_value = encrypt_credential(self.key_value)
|
|
703
|
+
else:
|
|
704
|
+
# If already encrypted, we can't recompute the hash from plaintext
|
|
705
|
+
# Keep existing hash or compute from encrypted value (not ideal but necessary)
|
|
706
|
+
if not self.kv_hash:
|
|
707
|
+
combined = f"{self.key_name}{self.key_value}"
|
|
708
|
+
self.kv_hash = hashlib.sha256(combined.encode('utf-8')).hexdigest()
|
|
709
|
+
|
|
710
|
+
super().save(*args, **kwargs)
|
|
711
|
+
|
|
712
|
+
def __str__(self):
|
|
713
|
+
return f"{self.policy.name} - {self.key_name}"
|
|
714
|
+
|
|
715
|
+
def _is_encrypted(self, value):
|
|
716
|
+
"""Return True when ``value`` is already a Fernet token (``gAAAAA`` prefix)."""
|
|
717
|
+
return value and value.startswith('gAAAAA')
|
|
718
|
+
|
|
719
|
+
def get_key_value(self):
|
|
720
|
+
"""Return the decrypted key value, or None if unset."""
|
|
721
|
+
return decrypt_credential(self.key_value) if self.key_value else None
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
class Revision(models.Model):
|
|
725
|
+
"""A deployed snapshot of a policy.
|
|
726
|
+
|
|
727
|
+
Each revision stores the complete policy state at deploy time (config
|
|
728
|
+
files, user pipelines, user keystore entries). SNMP artifacts are never
|
|
729
|
+
recorded here.
|
|
730
|
+
"""
|
|
731
|
+
revision_number = models.IntegerField(
|
|
732
|
+
help_text="Revision number for this deployment"
|
|
733
|
+
)
|
|
734
|
+
policy = models.ForeignKey(
|
|
735
|
+
Policy,
|
|
736
|
+
on_delete=models.CASCADE,
|
|
737
|
+
related_name='revisions',
|
|
738
|
+
help_text="Policy this revision belongs to"
|
|
739
|
+
)
|
|
740
|
+
snapshot_json = models.JSONField(
|
|
741
|
+
help_text="Complete serialized state including config files, pipelines, and keystore entries"
|
|
742
|
+
)
|
|
743
|
+
created_at = models.DateTimeField(auto_now_add=True)
|
|
744
|
+
created_by = models.CharField(
|
|
745
|
+
max_length=150,
|
|
746
|
+
help_text="Username of the user who created this revision"
|
|
747
|
+
)
|
|
748
|
+
|
|
749
|
+
class Meta:
|
|
750
|
+
ordering = ['-revision_number', '-created_at']
|
|
751
|
+
verbose_name = 'Revision'
|
|
752
|
+
verbose_name_plural = 'Revisions'
|
|
753
|
+
constraints = [
|
|
754
|
+
models.UniqueConstraint(
|
|
755
|
+
fields=['policy', 'revision_number'],
|
|
756
|
+
name='unique_revision_per_policy'
|
|
757
|
+
)
|
|
758
|
+
]
|
|
759
|
+
|
|
760
|
+
def __str__(self):
|
|
761
|
+
return f"{self.policy.name} - Revision {self.revision_number}"
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
class EnrollmentToken(models.Model):
|
|
765
|
+
"""An enrollment token used during initial agent enrollment.
|
|
766
|
+
|
|
767
|
+
Each token belongs to a specific policy. The agent presents a base64
|
|
768
|
+
JSON payload containing this token's raw value.
|
|
769
|
+
"""
|
|
770
|
+
policy = models.ForeignKey(
|
|
771
|
+
Policy,
|
|
772
|
+
on_delete=models.CASCADE,
|
|
773
|
+
related_name='enrollment_tokens',
|
|
774
|
+
help_text="Policy this enrollment token is associated with"
|
|
775
|
+
)
|
|
776
|
+
name = models.CharField(
|
|
777
|
+
max_length=100,
|
|
778
|
+
default="default",
|
|
779
|
+
help_text="Name for this enrollment token"
|
|
780
|
+
)
|
|
781
|
+
token = models.CharField(
|
|
782
|
+
max_length=512,
|
|
783
|
+
help_text="Enrollment token string"
|
|
784
|
+
)
|
|
785
|
+
|
|
786
|
+
class Meta:
|
|
787
|
+
ordering = ['policy', 'name']
|
|
788
|
+
verbose_name = 'Enrollment Token'
|
|
789
|
+
verbose_name_plural = 'Enrollment Tokens'
|
|
790
|
+
constraints = [
|
|
791
|
+
models.UniqueConstraint(
|
|
792
|
+
fields=['policy', 'name'],
|
|
793
|
+
name='unique_token_name_per_policy'
|
|
794
|
+
)
|
|
795
|
+
]
|
|
796
|
+
|
|
797
|
+
def __str__(self):
|
|
798
|
+
return f"{self.policy.name} - {self.name}"
|
|
799
|
+
|
|
800
|
+
|
|
801
|
+
#: Namespace marker on admin API tokens. Agent keys carry no prefix, so the
|
|
802
|
+
#: token middleware can tell the two apart from the header alone.
|
|
803
|
+
API_TOKEN_SCHEME = 'lsui'
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
class ApiKey(models.Model):
|
|
807
|
+
"""A hashed bearer credential. Two flavours share this table.
|
|
808
|
+
|
|
809
|
+
* **Agent keys** — issued at enrollment, scoped to a ``connection``. The
|
|
810
|
+
agent sends ``connection_id`` in the request body, so the row is found
|
|
811
|
+
before the hash is ever checked and no lookup column is needed. These
|
|
812
|
+
rows have ``prefix=None``.
|
|
813
|
+
* **Admin API tokens** — issued from Management, scoped to a ``user``, and
|
|
814
|
+
presented as ``Authorization: ApiKey lsui_<prefix>_<secret>``. Here the
|
|
815
|
+
header is the *only* identifier, so ``prefix`` is stored unhashed and
|
|
816
|
+
indexed; without it, resolving a token would mean a PBKDF2 comparison
|
|
817
|
+
against every row in the table on every request.
|
|
818
|
+
|
|
819
|
+
Exactly one of ``connection`` / ``user`` is set.
|
|
820
|
+
"""
|
|
821
|
+
connection = models.ForeignKey(
|
|
822
|
+
Connection,
|
|
823
|
+
on_delete=models.CASCADE,
|
|
824
|
+
related_name='api_keys',
|
|
825
|
+
null=True,
|
|
826
|
+
blank=True,
|
|
827
|
+
help_text="Connection this API key belongs to (agent keys only)"
|
|
828
|
+
)
|
|
829
|
+
user = models.ForeignKey(
|
|
830
|
+
settings.AUTH_USER_MODEL,
|
|
831
|
+
on_delete=models.CASCADE,
|
|
832
|
+
related_name='api_tokens',
|
|
833
|
+
null=True,
|
|
834
|
+
blank=True,
|
|
835
|
+
help_text="User this API token acts as (admin tokens only)"
|
|
836
|
+
)
|
|
837
|
+
name = models.CharField(
|
|
838
|
+
max_length=100,
|
|
839
|
+
blank=True,
|
|
840
|
+
default='',
|
|
841
|
+
help_text="Human-readable label for this token"
|
|
842
|
+
)
|
|
843
|
+
prefix = models.CharField(
|
|
844
|
+
max_length=12,
|
|
845
|
+
null=True,
|
|
846
|
+
blank=True,
|
|
847
|
+
unique=True,
|
|
848
|
+
db_index=True,
|
|
849
|
+
help_text="Unhashed lookup key for admin tokens; null for agent keys"
|
|
850
|
+
)
|
|
851
|
+
api_key = models.CharField(
|
|
852
|
+
max_length=512,
|
|
853
|
+
help_text="Hashed API key for agent authentication"
|
|
854
|
+
)
|
|
855
|
+
created_at = models.DateTimeField(null=True, blank=True, auto_now_add=True)
|
|
856
|
+
last_used_at = models.DateTimeField(null=True, blank=True)
|
|
857
|
+
revoked_at = models.DateTimeField(null=True, blank=True)
|
|
858
|
+
expires_at = models.DateTimeField(null=True, blank=True)
|
|
859
|
+
|
|
860
|
+
class Meta:
|
|
861
|
+
verbose_name = 'API Key'
|
|
862
|
+
verbose_name_plural = 'API Keys'
|
|
863
|
+
|
|
864
|
+
def __str__(self):
|
|
865
|
+
if self.connection_id:
|
|
866
|
+
return f"{self.connection.name} - API Key"
|
|
867
|
+
return f"{self.name or 'unnamed'} - API Token"
|
|
868
|
+
|
|
869
|
+
def clean(self):
|
|
870
|
+
"""Require exactly one of ``connection`` or ``user``.
|
|
871
|
+
|
|
872
|
+
Not a DB CheckConstraint: constraint enforcement is uneven across the
|
|
873
|
+
MySQL 8.0 floor, and this is only ever violated by our own code.
|
|
874
|
+
"""
|
|
875
|
+
if bool(self.connection_id) == bool(self.user_id):
|
|
876
|
+
raise ValidationError(
|
|
877
|
+
"An ApiKey must belong to exactly one of connection or user."
|
|
878
|
+
)
|
|
879
|
+
|
|
880
|
+
def save(self, *args, **kwargs):
|
|
881
|
+
"""Persist the key, hashing ``api_key`` only when it is still plaintext.
|
|
882
|
+
|
|
883
|
+
Renaming or revoking re-saves the row. Re-running ``make_password`` on a
|
|
884
|
+
stored hash would silently invalidate the credential, so hashing is
|
|
885
|
+
guarded by ``_is_hashed``.
|
|
886
|
+
"""
|
|
887
|
+
if self.api_key and not self._is_hashed(self.api_key):
|
|
888
|
+
self.api_key = (
|
|
889
|
+
self._key_digest(self.api_key)
|
|
890
|
+
if bool(self.connection_id) != bool(self.user_id)
|
|
891
|
+
else make_password(self.api_key)
|
|
892
|
+
)
|
|
893
|
+
super().save(*args, **kwargs)
|
|
894
|
+
|
|
895
|
+
@staticmethod
|
|
896
|
+
def _is_hashed(value):
|
|
897
|
+
if re.fullmatch(r'(agent|api)_sha256\$[0-9a-f]{64}', value):
|
|
898
|
+
return True
|
|
899
|
+
try:
|
|
900
|
+
identify_hasher(value)
|
|
901
|
+
except ValueError:
|
|
902
|
+
return False
|
|
903
|
+
return True
|
|
904
|
+
|
|
905
|
+
def _key_digest(self, raw_api_key):
|
|
906
|
+
"""Hash a generated secret using its owner-specific storage prefix."""
|
|
907
|
+
# Agent enrollment and API token issuance generate 256-bit secrets.
|
|
908
|
+
# A fast digest avoids blocking gevent on PBKDF2 for every request.
|
|
909
|
+
prefix = 'agent_sha256$' if self.connection_id else 'api_sha256$'
|
|
910
|
+
return prefix + hashlib.sha256(raw_api_key.encode('utf-8')).hexdigest()
|
|
911
|
+
|
|
912
|
+
def verify_api_key(self, raw_api_key):
|
|
913
|
+
"""Verify a generated key, upgrading legacy hashes after successful auth.
|
|
914
|
+
|
|
915
|
+
Args:
|
|
916
|
+
raw_api_key: Plaintext secret from the ``Authorization`` header.
|
|
917
|
+
"""
|
|
918
|
+
if not isinstance(raw_api_key, str) or not raw_api_key:
|
|
919
|
+
return False
|
|
920
|
+
has_owner = bool(self.connection_id) != bool(self.user_id)
|
|
921
|
+
if self.api_key.startswith(('agent_sha256$', 'api_sha256$')):
|
|
922
|
+
return has_owner and secrets.compare_digest(
|
|
923
|
+
self._key_digest(raw_api_key), self.api_key
|
|
924
|
+
)
|
|
925
|
+
valid = check_password(raw_api_key, self.api_key)
|
|
926
|
+
if valid and has_owner and self.pk:
|
|
927
|
+
digest = self._key_digest(raw_api_key)
|
|
928
|
+
# Do not overwrite a key rotated while verification was in flight.
|
|
929
|
+
updated = type(self).objects.filter(pk=self.pk, api_key=self.api_key).update(
|
|
930
|
+
api_key=digest
|
|
931
|
+
)
|
|
932
|
+
if updated:
|
|
933
|
+
self.api_key = digest
|
|
934
|
+
return valid
|
|
935
|
+
|
|
936
|
+
# -- admin API tokens ---------------------------------------------------
|
|
937
|
+
|
|
938
|
+
@classmethod
|
|
939
|
+
def issue_for_user(cls, user, name='', expires_at=None):
|
|
940
|
+
"""Mint an admin API token.
|
|
941
|
+
|
|
942
|
+
The raw token is the only time the secret exists in plaintext — it is
|
|
943
|
+
not recoverable afterwards. The prefix is ``token_hex`` (no ``_``) so
|
|
944
|
+
``split('_', 2)`` on the wire format is unambiguous.
|
|
945
|
+
|
|
946
|
+
Args:
|
|
947
|
+
user: Owner the token will act as.
|
|
948
|
+
name: Human-readable label.
|
|
949
|
+
expires_at: Optional expiry; ``None`` means no expiry.
|
|
950
|
+
|
|
951
|
+
Returns:
|
|
952
|
+
``(instance, raw_token)`` where ``raw_token`` is
|
|
953
|
+
``lsui_<prefix>_<secret>``.
|
|
954
|
+
"""
|
|
955
|
+
# token_hex, not token_urlsafe: the prefix must contain no '_' so that
|
|
956
|
+
# split('_', 2) on the wire format is unambiguous.
|
|
957
|
+
prefix = secrets.token_hex(6)
|
|
958
|
+
secret = secrets.token_urlsafe(32)
|
|
959
|
+
token = cls(
|
|
960
|
+
user=user,
|
|
961
|
+
name=name,
|
|
962
|
+
prefix=prefix,
|
|
963
|
+
api_key=secret,
|
|
964
|
+
expires_at=expires_at,
|
|
965
|
+
)
|
|
966
|
+
token.full_clean(exclude=['api_key'], validate_unique=False)
|
|
967
|
+
token.save()
|
|
968
|
+
return token, f"{API_TOKEN_SCHEME}_{prefix}_{secret}"
|
|
969
|
+
|
|
970
|
+
@staticmethod
|
|
971
|
+
def parse_token(raw):
|
|
972
|
+
"""Split a wire-format token into ``(prefix, secret)``.
|
|
973
|
+
|
|
974
|
+
Returns ``(None, None)`` for anything that is not an admin token,
|
|
975
|
+
including agent keys, which carry no scheme marker.
|
|
976
|
+
|
|
977
|
+
Args:
|
|
978
|
+
raw: Header value after the ``ApiKey `` scheme, or the full token.
|
|
979
|
+
|
|
980
|
+
Returns:
|
|
981
|
+
``(prefix, secret)`` for ``lsui_<prefix>_<secret>``;
|
|
982
|
+
``(None, None)`` otherwise.
|
|
983
|
+
"""
|
|
984
|
+
parts = (raw or '').split('_', 2)
|
|
985
|
+
if len(parts) != 3 or parts[0] != API_TOKEN_SCHEME:
|
|
986
|
+
return None, None
|
|
987
|
+
if not parts[1] or not parts[2]:
|
|
988
|
+
return None, None
|
|
989
|
+
return parts[1], parts[2]
|
|
990
|
+
|
|
991
|
+
@property
|
|
992
|
+
def masked(self):
|
|
993
|
+
"""Return the display form for the token list — prefix only, never the secret."""
|
|
994
|
+
return f"{API_TOKEN_SCHEME}_{self.prefix}_…" if self.prefix else ''
|
|
995
|
+
|
|
996
|
+
@property
|
|
997
|
+
def is_expired(self):
|
|
998
|
+
"""True when ``expires_at`` is set and in the past."""
|
|
999
|
+
return self.expires_at is not None and self.expires_at <= timezone.now()
|
|
1000
|
+
|
|
1001
|
+
@property
|
|
1002
|
+
def is_active(self):
|
|
1003
|
+
"""True when the token is neither revoked nor expired."""
|
|
1004
|
+
return self.revoked_at is None and not self.is_expired
|
|
1005
|
+
|
|
1006
|
+
|
|
1007
|
+
#: Release tarballs LogstashUI is willing to cache and serve. Anchored, and with
|
|
1008
|
+
#: no path separators in any branch, so a filename that matches can never escape
|
|
1009
|
+
#: the cache directory.
|
|
1010
|
+
ARTIFACT_FILENAME_RE = re.compile(
|
|
1011
|
+
r'^logstash-(?P<version>[0-9][0-9A-Za-z.+-]{0,31})'
|
|
1012
|
+
r'-(?P<platform>linux|darwin|windows)'
|
|
1013
|
+
r'-(?P<arch>x86_64|aarch64)'
|
|
1014
|
+
r'\.tar\.gz(?P<checksum>\.sha512)?$'
|
|
1015
|
+
)
|
|
1016
|
+
|
|
1017
|
+
#: Checksum sidecars are a few dozen bytes. Serving one must not consume a slot
|
|
1018
|
+
#: in the download semaphore, or a burst of them starves real transfers.
|
|
1019
|
+
SMALL_FILE_BYTES = 1024 * 1024
|
|
1020
|
+
|
|
1021
|
+
|
|
1022
|
+
def parse_artifact_filename(filename):
|
|
1023
|
+
"""Validate a requested artifact filename against ``ARTIFACT_FILENAME_RE``.
|
|
1024
|
+
|
|
1025
|
+
Args:
|
|
1026
|
+
filename: Requested ``.tar.gz`` or ``.tar.gz.sha512`` basename.
|
|
1027
|
+
|
|
1028
|
+
Returns:
|
|
1029
|
+
``(tarball_name, version, arch, is_checksum)``, where ``tarball_name``
|
|
1030
|
+
is the ``.tar.gz`` even when the checksum sidecar was requested — both
|
|
1031
|
+
files belong to one ``LogstashArtifact`` row and one upstream fetch.
|
|
1032
|
+
``None`` for anything unrecognized, which callers answer with 404.
|
|
1033
|
+
"""
|
|
1034
|
+
match = ARTIFACT_FILENAME_RE.match(filename or '')
|
|
1035
|
+
if match is None:
|
|
1036
|
+
return None
|
|
1037
|
+
is_checksum = bool(match.group('checksum'))
|
|
1038
|
+
tarball = filename[:-len('.sha512')] if is_checksum else filename
|
|
1039
|
+
arch = f"{match.group('platform')}-{match.group('arch')}"
|
|
1040
|
+
return tarball, match.group('version'), arch, is_checksum
|
|
1041
|
+
|
|
1042
|
+
|
|
1043
|
+
class LogstashArtifact(models.Model):
|
|
1044
|
+
"""A Logstash release tarball cached locally and served to agents.
|
|
1045
|
+
|
|
1046
|
+
One row covers the ``.tar.gz`` and its ``.sha512`` sidecar; a request for
|
|
1047
|
+
either resolves here and a single fetch pulls both.
|
|
1048
|
+
|
|
1049
|
+
The status field doubles as the cross-process lock. LogstashUI has no shared
|
|
1050
|
+
cache backend (no ``CACHES`` in settings, so Django falls back to per-process
|
|
1051
|
+
LocMemCache), and gunicorn runs 2+ worker processes, so an in-memory lock
|
|
1052
|
+
cannot prevent two workers starting the same 450 MB download. A conditional
|
|
1053
|
+
UPDATE on this row can — see ``claim_for_fetch()``.
|
|
1054
|
+
"""
|
|
1055
|
+
|
|
1056
|
+
class Status(models.TextChoices):
|
|
1057
|
+
PENDING = 'PENDING', 'Pending'
|
|
1058
|
+
FETCHING = 'FETCHING', 'Downloading'
|
|
1059
|
+
READY = 'READY', 'Ready'
|
|
1060
|
+
FAILED = 'FAILED', 'Failed'
|
|
1061
|
+
IMPORTING = 'IMPORTING', 'Verifying import'
|
|
1062
|
+
|
|
1063
|
+
#: A claim whose heartbeat is older than this is assumed dead and may be
|
|
1064
|
+
#: taken over. Fetch greenlets die with their gunicorn worker, so on any
|
|
1065
|
+
#: restart mid-download this is the recovery path, not an edge case.
|
|
1066
|
+
STALE_CLAIM_SECONDS = 120
|
|
1067
|
+
|
|
1068
|
+
filename = models.CharField(
|
|
1069
|
+
max_length=255,
|
|
1070
|
+
unique=True,
|
|
1071
|
+
help_text="Tarball filename, e.g. logstash-9.4.3-linux-x86_64.tar.gz"
|
|
1072
|
+
)
|
|
1073
|
+
version = models.CharField(
|
|
1074
|
+
max_length=32,
|
|
1075
|
+
db_index=True,
|
|
1076
|
+
help_text="Logstash version, e.g. 9.4.3"
|
|
1077
|
+
)
|
|
1078
|
+
arch = models.CharField(
|
|
1079
|
+
max_length=32,
|
|
1080
|
+
help_text="Platform and architecture, e.g. linux-x86_64"
|
|
1081
|
+
)
|
|
1082
|
+
source_url = models.CharField(
|
|
1083
|
+
max_length=512,
|
|
1084
|
+
blank=True,
|
|
1085
|
+
default="",
|
|
1086
|
+
help_text="Explicit upstream URL. Blank derives one from the base URL setting."
|
|
1087
|
+
)
|
|
1088
|
+
status = models.CharField(
|
|
1089
|
+
max_length=16,
|
|
1090
|
+
choices=Status.choices,
|
|
1091
|
+
default=Status.PENDING,
|
|
1092
|
+
db_index=True,
|
|
1093
|
+
)
|
|
1094
|
+
size_bytes = models.BigIntegerField(
|
|
1095
|
+
null=True,
|
|
1096
|
+
blank=True,
|
|
1097
|
+
help_text="Total size, from the upstream Content-Length or the file on disk"
|
|
1098
|
+
)
|
|
1099
|
+
bytes_downloaded = models.BigIntegerField(
|
|
1100
|
+
default=0,
|
|
1101
|
+
help_text="Progress counter, written on a time floor rather than per chunk"
|
|
1102
|
+
)
|
|
1103
|
+
sha512 = models.CharField(
|
|
1104
|
+
max_length=128,
|
|
1105
|
+
blank=True,
|
|
1106
|
+
default="",
|
|
1107
|
+
help_text="Verified SHA-512 of the published tarball"
|
|
1108
|
+
)
|
|
1109
|
+
error = models.TextField(
|
|
1110
|
+
blank=True,
|
|
1111
|
+
default="",
|
|
1112
|
+
help_text="Why the last fetch failed"
|
|
1113
|
+
)
|
|
1114
|
+
claimed_at = models.DateTimeField(null=True, blank=True)
|
|
1115
|
+
heartbeat_at = models.DateTimeField(null=True, blank=True)
|
|
1116
|
+
serve_count = models.PositiveIntegerField(
|
|
1117
|
+
default=0,
|
|
1118
|
+
help_text=(
|
|
1119
|
+
"Fresh tarball downloads by agents. Checksum fetches and resumed "
|
|
1120
|
+
"range requests hit the same row but are not counted"
|
|
1121
|
+
)
|
|
1122
|
+
)
|
|
1123
|
+
last_served_at = models.DateTimeField(
|
|
1124
|
+
null=True,
|
|
1125
|
+
blank=True,
|
|
1126
|
+
help_text="When the tarball was last downloaded in full"
|
|
1127
|
+
)
|
|
1128
|
+
created_at = models.DateTimeField(auto_now_add=True)
|
|
1129
|
+
updated_at = models.DateTimeField(auto_now=True)
|
|
1130
|
+
|
|
1131
|
+
class Meta:
|
|
1132
|
+
db_table = 'logstash_artifact'
|
|
1133
|
+
ordering = ['-created_at']
|
|
1134
|
+
|
|
1135
|
+
def __str__(self):
|
|
1136
|
+
return f"{self.filename} ({self.status})"
|
|
1137
|
+
|
|
1138
|
+
@property
|
|
1139
|
+
def checksum_filename(self):
|
|
1140
|
+
"""Return the ``.sha512`` sidecar basename for this tarball."""
|
|
1141
|
+
return f"{self.filename}.sha512"
|
|
1142
|
+
|
|
1143
|
+
@property
|
|
1144
|
+
def percent(self):
|
|
1145
|
+
"""Whole-percent progress, or None when the total is not yet known."""
|
|
1146
|
+
if not self.size_bytes:
|
|
1147
|
+
return None
|
|
1148
|
+
return min(100, int(self.bytes_downloaded * 100 / self.size_bytes))
|
|
1149
|
+
|
|
1150
|
+
def resolve_source_url(self, base_url):
|
|
1151
|
+
"""Return the upstream URL for the tarball.
|
|
1152
|
+
|
|
1153
|
+
An explicit ``source_url`` wins over ``base_url`` + filename.
|
|
1154
|
+
|
|
1155
|
+
Args:
|
|
1156
|
+
base_url: Operator-configured artifact host (or Elastic default).
|
|
1157
|
+
"""
|
|
1158
|
+
if self.source_url:
|
|
1159
|
+
return self.source_url
|
|
1160
|
+
return f"{base_url.rstrip('/')}/{self.filename}"
|
|
1161
|
+
|
|
1162
|
+
@classmethod
|
|
1163
|
+
def claim_for_fetch(cls, pk, *, now=None):
|
|
1164
|
+
"""Atomically take ownership of a download.
|
|
1165
|
+
|
|
1166
|
+
A single conditional UPDATE is the whole mechanism. It is race-free on
|
|
1167
|
+
every supported engine: PostgreSQL re-evaluates the WHERE clause after
|
|
1168
|
+
taking the row lock, InnoDB does a current read so the loser sees the
|
|
1169
|
+
winner's committed FETCHING, and SQLite has one global writer. Exactly
|
|
1170
|
+
one caller comes back with a rowcount of 1.
|
|
1171
|
+
|
|
1172
|
+
A FETCHING row whose heartbeat has gone stale is also claimable, which
|
|
1173
|
+
is how a download orphaned by a worker restart gets picked back up.
|
|
1174
|
+
|
|
1175
|
+
Args:
|
|
1176
|
+
pk: ``LogstashArtifact`` primary key.
|
|
1177
|
+
now: Claim timestamp; defaults to ``timezone.now()``.
|
|
1178
|
+
|
|
1179
|
+
Returns:
|
|
1180
|
+
True if this caller won the claim.
|
|
1181
|
+
"""
|
|
1182
|
+
now = now or timezone.now()
|
|
1183
|
+
stale_before = now - timedelta(seconds=cls.STALE_CLAIM_SECONDS)
|
|
1184
|
+
updated = cls.objects.filter(pk=pk).filter(
|
|
1185
|
+
models.Q(status__in=[cls.Status.PENDING, cls.Status.FAILED])
|
|
1186
|
+
| models.Q(status=cls.Status.FETCHING, heartbeat_at__lt=stale_before)
|
|
1187
|
+
| models.Q(status=cls.Status.FETCHING, heartbeat_at__isnull=True)
|
|
1188
|
+
).update(
|
|
1189
|
+
status=cls.Status.FETCHING,
|
|
1190
|
+
claimed_at=now,
|
|
1191
|
+
heartbeat_at=now,
|
|
1192
|
+
bytes_downloaded=0,
|
|
1193
|
+
error='',
|
|
1194
|
+
)
|
|
1195
|
+
return updated == 1
|
|
1196
|
+
|
|
1197
|
+
@classmethod
|
|
1198
|
+
def release_claim(cls, pk):
|
|
1199
|
+
"""Hand a claim back without failing it, for the over-capacity path.
|
|
1200
|
+
|
|
1201
|
+
Args:
|
|
1202
|
+
pk: ``LogstashArtifact`` primary key.
|
|
1203
|
+
|
|
1204
|
+
Returns:
|
|
1205
|
+
Number of rows updated (0 or 1).
|
|
1206
|
+
"""
|
|
1207
|
+
return cls.objects.filter(pk=pk, status=cls.Status.FETCHING).update(
|
|
1208
|
+
status=cls.Status.PENDING,
|
|
1209
|
+
claimed_at=None,
|
|
1210
|
+
heartbeat_at=None,
|
|
1211
|
+
)
|
|
1212
|
+
|
|
1213
|
+
@classmethod
|
|
1214
|
+
def active_fetch_count(cls, *, now=None):
|
|
1215
|
+
"""Count fetches genuinely in flight, ignoring rows abandoned by dead workers.
|
|
1216
|
+
|
|
1217
|
+
Args:
|
|
1218
|
+
now: Clock for the stale-heartbeat cutoff; defaults to ``timezone.now()``.
|
|
1219
|
+
"""
|
|
1220
|
+
now = now or timezone.now()
|
|
1221
|
+
stale_before = now - timedelta(seconds=cls.STALE_CLAIM_SECONDS)
|
|
1222
|
+
return cls.objects.filter(
|
|
1223
|
+
status=cls.Status.FETCHING,
|
|
1224
|
+
heartbeat_at__gte=stale_before,
|
|
1225
|
+
).count()
|
|
1226
|
+
|
|
1227
|
+
|
|
1228
|
+
class SimulationResult(models.Model):
|
|
1229
|
+
"""One event a simulation pipeline posted back, waiting to be read.
|
|
1230
|
+
|
|
1231
|
+
The simulate agent posts results to whichever gunicorn worker takes the
|
|
1232
|
+
request, and the reader (the editor's poll or a synchronous API call) may
|
|
1233
|
+
be on another worker. The database is the only state they share, so
|
|
1234
|
+
results are queued here rather than in process memory. Rows are deleted
|
|
1235
|
+
when read, and unread rows are pruned after ``MAX_AGE_SECONDS``.
|
|
1236
|
+
|
|
1237
|
+
Examples:
|
|
1238
|
+
>>> SimulationResult.add({'run_id': 'r1', 'message': 'hi'})
|
|
1239
|
+
True
|
|
1240
|
+
>>> SimulationResult.take(['r1'])
|
|
1241
|
+
{'r1': [{'run_id': 'r1', 'message': 'hi'}]}
|
|
1242
|
+
"""
|
|
1243
|
+
|
|
1244
|
+
#: Unread results older than this are dropped; no reader waits this long.
|
|
1245
|
+
MAX_AGE_SECONDS = 600
|
|
1246
|
+
#: Results queued per run beyond this are refused.
|
|
1247
|
+
MAX_PER_RUN = 1000
|
|
1248
|
+
|
|
1249
|
+
run_id = models.CharField(max_length=64, db_index=True)
|
|
1250
|
+
payload = models.JSONField()
|
|
1251
|
+
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
|
|
1252
|
+
|
|
1253
|
+
class Meta:
|
|
1254
|
+
db_table = 'simulation_result'
|
|
1255
|
+
ordering = ['id']
|
|
1256
|
+
|
|
1257
|
+
def __str__(self):
|
|
1258
|
+
return f"{self.run_id} #{self.pk}"
|
|
1259
|
+
|
|
1260
|
+
@classmethod
|
|
1261
|
+
def add(cls, event):
|
|
1262
|
+
"""Queue one posted event and prune results nobody read.
|
|
1263
|
+
|
|
1264
|
+
Args:
|
|
1265
|
+
event: Decoded event JSON; ``run_id`` identifies its run.
|
|
1266
|
+
|
|
1267
|
+
Returns:
|
|
1268
|
+
bool: False when the run already has ``MAX_PER_RUN`` queued results
|
|
1269
|
+
and the event was not stored.
|
|
1270
|
+
"""
|
|
1271
|
+
run_id = str(event.get('run_id') or '')[:64]
|
|
1272
|
+
if cls.objects.filter(run_id=run_id).count() >= cls.MAX_PER_RUN:
|
|
1273
|
+
return False
|
|
1274
|
+
cls.objects.create(run_id=run_id, payload=event)
|
|
1275
|
+
cutoff = timezone.now() - timedelta(seconds=cls.MAX_AGE_SECONDS)
|
|
1276
|
+
cls.objects.filter(created_at__lt=cutoff).delete()
|
|
1277
|
+
return True
|
|
1278
|
+
|
|
1279
|
+
@classmethod
|
|
1280
|
+
def take(cls, run_ids):
|
|
1281
|
+
"""Remove and return queued results for ``run_ids``, oldest first.
|
|
1282
|
+
|
|
1283
|
+
Args:
|
|
1284
|
+
run_ids: Run identifiers to collect.
|
|
1285
|
+
|
|
1286
|
+
Returns:
|
|
1287
|
+
dict: ``{run_id: [event, ...]}`` for every requested run id.
|
|
1288
|
+
"""
|
|
1289
|
+
collected = {run_id: [] for run_id in run_ids}
|
|
1290
|
+
with transaction.atomic():
|
|
1291
|
+
rows = list(
|
|
1292
|
+
cls.objects.select_for_update()
|
|
1293
|
+
.filter(run_id__in=list(collected))
|
|
1294
|
+
.values_list('id', 'run_id', 'payload')
|
|
1295
|
+
)
|
|
1296
|
+
if rows:
|
|
1297
|
+
cls.objects.filter(id__in=[row[0] for row in rows]).delete()
|
|
1298
|
+
for _id, run_id, payload in rows:
|
|
1299
|
+
collected[run_id].append(payload)
|
|
1300
|
+
return collected
|