Score:-2

How to create a script to check logfile

cz flag

I want to create a script where i check the logfile every 5 or 10 minutes to know if the service is up and running, and also, to know if the logfile is receiving and sending these files that are being received (more like if a new file enters in the logfile, or not receiving anything.) In case of not receiving anything in 5 or 10 mins, depending on the configuration, warns me via Nagios Monitoring. I have no idea how to start scripting this one.

digijay avatar
mx flag
Nagios (resp. nrpe) comes with lots of check scripts (in `/usr/lib/nagios/plugins`), furthermore masses of scripts for each and any service can be found in the internet. These scripts are being scheduled and executed from a remote host with nagios or icinga2.
Score:1
in flag

Well this depends on the contents of your logfiles, but here are some suggestions, which might help you:

If you just want to see if a process is running, you can use the nagios plugin "check_procs".

To check if a logfile is beeing written to, you can use the nagios plugin "check_file_age".

If you want to check for certain expressions, this is a great plugin: https://labs.consol.de/nagios/check_logfiles

Jhony avatar
cz flag
Hi, thanks for the reply. In my case, this logfile is "feeded" every minute, the situation was: the service was up and running, but even with the service up, was in zombie state, service was running, but not receiving and transmitting files. The alert was needed to fix this problem. So i was thinking about to monitor the logfile every 5 minutes to check if the logfile was feeded, if it's feeded, ok. If it's not, i want Nagios to warn me.
Score:0
cn flag

You are better off checking the process table via ps to see if your process is running correctly.

Some nagios plugins you may consider:

https://exchange.nagios.org/directory/Plugins/Operating-Systems/Linux/check_ps-2Esh/details

https://exchange.nagios.org/directory/Plugins/Operating-Systems/Linux/check_logfiles/details

See check_procs @Virsacer says as well.

Jhony avatar
cz flag
Thanks for the reply. The service was up and running, but not working as expected. Like i said to Virsacer, the service was running in a zombie state, was up and running, but without any action... A restart in the service was needed to solve the problem. And to avoid situations like this in the future, i want to create this script to alert me.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.