naemon/naemon-livestatus

[Help] socat query broken pipe

oneingan opened this issue · 5 comments

Hi, I would like to make queries to livestatus without using shell pipes or redirections. I'm playin with socat and found some weird behaviour.

If I run

# echo -e "GET status\nColumns: livestatus_version" | socat STDIO UNIX:/run/naemon/live
1.0.6_20160914

works well, but if I run:

# socat EXEC:'echo -e "GET status\nColumns: program_version"' UNIX:/run/naemon/live
2016/09/19 15:43:51 socat[234] E write(5, 0xa29850, 15): Broken pipe

some debug

# socat -vvv EXEC:'echo -e "GET status\nColumns: program_version"' UNIX:/run/naemon/live
GET status
Columns: program_version
< 2016/09/19 15:44:55.457792  length=15 from=0 to=14
1.0.6_20160914
2016/09/19 15:44:55 socat[345] E write(5, 0xe34320, 15): Broken pipe

Do you have any hint about the difference between both commands?

Thanks, @juaningan. I was unable to use socat to extract info, and your first example is working for me 👍

sni commented

socat does not play nicely with livestatus. I spend hours of stracing this setup already. It seems like it has something to do with the buffersize of socat.
In the end we switched to ssh tunnel. There is also the advice in the Thruk FAQ not to use
socat: https://www.thruk.org/documentation/faq.html#backend-not-available

Thanks, @sni. That documentation page you referred to, mentions "the normal xinetd way". What does that mean? Is there any further explanation? In other words, barring socat, what is the "best practice" way of extracting information from mk_livestatus ?

sni commented

See https://mathias-kettner.de/checkmk_livestatus.html#Remote%20access%20to%20Livestatus%20via%20SSH%20or%20xinetd

When using OMD, you can enable this by "omd config" in the "Distributed Monitoring" Subsection.

I solved this by adding the -t to the socat command line. Turns out socat has a builtin timeout of 0.5 seconds. If the livestatus query takes longer, it results in the Broken pipe message.