Page 1 of 1

Read a file in Linux server

Posted: Mon May 18, 2020 4:49 pm
by ets_user
Hi,

We want to read a file in a specific path in a linux server (Alarm file) and them send the contents over mail.

Pls let us know how we can achieve it.

PS: We have email configured already.

Thanks.

Re: Read a file in Linux server

Posted: Tue May 19, 2020 1:46 pm
by benjaminsmith
Hello @ets_user,

Just to clarify, you want to monitor a file on a Linux server, and when some value or keyword is present in the file, you want to send the contents of the file by email.

One option is to use Event Handlers in Nagios XI to execute a bash script send the file. The development of customs scripts is out of scope for product support, but the following document will help get you started.

Introduction to Event Handlers in Nagios XI

Take a look and let me know if you have any questions.

Re: Read a file in Linux server

Posted: Tue May 19, 2020 1:48 pm
by cdienger
I don't think I have enough detail to provide solution yet but There is the /usr/local/nagios/libexec/check_log plugin which is default on XI systems. You may also want to check out - https://labs.consol.de/nagios/check_logfiles/index.html.

If you need further assistance please answer the following:

Is the file on the XI server or another remote server that XI is monitoring?

Are you trying to alert if specific strings are found or when other conditions are met?

Are you trying to send the entire file or just a portion? This may not be doable, but if you can provide more details we can better provide guidance.

Re: Read a file in Linux server

Posted: Tue May 19, 2020 4:29 pm
by ets_user
Kinldy find below details for more clarity.

Is the file on the XI server or another remote server that XI is monitoring?
Its on another remote Linux server where NRPE agent is running and monitoring CPU,Memory etc..
Are you trying to alert if specific strings are found or when other conditions are met?
Yes, if the file has error string we want to send that error message by email
Are you trying to send the entire file or just a portion? This may not be doable, but if you can provide more details we can better provide guidance.
Entire file for now, but we might need to parse the file and get the required format in future
Please advise.

Re: Read a file in Linux server

Posted: Wed May 20, 2020 11:18 am
by cdienger
Thanks for the extra information. With that I would second the recommendation of @benjaminsmith of using an event handler to email the file. https://assets.nagios.com/downloads/nag ... ios-XI.pdf