mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2025-12-09 18:52:52 +01:00
Refactor for Elastic Upgrade
This commit is contained in:
@@ -1,5 +1,3 @@
|
|||||||
{% from 'vars/globals.map.jinja' import GLOBALS %}
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"package": {
|
"package": {
|
||||||
"name": "fleet_server",
|
"name": "fleet_server",
|
||||||
@@ -7,7 +5,7 @@
|
|||||||
},
|
},
|
||||||
"name": "fleet_server-1",
|
"name": "fleet_server-1",
|
||||||
"namespace": "default",
|
"namespace": "default",
|
||||||
"policy_id": "FleetServer_{{ GLOBALS.hostname }}",
|
"policy_id": "FleetServer_hostname",
|
||||||
"vars": {},
|
"vars": {},
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"fleet_server-fleet-server": {
|
"fleet_server-fleet-server": {
|
||||||
|
|||||||
@@ -6,18 +6,24 @@
|
|||||||
|
|
||||||
. /usr/sbin/so-elastic-fleet-common
|
. /usr/sbin/so-elastic-fleet-common
|
||||||
|
|
||||||
# Make the curl request to fetch the JSON data
|
# Get all the fleet policies
|
||||||
json_output=$(curl -s -K /opt/so/conf/elasticsearch/curl.config -L -X GET "localhost:5601/api/fleet/agent_policies" -H 'kbn-xsrf: true')
|
json_output=$(curl -s -K /opt/so/conf/elasticsearch/curl.config -L -X GET "localhost:5601/api/fleet/agent_policies" -H 'kbn-xsrf: true')
|
||||||
|
|
||||||
# Extract the IDs that start with "FleetServer_" using jq
|
# Extract the IDs that start with "FleetServer_"
|
||||||
POLICY=$(echo "$json_output" | jq -r '.items[] | select(.id | startswith("FleetServer_")) | .id')
|
POLICY=$(echo "$json_output" | jq -r '.items[] | select(.id | startswith("FleetServer_")) | .id')
|
||||||
|
|
||||||
echo $POLICY
|
# Iterate over each ID in the POLICY variable
|
||||||
|
|
||||||
# Iterate over each ID in the POLICY variable and run the specified commands
|
|
||||||
for POLICYNAME in $POLICY; do
|
for POLICYNAME in $POLICY; do
|
||||||
|
printf "\nUpdating Policy: $POLICYNAME\n"
|
||||||
|
|
||||||
# First get the Integration ID
|
# First get the Integration ID
|
||||||
elastic_fleet_integration_check "$POLICYNAME" "/opt/so/conf/elastic-fleet/integrations/fleet-server/fleet-server.json"
|
elastic_fleet_integration_check "$POLICYNAME" "/opt/so/conf/elastic-fleet/integrations/fleet-server/fleet-server.json"
|
||||||
# Now update the integration policy
|
|
||||||
elastic_fleet_integration_update "$INTEGRATION_ID" "@/opt/so/conf/elastic-fleet/integrations/fleet-server/fleet-server.json"
|
# Modify the default integration policy to update the policy_id and an with the correct naming
|
||||||
|
UPDATED_INTEGRATION_POLICY=$(jq --arg policy_id "$POLICYNAME" --arg name "fleet_server-$POLICYNAME" '
|
||||||
|
.policy_id = $policy_id |
|
||||||
|
.name = $name' /opt/so/conf/elastic-fleet/integrations/fleet-server/fleet-server.json)
|
||||||
|
|
||||||
|
# Now update the integration policy using the modified JSON
|
||||||
|
elastic_fleet_integration_update "$INTEGRATION_ID" "$UPDATED_INTEGRATION_POLICY"
|
||||||
done
|
done
|
||||||
@@ -9,6 +9,10 @@ if [ -f /usr/sbin/so-common ]; then
|
|||||||
. /usr/sbin/so-common
|
. /usr/sbin/so-common
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -f /usr/sbin/so-elastic-fleet-common ]; then
|
||||||
|
. /usr/sbin/so-elastic-fleet-common
|
||||||
|
fi
|
||||||
|
|
||||||
function usage() {
|
function usage() {
|
||||||
echo "Usage: $0 -o=<operation> -m=[id]"
|
echo "Usage: $0 -o=<operation> -m=[id]"
|
||||||
echo ""
|
echo ""
|
||||||
@@ -380,23 +384,31 @@ function add_elastic_fleet_package_registry_to_minion() {
|
|||||||
|
|
||||||
function create_fleet_policy() {
|
function create_fleet_policy() {
|
||||||
|
|
||||||
JSON_STRING=$( jq -n \
|
# First, set the default output to Elasticsearch
|
||||||
--arg NAME "FleetServer_$LSHOSTNAME" \
|
# This is required because of the license output bug
|
||||||
--arg DESC "Fleet Server - $LSHOSTNAME" \
|
JSON_STRING=$(jq -n \
|
||||||
'{"name": $NAME,"id":$NAME,"description":$DESC,"namespace":"default","monitoring_enabled":["logs"],"inactivity_timeout":1209600,"has_fleet_server":true}'
|
'{
|
||||||
)
|
"name": "so-manager_elasticsearch",
|
||||||
|
"type": "elasticsearch",
|
||||||
|
"is_default": true,
|
||||||
|
"is_default_monitoring": false
|
||||||
|
}')
|
||||||
|
|
||||||
# Create Fleet Sever Policy
|
curl -K /opt/so/conf/elasticsearch/curl.config -L -X PUT "localhost:5601/api/fleet/outputs/so-manager_elasticsearch" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d "$JSON_STRING"
|
||||||
curl -K /opt/so/conf/elasticsearch/curl.config -L -X POST "localhost:5601/api/fleet/agent_policies" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d "$JSON_STRING"
|
|
||||||
|
|
||||||
JSON_STRING_UPDATE=$( jq -n \
|
# Create the Fleet Server Policy
|
||||||
--arg NAME "FleetServer_$LSHOSTNAME" \
|
elastic_fleet_policy_create "FleetServer_$LSHOSTNAME" "Fleet Server - $LSHOSTNAME" "false" "120"
|
||||||
--arg DESC "Fleet Server - $LSHOSTNAME" \
|
|
||||||
'{"name":$NAME,"description":$DESC,"namespace":"default","monitoring_enabled":["logs"],"inactivity_timeout":120,"data_output_id":"so-manager_elasticsearch"}'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Update Fleet Policy - ES Output
|
# Modify the default integration policy to update the policy_id with the correct naming
|
||||||
curl -K /opt/so/conf/elasticsearch/curl.config -L -X PUT "localhost:5601/api/fleet/agent_policies/FleetServer_$LSHOSTNAME" -H 'kbn-xsrf: true' -H 'Content-Type: application/json' -d "$JSON_STRING_UPDATE"
|
UPDATED_INTEGRATION_POLICY=$(jq --arg policy_id "FleetServer_$LSHOSTNAME" --arg name "fleet_server-$LSHOSTNAME" '
|
||||||
|
.policy_id = $policy_id |
|
||||||
|
.name = $name' /opt/so/conf/elastic-fleet/integrations/fleet-server/fleet-server.json)
|
||||||
|
|
||||||
|
# Add the Fleet Server Integration to the new Fleet Policy
|
||||||
|
elastic_fleet_integration_create "$UPDATED_INTEGRATION_POLICY"
|
||||||
|
|
||||||
|
# Set the default output back to the default
|
||||||
|
/sbin/so-elastic-fleet-outputs-update
|
||||||
}
|
}
|
||||||
|
|
||||||
function update_fleet_host_urls() {
|
function update_fleet_host_urls() {
|
||||||
|
|||||||
Reference in New Issue
Block a user