extend script to use ninja fields
This commit is contained in:
23
error-in-logs-ninja.sh
Normal file
23
error-in-logs-ninja.sh
Normal 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
|
||||||
Reference in New Issue
Block a user