Nagios Command File - Timestamp parsing

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Sphinx
Posts: 5
Joined: Thu Mar 05, 2015 3:29 am

Nagios Command File - Timestamp parsing

Post by Sphinx »

Hey all.

We have installed Nagios Core 3.5.0 and are in the need to process a vast amount from passive check results at once.
The results are comming from a database output and have different check result timestamps.

And here ist the problem, when we insert the passive check result into the nagios.cmd, the leading timestamp is dropped and replaced with the system timestamp when executing.

As an example:
Result Check Result from our test with only one result

Code: Select all

[1425537702] PROCESS_SERVICE_CHECK_RESULT;fkwinbck;Active Backups;0;No Backups Running
Nagios Log at the same second

Code: Select all

[1425541078] EXTERNAL COMMAND: PROCESS_SERVICE_CHECK_RESULT;fkwinbck;Active Backups;0;No Backups Running
[1425541081] PASSIVE SERVICE CHECK: fkwinbck;Active Backups;0;No Backups Running
The CGI's and our database are showing the timestamp of the command execution rather than the check execution.
Is there any chance to configure the command file parser not to overwrite the timestamp?
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Nagios Command File - Timestamp parsing

Post by Box293 »

Can you show us the command you are using to submit the passive check to nagios.cmd
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Sphinx
Posts: 5
Joined: Thu Mar 05, 2015 3:29 am

Re: Nagios Command File - Timestamp parsing

Post by Sphinx »

Sure, but it's just a redirected output from a file.

Command

Code: Select all

cat passive_check_results >> /usr/local/nagios/var/rw/nagios.cmd
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios Command File - Timestamp parsing

Post by scottwilkerson »

Not sure what you have in the file but this is the generally accepted way to send results

from http://old.nagios.org/developerinfo/ext ... and_id=115

Code: Select all

#!/bin/sh
# This is a sample shell script showing how you can submit the PROCESS_HOST_CHECK_RESULT command
# to Nagios.  Adjust variables to fit your environment as necessary.

now=`date +%s`
commandfile='/usr/local/nagios/var/rw/nagios.cmd'

/bin/printf "[%lu] PROCESS_HOST_CHECK_RESULT;host1;0;Host appears to be UP\n" $now > $commandfile
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Sphinx
Posts: 5
Joined: Thu Mar 05, 2015 3:29 am

Re: Nagios Command File - Timestamp parsing

Post by Sphinx »

Hey.

The content of my output is stated on my first post.
The referenced shell script is doing the same thing as mine, basically.
But nagios totally ignores the timestamp in the brackets and replaces it with the current time.

What we need, is to insert check results from days, hours, minutes ago in the command file and want exactly this timestamp and not the timestamp when it is being processed by nagios.

To display it:
the output i want

Code: Select all

[1425537702] PROCESS_SERVICE_CHECK_RESULT;fkwinbck;Active Backups;0;No Backups Running
the output the script produces

Code: Select all

[1425912857] PROCESS_SERVICE_CHECK_RESULT;fkwinbck;Active Backups;0;No Backups Running
What's being inserted into nagios

Code: Select all

[1425912657] EXTERNAL COMMAND: PROCESS_SERVICE_CHECK_RESULT;fkwinbck;Active Backups;0;No Backups Running
[1425912662] PASSIVE SERVICE CHECK: fkwinbck;Active Backups;0;No Backups Running
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Nagios Command File - Timestamp parsing

Post by scottwilkerson »

Sphinx wrote:What we need, is to insert check results from days, hours, minutes ago in the command file and want exactly this timestamp and not the timestamp when it is being processed by nagios.
This does not work in Core, it cannot write/replace/update the log files into the past.
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Sphinx
Posts: 5
Joined: Thu Mar 05, 2015 3:29 am

Re: Nagios Command File - Timestamp parsing

Post by Sphinx »

Okay, the timestamp in the log can be the current time, we don't care about that.
But is it possibly to parse our timestamp into nagios event queue instead of the current timestamp, so that we get an entry in the past.
Or are there any other possibilities, without database injection?
jdalrymple
Skynet Drone
Posts: 2620
Joined: Wed Feb 11, 2015 1:56 pm

Re: Nagios Command File - Timestamp parsing

Post by jdalrymple »

... The CGIs get their data from the log, so not really.
There is no database to inject.

If you have NDO then you can use database injection to update the timestamps there, but that won't get used in the Nagios Core interface. Where "in the world" do you need those original check timestamps to be reflected. If in the core web UI... there is no tidy way.
Sphinx
Posts: 5
Joined: Thu Mar 05, 2015 3:29 am

Re: Nagios Command File - Timestamp parsing

Post by Sphinx »

Yes, we have an NDO with a MySQL Database.
The use case we have is kind of special and i hoped that it would be possible.

Due to the fact that it is not possible, my question is answered, even if not succesfully resolved.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Nagios Command File - Timestamp parsing

Post by abrist »

Fair enough. Nagios Core is tethered to time's arrow . . . .
Lockin' 'er up.
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
Locked