Aucune description

send-wazuh-sim-logs.sh 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. # Combined Wazuh simulator script (single entrypoint)
  4. # Replays production-style sample logs from samples/*.log to Wazuh syslog UDP.
  5. #
  6. # Usage:
  7. # scripts/send-wazuh-sim-logs.sh [selector] [count] [delay_seconds] [--forever] [--dry-run] [--no-mock] [--no-guarantee-hits] [--random-types] [--include-nonalerts] [--docker-send]
  8. #
  9. # Selectors:
  10. # all
  11. # a|b|c|appendix-a|appendix-b|appendix-c
  12. # a1|a2|a3|a4|b1|b2|b3|c1|c2|c3
  13. # A1-01, A2-10, B3-06, C1-01, ...
  14. SELECTOR="${1:-all}"
  15. COUNT="${2:-1}"
  16. DELAY="${3:-1}"
  17. shift $(( $# >= 3 ? 3 : $# )) || true
  18. FOREVER=0
  19. DRY_RUN="${DRY_RUN:-0}"
  20. MOCK_VALUES="${MOCK_VALUES:-1}"
  21. GUARANTEE_HITS="${GUARANTEE_HITS:-1}"
  22. RANDOM_TYPES="${RANDOM_TYPES:-0}"
  23. INCLUDE_NONALERTS="${INCLUDE_NONALERTS:-0}"
  24. DOCKER_SEND="${DOCKER_SEND:-0}"
  25. WAZUH_MANAGER_CONTAINER="${WAZUH_MANAGER_CONTAINER:-wazuh-single-wazuh.manager-1}"
  26. for arg in "$@"; do
  27. case "$arg" in
  28. --forever)
  29. FOREVER=1
  30. ;;
  31. --dry-run)
  32. DRY_RUN=1
  33. ;;
  34. --no-mock)
  35. MOCK_VALUES=0
  36. ;;
  37. --mock)
  38. MOCK_VALUES=1
  39. ;;
  40. --no-guarantee-hits)
  41. GUARANTEE_HITS=0
  42. ;;
  43. --guarantee-hits)
  44. GUARANTEE_HITS=1
  45. ;;
  46. --random-types)
  47. RANDOM_TYPES=1
  48. ;;
  49. --include-nonalerts)
  50. INCLUDE_NONALERTS=1
  51. ;;
  52. --docker-send)
  53. DOCKER_SEND=1
  54. ;;
  55. -h|--help)
  56. echo "usage: scripts/send-wazuh-sim-logs.sh [selector] [count] [delay_seconds] [--forever] [--dry-run] [--no-mock] [--no-guarantee-hits] [--random-types] [--include-nonalerts] [--docker-send]"
  57. exit 0
  58. ;;
  59. *)
  60. echo "error: unknown option '$arg'"
  61. exit 1
  62. ;;
  63. esac
  64. done
  65. if ! [[ "$COUNT" =~ ^[0-9]+$ ]] || [ "$COUNT" -lt 1 ]; then
  66. echo "error: count must be a positive integer"
  67. exit 1
  68. fi
  69. if ! [[ "$DELAY" =~ ^[0-9]+([.][0-9]+)?$ ]]; then
  70. echo "error: delay_seconds must be numeric"
  71. exit 1
  72. fi
  73. WAZUH_SYSLOG_HOST="${WAZUH_SYSLOG_HOST:-127.0.0.1}"
  74. WAZUH_SYSLOG_PORT="${WAZUH_SYSLOG_PORT:-514}"
  75. NC_WAIT_SECONDS="${NC_WAIT_SECONDS:-0}"
  76. STRICT_SEND="${STRICT_SEND:-1}"
  77. BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
  78. SAMPLES_DIR="${BASE_DIR}/samples"
  79. normalize() {
  80. printf '%s' "$1" | tr '[:upper:]' '[:lower:]'
  81. }
  82. is_valid_selector() {
  83. local sel
  84. sel="$(normalize "$1")"
  85. case "$sel" in
  86. all|a|b|c|appendix-a|appendix-b|appendix-c|a1|a2|a3|a4|b1|b2|b3|c1|c2|c3)
  87. return 0
  88. ;;
  89. [abc][0-9]-[0-9][0-9])
  90. return 0
  91. ;;
  92. *)
  93. return 1
  94. ;;
  95. esac
  96. }
  97. selector_matches_tag() {
  98. local selector tag sel tagl
  99. selector="$1"
  100. tag="$2"
  101. sel="$(normalize "$selector")"
  102. tagl="$(normalize "$tag")"
  103. if [ -z "$tagl" ]; then
  104. case "$sel" in
  105. all|a|b|c|appendix-a|appendix-b|appendix-c)
  106. return 0
  107. ;;
  108. *)
  109. return 1
  110. ;;
  111. esac
  112. fi
  113. case "$sel" in
  114. all)
  115. return 0
  116. ;;
  117. a|appendix-a)
  118. [[ "$tagl" == a* ]]
  119. return
  120. ;;
  121. b|appendix-b)
  122. [[ "$tagl" == b* ]]
  123. return
  124. ;;
  125. c|appendix-c)
  126. [[ "$tagl" == c* ]]
  127. return
  128. ;;
  129. a1|a2|a3|a4|b1|b2|b3|c1|c2|c3)
  130. [[ "$tagl" == "$sel"-* ]]
  131. return
  132. ;;
  133. [abc][0-9]-[0-9][0-9])
  134. [[ "$tagl" == "$sel" ]]
  135. return
  136. ;;
  137. *)
  138. return 1
  139. ;;
  140. esac
  141. }
  142. sample_files_for_selector() {
  143. local sel
  144. sel="$(normalize "$1")"
  145. case "$sel" in
  146. all)
  147. echo "${SAMPLES_DIR}/appendix-a-production-samples.log"
  148. echo "${SAMPLES_DIR}/appendix-b-production-samples.log"
  149. echo "${SAMPLES_DIR}/appendix-c-production-samples.log"
  150. ;;
  151. a|appendix-a|a1|a2|a3|a4|a[0-9]-[0-9][0-9])
  152. echo "${SAMPLES_DIR}/appendix-a-production-samples.log"
  153. ;;
  154. b|appendix-b|b1|b2|b3|b[0-9]-[0-9][0-9])
  155. echo "${SAMPLES_DIR}/appendix-b-production-samples.log"
  156. ;;
  157. c|appendix-c|c1|c2|c3|c[0-9]-[0-9][0-9])
  158. echo "${SAMPLES_DIR}/appendix-c-production-samples.log"
  159. ;;
  160. *)
  161. echo "error: unsupported selector '$1'" >&2
  162. return 1
  163. ;;
  164. esac
  165. }
  166. emit_syslog() {
  167. local line="$1"
  168. if [ "${DRY_RUN}" = "1" ]; then
  169. echo "DRY_RUN -> ${line}"
  170. return 0
  171. fi
  172. if [ "${DOCKER_SEND}" = "1" ]; then
  173. if ! printf '%s\n' "${line}" | docker exec -i "${WAZUH_MANAGER_CONTAINER}" bash -lc 'cat > /dev/udp/127.0.0.1/514'; then
  174. echo "send_failed target=${WAZUH_MANAGER_CONTAINER}:127.0.0.1:514/udp transport=docker-exec" >&2
  175. if [ "${STRICT_SEND}" = "1" ]; then
  176. return 1
  177. fi
  178. fi
  179. return 0
  180. fi
  181. if command -v nc >/dev/null 2>&1; then
  182. if ! printf '%s\n' "${line}" | nc -w "${NC_WAIT_SECONDS}" -u "${WAZUH_SYSLOG_HOST}" "${WAZUH_SYSLOG_PORT}"; then
  183. echo "send_failed target=${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp transport=nc" >&2
  184. if [ "${STRICT_SEND}" = "1" ]; then
  185. return 1
  186. fi
  187. fi
  188. else
  189. if ! printf '%s\n' "${line}" >"/dev/udp/${WAZUH_SYSLOG_HOST}/${WAZUH_SYSLOG_PORT}"; then
  190. echo "send_failed target=${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp transport=devudp" >&2
  191. if [ "${STRICT_SEND}" = "1" ]; then
  192. return 1
  193. fi
  194. fi
  195. fi
  196. }
  197. rand_between() {
  198. local min max
  199. min="$1"
  200. max="$2"
  201. echo $(( min + RANDOM % (max - min + 1) ))
  202. }
  203. random_public_ip() {
  204. local range last
  205. range="$(rand_between 0 2)"
  206. last="$(rand_between 2 254)"
  207. case "$range" in
  208. 0) echo "198.51.100.${last}" ;;
  209. 1) echo "203.0.113.${last}" ;;
  210. *) echo "192.0.2.${last}" ;;
  211. esac
  212. }
  213. random_private_ip() {
  214. echo "10.$(rand_between 10 30).$(rand_between 1 254).$(rand_between 1 254)"
  215. }
  216. random_user() {
  217. local users=(
  218. "admin01" "analyst01" "helpdesk01" "ops.admin" "jane.doe"
  219. "svc_backup$" "svc_dbbackup$" "finance.user" "it-admin" "guest"
  220. )
  221. echo "${users[$((RANDOM % ${#users[@]}))]}"
  222. }
  223. random_fgt_model() {
  224. local models=("FGT40F-Branch01" "FGT60F-Branch01" "FGT80F-Branch01" "FGT501E-DC01")
  225. echo "${models[$((RANDOM % ${#models[@]}))]}"
  226. }
  227. random_devid() {
  228. local n
  229. n="$(rand_between 10000000 99999999)"
  230. echo "FGT80FTK${n}"
  231. }
  232. random_domain() {
  233. echo "ioc-$(rand_between 1000 9999).malicious.example"
  234. }
  235. replace_kv() {
  236. local input key new
  237. input="$1"
  238. key="$2"
  239. new="$3"
  240. printf '%s' "$input" | sed -E "s#${key}=\"[^\"]*\"#${key}=\"${new}\"#g; s#${key}=([^\" ][^ ]*)#${key}=${new}#g"
  241. }
  242. mock_windows_json_line() {
  243. local line src_ip
  244. line="$1"
  245. src_ip="$(random_public_ip)"
  246. if command -v jq >/dev/null 2>&1; then
  247. printf '%s' "$line" | jq -c \
  248. --arg srcip "$src_ip" \
  249. '
  250. if (.win.eventdata | type) == "object" then
  251. .win.eventdata |= (
  252. if has("subjectUserName") then .subjectUserName = "SYSTEM" else . end |
  253. if has("workstationName") then .workstationName = ("WS-" + (($srcip|split("."))[3])) else . end |
  254. if has("ipAddress") then .ipAddress = $srcip else . end
  255. )
  256. else
  257. .
  258. end
  259. ' 2>/dev/null || printf '%s' "$line"
  260. else
  261. printf '%s' "$line"
  262. fi
  263. }
  264. mock_non_json_line() {
  265. local line now_date now_time now_iso epoch src_pub dst_priv prev_pub devname devid query
  266. line="$1"
  267. now_date="$(date '+%Y-%m-%d')"
  268. now_time="$(date '+%H:%M:%S')"
  269. now_iso="$(date -u '+%Y-%m-%dT%H:%M:%S.000Z')"
  270. epoch="$(date '+%s')"
  271. src_pub="$(random_public_ip)"
  272. dst_priv="$(random_private_ip)"
  273. prev_pub="$(random_public_ip)"
  274. devname="$(random_fgt_model)"
  275. devid="$(random_devid)"
  276. query="$(random_domain)"
  277. line="$(replace_kv "$line" "date" "$now_date")"
  278. line="$(replace_kv "$line" "time" "$now_time")"
  279. line="$(replace_kv "$line" "eventtime" "$epoch")"
  280. line="$(replace_kv "$line" "devname" "$devname")"
  281. line="$(replace_kv "$line" "devid" "$devid")"
  282. line="$(replace_kv "$line" "srcip" "$src_pub")"
  283. line="$(replace_kv "$line" "dstip" "$dst_priv")"
  284. line="$(replace_kv "$line" "src_ip" "$src_pub")"
  285. line="$(replace_kv "$line" "prev_ip" "$prev_pub")"
  286. line="$(replace_kv "$line" "query" "$query")"
  287. line="$(replace_kv "$line" "srcport" "$(rand_between 1025 65535)")"
  288. line="$(replace_kv "$line" "distance_km" "$(rand_between 500 16000)")"
  289. line="$(replace_kv "$line" "travel_minutes" "$(rand_between 5 180)")"
  290. if [[ "$line" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}T ]]; then
  291. line="$(printf '%s' "$line" | sed -E "s#^[0-9]{4}-[0-9]{2}-[0-9]{2}T[^ ]+#${now_iso}#")"
  292. fi
  293. line="$(printf '%s' "$line" | sed -E "s#from [0-9]{1,3}(\.[0-9]{1,3}){3}#from ${src_pub}#g")"
  294. line="$(printf '%s' "$line" | sed -E "s# port [0-9]{2,5}# port $(rand_between 1025 65535)#g")"
  295. printf '%s' "$line"
  296. }
  297. mock_line() {
  298. local line="$1"
  299. if [ "$MOCK_VALUES" != "1" ]; then
  300. printf '%s' "$line"
  301. return 0
  302. fi
  303. if [[ "$line" =~ ^\{ ]]; then
  304. mock_windows_json_line "$line"
  305. else
  306. mock_non_json_line "$line"
  307. fi
  308. }
  309. send_file_once() {
  310. local file selector line sent current_tag extracted
  311. file="$1"
  312. selector="$2"
  313. sent=0
  314. current_tag=""
  315. while IFS= read -r line || [ -n "$line" ]; do
  316. if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*([A-Za-z][0-9]-[0-9]{2})([[:space:]]|$) ]]; then
  317. extracted="${BASH_REMATCH[1]}"
  318. current_tag="$(normalize "$extracted")"
  319. continue
  320. fi
  321. if [[ -z "${line// }" ]] || [[ "$line" =~ ^[[:space:]]*# ]]; then
  322. continue
  323. fi
  324. if selector_matches_tag "$selector" "$current_tag"; then
  325. line="$(mock_line "$line")"
  326. emit_syslog "$line"
  327. sent=$((sent + 1))
  328. sleep "$DELAY"
  329. fi
  330. done < "$file"
  331. echo "sent=${sent} file=$(basename "$file") selector=$(normalize "$selector")"
  332. }
  333. send_guaranteed_hits_once() {
  334. local selector sent idx tag line
  335. selector="$1"
  336. sent=0
  337. local tags=(
  338. "a1-01"
  339. "a1-02"
  340. "a2-02"
  341. "a2-03"
  342. "a2-05"
  343. "a2-10"
  344. "c1-01"
  345. "c1-01"
  346. )
  347. local lines=(
  348. "soc_event=dns_ioc event_type=ioc_dns_traffic src_ip=10.26.45.214 query=ioc-2294.malicious.example action=blocked severity=medium"
  349. "soc_event=dns_ioc event_type=ioc_domain_match src_ip=10.26.45.214 query=bad-c2.example feed=internal_main confidence=high action=alert"
  350. "date=2026-03-09 time=10:02:04 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773079324 vd=\"root\" logid=\"0100044547\" type=\"event\" subtype=\"system\" level=\"warning\" user=\"admin\" action=\"password-change\" ui=\"https(10.20.55.1)\""
  351. "date=2026-03-09 time=10:02:17 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773079337 vd=\"root\" logid=\"0100044548\" type=\"event\" subtype=\"system\" level=\"warning\" user=\"admin\" action=\"create-admin\" target_user=\"soc-backup-admin\""
  352. "date=2026-03-09 time=10:04:03 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773079443 vd=\"root\" logid=\"0100044552\" type=\"event\" subtype=\"system\" level=\"notice\" user=\"admin\" action=\"download-config\" dstip=10.20.50.33"
  353. "date=2026-03-09 time=10:07:59 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773079679 vd=\"root\" logid=\"0000000014\" type=\"traffic\" subtype=\"forward\" level=\"warning\" srcip=10.20.55.50 dstip=203.0.113.60 dstport=443 threat_label=\"known-c2\" action=\"accept\""
  354. "date=2026-03-09 time=10:31:00 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773081060 vd=\"root\" logid=\"0101037135\" type=\"event\" subtype=\"vpn\" tunneltype=\"ssl\" action=\"ssl-login-success\" user=\"analyst01\" srcip=203.0.113.71 previous_country=TH current_country=US"
  355. "soc_event=correlation event_type=c1_impossible_travel user=\"analyst01\" src_ip=203.0.113.71 prev_ip=203.0.113.11 prev_country=TH current_country=US distance_km=13890 travel_minutes=18"
  356. )
  357. for idx in "${!lines[@]}"; do
  358. tag="${tags[$idx]}"
  359. if selector_matches_tag "$selector" "$tag"; then
  360. line="$(mock_line "${lines[$idx]}")"
  361. emit_syslog "$line"
  362. sent=$((sent + 1))
  363. sleep "$DELAY"
  364. fi
  365. done
  366. echo "guaranteed_sent=${sent} selector=$(normalize "$selector")"
  367. }
  368. EVENT_POOL_READY=0
  369. EVENT_POOL_SELECTOR=""
  370. declare -a EVENT_POOL_TAGS
  371. declare -a EVENT_POOL_LINES
  372. build_event_pool() {
  373. local selector file line current_tag extracted idx tag
  374. selector="$1"
  375. EVENT_POOL_READY=0
  376. EVENT_POOL_SELECTOR="$selector"
  377. EVENT_POOL_TAGS=()
  378. EVENT_POOL_LINES=()
  379. if [ "$INCLUDE_NONALERTS" = "1" ]; then
  380. for file in "${FILES[@]}"; do
  381. current_tag=""
  382. while IFS= read -r line || [ -n "$line" ]; do
  383. if [[ "$line" =~ ^[[:space:]]*#[[:space:]]*([A-Za-z][0-9]-[0-9]{2})([[:space:]]|$) ]]; then
  384. extracted="${BASH_REMATCH[1]}"
  385. current_tag="$(normalize "$extracted")"
  386. continue
  387. fi
  388. if [[ -z "${line// }" ]] || [[ "$line" =~ ^[[:space:]]*# ]]; then
  389. continue
  390. fi
  391. if selector_matches_tag "$selector" "$current_tag"; then
  392. EVENT_POOL_TAGS+=("$current_tag")
  393. EVENT_POOL_LINES+=("$line")
  394. fi
  395. done < "$file"
  396. done
  397. fi
  398. if [ "$GUARANTEE_HITS" = "1" ]; then
  399. local guaranteed_tags=(
  400. "a1-01" "a1-02" "a2-02" "a2-03" "a2-05" "a2-10" "c1-01" "c1-01"
  401. )
  402. local guaranteed_lines=(
  403. "soc_event=dns_ioc event_type=ioc_dns_traffic src_ip=10.26.45.214 query=ioc-2294.malicious.example action=blocked severity=medium"
  404. "soc_event=dns_ioc event_type=ioc_domain_match src_ip=10.26.45.214 query=bad-c2.example feed=internal_main confidence=high action=alert"
  405. "date=2026-03-09 time=10:02:04 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773079324 vd=\"root\" logid=\"0100044547\" type=\"event\" subtype=\"system\" level=\"warning\" user=\"admin\" action=\"password-change\" ui=\"https(10.20.55.1)\""
  406. "date=2026-03-09 time=10:02:17 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773079337 vd=\"root\" logid=\"0100044548\" type=\"event\" subtype=\"system\" level=\"warning\" user=\"admin\" action=\"create-admin\" target_user=\"soc-backup-admin\""
  407. "date=2026-03-09 time=10:04:03 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773079443 vd=\"root\" logid=\"0100044552\" type=\"event\" subtype=\"system\" level=\"notice\" user=\"admin\" action=\"download-config\" dstip=10.20.50.33"
  408. "date=2026-03-09 time=10:07:59 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773079679 vd=\"root\" logid=\"0000000014\" type=\"traffic\" subtype=\"forward\" level=\"warning\" srcip=10.20.55.50 dstip=203.0.113.60 dstport=443 threat_label=\"known-c2\" action=\"accept\""
  409. "date=2026-03-09 time=10:31:00 devname=\"FGT80F-Branch01\" devid=\"FGT80FTK20000001\" eventtime=1773081060 vd=\"root\" logid=\"0101037135\" type=\"event\" subtype=\"vpn\" tunneltype=\"ssl\" action=\"ssl-login-success\" user=\"analyst01\" srcip=203.0.113.71 previous_country=TH current_country=US"
  410. "soc_event=correlation event_type=c1_impossible_travel user=\"analyst01\" src_ip=203.0.113.71 prev_ip=203.0.113.11 prev_country=TH current_country=US distance_km=13890 travel_minutes=18"
  411. )
  412. for idx in "${!guaranteed_lines[@]}"; do
  413. tag="${guaranteed_tags[$idx]}"
  414. if selector_matches_tag "$selector" "$tag"; then
  415. EVENT_POOL_TAGS+=("$tag")
  416. EVENT_POOL_LINES+=("${guaranteed_lines[$idx]}")
  417. fi
  418. done
  419. fi
  420. EVENT_POOL_READY=1
  421. }
  422. send_random_event_once() {
  423. local selector size idx line tag
  424. selector="$1"
  425. if [ "$EVENT_POOL_READY" -ne 1 ] || [ "$EVENT_POOL_SELECTOR" != "$selector" ]; then
  426. build_event_pool "$selector"
  427. fi
  428. size="${#EVENT_POOL_LINES[@]}"
  429. if [ "$size" -eq 0 ]; then
  430. echo "random_sent=0 selector=$(normalize "$selector")"
  431. return 0
  432. fi
  433. idx=$((RANDOM % size))
  434. tag="${EVENT_POOL_TAGS[$idx]}"
  435. line="${EVENT_POOL_LINES[$idx]}"
  436. line="$(mock_line "$line")"
  437. emit_syslog "$line"
  438. echo "random_sent=1 tag=${tag} selector=$(normalize "$selector")"
  439. }
  440. if ! is_valid_selector "$SELECTOR"; then
  441. echo "error: selector must be one of all|a|b|c|appendix-a|appendix-b|appendix-c|a1..a4|b1..b3|c1..c3|A1-01..C3-04"
  442. exit 1
  443. fi
  444. FILES=()
  445. while IFS= read -r f; do
  446. [ -n "$f" ] && FILES+=("$f")
  447. done < <(sample_files_for_selector "$SELECTOR")
  448. for f in "${FILES[@]}"; do
  449. if [ ! -f "$f" ]; then
  450. echo "error: missing sample file '$f'"
  451. exit 1
  452. fi
  453. done
  454. echo "selector=${SELECTOR} count=${COUNT} delay=${DELAY}s forever=${FOREVER} dry_run=${DRY_RUN} mock_values=${MOCK_VALUES} guarantee_hits=${GUARANTEE_HITS} random_types=${RANDOM_TYPES} include_nonalerts=${INCLUDE_NONALERTS} docker_send=${DOCKER_SEND} nc_wait=${NC_WAIT_SECONDS}s strict_send=${STRICT_SEND}"
  455. echo "target=${WAZUH_SYSLOG_HOST}:${WAZUH_SYSLOG_PORT}/udp"
  456. if [ "$RANDOM_TYPES" = "1" ]; then
  457. if [ "$FOREVER" -eq 1 ]; then
  458. loop=1
  459. while true; do
  460. send_random_event_once "$SELECTOR"
  461. echo "loop=${loop} complete"
  462. loop=$((loop + 1))
  463. sleep "$DELAY"
  464. done
  465. else
  466. for ((i=1; i<=COUNT; i++)); do
  467. send_random_event_once "$SELECTOR"
  468. echo "iteration=${i}/${COUNT} complete"
  469. sleep "$DELAY"
  470. done
  471. fi
  472. elif [ "$FOREVER" -eq 1 ]; then
  473. loop=1
  474. while true; do
  475. for f in "${FILES[@]}"; do
  476. send_file_once "$f" "$SELECTOR"
  477. done
  478. if [ "$GUARANTEE_HITS" = "1" ]; then
  479. send_guaranteed_hits_once "$SELECTOR"
  480. fi
  481. echo "loop=${loop} complete"
  482. loop=$((loop + 1))
  483. done
  484. else
  485. for ((i=1; i<=COUNT; i++)); do
  486. for f in "${FILES[@]}"; do
  487. send_file_once "$f" "$SELECTOR"
  488. done
  489. if [ "$GUARANTEE_HITS" = "1" ]; then
  490. send_guaranteed_hits_once "$SELECTOR"
  491. fi
  492. echo "iteration=${i}/${COUNT} complete"
  493. done
  494. fi