From 994be79274f080d13ed9149a0235b0a19d51a403 Mon Sep 17 00:00:00 2001 From: Petar Cubela Date: Mon, 17 Jun 2024 13:33:12 +0200 Subject: [PATCH] extend script to use ninja fields --- error-in-logs-ninja.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 error-in-logs-ninja.sh 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