naemon / naemon-core

Networks, Applications and Event Monitor
http://www.naemon.io/
GNU General Public License v2.0
153 stars 63 forks source link

Not able to submit multiple lines of long_service_output via LiveStatus (PROCESS_SERVICE_CHECK_RESULT) #387

Closed llange closed 2 years ago

llange commented 2 years ago

While migrating from a Nagios 3.x to a Naemon 1.3, I just discovered a change in behaviour regarding the handline of passive checks results with multiple lines in their output.

In previous Nagios + Livestatus setup, I was able to submit a passive check result with multiple lines of long service output. To do so, I needed to escape the newlines (as Livestatus is a line-oriented protocol, it stops processing a line after the newline \n character).

Now since using Naemon, I find that this is not possible anymore, i.e. the whole output is captured in SERVICEOUTPUT as a whole.

Examples

No LONGSERVICEOUTPUT

Command

echo "COMMAND [$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;HOST;SERVICE;0;FirstLine_SecondLine" | sudo unixcat /var/spool/nagios/rw/live

Debug log

[1656605865.841795] [016.2] [pid=24925] Parsing check output...
[1656605865.841798] [016.2] [pid=24925] Short Output: FirstLine_SecondLine
[1656605865.841801] [016.2] [pid=24925] Long Output:  NULL
[1656605865.841804] [016.2] [pid=24925] Perf Data:    NULL

Incorrectly parsed LONGSERVICEOUTPUT

Command

echo "COMMAND [$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;HOST;SERVICE;0;FirstLine_SecondLine\nLine2\nLine3" | sudo unixcat /var/spool/nagios/rw/live

Incorrect debug log

[1656606244.698241] [016.2] [pid=24925] Parsing check output...
[1656606244.698244] [016.2] [pid=24925] Short Output: FirstLine_SecondLine\nLine2\nLine3
[1656606244.698246] [016.2] [pid=24925] Long Output:  NULL
[1656606244.698248] [016.2] [pid=24925] Perf Data:    NULL

Expected debug log

[1656606244.698241] [016.2] [pid=24925] Parsing check output...
[1656606244.698244] [016.2] [pid=24925] Short Output: FirstLine_SecondLine
[1656606244.698246] [016.2] [pid=24925] Long Output:  Line2\nLine3
[1656606244.698248] [016.2] [pid=24925] Perf Data:    NULL

Impossible to send unescaped \n

(As Livestatus is line-oriented, a real \n character is taken as a line separator, thus does not land in the raw plugin output)

$ echo -e "COMMAND [$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;DV_AWS_NAGIOS;DollarU;0;FirstLine_SecondLine\nLine2\nLine3" | sudo unixcat /var/spool/nagios/rw/live
Invalid request method

I found a similar issue #144 but with no real progress on it.

I believe it could be related to the fact that parse_check_output() has been modified between Nagios 3.x and Nagios 4.x / Naemon, and that it now expects real (unescaped) \n characters.

What would be the preferred way to patch for this ? I'm willing to fix it, but before rushing I'd like to have feedback on the appropriate way to deal with it - and test for regressions.

Thanks.

sni commented 2 years ago

A pull request would be perfect. I cannot think of a regression if it's simply not possible right now. I guess livestatus would be a good place to fix this, since livestatus simply passes the commands to the query handler. And if i read #144 correctly, then the query handler is capable of multiline output.

llange commented 2 years ago

Yes I confirm that the query handler does accept multiline output:

Command

echo -e '@command run [$(date +%s)] PROCESS_SERVICE_CHECK_RESULT;HOST;SERVICE;0;FirstLine_SecondLine\nLine2\nLine3\0' | socat - UNIX-CONNECT:/var/lib/naemon/naemon.qh

Debug log

[1656618897.153289] [016.2] [pid=5942] Parsing check output...
[1656618897.153292] [016.2] [pid=5942] Short Output: FirstLine_SecondLine
[1656618897.153294] [016.2] [pid=5942] Long Output:  Line2\nLine3
[1656618897.153297] [016.2] [pid=5942] Perf Data:    NULL

OK so I'll dive into livestatus code and try to make it work ; and will update with a PR then.

llange commented 2 years ago

Thanks for the merge, I'm closing the issue then.