Team Operation Ticket #918: Create Custom NRPE to monitor logs - KeegMitch/Operations-Engineering-group-c GitHub Wiki
Ticket #918
Do these inside DB server
sudo vim /usr/lib/nagios/plugins/check_logfile.sh
#!/bin/bash
LOGFILE="/var/log/syslog"
PATTERNS=("ERROR" "CRITICAL" "WARNING")
RESULT=""
for PATTERN in "${PATTERNS[@]}"; do
if grep -q "$PATTERN" "$LOGFILE"; then
RESULT+="$PATTERN found. "
fi
done
if [ -z "$RESULT" ]; then
echo "OK: No patterns found."
exit 0
else
echo "CRITICAL: $RESULT"
exit 2
fi
sudo chmod +x /usr/lib/nagios/plugins/check_logfile.sh
sudo vim /etc/nagios/nrpe.cfg
Add this with all the other check commands:
command[check_logfile]=/usr/lib/nagios/plugins/check_logfile.sh
sudo systemctl restart nagios-nrpe-server
Do these inside MGMT server
- Use the existing check_nrpe command from nagios plugins
Go to the existing nagios puppet module config.pp
nagios_hostgroup {"Check-Logfiles":
target => "/etc/nagios3/conf.d/ppt_hostgroups.cfg",
mode => "0444",
alias => "Check logfiles",
members => "db-c",
}
nagios_service { "db_logfiles_check":
service_description => "Checking DB Logfiles",
hostgroup_name => "Check-Logfiles",
target => "/etc/nagios3/conf.d/ppt_services.cfg",
check_command => "check_nrpe!check_logfile",
max_check_attempts => 3,
retry_check_interval => 1,
normal_check_interval => 5,
check_period => "24x7",
notification_interval => 30,
notification_period => "24x7",
notification_options => "w,u,c,r",
contact_groups => "slackgroup",
mode => "0444",
}
- Apply to puppet agent
- Restart Nagios
If all goes well you should be able to see the nagios check here: