Files
error-in-logs/error-in-logs-ninja.sh

24 lines
672 B
Bash

#!/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