diff --git a/error-in-logs-ninja.sh b/error-in-logs-ninja.sh new file mode 100644 index 0000000..cf2cfcc --- /dev/null +++ b/error-in-logs-ninja.sh @@ -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