extend script to use ninja fields

This commit is contained in:
2024-06-17 13:33:12 +02:00
parent 4c58fd9fae
commit 994be79274

23
error-in-logs-ninja.sh Normal file
View File

@@ -0,0 +1,23 @@
#!/bin/bash
# Define your keywords
#keywords=("ERROR" "keyword2" "keyword3")
keywords=("ERROR")
# Path to your log file
log_file="/var/log/syslog"
# Iterate through each keyword
for keyword in "${keywords[@]}"; do
# Use grep to search for the keyword in the log file
matched_lines=$(grep "$keyword" "$log_file")
# Check if any lines contain the keyword
if [[ -n "$matched_lines" ]]; then
# Use ninjarmm-cli to set a custom field with the matched text
ninjarmm-cli set fieldname "$matched_lines"
# You may want to add some logic here to handle multiple matches differently
# For example, you can append all matched lines to a single custom field.
fi
done