mirror of
https://github.com/Security-Onion-Solutions/securityonion.git
synced 2026-11-18 18:16:02 +01:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ae394ce709 |
No files matched your search
@@ -18,7 +18,6 @@ INSTALLEDVERSION=$(cat /etc/soversion)
|
||||
# here before preupgrade_changes mutates INSTALLEDVERSION and before any highstate
|
||||
# stamps /etc/soversion from the pillar.
|
||||
POSTVERSION_FILE=/etc/sopostversion
|
||||
|
||||
if [ -f "$POSTVERSION_FILE" ]; then
|
||||
POSTVERSION=$(cat "$POSTVERSION_FILE")
|
||||
else
|
||||
@@ -55,7 +54,6 @@ fi
|
||||
# used to display messages to the user at the end of soup
|
||||
declare -a FINAL_MESSAGE_QUEUE=()
|
||||
SOUP_ERR_CONTEXT=
|
||||
TELEGRAF_REPAIR_RAN=
|
||||
|
||||
|
||||
check_err() {
|
||||
@@ -1064,17 +1062,6 @@ up_to_3.3.0() {
|
||||
}
|
||||
|
||||
telegraf_repair() {
|
||||
# post_to_3.3.0 and post_to_3.5.0 both call this; run it once per soup.
|
||||
[[ -n "$TELEGRAF_REPAIR_RAN" ]] && return 0
|
||||
TELEGRAF_REPAIR_RAN=true
|
||||
local output
|
||||
output=$(salt-call pillar.get telegraf:output --out=newline_values_only)
|
||||
output=$(tr -d '[:space:]' <<<"$output" | tr '[:lower:]' '[:upper:]')
|
||||
output=${output:-INFLUXDB}
|
||||
case "$output" in
|
||||
POSTGRES|BOTH) ;;
|
||||
*) return 0 ;;
|
||||
esac
|
||||
# Only grids whose Telegraf partitions stalled need this; --check exits 1
|
||||
# when there is something to repair, so everyone else is left alone.
|
||||
local repair=/usr/sbin/so-telegraf-repair
|
||||
|
||||
@@ -60,13 +60,9 @@ if ! docker exec so-postgres psql -U postgres -lqt 2>/dev/null | cut -d\| -f1 |
|
||||
exit 2
|
||||
fi
|
||||
|
||||
role_ok=$(docker exec so-postgres psql -U postgres -tAc "SELECT rolcanlogin AND NOT (rolsuper OR rolcreatedb OR rolcreaterole OR rolreplication OR rolbypassrls) FROM pg_roles WHERE rolname = 'so_maint_telegraf'" 2>/dev/null)
|
||||
if [ -z "$role_ok" ]; then
|
||||
if ! docker exec so-postgres psql -U postgres -tAc "SELECT 1 FROM pg_roles WHERE rolname = 'so_maint_telegraf'" 2>/dev/null | grep -q 1; then
|
||||
echo "The so_maint_telegraf role is missing; run a highstate."
|
||||
exit 1
|
||||
elif [ "$role_ok" != t ]; then
|
||||
echo "The so_maint_telegraf role is misconfigured; run a highstate."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
table_exists() {
|
||||
|
||||
@@ -100,13 +100,12 @@ DECLARE
|
||||
r record;
|
||||
BEGIN
|
||||
FOR r IN
|
||||
SELECT c.oid::regclass AS pt
|
||||
SELECT to_regclass(pc.parent_table) AS pt
|
||||
FROM partman.part_config pc
|
||||
JOIN pg_catalog.pg_class c ON c.oid = to_regclass(pc.parent_table)
|
||||
WHERE pc.parent_table LIKE 'telegraf.%'
|
||||
AND c.relkind = 'p'
|
||||
ORDER BY pc.parent_table
|
||||
LOOP
|
||||
CONTINUE WHEN r.pt IS NULL;
|
||||
parent_table := r.pt;
|
||||
|
||||
SELECT c.oid::regclass INTO default_part
|
||||
@@ -161,7 +160,8 @@ BEGIN
|
||||
-- Bounded so a large backlog drains across several runs.
|
||||
CALL partman.partition_data_proc(
|
||||
p_parent_table := r.parent_table,
|
||||
p_loop_count := 200
|
||||
p_loop_count := 200,
|
||||
p_source_table := r.default_part::text
|
||||
);
|
||||
COMMIT;
|
||||
END LOOP;
|
||||
@@ -365,9 +365,7 @@ SET retention = :'retention_days' || ' days',
|
||||
retention_keep_table = false,
|
||||
premake = 7,
|
||||
infinite_time_partitions = true
|
||||
WHERE parent_table LIKE 'telegraf.%'
|
||||
AND EXISTS (SELECT 1 FROM pg_catalog.pg_class c
|
||||
WHERE c.oid = to_regclass(parent_table) AND c.relkind = 'p');
|
||||
WHERE parent_table LIKE 'telegraf.%';
|
||||
\endif
|
||||
EOSQL
|
||||
;;
|
||||
|
||||
@@ -106,11 +106,6 @@ psql_cron() {
|
||||
capture docker exec -i -e PGOPTIONS="$PG_OPTS" so-postgres psql -U postgres -d "$cron_db" "$@"
|
||||
}
|
||||
|
||||
# A part_config row counts only while its parent is a partitioned table.
|
||||
TELEGRAF_PARENTS="parent_table LIKE 'telegraf.%'
|
||||
AND EXISTS (SELECT 1 FROM pg_class c
|
||||
WHERE c.oid = to_regclass(parent_table) AND c.relkind = 'p')"
|
||||
|
||||
REPORT="
|
||||
SELECT d.parent_table,
|
||||
c.newest_child,
|
||||
@@ -120,7 +115,6 @@ SELECT d.parent_table,
|
||||
pg_size_pretty(d.default_size) AS default_size
|
||||
FROM so_admin.telegraf_defaults() d
|
||||
JOIN partman.part_config pc ON to_regclass(pc.parent_table) = d.parent_table
|
||||
JOIN pg_class p ON p.oid = d.parent_table AND p.relkind = 'p'
|
||||
LEFT JOIN LATERAL (
|
||||
SELECT max(to_date(substring(ch.relname FROM '_p(\d{8})\$'), 'YYYYMMDD')) AS newest_child
|
||||
FROM pg_inherits i
|
||||
@@ -171,25 +165,19 @@ has_db=$(psql_pg -tAc "SELECT 1 FROM pg_database WHERE datname = 'so_telegraf'")
|
||||
cron_db=$(psql_pg -tAc "SELECT current_setting('cron.database_name', true)")
|
||||
cron_db=$(tr -d '[:space:]' <<<"$cron_db")
|
||||
|
||||
role_ok=$(psql_pg -tAc \
|
||||
"SELECT rolcanlogin AND NOT (rolsuper OR rolcreatedb OR rolcreaterole OR rolreplication OR rolbypassrls)
|
||||
FROM pg_roles WHERE rolname = '$MAINT_ROLE'")
|
||||
has_role=$(psql_pg -tAc "SELECT 1 FROM pg_roles WHERE rolname = '$MAINT_ROLE'")
|
||||
job=
|
||||
[[ "$cron_db" == postgres ]] && job=$(lookup_job)
|
||||
|
||||
if [[ "$role_ok" != t ]] && $CHECK_ONLY; then
|
||||
if [[ -z "$has_role" ]] && $CHECK_ONLY; then
|
||||
echo "Repair is needed:"
|
||||
if [[ -z "$role_ok" ]]; then
|
||||
echo " * maintenance role $MAINT_ROLE is missing"
|
||||
else
|
||||
echo " * maintenance role $MAINT_ROLE is misconfigured"
|
||||
fi
|
||||
echo " * maintenance role $MAINT_ROLE is missing"
|
||||
echo
|
||||
echo "Re-run without --check to repair."
|
||||
finish 1
|
||||
fi
|
||||
|
||||
if ! $CHECK_ONLY && [[ "$role_ok" != t || ( "$cron_db" == postgres && -z "$job" ) ]]; then
|
||||
if ! $CHECK_ONLY && [[ -z "$has_role" || ( "$cron_db" == postgres && -z "$job" ) ]]; then
|
||||
echo "Registering the maintenance role and job."
|
||||
if ! /usr/sbin/so-telegraf-postgres group_role; then
|
||||
echo "Could not register the maintenance job; run a highstate and try again." >&2
|
||||
@@ -203,7 +191,7 @@ has_partman=$(psql_tg -tAc "SELECT 1 FROM pg_extension WHERE extname = 'pg_partm
|
||||
|| skip "pg_partman is not installed in so_telegraf; nothing to repair."
|
||||
|
||||
parents=$(psql_tg -tAc \
|
||||
"SELECT count(*) FROM partman.part_config WHERE $TELEGRAF_PARENTS")
|
||||
"SELECT count(*) FROM partman.part_config WHERE parent_table LIKE 'telegraf.%'")
|
||||
counts=$(psql_tg -tAc \
|
||||
"SELECT count(*) FILTER (WHERE default_has_rows) || '|' ||
|
||||
count(*) FILTER (WHERE coalesce(days_ahead, -1) < 1)
|
||||
@@ -213,7 +201,7 @@ IFS='|' read -r stranded behind <<<"$counts"
|
||||
# refuses to premake forward across the gap the stall left behind.
|
||||
misconfigured=$(psql_tg -tAc \
|
||||
"SELECT count(*) FROM partman.part_config
|
||||
WHERE $TELEGRAF_PARENTS
|
||||
WHERE parent_table LIKE 'telegraf.%'
|
||||
AND (premake < $PREMAKE OR NOT infinite_time_partitions)")
|
||||
|
||||
# Both columns are matched because which one carries the launcher's name varies
|
||||
@@ -317,7 +305,7 @@ if [[ "$misconfigured" -gt 0 ]]; then
|
||||
"UPDATE partman.part_config
|
||||
SET premake = GREATEST(premake, $PREMAKE),
|
||||
infinite_time_partitions = true
|
||||
WHERE $TELEGRAF_PARENTS"
|
||||
WHERE parent_table LIKE 'telegraf.%'"
|
||||
fi
|
||||
|
||||
if [[ "$stranded" -gt 0 ]]; then
|
||||
|
||||
Reference in new issue
Block a user