0

I want to query a present Munin plugin from Nagios. As I would like to do some calculations and aggregations (the plugin reports data over a period of time) and not just look at the last values, the available plugins querying Munin data like check_munin seem unsuitable. So my idea was to get the entire fetch output and parse it. This however seems to present a problem for a reason I cannot understand.

If I enter fetch my-plugin manually after issuing nc my-munin-node 4949, I get the expected data output. If I try to script it, it does not work out as expected:

echo "fetch my-plugin" | nc my-munin-node 4949

just returns nothing while

(sleep 1 && echo "fetch my-plugin") | nc my-munin-node 4949

only returns the munin-node banner

# munin node at my-munin-node

without any trailing data. Running a network trace shows that the remote Munin node indeed starts sending data but is getting a TCP RST from the requester's end immediately.

the-wabbit
  • 40,737
  • 13
  • 111
  • 174

1 Answers1

1

Netcat will close a connection if EOF is being received through the input file descriptor. As the echo "string" | nc syntax is sending the "string" immediately followed by EOF, netcat is tearing down the connection instantly, without accepting any data from the remote end.

A more suitable syntax would be something like

(echo "fetch my-plugin" && sleep 5) | nc my-munin-node 4949

This way, EOF will not be sent unless the sleep returns - which will take 5 seconds in this example. The time interval should be chosen long enough for fetch my-plugin to complete and get all data transferred.

the-wabbit
  • 40,737
  • 13
  • 111
  • 174